Add mechanism to reinsert buffer leftovers into the queue.

This commit is contained in:
gb 2010-05-15 09:43:28 +00:00 committed by Gwenole Beauchesne
parent 9a3b4a7844
commit a777a98f2f
3 changed files with 51 additions and 7 deletions

View 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)
{
@ -413,6 +424,24 @@ gst_vaapi_decoder_ensure_context(
return priv->context != NULL;
}
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,

View 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;

View file

@ -131,6 +131,14 @@ gst_vaapi_decoder_ensure_context(
guint height
) 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,