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 vp_stages_output_com_config_t occ;
38 static PIPELINE_HANDLE pipeline_handle;
40 static vp_api_picture_t picture;
44 buffer_to_picture_open(int *cfg)
46 picture.format = PIX_FMT_YUV420P;
48 picture.width = ACQ_WIDTH;
49 picture.height = ACQ_HEIGHT;
50 picture.framerate = 15;
52 picture.y_line_size = ACQ_WIDTH;
53 picture.cb_line_size = ACQ_WIDTH/2;
54 picture.cr_line_size = ACQ_WIDTH/2;
60 buffer_to_picture_transform(int *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
62 static int32_t blockline;
64 vp_os_mutex_lock(&out->lock);
66 if(out->status == VP_API_STATUS_INIT)
70 out->size = ACQ_WIDTH*ACQ_HEIGHT*3/2;
71 out->buffers = (int8_t **)(int8_t *)&picture;
73 out->status = VP_API_STATUS_PROCESSING;
76 out->status = in->status;
78 if(out->status == VP_API_STATUS_ENDED)
82 if(out->status == VP_API_STATUS_PROCESSING)
84 picture.y_buf = (uint8_t*)in->buffers[0];
85 picture.cb_buf = (uint8_t*)in->buffers[0] + ACQ_WIDTH*ACQ_HEIGHT;
86 picture.cr_buf = (uint8_t*)in->buffers[0] + ACQ_WIDTH*ACQ_HEIGHT*5/4;
90 out->status = in->status;
92 vp_os_mutex_unlock(&out->lock);
98 buffer_to_picture_close(int *cfg)
103 const vp_api_stage_funcs_t buffer_to_picture_funcs =
106 (vp_api_stage_open_t)buffer_to_picture_open,
107 (vp_api_stage_transform_t)buffer_to_picture_transform,
108 (vp_api_stage_close_t)buffer_to_picture_close
112 vp_com_t* wired_com(void)
114 static vp_com_t com = {
138 vp_com_config_t* wired_config(void)
140 static vp_com_wired_config_t config = {
147 return (vp_com_config_t*) &config;
150 vp_com_connection_t* wired_connection(void)
152 static vp_com_wired_connection_t connection = {
156 return (vp_com_connection_t*) (void*) &connection;
160 int main(int argc, char **argv)
162 START_THREAD(app, argv);
169 PROTO_THREAD_ROUTINE(app,argv)
171 vp_api_io_pipeline_t pipeline;
172 vp_api_io_data_t out;
173 vp_api_io_stage_t stages[NB_STAGES_MAX];
175 uint16_t time1,time2;
180 vp_os_memset(&ivc,0,sizeof(ivc));
181 //vp_os_memset(&vec,0,sizeof(vec));
182 vp_os_memset(&occ,0,sizeof(occ));
184 ivc.device = "/tmp/video0";
185 ivc.width = ACQ_WIDTH;
186 ivc.height = ACQ_HEIGHT;
187 ivc.vp_api_picture = &picture;
189 /* vec.width = ACQ_WIDTH; */
190 /* vec.height = ACQ_HEIGHT; */
191 /* vec.block_mode_enable = FALSE; */
192 /* vec.picture = &picture; */
194 occ.com = COM_VIDEO();
195 occ.config = COM_CONFIG_VIDEO();
196 occ.connection = COM_CONNECTION_VIDEO();
197 occ.socket.type = VP_COM_SERVER;
198 occ.socket.protocol = VP_COM_TCP;
199 occ.socket.port = 5555;
200 occ.buffer_size = 320*240*3/2;
202 pipeline.nb_stages = 0;
204 stages[pipeline.nb_stages].type = VP_API_INPUT_FILE;
205 stages[pipeline.nb_stages].cfg = (void *)&ivc;
206 stages[pipeline.nb_stages++].funcs = vp_stages_input_v4l_funcs;
208 /* stages[pipeline.nb_stages].type = VP_API_FILTER_ENCODER; */
209 /* stages[pipeline.nb_stages].cfg = (void *)NULL; */
210 /* stages[pipeline.nb_stages++].funcs = buffer_to_picture_funcs; */
212 /* stages[pipeline.nb_stages].type = VP_API_FILTER_ENCODER; */
213 /* stages[pipeline.nb_stages].cfg = (void*)&vec; */
214 /* stages[pipeline.nb_stages++].funcs = vlib_encoding_funcs; */
216 stages[pipeline.nb_stages].type = VP_API_OUTPUT_SOCKET;
217 stages[pipeline.nb_stages].cfg = (void *)&occ;
218 stages[pipeline.nb_stages++].funcs = vp_stages_output_com_funcs;
220 pipeline.stages = &stages[0];
222 vp_api_open(&pipeline, &pipeline_handle);
224 out.status = VP_API_STATUS_PROCESSING;
226 /////////////////////////////////////////////////////////////////////////////////////////
228 while(SUCCEED(vp_api_run(&pipeline, &out)) && (out.status == VP_API_STATUS_PROCESSING))
231 PRINT("image %d \n",i);
234 /////////////////////////////////////////////////////////////////////////////////////////
237 printf("temps ecoule : %d \n",time2-time1);
239 vp_api_close(&pipeline, &pipeline_handle);