31 #include <libcjson/cJSON.h> 32 #include <libmediaprocsutils/uri_parser.h> 33 #include <libmediaprocsutils/log.h> 34 #include <libmediaprocsutils/stat_codes.h> 35 #include <libmediaprocsutils/check_utils.h> 36 #include <libmediaprocs/proc_if.h> 49 if(ref_video_settings_enc_ctx== NULL)
52 if((video_settings_enc_ctx= *ref_video_settings_enc_ctx)!= NULL) {
55 video_settings_enc_ctx);
57 free(video_settings_enc_ctx);
58 *ref_video_settings_enc_ctx= NULL;
68 CHECK_DO(video_settings_enc_ctx!= NULL,
return STAT_ERROR);
74 video_settings_enc_ctx->
gop_size= 15;
75 memset((
void*)video_settings_enc_ctx->
conf_preset, 0,
94 CHECK_DO(video_settings_enc_ctx_src!= NULL,
return STAT_ERROR);
95 CHECK_DO(video_settings_enc_ctx_dst!= NULL,
return STAT_ERROR);
98 memcpy(video_settings_enc_ctx_dst, video_settings_enc_ctx_src,
110 int end_code= STAT_ERROR;
111 int flag_is_query= 0;
112 cJSON *cjson_rest= NULL, *cjson_aux= NULL;
113 char *bit_rate_output_str= NULL, *frame_rate_output_str= NULL,
114 *width_output_str= NULL, *height_output_str= NULL,
115 *gop_size_str= NULL, *sample_fmt_input_str= NULL,
116 *profile_str= NULL, *conf_preset_str= NULL;
117 LOG_CTX_INIT(log_ctx);
120 CHECK_DO(video_settings_enc_ctx!= NULL,
return STAT_ERROR);
121 CHECK_DO(str!= NULL,
return STAT_EINVAL);
125 flag_is_query= (str[0]==
'{' && str[strlen(str)-1]==
'}')? 0: 1;
129 if(flag_is_query== 1) {
132 bit_rate_output_str= uri_parser_query_str_get_value(
"bit_rate_output",
134 if(bit_rate_output_str!= NULL)
138 frame_rate_output_str= uri_parser_query_str_get_value(
139 "frame_rate_output", str);
140 if(frame_rate_output_str!= NULL)
142 atoll(frame_rate_output_str);
145 width_output_str= uri_parser_query_str_get_value(
"width_output", str);
146 if(width_output_str!= NULL)
147 video_settings_enc_ctx->
width_output= atoll(width_output_str);
150 height_output_str= uri_parser_query_str_get_value(
"height_output", str);
151 if(height_output_str!= NULL)
152 video_settings_enc_ctx->
height_output= atoll(height_output_str);
155 gop_size_str= uri_parser_query_str_get_value(
"gop_size", str);
156 if(gop_size_str!= NULL)
157 video_settings_enc_ctx->
gop_size= atoll(gop_size_str);
160 conf_preset_str= uri_parser_query_str_get_value(
"conf_preset", str);
161 if(conf_preset_str!= NULL) {
164 end_code= STAT_EINVAL;
goto end);
165 memcpy((
void*)video_settings_enc_ctx->
conf_preset, conf_preset_str,
166 strlen(conf_preset_str));
167 video_settings_enc_ctx->
conf_preset[strlen(conf_preset_str)]= 0;
173 cjson_rest= cJSON_Parse(str);
174 CHECK_DO(cjson_rest!= NULL,
goto end);
177 cjson_aux= cJSON_GetObjectItem(cjson_rest,
"bit_rate_output");
182 cjson_aux= cJSON_GetObjectItem(cjson_rest,
"frame_rate_output");
187 cjson_aux= cJSON_GetObjectItem(cjson_rest,
"width_output");
189 video_settings_enc_ctx->
width_output= cjson_aux->valuedouble;
192 cjson_aux= cJSON_GetObjectItem(cjson_rest,
"height_output");
194 video_settings_enc_ctx->
height_output= cjson_aux->valuedouble;
197 cjson_aux= cJSON_GetObjectItem(cjson_rest,
"gop_size");
199 video_settings_enc_ctx->
gop_size= cjson_aux->valuedouble;
202 cjson_aux= cJSON_GetObjectItem(cjson_rest,
"conf_preset");
203 if(cjson_aux!= NULL && cjson_aux->valuestring!= NULL) {
204 CHECK_DO(strlen(cjson_aux->valuestring)<
206 end_code= STAT_EINVAL;
goto end);
208 cjson_aux->valuestring, strlen(cjson_aux->valuestring));
210 [strlen(cjson_aux->valuestring)]= 0;
214 end_code= STAT_SUCCESS;
216 if(cjson_rest!= NULL)
217 cJSON_Delete(cjson_rest);
218 if(bit_rate_output_str!= NULL)
219 free(bit_rate_output_str);
220 if(frame_rate_output_str!= NULL)
221 free(frame_rate_output_str);
222 if(width_output_str!= NULL)
223 free(width_output_str);
224 if(height_output_str!= NULL)
225 free(height_output_str);
226 if(gop_size_str!= NULL)
228 if(sample_fmt_input_str!= NULL)
229 free(sample_fmt_input_str);
230 if(profile_str!= NULL)
232 if(conf_preset_str!= NULL)
233 free(conf_preset_str);
239 cJSON **ref_cjson_rest,
log_ctx_t *log_ctx)
241 int end_code= STAT_ERROR;
242 cJSON *cjson_rest= NULL, *cjson_aux= NULL;
243 LOG_CTX_INIT(log_ctx);
245 CHECK_DO(video_settings_enc_ctx!= NULL,
goto end);
246 CHECK_DO(ref_cjson_rest!= NULL,
goto end);
248 *ref_cjson_rest= NULL;
251 cjson_rest= cJSON_CreateObject();
252 CHECK_DO(cjson_rest!= NULL,
goto end);
266 cjson_aux= cJSON_CreateNumber((
double)
268 CHECK_DO(cjson_aux!= NULL,
goto end);
269 cJSON_AddItemToObject(cjson_rest,
"bit_rate_output", cjson_aux);
272 cjson_aux= cJSON_CreateNumber((
double)
274 CHECK_DO(cjson_aux!= NULL,
goto end);
275 cJSON_AddItemToObject(cjson_rest,
"frame_rate_output", cjson_aux);
278 cjson_aux= cJSON_CreateNumber((
double)video_settings_enc_ctx->
width_output);
279 CHECK_DO(cjson_aux!= NULL,
goto end);
280 cJSON_AddItemToObject(cjson_rest,
"width_output", cjson_aux);
283 cjson_aux= cJSON_CreateNumber((
double)
285 CHECK_DO(cjson_aux!= NULL,
goto end);
286 cJSON_AddItemToObject(cjson_rest,
"height_output", cjson_aux);
289 cjson_aux= cJSON_CreateNumber((
double)video_settings_enc_ctx->
gop_size);
290 CHECK_DO(cjson_aux!= NULL,
goto end);
291 cJSON_AddItemToObject(cjson_rest,
"gop_size", cjson_aux);
295 strlen((
const char*)video_settings_enc_ctx->
conf_preset)> 0) {
296 cjson_aux= cJSON_CreateString((
const char*)
299 cjson_aux= cJSON_CreateNull();
301 CHECK_DO(cjson_aux!= NULL,
goto end);
302 cJSON_AddItemToObject(cjson_rest,
"conf_preset", cjson_aux);
304 *ref_cjson_rest= cjson_rest;
306 end_code= STAT_SUCCESS;
308 if(cjson_rest!= NULL)
309 cJSON_Delete(cjson_rest);
324 if(ref_video_settings_dec_ctx== NULL)
327 if((video_settings_dec_ctx= *ref_video_settings_dec_ctx)!= NULL) {
329 free(video_settings_dec_ctx);
330 *ref_video_settings_dec_ctx= NULL;
340 CHECK_DO(video_settings_dec_ctx!= NULL,
return STAT_ERROR);
363 CHECK_DO(video_settings_dec_ctx_src!= NULL,
return STAT_ERROR);
364 CHECK_DO(video_settings_dec_ctx_dst!= NULL,
return STAT_ERROR);
376 int end_code= STAT_ERROR;
377 int flag_is_query= 0;
378 cJSON *cjson_rest= NULL;
379 LOG_CTX_INIT(log_ctx);
382 CHECK_DO(video_settings_dec_ctx!= NULL,
return STAT_ERROR);
383 CHECK_DO(str!= NULL,
return STAT_EINVAL);
387 flag_is_query= (str[0]==
'{' && str[strlen(str)-1]==
'}')? 0: 1;
391 if(flag_is_query== 1) {
411 cjson_rest= cJSON_Parse(str);
412 CHECK_DO(cjson_rest!= NULL,
goto end);
427 end_code= STAT_SUCCESS;
429 if(cjson_rest!= NULL)
430 cJSON_Delete(cjson_rest);
436 cJSON **ref_cjson_rest,
log_ctx_t *log_ctx)
438 int end_code= STAT_ERROR;
439 cJSON *cjson_rest= NULL;
440 LOG_CTX_INIT(log_ctx);
442 CHECK_DO(video_settings_dec_ctx!= NULL,
goto end);
443 CHECK_DO(ref_cjson_rest!= NULL,
goto end);
445 *ref_cjson_rest= NULL;
448 cjson_rest= cJSON_CreateObject();
449 CHECK_DO(cjson_rest!= NULL,
goto end);
469 *ref_cjson_rest= cjson_rest;
471 end_code= STAT_SUCCESS;
473 if(cjson_rest!= NULL)
474 cJSON_Delete(cjson_rest);
int video_settings_enc_ctx_init(volatile video_settings_enc_ctx_t *video_settings_enc_ctx)
int video_settings_dec_ctx_restful_get(volatile video_settings_dec_ctx_t *video_settings_dec_ctx, cJSON **ref_cjson_rest, log_ctx_t *log_ctx)
Video encoder and decoder generic settings.
int video_settings_dec_ctx_init(volatile video_settings_dec_ctx_t *video_settings_dec_ctx)
int video_settings_enc_ctx_restful_put(volatile video_settings_enc_ctx_t *video_settings_enc_ctx, const char *str, log_ctx_t *log_ctx)
void video_settings_dec_ctx_release(video_settings_dec_ctx_t **ref_video_settings_dec_ctx)
video_settings_dec_ctx_t * video_settings_dec_ctx_allocate()
void video_settings_enc_ctx_deinit(volatile video_settings_enc_ctx_t *video_settings_enc_ctx)
void video_settings_enc_ctx_release(video_settings_enc_ctx_t **ref_video_settings_enc_ctx)
#define CHECK_DO(COND, ACTION)
int video_settings_enc_ctx_cpy(const video_settings_enc_ctx_t *video_settings_enc_ctx_src, video_settings_enc_ctx_t *video_settings_enc_ctx_dst)
int video_settings_enc_ctx_restful_get(volatile video_settings_enc_ctx_t *video_settings_enc_ctx, cJSON **ref_cjson_rest, log_ctx_t *log_ctx)
int video_settings_dec_ctx_cpy(const video_settings_dec_ctx_t *video_settings_dec_ctx_src, video_settings_dec_ctx_t *video_settings_dec_ctx_dst)
video_settings_enc_ctx_t * video_settings_enc_ctx_allocate()
int video_settings_dec_ctx_restful_put(volatile video_settings_dec_ctx_t *video_settings_dec_ctx, const char *str, log_ctx_t *log_ctx)
void video_settings_dec_ctx_deinit(volatile video_settings_dec_ctx_t *video_settings_dec_ctx)