Add mechanism to reinsert buffer leftovers into the queue.
authorgb <gb@5584edef-b1fe-4b99-b61b-dd2bab72e969>
Sat, 15 May 2010 09:43:28 +0000 (09:43 +0000)
committerGwenole Beauchesne <gbeauchesne@splitted-desktop.com>
Mon, 20 Sep 2010 10:55:46 +0000 (12:55 +0200)
gst-libs/gst/vaapi/gstvaapidecoder.c
gst-libs/gst/vaapi/gstvaapidecoder_ffmpeg.c
gst-libs/gst/vaapi/gstvaapidecoder_priv.h

index 0bdf05e..7fb4e86 100644 (file)
@@ -70,6 +70,17 @@ push_buffer(GstVaapiDecoder *decoder, GstBuffer *buffer)
     return TRUE;
 }
 
+static void
+push_back_buffer(GstVaapiDecoder *decoder, GstBuffer *buffer)
+{
+    GstVaapiDecoderPrivate * const priv = decoder->priv;
+
+    GST_DEBUG("requeue encoded data buffer %p (%d bytes)",
+              buffer, GST_BUFFER_SIZE(buffer));
+
+    g_queue_push_head(priv->buffers, buffer);
+}
+
 static GstBuffer *
 pop_buffer(GstVaapiDecoder *decoder)
 {
@@ -414,6 +425,24 @@ gst_vaapi_decoder_ensure_context(
 }
 
 gboolean
+gst_vaapi_decoder_push_buffer_sub(
+    GstVaapiDecoder *decoder,
+    GstBuffer       *buffer,
+    guint            offset,
+    guint            size
+)
+{
+    GstBuffer *subbuffer;
+
+    subbuffer = gst_buffer_create_sub(buffer, offset, size);
+    if (!subbuffer)
+        return FALSE;
+
+    push_back_buffer(decoder, subbuffer);
+    return TRUE;
+}
+
+gboolean
 gst_vaapi_decoder_push_surface(
     GstVaapiDecoder *decoder,
     GstVaapiSurface *surface,
index 79fa94f..5537ea3 100644 (file)
@@ -490,8 +490,8 @@ gst_vaapi_decoder_ffmpeg_decode(GstVaapiDecoder *decoder, GstBuffer *buffer)
     GstVaapiDecoderFfmpeg * const ffdecoder = GST_VAAPI_DECODER_FFMPEG(decoder);
     GstVaapiDecoderFfmpegPrivate * const priv = ffdecoder->priv;
     GstClockTime inbuf_ts;
-    guchar *inbuf, *outbuf;
-    gint inbuf_size, outbuf_size;
+    guchar *outbuf;
+    gint inbuf_ofs, inbuf_size, outbuf_size;
     gboolean got_frame;
 
     g_return_val_if_fail(priv->is_constructed,
@@ -503,7 +503,7 @@ gst_vaapi_decoder_ffmpeg_decode(GstVaapiDecoder *decoder, GstBuffer *buffer)
             return GST_VAAPI_DECODER_STATUS_ERROR_UNSUPPORTED_CODEC;
     }
 
-    inbuf      = GST_BUFFER_DATA(buffer);
+    inbuf_ofs  = 0;
     inbuf_size = GST_BUFFER_SIZE(buffer);
     inbuf_ts   = GST_BUFFER_TIMESTAMP(buffer);
 
@@ -513,24 +513,31 @@ gst_vaapi_decoder_ffmpeg_decode(GstVaapiDecoder *decoder, GstBuffer *buffer)
                 priv->pctx,
                 priv->avctx,
                 &outbuf, &outbuf_size,
-                inbuf, inbuf_size,
+                GST_BUFFER_DATA(buffer) + inbuf_ofs, inbuf_size,
                 inbuf_ts, inbuf_ts
             );
             got_frame = outbuf && outbuf_size > 0;
 
             if (parsed_size > 0) {
-                inbuf      += parsed_size;
+                inbuf_ofs  += parsed_size;
                 inbuf_size -= parsed_size;
             }
         } while (!got_frame && inbuf_size > 0);
         inbuf_ts    = priv->pctx->pts;
     }
     else {
-        outbuf      = inbuf;
+        outbuf      = GST_BUFFER_DATA(buffer);
         outbuf_size = inbuf_size;
-        got_frame   = inbuf && inbuf_size > 0;
+        got_frame   = outbuf && outbuf_size > 0;
+        inbuf_ofs   = inbuf_size;
+        inbuf_size  = 0;
     }
 
+    if (inbuf_size > 0 &&
+        !gst_vaapi_decoder_push_buffer_sub(decoder, buffer,
+                                           inbuf_ofs, inbuf_size))
+        return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED;
+
     if (!got_frame && !GST_BUFFER_IS_EOS(buffer))
         return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
 
index 2b30cf3..2dd0285 100644 (file)
@@ -132,6 +132,14 @@ gst_vaapi_decoder_ensure_context(
 ) attribute_hidden;
 
 gboolean
+gst_vaapi_decoder_push_buffer_sub(
+    GstVaapiDecoder *decoder,
+    GstBuffer       *buffer,
+    guint            offset,
+    guint            size
+) attribute_hidden;
+
+gboolean
 gst_vaapi_decoder_push_surface(
     GstVaapiDecoder *decoder,
     GstVaapiSurface *surface,