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

Paul B Mahol onemda at gmail.com
Wed Sep 16 12:26:55 EEST 2020


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 at 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 at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-devel mailing list