hardware/intel/libva
修订版 | e272a93ebccb44b8b78b238e617137708f08c94d (tree) |
---|---|
时间 | 2010-03-04 18:54:20 |
作者 | Austin Yuan <shengquan.yuan@inte...> |
Commiter | Austin Yuan |
Fix test/./h264encode.c issue
Signed-off-by: Austin Yuan <shengquan.yuan@intel.com>
@@ -212,10 +212,11 @@ static int do_h264_encoding(void) | ||
212 | 212 | VAEncPictureParameterBufferH264 pic_h264; |
213 | 213 | VAEncSliceParameterBuffer slice_h264; |
214 | 214 | VAStatus va_status; |
215 | - VABufferID coded_buf, seq_param_buf, pic_param_buf, slice_param_buf; | |
215 | + VABufferID seq_param_buf, pic_param_buf, slice_param_buf; | |
216 | 216 | int codedbuf_size; |
217 | 217 | VASurfaceStatus surface_status; |
218 | 218 | int src_surface, dst_surface, ref_surface; |
219 | + int codedbuf_idx = 0; | |
219 | 220 | int frame_skipped = 0; |
220 | 221 | int i; |
221 | 222 |
@@ -229,12 +230,24 @@ static int do_h264_encoding(void) | ||
229 | 230 | |
230 | 231 | codedbuf_size = (frame_width * frame_height * 400) / (16*16); |
231 | 232 | |
233 | + for (i = 0; i < CODEDBUF_NUM; i++) { | |
234 | + /* create coded buffer once for all | |
235 | + * other VA buffers which won't be used again after vaRenderPicture. | |
236 | + * so APP can always vaCreateBuffer for every frame | |
237 | + * but coded buffer need to be mapped and accessed after vaRenderPicture/vaEndPicture | |
238 | + * so VA won't maintain the coded buffer | |
239 | + */ | |
240 | + va_status = vaCreateBuffer(va_dpy,context_id,VAEncCodedBufferType, | |
241 | + codedbuf_size, 1, NULL, &coded_buf[i]); | |
242 | + CHECK_VASTATUS(va_status,"vaBeginPicture"); | |
243 | + } | |
244 | + | |
232 | 245 | src_surface = 0; |
233 | 246 | /* the last two frames are reference/reconstructed frame */ |
234 | 247 | dst_surface = SURFACE_NUM - 1; |
235 | 248 | ref_surface = SURFACE_NUM - 2; |
236 | 249 | |
237 | - for (i=0; i < frame_count; i++) { | |
250 | + for (i=0; i < (frame_count - 2); i++) { | |
238 | 251 | va_status = vaBeginPicture(va_dpy, context_id, surface_id[src_surface]); |
239 | 252 | CHECK_VASTATUS(va_status,"vaBeginPicture"); |
240 | 253 |
@@ -249,7 +262,7 @@ static int do_h264_encoding(void) | ||
249 | 262 | seq_h264.frame_rate = frame_rate; |
250 | 263 | seq_h264.initial_qp = initial_qp; |
251 | 264 | seq_h264.min_qp = minimal_qp; |
252 | - seq_h264.basic_unit_size = 6; | |
265 | + seq_h264.basic_unit_size = 0; | |
253 | 266 | seq_h264.intra_period = intra_count; |
254 | 267 | |
255 | 268 | va_status = vaCreateBuffer(va_dpy, context_id, |
@@ -261,12 +274,10 @@ static int do_h264_encoding(void) | ||
261 | 274 | CHECK_VASTATUS(va_status,"vaRenderPicture");; |
262 | 275 | } |
263 | 276 | |
264 | - va_status = vaCreateBuffer(va_dpy,context_id,VAEncCodedBufferType, | |
265 | - codedbuf_size, 1, NULL, &coded_buf); | |
266 | 277 | |
267 | 278 | pic_h264.reference_picture = surface_id[ref_surface]; |
268 | 279 | pic_h264.reconstructed_picture= surface_id[dst_surface]; |
269 | - pic_h264.coded_buf = coded_buf; | |
280 | + pic_h264.coded_buf = coded_buf[codedbuf_idx]; | |
270 | 281 | pic_h264.picture_width = frame_width; |
271 | 282 | pic_h264.picture_height = frame_height; |
272 | 283 | pic_h264.last_picture = (i==frame_count); |
@@ -300,7 +311,7 @@ static int do_h264_encoding(void) | ||
300 | 311 | va_status = vaQuerySurfaceStatus(va_dpy, surface_id[src_surface],&surface_status); |
301 | 312 | frame_skipped = (surface_status & VASurfaceSkipped); |
302 | 313 | |
303 | - save_coded_buf(coded_buf, i, frame_skipped); | |
314 | + save_coded_buf(coded_buf[codedbuf_idx], i, frame_skipped); | |
304 | 315 | |
305 | 316 | /* should display reconstructed frame, but just diplay source frame */ |
306 | 317 | if (frame_display) { |
@@ -316,6 +327,11 @@ static int do_h264_encoding(void) | ||
316 | 327 | if (src_surface == (SURFACE_NUM - 2)) |
317 | 328 | src_surface = 0; |
318 | 329 | |
330 | + /* use next codedbuf */ | |
331 | + codedbuf_idx++; | |
332 | + if (codedbuf_idx == (CODEDBUF_NUM - 1)) | |
333 | + codedbuf_idx = 0; | |
334 | + | |
319 | 335 | /* if a frame is skipped, current frame still use last reference frame */ |
320 | 336 | if (frame_skipped == 0) { |
321 | 337 | /* swap ref/dst */ |
@@ -375,7 +391,8 @@ int main(int argc,char **argv) | ||
375 | 391 | case '?': |
376 | 392 | printf("./h264encode <options>\n"); |
377 | 393 | printf(" -w -h: resolution\n"); |
378 | - printf(" -n frame number\n"); | |
394 | + printf(" -n frame number\n"); | |
395 | + printf(" -d display the source frame\n"); | |
379 | 396 | printf(" -p P frame count between two I frames\n"); |
380 | 397 | printf(" -f frame rate\n"); |
381 | 398 | printf(" -r bit rate\n"); |