[FFmpeg-devel] [PATCH] pkt_pts reordering

Stefano Sabatini stefano.sabatini-lala
Fri Jan 7 22:16:14 CET 2011


On date Friday 2011-01-07 15:37:01 +0100, Michael Niedermayer encoded:
> There was some discussion about this, heres actual code
> I will apply this later today if noone complains
> Also after this patch it should become easier both to add multframe/thread
> decoders as well as a single timestamp through guess_correct_pts()
> 
> -- 
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> The worst form of inequality is to try to make unequal things equal.
> -- Aristotle

> From 67cbc7b3471beb99f325396f0ec5b5400d25644a Mon Sep 17 00:00:00 2001
> From: Michael Niedermayer <michaelni at gmx.at>
> Date: Fri, 7 Jan 2011 15:06:39 +0100
> Subject: [PATCH 1/3] Add AVFrame.pkt_pts that contains the correctly reordered AVPacket.pts
> 
> ---
>  doc/APIchanges       |    3 +++
>  ffplay.c             |    4 ++++
>  libavcodec/avcodec.h |   19 ++++++++++++++++++-
>  libavcodec/utils.c   |    8 ++++++++
>  4 files changed, 33 insertions(+), 1 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index bf9d11d..3b0dc34 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -13,6 +13,9 @@ libavutil:   2009-03-08
>  
>  API changes, most recent first:
>  
> +2011-01-07 - r26254 - lavc 52.103.0 - pkt_pts
> +  Add pkt_pts to AVFrame

Nit++: missing dot.

>  2010-12-27 - r26108 - lavfi 1.71.0 - AV_PERM_NEG_LINESIZES
>    Add AV_PERM_NEG_LINESIZES in avfilter.h.
>  
> diff --git a/ffplay.c b/ffplay.c
> index e0cc305..a52ec12 100644
> --- a/ffplay.c
> +++ b/ffplay.c
> @@ -1652,6 +1652,8 @@ static int input_get_buffer(AVCodecContext *codec, AVFrame *pic)
>      pic->age    = INT_MAX;
>      pic->type   = FF_BUFFER_TYPE_USER;
>      pic->reordered_opaque = codec->reordered_opaque;
> +    if(codec->pkt) pic->pkt_pts = codec->pkt->pts;
> +    else           pic->pkt_pts = AV_NOPTS_VALUE;

Nit:
I'd prefer
pic->pkt_pts = codec->pkt ? codec->pkt->pts : AV_NOPTS_VALUE;
but do as you prefer

>      return 0;
>  }
>  
> @@ -1677,6 +1679,8 @@ static int input_reget_buffer(AVCodecContext *codec, AVFrame *pic)
>      }
>  
>      pic->reordered_opaque = codec->reordered_opaque;
> +    if(codec->pkt) pic->pkt_pts = codec->pkt->pts;
> +    else           pic->pkt_pts = AV_NOPTS_VALUE;

ditto

