audiodecoder: Add negotiate vfunc that is used to negotiate with downstream
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Thu, 9 Aug 2012 13:07:18 +0000 (15:07 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Thu, 9 Aug 2012 13:10:05 +0000 (15:10 +0200)
The default implementation negotiates a buffer pool and allocator
with downstream.

gst-libs/gst/audio/gstaudiodecoder.c
gst-libs/gst/audio/gstaudiodecoder.h

index 1bb6efb..630b5c0 100644 (file)
@@ -308,6 +308,7 @@ static gboolean gst_audio_decoder_decide_allocation_default (GstAudioDecoder *
     dec, GstQuery * query);
 static gboolean gst_audio_decoder_propose_allocation_default (GstAudioDecoder *
     dec, GstQuery * query);
+static gboolean gst_audio_decoder_negotiate_default (GstAudioDecoder * dec);
 
 static GstElementClass *parent_class = NULL;
 
@@ -393,6 +394,8 @@ gst_audio_decoder_class_init (GstAudioDecoderClass * klass)
       GST_DEBUG_FUNCPTR (gst_audio_decoder_propose_allocation_default);
   audiodecoder_class->decide_allocation =
       GST_DEBUG_FUNCPTR (gst_audio_decoder_decide_allocation_default);
+  audiodecoder_class->negotiate =
+      GST_DEBUG_FUNCPTR (gst_audio_decoder_negotiate_default);
 }
 
 static void
@@ -524,16 +527,8 @@ gst_audio_decoder_finalize (GObject * object)
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
-/**
- * gst_audio_decoder_negotiate:
- * @dec: a #GstAudioDecoder
- *
- * Negotiate with downstreame elements to currently configured #GstAudioInfo.
- *
- * Returns: #TRUE if the negotiation succeeded, else #FALSE.
- */
-gboolean
-gst_audio_decoder_negotiate (GstAudioDecoder * dec)
+static gboolean
+gst_audio_decoder_negotiate_default (GstAudioDecoder * dec)
 {
   GstAudioDecoderClass *klass;
   gboolean res = TRUE;
@@ -547,8 +542,6 @@ gst_audio_decoder_negotiate (GstAudioDecoder * dec)
 
   klass = GST_AUDIO_DECODER_GET_CLASS (dec);
 
-  GST_AUDIO_DECODER_STREAM_LOCK (dec);
-
   GST_DEBUG_OBJECT (dec, "setting src caps %" GST_PTR_FORMAT, caps);
 
   caps = gst_audio_info_to_caps (&dec->priv->ctx.info);
@@ -587,7 +580,6 @@ gst_audio_decoder_negotiate (GstAudioDecoder * dec)
   dec->priv->ctx.params = params;
 
 done:
-  GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
 
   if (query)
     gst_query_unref (query);
@@ -604,6 +596,32 @@ no_decide_allocation:
 }
 
 /**
+ * gst_audio_decoder_negotiate:
+ * @dec: a #GstAudioDecoder
+ *
+ * Negotiate with downstreame elements to currently configured #GstAudioInfo.
+ *
+ * Returns: #TRUE if the negotiation succeeded, else #FALSE.
+ */
+gboolean
+gst_audio_decoder_negotiate (GstAudioDecoder * dec)
+{
+  GstAudioDecoderClass *klass;
+  gboolean res = TRUE;
+
+  g_return_val_if_fail (GST_IS_AUDIO_DECODER (dec), FALSE);
+
+  klass = GST_AUDIO_DECODER_GET_CLASS (dec);
+
+  GST_AUDIO_DECODER_STREAM_LOCK (dec);
+  if (klass->negotiate)
+    res = klass->negotiate (dec);
+  GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
+
+  return res;
+}
+
+/**
  * gst_audio_decoder_set_output_format:
  * @dec: a #GstAudioDecoder
  * @info: #GstAudioInfo
@@ -660,7 +678,8 @@ gst_audio_decoder_set_output_format (GstAudioDecoder * dec,
 done:
   GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
 
-  gst_caps_unref (caps);
+  if (caps)
+    gst_caps_unref (caps);
 
   return res;
 
index 5285d0d..cbc2464 100644 (file)
@@ -213,6 +213,8 @@ struct _GstAudioDecoder
  * @close:          Optional.
  *                  Called when the element changes to GST_STATE_NULL.
  *                  Allows closing external resources.
+ * @negotiate:      Optional.
+ *                  Negotiate with downstream and configure buffer pools, etc.
  * @decide_allocation: Optional.
  *                     Setup the allocation parameters for allocating output
  *                     buffers. The passed in query contains the result of the
@@ -259,6 +261,8 @@ struct _GstAudioDecoderClass
   
   gboolean      (*close)              (GstAudioDecoder *dec);
 
+  gboolean      (*negotiate)          (GstAudioDecoder *dec);
+
   gboolean      (*decide_allocation)  (GstAudioDecoder *dec, GstQuery *query);
 
   gboolean      (*propose_allocation) (GstAudioDecoder *dec,