diff mbox series

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

Message ID 20200916073836.27644-4-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
For the argo_brp demuxer.

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

Comments

Paul B Mahol Sept. 16, 2020, 9:26 a.m. UTC | #1
On Wed, Sep 16, 2020 at 07:39:21AM +0000, Zane van Iperen wrote:
> For the argo_brp demuxer.
> 
> Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
> ---
>  libavformat/argo_asf.c | 50 ++++++++++++++++++++++--------------------
>  libavformat/argo_asf.h |  2 ++
>  2 files changed, 28 insertions(+), 24 deletions(-)
> 
> diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c
> index deb64f7b1c..58d0c4fd23 100644
> --- a/libavformat/argo_asf.c
> +++ b/libavformat/argo_asf.c
> @@ -143,6 +143,31 @@ 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);
> +    *blocks_read       += (ret / st->codecpar->block_align);

This line breaks seeking.

Ultimately you want to support seeking in demuxer(s).

> +
> +    pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
> +    return 0;
> +}
> +
>  #if CONFIG_ARGO_ASF_DEMUXER
>  /*
>   * Known versions:
> @@ -214,30 +239,7 @@ 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)
> -        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;
> -    return 0;
> +    return ff_argo_asf_read(s->pb, s->streams[0], pkt, &asf->ckhdr, &asf->blocks_read);
>  }
>  
>  /*
> diff --git a/libavformat/argo_asf.h b/libavformat/argo_asf.h
> index eb2669a63f..0fd6aced58 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 */
> -- 
> 2.25.4
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Zane van Iperen Sept. 16, 2020, 10:28 a.m. UTC | #2
On Wed, 16 Sep 2020 11:26:55 +0200
"Paul B Mahol" <onemda@gmail.com> wrote:

> > +    pkt->stream_index   = st->index;
> > +    pkt->duration       = ckhdr->num_samples * (ret / st->codecpar->block_align);
> > +    *blocks_read       += (ret / st->codecpar->block_align);
> 
> This line breaks seeking.
> 
> Ultimately you want to support seeking in demuxer(s).

This isn't a seekable format, each block depends on the previous.
There's nowhere to seek to other than the start.
diff mbox series

Patch

diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c
index deb64f7b1c..58d0c4fd23 100644
--- a/libavformat/argo_asf.c
+++ b/libavformat/argo_asf.c
@@ -143,6 +143,31 @@  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);
+    *blocks_read       += (ret / st->codecpar->block_align);
+
+    pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
+    return 0;
+}
+
 #if CONFIG_ARGO_ASF_DEMUXER
 /*
  * Known versions:
@@ -214,30 +239,7 @@  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)
-        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;
-    return 0;
+    return ff_argo_asf_read(s->pb, s->streams[0], pkt, &asf->ckhdr, &asf->blocks_read);
 }
 
 /*
diff --git a/libavformat/argo_asf.h b/libavformat/argo_asf.h
index eb2669a63f..0fd6aced58 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 */