msdk: support for MFX_FOURCC_BGR4 frame allocation
authorHaihao Xiang <haihao.xiang@intel.com>
Wed, 9 Oct 2019 05:41:09 +0000 (13:41 +0800)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Sat, 2 Nov 2019 09:52:36 +0000 (09:52 +0000)
MFX_FOURCC_BGR4 is mapped to VA_FOURCC_ABGR and JPEG encoder needs a
MFX_FOURCC_BGR4 frame for internal usage when the input format is
MFX_FOURCC_RGB4

This is a preparation for supporting native formats of JPEG encoder

sys/msdk/gstmsdkallocator_libva.c
sys/msdk/msdk_libva.c

index af1243dcc24ca0703a7e45b4db07b395933c0faa..05ffa59287a5f25755bc11c690a0efe0663f0b32 100644 (file)
@@ -46,7 +46,8 @@ gst_msdk_frame_alloc (mfxHDL pthis, mfxFrameAllocRequest * req,
   guint format;
   guint va_fourcc = 0;
   VASurfaceID *surfaces = NULL;
-  VASurfaceAttrib attrib;
+  VASurfaceAttrib attribs[2];
+  guint num_attribs = 0;
   mfxMemId *mids = NULL;
   GstMsdkContext *context = (GstMsdkContext *) pthis;
   GstMsdkMemoryID *msdk_mids = NULL;
@@ -98,10 +99,21 @@ gst_msdk_frame_alloc (mfxHDL pthis, mfxFrameAllocRequest * req,
       (GstMsdkAllocResponse *) g_slice_alloc0 (sizeof (GstMsdkAllocResponse));
 
   if (va_fourcc != VA_FOURCC_P208) {
-    attrib.type = VASurfaceAttribPixelFormat;
-    attrib.flags = VA_SURFACE_ATTRIB_SETTABLE;
-    attrib.value.type = VAGenericValueTypeInteger;
-    attrib.value.value.i = va_fourcc;
+    attribs[0].type = VASurfaceAttribPixelFormat;
+    attribs[0].flags = VA_SURFACE_ATTRIB_SETTABLE;
+    attribs[0].value.type = VAGenericValueTypeInteger;
+    attribs[0].value.value.i = va_fourcc;
+    num_attribs = 1;
+
+    /* set VA_SURFACE_ATTRIB_USAGE_HINT_ENCODER flag for encoding */
+    if ((req->Type & MFX_MEMTYPE_VIDEO_MEMORY_ENCODER_TARGET) &&
+        (req->Type & MFX_MEMTYPE_FROM_ENCODE)) {
+      attribs[1].type = VASurfaceAttribUsageHint;
+      attribs[1].flags = VA_SURFACE_ATTRIB_SETTABLE;
+      attribs[1].value.type = VAGenericValueTypeInteger;
+      attribs[1].value.value.i = VA_SURFACE_ATTRIB_USAGE_HINT_ENCODER;
+      num_attribs = 2;
+    }
 
     format =
         gst_msdk_get_va_rt_format_from_mfx_rt_format (req->Info.ChromaFormat);
@@ -127,7 +139,8 @@ gst_msdk_frame_alloc (mfxHDL pthis, mfxFrameAllocRequest * req,
 
     va_status = vaCreateSurfaces (gst_msdk_context_get_handle (context),
         format,
-        req->Info.Width, req->Info.Height, surfaces, surfaces_num, &attrib, 1);
+        req->Info.Width, req->Info.Height, surfaces, surfaces_num, attribs,
+        num_attribs);
 
     status = gst_msdk_get_mfx_status_from_va_status (va_status);
     if (status != MFX_ERR_NONE) {
@@ -385,6 +398,13 @@ gst_msdk_frame_lock (mfxHDL pthis, mfxMemId mid, mfxFrameData * data)
         data->U = buf + mem_id->image.offsets[0];       /* data->Y410 */
         break;
 #endif
+      case VA_FOURCC_ABGR:
+        data->Pitch = mem_id->image.pitches[0];
+        data->R = buf + mem_id->image.offsets[0];
+        data->G = data->R + 1;
+        data->B = data->R + 2;
+        data->A = data->R + 3;
+        break;
 
       default:
         g_assert_not_reached ();
index 870fd412e034218db25bc0a952a29c7250e539a1..689956643ec68d4e8e27c99e668ef3af0869d0f1 100644 (file)
@@ -73,6 +73,7 @@ static const struct fourcc_map gst_msdk_fourcc_mfx_to_va[] = {
   FOURCC_MFX_TO_VA (Y210, Y210),
   FOURCC_MFX_TO_VA (Y410, Y410),
 #endif
+  FOURCC_MFX_TO_VA (BGR4, ABGR),
   {0, 0}
 };