7272#include " types.h" // for video_desc, tile, video_frame, UYVY, RGB
7373#include " utils/macros.h" // for TOSTRING, to_fourcc
7474#include " utils/color_out.h" // for color_printf
75+ #include " utils/string_view_utils.hpp"
7576#include " video_codec.h" // for vc_get_linesize, get_codec_name
7677#include " video_compress.h" // for codec, module_option, encoder, compres...
7778#include " video_frame.h" // for vf_free, vf_alloc_desc_data, vf_copy_m...
@@ -150,34 +151,40 @@ static void usage() {
150151 printf (" \n " );
151152}
152153
153- static int parse_fmt (struct state_video_compress_cineform *s, char *fmt) {
154- char *item, *save_ptr = NULL ;
155- if (fmt) {
156- while ((item = strtok_r (fmt, " :" , &save_ptr)) != NULL ) {
157- if (strncasecmp (" help" , item, strlen (" help" )) == 0 ) {
158- usage ();
159- return 1 ;
160- } else if (strncasecmp (" quality=" , item, strlen (" quality=" )) == 0 ) {
161- char *quality = item + strlen (" quality=" );
162- int qual = atoi (quality);
163- if (qual >= 1 && qual <= 6 ){
164- s->requested_quality = static_cast <CFHD_EncodingQuality>(qual);
165- } else {
166- log_msg (LOG_LEVEL_ERROR, MOD_NAME " Error: Quality must be in range 1-6.\n " );
167- return -1 ;
168- }
169- } else if (strncasecmp (" threads=" , item, strlen (" threads=" )) == 0 ) {
170- char *threads = item + strlen (" threads=" );
171- s->requested_threads = atoi (threads);
172- } else if (strncasecmp (" pool_size=" , item, strlen (" pool_size=" )) == 0 ) {
173- char *pool_size = item + strlen (" pool_size=" );
174- s->requested_pool_size = atoi (pool_size);
175- } else {
176- log_msg (LOG_LEVEL_ERROR, MOD_NAME " Error: unknown option %s.\n " ,
177- item);
154+ static int parse_cfg (struct state_video_compress_cineform *s, std::string_view cfg) {
155+ while (!cfg.empty ()){
156+ auto tok = tokenize (cfg, ' :' , ' "' );
157+ auto key = tokenize (tok, ' =' );
158+ auto val = tokenize (tok, ' =' );
159+
160+ if (key == " help" ) {
161+ usage ();
162+ return 1 ;
163+ } else if (key == " quality" ) {
164+ int qual;
165+ if (!parse_num (val, qual)){
166+ log_msg (LOG_LEVEL_ERROR, MOD_NAME " Failed to parse value for option %s\n " , std::string (key).c_str ());
178167 return -1 ;
179168 }
180- fmt = NULL ;
169+ if (qual < 1 || qual > 6 ){
170+ log_msg (LOG_LEVEL_ERROR, MOD_NAME " Error: Quality must be in range 1-6.\n " );
171+ return -1 ;
172+ }
173+ s->requested_quality = static_cast <CFHD_EncodingQuality>(qual);
174+ } else if (key == " threads" ) {
175+ if (!parse_num (val, s->requested_threads )){
176+ log_msg (LOG_LEVEL_ERROR, MOD_NAME " Failed to parse value for option %s\n " , std::string (key).c_str ());
177+ return -1 ;
178+ }
179+ } else if (key == " pool_size" ) {
180+ if (!parse_num (val, s->requested_pool_size )){
181+ log_msg (LOG_LEVEL_ERROR, MOD_NAME " Failed to parse value for option %s\n " , std::string (key).c_str ());
182+ return -1 ;
183+ }
184+ } else {
185+ log_msg (LOG_LEVEL_ERROR, MOD_NAME " Error: unknown option %s.\n " ,
186+ std::string (key).c_str ());
187+ return -1 ;
181188 }
182189 }
183190
@@ -190,9 +197,7 @@ static void * cineform_compress_init(struct module *parent, const char *opts)
190197
191198 auto s = std::make_unique<state_video_compress_cineform>();
192199
193- char *fmt = strdup (opts);
194- int ret = parse_fmt (s.get (), fmt);
195- free (fmt);
200+ int ret = parse_cfg (s.get (), opts);
196201 if (ret != 0 ) {
197202 return ret > 0 ? INIT_NOERR : nullptr ;
198203 }
@@ -472,8 +477,7 @@ static std::shared_ptr<video_frame> cineform_compress_pop(void *state)
472477 }
473478
474479 static auto dispose = [](struct video_frame *frame) {
475- std::tuple<CFHD_EncoderPoolRef, CFHD_SampleBufferRef> *t =
476- static_cast <std::tuple<CFHD_EncoderPoolRef, CFHD_SampleBufferRef> *>(frame->callbacks .dispose_udata );
480+ auto t = static_cast <std::tuple<CFHD_EncoderPoolRef, CFHD_SampleBufferRef> *>(frame->callbacks .dispose_udata );
477481 if (t)
478482 CFHD_ReleaseSampleBuffer (std::get<0 >(*t), std::get<1 >(*t));
479483 vf_free (frame);
@@ -528,10 +532,10 @@ static compress_module_info get_cineform_module_info(){
528532const struct video_compress_info cineform_info = {
529533 cineform_compress_init,
530534 cineform_compress_done,
531- NULL ,
532- NULL ,
533- NULL ,
534- NULL ,
535+ nullptr ,
536+ nullptr ,
537+ nullptr ,
538+ nullptr ,
535539 cineform_compress_push,
536540 cineform_compress_pop,
537541 get_cineform_module_info,
0 commit comments