Discussion:
[Libva-intel-driver][PATCH v2 0/3] Save all common misc paramters in the common context
(too old to reply)
Xiang, Haihao
2016-11-29 04:33:05 UTC
Permalink
The patch series saves some misc parameters in the common context
because these parameters can be used for all codecs and cleans up the the
corresponding code in VDEnc.

Xiang, Haihao (1):
Don't parse Misc parameters in VDEnc

peng.chen (2):
Save ROI parameters in the common encoder context
Save other bitrate control parameters in the common encoder context

src/gen9_vdenc.c | 160 +++++++++++------------------------------------------
src/i965_encoder.c | 49 +++++++++++++++-
src/i965_encoder.h | 8 +++
3 files changed, 89 insertions(+), 128 deletions(-)
--
1.9.1
Xiang, Haihao
2016-11-29 04:33:06 UTC
Permalink
From: "peng.chen" <***@intel.com>

These parameters can be used for all codecs

v2: Don't align ROI region, each codec might have
special requirement

Signed-off-by: peng.chen <***@intel.com>
Signed-off-by: Xiang, Haihao <***@intel.com>
---
src/i965_encoder.c | 35 +++++++++++++++++++++++++++++++++++
src/i965_encoder.h | 6 ++++++
2 files changed, 41 insertions(+)

diff --git a/src/i965_encoder.c b/src/i965_encoder.c
index 4ef92eb..4aa3ee1 100644
--- a/src/i965_encoder.c
+++ b/src/i965_encoder.c
@@ -438,6 +438,30 @@ intel_encoder_check_framerate_parameter(VADriverContextP ctx,
}
}

+static void
+intel_encoder_check_roi_parameter(VADriverContextP ctx,
+ struct intel_encoder_context *encoder_context,
+ VAEncMiscParameterBufferROI *misc)
+{
+ int i = 0;
+
+ encoder_context->brc.num_roi = MIN(misc->num_roi, I965_MAX_NUM_ROI_REGIONS);
+ encoder_context->brc.roi_max_delta_qp = misc->max_delta_qp;
+ encoder_context->brc.roi_min_delta_qp = misc->min_delta_qp;
+ encoder_context->brc.roi_value_is_qp_delta = 0;
+
+ if (encoder_context->rate_control_mode != VA_RC_CQP)
+ encoder_context->brc.roi_value_is_qp_delta = misc->roi_flags.bits.roi_value_is_qp_delta;
+
+ for (i = 0; i < encoder_context->brc.num_roi; i++) {
+ encoder_context->brc.roi[i].left = misc->roi->roi_rectangle.x;
+ encoder_context->brc.roi[i].right = encoder_context->brc.roi[i].left + misc->roi->roi_rectangle.width;
+ encoder_context->brc.roi[i].top = misc->roi->roi_rectangle.y;
+ encoder_context->brc.roi[i].bottom = encoder_context->brc.roi[i].top + misc->roi->roi_rectangle.height;
+ encoder_context->brc.roi[i].value = misc->roi->roi_value;
+ }
+}
+
static VAStatus
intel_encoder_check_brc_parameter(VADriverContextP ctx,
struct encode_state *encode_state,
@@ -481,6 +505,12 @@ intel_encoder_check_brc_parameter(VADriverContextP ctx,
(VAEncMiscParameterHRD *)misc_param->data);
break;

+ case VAEncMiscParameterTypeROI:
+ intel_encoder_check_roi_parameter(ctx,
+ encoder_context,
+ (VAEncMiscParameterBufferROI *)misc_param->data);
+ break;
+
default:
break;
}
@@ -1056,6 +1086,11 @@ intel_encoder_end_picture(VADriverContextP ctx,
encoder_context->mfc_pipeline(ctx, profile, encode_state, encoder_context);
encoder_context->num_frames_in_sequence++;
encoder_context->brc.need_reset = 0;
+ /*
+ * ROI is only available for the current frame, see the comment
+ * for VAEncROI in va.h
+ */
+ encoder_context->brc.num_roi = 0;

return VA_STATUS_SUCCESS;
}
diff --git a/src/i965_encoder.h b/src/i965_encoder.h
index ba31364..fe5a595 100644
--- a/src/i965_encoder.h
+++ b/src/i965_encoder.h
@@ -84,6 +84,12 @@ struct intel_encoder_context
unsigned int hrd_buffer_size;
unsigned int hrd_initial_buffer_fullness;
unsigned int need_reset;
+
+ unsigned int num_roi;
+ unsigned int roi_max_delta_qp;
+ unsigned int roi_min_delta_qp;
+ unsigned int roi_value_is_qp_delta;
+ struct intel_roi roi[I965_MAX_NUM_ROI_REGIONS];
} brc;

