libs: encoder: dummy context for get_surface_formats()
authorVíctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
Thu, 6 Apr 2017 10:28:51 +0000 (12:28 +0200)
committerVíctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
Thu, 6 Apr 2017 20:00:05 +0000 (22:00 +0200)
Instead of creating (if it doesn't exist, yet) the encoder's context
the method gst_vaapi_encoder_get_surface_formats() now it creates
dummy contexts, unless the encoder has it already created.

The purpose of this is to avoid setting a encoder's context with a
wrong profile.

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

gst-libs/gst/vaapi/gstvaapiencoder.c

index f4836e3..3ecd2c4 100644 (file)
@@ -1160,17 +1160,18 @@ error:
   }
 }
 
-static gboolean
-gst_vaapi_encoder_ensure_context_config (GstVaapiEncoder * encoder)
+static GstVaapiContext *
+create_test_context_config (GstVaapiEncoder * encoder)
 {
-  GstVaapiContextInfo *const cip = &encoder->context_info;
+  GstVaapiContextInfo cip = { 0, };
+  GstVaapiContext *ctxt;
 
   if (encoder->context)
-    return TRUE;
+    return gst_vaapi_object_ref (encoder->context);
 
-  init_context_info (encoder, cip, get_profile (encoder));
-  encoder->context = gst_vaapi_context_new (encoder->display, cip);
-  return (encoder->context != NULL);
+  init_context_info (encoder, &cip, get_profile (encoder));
+  ctxt = gst_vaapi_context_new (encoder->display, &cip);
+  return ctxt;
 }
 
 /**
@@ -1184,9 +1185,15 @@ gst_vaapi_encoder_ensure_context_config (GstVaapiEncoder * encoder)
 GArray *
 gst_vaapi_encoder_get_surface_formats (GstVaapiEncoder * encoder)
 {
-  if (!gst_vaapi_encoder_ensure_context_config (encoder))
+  GstVaapiContext *ctxt;
+  GArray *formats;
+
+  ctxt = create_test_context_config (encoder);
+  if (!ctxt)
     return NULL;
-  return gst_vaapi_context_get_surface_formats (encoder->context);
+  formats = gst_vaapi_context_get_surface_formats (ctxt);
+  gst_vaapi_object_unref (ctxt);
+  return formats;
 }
 
 /** Returns a GType for the #GstVaapiEncoderTune set */