[FFmpeg-devel] [PATCH] avcodec: Allow to query number of consumed bytes using the new API

James Almer jamrial at gmail.com
Wed Jan 30 18:32:07 EET 2019


On 1/30/2019 12:53 PM, jannis_wth wrote:
> This patch fixes the issue discussed in ticket #7708.
> 
> 
> 0001-avcodec-Allow-to-query-number-of-consumed-bytes-usin.patch
> 
> From 756b3b59ac491bdbf01de4f399f5eeb74db8861a Mon Sep 17 00:00:00 2001
> From: user <user at host>
> Date: Wed, 30 Jan 2019 16:48:58 +0100
> Subject: [PATCH 1/1] avcodec: Allow to query number of consumed bytes using
>  the new API
> 
> Currently the only way to get the number of consumed bytes is by using
> the deprecated decode_audio4() API. This patch adds a simple function
> to fix this.
> 
> Signed-off-by: Jannis Kambs <jannis_wth at gmx.de>
> ---
>  libavcodec/avcodec.h | 9 +++++++++
>  libavcodec/utils.c   | 7 +++++++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index f554c53f0e..54f48754e4 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -5714,6 +5714,15 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes);
>   */
>  int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes);
>  
> +/**
> + * This function allows to get the number of consumed bytes, analogous to the
> + * old decode API. Call it after avcodec_receive_frame().
> + *
> + * @param avctx the codec context
> + * @return number of bytes consumed from the input AVPacket.
> + */
> +int av_get_num_consumed(AVCodecContext *avctx);

Use the avcodec_ prefix instead.

> +
>  #if FF_API_OLD_BSF
>  typedef struct AVBitStreamFilterContext {
>      void *priv_data;
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index d519b16092..a3cb8fef3f 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -1727,6 +1727,13 @@ int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
>                                      frame_bytes);
>  }
>  
> +int av_get_num_consumed(AVCodecContext *avctx)
> +{
> +    int ret = avctx->internal->compat_decode_consumed;
> +    avctx->internal->compat_decode_consumed = 0;

compat_decode_consumed doesn't look to have any significance when using
the new API. It's working as an accumulator for all bytes consumed from
all frames and it's never cleared (sounds like a potential overflow for
that matter in long lasting decoding scenarios like streaming), whereas
for the old API it's effectively keeping track of bytes consumed in one
frame, and cleared after every avcodec_decode_* call. So I guess that's
why you're clearing it here even though this function should by no means
do that.

Clearing compat_decode_consumed for the new API should be done somewhere
in decode.c where it doesn't break the logic for the old API, regardless
of using the AVCodec.decode() or AVCodec.receive_frame() callbacks.

> +    return ret;
> +}
> +
>  #if !HAVE_THREADS
>  int ff_thread_init(AVCodecContext *s)
>  {
> -- 2.11.0
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 



More information about the ffmpeg-devel mailing list