Add new avc_find_picture() helper macro to search for a VAPictureH264 struct based on the supplied VA surface id.
Signed-off-by: Gwenole Beauchesne <[email protected]> --- src/gen6_mfd.c | 22 +++++----------------- src/gen75_mfd.c | 44 ++++++++++---------------------------------- src/gen7_mfd.c | 22 +++++----------------- src/gen8_mfd.c | 22 +++++----------------- src/i965_avc_bsd.c | 40 +++++++--------------------------------- src/i965_decoder_utils.c | 17 +++++++++++++++++ src/i965_decoder_utils.h | 3 +++ src/i965_media_h264.c | 21 ++++++--------------- 8 files changed, 58 insertions(+), 133 deletions(-) diff --git a/src/gen6_mfd.c b/src/gen6_mfd.c index dbdebbc..1c3b9e3 100755 --- a/src/gen6_mfd.c +++ b/src/gen6_mfd.c @@ -417,7 +417,7 @@ gen6_mfd_avc_directmode_state(VADriverContextP ctx, struct object_surface *obj_surface; GenAvcSurface *gen6_avc_surface; VAPictureH264 *va_pic; - int i, j; + int i; BEGIN_BCS_BATCH(batch, 69); OUT_BCS_BATCH(batch, MFX_AVC_DIRECTMODE_STATE | (69 - 2)); @@ -470,23 +470,11 @@ gen6_mfd_avc_directmode_state(VADriverContextP ctx, obj_surface = gen6_mfd_context->fsc.used_frames[i].obj_surface; if (obj_surface) { - int found = 0; - - for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) { - va_pic = &pic_param->ReferenceFrames[j]; - - if (va_pic->flags & VA_PICTURE_H264_INVALID) - continue; - - if (va_pic->picture_id == obj_surface->base.id) { - found = 1; - break; - } - } + const VAPictureH264 * const va_pic = avc_find_picture( + obj_surface->base.id, pic_param->ReferenceFrames, + ARRAY_ELEMS(pic_param->ReferenceFrames)); - assert(found == 1); - assert(!(va_pic->flags & VA_PICTURE_H264_INVALID)); - + assert(va_pic != NULL); OUT_BCS_BATCH(batch, va_pic->TopFieldOrderCnt); OUT_BCS_BATCH(batch, va_pic->BottomFieldOrderCnt); } else { diff --git a/src/gen75_mfd.c b/src/gen75_mfd.c index be481c6..018740e 100644 --- a/src/gen75_mfd.c +++ b/src/gen75_mfd.c @@ -658,7 +658,7 @@ gen75_mfd_avc_directmode_state_bplus(VADriverContextP ctx, struct object_surface *obj_surface; GenAvcSurface *gen7_avc_surface; VAPictureH264 *va_pic; - int i, j; + int i; BEGIN_BCS_BATCH(batch, 71); OUT_BCS_BATCH(batch, MFX_AVC_DIRECTMODE_STATE | (71 - 2)); @@ -700,23 +700,11 @@ gen75_mfd_avc_directmode_state_bplus(VADriverContextP ctx, obj_surface = gen7_mfd_context->fsc.used_frames[i].obj_surface; if (obj_surface) { - int found = 0; - - for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) { - va_pic = &pic_param->ReferenceFrames[j]; - - if (va_pic->flags & VA_PICTURE_H264_INVALID) - continue; - - if (va_pic->picture_id == obj_surface->base.id) { - found = 1; - break; - } - } + const VAPictureH264 * const va_pic = avc_find_picture( + obj_surface->base.id, pic_param->ReferenceFrames, + ARRAY_ELEMS(pic_param->ReferenceFrames)); - assert(found == 1); - assert(!(va_pic->flags & VA_PICTURE_H264_INVALID)); - + assert(va_pic != NULL); OUT_BCS_BATCH(batch, va_pic->TopFieldOrderCnt); OUT_BCS_BATCH(batch, va_pic->BottomFieldOrderCnt); } else { @@ -744,7 +732,7 @@ gen75_mfd_avc_directmode_state(VADriverContextP ctx, struct object_surface *obj_surface; GenAvcSurface *gen7_avc_surface; VAPictureH264 *va_pic; - int i, j; + int i; if (IS_STEPPING_BPLUS(i965)) { gen75_mfd_avc_directmode_state_bplus(ctx, decode_state, pic_param, slice_param, @@ -805,23 +793,11 @@ gen75_mfd_avc_directmode_state(VADriverContextP ctx, obj_surface = gen7_mfd_context->fsc.used_frames[i].obj_surface; if (obj_surface) { - int found = 0; - - for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) { - va_pic = &pic_param->ReferenceFrames[j]; - - if (va_pic->flags & VA_PICTURE_H264_INVALID) - continue; - - if (va_pic->picture_id == obj_surface->base.id) { - found = 1; - break; - } - } + const VAPictureH264 * const va_pic = avc_find_picture( + obj_surface->base.id, pic_param->ReferenceFrames, + ARRAY_ELEMS(pic_param->ReferenceFrames)); - assert(found == 1); - assert(!(va_pic->flags & VA_PICTURE_H264_INVALID)); - + assert(va_pic != NULL); OUT_BCS_BATCH(batch, va_pic->TopFieldOrderCnt); OUT_BCS_BATCH(batch, va_pic->BottomFieldOrderCnt); } else { diff --git a/src/gen7_mfd.c b/src/gen7_mfd.c index 19cf1d9..07cdd46 100755 --- a/src/gen7_mfd.c +++ b/src/gen7_mfd.c @@ -426,7 +426,7 @@ gen7_mfd_avc_directmode_state(VADriverContextP ctx, struct object_surface *obj_surface; GenAvcSurface *gen7_avc_surface; VAPictureH264 *va_pic; - int i, j; + int i; BEGIN_BCS_BATCH(batch, 69); OUT_BCS_BATCH(batch, MFX_AVC_DIRECTMODE_STATE | (69 - 2)); @@ -479,23 +479,11 @@ gen7_mfd_avc_directmode_state(VADriverContextP ctx, obj_surface = gen7_mfd_context->fsc.used_frames[i].obj_surface; if (obj_surface) { - int found = 0; - - for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) { - va_pic = &pic_param->ReferenceFrames[j]; - - if (va_pic->flags & VA_PICTURE_H264_INVALID) - continue; - - if (va_pic->picture_id == gen7_mfd_context->fsc.used_frames[i].surface_id) { - found = 1; - break; - } - } + const VAPictureH264 * const va_pic = avc_find_picture( + obj_surface->base.id, pic_param->ReferenceFrames, + ARRAY_ELEMS(pic_param->ReferenceFrames)); - assert(found == 1); - assert(!(va_pic->flags & VA_PICTURE_H264_INVALID)); - + assert(va_pic != NULL); OUT_BCS_BATCH(batch, va_pic->TopFieldOrderCnt); OUT_BCS_BATCH(batch, va_pic->BottomFieldOrderCnt); } else { diff --git a/src/gen8_mfd.c b/src/gen8_mfd.c index 459c430..10c109c 100644 --- a/src/gen8_mfd.c +++ b/src/gen8_mfd.c @@ -528,7 +528,7 @@ gen8_mfd_avc_directmode_state(VADriverContextP ctx, struct object_surface *obj_surface; GenAvcSurface *gen7_avc_surface; VAPictureH264 *va_pic; - int i, j; + int i; BEGIN_BCS_BATCH(batch, 71); OUT_BCS_BATCH(batch, MFX_AVC_DIRECTMODE_STATE | (71 - 2)); @@ -570,23 +570,11 @@ gen8_mfd_avc_directmode_state(VADriverContextP ctx, obj_surface = gen7_mfd_context->fsc.used_frames[i].obj_surface; if (obj_surface) { - int found = 0; - - for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) { - va_pic = &pic_param->ReferenceFrames[j]; - - if (va_pic->flags & VA_PICTURE_H264_INVALID) - continue; - - if (va_pic->picture_id == obj_surface->base.id) { - found = 1; - break; - } - } + const VAPictureH264 * const va_pic = avc_find_picture( + obj_surface->base.id, pic_param->ReferenceFrames, + ARRAY_ELEMS(pic_param->ReferenceFrames)); - assert(found == 1); - assert(!(va_pic->flags & VA_PICTURE_H264_INVALID)); - + assert(va_pic != NULL); OUT_BCS_BATCH(batch, va_pic->TopFieldOrderCnt); OUT_BCS_BATCH(batch, va_pic->BottomFieldOrderCnt); } else { diff --git a/src/i965_avc_bsd.c b/src/i965_avc_bsd.c index d2c70f6..ce03439 100644 --- a/src/i965_avc_bsd.c +++ b/src/i965_avc_bsd.c @@ -378,7 +378,7 @@ i965_avc_bsd_buf_base_state(VADriverContextP ctx, { struct intel_batchbuffer *batch = i965_h264_context->batch; struct i965_avc_bsd_context *i965_avc_bsd_context; - int i, j; + int i; VAPictureH264 *va_pic; struct object_surface *obj_surface; GenAvcSurface *avc_bsd_surface; @@ -411,20 +411,6 @@ i965_avc_bsd_buf_base_state(VADriverContextP ctx, obj_surface = i965_h264_context->fs_context.used_frames[i].obj_surface; if (obj_surface && obj_surface->private_data) { - int found = 0; - for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) { - va_pic = &pic_param->ReferenceFrames[j]; - - if (va_pic->flags & VA_PICTURE_H264_INVALID) - continue; - - if (va_pic->picture_id == obj_surface->base.id) { - found = 1; - break; - } - } - - assert(found == 1); avc_bsd_surface = obj_surface->private_data; OUT_BCS_RELOC(batch, avc_bsd_surface->dmv_top, @@ -484,25 +470,13 @@ i965_avc_bsd_buf_base_state(VADriverContextP ctx, obj_surface = i965_h264_context->fs_context.used_frames[i].obj_surface; if (obj_surface) { - int found = 0; - for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) { - va_pic = &pic_param->ReferenceFrames[j]; - - if (va_pic->flags & VA_PICTURE_H264_INVALID) - continue; - - if (va_pic->picture_id == obj_surface->base.id) { - found = 1; - break; - } - } - - assert(found == 1); + const VAPictureH264 * const va_pic = avc_find_picture( + obj_surface->base.id, pic_param->ReferenceFrames, + ARRAY_ELEMS(pic_param->ReferenceFrames)); - if (!(va_pic->flags & VA_PICTURE_H264_INVALID)) { - OUT_BCS_BATCH(batch, va_pic->TopFieldOrderCnt); - OUT_BCS_BATCH(batch, va_pic->BottomFieldOrderCnt); - } + assert(va_pic != NULL); + OUT_BCS_BATCH(batch, va_pic->TopFieldOrderCnt); + OUT_BCS_BATCH(batch, va_pic->BottomFieldOrderCnt); } else { OUT_BCS_BATCH(batch, 0); OUT_BCS_BATCH(batch, 0); diff --git a/src/i965_decoder_utils.c b/src/i965_decoder_utils.c index b834a0e..fff20c6 100644 --- a/src/i965_decoder_utils.c +++ b/src/i965_decoder_utils.c @@ -252,6 +252,23 @@ avc_gen_default_iq_matrix(VAIQMatrixBufferH264 *iq_matrix) memset(&iq_matrix->ScalingList8x8, 16, sizeof(iq_matrix->ScalingList8x8)); } +/* Finds the VA/H264 picture associated with the specified VA surface id */ +VAPictureH264 * +avc_find_picture(VASurfaceID id, VAPictureH264 *pic_list, int pic_list_count) +{ + int i; + + if (id != VA_INVALID_ID) { + for (i = 0; i < pic_list_count; i++) { + VAPictureH264 * const va_pic = &pic_list[i]; + if (va_pic->picture_id == id && + !(va_pic->flags & VA_PICTURE_H264_INVALID)) + return va_pic; + } + } + return NULL; +} + /* Get first macroblock bit offset for BSD, minus EPB count (AVC) */ /* XXX: slice_data_bit_offset does not account for EPB */ unsigned int diff --git a/src/i965_decoder_utils.h b/src/i965_decoder_utils.h index 14a45fb..a4c9415 100644 --- a/src/i965_decoder_utils.h +++ b/src/i965_decoder_utils.h @@ -54,6 +54,9 @@ avc_ensure_surface_bo( void avc_gen_default_iq_matrix(VAIQMatrixBufferH264 *iq_matrix); +VAPictureH264 * +avc_find_picture(VASurfaceID id, VAPictureH264 *pic_list, int pic_list_count); + unsigned int avc_get_first_mb_bit_offset( dri_bo *slice_data_bo, diff --git a/src/i965_media_h264.c b/src/i965_media_h264.c index b291886..65afb2d 100644 --- a/src/i965_media_h264.c +++ b/src/i965_media_h264.c @@ -11,6 +11,7 @@ #include "i965_drv_video.h" #include "i965_media.h" #include "i965_media_h264.h" +#include "i965_decoder_utils.h" enum { INTRA_16X16 = 0, @@ -343,7 +344,7 @@ i965_media_h264_surfaces_setup(VADriverContextP ctx, struct object_surface *obj_surface; VAPictureParameterBufferH264 *pic_param; VAPictureH264 *va_pic; - int i, j, w, h; + int i, w, h; int field_picture; assert(media_context->private_context); @@ -379,21 +380,11 @@ i965_media_h264_surfaces_setup(VADriverContextP ctx, i965_h264_context->fs_context.used_frames[i].obj_surface; if (obj_surface) { - int found = 0; - for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) { - va_pic = &pic_param->ReferenceFrames[j]; - - if (va_pic->flags & VA_PICTURE_H264_INVALID) - continue; - - if (va_pic->picture_id == obj_surface->base.id) { - found = 1; - break; - } - } - - assert(found == 1); + const VAPictureH264 * const va_pic = avc_find_picture( + obj_surface->base.id, pic_param->ReferenceFrames, + ARRAY_ELEMS(pic_param->ReferenceFrames)); + assert(va_pic != NULL); w = obj_surface->width; h = obj_surface->height; field_picture = !!(va_pic->flags & (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD)); -- 1.7.9.5 _______________________________________________ Libva mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libva
