MediaProcessors
utests_proc_if.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, 2018 Rafael Antoniello
3  *
4  * This file is part of MediaProcessors.
5  *
6  * MediaProcessors is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * MediaProcessors is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with MediaProcessors. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 #include <UnitTest++/UnitTest++.h>
27 
28 extern "C" {
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <unistd.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <string.h>
35 
36 #include <libmediaprocsutils/log.h>
37 #include <libmediaprocsutils/stat_codes.h>
38 #include <libmediaprocs/proc_if.h>
39 #include <libmediaprocs/proc.h>
40 }
41 
42 /* **** Define dummy callback's for the interface **** */
43 
44 static proc_ctx_t* dummy_proc_open(const proc_if_t*, const char *settings_str,
45  log_ctx_t *log_ctx, va_list arg)
46 {
47  return NULL;
48 }
49 
50 static void dummy_proc_close(proc_ctx_t**)
51 {
52 }
53 
54 static int dummy_proc_rest_put(proc_ctx_t*, const char *str)
55 {
56  return STAT_SUCCESS;
57 }
58 
59 static int dummy_proc_rest_get(proc_ctx_t*, const proc_if_rest_fmt_t rest_fmt,
60  void **ref_reponse)
61 {
62  return STAT_SUCCESS;
63 }
64 
65 static int dummy_proc_process_frame(proc_ctx_t*, fifo_ctx_t* i, fifo_ctx_t* o)
66 {
67  return STAT_SUCCESS;
68 }
69 
70 static int dummy_proc_opt(proc_ctx_t*, const char *tag, va_list arg)
71 {
72  return STAT_SUCCESS;
73 }
74 
75 static void* dummy_proc_iput_fifo_elem_dup(const proc_frame_ctx_t*)
76 {
77  return NULL;
78 }
79 
80 static void dummy_proc_iput_fifo_elem_release(void**)
81 {
82 }
83 
84 static proc_frame_ctx_t* dummy_proc_oput_fifo_elem_dup(const void*)
85 {
86  return NULL;
87 }
88 
89 SUITE(UTESTS_PROC_IF)
90 {
91  TEST(ALLOCATE_DUP_RELEASE_PROC_IF_T)
92  {
93  proc_if_t *proc_if= NULL;
94  const proc_if_t proc_if_dummy_proc= {
95  "dummy_processor", "encoder", "application/octet-stream",
96  (uint64_t)(PROC_FEATURE_BITRATE|PROC_FEATURE_REGISTER_PTS|
97  PROC_FEATURE_LATENCY),
98  dummy_proc_open,
99  dummy_proc_close,
100  proc_send_frame_default1,
101  NULL, // no 'send-no-dup'
102  proc_recv_frame_default1,
103  NULL, // no specific unblock function extension
104  dummy_proc_rest_put,
105  dummy_proc_rest_get,
106  dummy_proc_process_frame,
107  dummy_proc_opt,
108  dummy_proc_iput_fifo_elem_dup,
109  dummy_proc_iput_fifo_elem_release,
110  dummy_proc_oput_fifo_elem_dup
111  };
112 
113  /* Duplicate 'dummy' processor interface context structure
114  * (Internally allocates processor interface context structure using
115  * 'proc_if_allocate()').
116  */
117  proc_if= proc_if_dup(&proc_if_dummy_proc);
118  CHECK(proc_if!= NULL);
119  if(proc_if== NULL)
120  return;
121 
122  /* Check duplication */
123  CHECK(proc_if_cmp(&proc_if_dummy_proc, proc_if)== 0);
124 
125  /* Release processor interface */
126  proc_if_release(&proc_if);
127  }
128 
129  TEST(ALLOCATE_DUP_RELEASE_PROC_FRAME_CTX)
130  {
131  int i, x, y;
132  proc_frame_ctx_t *proc_frame_ctx= NULL;
133  uint8_t yuv_frame[48]= { // YUV4:2:0 simple data example
134  0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // Y
135  0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, // Y
136  0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, // Y
137  0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, // Y
138  0x00, 0x01, 0x02, 0x03, // U
139  0x04, 0x05, 0x06, 0x07, // U
140  0x00, 0x01, 0x02, 0x03, // V
141  0x04, 0x05, 0x06, 0x07 // V
142  };
143  proc_frame_ctx_t proc_frame_ctx_yuv= {0};
144 
145  /* Initialize YUV frame structure */
146  proc_frame_ctx_yuv.data= yuv_frame;
147  proc_frame_ctx_yuv.p_data[0]= &yuv_frame[0]; // Y
148  proc_frame_ctx_yuv.p_data[1]= &yuv_frame[32]; // U
149  proc_frame_ctx_yuv.p_data[2]= &yuv_frame[40]; // V
150  proc_frame_ctx_yuv.linesize[0]= proc_frame_ctx_yuv.width[0]= 8;
151  proc_frame_ctx_yuv.linesize[1]= proc_frame_ctx_yuv.width[1]= 4;
152  proc_frame_ctx_yuv.linesize[2]= proc_frame_ctx_yuv.width[2]= 4;
153  proc_frame_ctx_yuv.height[0]= 4;
154  proc_frame_ctx_yuv.height[1]= proc_frame_ctx_yuv.height[2]= 2;
155  proc_frame_ctx_yuv.proc_sample_fmt= PROC_IF_FMT_UNDEF;
156  proc_frame_ctx_yuv.proc_sampling_rate= -1;
157  proc_frame_ctx_yuv.pts= -1;
158  proc_frame_ctx_yuv.dts= -1;
159  proc_frame_ctx_yuv.es_id= -1;
160 
161  /* Duplicate 'YUV' frame context structure
162  * (Internally allocates frame context structure using
163  * 'proc_frame_ctx_allocate()').
164  */
165  proc_frame_ctx= proc_frame_ctx_dup(&proc_frame_ctx_yuv);
166  CHECK(proc_frame_ctx!= NULL);
167  if(proc_frame_ctx== NULL)
168  return;
169 
170  CHECK(proc_frame_ctx->proc_sample_fmt== PROC_IF_FMT_UNDEF);
171  CHECK(proc_frame_ctx->proc_sampling_rate== -1);
172  CHECK(proc_frame_ctx->pts== -1);
173  CHECK(proc_frame_ctx->dts== -1);
174  CHECK(proc_frame_ctx->es_id== -1);
175  for(i= 0; i< 3/*Num. of data planes*/; i++) {
176  for(y= 0; y< (int)proc_frame_ctx->height[i]; y++) {
177  for(x= 0; x< (int)proc_frame_ctx->width[i]; x++) {
178  int data_coord= x+ y* proc_frame_ctx->linesize[i];
179  int expected_val= x+ y* proc_frame_ctx_yuv.width[i];
180  CHECK(proc_frame_ctx->p_data[i][data_coord]== expected_val);
181  //printf("0x%02x ", proc_frame_ctx->data
182  // [i][data_coord]); // comment-me
183  }
184  //printf("\n"); // comment-me
185  }
186  }
187 
188  /* Release frame structure */
189  proc_frame_ctx_release(&proc_frame_ctx);
190  }
191 }
size_t width[PROC_FRAME_NUM_DATA_POINTERS]
Definition: proc_if.h:113
void proc_frame_ctx_release(proc_frame_ctx_t **ref_proc_frame_ctx)
Definition: proc_if.c:125
int proc_sampling_rate
Definition: proc_if.h:134
int linesize[PROC_FRAME_NUM_DATA_POINTERS]
Definition: proc_if.h:107
SUITE(UTESTS_LIVE555_RTSP)
int proc_sample_fmt
Definition: proc_if.h:127
int64_t dts
Definition: proc_if.h:144
void proc_if_release(proc_if_t **ref_proc_if)
Definition: proc_if.c:232
proc_if_t * proc_if_dup(const proc_if_t *proc_if_arg)
Definition: proc_if.c:147
enum proc_if_rest_fmt_enum proc_if_rest_fmt_t
int proc_if_cmp(const proc_if_t *proc_if1, const proc_if_t *proc_if2)
Definition: proc_if.c:187
Undefined format.
Definition: proc_if.h:54
proc_frame_ctx_t * proc_frame_ctx_dup(const proc_frame_ctx_t *proc_frame_ctx_arg)
Definition: proc_if.c:52
size_t height[PROC_FRAME_NUM_DATA_POINTERS]
Definition: proc_if.h:119
Definition: log.c:102
const uint8_t * p_data[PROC_FRAME_NUM_DATA_POINTERS]
Definition: proc_if.h:94
uint8_t * data
Definition: proc_if.h:84
int64_t pts
Definition: proc_if.h:138