void *vme_context;
--
1.9.1
Zhao Yakui
2016-11-30 00:21:31 UTC
Permalink
Post by Xiang, Haihao
These parameters can be used for all codecs
v2: Don't align ROI region, each codec might have
special requirement
This looks fine to me.

Thanks
Post by Xiang, Haihao
---
src/i965_encoder.c | 35 +++++++++++++++++++++++++++++++++++
src/i965_encoder.h | 6 ++++++
2 files changed, 41 insertions(+)
diff --git a/src/i965_encoder.c b/src/i965_encoder.c
index 4ef92eb..4aa3ee1 100644
--- a/src/i965_encoder.c
+++ b/src/i965_encoder.c
@@ -438,6 +438,30 @@ intel_encoder_check_framerate_parameter(VADriverContextP ctx,
}
}
+static void
+intel_encoder_check_roi_parameter(VADriverContextP ctx,
+ struct intel_encoder_context *encoder_context,
+ VAEncMiscParameterBufferROI *misc)
+{
+ int i = 0;
+
+ encoder_context->brc.num_roi = MIN(misc->num_roi, I965_MAX_NUM_ROI_REGIONS);
+ encoder_context->brc.roi_max_delta_qp = misc->max_delta_qp;
+ encoder_context->brc.roi_min_delta_qp = misc->min_delta_qp;
+ encoder_context->brc.roi_value_is_qp_delta = 0;
+
+ if (encoder_context->rate_control_mode != VA_RC_CQP)
+ encoder_context->brc.roi_value_is_qp_delta = misc->roi_flags.bits.roi_value_is_qp_delta;
+
+ for (i = 0; i< encoder_context->brc.num_roi; i++) {
+ encoder_context->brc.roi[i].left = misc->roi->roi_rectangle.x;
+ encoder_context->brc.roi[i].right = encoder_context->brc.roi[i].left + misc->roi->roi_rectangle.width;
+ encoder_context->brc.roi[i].top = misc->roi->roi_rectangle.y;
+ encoder_context->brc.roi[i].bottom = encoder_context->brc.roi[i].top + misc->roi->roi_rectangle.height;
+ encoder_context->brc.roi[i].value = misc->roi->roi_value;
+ }
+}
+
static VAStatus
intel_encoder_check_brc_parameter(VADriverContextP ctx,
struct encode_state *encode_state,
@@ -481,6 +505,12 @@ intel_encoder_check_brc_parameter(VADriverContextP ctx,
(VAEncMiscParameterHRD *)misc_param->data);
break;
+ intel_encoder_check_roi_parameter(ctx,
+ encoder_context,
+ (VAEncMiscParameterBufferROI *)misc_param->data);
+ break;
+
break;
}
@@ -1056,6 +1086,11 @@ intel_encoder_end_picture(VADriverContextP ctx,
encoder_context->mfc_pipeline(ctx, profile, encode_state, encoder_context);
encoder_context->num_frames_in_sequence++;
encoder_context->brc.need_reset = 0;
+ /*
+ * ROI is only available for the current frame, see the comment
+ * for VAEncROI in va.h
+ */
+ encoder_context->brc.num_roi = 0;
return VA_STATUS_SUCCESS;
}
diff --git a/src/i965_encoder.h b/src/i965_encoder.h
index ba31364..fe5a595 100644
--- a/src/i965_encoder.h
+++ b/src/i965_encoder.h
@@ -84,6 +84,12 @@ struct intel_encoder_context
unsigned int hrd_buffer_size;
unsigned int hrd_initial_buffer_fullness;
unsigned int need_reset;
+
+ unsigned int num_roi;
+ unsigned int roi_max_delta_qp;
+ unsigned int roi_min_delta_qp;
+ unsigned int roi_value_is_qp_delta;
+ struct intel_roi roi[I965_MAX_NUM_ROI_REGIONS];
} brc;
void *vme_context;
Xiang, Haihao
2016-11-29 04:33:07 UTC
Permalink
From: "peng.chen" <***@intel.com>

