[Libva] [PATCH 5/7] VP8 HWEnc: Calc vp8 coded size by internal buffer
Zhong Li
zhong.li at intel.com
Mon Dec 22 23:46:22 PST 2014
Signed-off-by: Zhong Li <zhong.li at intel.com>
---
src/gen9_mfc.c | 28 ++++++++++++++++++++++++++++
src/i965_drv_video.c | 21 ++++++++-------------
src/i965_drv_video.h | 6 ------
3 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/src/gen9_mfc.c b/src/gen9_mfc.c
index 99c249b..28be67b 100644
--- a/src/gen9_mfc.c
+++ b/src/gen9_mfc.c
@@ -3116,6 +3116,33 @@ gen9_mfc_vp8_pipeline_programing(VADriverContextP ctx,
dri_bo_unreference(slice_batch_bo);
}
+static void gen9_mfc_calc_vp8_coded_buffer_size(VADriverContextP ctx,
+ struct encode_state *encode_state,
+ struct intel_encoder_context *encoder_context)
+{
+ struct i965_driver_data *i965 = i965_driver_data(ctx);
+ struct gen6_mfc_context *mfc_context = encoder_context->mfc_context;
+ VAEncPictureParameterBufferVP8 *pic_param = (VAEncPictureParameterBufferVP8 *)encode_state->pic_param_ext->buffer;
+ unsigned char is_intra_frame = !pic_param->pic_flags.bits.frame_type;
+ unsigned int *vp8_encoding_status, first_partition_bytes, token_partition_bytes, vp8_coded_bytes;
+
+ dri_bo_map(mfc_context->vp8_state.token_statistics_bo, 1);
+
+ vp8_encoding_status = (unsigned int *)mfc_context->vp8_state.token_statistics_bo->virtual;
+ first_partition_bytes = (*vp8_encoding_status + 7) / 8;
+ token_partition_bytes = (*(unsigned int *)(vp8_encoding_status + 9) + 8) / 8;
+
+ /*coded_bytes includes P0~P8 partitions bytes + uncompresse date bytes + partion_size bytes in bitstream */
+ vp8_coded_bytes = first_partition_bytes + token_partition_bytes + (3 + 7 * !!is_intra_frame) + (pic_param->pic_flags.bits.num_token_partitions - 1) * 3;
+
+ dri_bo_unmap(mfc_context->vp8_state.token_statistics_bo);
+
+ dri_bo_map(mfc_context->vp8_state.final_frame_bo, 1);
+ struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(mfc_context->vp8_state.final_frame_bo->virtual);
+ coded_buffer_segment->base.size = vp8_coded_bytes;
+ dri_bo_unmap(mfc_context->vp8_state.final_frame_bo);
+}
+
static VAStatus
gen9_mfc_vp8_encode_picture(VADriverContextP ctx,
struct encode_state *encode_state,
@@ -3128,6 +3155,7 @@ gen9_mfc_vp8_encode_picture(VADriverContextP ctx,
/*Programing bcs pipeline*/
gen9_mfc_vp8_pipeline_programing(ctx, encode_state, encoder_context);
gen9_mfc_run(ctx, encode_state, encoder_context);
+ gen9_mfc_calc_vp8_coded_buffer_size(ctx, encode_state, encoder_context);
return VA_STATUS_SUCCESS;
}
diff --git a/src/i965_drv_video.c b/src/i965_drv_video.c
index d2928e1..d1424b5 100644
--- a/src/i965_drv_video.c
+++ b/src/i965_drv_video.c
@@ -2209,13 +2209,7 @@ i965_MapBuffer(VADriverContextP ctx,
//In JPEG End of Image (EOI = 0xDDF9) marker can be used for delimiter.
delimiter0 = 0xFF;
delimiter1 = 0xD9;
- } else if (coded_buffer_segment->codec == CODEC_VP8) {
- delimiter0 = VP8_DELIMITER0;
- delimiter1 = VP8_DELIMITER1;
- delimiter2 = VP8_DELIMITER2;
- delimiter3 = VP8_DELIMITER3;
- delimiter4 = VP8_DELIMITER4;
- } else {
+ } else if (coded_buffer_segment->codec != CODEC_VP8) {
ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
}
@@ -2225,13 +2219,10 @@ i965_MapBuffer(VADriverContextP ctx,
break;
}
}
-
- if (i == obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 1 - 0x1000) {
- coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
- }
-
coded_buffer_segment->base.size = i + 2;
- } else {
+ } else if (coded_buffer_segment->codec != CODEC_VP8) {
+ /* vp8 coded buffer size can be told by vp8 internal statistics buffer,
+ so it don't need to traversal the coded buffer */
for (i = 0; i < obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000; i++) {
if ((buffer[i] == delimiter0) &&
(buffer[i + 1] == delimiter1) &&
@@ -2247,6 +2238,10 @@ i965_MapBuffer(VADriverContextP ctx,
coded_buffer_segment->base.size = i;
}
+ if (coded_buffer_segment->base.size >= obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 0x1000) {
+ coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
+ }
+
coded_buffer_segment->mapped = 1;
} else {
assert(coded_buffer_segment->base.buf);
diff --git a/src/i965_drv_video.h b/src/i965_drv_video.h
index dc3c91c..1019f80 100644
--- a/src/i965_drv_video.h
+++ b/src/i965_drv_video.h
@@ -469,12 +469,6 @@ va_enc_packed_type_to_idx(int packed_type);
#define MPEG2_DELIMITER3 0x00
#define MPEG2_DELIMITER4 0xb0
-#define VP8_DELIMITER0 0x00
-#define VP8_DELIMITER1 0x00
-#define VP8_DELIMITER2 0x00
-#define VP8_DELIMITER3 0x00
-#define VP8_DELIMITER4 0x00
-
struct i965_coded_buffer_segment
{
VACodedBufferSegment base;
--
1.9.1
More information about the Libva
mailing list