hardware/intel/libva
修订版 | df0b9f1615ca067dfb7c71dc08d720fda44e8437 (tree) |
---|---|
时间 | 2013-05-28 17:46:48 |
作者 | Xiang, Haihao <haihao.xiang@inte...> |
Commiter | Xiang, Haihao |
test/encode/avcenc: use new packed header interface
Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
@@ -108,14 +108,6 @@ struct upload_thread_param | ||
108 | 108 | static void |
109 | 109 | upload_yuv_to_surface(FILE *yuv_fp, VASurfaceID surface_id); |
110 | 110 | |
111 | -struct packed_data_format | |
112 | -{ | |
113 | - unsigned int length_in_bits; | |
114 | - unsigned char flag; | |
115 | - unsigned char num_skip_bytes; | |
116 | - unsigned char pad[2]; | |
117 | -}; | |
118 | - | |
119 | 111 | struct { |
120 | 112 | VAEncSequenceParameterBufferH264Ext seq_param; |
121 | 113 | VAEncPictureParameterBufferH264Ext pic_param; |
@@ -128,7 +120,9 @@ struct { | ||
128 | 120 | VABufferID slice_param_buf_id[MAX_SLICES]; /* Slice level parameter, multil slices */ |
129 | 121 | VABufferID dec_ref_pic_marking_buf_id; |
130 | 122 | VABufferID codedbuf_buf_id; /* Output buffer, compressed data */ |
123 | + VABufferID packed_seq_header_param_buf_id; | |
131 | 124 | VABufferID packed_seq_buf_id; |
125 | + VABufferID packed_pic_header_param_buf_id; | |
132 | 126 | VABufferID packed_pic_buf_id; |
133 | 127 | int num_slices; |
134 | 128 | int codedbuf_i_size; |
@@ -355,8 +349,8 @@ static void avcenc_update_slice_parameter(int slice_type) | ||
355 | 349 | // Slice level |
356 | 350 | i = 0; |
357 | 351 | slice_param = &avcenc_context.slice_param[i]; |
358 | - slice_param->start_row_number = 0; | |
359 | - slice_param->slice_height = picture_height_in_mbs/16; /* Measured by MB */ | |
352 | + slice_param->starting_macroblock_address = 0; | |
353 | + slice_param->number_of_mbs = picture_height_in_mbs * picture_width_in_mbs; | |
360 | 354 | slice_param->pic_parameter_set_id = 0; |
361 | 355 | slice_param->slice_type = slice_type; |
362 | 356 | slice_param->direct_spatial_mv_pred_flag = 0; |
@@ -405,25 +399,55 @@ static int begin_picture(FILE *yuv_fp, int frame_num, int display_num, int slice | ||
405 | 399 | avcenc_context.current_input_surface = SID_INPUT_PICTURE_0; |
406 | 400 | |
407 | 401 | if (frame_num == 0) { |
402 | + VAEncPackedHeaderParameterBuffer packed_header_param_buffer; | |
403 | + unsigned int length_in_bits, offset_in_bytes; | |
408 | 404 | unsigned char *packed_seq_buffer = NULL, *packed_pic_buffer = NULL; |
409 | - int seq_length, pic_length; | |
410 | 405 | |
411 | 406 | assert(slice_type == SLICE_TYPE_I); |
412 | - seq_length = build_packed_seq_buffer(&packed_seq_buffer); | |
407 | + length_in_bits = build_packed_seq_buffer(&packed_seq_buffer); | |
408 | + offset_in_bytes = 0; | |
409 | + packed_header_param_buffer.type = VAEncPackedHeaderSPS; | |
410 | + packed_header_param_buffer.insert_emulation_bytes = 1; | |
411 | + packed_header_param_buffer.skip_emulation_check_count = 5; /* ignore start code & nal type for emulation prevetion check */ | |
412 | + packed_header_param_buffer.num_headers = 1; | |
413 | + packed_header_param_buffer.length_in_bits = &length_in_bits; | |
414 | + packed_header_param_buffer.offset_in_bytes = &offset_in_bytes; | |
413 | 415 | va_status = vaCreateBuffer(va_dpy, |
414 | 416 | avcenc_context.context_id, |
415 | - VAEncPackedSequenceParameterBufferType, | |
416 | - (seq_length + 7) / 8, 1, packed_seq_buffer, | |
417 | + VAEncPackedHeaderParameterBufferType, | |
418 | + sizeof(packed_header_param_buffer), 1, &packed_header_param_buffer, | |
419 | + &avcenc_context.packed_seq_header_param_buf_id); | |
420 | + CHECK_VASTATUS(va_status,"vaCreateBuffer"); | |
421 | + | |
422 | + va_status = vaCreateBuffer(va_dpy, | |
423 | + avcenc_context.context_id, | |
424 | + VAEncPackedHeaderDataBufferType, | |
425 | + (length_in_bits + 7) / 8, 1, packed_seq_buffer, | |
417 | 426 | &avcenc_context.packed_seq_buf_id); |
418 | - CHECK_VASTATUS(va_status,"vaCreateBuffer");; | |
427 | + CHECK_VASTATUS(va_status,"vaCreateBuffer"); | |
428 | + | |
429 | + length_in_bits = build_packed_pic_buffer(&packed_pic_buffer); | |
430 | + offset_in_bytes = 0; | |
431 | + packed_header_param_buffer.type = VAEncPackedHeaderPPS; | |
432 | + packed_header_param_buffer.insert_emulation_bytes = 1; | |
433 | + packed_header_param_buffer.skip_emulation_check_count = 5; /* ignore start code & nal type for emulation prevetion check */ | |
434 | + packed_header_param_buffer.num_headers = 1; | |
435 | + packed_header_param_buffer.length_in_bits = &length_in_bits; | |
436 | + packed_header_param_buffer.offset_in_bytes = &offset_in_bytes; | |
419 | 437 | |
420 | - pic_length = build_packed_pic_buffer(&packed_pic_buffer); | |
421 | 438 | va_status = vaCreateBuffer(va_dpy, |
422 | 439 | avcenc_context.context_id, |
423 | - VAEncPackedPictureParameterBufferType, | |
424 | - (pic_length + 7) / 8 , 1, packed_pic_buffer, | |
440 | + VAEncPackedHeaderParameterBufferType, | |
441 | + sizeof(packed_header_param_buffer), 1, &packed_header_param_buffer, | |
442 | + &avcenc_context.packed_pic_header_param_buf_id); | |
443 | + CHECK_VASTATUS(va_status,"vaCreateBuffer"); | |
444 | + | |
445 | + va_status = vaCreateBuffer(va_dpy, | |
446 | + avcenc_context.context_id, | |
447 | + VAEncPackedHeaderDataBufferType, | |
448 | + (length_in_bits + 7) / 8, 1, packed_pic_buffer, | |
425 | 449 | &avcenc_context.packed_pic_buf_id); |
426 | - CHECK_VASTATUS(va_status,"vaCreateBuffer");; | |
450 | + CHECK_VASTATUS(va_status,"vaCreateBuffer"); | |
427 | 451 | |
428 | 452 | free(packed_seq_buffer); |
429 | 453 | free(packed_pic_buffer); |
@@ -456,9 +480,15 @@ int avcenc_render_picture() | ||
456 | 480 | if (avcenc_context.dec_ref_pic_marking_buf_id != VA_INVALID_ID) |
457 | 481 | va_buffers[num_va_buffers++] = avcenc_context.dec_ref_pic_marking_buf_id; |
458 | 482 | |
483 | + if (avcenc_context.packed_seq_header_param_buf_id != VA_INVALID_ID) | |
484 | + va_buffers[num_va_buffers++] = avcenc_context.packed_seq_header_param_buf_id; | |
485 | + | |
459 | 486 | if (avcenc_context.packed_seq_buf_id != VA_INVALID_ID) |
460 | 487 | va_buffers[num_va_buffers++] = avcenc_context.packed_seq_buf_id; |
461 | 488 | |
489 | + if (avcenc_context.packed_pic_header_param_buf_id != VA_INVALID_ID) | |
490 | + va_buffers[num_va_buffers++] = avcenc_context.packed_pic_header_param_buf_id; | |
491 | + | |
462 | 492 | if (avcenc_context.packed_pic_buf_id != VA_INVALID_ID) |
463 | 493 | va_buffers[num_va_buffers++] = avcenc_context.packed_pic_buf_id; |
464 | 494 |
@@ -527,7 +557,9 @@ static void end_picture(int slice_type, int next_is_bpic) | ||
527 | 557 | avcenc_destroy_buffers(&avcenc_context.seq_param_buf_id, 1); |
528 | 558 | avcenc_destroy_buffers(&avcenc_context.pic_param_buf_id, 1); |
529 | 559 | avcenc_destroy_buffers(&avcenc_context.dec_ref_pic_marking_buf_id, 1); |
560 | + avcenc_destroy_buffers(&avcenc_context.packed_seq_header_param_buf_id, 1); | |
530 | 561 | avcenc_destroy_buffers(&avcenc_context.packed_seq_buf_id, 1); |
562 | + avcenc_destroy_buffers(&avcenc_context.packed_pic_header_param_buf_id, 1); | |
531 | 563 | avcenc_destroy_buffers(&avcenc_context.packed_pic_buf_id, 1); |
532 | 564 | avcenc_destroy_buffers(&avcenc_context.slice_param_buf_id[0], avcenc_context.num_slices); |
533 | 565 | avcenc_destroy_buffers(&avcenc_context.codedbuf_buf_id, 1); |
@@ -579,7 +611,7 @@ bitstream_start(bitstream *bs) | ||
579 | 611 | { |
580 | 612 | bs->max_size_in_dword = BITSTREAM_ALLOCATE_STEPPING; |
581 | 613 | bs->buffer = calloc(bs->max_size_in_dword * sizeof(int), 1); |
582 | - bs->bit_offset = sizeof(struct packed_data_format) * 8; /* the first 64 bits used for format */ | |
614 | + bs->bit_offset = 0; | |
583 | 615 | } |
584 | 616 | |
585 | 617 | static void |
@@ -588,16 +620,10 @@ bitstream_end(bitstream *bs) | ||
588 | 620 | int pos = (bs->bit_offset >> 5); |
589 | 621 | int bit_offset = (bs->bit_offset & 0x1f); |
590 | 622 | int bit_left = 32 - bit_offset; |
591 | - struct packed_data_format *format; | |
592 | 623 | |
593 | 624 | if (bit_offset) { |
594 | 625 | bs->buffer[pos] = va_swap32((bs->buffer[pos] << bit_left)); |
595 | 626 | } |
596 | - | |
597 | - format = (struct packed_data_format *)bs->buffer; | |
598 | - format->length_in_bits = bs->bit_offset - sizeof(struct packed_data_format) * 8; | |
599 | - format->flag |= 1; | |
600 | - format->num_skip_bytes = 5; /* ignore start code & nal type for emulation prevetion check */ | |
601 | 627 | } |
602 | 628 | |
603 | 629 | static void |
@@ -1193,7 +1219,9 @@ static void avcenc_context_init(int width, int height) | ||
1193 | 1219 | avcenc_context.seq_param_buf_id = VA_INVALID_ID; |
1194 | 1220 | avcenc_context.pic_param_buf_id = VA_INVALID_ID; |
1195 | 1221 | avcenc_context.dec_ref_pic_marking_buf_id = VA_INVALID_ID; |
1222 | + avcenc_context.packed_seq_header_param_buf_id = VA_INVALID_ID; | |
1196 | 1223 | avcenc_context.packed_seq_buf_id = VA_INVALID_ID; |
1224 | + avcenc_context.packed_pic_header_param_buf_id = VA_INVALID_ID; | |
1197 | 1225 | avcenc_context.packed_pic_buf_id = VA_INVALID_ID; |
1198 | 1226 | avcenc_context.codedbuf_buf_id = VA_INVALID_ID; |
1199 | 1227 | avcenc_context.codedbuf_i_size = width * height; |