1 #include <VP_Api/vp_api.h>
2 #include <VP_Api/vp_api_error.h>
3 #include <VP_Stages/vp_stages_configs.h>
4 #include <VP_Stages/vp_stages_i_v4l.h>
5 #include <VP_Stages/vp_stages_io_com.h>
6 #include <VP_Os/vp_os_print.h>
7 #include <VP_Os/vp_os_malloc.h>
8 #include <VP_Os/vp_os_delay.h>
9 #include <VP_Api/vp_api_thread_helper.h>
10 #include <VLIB/Stages/vlib_stage_encode.h>
18 #define ACQ_HEIGHT 240
20 #define COM_VIDEO() wired_com()
21 #define COM_CONFIG_VIDEO() wired_config()
22 #define COM_CONNECTION_VIDEO() wired_connection()
25 PROTO_THREAD_ROUTINE(app,nomParams);
28 THREAD_TABLE_ENTRY(app,20)
32 #define NB_STAGES_MAX 10
35 static vp_stages_input_v4l_config_t ivc;
36 static vlib_stage_encoding_config_t vec;
37 static vp_stages_output_com_config_t occ;
39 static PIPELINE_HANDLE pipeline_handle;
41 static vp_api_picture_t picture;
45 buffer_to_picture_open(int *cfg)
47 picture.format = PIX_FMT_YUV420P;
49 picture.width = ACQ_WIDTH;
50 picture.height = ACQ_HEIGHT;
51 picture.framerate = 15;
53 picture.y_line_size = ACQ_WIDTH;
54 picture.cb_line_size = ACQ_WIDTH/2;
55 picture.cr_line_size = ACQ_WIDTH/2;
61 buffer_to_picture_transform(int *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
63 static int32_t blockline;
65 vp_os_mutex_lock(&out->lock);
67 if(out->status == VP_API_STATUS_INIT)
71 out->size = ACQ_WIDTH*ACQ_HEIGHT*3/2;
72 out->buffers = (int8_t **)(int8_t *)&picture;
74 out->status = VP_API_STATUS_PROCESSING;
77 out->status = in->status;
79 if(out->status == VP_API_STATUS_ENDED)
83 if(out->status == VP_API_STATUS_PROCESSING)
85 picture.y_buf = (uint8_t*)in->buffers[0];
86 picture.cb_buf = (uint8_t*)in->buffers[0] + ACQ_WIDTH*ACQ_HEIGHT;
87 picture.cr_buf = (uint8_t*)in->buffers[0] + ACQ_WIDTH*ACQ_HEIGHT*5/4;
91 out->status = in->status;
93 vp_os_mutex_unlock(&out->lock);
99 buffer_to_picture_close(int *cfg)
104 const vp_api_stage_funcs_t buffer_to_picture_funcs =
107 (vp_api_stage_open_t)buffer_to_picture_open,
108 (vp_api_stage_transform_t)buffer_to_picture_transform,
109 (vp_api_stage_close_t)buffer_to_picture_close
113 vp_com_t* wired_com(void)
115 static vp_com_t com = {
139 vp_com_config_t* wired_config(void)
141 static vp_com_wired_config_t config = {
148 return (vp_com_config_t*) &config;
151 vp_com_connection_t* wired_connection(void)
153 static vp_com_wired_connection_t connection = {
157 return (vp_com_connection_t*) (void*) &connection;
161 int main(int argc, char **argv)
163 START_THREAD(app, argv);
170 PROTO_THREAD_ROUTINE(app,argv)
172 vp_api_io_pipeline_t pipeline;
173 vp_api_io_data_t out;
174 vp_api_io_stage_t stages[NB_STAGES_MAX];
176 uint16_t time1,time2;
181 vp_os_memset(&ivc,0,sizeof(ivc));
182 vp_os_memset(&vec,0,sizeof(vec));
183 vp_os_memset(&occ,0,sizeof(occ));
185 ivc.device = "/tmp/video0";
186 ivc.width = ACQ_WIDTH;
187 ivc.height = ACQ_HEIGHT;
188 ivc.vp_api_picture = &picture;
190 vec.width = ACQ_WIDTH;
191 vec.height = ACQ_HEIGHT;
192 vec.block_mode_enable = FALSE;
193 vec.picture = &picture;
195 occ.com = COM_VIDEO();
196 occ.config = COM_CONFIG_VIDEO();
197 occ.connection = COM_CONNECTION_VIDEO();
198 occ.socket.type = VP_COM_SERVER;
199 occ.socket.protocol = VP_COM_TCP;
200 occ.socket.port = 5555;
201 occ.buffer_size = 1500;
203 pipeline.nb_stages = 0;
205 stages[pipeline.nb_stages].type = VP_API_INPUT_FILE;
206 stages[pipeline.nb_stages].cfg = (void *)&ivc;
207 stages[pipeline.nb_stages++].funcs = vp_stages_input_v4l_funcs;
209 stages[pipeline.nb_stages].type = VP_API_FILTER_ENCODER;
210 stages[pipeline.nb_stages].cfg = (void *)NULL;
211 stages[pipeline.nb_stages++].funcs = buffer_to_picture_funcs;
213 stages[pipeline.nb_stages].type = VP_API_FILTER_ENCODER;
214 stages[pipeline.nb_stages].cfg = (void*)&vec;
215 stages[pipeline.nb_stages++].funcs = vlib_encoding_funcs;
217 stages[pipeline.nb_stages].type = VP_API_OUTPUT_SOCKET;
218 stages[pipeline.nb_stages].cfg = (void *)&occ;
219 stages[pipeline.nb_stages++].funcs = vp_stages_output_com_funcs;
221 pipeline.stages = &stages[0];
223 vp_api_open(&pipeline, &pipeline_handle);
225 out.status = VP_API_STATUS_PROCESSING;
227 /////////////////////////////////////////////////////////////////////////////////////////
229 while(SUCCEED(vp_api_run(&pipeline, &out)) && (out.status == VP_API_STATUS_PROCESSING))
232 PRINT("image %d \n",i);
235 /////////////////////////////////////////////////////////////////////////////////////////
238 printf("temps ecoule : %d \n",time2-time1);
240 vp_api_close(&pipeline, &pipeline_handle);