4 #include <VP_Api/vp_api.h>
5 #include <VP_Api/vp_api_thread_helper.h>
6 #include <VP_Api/vp_api_error.h>
7 #include <VP_Api/vp_api_picture.h>
8 #include <VP_Stages/vp_stages_configs.h>
9 #include <VP_Stages/vp_stages_io_console.h>
10 #include <VP_Stages/vp_stages_o_sdl.h>
11 #include <VP_Stages/vp_stages_io_file.h>
12 #include <VP_Os/vp_os_print.h>
13 #include <VP_Os/vp_os_malloc.h>
14 #include <VP_Os/vp_os_delay.h>
16 #include <MJPEG/mjpeg.h>
17 #include <MJPEG/dct.h>
19 #define ACQ_WIDTH (176*2)
20 #define ACQ_HEIGHT (144*2)
25 PIPELINE_HANDLE pipeline_handle;
27 PROTO_THREAD_ROUTINE(escaper, nomParams);
28 PROTO_THREAD_ROUTINE(app, nomParams);
31 THREAD_TABLE_ENTRY(escaper, 20)
32 THREAD_TABLE_ENTRY(app, 20)
36 ///*******************************************************************************************************************///
38 typedef struct _buffer_to_picture_config_t
40 vp_api_picture_t* picture;
42 } buffer_to_picture_config_t;
45 buffer_to_picture_open(buffer_to_picture_config_t *cfg)
47 cfg->picture->format = PIX_FMT_YUV420P;
49 cfg->picture->width = ACQ_WIDTH;
50 cfg->picture->height = ACQ_HEIGHT;
51 cfg->picture->framerate = 15;
53 cfg->picture->y_line_size = ACQ_WIDTH;
54 cfg->picture->cb_line_size = ACQ_WIDTH / 2;
55 cfg->picture->cr_line_size = ACQ_WIDTH / 2;
57 cfg->picture->y_pad = 0;
58 cfg->picture->c_pad = 0;
64 buffer_to_picture_transform(buffer_to_picture_config_t *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
66 vp_os_mutex_lock(&out->lock);
69 if(out->status == VP_API_STATUS_INIT)
72 out->size = (ACQ_WIDTH*ACQ_HEIGHT*3)/2;
73 out->buffers = (int8_t **) cfg->picture;
75 out->status = VP_API_STATUS_PROCESSING;
78 if(out->status == VP_API_STATUS_ENDED)
82 if(out->status == VP_API_STATUS_PROCESSING)
84 cfg->picture->y_buf = in->buffers[0];
85 cfg->picture->cb_buf = in->buffers[0] + ACQ_WIDTH*ACQ_HEIGHT;
86 cfg->picture->cr_buf = in->buffers[0] + ACQ_WIDTH*ACQ_HEIGHT + ACQ_WIDTH*ACQ_HEIGHT/4;
89 out->status = in->status;
91 vp_os_mutex_unlock(&out->lock);
97 buffer_to_picture_close(buffer_to_picture_config_t *cfg)
102 const vp_api_stage_funcs_t buffer_to_picture_funcs =
105 (vp_api_stage_open_t)buffer_to_picture_open,
106 (vp_api_stage_transform_t)buffer_to_picture_transform,
107 (vp_api_stage_close_t)buffer_to_picture_close
112 main(int argc, char **argv)
116 PRINT("You must specify a filename.\n");
120 START_THREAD(escaper, NO_PARAM);
121 START_THREAD(app, argv);
123 JOIN_THREAD(escaper);
130 PROTO_THREAD_ROUTINE(app,argv)
132 vp_api_picture_t picture;
134 vp_api_io_pipeline_t pipeline;
135 vp_api_io_data_t out;
136 vp_api_io_stage_t stages[NB_STAGES];
138 vp_stages_input_file_config_t ifc;
139 vp_stages_output_sdl_config_t osc;
140 buffer_to_picture_config_t bpc;
142 vp_os_memset(&ifc,0,sizeof(vp_stages_input_file_config_t));
144 ifc.name = ((char**)argv)[1];
145 ifc.buffer_size = (ACQ_WIDTH*ACQ_HEIGHT*3)/2;
147 osc.width = ACQ_WIDTH;
148 osc.height = ACQ_HEIGHT;
150 osc.window_width = ACQ_WIDTH;
151 osc.window_height = ACQ_HEIGHT;
152 osc.pic_width = ACQ_WIDTH;
153 osc.pic_height = ACQ_HEIGHT;
154 osc.y_size = ACQ_WIDTH*ACQ_HEIGHT;
155 osc.c_size = (ACQ_WIDTH*ACQ_HEIGHT) >> 2;
157 bpc.picture = &picture;
159 stages[0].type = VP_API_INPUT_FILE;
160 stages[0].cfg = (void *)&ifc;
161 stages[0].funcs = vp_stages_input_file_funcs;
163 stages[1].type = VP_API_FILTER_DECODER;
164 stages[1].cfg = (void *)&bpc;
165 stages[1].funcs = buffer_to_picture_funcs;
167 stages[2].type = VP_API_OUTPUT_SDL;
168 stages[2].cfg = (void *)&osc;
169 stages[2].funcs = vp_stages_output_sdl_funcs;
171 pipeline.nb_stages = NB_STAGES;
172 pipeline.stages = &stages[0];
174 vp_api_open(&pipeline, &pipeline_handle);
175 out.status = VP_API_STATUS_PROCESSING;
176 while(SUCCEED(vp_api_run(&pipeline, &out)) && (out.status == VP_API_STATUS_PROCESSING || out.status == VP_API_STATUS_STILL_RUNNING))
181 vp_api_close(&pipeline, &pipeline_handle);