These parameters can be used for all codecs

v2: Save mb_rate_control/target_percentage per layer too

Signed-off-by: peng.chen <***@intel.com>
Signed-off-by: Xiang, Haihao <***@intel.com>
---
src/i965_encoder.c | 14 +++++++++++++-
src/i965_encoder.h | 2 ++
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/i965_encoder.c b/src/i965_encoder.c
index 4aa3ee1..bca8ebd 100644
--- a/src/i965_encoder.c
+++ b/src/i965_encoder.c
@@ -393,11 +393,23 @@ intel_encoder_check_rate_control_parameter(VADriverContextP ctx,
if (temporal_id >= encoder_context->layer.num_layers)
return;

- // TODO: for VBR
+ if (misc->rc_flags.bits.reset)
+ encoder_context->brc.need_reset = 1;
+
if (encoder_context->brc.bits_per_second[temporal_id] != misc->bits_per_second) {
encoder_context->brc.bits_per_second[temporal_id] = misc->bits_per_second;
encoder_context->brc.need_reset = 1;
}
+
+ if (encoder_context->brc.mb_rate_control[temporal_id] != misc->rc_flags.bits.mb_rate_control) {
+ encoder_context->brc.mb_rate_control[temporal_id] = misc->rc_flags.bits.mb_rate_control;
+ encoder_context->brc.need_reset = 1;
+ }
+
+ if (encoder_context->brc.target_percentage[temporal_id] != misc->target_percentage) {
+ encoder_context->brc.target_percentage[temporal_id] = misc->target_percentage;
+ encoder_context->brc.need_reset = 1;
+ }
}

static void
diff --git a/src/i965_encoder.h b/src/i965_encoder.h
index fe5a595..0b636d6 100644
--- a/src/i965_encoder.h
+++ b/src/i965_encoder.h
@@ -81,6 +81,8 @@ struct intel_encoder_context
unsigned short num_bframes_in_gop;
unsigned int bits_per_second[MAX_TEMPORAL_LAYERS];
unsigned int framerate_per_100s[MAX_TEMPORAL_LAYERS];
+ unsigned int mb_rate_control[MAX_TEMPORAL_LAYERS];
+ unsigned int target_percentage[MAX_TEMPORAL_LAYERS];
unsigned int hrd_buffer_size;
unsigned int hrd_initial_buffer_fullness;
unsigned int need_reset;
--
1.9.1
Zhao Yakui
2016-11-30 00:22:10 UTC
Permalink
Post by Xiang, Haihao
These parameters can be used for all codecs
This looks fine to me.

Thanks
Post by Xiang, Haihao
v2: Save mb_rate_control/target_percentage per layer too
---
src/i965_encoder.c | 14 +++++++++++++-
src/i965_encoder.h | 2 ++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/i965_encoder.c b/src/i965_encoder.c
index 4aa3ee1..bca8ebd 100644
--- a/src/i965_encoder.c
+++ b/src/i965_encoder.c
@@ -393,11 +393,23 @@ intel_encoder_check_rate_control_parameter(VADriverContextP ctx,
if (temporal_id>= encoder_context->layer.num_layers)
return;
- // TODO: for VBR
+ if (misc->rc_flags.bits.reset)
+ encoder_context->brc.need_reset = 1;
+
if (encoder_context->brc.bits_per_second[temporal_id] != misc->bits_per_second) {
encoder_context->brc.bits_per_second[temporal_id] = misc->bits_per_second;
encoder_context->brc.need_reset = 1;
}
+
+ if (encoder_context->brc.mb_rate_control[temporal_id] != misc->rc_flags.bits.mb_rate_control) {
+ encoder_context->brc.mb_rate_control[temporal_id] = misc->rc_flags.bits.mb_rate_control;
+ encoder_context->brc.need_reset = 1;
+ }
+
+ if (encoder_context->brc.target_percentage[temporal_id] != misc->target_percentage) {
+ encoder_context->brc.target_percentage[temporal_id] = misc->target_percentage;
+ encoder_context->brc.need_reset = 1;
+ }
}
static void
diff --git a/src/i965_encoder.h b/src/i965_encoder.h
index fe5a595..0b636d6 100644
--- a/src/i965_encoder.h
+++ b/src/i965_encoder.h
@@ -81,6 +81,8 @@ struct intel_encoder_context
unsigned short num_bframes_in_gop;
unsigned int bits_per_second[MAX_TEMPORAL_LAYERS];
unsigned int framerate_per_100s[MAX_TEMPORAL_LAYERS];
+ unsigned int mb_rate_control[MAX_TEMPORAL_LAYERS];
+ unsigned int target_percentage[MAX_TEMPORAL_LAYERS];
unsigned int hrd_buffer_size;
unsigned int hrd_initial_buffer_fullness;
unsigned int need_reset;
Xiang, Haihao
2016-11-29 04:33:08 UTC
Permalink
Instead we can use the parameters saved in the common encoder context.
It also corrects frame rate used in VDEnc

