diff options
author | Xiang, Haihao <haihao.xiang@intel.com> | 2016-09-13 16:02:45 +0800 |
---|---|---|
committer | Sean V Kelley <seanvk@posteo.de> | 2016-09-16 10:51:01 -0700 |
commit | 415ee5976f1d18a840918f96869e529d3a2fb1ce (patch) | |
tree | d529974c09edff40d697d0dc91afa60b5b95932b /src/gen6_mfc_common.c | |
parent | 2da21333293029d360eb071e1a05b390329fbb55 (diff) | |
download | libva-intel-driver-415ee5976f1d18a840918f96869e529d3a2fb1ce.tar.gz |
Initialize internal related parameters per temporal layer for H.264 BRC
v2: rebased
Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
Tested-by: Luo, Focus <focus.luo@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Diffstat (limited to 'src/gen6_mfc_common.c')
-rw-r--r-- | src/gen6_mfc_common.c | 70 |
1 files changed, 42 insertions, 28 deletions
diff --git a/src/gen6_mfc_common.c b/src/gen6_mfc_common.c index 0a8720b8..ff3e3ae5 100644 --- a/src/gen6_mfc_common.c +++ b/src/gen6_mfc_common.c @@ -94,34 +94,22 @@ static void intel_mfc_brc_init(struct encode_state *encode_state, struct intel_encoder_context* encoder_context) { struct gen6_mfc_context *mfc_context = encoder_context->mfc_context; - double bitrate = encoder_context->brc.bits_per_second[0]; - double framerate = (double)encoder_context->brc.framerate_per_100s[0] / 100.0; + double bitrate, framerate; + double qp1_size = 0.1 * 8 * 3 * encoder_context->frame_width_in_pixel * encoder_context->frame_height_in_pixel / 2; + double qp51_size = 0.001 * 8 * 3 * encoder_context->frame_width_in_pixel * encoder_context->frame_height_in_pixel / 2; + double bpf, factor; int inum = encoder_context->brc.num_iframes_in_gop, pnum = encoder_context->brc.num_pframes_in_gop, bnum = encoder_context->brc.num_bframes_in_gop; /* Gop structure: number of I, P, B frames in the Gop. */ int intra_period = encoder_context->brc.gop_size; - double qp1_size = 0.1 * 8 * 3 * encoder_context->frame_width_in_pixel * encoder_context->frame_height_in_pixel / 2; - double qp51_size = 0.001 * 8 * 3 * encoder_context->frame_width_in_pixel * encoder_context->frame_height_in_pixel / 2; - double bpf; int i; mfc_context->brc.mode = encoder_context->rate_control_mode; - for (i = 0; i < 3; i++) { - mfc_context->brc.qp_prime_y[0][i] = 26; - } - - mfc_context->brc.target_frame_size[0][SLICE_TYPE_I] = (int)((double)((bitrate * intra_period)/framerate) / - (double)(inum + BRC_PWEIGHT * pnum + BRC_BWEIGHT * bnum)); - mfc_context->brc.target_frame_size[0][SLICE_TYPE_P] = BRC_PWEIGHT * mfc_context->brc.target_frame_size[0][SLICE_TYPE_I]; - mfc_context->brc.target_frame_size[0][SLICE_TYPE_B] = BRC_BWEIGHT * mfc_context->brc.target_frame_size[0][SLICE_TYPE_I]; - mfc_context->brc.gop_nums[SLICE_TYPE_I] = inum; mfc_context->brc.gop_nums[SLICE_TYPE_P] = pnum; mfc_context->brc.gop_nums[SLICE_TYPE_B] = bnum; - bpf = mfc_context->brc.bits_per_frame[0] = bitrate/framerate; - mfc_context->hrd.buffer_size = encoder_context->brc.hrd_buffer_size; mfc_context->hrd.current_buffer_fullness = (double)(encoder_context->brc.hrd_initial_buffer_fullness < mfc_context->hrd.buffer_size) ? @@ -130,20 +118,46 @@ static void intel_mfc_brc_init(struct encode_state *encode_state, mfc_context->hrd.buffer_capacity = (double)mfc_context->hrd.buffer_size/qp1_size; mfc_context->hrd.violation_noted = 0; - if ((bpf > qp51_size) && (bpf < qp1_size)) { - mfc_context->brc.qp_prime_y[0][SLICE_TYPE_P] = 51 - 50*(bpf - qp51_size)/(qp1_size - qp51_size); - } - else if (bpf >= qp1_size) - mfc_context->brc.qp_prime_y[0][SLICE_TYPE_P] = 1; - else if (bpf <= qp51_size) - mfc_context->brc.qp_prime_y[0][SLICE_TYPE_P] = 51; + for (i = 0; i < encoder_context->layer.num_layers; i++) { + mfc_context->brc.qp_prime_y[i][SLICE_TYPE_I] = 26; + mfc_context->brc.qp_prime_y[i][SLICE_TYPE_P] = 26; + mfc_context->brc.qp_prime_y[i][SLICE_TYPE_B] = 26; - mfc_context->brc.qp_prime_y[0][SLICE_TYPE_I] = mfc_context->brc.qp_prime_y[0][SLICE_TYPE_P]; - mfc_context->brc.qp_prime_y[0][SLICE_TYPE_B] = mfc_context->brc.qp_prime_y[0][SLICE_TYPE_I]; + if (i == 0) { + bitrate = encoder_context->brc.bits_per_second[0]; + framerate = (double)encoder_context->brc.framerate_per_100s[0] / 100.0; + } else { + bitrate = (encoder_context->brc.bits_per_second[i] - encoder_context->brc.bits_per_second[i - 1]); + framerate = (double)(encoder_context->brc.framerate_per_100s[i] - encoder_context->brc.framerate_per_100s[i - 1]) / 100.0; + } + + if (i == encoder_context->layer.num_layers - 1) + factor = 1.0; + else + factor = (double)encoder_context->brc.framerate_per_100s[i] / encoder_context->brc.framerate_per_100s[i + 1]; + + mfc_context->brc.target_frame_size[i][SLICE_TYPE_I] = (int)((double)((bitrate * intra_period * factor)/framerate) / + (double)(inum + BRC_PWEIGHT * pnum * factor + BRC_BWEIGHT * bnum * factor)); + mfc_context->brc.target_frame_size[i][SLICE_TYPE_P] = BRC_PWEIGHT * mfc_context->brc.target_frame_size[i][SLICE_TYPE_I]; + mfc_context->brc.target_frame_size[i][SLICE_TYPE_B] = BRC_BWEIGHT * mfc_context->brc.target_frame_size[i][SLICE_TYPE_I]; + + bpf = mfc_context->brc.bits_per_frame[i] = bitrate/framerate; - BRC_CLIP(mfc_context->brc.qp_prime_y[0][SLICE_TYPE_I], 1, 51); - BRC_CLIP(mfc_context->brc.qp_prime_y[0][SLICE_TYPE_P], 1, 51); - BRC_CLIP(mfc_context->brc.qp_prime_y[0][SLICE_TYPE_B], 1, 51); + if ((bpf > qp51_size) && (bpf < qp1_size)) { + mfc_context->brc.qp_prime_y[i][SLICE_TYPE_P] = 51 - 50*(bpf - qp51_size)/(qp1_size - qp51_size); + } + else if (bpf >= qp1_size) + mfc_context->brc.qp_prime_y[i][SLICE_TYPE_P] = 1; + else if (bpf <= qp51_size) + mfc_context->brc.qp_prime_y[i][SLICE_TYPE_P] = 51; + + mfc_context->brc.qp_prime_y[i][SLICE_TYPE_I] = mfc_context->brc.qp_prime_y[i][SLICE_TYPE_P]; + mfc_context->brc.qp_prime_y[i][SLICE_TYPE_B] = mfc_context->brc.qp_prime_y[i][SLICE_TYPE_I]; + + BRC_CLIP(mfc_context->brc.qp_prime_y[i][SLICE_TYPE_I], 1, 51); + BRC_CLIP(mfc_context->brc.qp_prime_y[i][SLICE_TYPE_P], 1, 51); + BRC_CLIP(mfc_context->brc.qp_prime_y[i][SLICE_TYPE_B], 1, 51); + } } int intel_mfc_update_hrd(struct encode_state *encode_state, |