diff mbox series

[FFmpeg-devel,3/5] avformat/argo_asf: read multiple blocks at once

Message ID 20200916073836.27644-3-zane@zanevaniperen.com
State Superseded
Headers show
Series [FFmpeg-devel,1/5] avcodec/adpcm_argo: support decoding multiple frames
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Zane van Iperen Sept. 16, 2020, 7:39 a.m. UTC
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
---
 libavformat/argo_asf.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c
index b1632f3ba5..deb64f7b1c 100644
--- a/libavformat/argo_asf.c
+++ b/libavformat/argo_asf.c
@@ -26,6 +26,9 @@ 
 #include "libavutil/opt.h"
 #include "argo_asf.h"
 
+/* Maximum number of blocks to read at once. */
+#define ASF_NB_BLOCKS 32
+
 typedef struct ArgoASFDemuxContext {
     ArgoASFFileHeader   fhdr;
     ArgoASFChunkHeader  ckhdr;
@@ -125,12 +128,10 @@  int ff_argo_asf_fill_stream(AVStream *st, const ArgoASFFileHeader *fhdr,
      * (nchannel control bytes) + ((bytes_per_channel) * nchannel)
      * For mono, this is 17. For stereo, this is 34.
      */
-    st->codecpar->frame_size            = st->codecpar->channels +
+    st->codecpar->block_align           = st->codecpar->channels +
                                           (ckhdr->num_samples / 2) *
                                           st->codecpar->channels;
 
-    st->codecpar->block_align           = st->codecpar->frame_size;
-
     st->codecpar->bit_rate              = st->codecpar->channels *
                                           st->codecpar->sample_rate *
                                           st->codecpar->bits_per_coded_sample;
@@ -221,15 +222,21 @@  static int argo_asf_read_packet(AVFormatContext *s, AVPacket *pkt)
     if (asf->blocks_read >= asf->ckhdr.num_blocks)
         return AVERROR_EOF;
 
-    if ((ret = av_get_packet(pb, pkt, st->codecpar->frame_size)) < 0)
+    ret = av_get_packet(pb, pkt, st->codecpar->block_align *
+                        FFMIN(ASF_NB_BLOCKS, asf->ckhdr.num_blocks - asf->blocks_read));
+    if (ret < 0)
         return ret;
-    else if (ret != st->codecpar->frame_size)
+
+    /* Something real screwy is going on. */
+    if (ret % st->codecpar->block_align != 0)
         return AVERROR_INVALIDDATA;
 
+
     pkt->stream_index   = st->index;
-    pkt->duration       = asf->ckhdr.num_samples;
+    pkt->duration       = asf->ckhdr.num_samples * (ret / st->codecpar->block_align);
+    asf->blocks_read   += (ret / st->codecpar->block_align);
 
-    ++asf->blocks_read;
+    pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
     return 0;
 }