hardware/intel/libva
リビジョン | f47cb0027cdf7bc21a3d7bed595af102dddbb3a9 (tree) |
---|---|
日時 | 2014-09-09 02:18:54 |
作者 | Zhao Yakui <yakui.zhao@inte...> |
コミッター | Xiang, Haihao |
test/avcenc: Fix the incorrect parameter setting for SPS under CBR mode
Currently the parameter setting is incorrect for CBR, which causes that
it will complain the underflow/overflow during encoding.
V1->V2: Follow Haihao's comment to update some incorrect usage about the
frame_bit_rate.
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
(cherry picked from commit 5e10a246287fa2dd3fae2bf756a5b33087cc097c)
@@ -88,6 +88,8 @@ static int qp_value = 26; | ||
88 | 88 | static int intra_period = 30; |
89 | 89 | static int pb_period = 5; |
90 | 90 | static int frame_bit_rate = -1; |
91 | +static int frame_rate = 30; | |
92 | +static int ip_period = 1; | |
91 | 93 | |
92 | 94 | #define MAX_SLICES 32 |
93 | 95 |
@@ -596,8 +598,8 @@ static int begin_picture(FILE *yuv_fp, int frame_num, int display_num, int slice | ||
596 | 598 | misc_hrd_param = (VAEncMiscParameterHRD *)misc_param->data; |
597 | 599 | |
598 | 600 | if (frame_bit_rate > 0) { |
599 | - misc_hrd_param->initial_buffer_fullness = frame_bit_rate * 1024 * 4; | |
600 | - misc_hrd_param->buffer_size = frame_bit_rate * 1024 * 8; | |
601 | + misc_hrd_param->initial_buffer_fullness = frame_bit_rate * 1000 * 4; | |
602 | + misc_hrd_param->buffer_size = frame_bit_rate * 1000 * 8; | |
601 | 603 | } else { |
602 | 604 | misc_hrd_param->initial_buffer_fullness = 0; |
603 | 605 | misc_hrd_param->buffer_size = 0; |
@@ -943,19 +945,20 @@ static void sps_rbsp(bitstream *bs) | ||
943 | 945 | bitstream_put_ui(bs, 0, 1); /* chroma_loc_info_present_flag */ |
944 | 946 | bitstream_put_ui(bs, 1, 1); /* timing_info_present_flag */ |
945 | 947 | { |
946 | - bitstream_put_ui(bs, 15, 32); | |
947 | - bitstream_put_ui(bs, 900, 32); | |
948 | + bitstream_put_ui(bs, 1, 32); | |
949 | + bitstream_put_ui(bs, frame_rate * 2, 32); | |
948 | 950 | bitstream_put_ui(bs, 1, 1); |
949 | 951 | } |
950 | 952 | bitstream_put_ui(bs, 1, 1); /* nal_hrd_parameters_present_flag */ |
951 | 953 | { |
952 | 954 | // hrd_parameters |
953 | 955 | bitstream_put_ue(bs, 0); /* cpb_cnt_minus1 */ |
954 | - bitstream_put_ui(bs, 4, 4); /* bit_rate_scale */ | |
955 | - bitstream_put_ui(bs, 6, 4); /* cpb_size_scale */ | |
956 | + bitstream_put_ui(bs, 0, 4); /* bit_rate_scale */ | |
957 | + bitstream_put_ui(bs, 2, 4); /* cpb_size_scale */ | |
956 | 958 | |
957 | - bitstream_put_ue(bs, frame_bit_rate - 1); /* bit_rate_value_minus1[0] */ | |
958 | - bitstream_put_ue(bs, frame_bit_rate*8 - 1); /* cpb_size_value_minus1[0] */ | |
959 | + /* the frame_bit_rate is in kbps */ | |
960 | + bitstream_put_ue(bs, (((frame_bit_rate * 1000)>> 6) - 1)); /* bit_rate_value_minus1[0] */ | |
961 | + bitstream_put_ue(bs, ((frame_bit_rate * 8000) >> 6) - 1); /* cpb_size_value_minus1[0] */ | |
959 | 962 | bitstream_put_ui(bs, 1, 1); /* cbr_flag[0] */ |
960 | 963 | |
961 | 964 | bitstream_put_ui(bs, 23, 5); /* initial_cpb_removal_delay_length_minus1 */ |
@@ -1395,7 +1398,7 @@ static void avcenc_context_seq_param_init(VAEncSequenceParameterBufferH264 *seq_ | ||
1395 | 1398 | seq_param->seq_parameter_set_id = 0; |
1396 | 1399 | seq_param->level_idc = 41; |
1397 | 1400 | seq_param->intra_period = intra_period; |
1398 | - seq_param->ip_period = 0; /* FIXME: ??? */ | |
1401 | + seq_param->ip_period = ip_period; | |
1399 | 1402 | seq_param->max_num_ref_frames = 4; |
1400 | 1403 | seq_param->picture_width_in_mbs = width_in_mbs; |
1401 | 1404 | seq_param->picture_height_in_mbs = height_in_mbs; |
@@ -1404,12 +1407,12 @@ static void avcenc_context_seq_param_init(VAEncSequenceParameterBufferH264 *seq_ | ||
1404 | 1407 | |
1405 | 1408 | |
1406 | 1409 | if (frame_bit_rate > 0) |
1407 | - seq_param->bits_per_second = 1024 * frame_bit_rate; /* use kbps as input */ | |
1410 | + seq_param->bits_per_second = 1000 * frame_bit_rate; /* use kbps as input */ | |
1408 | 1411 | else |
1409 | 1412 | seq_param->bits_per_second = 0; |
1410 | 1413 | |
1411 | - seq_param->time_scale = 900; | |
1412 | - seq_param->num_units_in_tick = 15; /* Tc = num_units_in_tick / time_sacle */ | |
1414 | + seq_param->time_scale = frame_rate * 2; | |
1415 | + seq_param->num_units_in_tick = 1; /* Tc = num_units_in_tick / time_sacle */ | |
1413 | 1416 | |
1414 | 1417 | if (height_in_mbs * 16 - height) { |
1415 | 1418 | frame_cropping_flag = 1; |
@@ -1581,14 +1584,18 @@ int main(int argc, char *argv[]) | ||
1581 | 1584 | if ( mode_value == 0 ) { |
1582 | 1585 | i_frame_only = 1; |
1583 | 1586 | i_p_frame_only = 0; |
1587 | + ip_period = 0; | |
1584 | 1588 | } |
1585 | 1589 | else if ( mode_value == 1) { |
1586 | 1590 | i_frame_only = 0; |
1587 | 1591 | i_p_frame_only = 1; |
1592 | + ip_period = 1; | |
1588 | 1593 | } |
1589 | 1594 | else if ( mode_value == 2 ) { |
1590 | 1595 | i_frame_only = 0; |
1591 | 1596 | i_p_frame_only = 0; |
1597 | + /* Hack mechanism before adding the parameter of B-frame number */ | |
1598 | + ip_period = 3; | |
1592 | 1599 | } |
1593 | 1600 | else { |
1594 | 1601 | printf("mode_value=%d\n",mode_value); |