mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-22 00:06:36 +00:00
ffmpegdec: do buffer padding before parsing and before decoding
FFMpeg parsing and decoding calls require to additionally allocate bytes at the end of the input bitstream and this padding must be initialized to zero. https://bugzilla.gnome.org/show_bug.cgi?id=595590
This commit is contained in:
parent
2289cc2d5b
commit
f63d36ade8
1 changed files with 25 additions and 17 deletions
|
@ -2450,7 +2450,7 @@ gst_ffmpegdec_chain (GstPad * pad, GstBuffer * inbuf)
|
|||
{
|
||||
GstFFMpegDec *ffmpegdec;
|
||||
GstFFMpegDecClass *oclass;
|
||||
guint8 *data, *bdata, *pdata;
|
||||
guint8 *data, *bdata;
|
||||
gint size, bsize, len, have_data;
|
||||
GstFlowReturn ret = GST_FLOW_OK;
|
||||
GstClockTime in_timestamp;
|
||||
|
@ -2557,7 +2557,23 @@ gst_ffmpegdec_chain (GstPad * pad, GstBuffer * inbuf)
|
|||
bdata = GST_BUFFER_DATA (inbuf);
|
||||
bsize = GST_BUFFER_SIZE (inbuf);
|
||||
|
||||
if (ffmpegdec->do_padding) {
|
||||
/* add padding */
|
||||
if (ffmpegdec->padded_size < bsize + FF_INPUT_BUFFER_PADDING_SIZE) {
|
||||
ffmpegdec->padded_size = bsize + FF_INPUT_BUFFER_PADDING_SIZE;
|
||||
ffmpegdec->padded = g_realloc (ffmpegdec->padded, ffmpegdec->padded_size);
|
||||
GST_LOG_OBJECT (ffmpegdec, "resized padding buffer to %d",
|
||||
ffmpegdec->padded_size);
|
||||
}
|
||||
memcpy (ffmpegdec->padded, bdata, bsize);
|
||||
memset (ffmpegdec->padded + bsize, 0, FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
|
||||
bdata = ffmpegdec->padded;
|
||||
}
|
||||
|
||||
do {
|
||||
guint8 tmp_padding[FF_INPUT_BUFFER_PADDING_SIZE];
|
||||
|
||||
/* parse, if at all possible */
|
||||
if (ffmpegdec->pctx) {
|
||||
gint res;
|
||||
|
@ -2616,26 +2632,18 @@ gst_ffmpegdec_chain (GstPad * pad, GstBuffer * inbuf)
|
|||
}
|
||||
|
||||
if (ffmpegdec->do_padding) {
|
||||
/* add padding */
|
||||
if (ffmpegdec->padded_size < size + FF_INPUT_BUFFER_PADDING_SIZE) {
|
||||
ffmpegdec->padded_size = size + FF_INPUT_BUFFER_PADDING_SIZE;
|
||||
ffmpegdec->padded =
|
||||
g_realloc (ffmpegdec->padded, ffmpegdec->padded_size);
|
||||
GST_LOG_OBJECT (ffmpegdec, "resized padding buffer to %d",
|
||||
ffmpegdec->padded_size);
|
||||
}
|
||||
memcpy (ffmpegdec->padded, data, size);
|
||||
memset (ffmpegdec->padded + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
|
||||
pdata = ffmpegdec->padded;
|
||||
} else {
|
||||
pdata = data;
|
||||
/* add temporary padding */
|
||||
memcpy (tmp_padding, data + size, FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
memset (data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
}
|
||||
|
||||
/* decode a frame of audio/video now */
|
||||
len =
|
||||
gst_ffmpegdec_frame (ffmpegdec, pdata, size, &have_data, dec_info,
|
||||
&ret);
|
||||
gst_ffmpegdec_frame (ffmpegdec, data, size, &have_data, dec_info, &ret);
|
||||
|
||||
if (ffmpegdec->do_padding) {
|
||||
memcpy (data + size, tmp_padding, FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
}
|
||||
|
||||
if (ret != GST_FLOW_OK) {
|
||||
GST_LOG_OBJECT (ffmpegdec, "breaking because of flow ret %s",
|
||||
|
|
Loading…
Reference in a new issue