@@ -132,15 +132,18 @@ struct cmpto_j2k_enc_cuda_buffer_data_allocator
132132
133133struct cmpto_j2k_technology {
134134 const char *name;
135- size_t default_mem_limit;
135+ int cmpto_supp_bit;
136+ size_t default_mem_limit;
136137 unsigned default_img_tile_limit; // /< nr of frames encoded at a moment
137138 bool (*add_device)(struct cmpto_j2k_enc_ctx_cfg *ctx_cfg,
138139 size_t mem_limit, unsigned int tile_limit,
139140 int thread_count);
140141};
141142
142143constexpr struct cmpto_j2k_technology technology_cpu = {
143- " CPU" , 0 , // /< unimplemented, should be 0
144+ " CPU" ,
145+ CMPTO_TECHNOLOGY_CPU,
146+ 0 , // /< mem_limit unimplemented, should be 0
144147 0 ,
145148 [](struct cmpto_j2k_enc_ctx_cfg *ctx_cfg, size_t mem_limit,
146149 unsigned int tile_limit, int thread_count) {
@@ -152,7 +155,9 @@ constexpr struct cmpto_j2k_technology technology_cpu = {
152155};
153156
154157constexpr struct cmpto_j2k_technology technology_cuda = {
155- " CUDA" , 1000LLU * 1000 * 1000 ,
158+ " CUDA" ,
159+ CMPTO_TECHNOLOGY_CUDA,
160+ 1000LLU * 1000 * 1000 ,
156161 1 ,
157162 [](struct cmpto_j2k_enc_ctx_cfg *ctx_cfg, size_t mem_limit,
158163 unsigned int tile_limit, int /* thread_count */ ) {
@@ -166,40 +171,70 @@ constexpr struct cmpto_j2k_technology technology_cuda = {
166171 },
167172};
168173
174+ /* *
175+ * @param name name of the techoology, must not be NULL
176+ * @returns techoology from name, may not be supported; 0 if not found
177+ */
178+ static const struct cmpto_j2k_technology *
179+ get_technology_by_name (const char *name) {
180+ const struct cmpto_j2k_technology *technologies[] = {
181+ &technology_cpu, &technology_cuda
182+ };
183+ for (size_t i = 0 ; i < ARR_COUNT (technologies); ++i) {
184+ if (strcasecmp (name, technologies[i]->name ) == 0 ) {
185+ return technologies[i];
186+ }
187+ }
188+ MSG (ERROR, " Unknown/unsupported technology: %s\n " , name);
189+ return nullptr ;
190+ }
191+
192+ /* *
193+ * @param name comma-separated list of requested technologies, nullptr for
194+ * default order (in tech_default variable)
195+ * @returns first supported technology requested in name
196+ */
169197static const struct cmpto_j2k_technology *
170- get_default_technology ( )
198+ get_supported_technology ( const char *name )
171199{
200+ std::string const tech_default = " cuda,cpu" ;
172201 const struct cmpto_version *version = cmpto_j2k_enc_get_version ();
173202 if (version == nullptr ) {
174203 MSG (ERROR, " Cannot get Cmpto J2K supported technologies!\n " );
175204 return nullptr ;
176205 }
177- if ((version->technology & CMPTO_TECHNOLOGY_CUDA) != 0 ) {
178- return &technology_cuda;
206+ std::string cfg = tech_default;
207+ if (name != nullptr ) {
208+ cfg = name;
179209 }
180- if ((version->technology & CMPTO_TECHNOLOGY_CPU) != 0 ) {
181- return &technology_cpu;
210+ char *tmp = &cfg[0 ];
211+ char *endptr = nullptr ;
212+ while (char *tname = strtok_r (tmp, " ," , &endptr)) {
213+ tmp = nullptr ;
214+ const struct cmpto_j2k_technology *technology =
215+ get_technology_by_name (tname);
216+ if (technology == nullptr ) {
217+ return nullptr ;
218+ }
219+ if ((version->technology & technology->cmpto_supp_bit ) != 0 ) {
220+ return technology;
221+ }
222+ MSG (VERBOSE, " Technology %s not supported, trying next...\n " ,
223+ tname);
182224 }
183- MSG (ERROR, " No supported technology (CUDA or CPU)!\n " );
184- return nullptr ;
185- }
186225
187- static const struct cmpto_j2k_technology *
188- get_technology (const char *name)
189- {
190- if (strcasecmp (name, " cuda" ) == 0 ) {
191- return &technology_cuda;
192- }
193- if (strcasecmp (name, " cpu" ) == 0 ) {
194- return &technology_cpu;
226+ if (name == nullptr ) {
227+ MSG (ERROR, " No supported technology (%s)!\n " ,
228+ tech_default.c_str ());
229+ } else {
230+ MSG (ERROR, " Requested technology %s not available!\n " , name);
195231 }
196- MSG (ERROR, " Unknown/unsupported technology: %s\n " , name);
197232 return nullptr ;
198233}
199234
200235struct state_video_compress_j2k {
201236 struct module module_data{};
202- const struct cmpto_j2k_technology *tech = get_default_technology() ;
237+ const struct cmpto_j2k_technology *tech = nullptr ;
203238 struct cmpto_j2k_enc_ctx *context{};
204239 struct cmpto_j2k_enc_cfg *enc_settings{};
205240 long long int rate = 0 ; // /< bitrate in bits per second
@@ -539,8 +574,8 @@ struct {
539574 const bool is_boolean;
540575 const char *placeholder;
541576} usage_opts[] = {
542- { " Technology" , " technology" , " technology to use" ,
543- " :technology=" , false , " gpu " },
577+ { " Technology" , " technology" , " technology to use (use comma to separate multiple) " ,
578+ " :technology=" , false , " cuda " },
544579 { " Bitrate" , " quality" , " Target bitrate" , " :rate=" , false , " 70M" },
545580 { " Quality" , " quant_coeff" ,
546581 " Quality in range [0-1], 1.0 is best, default: " TOSTRING (DEFAULT_QUALITY),
@@ -651,6 +686,7 @@ static struct module * j2k_compress_init(struct module *parent, const char *c_cf
651686 const auto *version = cmpto_j2k_enc_get_version ();
652687 LOG (LOG_LEVEL_INFO) << MOD_NAME << " Using codec version: " << (version == nullptr ? " (unknown)" : version->name ) << " \n " ;
653688
689+ const char *req_technology = nullptr ;
654690 auto *s = new state_video_compress_j2k ();
655691
656692 std::string cfg = c_cfg;
@@ -661,7 +697,7 @@ static struct module * j2k_compress_init(struct module *parent, const char *c_cf
661697 if (IS_KEY_PREFIX (item, " rate" )) {
662698 ASSIGN_CHECK_VAL (s->rate , strchr (item, ' =' ) + 1 , 1 );
663699 } else if (IS_KEY_PREFIX (item, " technology" )) {
664- s-> tech = get_technology ( strchr (item, ' =' ) + 1 ) ;
700+ req_technology = strchr (item, ' =' ) + 1 ;
665701 } else if (IS_KEY_PREFIX (item, " quality" )) {
666702 s->quality = stod (strchr (item, ' =' ) + 1 );
667703 } else if (IS_PREFIX (item, " lossless" )) {
@@ -692,6 +728,7 @@ static struct module * j2k_compress_init(struct module *parent, const char *c_cf
692728 return nullptr ;
693729 }
694730
731+ s->tech = get_supported_technology (req_technology);
695732 if (s->tech == nullptr ) {
696733 j2k_compress_done ((struct module *) s);
697734 return nullptr ;
0 commit comments