vaapiencode: get surface formats in get_caps()
authorHyunjun Ko <zzoon@igalia.com>
Thu, 1 Dec 2016 09:57:10 +0000 (18:57 +0900)
committerVíctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
Wed, 7 Dec 2016 15:47:18 +0000 (16:47 +0100)
Query for the supported surface formats in config at get_caps() vmethod.

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

Signed-off-by: Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
gst/vaapi/gstvaapiencode.c
gst/vaapi/gstvaapiencode.h

index 8d76b3c..4a7c64f 100644 (file)
@@ -342,16 +342,72 @@ gst_vaapiencode_buffer_loop (GstVaapiEncode * encode)
   gst_pad_pause_task (GST_VAAPI_PLUGIN_BASE_SRC_PAD (encode));
 }
 
+static gboolean
+ensure_allowed_sinkpad_caps (GstVaapiEncode * encode)
+{
+  GstCaps *out_caps, *raw_caps = NULL;
+  GArray *formats = NULL;
+  gboolean ret = FALSE;
+
+  if (encode->allowed_sinkpad_caps)
+    return TRUE;
+  if (!encode->encoder)
+    return TRUE;
+
+  out_caps = gst_caps_from_string (GST_VAAPI_MAKE_SURFACE_CAPS);
+  if (!out_caps)
+    goto failed_create_va_caps;
+
+  formats = gst_vaapi_encoder_get_surface_formats (encode->encoder);
+  if (!formats)
+    goto failed_get_formats;
+
+  raw_caps = gst_vaapi_video_format_new_template_caps_from_list (formats);
+  if (!raw_caps)
+    goto failed_create_raw_caps;
+
+  out_caps = gst_caps_make_writable (out_caps);
+  gst_caps_append (out_caps, gst_caps_copy (raw_caps));
+  gst_caps_replace (&encode->allowed_sinkpad_caps, out_caps);
+  ret = TRUE;
+
+bail:
+  if (out_caps)
+    gst_caps_unref (out_caps);
+  if (raw_caps)
+    gst_caps_unref (raw_caps);
+  if (formats)
+    g_array_unref (formats);
+  return ret;
+
+failed_create_va_caps:
+  {
+    GST_WARNING_OBJECT (encode, "failed to create VA/GL sink caps");
+    return FALSE;
+  }
+failed_get_formats:
+  {
+    GST_WARNING_OBJECT (encode, "failed to get allowed surface formats");
+    goto bail;
+  }
+failed_create_raw_caps:
+  {
+    GST_WARNING_OBJECT (encode, "failed to create raw sink caps");
+    goto bail;
+  }
+}
+
 static GstCaps *
 gst_vaapiencode_get_caps (GstVideoEncoder * venc, GstCaps * filter)
 {
-  GstVaapiPluginBase *const plugin = GST_VAAPI_PLUGIN_BASE (venc);
+  GstVaapiEncode *const encode = GST_VAAPIENCODE_CAST (venc);
   GstCaps *result;
 
-  result = gst_video_encoder_proxy_getcaps (venc, plugin->sinkpad_caps, filter);
+  ensure_allowed_sinkpad_caps (encode);
+  result = gst_video_encoder_proxy_getcaps (venc, encode->allowed_sinkpad_caps,
+      filter);
 
   GST_DEBUG_OBJECT (venc, "Returning sink caps %" GST_PTR_FORMAT, result);
-
   return result;
 }
 
@@ -367,6 +423,8 @@ gst_vaapiencode_destroy (GstVaapiEncode * encode)
     gst_video_codec_state_unref (encode->output_state);
     encode->output_state = NULL;
   }
+
+  gst_caps_replace (&encode->allowed_sinkpad_caps, NULL);
   gst_vaapi_encoder_replace (&encode->encoder, NULL);
   return TRUE;
 }
index 03c6a10..77a8a40 100644 (file)
@@ -59,6 +59,7 @@ struct _GstVaapiEncode
   gboolean need_codec_data;
   GstVideoCodecState *output_state;
   GPtrArray *prop_values;
+  GstCaps *allowed_sinkpad_caps;
 };
 
 struct _GstVaapiEncodeClass