hardware/intel/libva
修订版 | 6cc4260780cc2a9ce102a43e523e0f06e2341004 (tree) |
---|---|
时间 | 2013-05-28 17:46:48 |
作者 | Zhou Chang <chang.zhou@inte...> |
Commiter | Xiang, Haihao |
test/encode/avcenc: Add HRD support in avcenc demo application.
Signed-off-by: Zhou Chang <chang.zhou@intel.com>
@@ -367,7 +367,7 @@ static void avcenc_update_slice_parameter(int slice_type) | ||
367 | 367 | i = 0; |
368 | 368 | slice_param = &avcenc_context.slice_param[i]; |
369 | 369 | slice_param->starting_macroblock_address = 0; |
370 | - slice_param->number_of_mbs = picture_height_in_mbs * picture_width_in_mbs; | |
370 | + slice_param->number_of_mbs = picture_height_in_mbs * picture_width_in_mbs; | |
371 | 371 | slice_param->pic_parameter_set_id = 0; |
372 | 372 | slice_param->slice_type = slice_type; |
373 | 373 | slice_param->direct_spatial_mv_pred_flag = 0; |
@@ -391,8 +391,37 @@ static void avcenc_update_slice_parameter(int slice_type) | ||
391 | 391 | sizeof(*slice_param), 1, slice_param, |
392 | 392 | &avcenc_context.slice_param_buf_id[i]); |
393 | 393 | CHECK_VASTATUS(va_status,"vaCreateBuffer");; |
394 | + i++; | |
394 | 395 | |
396 | +#if 0 | |
397 | + 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; | |
400 | + slice_param->pic_parameter_set_id = 0; | |
401 | + slice_param->slice_type = slice_type; | |
402 | + slice_param->direct_spatial_mv_pred_flag = 0; | |
403 | + slice_param->num_ref_idx_l0_active_minus1 = 0; /* FIXME: ??? */ | |
404 | + slice_param->num_ref_idx_l1_active_minus1 = 0; | |
405 | + slice_param->cabac_init_idc = 0; | |
406 | + slice_param->slice_qp_delta = 0; | |
407 | + slice_param->disable_deblocking_filter_idc = 0; | |
408 | + slice_param->slice_alpha_c0_offset_div2 = 2; | |
409 | + slice_param->slice_beta_offset_div2 = 2; | |
410 | + slice_param->idr_pic_id = 0; | |
411 | + | |
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 | + /* FIXME: fill other fields */ | |
416 | + | |
417 | + va_status = vaCreateBuffer(va_dpy, | |
418 | + avcenc_context.context_id, | |
419 | + VAEncSliceParameterBufferType, | |
420 | + sizeof(*slice_param), 1, slice_param, | |
421 | + &avcenc_context.slice_param_buf_id[i]); | |
422 | + CHECK_VASTATUS(va_status,"vaCreateBuffer");; | |
395 | 423 | i++; |
424 | +#endif | |
396 | 425 | |
397 | 426 | avcenc_context.num_slices = i; |
398 | 427 | } |
@@ -490,6 +519,7 @@ int avcenc_render_picture() | ||
490 | 519 | VAStatus va_status; |
491 | 520 | VABufferID va_buffers[8]; |
492 | 521 | unsigned int num_va_buffers = 0; |
522 | + int i; | |
493 | 523 | |
494 | 524 | va_buffers[num_va_buffers++] = avcenc_context.seq_param_buf_id; |
495 | 525 | va_buffers[num_va_buffers++] = avcenc_context.pic_param_buf_id; |
@@ -513,18 +543,20 @@ int avcenc_render_picture() | ||
513 | 543 | avcenc_context.context_id, |
514 | 544 | surface_ids[avcenc_context.current_input_surface]); |
515 | 545 | CHECK_VASTATUS(va_status,"vaBeginPicture"); |
516 | - | |
546 | + | |
517 | 547 | va_status = vaRenderPicture(va_dpy, |
518 | 548 | avcenc_context.context_id, |
519 | 549 | va_buffers, |
520 | 550 | num_va_buffers); |
521 | 551 | CHECK_VASTATUS(va_status,"vaRenderPicture"); |
522 | - | |
523 | - va_status = vaRenderPicture(va_dpy, | |
552 | + | |
553 | + for(i = 0; i < avcenc_context.num_slices; i++) { | |
554 | + va_status = vaRenderPicture(va_dpy, | |
524 | 555 | avcenc_context.context_id, |
525 | - &avcenc_context.slice_param_buf_id[0], | |
526 | - avcenc_context.num_slices); | |
527 | - CHECK_VASTATUS(va_status,"vaRenderPicture"); | |
556 | + &avcenc_context.slice_param_buf_id[i], | |
557 | + 1); | |
558 | + CHECK_VASTATUS(va_status,"vaRenderPicture"); | |
559 | + } | |
528 | 560 | |
529 | 561 | va_status = vaEndPicture(va_dpy, avcenc_context.context_id); |
530 | 562 | CHECK_VASTATUS(va_status,"vaEndPicture"); |
@@ -785,8 +817,44 @@ static void sps_rbsp(bitstream *bs) | ||
785 | 817 | bitstream_put_ue(bs, seq_param->frame_crop_top_offset); /* frame_crop_top_offset */ |
786 | 818 | bitstream_put_ue(bs, seq_param->frame_crop_bottom_offset); /* frame_crop_bottom_offset */ |
787 | 819 | } |
820 | + | |
821 | + if ( frame_bit_rate < 0 ) { | |
822 | + bitstream_put_ui(bs, 0, 1); /* vui_parameters_present_flag */ | |
823 | + } else { | |
824 | + bitstream_put_ui(bs, 1, 1); /* vui_parameters_present_flag */ | |
825 | + bitstream_put_ui(bs, 0, 1); /* aspect_ratio_info_present_flag */ | |
826 | + bitstream_put_ui(bs, 0, 1); /* overscan_info_present_flag */ | |
827 | + bitstream_put_ui(bs, 0, 1); /* video_signal_type_present_flag */ | |
828 | + bitstream_put_ui(bs, 0, 1); /* chroma_loc_info_present_flag */ | |
829 | + bitstream_put_ui(bs, 1, 1); /* timing_info_present_flag */ | |
830 | + { | |
831 | + bitstream_put_ui(bs, 15, 32); | |
832 | + bitstream_put_ui(bs, 900, 32); | |
833 | + bitstream_put_ui(bs, 1, 1); | |
834 | + } | |
835 | + bitstream_put_ui(bs, 1, 1); /* nal_hrd_parameters_present_flag */ | |
836 | + { | |
837 | + // hrd_parameters | |
838 | + bitstream_put_ue(bs, 0); /* cpb_cnt_minus1 */ | |
839 | + bitstream_put_ui(bs, 4, 4); /* bit_rate_scale */ | |
840 | + bitstream_put_ui(bs, 6, 4); /* cpb_size_scale */ | |
841 | + | |
842 | + bitstream_put_ue(bs, frame_bit_rate - 1); /* bit_rate_value_minus1[0] */ | |
843 | + bitstream_put_ue(bs, frame_bit_rate*8 - 1); /* cpb_size_value_minus1[0] */ | |
844 | + bitstream_put_ui(bs, 1, 1); /* cbr_flag[0] */ | |
845 | + | |
846 | + bitstream_put_ui(bs, 23, 5); /* initial_cpb_removal_delay_length_minus1 */ | |
847 | + bitstream_put_ui(bs, 23, 5); /* cpb_removal_delay_length_minus1 */ | |
848 | + bitstream_put_ui(bs, 23, 5); /* dpb_output_delay_length_minus1 */ | |
849 | + bitstream_put_ui(bs, 23, 5); /* time_offset_length */ | |
850 | + } | |
851 | + bitstream_put_ui(bs, 0, 1); /* vcl_hrd_parameters_present_flag */ | |
852 | + bitstream_put_ui(bs, 0, 1); /* low_delay_hrd_flag */ | |
853 | + | |
854 | + bitstream_put_ui(bs, 0, 1); /* pic_struct_present_flag */ | |
855 | + bitstream_put_ui(bs, 0, 1); /* bitstream_restriction_flag */ | |
856 | + } | |
788 | 857 | |
789 | - bitstream_put_ui(bs, 0, 1); /* vui_parameters_present_flag */ | |
790 | 858 | rbsp_trailing_bits(bs); /* rbsp_trailing_bits */ |
791 | 859 | } |
792 | 860 |
@@ -1186,10 +1254,15 @@ static void avcenc_context_seq_param_init(VAEncSequenceParameterBufferH264 *seq_ | ||
1186 | 1254 | seq_param->min_bits_per_second = 0; |
1187 | 1255 | } |
1188 | 1256 | |
1189 | - seq_param->initial_hrd_buffer_fullness = 0; /* FIXME: ??? */ | |
1190 | - seq_param->hrd_buffer_size = 0; /* FIXME: ??? */ | |
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 | + } | |
1191 | 1264 | seq_param->time_scale = 900; |
1192 | - seq_param->num_units_in_tick = 15; | |
1265 | + seq_param->num_units_in_tick = 15; /* Tc = num_units_in_tick / time_sacle */ | |
1193 | 1266 | |
1194 | 1267 | if (height_in_mbs * 16 - height) { |
1195 | 1268 | frame_cropping_flag = 1; |
@@ -1208,8 +1281,11 @@ static void avcenc_context_seq_param_init(VAEncSequenceParameterBufferH264 *seq_ | ||
1208 | 1281 | |
1209 | 1282 | seq_param->log2_max_frame_num_minus4 = 0; |
1210 | 1283 | seq_param->log2_max_pic_order_cnt_lsb_minus4 = 2; |
1211 | - | |
1212 | - seq_param->vui_flag = 0; | |
1284 | + | |
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; | |
1213 | 1289 | } |
1214 | 1290 | |
1215 | 1291 | static void avcenc_context_pic_param_init(VAEncPictureParameterBufferH264 *pic_param) |