libs: audio: split allocation query caps and pad caps
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Fri, 1 Apr 2016 10:25:14 +0000 (12:25 +0200)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Tue, 5 Apr 2016 09:37:15 +0000 (11:37 +0200)
Since the allocation query caps contains memory size and the pad's caps
contains the display size, an audio encoder or decoder might need to allocate
a different buffer size than the size negotiated in the caps.

This patch splits this logic distinction for audiodecoder and audioencoder.

Thus the user, if needs a different allocation caps, should set it through
gst_audio_{encoder,decoder}_set_allocation_cap() before calling the negotiate()
vmethod. Otherwise the allocation_caps will be the same as the caps in the
src pad.

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

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

index e65b76c..4a43c94 100644 (file)
@@ -203,6 +203,7 @@ typedef struct _GstAudioDecoderContext
   gboolean do_plc;
   gboolean do_estimate_rate;
   gint max_errors;
+  GstCaps *allocation_caps;
   /* MT-protected (with LOCK) */
   GstClockTime min_latency;
   GstClockTime max_latency;
@@ -525,6 +526,7 @@ gst_audio_decoder_reset (GstAudioDecoder * dec, gboolean full)
       gst_object_unref (dec->priv->ctx.allocator);
 
     gst_caps_replace (&dec->priv->ctx.input_caps, NULL);
+    gst_caps_replace (&dec->priv->ctx.allocation_caps, NULL);
 
     memset (&dec->priv->ctx, 0, sizeof (dec->priv->ctx));
 
@@ -639,6 +641,8 @@ gst_audio_decoder_negotiate_default (GstAudioDecoder * dec)
   klass = GST_AUDIO_DECODER_GET_CLASS (dec);
 
   caps = gst_audio_info_to_caps (&dec->priv->ctx.info);
+  if (dec->priv->ctx.allocation_caps == NULL)
+    dec->priv->ctx.allocation_caps = gst_caps_ref (caps);
 
   GST_DEBUG_OBJECT (dec, "setting src caps %" GST_PTR_FORMAT, caps);
 
@@ -673,7 +677,7 @@ gst_audio_decoder_negotiate_default (GstAudioDecoder * dec)
     goto done;
   dec->priv->ctx.output_format_changed = FALSE;
 
-  query = gst_query_new_allocation (caps, TRUE);
+  query = gst_query_new_allocation (dec->priv->ctx.allocation_caps, TRUE);
   if (!gst_pad_peer_query (dec->srcpad, query)) {
     GST_DEBUG_OBJECT (dec, "didn't get downstream ALLOCATION hints");
   }
@@ -3266,6 +3270,27 @@ gst_audio_decoder_get_parse_state (GstAudioDecoder * dec,
 }
 
 /**
+ * gst_audio_decoder_set_allocation_caps:
+ * @dec: a #GstAudioDecoder
+ * @allocation_caps: (allow-none): a #GstCaps or %NULL
+ *
+ * Sets a caps in allocation query which are different from the set
+ * pad's caps. Use this function before calling
+ * gst_audio_decoder_negotiate(). Setting to %NULL the allocation
+ * query will use the caps from the pad.
+ *
+ * Since: 1.10
+ */
+void
+gst_audio_decoder_set_allocation_caps (GstAudioDecoder * dec,
+    GstCaps * allocation_caps)
+{
+  g_return_if_fail (GST_IS_AUDIO_DECODER (dec));
+
+  gst_caps_replace (&dec->priv->ctx.allocation_caps, allocation_caps);
+}
+
+/**
  * gst_audio_decoder_set_plc:
  * @dec: a #GstAudioDecoder
  * @enabled: new state
index f364161..71e0ce7 100644 (file)
@@ -360,6 +360,8 @@ void              gst_audio_decoder_get_parse_state (GstAudioDecoder * dec,
                                                      gboolean        * sync,
                                                      gboolean        * eos);
 
+void              gst_audio_decoder_set_allocation_caps (GstAudioDecoder * dec,
+                                                         GstCaps         * allocation_caps);
 
 /* object properties */
 void              gst_audio_decoder_set_plc (GstAudioDecoder * dec,
index ac751a8..50ed79c 100644 (file)
@@ -194,6 +194,7 @@ typedef struct _GstAudioEncoderContext
 
   /* output */
   GstCaps *caps;
+  GstCaps *allocation_caps;
   gboolean output_caps_changed;
   gint frame_samples_min, frame_samples_max;
   gint frame_max;
@@ -492,6 +493,7 @@ gst_audio_encoder_reset (GstAudioEncoder * enc, gboolean full)
 
     gst_caps_replace (&enc->priv->ctx.input_caps, NULL);
     gst_caps_replace (&enc->priv->ctx.caps, NULL);
+    gst_caps_replace (&enc->priv->ctx.allocation_caps, NULL);
 
     memset (&enc->priv->ctx, 0, sizeof (enc->priv->ctx));
     gst_audio_info_init (&enc->priv->ctx.info);
@@ -2387,6 +2389,27 @@ gst_audio_encoder_set_headers (GstAudioEncoder * enc, GList * headers)
 }
 
 /**
+ * gst_audio_encoder_set_allocation_caps:
+ * @enc: a #GstAudioEncoder
+ * @allocation_caps: (allow-none): a #GstCaps or %NULL
+ *
+ * Sets a caps in allocation query which are different from the set
+ * pad's caps. Use this function before calling
+ * gst_audio_encoder_negotiate(). Setting to %NULL the allocation
+ * query will use the caps from the pad.
+ *
+ * Since: 1.10
+ */
+void
+gst_audio_encoder_set_allocation_caps (GstAudioEncoder * enc,
+    GstCaps * allocation_caps)
+{
+  g_return_if_fail (GST_IS_AUDIO_ENCODER (enc));
+
+  gst_caps_replace (&enc->priv->ctx.allocation_caps, allocation_caps);
+}
+
+/**
  * gst_audio_encoder_set_mark_granule:
  * @enc: a #GstAudioEncoder
  * @enabled: new state
@@ -2717,6 +2740,8 @@ gst_audio_encoder_negotiate_default (GstAudioEncoder * enc)
   klass = GST_AUDIO_ENCODER_GET_CLASS (enc);
 
   caps = enc->priv->ctx.caps;
+  if (enc->priv->ctx.allocation_caps == NULL)
+    enc->priv->ctx.allocation_caps = gst_caps_ref (caps);
 
   GST_DEBUG_OBJECT (enc, "Setting srcpad caps %" GST_PTR_FORMAT, caps);
 
@@ -2751,7 +2776,7 @@ gst_audio_encoder_negotiate_default (GstAudioEncoder * enc)
     goto done;
   enc->priv->ctx.output_caps_changed = FALSE;
 
-  query = gst_query_new_allocation (caps, TRUE);
+  query = gst_query_new_allocation (enc->priv->ctx.allocation_caps, TRUE);
   if (!gst_pad_peer_query (enc->srcpad, query)) {
     GST_DEBUG_OBJECT (enc, "didn't get downstream ALLOCATION hints");
   }
index 47ca340..a186bd5 100644 (file)
@@ -295,6 +295,9 @@ void            gst_audio_encoder_set_latency (GstAudioEncoder * enc,
 void            gst_audio_encoder_set_headers (GstAudioEncoder * enc,
                                                GList           * headers);
 
+void            gst_audio_encoder_set_allocation_caps (GstAudioEncoder * enc,
+                                                       GstCaps         * allocation_caps);
+
 /* object properties */
 
 void            gst_audio_encoder_set_mark_granule (GstAudioEncoder * enc,