• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

hardware/intel/intel-driver


Commit MetaInfo

Revisionab776598eeea312b51add08a6ccb7d8ac2793e6b (tree)
Zeit2016-05-27 14:24:35
AutorZhao Yakui <yakui.zhao@inte...>
CommiterXiang, Haihao

Log Message

Add the support of CBR/VBR for Vp9 Encoding

Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Sean V Kelley <sean.v.kelley@intel.com>

Ändern Zusammenfassung

Diff

--- a/src/gen9_vp9_encoder.c
+++ b/src/gen9_vp9_encoder.c
@@ -3858,22 +3858,170 @@ gen9_encode_vp9_check_parameter(VADriverContextP ctx,
38583858 return VA_STATUS_ERROR_UNIMPLEMENTED;
38593859
38603860 if (vp9_state->brc_enabled) {
3861- if (!vp9_state->target_bit_rate && seq_param) {
3862- vp9_state->brc_reset = 1;
3863- vp9_state->target_bit_rate = seq_param->bits_per_second;
3864- vp9_state->gop_size = seq_param->intra_period;
3861+ if (vp9_state->brc_flag_check & VP9_BRC_FAILURE) {
3862+ WARN_ONCE("Rate control misc_parameter is required for BRC\n");
3863+ return VA_STATUS_ERROR_INVALID_PARAMETER;
38653864 }
38663865
3867- if (vp9_state->target_bit_rate != seq_param->bits_per_second) {
3868- vp9_state->brc_reset = 1;
3869- vp9_state->target_bit_rate = seq_param->bits_per_second;
3870- }
3871- if (vp9_state->gop_size != seq_param->intra_period) {
3872- vp9_state->brc_reset = 1;
3873- vp9_state->gop_size = seq_param->intra_period;
3866+ if (vp9_state->first_frame) {
3867+ unsigned int brc_flag;
3868+ VAEncMiscParameterBuffer *misc_param;
3869+
3870+ brc_flag = VP9_BRC_SEQ | VP9_BRC_RC;
3871+ if ((vp9_state->brc_flag_check & brc_flag) != brc_flag) {
3872+ WARN_ONCE("SPS/RC misc is required for BRC\n");
3873+ return VA_STATUS_ERROR_INVALID_PARAMETER;
3874+ }
3875+
3876+ /* check the corresponding BRC parameter for CBR and VBR */
3877+ if (encoder_context->rate_control_mode == VA_RC_CBR) {
3878+ vp9_state->target_bit_rate = seq_param->bits_per_second;
3879+ vp9_state->gop_size = seq_param->intra_period;
3880+
3881+ if (vp9_state->brc_flag_check & VP9_BRC_HRD) {
3882+ VAEncMiscParameterHRD *misc_param_hrd;
3883+
3884+ misc_param = (VAEncMiscParameterBuffer *)
3885+ encode_state->misc_param[VAEncMiscParameterTypeHRD]->buffer;
3886+ misc_param_hrd = (VAEncMiscParameterHRD *)misc_param->data;
3887+
3888+ vp9_state->init_vbv_buffer_fullness_in_bit = misc_param_hrd->initial_buffer_fullness;
3889+ vp9_state->vbv_buffer_size_in_bit = misc_param_hrd->buffer_size;
3890+ }
3891+
3892+ if (vp9_state->brc_flag_check & VP9_BRC_FR) {
3893+ VAEncMiscParameterFrameRate *misc_param_fr;
3894+
3895+ misc_param = (VAEncMiscParameterBuffer *)
3896+ encode_state->misc_param[VAEncMiscParameterTypeFrameRate]->buffer;
3897+ misc_param_fr = (VAEncMiscParameterFrameRate *)misc_param->data;
3898+
3899+ vp9_state->frame_rate = misc_param_fr->framerate;
3900+ } else {
3901+ /* Assign the default frame rate */
3902+ vp9_state->frame_rate = 30;
3903+ }
3904+
3905+ /* RC misc will override HRD parameter */
3906+ if (vp9_state->brc_flag_check & VP9_BRC_RC) {
3907+ VAEncMiscParameterRateControl *misc_param_rc;
3908+
3909+ misc_param = (VAEncMiscParameterBuffer *)
3910+ encode_state->misc_param[VAEncMiscParameterTypeRateControl]->buffer;
3911+ misc_param_rc = (VAEncMiscParameterRateControl *)misc_param->data;
3912+
3913+ vp9_state->target_bit_rate = misc_param_rc->bits_per_second;
3914+ vp9_state->vbv_buffer_size_in_bit = (misc_param_rc->bits_per_second / 1000) *
3915+ misc_param_rc->window_size;
3916+ vp9_state->init_vbv_buffer_fullness_in_bit = vp9_state->vbv_buffer_size_in_bit / 2;
3917+ vp9_state->window_size = misc_param_rc->window_size;
3918+ }
3919+ vp9_state->max_bit_rate = vp9_state->target_bit_rate;
3920+ vp9_state->min_bit_rate = vp9_state->target_bit_rate;
3921+ } else {
3922+ /* VBR mode */
3923+ brc_flag = VP9_BRC_SEQ | VP9_BRC_RC;
3924+ vp9_state->target_bit_rate = seq_param->bits_per_second;
3925+ vp9_state->gop_size = seq_param->intra_period;
3926+
3927+ if (vp9_state->brc_flag_check & VP9_BRC_FR) {
3928+ VAEncMiscParameterFrameRate *misc_param_fr;
3929+
3930+ misc_param = (VAEncMiscParameterBuffer *)
3931+ encode_state->misc_param[VAEncMiscParameterTypeFrameRate]->buffer;
3932+ misc_param_fr = (VAEncMiscParameterFrameRate *)misc_param->data;
3933+
3934+ vp9_state->frame_rate = misc_param_fr->framerate;
3935+ } else {
3936+ /* Assign the default frame rate */
3937+ vp9_state->frame_rate = 30;
3938+ }
3939+
3940+ if (vp9_state->brc_flag_check & VP9_BRC_RC) {
3941+ VAEncMiscParameterRateControl *misc_param_rc;
3942+
3943+ misc_param = (VAEncMiscParameterBuffer *)
3944+ encode_state->misc_param[VAEncMiscParameterTypeRateControl]->buffer;
3945+ misc_param_rc = (VAEncMiscParameterRateControl *)misc_param->data;
3946+
3947+ vp9_state->max_bit_rate = misc_param_rc->bits_per_second;
3948+ vp9_state->vbv_buffer_size_in_bit = (misc_param_rc->bits_per_second / 1000) *
3949+ misc_param_rc->window_size;
3950+ vp9_state->init_vbv_buffer_fullness_in_bit = vp9_state->vbv_buffer_size_in_bit / 2;
3951+ vp9_state->target_bit_rate = (misc_param_rc->bits_per_second / 100) *
3952+ misc_param_rc->target_percentage;
3953+ vp9_state->min_bit_rate = (misc_param_rc->bits_per_second / 100) *
3954+ (2 * misc_param_rc->target_percentage - 100);
3955+ vp9_state->target_percentage = misc_param_rc->target_percentage;
3956+ vp9_state->window_size = misc_param_rc->window_size;
3957+ }
3958+ }
38743959 }
3960+ else if (vp9_state->picture_coding_type == KEY_FRAME){
3961+ VAEncMiscParameterBuffer *misc_param;
3962+ /* update the BRC parameter only when it is key-frame */
3963+ /* If the parameter related with RC is changed. Reset BRC */
3964+ if (vp9_state->brc_flag_check & VP9_BRC_FR) {
3965+ VAEncMiscParameterFrameRate *misc_param_fr;
3966+
3967+ misc_param = (VAEncMiscParameterBuffer *)
3968+ encode_state->misc_param[VAEncMiscParameterTypeFrameRate]->buffer;
3969+ misc_param_fr = (VAEncMiscParameterFrameRate *)misc_param->data;
3970+
3971+ if (vp9_state->frame_rate != misc_param_fr->framerate) {
3972+ vp9_state->brc_reset = 1;
3973+ vp9_state->frame_rate = misc_param_fr->framerate;
3974+ }
3975+ }
3976+
3977+ /* check the GOP size. And bit_per_second in SPS is ignored */
3978+ if (vp9_state->brc_flag_check & VP9_BRC_SEQ) {
3979+ if (vp9_state->gop_size != seq_param->intra_period) {
3980+ vp9_state->brc_reset = 1;
3981+ vp9_state->gop_size = seq_param->intra_period;
3982+ }
3983+ }
38753984
3876- /* check Misc Rate_Control, Frame_rate buffer */
3985+ /* update the bit_per_second */
3986+ if (vp9_state->brc_flag_check & VP9_BRC_RC) {
3987+ VAEncMiscParameterRateControl *misc_param_rc;
3988+
3989+ misc_param = (VAEncMiscParameterBuffer *)
3990+ encode_state->misc_param[VAEncMiscParameterTypeRateControl]->buffer;
3991+ misc_param_rc = (VAEncMiscParameterRateControl *)misc_param->data;
3992+
3993+ if (encoder_context->rate_control_mode == VA_RC_CBR) {
3994+ if (vp9_state->target_bit_rate != misc_param_rc->bits_per_second ||
3995+ vp9_state->window_size != misc_param_rc->window_size) {
3996+ vp9_state->target_bit_rate = misc_param_rc->bits_per_second;
3997+ vp9_state->vbv_buffer_size_in_bit = (misc_param_rc->bits_per_second / 1000) *
3998+ misc_param_rc->window_size;
3999+ vp9_state->init_vbv_buffer_fullness_in_bit = vp9_state->vbv_buffer_size_in_bit * 2;
4000+ vp9_state->window_size = misc_param_rc->window_size;
4001+ vp9_state->max_bit_rate = vp9_state->target_bit_rate;
4002+ vp9_state->min_bit_rate = vp9_state->target_bit_rate;
4003+ vp9_state->brc_reset = 1;
4004+ }
4005+ } else {
4006+ /* VBR mode */
4007+ if (vp9_state->max_bit_rate != misc_param_rc->bits_per_second ||
4008+ vp9_state->target_percentage != misc_param_rc->target_percentage) {
4009+
4010+ vp9_state->target_bit_rate = (misc_param_rc->bits_per_second / 100) *
4011+ misc_param_rc->target_percentage;
4012+ vp9_state->min_bit_rate = (misc_param_rc->bits_per_second / 100) *
4013+ (2 * misc_param_rc->target_percentage - 100);
4014+ vp9_state->max_bit_rate = misc_param_rc->bits_per_second;
4015+ vp9_state->vbv_buffer_size_in_bit = (misc_param_rc->bits_per_second / 1000) *
4016+ misc_param_rc->window_size;
4017+ vp9_state->init_vbv_buffer_fullness_in_bit = vp9_state->vbv_buffer_size_in_bit / 2;
4018+ vp9_state->target_percentage = misc_param_rc->target_percentage;
4019+ vp9_state->window_size = misc_param_rc->window_size;
4020+ vp9_state->brc_reset = 1;
4021+ }
4022+ }
4023+ }
4024+ }
38774025 }
38784026
38794027 vp9_state->frame_width = pic_param->frame_width_dst;
@@ -3960,7 +4108,8 @@ gen9_encode_vp9_check_parameter(VADriverContextP ctx,
39604108 vp9_state->b16xme_enabled = 0;
39614109 }
39624110
3963- if (vp9_state->picture_coding_type &&
4111+ vp9_state->mbenc_keyframe_dist_enabled = 0;
4112+ if ((vp9_state->picture_coding_type == KEY_FRAME) &&
39644113 vp9_state->brc_distortion_buffer_supported)
39654114 vp9_state->mbenc_keyframe_dist_enabled = 1;
39664115
@@ -5706,6 +5855,7 @@ gen9_vp9_pak_pipeline(VADriverContextP ctx,
57065855 vp9_state->vp9_last_frame.intra_only = pic_param->pic_flags.bits.intra_only;
57075856 vp9_state->frame_number++;
57085857 vp9_state->curr_mv_temporal_index ^= 1;
5858+ vp9_state->first_frame = 0;
57095859
57105860 return VA_STATUS_SUCCESS;
57115861 }
--- a/src/gen9_vp9_encoder.h
+++ b/src/gen9_vp9_encoder.h
@@ -1927,6 +1927,8 @@ struct gen9_vp9_state {
19271927 unsigned int adaptive_transform_decision_enabled;
19281928 int curr_mode_decision_index;
19291929 int target_usage;
1930+ int window_size;
1931+ int target_percentage;
19301932 unsigned int mb_data_offset;
19311933 int curr_pak_pass;
19321934 unsigned int brc_flag_check;