hardware/intel/libva
修訂 | 51b2f0062d5cfc9eec181ef08396c50d898cfb3c (tree) |
---|---|
時間 | 2013-05-28 17:46:48 |
作者 | Xiang, Haihao <haihao.xiang@inte...> |
Commiter | Xiang, Haihao |
test: use the new H264 encoding and VPP interfaces
Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
@@ -45,6 +45,7 @@ | ||
45 | 45 | #include <pthread.h> |
46 | 46 | |
47 | 47 | #include <va/va.h> |
48 | +#include <va/va_enc_h264.h> | |
48 | 49 | #include "va_display.h" |
49 | 50 | |
50 | 51 | #define NAL_REF_IDC_NONE 0 |
@@ -87,10 +88,6 @@ static int intra_period = 30; | ||
87 | 88 | static int pb_period = 5; |
88 | 89 | static int frame_bit_rate = -1; |
89 | 90 | |
90 | -#define BR_CBR 0 | |
91 | -#define BR_VBR 1 | |
92 | -#define BR_CQP 2 | |
93 | - | |
94 | 91 | #define MAX_SLICES 32 |
95 | 92 | |
96 | 93 | static int |
@@ -108,26 +105,28 @@ struct upload_thread_param | ||
108 | 105 | static void |
109 | 106 | upload_yuv_to_surface(FILE *yuv_fp, VASurfaceID surface_id); |
110 | 107 | |
111 | -struct { | |
108 | +static struct { | |
109 | + VAProfile profile; | |
112 | 110 | VAEncSequenceParameterBufferH264 seq_param; |
113 | 111 | VAEncPictureParameterBufferH264 pic_param; |
114 | 112 | VAEncSliceParameterBufferH264 slice_param[MAX_SLICES]; |
115 | - VAEncH264DecRefPicMarkingBuffer dec_ref_pic_marking; | |
116 | 113 | VAContextID context_id; |
117 | 114 | VAConfigID config_id; |
118 | 115 | VABufferID seq_param_buf_id; /* Sequence level parameter */ |
119 | 116 | VABufferID pic_param_buf_id; /* Picture level parameter */ |
120 | 117 | VABufferID slice_param_buf_id[MAX_SLICES]; /* Slice level parameter, multil slices */ |
121 | - VABufferID dec_ref_pic_marking_buf_id; | |
122 | 118 | VABufferID codedbuf_buf_id; /* Output buffer, compressed data */ |
123 | 119 | VABufferID packed_seq_header_param_buf_id; |
124 | 120 | VABufferID packed_seq_buf_id; |
125 | 121 | VABufferID packed_pic_header_param_buf_id; |
126 | 122 | VABufferID packed_pic_buf_id; |
123 | + VABufferID misc_parameter_hrd_buf_id; | |
124 | + | |
127 | 125 | int num_slices; |
128 | 126 | int codedbuf_i_size; |
129 | 127 | int codedbuf_pb_size; |
130 | 128 | int current_input_surface; |
129 | + int rate_control_method; | |
131 | 130 | struct upload_thread_param upload_thread_param; |
132 | 131 | pthread_t upload_thread_id; |
133 | 132 | int upload_thread_value; |
@@ -145,7 +144,7 @@ static void create_encode_pipe() | ||
145 | 144 | va_status = vaInitialize(va_dpy, &major_ver, &minor_ver); |
146 | 145 | CHECK_VASTATUS(va_status, "vaInitialize"); |
147 | 146 | |
148 | - vaQueryConfigEntrypoints(va_dpy, VAProfileH264Baseline, entrypoints, | |
147 | + vaQueryConfigEntrypoints(va_dpy, avcenc_context.profile, entrypoints, | |
149 | 148 | &num_entrypoints); |
150 | 149 | |
151 | 150 | for (slice_entrypoint = 0; slice_entrypoint < num_entrypoints; slice_entrypoint++) { |
@@ -161,7 +160,7 @@ static void create_encode_pipe() | ||
161 | 160 | /* find out the format for the render target, and rate control mode */ |
162 | 161 | attrib[0].type = VAConfigAttribRTFormat; |
163 | 162 | attrib[1].type = VAConfigAttribRateControl; |
164 | - vaGetConfigAttributes(va_dpy, VAProfileH264Baseline, VAEntrypointEncSlice, | |
163 | + vaGetConfigAttributes(va_dpy, avcenc_context.profile, VAEntrypointEncSlice, | |
165 | 164 | &attrib[0], 2); |
166 | 165 | |
167 | 166 | if ((attrib[0].value & VA_RT_FORMAT_YUV420) == 0) { |
@@ -169,16 +168,16 @@ static void create_encode_pipe() | ||
169 | 168 | assert(0); |
170 | 169 | } |
171 | 170 | |
172 | - if ((attrib[1].value & VA_RC_VBR) == 0) { | |
171 | + if ((attrib[1].value & avcenc_context.rate_control_method) == 0) { | |
173 | 172 | /* Can't find matched RC mode */ |
174 | - printf("VBR mode doesn't found, exit\n"); | |
173 | + printf("Can't find the desired RC mode, exit\n"); | |
175 | 174 | assert(0); |
176 | 175 | } |
177 | 176 | |
178 | 177 | attrib[0].value = VA_RT_FORMAT_YUV420; /* set to desired RT format */ |
179 | - attrib[1].value = VA_RC_VBR; /* set to desired RC mode */ | |
178 | + attrib[1].value = avcenc_context.rate_control_method; /* set to desired RC mode */ | |
180 | 179 | |
181 | - va_status = vaCreateConfig(va_dpy, VAProfileH264Baseline, VAEntrypointEncSlice, | |
180 | + va_status = vaCreateConfig(va_dpy, avcenc_context.profile, VAEntrypointEncSlice, | |
182 | 181 | &attrib[0], 2,&avcenc_context.config_id); |
183 | 182 | CHECK_VASTATUS(va_status, "vaCreateConfig"); |
184 | 183 |
@@ -270,7 +269,7 @@ static void avcenc_update_picture_parameter(int slice_type, int frame_num, int d | ||
270 | 269 | pic_param->ReferenceFrames[1].picture_id = surface_ids[SID_REFERENCE_PICTURE_L1]; |
271 | 270 | pic_param->ReferenceFrames[2].picture_id = VA_INVALID_ID; |
272 | 271 | assert(avcenc_context.codedbuf_buf_id != VA_INVALID_ID); |
273 | - pic_param->CodedBuf = avcenc_context.codedbuf_buf_id; | |
272 | + pic_param->coded_buf = avcenc_context.codedbuf_buf_id; | |
274 | 273 | pic_param->frame_num = frame_num; |
275 | 274 | pic_param->pic_fields.bits.idr_pic_flag = !!is_idr; |
276 | 275 | pic_param->pic_fields.bits.reference_pic_flag = (slice_type != SLICE_TYPE_B); |
@@ -366,8 +365,8 @@ static void avcenc_update_slice_parameter(int slice_type) | ||
366 | 365 | // Slice level |
367 | 366 | i = 0; |
368 | 367 | slice_param = &avcenc_context.slice_param[i]; |
369 | - slice_param->starting_macroblock_address = 0; | |
370 | - slice_param->number_of_mbs = picture_height_in_mbs * picture_width_in_mbs; | |
368 | + slice_param->macroblock_address = 0; | |
369 | + slice_param->num_macroblocks = picture_height_in_mbs * picture_width_in_mbs; | |
371 | 370 | slice_param->pic_parameter_set_id = 0; |
372 | 371 | slice_param->slice_type = slice_type; |
373 | 372 | slice_param->direct_spatial_mv_pred_flag = 0; |
@@ -380,9 +379,6 @@ static void avcenc_update_slice_parameter(int slice_type) | ||
380 | 379 | slice_param->slice_beta_offset_div2 = 2; |
381 | 380 | slice_param->idr_pic_id = 0; |
382 | 381 | |
383 | - /* ref_pic_list_modification() */ | |
384 | - slice_param->ref_pic_list_modification_flag_l0 = 0; | |
385 | - slice_param->ref_pic_list_modification_flag_l1 = 0; | |
386 | 382 | /* FIXME: fill other fields */ |
387 | 383 | |
388 | 384 | va_status = vaCreateBuffer(va_dpy, |
@@ -395,8 +391,8 @@ static void avcenc_update_slice_parameter(int slice_type) | ||
395 | 391 | |
396 | 392 | #if 0 |
397 | 393 | slice_param = &avcenc_context.slice_param[i]; |
398 | - slice_param->starting_macroblock_address = picture_height_in_mbs * picture_width_in_mbs / 2; | |
399 | - slice_param->number_of_mbs = picture_height_in_mbs * picture_width_in_mbs / 2; | |
394 | + slice_param->macroblock_address = picture_height_in_mbs * picture_width_in_mbs / 2; | |
395 | + slice_param->num_macroblocks = picture_height_in_mbs * picture_width_in_mbs / 2; | |
400 | 396 | slice_param->pic_parameter_set_id = 0; |
401 | 397 | slice_param->slice_type = slice_type; |
402 | 398 | slice_param->direct_spatial_mv_pred_flag = 0; |
@@ -409,9 +405,6 @@ static void avcenc_update_slice_parameter(int slice_type) | ||
409 | 405 | slice_param->slice_beta_offset_div2 = 2; |
410 | 406 | slice_param->idr_pic_id = 0; |
411 | 407 | |
412 | - /* ref_pic_list_modification() */ | |
413 | - slice_param->ref_pic_list_modification_flag_l0 = 0; | |
414 | - slice_param->ref_pic_list_modification_flag_l1 = 0; | |
415 | 408 | /* FIXME: fill other fields */ |
416 | 409 | |
417 | 410 | va_status = vaCreateBuffer(va_dpy, |
@@ -452,12 +445,9 @@ static int begin_picture(FILE *yuv_fp, int frame_num, int display_num, int slice | ||
452 | 445 | assert(slice_type == SLICE_TYPE_I); |
453 | 446 | length_in_bits = build_packed_seq_buffer(&packed_seq_buffer); |
454 | 447 | offset_in_bytes = 0; |
455 | - packed_header_param_buffer.type = VAEncPackedHeaderSPS; | |
456 | - packed_header_param_buffer.insert_emulation_bytes = 1; | |
457 | - packed_header_param_buffer.skip_emulation_check_count = 5; /* ignore start code & nal type for emulation prevetion check */ | |
458 | - packed_header_param_buffer.num_headers = 1; | |
459 | - packed_header_param_buffer.length_in_bits = &length_in_bits; | |
460 | - packed_header_param_buffer.offset_in_bytes = &offset_in_bytes; | |
448 | + packed_header_param_buffer.type = VAEncPackedHeaderSequence; | |
449 | + packed_header_param_buffer.bit_length = length_in_bits; | |
450 | + packed_header_param_buffer.has_emulation_bytes = 0; | |
461 | 451 | va_status = vaCreateBuffer(va_dpy, |
462 | 452 | avcenc_context.context_id, |
463 | 453 | VAEncPackedHeaderParameterBufferType, |
@@ -474,12 +464,9 @@ static int begin_picture(FILE *yuv_fp, int frame_num, int display_num, int slice | ||
474 | 464 | |
475 | 465 | length_in_bits = build_packed_pic_buffer(&packed_pic_buffer); |
476 | 466 | offset_in_bytes = 0; |
477 | - packed_header_param_buffer.type = VAEncPackedHeaderPPS; | |
478 | - packed_header_param_buffer.insert_emulation_bytes = 1; | |
479 | - packed_header_param_buffer.skip_emulation_check_count = 5; /* ignore start code & nal type for emulation prevetion check */ | |
480 | - packed_header_param_buffer.num_headers = 1; | |
481 | - packed_header_param_buffer.length_in_bits = &length_in_bits; | |
482 | - packed_header_param_buffer.offset_in_bytes = &offset_in_bytes; | |
467 | + packed_header_param_buffer.type = VAEncPackedHeaderPicture; | |
468 | + packed_header_param_buffer.bit_length = length_in_bits; | |
469 | + packed_header_param_buffer.has_emulation_bytes = 0; | |
483 | 470 | |
484 | 471 | va_status = vaCreateBuffer(va_dpy, |
485 | 472 | avcenc_context.context_id, |
@@ -506,7 +493,36 @@ static int begin_picture(FILE *yuv_fp, int frame_num, int display_num, int slice | ||
506 | 493 | VAEncSequenceParameterBufferType, |
507 | 494 | sizeof(*seq_param), 1, seq_param, |
508 | 495 | &avcenc_context.seq_param_buf_id); |
509 | - CHECK_VASTATUS(va_status,"vaCreateBuffer");; | |
496 | + CHECK_VASTATUS(va_status,"vaCreateBuffer"); | |
497 | + | |
498 | + | |
499 | + /* hrd parameter */ | |
500 | + VAEncMiscParameterBuffer *misc_param; | |
501 | + VAEncMiscParameterHRD *misc_hrd_param; | |
502 | + vaCreateBuffer(va_dpy, | |
503 | + avcenc_context.context_id, | |
504 | + VAEncMiscParameterBufferType, | |
505 | + sizeof(VAEncMiscParameterBuffer) + sizeof(VAEncMiscParameterRateControl), | |
506 | + 1, | |
507 | + NULL, | |
508 | + &avcenc_context.misc_parameter_hrd_buf_id); | |
509 | + CHECK_VASTATUS(va_status, "vaCreateBuffer"); | |
510 | + | |
511 | + vaMapBuffer(va_dpy, | |
512 | + avcenc_context.misc_parameter_hrd_buf_id, | |
513 | + (void **)&misc_param); | |
514 | + misc_param->type = VAEncMiscParameterTypeHRD; | |
515 | + misc_hrd_param = (VAEncMiscParameterHRD *)misc_param->data; | |
516 | + | |
517 | + if (frame_bit_rate > 0) { | |
518 | + misc_hrd_param->initial_buffer_fullness = frame_bit_rate * 1024 * 4; | |
519 | + misc_hrd_param->buffer_size = frame_bit_rate * 1024 * 8; | |
520 | + } else { | |
521 | + misc_hrd_param->initial_buffer_fullness = 0; | |
522 | + misc_hrd_param->buffer_size = 0; | |
523 | + } | |
524 | + | |
525 | + vaUnmapBuffer(va_dpy, avcenc_context.misc_parameter_hrd_buf_id); | |
510 | 526 | |
511 | 527 | /* slice parameter */ |
512 | 528 | avcenc_update_slice_parameter(slice_type); |
@@ -524,9 +540,6 @@ int avcenc_render_picture() | ||
524 | 540 | va_buffers[num_va_buffers++] = avcenc_context.seq_param_buf_id; |
525 | 541 | va_buffers[num_va_buffers++] = avcenc_context.pic_param_buf_id; |
526 | 542 | |
527 | - if (avcenc_context.dec_ref_pic_marking_buf_id != VA_INVALID_ID) | |
528 | - va_buffers[num_va_buffers++] = avcenc_context.dec_ref_pic_marking_buf_id; | |
529 | - | |
530 | 543 | if (avcenc_context.packed_seq_header_param_buf_id != VA_INVALID_ID) |
531 | 544 | va_buffers[num_va_buffers++] = avcenc_context.packed_seq_header_param_buf_id; |
532 | 545 |
@@ -539,6 +552,9 @@ int avcenc_render_picture() | ||
539 | 552 | if (avcenc_context.packed_pic_buf_id != VA_INVALID_ID) |
540 | 553 | va_buffers[num_va_buffers++] = avcenc_context.packed_pic_buf_id; |
541 | 554 | |
555 | + if (avcenc_context.misc_parameter_hrd_buf_id != VA_INVALID_ID) | |
556 | + va_buffers[num_va_buffers++] = avcenc_context.misc_parameter_hrd_buf_id; | |
557 | + | |
542 | 558 | va_status = vaBeginPicture(va_dpy, |
543 | 559 | avcenc_context.context_id, |
544 | 560 | surface_ids[avcenc_context.current_input_surface]); |
@@ -605,13 +621,14 @@ static void end_picture(int slice_type, int next_is_bpic) | ||
605 | 621 | |
606 | 622 | avcenc_destroy_buffers(&avcenc_context.seq_param_buf_id, 1); |
607 | 623 | avcenc_destroy_buffers(&avcenc_context.pic_param_buf_id, 1); |
608 | - avcenc_destroy_buffers(&avcenc_context.dec_ref_pic_marking_buf_id, 1); | |
609 | 624 | avcenc_destroy_buffers(&avcenc_context.packed_seq_header_param_buf_id, 1); |
610 | 625 | avcenc_destroy_buffers(&avcenc_context.packed_seq_buf_id, 1); |
611 | 626 | avcenc_destroy_buffers(&avcenc_context.packed_pic_header_param_buf_id, 1); |
612 | 627 | avcenc_destroy_buffers(&avcenc_context.packed_pic_buf_id, 1); |
613 | 628 | avcenc_destroy_buffers(&avcenc_context.slice_param_buf_id[0], avcenc_context.num_slices); |
614 | 629 | avcenc_destroy_buffers(&avcenc_context.codedbuf_buf_id, 1); |
630 | + avcenc_destroy_buffers(&avcenc_context.misc_parameter_hrd_buf_id, 1); | |
631 | + | |
615 | 632 | memset(avcenc_context.slice_param, 0, sizeof(avcenc_context.slice_param)); |
616 | 633 | avcenc_context.num_slices = 0; |
617 | 634 | } |
@@ -773,8 +790,14 @@ static void nal_header(bitstream *bs, int nal_ref_idc, int nal_unit_type) | ||
773 | 790 | static void sps_rbsp(bitstream *bs) |
774 | 791 | { |
775 | 792 | VAEncSequenceParameterBufferH264 *seq_param = &avcenc_context.seq_param; |
793 | + int profile_idc = PROFILE_IDC_BASELINE; | |
794 | + | |
795 | + if (avcenc_context.profile == VAProfileH264High) | |
796 | + profile_idc = PROFILE_IDC_HIGH; | |
797 | + else if (avcenc_context.profile == VAProfileH264Main) | |
798 | + profile_idc = PROFILE_IDC_MAIN; | |
776 | 799 | |
777 | - bitstream_put_ui(bs, seq_param->profile_idc, 8); /* profile_idc */ | |
800 | + bitstream_put_ui(bs, profile_idc, 8); /* profile_idc */ | |
778 | 801 | bitstream_put_ui(bs, 0, 1); /* constraint_set0_flag */ |
779 | 802 | bitstream_put_ui(bs, 1, 1); /* constraint_set1_flag */ |
780 | 803 | bitstream_put_ui(bs, 0, 1); /* constraint_set2_flag */ |
@@ -783,16 +806,11 @@ static void sps_rbsp(bitstream *bs) | ||
783 | 806 | bitstream_put_ui(bs, seq_param->level_idc, 8); /* level_idc */ |
784 | 807 | bitstream_put_ue(bs, seq_param->seq_parameter_set_id); /* seq_parameter_set_id */ |
785 | 808 | |
786 | - if (seq_param->profile_idc >= PROFILE_IDC_HIGH) { | |
787 | - /* FIXME: fix for high profile */ | |
788 | - assert(0); | |
789 | - } | |
809 | + bitstream_put_ue(bs, seq_param->seq_fields.bits.log2_max_frame_num_minus4); /* log2_max_frame_num_minus4 */ | |
810 | + bitstream_put_ue(bs, seq_param->seq_fields.bits.pic_order_cnt_type); /* pic_order_cnt_type */ | |
790 | 811 | |
791 | - bitstream_put_ue(bs, seq_param->log2_max_frame_num_minus4); /* log2_max_frame_num_minus4 */ | |
792 | - bitstream_put_ue(bs, seq_param->pic_order_cnt_type); /* pic_order_cnt_type */ | |
793 | - | |
794 | - if (seq_param->pic_order_cnt_type == 0) | |
795 | - bitstream_put_ue(bs, seq_param->log2_max_pic_order_cnt_lsb_minus4); /* log2_max_pic_order_cnt_lsb_minus4 */ | |
812 | + if (seq_param->seq_fields.bits.pic_order_cnt_type == 0) | |
813 | + bitstream_put_ue(bs, seq_param->seq_fields.bits.log2_max_pic_order_cnt_lsb_minus4); /* log2_max_pic_order_cnt_lsb_minus4 */ | |
796 | 814 | else { |
797 | 815 | assert(0); |
798 | 816 | } |
@@ -802,13 +820,13 @@ static void sps_rbsp(bitstream *bs) | ||
802 | 820 | |
803 | 821 | bitstream_put_ue(bs, seq_param->picture_width_in_mbs - 1); /* pic_width_in_mbs_minus1 */ |
804 | 822 | bitstream_put_ue(bs, seq_param->picture_height_in_mbs - 1); /* pic_height_in_map_units_minus1 */ |
805 | - bitstream_put_ui(bs, seq_param->frame_mbs_only_flag, 1); /* frame_mbs_only_flag */ | |
823 | + bitstream_put_ui(bs, seq_param->seq_fields.bits.frame_mbs_only_flag, 1); /* frame_mbs_only_flag */ | |
806 | 824 | |
807 | - if (!seq_param->frame_mbs_only_flag) { | |
825 | + if (!seq_param->seq_fields.bits.frame_mbs_only_flag) { | |
808 | 826 | assert(0); |
809 | 827 | } |
810 | 828 | |
811 | - bitstream_put_ui(bs, seq_param->direct_8x8_inference_flag, 1); /* direct_8x8_inference_flag */ | |
829 | + bitstream_put_ui(bs, seq_param->seq_fields.bits.direct_8x8_inference_flag, 1); /* direct_8x8_inference_flag */ | |
812 | 830 | bitstream_put_ui(bs, seq_param->frame_cropping_flag, 1); /* frame_cropping_flag */ |
813 | 831 | |
814 | 832 | if (seq_param->frame_cropping_flag) { |
@@ -968,10 +986,10 @@ slice_header(bitstream *bs, int frame_num, int display_frame, int slice_type, in | ||
968 | 986 | bitstream_put_ue(bs, 0); /* first_mb_in_slice: 0 */ |
969 | 987 | bitstream_put_ue(bs, slice_type); /* slice_type */ |
970 | 988 | bitstream_put_ue(bs, 0); /* pic_parameter_set_id: 0 */ |
971 | - bitstream_put_ui(bs, frame_num & 0x0F, seq_param->log2_max_frame_num_minus4 + 4); /* frame_num */ | |
989 | + bitstream_put_ui(bs, frame_num & 0x0F, seq_param->seq_fields.bits.log2_max_frame_num_minus4 + 4); /* frame_num */ | |
972 | 990 | |
973 | 991 | /* frame_mbs_only_flag == 1 */ |
974 | - if (!seq_param->frame_mbs_only_flag) { | |
992 | + if (!seq_param->seq_fields.bits.frame_mbs_only_flag) { | |
975 | 993 | /* FIXME: */ |
976 | 994 | assert(0); |
977 | 995 | } |
@@ -979,8 +997,8 @@ slice_header(bitstream *bs, int frame_num, int display_frame, int slice_type, in | ||
979 | 997 | if (is_idr) |
980 | 998 | bitstream_put_ue(bs, 0); /* idr_pic_id: 0 */ |
981 | 999 | |
982 | - if (seq_param->pic_order_cnt_type == 0) { | |
983 | - bitstream_put_ui(bs, (display_frame*2) & 0x3F, seq_param->log2_max_pic_order_cnt_lsb_minus4 + 4); | |
1000 | + if (seq_param->seq_fields.bits.pic_order_cnt_type == 0) { | |
1001 | + bitstream_put_ui(bs, (display_frame*2) & 0x3F, seq_param->seq_fields.bits.log2_max_pic_order_cnt_lsb_minus4 + 4); | |
984 | 1002 | /* only support frame */ |
985 | 1003 | } else { |
986 | 1004 | /* FIXME: */ |
@@ -1224,50 +1242,26 @@ static void avcenc_context_seq_param_init(VAEncSequenceParameterBufferH264 *seq_ | ||
1224 | 1242 | int frame_crop_bottom_offset = 0; |
1225 | 1243 | |
1226 | 1244 | seq_param->seq_parameter_set_id = 0; |
1227 | - seq_param->profile_idc = PROFILE_IDC_MAIN; | |
1228 | 1245 | seq_param->level_idc = 41; |
1229 | 1246 | seq_param->intra_period = intra_period; |
1230 | 1247 | seq_param->ip_period = 0; /* FIXME: ??? */ |
1231 | 1248 | seq_param->max_num_ref_frames = 4; |
1232 | 1249 | seq_param->picture_width_in_mbs = width_in_mbs; |
1233 | 1250 | seq_param->picture_height_in_mbs = height_in_mbs; |
1234 | - seq_param->frame_mbs_only_flag = 1; | |
1235 | - seq_param->target_usage = 1; | |
1251 | + seq_param->seq_fields.bits.frame_mbs_only_flag = 1; | |
1236 | 1252 | |
1237 | - /* 0:CBR, 1:VBR, 2:Constant QP */ | |
1238 | - if (qp_value == -1) | |
1239 | - seq_param->rate_control_method = BR_CBR; | |
1240 | - else if (qp_value == -2) | |
1241 | - seq_param->rate_control_method = BR_VBR; | |
1242 | - else { | |
1243 | - assert(qp_value >= 0 && qp_value <= 51); | |
1244 | - seq_param->rate_control_method = BR_CQP; | |
1245 | - } | |
1246 | - | |
1247 | 1253 | if (frame_bit_rate > 0) |
1248 | 1254 | seq_param->bits_per_second = 1024 * frame_bit_rate; /* use kbps as input */ |
1249 | 1255 | else |
1250 | 1256 | seq_param->bits_per_second = 0; |
1251 | - | |
1252 | - if (seq_param->rate_control_method == BR_VBR) { | |
1253 | - seq_param->max_bits_per_second = 0; /* FIXME: set it later */ | |
1254 | - seq_param->min_bits_per_second = 0; | |
1255 | - } | |
1256 | - | |
1257 | - if ( frame_bit_rate > 0) { | |
1258 | - seq_param->initial_hrd_buffer_fullness = frame_bit_rate * 1024 * 4; | |
1259 | - seq_param->hrd_buffer_size = frame_bit_rate * 1024 * 8; | |
1260 | - } else { | |
1261 | - seq_param->initial_hrd_buffer_fullness = 0; | |
1262 | - seq_param->hrd_buffer_size = 0; | |
1263 | - } | |
1257 | + | |
1264 | 1258 | seq_param->time_scale = 900; |
1265 | 1259 | seq_param->num_units_in_tick = 15; /* Tc = num_units_in_tick / time_sacle */ |
1266 | 1260 | |
1267 | 1261 | if (height_in_mbs * 16 - height) { |
1268 | 1262 | frame_cropping_flag = 1; |
1269 | 1263 | frame_crop_bottom_offset = |
1270 | - (height_in_mbs * 16 - height) / (2 * (!seq_param->frame_mbs_only_flag + 1)); | |
1264 | + (height_in_mbs * 16 - height) / (2 * (!seq_param->seq_fields.bits.frame_mbs_only_flag + 1)); | |
1271 | 1265 | } |
1272 | 1266 | |
1273 | 1267 | seq_param->frame_cropping_flag = frame_cropping_flag; |
@@ -1276,16 +1270,16 @@ static void avcenc_context_seq_param_init(VAEncSequenceParameterBufferH264 *seq_ | ||
1276 | 1270 | seq_param->frame_crop_top_offset = 0; |
1277 | 1271 | seq_param->frame_crop_bottom_offset = frame_crop_bottom_offset; |
1278 | 1272 | |
1279 | - seq_param->pic_order_cnt_type = 0; | |
1280 | - seq_param->direct_8x8_inference_flag = 0; | |
1273 | + seq_param->seq_fields.bits.pic_order_cnt_type = 0; | |
1274 | + seq_param->seq_fields.bits.direct_8x8_inference_flag = 0; | |
1281 | 1275 | |
1282 | - seq_param->log2_max_frame_num_minus4 = 0; | |
1283 | - seq_param->log2_max_pic_order_cnt_lsb_minus4 = 2; | |
1276 | + seq_param->seq_fields.bits.log2_max_frame_num_minus4 = 0; | |
1277 | + seq_param->seq_fields.bits.log2_max_pic_order_cnt_lsb_minus4 = 2; | |
1284 | 1278 | |
1285 | - if ( frame_bit_rate > 0) | |
1286 | - seq_param->vui_flag = 1; //HRD info located in vui | |
1287 | - else | |
1288 | - seq_param->vui_flag = 0; | |
1279 | + if (frame_bit_rate > 0) | |
1280 | + seq_param->vui_parameters_present_flag = 1; //HRD info located in vui | |
1281 | + else | |
1282 | + seq_param->vui_parameters_present_flag = 0; | |
1289 | 1283 | } |
1290 | 1284 | |
1291 | 1285 | static void avcenc_context_pic_param_init(VAEncPictureParameterBufferH264 *pic_param) |
@@ -1295,7 +1289,6 @@ static void avcenc_context_pic_param_init(VAEncPictureParameterBufferH264 *pic_p | ||
1295 | 1289 | |
1296 | 1290 | pic_param->last_picture = 0; |
1297 | 1291 | pic_param->frame_num = 0; |
1298 | - pic_param->coding_type = 0; | |
1299 | 1292 | |
1300 | 1293 | pic_param->pic_init_qp = (qp_value >= 0 ? qp_value : 26); |
1301 | 1294 | pic_param->num_ref_idx_l0_active_minus1 = 0; |
@@ -1314,19 +1307,29 @@ static void avcenc_context_init(int width, int height) | ||
1314 | 1307 | { |
1315 | 1308 | int i; |
1316 | 1309 | memset(&avcenc_context, 0, sizeof(avcenc_context)); |
1310 | + avcenc_context.profile = VAProfileH264Main; | |
1317 | 1311 | avcenc_context.seq_param_buf_id = VA_INVALID_ID; |
1318 | 1312 | avcenc_context.pic_param_buf_id = VA_INVALID_ID; |
1319 | - avcenc_context.dec_ref_pic_marking_buf_id = VA_INVALID_ID; | |
1320 | 1313 | avcenc_context.packed_seq_header_param_buf_id = VA_INVALID_ID; |
1321 | 1314 | avcenc_context.packed_seq_buf_id = VA_INVALID_ID; |
1322 | 1315 | avcenc_context.packed_pic_header_param_buf_id = VA_INVALID_ID; |
1323 | 1316 | avcenc_context.packed_pic_buf_id = VA_INVALID_ID; |
1324 | 1317 | avcenc_context.codedbuf_buf_id = VA_INVALID_ID; |
1318 | + avcenc_context.misc_parameter_hrd_buf_id = VA_INVALID_ID; | |
1325 | 1319 | avcenc_context.codedbuf_i_size = width * height; |
1326 | 1320 | avcenc_context.codedbuf_pb_size = 0; |
1327 | 1321 | avcenc_context.current_input_surface = SID_INPUT_PICTURE_0; |
1328 | 1322 | avcenc_context.upload_thread_value = -1; |
1329 | 1323 | |
1324 | + if (qp_value == -1) | |
1325 | + avcenc_context.rate_control_method = VA_RC_CBR; | |
1326 | + else if (qp_value == -2) | |
1327 | + avcenc_context.rate_control_method = VA_RC_VBR; | |
1328 | + else { | |
1329 | + assert(qp_value >= 0 && qp_value <= 51); | |
1330 | + avcenc_context.rate_control_method = VA_RC_CQP; | |
1331 | + } | |
1332 | + | |
1330 | 1333 | for (i = 0; i < MAX_SLICES; i++) { |
1331 | 1334 | avcenc_context.slice_param_buf_id[i] = VA_INVALID_ID; |
1332 | 1335 | } |