[FFmpeg-devel,06/12] avformat/audiointerleave: pad last audio frame

Submitted by Baptiste Coudurier on July 4, 2018, 6:35 p.m.

Details

Message ID 20180704183514.71654-6-baptiste.coudurier@gmail.com
State New
Headers show

Commit Message

Baptiste Coudurier July 4, 2018, 6:35 p.m.
---
 libavformat/audiointerleave.c | 10 +++++++---
 tests/ref/lavf/mxf            |  4 ++--
 2 files changed, 9 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c
index 6d4954befe..dea5d99821 100644
--- a/libavformat/audiointerleave.c
+++ b/libavformat/audiointerleave.c
@@ -81,15 +81,19 @@  static int interleave_new_audio_packet(AVFormatContext *s, AVPacket *pkt,
     AVStream *st = s->streams[stream_index];
     AudioInterleaveContext *aic = st->priv_data;
     int ret;
-    int size = FFMIN(av_fifo_size(aic->fifo), *aic->samples * aic->sample_size);
+    int frame_size = *aic->samples * aic->sample_size;
+    int size = FFMIN(av_fifo_size(aic->fifo), frame_size);
     if (!size || (!flush && size == av_fifo_size(aic->fifo)))
         return 0;
 
-    ret = av_new_packet(pkt, size);
+    ret = av_new_packet(pkt, frame_size);
     if (ret < 0)
         return ret;
     av_fifo_generic_read(aic->fifo, pkt->data, size, NULL);
 
+    if (size < pkt->size)
+        memset(pkt->data + size, 0, pkt->size - size);
+
     pkt->dts = pkt->pts = aic->dts;
     pkt->duration = av_rescale_q(*aic->samples, st->time_base, aic->time_base);
     pkt->stream_index = stream_index;
@@ -99,7 +103,7 @@  static int interleave_new_audio_packet(AVFormatContext *s, AVPacket *pkt,
     if (!*aic->samples)
         aic->samples = aic->samples_per_frame;
 
-    return size;
+    return pkt->size;
 }
 
 int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush,
diff --git a/tests/ref/lavf/mxf b/tests/ref/lavf/mxf
index 81d21704d9..4466685a2d 100644
--- a/tests/ref/lavf/mxf
+++ b/tests/ref/lavf/mxf
@@ -1,9 +1,9 @@ 
 649009e3d3d62eb3b6c56334d057cc4d *./tests/data/lavf/lavf.mxf
 526393 ./tests/data/lavf/lavf.mxf
 ./tests/data/lavf/lavf.mxf CRC=0x8dddfaab
-5756c5f9bdb9718b91bfbf588afec189 *./tests/data/lavf/lavf.mxf
+9076b7015cffe8aa72883e900a2041a5 *./tests/data/lavf/lavf.mxf
 561721 ./tests/data/lavf/lavf.mxf
-./tests/data/lavf/lavf.mxf CRC=0xf21b1b48
+./tests/data/lavf/lavf.mxf CRC=0x96ff1b48
 02bf8f0cd8951a49e277306691cb1538 *./tests/data/lavf/lavf.mxf
 526393 ./tests/data/lavf/lavf.mxf
 ./tests/data/lavf/lavf.mxf CRC=0x8dddfaab