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_com.h>
12 #include <VP_Stages/vp_stages_io_file.h>
13 #include <VP_Os/vp_os_print.h>
14 #include <VP_Os/vp_os_malloc.h>
15 #include <VP_Os/vp_os_delay.h>
17 #include <MJPEG/mjpeg.h>
18 #include <MJPEG/dct.h>
20 #define ACQ_WIDTH (320)
21 #define ACQ_HEIGHT (240)
26 PIPELINE_HANDLE pipeline_handle;
28 PROTO_THREAD_ROUTINE(escaper, nomParams);
29 PROTO_THREAD_ROUTINE(app, nomParams);
32 THREAD_TABLE_ENTRY(escaper, 20)
33 THREAD_TABLE_ENTRY(app, 20)
37 ///*******************************************************************************************************************///
39 typedef struct _buffer_to_picture_config_t
41 vp_api_picture_t* picture;
43 } buffer_to_picture_config_t;
46 buffer_to_picture_open(buffer_to_picture_config_t *cfg)
48 cfg->picture->format = PIX_FMT_YUV420P;
50 cfg->picture->width = ACQ_WIDTH;
51 cfg->picture->height = ACQ_HEIGHT;
52 cfg->picture->framerate = 15;
54 cfg->picture->y_line_size = ACQ_WIDTH;
55 cfg->picture->cb_line_size = ACQ_WIDTH / 2;
56 cfg->picture->cr_line_size = ACQ_WIDTH / 2;
58 cfg->picture->y_pad = 0;
59 cfg->picture->c_pad = 0;
65 buffer_to_picture_transform(buffer_to_picture_config_t *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
67 vp_os_mutex_lock(&out->lock);
70 if(out->status == VP_API_STATUS_INIT)
73 out->size = (ACQ_WIDTH*ACQ_HEIGHT*3)/2;
74 out->buffers = (int8_t **) cfg->picture;
76 out->status = VP_API_STATUS_PROCESSING;
79 if(out->status == VP_API_STATUS_ENDED)
83 if(out->status == VP_API_STATUS_PROCESSING)
85 cfg->picture->y_buf = in->buffers[0];
86 cfg->picture->cb_buf = in->buffers[0] + ACQ_WIDTH*ACQ_HEIGHT;
87 cfg->picture->cr_buf = in->buffers[0] + ACQ_WIDTH*ACQ_HEIGHT + ACQ_WIDTH*ACQ_HEIGHT/4;
90 out->status = in->status;
92 vp_os_mutex_unlock(&out->lock);
98 buffer_to_picture_close(buffer_to_picture_config_t *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
113 main(int argc, char **argv)
117 PRINT("You must specify a filename.\n");
121 START_THREAD(escaper, NO_PARAM);
122 START_THREAD(app, argv);
124 JOIN_THREAD(escaper);
131 PROTO_THREAD_ROUTINE(app,argv)
133 vp_api_picture_t picture;
135 vp_api_io_pipeline_t pipeline;
136 vp_api_io_data_t out;
137 vp_api_io_stage_t stages[NB_STAGES];
139 vp_stages_input_file_config_t ifc;
140 vp_stages_output_sdl_config_t osc;
141 buffer_to_picture_config_t bpc;
143 vp_os_memset(&ifc,0,sizeof(vp_stages_input_file_config_t));
145 ifc.name = ((char**)argv)[1];
146 ifc.buffer_size = (ACQ_WIDTH*ACQ_HEIGHT*3)/2;
148 osc.width = ACQ_WIDTH;
149 osc.height = ACQ_HEIGHT;
151 osc.window_width = ACQ_WIDTH;
152 osc.window_height = ACQ_HEIGHT;
153 osc.pic_width = ACQ_WIDTH;
154 osc.pic_height = ACQ_HEIGHT;
155 osc.y_size = ACQ_WIDTH*ACQ_HEIGHT;
156 osc.c_size = (ACQ_WIDTH*ACQ_HEIGHT) >> 2;
158 bpc.picture = &picture;
160 stages[0].type = VP_API_INPUT_FILE;
161 stages[0].cfg = (void *)&ifc;
162 stages[0].funcs = vp_stages_input_file_funcs;
164 stages[1].type = VP_API_FILTER_DECODER;
165 stages[1].cfg = (void *)&bpc;
166 stages[1].funcs = buffer_to_picture_funcs;
168 stages[2].type = VP_API_OUTPUT_SDL;
169 stages[2].cfg = (void *)&osc;
170 stages[2].funcs = vp_stages_output_sdl_funcs;
172 pipeline.nb_stages = NB_STAGES;
173 pipeline.stages = &stages[0];
175 vp_api_open(&pipeline, &pipeline_handle);
176 out.status = VP_API_STATUS_PROCESSING;
177 while(SUCCEED(vp_api_run(&pipeline, &out)) && (out.status == VP_API_STATUS_PROCESSING || out.status == VP_API_STATUS_STILL_RUNNING))
182 vp_api_close(&pipeline, &pipeline_handle);