libs: encoder: initialize chroma_type
authorVíctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
Tue, 4 Apr 2017 12:21:43 +0000 (14:21 +0200)
committerVíctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
Thu, 6 Apr 2017 20:00:05 +0000 (22:00 +0200)
Instead of initialize the chroma_type with a undefined value, which
will be converted to GST_VAAPI_CHROMA_TYPE_YUV420 by GstVaapiContext,
this patch queries the VA config, given the received
GstVaapiContextInfo's parameters, and gets the first response.

In order to get the GstVaapiChromaType value, also it was needed to
add a new utility function: to_GstVaapiChromaType(), which, given a
VA_RT_FORMAT_* will return the associated GstVaapiChromaType.

https://bugzilla.gnome.org/show_bug.cgi?id=771291

gst-libs/gst/vaapi/gstvaapiencoder.c
gst-libs/gst/vaapi/gstvaapiutils.c
gst-libs/gst/vaapi/gstvaapiutils.h

index 2989ff8..a1ec791 100644 (file)
@@ -588,6 +588,21 @@ unsupported:
   }
 }
 
+static guint
+get_default_chroma_type (GstVaapiEncoder * encoder,
+    const GstVaapiContextInfo * cip)
+{
+  guint value;
+
+  if (!gst_vaapi_get_config_attribute (encoder->display,
+          gst_vaapi_profile_get_va_profile (cip->profile),
+          gst_vaapi_entrypoint_get_va_entrypoint (cip->entrypoint),
+          VAConfigAttribRTFormat, &value))
+    return 0;
+
+  return to_GstVaapiChromaType (value);
+}
+
 static void
 init_context_info (GstVaapiEncoder * encoder)
 {
@@ -603,6 +618,7 @@ init_context_info (GstVaapiEncoder * encoder)
     if (cip->entrypoint != GST_VAAPI_ENTRYPOINT_SLICE_ENCODE_LP)
       cip->entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE;
   }
+  cip->chroma_type = get_default_chroma_type (encoder, cip);
   cip->width = 0;
   cip->height = 0;
   cip->ref_frames = encoder->num_ref_frames;
index d583ab4..0ed1efe 100644 (file)
@@ -316,6 +316,56 @@ string_of_VARateControl (guint rate_control)
 }
 
 /**
+ * to_GstVaapiChromaType:
+ * @va_rt_format: the value of VAConfigAttribRTFormat
+ *
+ * Converts the VA_RT_FORMAT_* to #GstVaapiChromaType
+ *
+ * Returns: the #GstVaapiChromaType associated to @va_rt_format or
+ * zero.
+ **/
+guint
+to_GstVaapiChromaType (guint va_rt_format)
+{
+  guint chroma_type;
+
+  switch (va_rt_format) {
+    case VA_RT_FORMAT_YUV420:
+      chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
+      break;
+    case VA_RT_FORMAT_YUV422:
+      chroma_type = GST_VAAPI_CHROMA_TYPE_YUV422;
+      break;
+    case VA_RT_FORMAT_YUV444:
+      chroma_type = GST_VAAPI_CHROMA_TYPE_YUV444;
+      break;
+#if VA_CHECK_VERSION(0,34,0)
+    case VA_RT_FORMAT_YUV411:
+      chroma_type = GST_VAAPI_CHROMA_TYPE_YUV411;
+      break;
+    case VA_RT_FORMAT_YUV400:
+      chroma_type = GST_VAAPI_CHROMA_TYPE_YUV400;
+      break;
+    case VA_RT_FORMAT_RGB32:
+      chroma_type = GST_VAAPI_CHROMA_TYPE_RGB32;
+      break;
+    case VA_RT_FORMAT_RGB16:
+      chroma_type = GST_VAAPI_CHROMA_TYPE_RGB16;
+      break;
+#endif
+#if VA_CHECK_VERSION(0,38,1)
+    case VA_RT_FORMAT_YUV420_10BPP:
+      chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420_10BPP;
+      break;
+#endif
+    default:
+      chroma_type = 0;
+      break;
+  }
+  return chroma_type;
+}
+
+/**
  * from_GstVaapiChromaType:
  * @chroma_type: the #GstVaapiChromaType
  *
index b4ee99e..41b5762 100644 (file)
@@ -87,6 +87,10 @@ string_of_VARateControl (guint rate_control);
 
 G_GNUC_INTERNAL
 guint
+to_GstVaapiChromaType (guint va_rt_format);
+
+G_GNUC_INTERNAL
+guint
 from_GstVaapiChromaType (guint chroma_type);
 
 G_GNUC_INTERNAL