26 #include <UnitTest++/UnitTest++.h> 32 #include <sys/types.h> 36 #include <libcjson/cJSON.h> 37 #include <libmediaprocsutils/uri_parser.h> 39 #include <libmediaprocsutils/log.h> 40 #include <libmediaprocsutils/check_utils.h> 41 #include <libmediaprocsutils/stat_codes.h> 42 #include <libmediaprocsutils/fifo.h> 43 #include <libmediaprocs/proc_if.h> 44 #include <libmediaprocs/procs.h> 45 #include <libmediaprocs/proc.h> 50 static void bypass_proc_close(
proc_ctx_t **ref_proc_ctx);
51 static int bypass_proc_rest_put(
proc_ctx_t *proc_ctx,
const char *str);
65 const char *settings_str,
log_ctx_t *log_ctx, va_list arg)
67 int ret_code, end_code= STAT_ERROR;
69 LOG_CTX_INIT(log_ctx);
72 if(proc_if== NULL || settings_str== NULL)
77 if(bypass_proc_ctx== NULL)
81 ret_code= bypass_proc_rest_put((
proc_ctx_t*)bypass_proc_ctx, settings_str);
82 CHECK_DO(ret_code== STAT_SUCCESS,
goto end);
84 end_code= STAT_SUCCESS;
86 if(end_code!= STAT_SUCCESS)
87 bypass_proc_close((
proc_ctx_t**)&bypass_proc_ctx);
91 static void bypass_proc_close(
proc_ctx_t **ref_proc_ctx)
95 if(ref_proc_ctx== NULL)
98 if((proc_ctx= *ref_proc_ctx)!= NULL) {
104 static int bypass_proc_rest_put(
proc_ctx_t *proc_ctx,
const char *str)
106 int end_code= STAT_ERROR;
107 int flag_is_query= 0;
108 cJSON *cjson_rest= NULL, *cjson_aux= NULL;
109 char *setting1_str= NULL;
113 CHECK_DO(proc_ctx!= NULL,
return STAT_ERROR);
114 CHECK_DO(str!= NULL,
return STAT_EINVAL);
118 flag_is_query= (str[0]==
'{' && str[strlen(str)-1]==
'}')? 0: 1;
122 if(flag_is_query== 1) {
125 setting1_str= uri_parser_query_str_get_value(
"setting1", str);
126 if(setting1_str!= NULL)
132 cjson_rest= cJSON_Parse(str);
133 CHECK_DO(cjson_rest!= NULL,
goto end);
136 cjson_aux= cJSON_GetObjectItem(cjson_rest,
"setting1");
141 end_code= STAT_SUCCESS;
143 if(cjson_rest!= NULL)
144 cJSON_Delete(cjson_rest);
145 if(setting1_str!= NULL)
150 static int bypass_proc_rest_get(
proc_ctx_t *proc_ctx,
153 int end_code= STAT_ERROR;
154 cJSON *cjson_rest= NULL, *cjson_settings= NULL, *cjson_aux= NULL;
158 if(proc_ctx== NULL || ref_reponse== NULL)
173 cjson_rest= cJSON_CreateObject();
174 CHECK_DO(cjson_rest!= NULL,
goto end);
177 cjson_settings= cJSON_CreateObject();
178 CHECK_DO(cjson_settings!= NULL,
goto end);
179 cJSON_AddItemToObject(cjson_rest,
"settings", cjson_settings);
182 cjson_aux= cJSON_CreateNumber((
double)
184 CHECK_DO(cjson_aux!= NULL,
goto end);
185 cJSON_AddItemToObject(cjson_settings,
"setting1", cjson_aux);
192 CHECK_DO(*ref_reponse!= NULL && strlen((
char*)*ref_reponse)> 0,
196 *ref_reponse= (
void*)cjson_rest;
200 LOGE(
"Unknown format requested for processor REST\n");
204 end_code= STAT_SUCCESS;
206 if(cjson_rest!= NULL)
207 cJSON_Delete(cjson_rest);
211 static int bypass_proc_process_frame(
proc_ctx_t *proc_ctx,
214 int ret_code, end_code= STAT_ERROR;
215 size_t fifo_elem_size= 0;
220 (
void**)&proc_frame_ctx, &fifo_elem_size);
221 CHECK(ret_code== STAT_SUCCESS || ret_code== STAT_EAGAIN);
222 if(ret_code!= STAT_SUCCESS) {
228 proc_frame_ctx,
sizeof(
void*));
229 CHECK(ret_code== STAT_SUCCESS || ret_code== STAT_ENOMEM);
231 end_code= STAT_SUCCESS;
233 if(proc_frame_ctx!= NULL)
240 TEST(REGISTER_UNREGISTER_PROC_IF)
244 "bypass_processor",
"encoder",
"application/octet-stream",
245 (uint64_t)(PROC_FEATURE_BITRATE|PROC_FEATURE_REGISTER_PTS|
246 PROC_FEATURE_LATENCY),
249 proc_send_frame_default1,
251 proc_recv_frame_default1,
253 bypass_proc_rest_put,
254 bypass_proc_rest_get,
255 bypass_proc_process_frame,
263 CHECK(ret_code== STAT_SUCCESS);
266 CHECK(ret_code== STAT_SUCCESS);
269 CHECK(ret_code== STAT_SUCCESS);
274 TEST(REGISTER_GET_COPY_PROC_IF)
278 "bypass_processor",
"encoder",
"application/octet-stream",
279 (uint64_t)(PROC_FEATURE_BITRATE|PROC_FEATURE_REGISTER_PTS|
280 PROC_FEATURE_LATENCY),
283 proc_send_frame_default1,
285 proc_recv_frame_default1,
287 bypass_proc_rest_put,
288 bypass_proc_rest_get,
289 bypass_proc_process_frame,
298 CHECK(ret_code== STAT_SUCCESS);
301 CHECK(ret_code== STAT_SUCCESS);
305 CHECK(ret_code== STAT_SUCCESS);
308 CHECK(
proc_if_cmp(&proc_if_bypass_proc, proc_if_cpy)== 0);
311 CHECK(ret_code== STAT_SUCCESS);
313 if(proc_if_cpy!= NULL)
318 TEST(POST_DELETE_PROCS)
320 int ret_code, proc_id= -1;
322 char *rest_str= NULL;
323 cJSON *cjson_rest= NULL, *cjson_aux= NULL;
325 "bypass_processor",
"encoder",
"application/octet-stream",
326 (uint64_t)(PROC_FEATURE_BITRATE|PROC_FEATURE_REGISTER_PTS|
327 PROC_FEATURE_LATENCY),
330 proc_send_frame_default1,
332 proc_recv_frame_default1,
334 bypass_proc_rest_put,
335 bypass_proc_rest_get,
336 bypass_proc_process_frame,
344 ret_code= log_module_open();
345 CHECK_DO(ret_code== STAT_SUCCESS, CHECK(
false);
goto end);
348 CHECK(ret_code== STAT_SUCCESS);
351 CHECK(ret_code== STAT_SUCCESS);
355 CHECK_DO(procs_ctx!= NULL, CHECK(
false);
goto end);
357 ret_code=
procs_opt(procs_ctx,
"PROCS_POST",
"bypass_processor",
358 "setting1=100", &rest_str);
359 CHECK_DO(ret_code== STAT_SUCCESS && rest_str!= NULL,
360 CHECK(
false);
goto end);
362 cjson_rest= cJSON_Parse(rest_str);
363 CHECK_DO(cjson_rest!= NULL, CHECK(
false);
goto end);
364 cjson_aux= cJSON_GetObjectItem(cjson_rest,
"proc_id");
365 CHECK_DO(cjson_aux!= NULL, CHECK(
false);
goto end);
366 CHECK((proc_id= cjson_aux->valuedouble)>= 0);
370 ret_code=
procs_opt(procs_ctx,
"PROCS_ID_DELETE", proc_id);
371 CHECK(ret_code== STAT_SUCCESS);
374 CHECK(ret_code== STAT_SUCCESS);
382 if(cjson_rest!= NULL)
383 cJSON_Delete(cjson_rest);
389 int ret_code, proc_id= -1;
391 char *rest_str= NULL;
392 cJSON *cjson_rest= NULL, *cjson_aux= NULL;
394 "bypass_processor",
"encoder",
"application/encoder",
395 (uint64_t)(PROC_FEATURE_BITRATE|PROC_FEATURE_REGISTER_PTS|
396 PROC_FEATURE_LATENCY),
399 proc_send_frame_default1,
401 proc_recv_frame_default1,
403 bypass_proc_rest_put,
404 bypass_proc_rest_get,
405 bypass_proc_process_frame,
412 "bypass_processor2",
"encoder2",
"application/encoder2",
413 (uint64_t)(PROC_FEATURE_BITRATE|PROC_FEATURE_REGISTER_PTS|
414 PROC_FEATURE_LATENCY),
417 proc_send_frame_default1,
419 proc_recv_frame_default1,
421 bypass_proc_rest_put,
422 bypass_proc_rest_get,
423 bypass_proc_process_frame,
434 CHECK(ret_code== STAT_SUCCESS);
437 &proc_if_bypass_proc);
438 CHECK(ret_code== STAT_SUCCESS);
440 &proc_if_bypass_proc2);
441 CHECK(ret_code== STAT_SUCCESS);
445 CHECK_DO(procs_ctx!= NULL, CHECK(
false);
goto end);
447 ret_code=
procs_opt(procs_ctx,
"PROCS_POST",
"bypass_processor",
448 "setting1=100", &rest_str);
449 CHECK_DO(ret_code== STAT_SUCCESS && rest_str!= NULL,
450 CHECK(
false);
goto end);
452 cjson_rest= cJSON_Parse(rest_str);
453 CHECK_DO(cjson_rest!= NULL, CHECK(
false);
goto end);
454 cjson_aux= cJSON_GetObjectItem(cjson_rest,
"proc_id");
455 CHECK_DO(cjson_aux!= NULL, CHECK(
false);
goto end);
456 CHECK((proc_id= cjson_aux->valuedouble)>= 0);
459 cJSON_Delete(cjson_rest);
463 ret_code=
procs_opt(procs_ctx,
"PROCS_ID_GET", proc_id, &rest_str);
464 CHECK_DO(ret_code== STAT_SUCCESS && rest_str!= NULL,
465 CHECK(
false);
goto end);
467 cjson_rest= cJSON_Parse(rest_str);
468 CHECK_DO(cjson_rest!= NULL, CHECK(
false);
goto end);
469 cjson_aux= cJSON_GetObjectItem(cjson_rest,
"settings");
470 CHECK_DO(cjson_aux!= NULL, CHECK(
false);
goto end);
471 cjson_aux= cJSON_GetObjectItem(cjson_aux,
"setting1");
472 CHECK_DO(cjson_aux!= NULL, CHECK(
false);
goto end);
473 CHECK(cjson_aux->valuedouble== 100);
474 free(rest_str); rest_str= NULL;
475 cJSON_Delete(cjson_rest); cjson_rest= NULL;
478 ret_code=
procs_opt(procs_ctx,
"PROCS_ID_PUT", proc_id,
"setting1=200");
479 CHECK(ret_code== STAT_SUCCESS);
482 ret_code=
procs_opt(procs_ctx,
"PROCS_ID_GET", proc_id, &rest_str);
483 CHECK_DO(ret_code== STAT_SUCCESS && rest_str!= NULL,
484 CHECK(
false);
goto end);
486 cjson_rest= cJSON_Parse(rest_str);
487 CHECK_DO(cjson_rest!= NULL, CHECK(
false);
goto end);
488 cjson_aux= cJSON_GetObjectItem(cjson_rest,
"settings");
489 CHECK_DO(cjson_aux!= NULL, CHECK(
false);
goto end);
490 cjson_aux= cJSON_GetObjectItem(cjson_aux,
"setting1");
491 CHECK_DO(cjson_aux!= NULL, CHECK(
false);
goto end);
492 CHECK(cjson_aux->valuedouble== 200);
493 free(rest_str); rest_str= NULL;
494 cJSON_Delete(cjson_rest); cjson_rest= NULL;
497 ret_code=
procs_opt(procs_ctx,
"PROCS_ID_PUT", proc_id,
498 "proc_name=bypass_processor");
499 CHECK(ret_code== STAT_SUCCESS);
502 ret_code=
procs_opt(procs_ctx,
"PROCS_ID_PUT", proc_id,
503 "proc_name=bypass_processor2");
504 CHECK(ret_code== STAT_SUCCESS);
507 ret_code=
procs_opt(procs_ctx,
"PROCS_ID_GET", proc_id, &rest_str);
508 CHECK_DO(ret_code== STAT_SUCCESS && rest_str!= NULL,
509 CHECK(
false);
goto end);
511 cjson_rest= cJSON_Parse(rest_str);
512 CHECK_DO(cjson_rest!= NULL, CHECK(
false);
goto end);
513 cjson_aux= cJSON_GetObjectItem(cjson_rest,
"settings");
514 CHECK_DO(cjson_aux!= NULL, CHECK(
false);
goto end);
515 cjson_aux= cJSON_GetObjectItem(cjson_aux,
"setting1");
516 CHECK_DO(cjson_aux!= NULL, CHECK(
false);
goto end);
517 CHECK(cjson_aux->valuedouble== 200);
518 free(rest_str); rest_str= NULL;
519 cJSON_Delete(cjson_rest); cjson_rest= NULL;
521 ret_code=
procs_opt(procs_ctx,
"PROCS_ID_DELETE", proc_id);
522 CHECK(ret_code== STAT_SUCCESS);
525 CHECK(ret_code== STAT_SUCCESS);
534 if(cjson_rest!= NULL)
535 cJSON_Delete(cjson_rest);
538 TEST(SEND_RECV_PROCS)
541 int frame_idx, i, x, y, ret_code, proc_id= -1;
543 char *rest_str= NULL;
544 cJSON *cjson_rest= NULL, *cjson_aux= NULL;
546 "bypass_processor",
"encoder",
"application/octet-stream",
547 (uint64_t)(PROC_FEATURE_BITRATE|PROC_FEATURE_REGISTER_PTS|
548 PROC_FEATURE_LATENCY),
551 proc_send_frame_default1,
553 proc_recv_frame_default1,
555 bypass_proc_rest_put,
556 bypass_proc_rest_get,
557 bypass_proc_process_frame,
564 uint8_t yuv_frame[48]= {
565 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
566 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
567 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
568 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
569 0x00, 0x01, 0x02, 0x03,
570 0x04, 0x05, 0x06, 0x07,
571 0x00, 0x01, 0x02, 0x03,
572 0x04, 0x05, 0x06, 0x07
580 proc_frame_ctx_yuv.
data= yuv_frame;
581 proc_frame_ctx_yuv.
p_data[0]= &yuv_frame[0];
582 proc_frame_ctx_yuv.
p_data[1]= &yuv_frame[32];
583 proc_frame_ctx_yuv.
p_data[2]= &yuv_frame[40];
584 proc_frame_ctx_yuv.
linesize[0]= proc_frame_ctx_yuv.
width[0]= 8;
585 proc_frame_ctx_yuv.
linesize[1]= proc_frame_ctx_yuv.
width[1]= 4;
586 proc_frame_ctx_yuv.
linesize[2]= proc_frame_ctx_yuv.
width[2]= 4;
587 proc_frame_ctx_yuv.
height[0]= 4;
588 proc_frame_ctx_yuv.
height[1]= proc_frame_ctx_yuv.
height[2]= 2;
590 proc_frame_ctx_yuv.
pts= -1;
591 proc_frame_ctx_yuv.
dts= -1;
594 CHECK(ret_code== STAT_SUCCESS);
597 CHECK(ret_code== STAT_SUCCESS);
601 CHECK_DO(procs_ctx!= NULL, CHECK(
false);
goto end);
603 ret_code=
procs_opt(procs_ctx,
"PROCS_POST",
"bypass_processor",
604 "setting1=100", &rest_str);
605 CHECK_DO(ret_code== STAT_SUCCESS && rest_str!= NULL,
606 CHECK(
false);
goto end);
608 cjson_rest= cJSON_Parse(rest_str);
609 CHECK_DO(cjson_rest!= NULL, CHECK(
false);
goto end);
610 cjson_aux= cJSON_GetObjectItem(cjson_rest,
"proc_id");
611 CHECK_DO(cjson_aux!= NULL, CHECK(
false);
goto end);
612 CHECK((proc_id= cjson_aux->valuedouble)>= 0);
617 for(frame_idx= 0; frame_idx< FIFO_SIZE; frame_idx++) {
619 CHECK(ret_code== STAT_SUCCESS);
625 for(frame_idx= 0; frame_idx< FIFO_SIZE; frame_idx++) {
626 if(proc_frame_ctx!= NULL)
629 CHECK(ret_code== STAT_SUCCESS);
630 CHECK(proc_frame_ctx!= NULL);
631 if(proc_frame_ctx== NULL)
635 CHECK(proc_frame_ctx->
pts== -1);
636 CHECK(proc_frame_ctx->
dts== -1);
637 for(i= 0; i< 3; i++) {
638 for(y= 0; y< (int)proc_frame_ctx->
height[i]; y++) {
639 for(x= 0; x< (int)proc_frame_ctx->
width[i]; x++) {
640 int data_coord= x+ y* proc_frame_ctx->
linesize[i];
641 uint8_t data_val= proc_frame_ctx->
p_data[i][data_coord];
642 int expected_val= x+ y* proc_frame_ctx_yuv.
width[i];
643 CHECK(data_val== expected_val);
663 if(cjson_rest!= NULL)
664 cJSON_Delete(cjson_rest);
int fifo_get(fifo_ctx_t *fifo_ctx, void **ref_elem, size_t *ref_elem_size)
#define CJSON_PRINT(CJSON_PTR)
size_t width[PROC_FRAME_NUM_DATA_POINTERS]
void proc_frame_ctx_release(proc_frame_ctx_t **ref_proc_frame_ctx)
int linesize[PROC_FRAME_NUM_DATA_POINTERS]
int fifo_put_dup(fifo_ctx_t *fifo_ctx, const void *elem, size_t elem_size)
SUITE(UTESTS_LIVE555_RTSP)
int procs_opt(procs_ctx_t *procs_ctx, const char *tag,...)
int procs_module_open(log_ctx_t *log_ctx)
int procs_module_opt(const char *tag,...)
void proc_if_release(proc_if_t **ref_proc_if)
int procs_recv_frame(procs_ctx_t *procs_ctx, int proc_id, proc_frame_ctx_t **ref_proc_frame_ctx)
void procs_module_close()
#define CHECK_DO(COND, ACTION)
Character string response.
int procs_send_frame(procs_ctx_t *procs_ctx, int proc_id, const proc_frame_ctx_t *proc_frame_ctx)
enum proc_if_rest_fmt_enum proc_if_rest_fmt_t
fifo_ctx_t * fifo_ctx_array[PROC_IO_NUM]
int proc_if_cmp(const proc_if_t *proc_if1, const proc_if_t *proc_if2)
proc_frame_ctx_t * proc_frame_ctx_dup(const proc_frame_ctx_t *proc_frame_ctx_arg)
size_t height[PROC_FRAME_NUM_DATA_POINTERS]
void procs_close(procs_ctx_t **ref_procs_ctx)
const uint8_t * p_data[PROC_FRAME_NUM_DATA_POINTERS]
procs_ctx_t * procs_open(log_ctx_t *log_ctx, size_t max_procs_num, const char *prefix_name, const char *procs_href)