st/va: also retrieve reference frames info for h264
authorJulien Isorce <j.isorce@samsung.com>
Thu, 26 Nov 2015 08:30:30 +0000 (08:30 +0000)
committerJulien Isorce <j.isorce@samsung.com>
Tue, 1 Dec 2015 08:21:37 +0000 (08:21 +0000)
Other hardwares than AMD require to parse:
VAPictureParameterBufferH264.ReferenceFrames[16]

Signed-off-by: Julien Isorce <j.isorce@samsung.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
src/gallium/state_trackers/va/picture_h264.c

index f6e5b70ebcc57339efef6699289178147e48ccd4..acbfe5d61ed2905056d94550cb8a3fc11352edec 100644 (file)
 #include "util/u_video.h"
 #include "va_private.h"
 
+static void resetReferencePictureDesc(struct pipe_h264_picture_desc *h264,
+                                      unsigned int i)
+{
+   h264->ref[i] = NULL;
+   h264->frame_num_list[i] = 0;
+   h264->is_long_term[i] = 0;
+   h264->top_is_reference[i] = 0;
+   h264->bottom_is_reference[i] = 0;
+   h264->field_order_cnt_list[i][0] = 0;
+   h264->field_order_cnt_list[i][1] = 0;
+}
+
 void vlVaHandlePictureParameterBufferH264(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf)
 {
    VAPictureParameterBufferH264 *h264 = buf->data;
+   unsigned int top_or_bottom_field;
+   unsigned i;
 
    assert(buf->size >= sizeof(VAPictureParameterBufferH264) && buf->num_elements == 1);
    /*CurrPic*/
@@ -91,9 +105,47 @@ void vlVaHandlePictureParameterBufferH264(vlVaDriver *drv, vlVaContext *context,
       h264->pic_fields.bits.redundant_pic_cnt_present_flag;
    /*reference_pic_flag*/
    context->desc.h264.frame_num = h264->frame_num;
+   context->desc.h264.is_reference = h264->pic_fields.bits.reference_pic_flag;
+   context->desc.h264.bottom_field_flag =
+      h264->pic_fields.bits.field_pic_flag &&
+      (h264->CurrPic.flags & VA_PICTURE_H264_BOTTOM_FIELD) != 0;
 
    if (!context->decoder && context->desc.h264.num_ref_frames > 0)
       context->templat.max_references = MIN2(context->desc.h264.num_ref_frames, 16);
+
+   for (i = 0; i < context->templat.max_references; ++i) {
+      if ((h264->ReferenceFrames[i].flags & VA_PICTURE_H264_INVALID) ||
+          (h264->ReferenceFrames[i].picture_id == VA_INVALID_SURFACE)) {
+         resetReferencePictureDesc(&context->desc.h264, i);
+         break;
+      }
+
+      vlVaGetReferenceFrame(drv, h264->ReferenceFrames[i].picture_id, &context->desc.h264.ref[i]);
+      context->desc.h264.frame_num_list[i] = h264->ReferenceFrames[i].frame_idx;
+
+      top_or_bottom_field = h264->ReferenceFrames[i].flags &
+         (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD);
+      context->desc.h264.is_long_term[i] = (h264->ReferenceFrames[i].flags &
+         (VA_PICTURE_H264_SHORT_TERM_REFERENCE |
+         VA_PICTURE_H264_LONG_TERM_REFERENCE)) !=
+         VA_PICTURE_H264_SHORT_TERM_REFERENCE;
+      context->desc.h264.top_is_reference[i] =
+         !context->desc.h264.is_long_term[i] ||
+         !!(h264->ReferenceFrames[i].flags & VA_PICTURE_H264_TOP_FIELD);
+      context->desc.h264.bottom_is_reference[i] =
+         !context->desc.h264.is_long_term[i] ||
+         !!(h264->ReferenceFrames[i].flags & VA_PICTURE_H264_BOTTOM_FIELD);
+      context->desc.h264.field_order_cnt_list[i][0] =
+         top_or_bottom_field != VA_PICTURE_H264_BOTTOM_FIELD ?
+         h264->ReferenceFrames[i].TopFieldOrderCnt: INT_MAX;
+      context->desc.h264.field_order_cnt_list[i][1] =
+         top_or_bottom_field != VA_PICTURE_H264_TOP_FIELD ?
+         h264->ReferenceFrames[i].BottomFieldOrderCnt: INT_MAX;
+   }
+
+   /* Make sure remaining elements are clean */
+   for (; i < 16; ++i)
+      resetReferencePictureDesc(&context->desc.h264, i);
 }
 
 void vlVaHandleIQMatrixBufferH264(vlVaContext *context, vlVaBuffer *buf)