audio: Always provide a buffer in gst_audio_(enc|dec)oder_allocate_output_buffer()
authorSebastian Dröge <slomo@circular-chaos.org>
Fri, 24 May 2013 14:52:50 +0000 (16:52 +0200)
committerSebastian Dröge <slomo@circular-chaos.org>
Fri, 24 May 2013 14:54:46 +0000 (16:54 +0200)
We have no way of tell the caller of the exact error (e.g. if we're flushing),
so will have to wait until the caller uses API that returns a GstFlowReturn,
for example when pushing this buffer.

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

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

index d9bfe95..f8fb8b7 100644 (file)
@@ -2985,15 +2985,25 @@ gst_audio_decoder_allocate_output_buffer (GstAudioDecoder * dec, gsize size)
   if (G_UNLIKELY (dec->priv->ctx.output_format_changed ||
           (GST_AUDIO_INFO_IS_VALID (&dec->priv->ctx.info)
               && gst_pad_check_reconfigure (dec->srcpad)))) {
-    if (!gst_audio_decoder_negotiate (dec))
-      goto done;
+    if (!gst_audio_decoder_negotiate (dec)) {
+      GST_INFO_OBJECT (dec, "Failed to negotiate, fallback allocation");
+      goto fallback;
+    }
   }
 
   buffer =
       gst_buffer_new_allocate (dec->priv->ctx.allocator, size,
       &dec->priv->ctx.params);
+  if (!buffer) {
+    GST_INFO_OBJECT (dec, "couldn't allocate output buffer");
+    goto fallback;
+  }
 
-done:
+  GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
+
+  return buffer;
+fallback:
+  buffer = gst_buffer_new_allocate (NULL, size, NULL);
   GST_AUDIO_DECODER_STREAM_UNLOCK (dec);
 
   return buffer;
index 9ed5924..3bf6b22 100644 (file)
@@ -2726,15 +2726,26 @@ gst_audio_encoder_allocate_output_buffer (GstAudioEncoder * enc, gsize size)
 
   if (G_UNLIKELY (enc->priv->ctx.output_caps_changed || (enc->priv->ctx.caps
               && gst_pad_check_reconfigure (enc->srcpad)))) {
-    if (!gst_audio_encoder_negotiate (enc))
-      goto done;
+    if (!gst_audio_encoder_negotiate (enc)) {
+      GST_INFO_OBJECT (enc, "Failed to negotiate, fallback allocation");
+      goto fallback;
+    }
   }
 
   buffer =
       gst_buffer_new_allocate (enc->priv->ctx.allocator, size,
       &enc->priv->ctx.params);
+  if (!buffer) {
+    GST_INFO_OBJECT (enc, "couldn't allocate output buffer");
+    goto fallback;
+  }
 
-done:
+  GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
+
+  return buffer;
+
+fallback:
+  buffer = gst_buffer_new_allocate (NULL, size, NULL);
   GST_AUDIO_ENCODER_STREAM_UNLOCK (enc);
 
   return buffer;