diff mbox series

[FFmpeg-devel,v2,4/7] avformat/argo_asf: add ff_argo_asf_read()

Message ID 20200918120416.7319-5-zane@zanevaniperen.com
State Superseded
Headers show
Series Support variable frame sizes in adpcm_argo
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. 18, 2020, 12:04 p.m. UTC
For the argo_brp demuxer.

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
---
 libavformat/argo_asf.c | 45 ++++++++++++++++++++++++------------------
 libavformat/argo_asf.h |  2 ++
 2 files changed, 28 insertions(+), 19 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c
index 048e5441d6..0e9ccbd02f 100644
--- a/libavformat/argo_asf.c
+++ b/libavformat/argo_asf.c
@@ -144,6 +144,30 @@  int ff_argo_asf_fill_stream(AVStream *st, const ArgoASFFileHeader *fhdr,
     return 0;
 }
 
+int ff_argo_asf_read(AVIOContext *pb, AVStream *st, AVPacket *pkt,
+                     const ArgoASFChunkHeader *ckhdr, uint32_t blocks_read)
+{
+    int64_t ret;
+
+    if (blocks_read >= ckhdr->num_blocks)
+        return AVERROR_EOF;
+
+    ret = av_get_packet(pb, pkt, st->codecpar->block_align *
+                        FFMIN(ASF_NB_BLOCKS, ckhdr->num_blocks - blocks_read));
+    if (ret < 0)
+        return ret;
+
+    /* Something real screwy is going on. */
+    if (ret % st->codecpar->block_align != 0)
+        return AVERROR_INVALIDDATA;
+
+    pkt->stream_index   = st->index;
+    pkt->duration       = ckhdr->num_samples * (ret / st->codecpar->block_align);
+
+    pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
+    return ret / st->codecpar->block_align;
+}
+
 #if CONFIG_ARGO_ASF_DEMUXER
 /*
  * Known versions:
@@ -215,29 +239,12 @@  static int argo_asf_read_header(AVFormatContext *s)
 static int argo_asf_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     ArgoASFDemuxContext *asf = s->priv_data;
-
-    AVStream *st = s->streams[0];
-    AVIOContext *pb = s->pb;
     int ret;
 
-    if (asf->blocks_read >= asf->ckhdr.num_blocks)
-        return AVERROR_EOF;
-
-    ret = av_get_packet(pb, pkt, st->codecpar->block_align *
-                        FFMIN(ASF_NB_BLOCKS, asf->ckhdr.num_blocks - asf->blocks_read));
-    if (ret < 0)
+    if ((ret = ff_argo_asf_read(s->pb, s->streams[0], pkt, &asf->ckhdr, asf->blocks_read)) < 0)
         return ret;
 
-    /* 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 * (ret / st->codecpar->block_align);
-    asf->blocks_read   += (ret / st->codecpar->block_align);
-
-    pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
+    asf->blocks_read += ret;
     return 0;
 }
 
diff --git a/libavformat/argo_asf.h b/libavformat/argo_asf.h
index eb2669a63f..e676dfb882 100644
--- a/libavformat/argo_asf.h
+++ b/libavformat/argo_asf.h
@@ -67,5 +67,7 @@  int  ff_argo_asf_validate_file_header(AVFormatContext *s, const ArgoASFFileHeade
 void ff_argo_asf_parse_chunk_header(ArgoASFChunkHeader *hdr, const uint8_t *buf);
 int  ff_argo_asf_fill_stream(AVStream *st, const ArgoASFFileHeader *fhdr,
                              const ArgoASFChunkHeader *ckhdr);
+int  ff_argo_asf_read(AVIOContext *pb, AVStream *st, AVPacket *pkt,
+                      const ArgoASFChunkHeader *ckhdr, uint32_t blocks_read);
 
 #endif /* AVFORMAT_ARGO_ASF_H */