v2: Align the ROI region and fix compile error after rebase

Signed-off-by: Xiang, Haihao <***@intel.com>
---
src/gen9_vdenc.c | 158 +++++++++++--------------------------------------------
1 file changed, 31 insertions(+), 127 deletions(-)

diff --git a/src/gen9_vdenc.c b/src/gen9_vdenc.c
index c8cdca0..e5c4204 100644
--- a/src/gen9_vdenc.c
+++ b/src/gen9_vdenc.c
@@ -838,132 +838,49 @@ map_44_lut_value(unsigned int v, unsigned char max)
}

static void
-gen9_vdenc_update_rate_control_parameters(VADriverContextP ctx,
- struct intel_encoder_context *encoder_context,
- VAEncMiscParameterRateControl *misc)
-{
- struct gen9_vdenc_context *vdenc_context = encoder_context->mfc_context;
-
- vdenc_context->max_bit_rate = ALIGN(misc->bits_per_second, 1000) / 1000;
- vdenc_context->mb_brc_enabled = 0;
-
- if (vdenc_context->internal_rate_mode == I965_BRC_CBR) {
- vdenc_context->min_bit_rate = vdenc_context->max_bit_rate;
- vdenc_context->mb_brc_enabled = (misc->rc_flags.bits.mb_rate_control < 2);
-
- if (vdenc_context->target_bit_rate != vdenc_context->max_bit_rate) {
- vdenc_context->target_bit_rate = vdenc_context->max_bit_rate;
- vdenc_context->brc_need_reset = 1;
- }
- } else if (vdenc_context->internal_rate_mode == I965_BRC_VBR) {
- vdenc_context->min_bit_rate = vdenc_context->max_bit_rate * (2 * misc->target_percentage - 100) / 100;
- vdenc_context->mb_brc_enabled = (misc->rc_flags.bits.mb_rate_control < 2);
-
- if (vdenc_context->target_bit_rate != vdenc_context->max_bit_rate * misc->target_percentage / 100) {
- vdenc_context->target_bit_rate = vdenc_context->max_bit_rate * misc->target_percentage / 100;
- vdenc_context->brc_need_reset = 1;
- }
- }
-}
-
-static void
-gen9_vdenc_update_hrd_parameters(VADriverContextP ctx,
- struct intel_encoder_context *encoder_context,
- VAEncMiscParameterHRD *misc)
-{
- struct gen9_vdenc_context *vdenc_context = encoder_context->mfc_context;
-
- if (vdenc_context->internal_rate_mode == I965_BRC_CQP)
- return;
-
- vdenc_context->vbv_buffer_size_in_bit = misc->buffer_size;
- vdenc_context->init_vbv_buffer_fullness_in_bit = misc->initial_buffer_fullness;
-}
-
-static void
-gen9_vdenc_update_framerate_parameters(VADriverContextP ctx,
- struct intel_encoder_context *encoder_context,
- VAEncMiscParameterFrameRate *misc)
-{
- struct gen9_vdenc_context *vdenc_context = encoder_context->mfc_context;
-
- vdenc_context->frames_per_100s = misc->framerate; /* misc->framerate is multiple of 100 */
-}
-
-static void
-gen9_vdenc_update_roi_parameters(VADriverContextP ctx,
- struct intel_encoder_context *encoder_context,
- VAEncMiscParameterBufferROI *misc)
-{
- struct gen9_vdenc_context *vdenc_context = encoder_context->mfc_context;
- int i;
-
- if (!misc || !misc->roi) {
- vdenc_context->num_roi = 0;
- return;
- }
-
- vdenc_context->num_roi = MIN(misc->num_roi, 3);
- vdenc_context->max_delta_qp = misc->max_delta_qp;
- vdenc_context->min_delta_qp = misc->min_delta_qp;
- vdenc_context->vdenc_streamin_enable = (vdenc_context->num_roi == 0);
-
- for (i = 0; i < vdenc_context->num_roi; i++) {
- vdenc_context->roi[i].left = misc->roi->roi_rectangle.x;
- vdenc_context->roi[i].right = vdenc_context->roi[i].left + misc->roi->roi_rectangle.width;
- vdenc_context->roi[i].top = misc->roi->roi_rectangle.y;
- vdenc_context->roi[i].bottom = vdenc_context->roi[i].top + misc->roi->roi_rectangle.height;
- vdenc_context->roi[i].value = misc->roi->roi_value;
-
- vdenc_context->roi[i].left /= 16;
- vdenc_context->roi[i].right /= 16;
- vdenc_context->roi[i].top /= 16;
- vdenc_context->roi[i].bottom /= 16;
- }
-}
-
-static void
gen9_vdenc_update_misc_parameters(VADriverContextP ctx,
struct encode_state *encode_state,
struct intel_encoder_context *encoder_context)
{
+ struct gen9_vdenc_context *vdenc_context = encoder_context->mfc_context;
int i;
- VAEncMiscParameterBuffer *misc_param;

- for (i = 0; i < ARRAY_ELEMS(encode_state->misc_param); i++) {
- if (!encode_state->misc_param[i][0] || !encode_state->misc_param[i][0]->buffer)
- continue;
+ vdenc_context->gop_size = encoder_context->brc.gop_size;
+ vdenc_context->ref_dist = encoder_context->brc.num_bframes_in_gop + 1;

- misc_param = (VAEncMiscParameterBuffer *)encode_state->misc_param[i][0]->buffer;
+ if (vdenc_context->internal_rate_mode != I965_BRC_CQP &&
+ encoder_context->brc.need_reset) {
+ /* So far, vdenc doesn't support temporal layer */
+ vdenc_context->frames_per_100s = encoder_context->brc.framerate_per_100s[0];

- switch (misc_param->type) {
- case VAEncMiscParameterTypeFrameRate:
- gen9_vdenc_update_framerate_parameters(ctx,
- encoder_context,
- (VAEncMiscParameterFrameRate *)misc_param->data);
- break;
+ vdenc_context->vbv_buffer_size_in_bit = encoder_context->brc.hrd_buffer_size;
+ vdenc_context->init_vbv_buffer_fullness_in_bit = encoder_context->brc.hrd_initial_buffer_fullness;

- case VAEncMiscParameterTypeRateControl:
- gen9_vdenc_update_rate_control_parameters(ctx,
- encoder_context,
- (VAEncMiscParameterRateControl *)misc_param->data);
- break;
+ vdenc_context->max_bit_rate = ALIGN(encoder_context->brc.bits_per_second[0], 1000) / 1000;
+ vdenc_context->mb_brc_enabled = encoder_context->brc.mb_rate_control[0];
+ vdenc_context->brc_need_reset = (vdenc_context->brc_initted && encoder_context->brc.need_reset);

- case VAEncMiscParameterTypeHRD:
- gen9_vdenc_update_hrd_parameters(ctx,
- encoder_context,
- (VAEncMiscParameterHRD *)misc_param->data);
- break;
+ if (vdenc_context->internal_rate_mode == I965_BRC_CBR) {
+ vdenc_context->min_bit_rate = vdenc_context->max_bit_rate;
+ vdenc_context->target_bit_rate = vdenc_context->max_bit_rate;
+ } else {
+ assert(vdenc_context->internal_rate_mode == I965_BRC_VBR);
+ vdenc_context->min_bit_rate = vdenc_context->max_bit_rate * (2 * encoder_context->brc.target_percentage[0] - 100) / 100;
+ vdenc_context->target_bit_rate = vdenc_context->max_bit_rate * encoder_context->brc.target_percentage[0] / 100;
+ }
+ }

- case VAEncMiscParameterTypeROI:
- gen9_vdenc_update_roi_parameters(ctx,
- encoder_context,
- (VAEncMiscParameterBufferROI *)misc_param->data);
- break;
+ vdenc_context->num_roi = MIN(encoder_context->brc.num_roi, 3);
+ vdenc_context->max_delta_qp = encoder_context->brc.roi_max_delta_qp;
+ vdenc_context->min_delta_qp = encoder_context->brc.roi_min_delta_qp;
+ vdenc_context->vdenc_streamin_enable = !!vdenc_context->num_roi;

- default:
- break;
- }
+ for (i = 0; i < vdenc_context->num_roi; i++) {
+ vdenc_context->roi[i].left = encoder_context->brc.roi[i].left >> 4;
+ vdenc_context->roi[i].right = encoder_context->brc.roi[i].right >> 4;
+ vdenc_context->roi[i].top = encoder_context->brc.roi[i].top >> 4;
+ vdenc_context->roi[i].bottom = encoder_context->brc.roi[i].top >> 4;
+ encoder_context->brc.roi[i].value = encoder_context->brc.roi[i].value;
}
}

@@ -994,19 +911,6 @@ gen9_vdenc_update_parameters(VADriverContextP ctx,
vdenc_context->down_scaled_height_4x = ((vdenc_context->down_scaled_height_in_mb4x + 1) >> 1) * 16;
vdenc_context->down_scaled_height_4x = ALIGN(vdenc_context->down_scaled_height_4x, 32) << 1;

- if (vdenc_context->internal_rate_mode == I965_BRC_CBR) {
- vdenc_context->target_bit_rate = ALIGN(seq_param->bits_per_second, 1000) / 1000;
- vdenc_context->max_bit_rate = ALIGN(seq_param->bits_per_second, 1000) / 1000;
- vdenc_context->min_bit_rate = ALIGN(seq_param->bits_per_second, 1000) / 1000;
- }
-
- vdenc_context->init_vbv_buffer_fullness_in_bit = seq_param->bits_per_second;
- vdenc_context->vbv_buffer_size_in_bit = (uint64_t)seq_param->bits_per_second << 1;
- vdenc_context->frames_per_100s = 3000; /* 30fps */
- vdenc_context->gop_size = seq_param->intra_period;
- vdenc_context->ref_dist = seq_param->ip_period;
- vdenc_context->vdenc_streamin_enable = 0;
-
gen9_vdenc_update_misc_parameters(ctx, encode_state, encoder_context);

vdenc_context->current_pass = 0;
--
1.9.1
Zhao Yakui
2016-11-30 00:30:54 UTC
Permalink
Post by Xiang, Haihao
Instead we can use the parameters saved in the common encoder context.
It also corrects frame rate used in VDEnc
v2: Align the ROI region and fix compile error after rebase
This looks fine to me.

Thanks
Post by Xiang, Haihao
---
src/gen9_vdenc.c | 158 +++++++++++--------------------------------------------
1 file changed, 31 insertions(+), 127 deletions(-)
diff --git a/src/gen9_vdenc.c b/src/gen9_vdenc.c
index c8cdca0..e5c4204 100644
--- a/src/gen9_vdenc.c
+++ b/src/gen9_vdenc.c
@@ -838,132 +838,49 @@ map_44_lut_value(unsigned int v, unsigned char max)
}
static void
-gen9_vdenc_update_rate_control_parameters(VADriverContextP ctx,
- struct intel_encoder_context *encoder_context,
- VAEncMiscParameterRateControl *misc)
-{
- struct gen9_vdenc_context *vdenc_context = encoder_context->mfc_context;
-
- vdenc_context->max_bit_rate = ALIGN(misc->bits_per_second, 1000) / 1000;
- vdenc_context->mb_brc_enabled = 0;
-
- if (vdenc_context->internal_rate_mode == I965_BRC_CBR) {
- vdenc_context->min_bit_rate = vdenc_context->max_bit_rate;
- vdenc_context->mb_brc_enabled = (misc->rc_flags.bits.mb_rate_control< 2);
-
- if (vdenc_context->target_bit_rate != vdenc_context->max_bit_rate) {
- vdenc_context->target_bit_rate = vdenc_context->max_bit_rate;
- vdenc_context->brc_need_reset = 1;
- }
- } else if (vdenc_context->internal_rate_mode == I965_BRC_VBR) {
- vdenc_context->min_bit_rate = vdenc_context->max_bit_rate * (2 * misc->target_percentage - 100) / 100;
- vdenc_context->mb_brc_enabled = (misc->rc_flags.bits.mb_rate_control< 2);
-
- if (vdenc_context->target_bit_rate != vdenc_context->max_bit_rate * misc->target_percentage / 100) {
- vdenc_context->target_bit_rate = vdenc_context->max_bit_rate * misc->target_percentage / 100;
- vdenc_context->brc_need_reset = 1;
- }
- }
-}
-
-static void
-gen9_vdenc_update_hrd_parameters(VADriverContextP ctx,
- struct intel_encoder_context *encoder_context,
- VAEncMiscParameterHRD *misc)
-{
- struct gen9_vdenc_context *vdenc_context = encoder_context->mfc_context;
-
- if (vdenc_context->internal_rate_mode == I965_BRC_CQP)
- return;
-
- vdenc_context->vbv_buffer_size_in_bit = misc->buffer_size;
- vdenc_context->init_vbv_buffer_fullness_in_bit = misc->initial_buffer_fullness;
-}
-
-static void
-gen9_vdenc_update_framerate_parameters(VADriverContextP ctx,
- struct intel_encoder_context *encoder_context,
- VAEncMiscParameterFrameRate *misc)
-{
- struct gen9_vdenc_context *vdenc_context = encoder_context->mfc_context;
-
- vdenc_context->frames_per_100s = misc->framerate; /* misc->framerate is multiple of 100 */
-}
-
-static void
-gen9_vdenc_update_roi_parameters(VADriverContextP ctx,
- struct intel_encoder_context *encoder_context,
- VAEncMiscParameterBufferROI *misc)
-{
- struct gen9_vdenc_context *vdenc_context = encoder_context->mfc_context;
- int i;
-
- if (!misc || !misc->roi) {
- vdenc_context->num_roi = 0;
- return;
- }
-
- vdenc_context->num_roi = MIN(misc->num_roi, 3);
- vdenc_context->max_delta_qp = misc->max_delta_qp;
- vdenc_context->min_delta_qp = misc->min_delta_qp;
- vdenc_context->vdenc_streamin_enable = (vdenc_context->num_roi == 0);
-
- for (i = 0; i< vdenc_context->num_roi; i++) {
- vdenc_context->roi[i].left = misc->roi->roi_rectangle.x;
- vdenc_context->roi[i].right = vdenc_context->roi[i].left + misc->roi->roi_rectangle.width;
- vdenc_context->roi[i].top = misc->roi->roi_rectangle.y;
- vdenc_context->roi[i].bottom = vdenc_context->roi[i].top + misc->roi->roi_rectangle.height;
- vdenc_context->roi[i].value = misc->roi->roi_value;
-
- vdenc_context->roi[i].left /= 16;
- vdenc_context->roi[i].right /= 16;
- vdenc_context->roi[i].top /= 16;
- vdenc_context->roi[i].bottom /= 16;
- }
-}
-
-static void
gen9_vdenc_update_misc_parameters(VADriverContextP ctx,
struct encode_state *encode_state,
struct intel_encoder_context *encoder_context)
{
+ struct gen9_vdenc_context *vdenc_context = encoder_context->mfc_context;
int i;
- VAEncMiscParameterBuffer *misc_param;
- for (i = 0; i< ARRAY_ELEMS(encode_state->misc_param); i++) {
- if (!encode_state->misc_param[i][0] || !encode_state->misc_param[i][0]->buffer)
- continue;
+ vdenc_context->gop_size = encoder_context->brc.gop_size;
+ vdenc_context->ref_dist = encoder_context->brc.num_bframes_in_gop + 1;
- misc_param = (VAEncMiscParameterBuffer *)encode_state->misc_param[i][0]->buffer;
+ if (vdenc_context->internal_rate_mode != I965_BRC_CQP&&
+ encoder_context->brc.need_reset) {
+ /* So far, vdenc doesn't support temporal layer */
+ vdenc_context->frames_per_100s = encoder_context->brc.framerate_per_100s[0];
- switch (misc_param->type) {
- gen9_vdenc_update_framerate_parameters(ctx,
- encoder_context,
- (VAEncMiscParameterFrameRate *)misc_param->data);
- break;
+ vdenc_context->vbv_buffer_size_in_bit = encoder_context->brc.hrd_buffer_size;
+ vdenc_context->init_vbv_buffer_fullness_in_bit = encoder_context->brc.hrd_initial_buffer_fullness;
- gen9_vdenc_update_rate_control_parameters(ctx,
- encoder_context,
- (VAEncMiscParameterRateControl *)misc_param->data);
- break;
+ vdenc_context->max_bit_rate = ALIGN(encoder_context->brc.bits_per_second[0], 1000) / 1000;
+ vdenc_context->mb_brc_enabled = encoder_context->brc.mb_rate_control[0];
+ vdenc_context->brc_need_reset = (vdenc_context->brc_initted&& encoder_context->brc.need_reset);
- gen9_vdenc_update_hrd_parameters(ctx,
- encoder_context,
- (VAEncMiscParameterHRD *)misc_param->data);
- break;
+ if (vdenc_context->internal_rate_mode == I965_BRC_CBR) {
+ vdenc_context->min_bit_rate = vdenc_context->max_bit_rate;
+ vdenc_context->target_bit_rate = vdenc_context->max_bit_rate;
+ } else {
+ assert(vdenc_context->internal_rate_mode == I965_BRC_VBR);
+ vdenc_context->min_bit_rate = vdenc_context->max_bit_rate * (2 * encoder_context->brc.target_percentage[0] - 100) / 100;
+ vdenc_context->target_bit_rate = vdenc_context->max_bit_rate * encoder_context->brc.target_percentage[0] / 100;
+ }
+ }
- gen9_vdenc_update_roi_parameters(ctx,
- encoder_context,
- (VAEncMiscParameterBufferROI *)misc_param->data);
- break;
+ vdenc_context->num_roi = MIN(encoder_context->brc.num_roi, 3);
+ vdenc_context->max_delta_qp = encoder_context->brc.roi_max_delta_qp;
+ vdenc_context->min_delta_qp = encoder_context->brc.roi_min_delta_qp;
+ vdenc_context->vdenc_streamin_enable = !!vdenc_context->num_roi;
- break;
- }
+ for (i = 0; i< vdenc_context->num_roi; i++) {
+ vdenc_context->roi[i].left = encoder_context->brc.roi[i].left>> 4;
+ vdenc_context->roi[i].right = encoder_context->brc.roi[i].right>> 4;
+ vdenc_context->roi[i].top = encoder_context->brc.roi[i].top>> 4;
+ vdenc_context->roi[i].bottom = encoder_context->brc.roi[i].top>> 4;
+ encoder_context->brc.roi[i].value = encoder_context->brc.roi[i].value;
}
}
@@ -994,19 +911,6 @@ gen9_vdenc_update_parameters(VADriverContextP ctx,
vdenc_context->down_scaled_height_4x = ((vdenc_context->down_scaled_height_in_mb4x + 1)>> 1) * 16;
vdenc_context->down_scaled_height_4x = ALIGN(vdenc_context->down_scaled_height_4x, 32)<< 1;
- if (vdenc_context->internal_rate_mode == I965_BRC_CBR) {
- vdenc_context->target_bit_rate = ALIGN(seq_param->bits_per_second, 1000) / 1000;
- vdenc_context->max_bit_rate = ALIGN(seq_param->bits_per_second, 1000) / 1000;
- vdenc_context->min_bit_rate = ALIGN(seq_param->bits_per_second, 1000) / 1000;
- }
-
- vdenc_context->init_vbv_buffer_fullness_in_bit = seq_param->bits_per_second;
- vdenc_context->vbv_buffer_size_in_bit = (uint64_t)seq_param->bits_per_second<< 1;
- vdenc_context->frames_per_100s = 3000; /* 30fps */
- vdenc_context->gop_size = seq_param->intra_period;
- vdenc_context->ref_dist = seq_param->ip_period;
- vdenc_context->vdenc_streamin_enable = 0;
-
gen9_vdenc_update_misc_parameters(ctx, encode_state, encoder_context);
vdenc_context->current_pass = 0;
Loading...