>      return 0;
>  }
>  
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 828b07a..1ed23eb 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -32,7 +32,7 @@
>  #include "libavutil/cpu.h"
>  
>  #define LIBAVCODEC_VERSION_MAJOR 52
> -#define LIBAVCODEC_VERSION_MINOR 102
> +#define LIBAVCODEC_VERSION_MINOR 103
>  #define LIBAVCODEC_VERSION_MICRO  0
>  
>  #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
> @@ -1009,6 +1009,13 @@ typedef struct AVPanScan{
>       * - decoding: Set by libavcodec\
>       */\
>      void *hwaccel_picture_private;\
> +\
> +    /**\
> +     * reordered pts from the AVPacket that has been input into the decoder\
> +     * - encoding: unused\
> +     * - decoding: Read by user.\
> +     */\
> +    int64_t pkt_pts;\

could you clarify the meaning of "reordered" in this case? Also maybe
it's more clear to say:
... from the *last* AVPacket that has been input into the decoder\

>  
>  
>  #define FF_QSCALE_TYPE_MPEG1 0
> @@ -2785,6 +2792,16 @@ typedef struct AVCodecContext {
>       */
>      uint8_t *subtitle_header;
>      int subtitle_header_size;
> +
> +    /**
> +     * Current packet as passed into the decoder, this here avoids having to
> +     * pass the packet to every function. The pointer cannot be expected to be
> +     * valid outside avcodec_decode_*() currently, aka this is internal to lavc
> +     * and the get/release buffer callbacks.
> +     * - decoding: set by avcodec_decode_*, read by get_buffer() for setting pkt_pts
> +     * - encoding: unused
> +     */
> +    AVPacket *pkt;
>  } AVCodecContext;
>  
>  /**
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index ce74735..8ea0b98 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -344,6 +344,8 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
>      }
>      s->internal_buffer_count++;
>  
> +    if(s->pkt) pic->pkt_pts= s->pkt->pts;
> +    else       pic->pkt_pts= AV_NOPTS_VALUE;

ditto

>      pic->reordered_opaque= s->reordered_opaque;
>  
>      if(s->debug&FF_DEBUG_BUFFERS)
> @@ -628,6 +630,9 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi
>      *got_picture_ptr= 0;
>      if((avctx->coded_width||avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
>          return -1;
> +
> +    avctx->pkt= avpkt;

Nit+++: avctx->pkt_= avpkt;

> +
>      if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){
>          ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
>                                  avpkt);
> @@ -662,6 +667,8 @@ int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *sa
>  {
>      int ret;
>  
> +    avctx->pkt= avpkt;
> +
>      if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){
>          //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough
>          if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){
> @@ -703,6 +710,7 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
>  {
>      int ret;
>  
> +    avctx->pkt= avpkt;
>      *got_sub_ptr = 0;
>      ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
>      if (*got_sub_ptr)
> -- 
> 1.7.2.3
> 

> From a86ea403fad2933ecc6957684049a9260f4e7ce1 Mon Sep 17 00:00:00 2001
> From: Michael Niedermayer <michaelni at gmx.at>
> Date: Fri, 7 Jan 2011 15:08:17 +0100
> Subject: [PATCH 2/3] Add pkt_dts to AVFrame, this will in the future allow multithreading decoders
>  to not mess up dts
> 
> ---
>  doc/APIchanges       |    4 ++++
>  libavcodec/avcodec.h |    9 ++++++++-
>  libavcodec/utils.c   |    2 ++
>  3 files changed, 14 insertions(+), 1 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 3b0dc34..c78fe3e 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -13,6 +13,10 @@ libavutil:   2009-03-08
>  
>  API changes, most recent first:
>  
> +2011-01-07 - r26255 - lavc 52.104.0 - pkt_dts
> +  Add pkt_dts to AVFrame, this will in the future allow multithreading decoders
> +  to not mess up dts

Nit: missing ending dot.

> +
>  2011-01-07 - r26254 - lavc 52.103.0 - pkt_pts
>    Add pkt_pts to AVFrame
>  
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 1ed23eb..c61988c 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -32,7 +32,7 @@
>  #include "libavutil/cpu.h"
>  
>  #define LIBAVCODEC_VERSION_MAJOR 52
> -#define LIBAVCODEC_VERSION_MINOR 103
> +#define LIBAVCODEC_VERSION_MINOR 104
>  #define LIBAVCODEC_VERSION_MICRO  0
>  
>  #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
> @@ -1016,6 +1016,13 @@ typedef struct AVPanScan{
>       * - decoding: Read by user.\
>       */\
>      int64_t pkt_pts;\
> +\
> +    /**\
> +     * dts from the AVPacket that has been input into the decoder\

from the *last* AVPacket?
-- 
FFmpeg = Fiendish and Foolish Magical Prodigious Enlightening Gadget



More information about the ffmpeg-devel mailing list