[FFmpeg-cvslog] lavc: Make AVPacket.duration int64, and deprecate convergence_duration

wm4 git at videolan.org
Tue Sep 29 15:23:16 CEST 2015


ffmpeg | branch: master | wm4 <nfxjfg at googlemail.com> | Sat Sep 26 18:13:55 2015 +0200| [948f3c19a8bd069768ca411212aaf8c1ed96b10d] | committer: Vittorio Giovara

lavc: Make AVPacket.duration int64, and deprecate convergence_duration

Note that convergence_duration had another meaning, one which was in
practice never used. The only real use for it was a 64 bit replacement
for the duration field. It's better just to make duration 64 bits, and
to get rid of it.

Signed-off-by: Vittorio Giovara <vittorio.giovara at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=948f3c19a8bd069768ca411212aaf8c1ed96b10d
---

 doc/APIchanges                 |    3 +++
 libavcodec/audio_frame_queue.c |    2 +-
 libavcodec/audio_frame_queue.h |    2 +-
 libavcodec/avcodec.h           |   42 +++++++++++-----------------------------
 libavcodec/avpacket.c          |   12 ++++++++++++
 libavcodec/parser.c            |    5 +++++
 libavcodec/version.h           |    3 +++
 libavformat/framecrcenc.c      |    2 +-
 libavformat/matroskadec.c      |    8 ++++++--
 libavformat/matroskaenc.c      |   10 ++++++++--
 libavformat/md5enc.c           |    2 +-
 libavformat/mov.c              |    2 +-
 libavformat/r3d.c              |    4 ++--
 libavformat/utils.c            |    8 ++++++--
 14 files changed, 61 insertions(+), 44 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 42caad7..144eb79 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:     2015-08-28
 
 API changes, most recent first:
 
+2015-xx-xx - xxxxxxx - lavc 57.0.0 - avcodec.h
+  Change type of AVPacket.duration from int to int64_t.
+
 2015-xx-xx - xxxxxxx - lavc 57.2.0 - d3d11va.h
   Add av_d3d11va_alloc_context(). This function must from now on be used for
   allocating AVD3D11VAContext.
diff --git a/libavcodec/audio_frame_queue.c b/libavcodec/audio_frame_queue.c
index 15ffa82..c4ca02b 100644
--- a/libavcodec/audio_frame_queue.c
+++ b/libavcodec/audio_frame_queue.c
@@ -111,7 +111,7 @@ int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
 }
 
 void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts,
-                        int *duration)
+                        int64_t *duration)
 {
     int64_t out_pts = AV_NOPTS_VALUE;
     int removed_samples = 0;
diff --git a/libavcodec/audio_frame_queue.h b/libavcodec/audio_frame_queue.h
index 4a29770..1250ec2 100644
--- a/libavcodec/audio_frame_queue.h
+++ b/libavcodec/audio_frame_queue.h
@@ -78,6 +78,6 @@ int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f);
  * @param[out] duration output packet duration
  */
 void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts,
-                        int *duration);
+                        int64_t *duration);
 
 #endif /* AVCODEC_AUDIO_FRAME_QUEUE_H */
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 8c635d7..9c6fde0 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1199,28 +1199,19 @@ typedef struct AVPacket {
      * Duration of this packet in AVStream->time_base units, 0 if unknown.
      * Equals next_pts - this_pts in presentation order.
      */
-    int   duration;
+    int64_t duration;
 
     int64_t pos;                            ///< byte position in stream, -1 if unknown
 
+#if FF_API_CONVERGENCE_DURATION
     /**
-     * Time difference in AVStream->time_base units from the pts of this
-     * packet to the point at which the output from the decoder has converged
-     * independent from the availability of previous frames. That is, the
-     * frames are virtually identical no matter if decoding started from
-     * the very first frame or from this keyframe.
-     * Is AV_NOPTS_VALUE if unknown.
-     * This field is not the display duration of the current packet.
-     * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
-     * set.
-     *
-     * The purpose of this field is to allow seeking in streams that have no
-     * keyframes in the conventional sense. It corresponds to the
-     * recovery point SEI in H.264 and match_time_delta in NUT. It is also
-     * essential for some types of subtitle streams to ensure that all
-     * subtitles are correctly displayed after seeking.
+     * @deprecated Same as the duration field, but as int64_t. This was required
+     * for Matroska subtitles, whose duration values could overflow when the
+     * duration field was still an int.
      */
+    attribute_deprecated
     int64_t convergence_duration;
+#endif
 } AVPacket;
 #define AV_PKT_FLAG_KEY     0x0001 ///< The packet contains a keyframe
 #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
@@ -3837,24 +3828,13 @@ typedef struct AVCodecParserContext {
      */
     int key_frame;
 
+#if FF_API_CONVERGENCE_DURATION
     /**
-     * Time difference in stream time base units from the pts of this
-     * packet to the point at which the output from the decoder has converged
-     * independent from the availability of previous frames. That is, the
-     * frames are virtually identical no matter if decoding started from
-     * the very first frame or from this keyframe.
-     * Is AV_NOPTS_VALUE if unknown.
-     * This field is not the display duration of the current frame.
-     * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
-     * set.
-     *
-     * The purpose of this field is to allow seeking in streams that have no
-     * keyframes in the conventional sense. It corresponds to the
-     * recovery point SEI in H.264 and match_time_delta in NUT. It is also
-     * essential for some types of subtitle streams to ensure that all
-     * subtitles are correctly displayed after seeking.
+     * @deprecated unused
      */
+    attribute_deprecated
     int64_t convergence_duration;
+#endif
 
     // Timestamp generation support:
     /**
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index dfaf045..e762a87 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -34,7 +34,11 @@ void av_init_packet(AVPacket *pkt)
     pkt->dts                  = AV_NOPTS_VALUE;
     pkt->pos                  = -1;
     pkt->duration             = 0;
+#if FF_API_CONVERGENCE_DURATION
+FF_DISABLE_DEPRECATION_WARNINGS
     pkt->convergence_duration = 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     pkt->flags                = 0;
     pkt->stream_index         = 0;
     pkt->buf                  = NULL;
@@ -269,7 +273,11 @@ int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
     dst->dts                  = src->dts;
     dst->pos                  = src->pos;
     dst->duration             = src->duration;
+#if FF_API_CONVERGENCE_DURATION
+FF_DISABLE_DEPRECATION_WARNINGS
     dst->convergence_duration = src->convergence_duration;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     dst->flags                = src->flags;
     dst->stream_index         = src->stream_index;
 
@@ -341,6 +349,10 @@ void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
         pkt->dts = av_rescale_q(pkt->dts, src_tb, dst_tb);
     if (pkt->duration > 0)
         pkt->duration = av_rescale_q(pkt->duration, src_tb, dst_tb);
+#if FF_API_CONVERGENCE_DURATION
+FF_DISABLE_DEPRECATION_WARNINGS
     if (pkt->convergence_duration > 0)
         pkt->convergence_duration = av_rescale_q(pkt->convergence_duration, src_tb, dst_tb);
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 }
diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index 4671c13..355187a 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -23,6 +23,7 @@
 #include <stdint.h>
 #include <string.h>
 
+#include "libavutil/internal.h"
 #include "libavutil/mem.h"
 
 #include "internal.h"
@@ -86,7 +87,11 @@ found:
     s->fetch_timestamp      = 1;
     s->pict_type            = AV_PICTURE_TYPE_I;
     s->key_frame            = -1;
+#if FF_API_CONVERGENCE_DURATION
+FF_DISABLE_DEPRECATION_WARNINGS
     s->convergence_duration = 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     s->dts_sync_point       = INT_MIN;
     s->dts_ref_dts_delta    = INT_MIN;
     s->pts_dts_delta        = INT_MIN;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index c704d44..80b0ba5 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -168,5 +168,8 @@
 #ifndef FF_API_VDPAU_PROFILE
 #define FF_API_VDPAU_PROFILE     (LIBAVCODEC_VERSION_MAJOR < 59)
 #endif
+#ifndef FF_API_CONVERGENCE_DURATION
+#define FF_API_CONVERGENCE_DURATION (LIBAVCODEC_VERSION_MAJOR < 59)
+#endif
 
 #endif /* AVCODEC_VERSION_H */
diff --git a/libavformat/framecrcenc.c b/libavformat/framecrcenc.c
index 4d5483a..470442e 100644
--- a/libavformat/framecrcenc.c
+++ b/libavformat/framecrcenc.c
@@ -30,7 +30,7 @@ static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
     uint32_t crc = av_adler32_update(0, pkt->data, pkt->size);
     char buf[256];
 
-    snprintf(buf, sizeof(buf), "%d, %10"PRId64", %10"PRId64", %8d, %8d, 0x%08"PRIx32"\n",
+    snprintf(buf, sizeof(buf), "%d, %10"PRId64", %10"PRId64", %8"PRId64", %8d, 0x%08"PRIx32"\n",
              pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size, crc);
     avio_write(s->pb, buf, strlen(buf));
     return 0;
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 3556b14..caf127f 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2335,10 +2335,14 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska,
     else
         pkt->pts = timecode;
     pkt->pos = pos;
+    if (track->type != MATROSKA_TRACK_TYPE_SUBTITLE || st->codec->codec_id == AV_CODEC_ID_TEXT)
+        pkt->duration = duration;
+#if FF_API_CONVERGENCE_DURATION
+FF_DISABLE_DEPRECATION_WARNINGS
     if (st->codec->codec_id == AV_CODEC_ID_TEXT)
         pkt->convergence_duration = duration;
-    else if (track->type != MATROSKA_TRACK_TYPE_SUBTITLE)
-        pkt->duration = duration;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     if (st->codec->codec_id == AV_CODEC_ID_SSA)
         matroska_fix_ass_packet(matroska, pkt, duration);
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 498f479..db86e88 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1394,7 +1394,7 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb,
     int64_t ts = mkv->tracks[pkt->stream_index].write_dts ? pkt->dts : pkt->pts;
 
     av_log(s, AV_LOG_DEBUG, "Writing block at offset %" PRIu64 ", size %d, "
-           "pts %" PRId64 ", dts %" PRId64 ", duration %d, flags %d\n",
+           "pts %" PRId64 ", dts %" PRId64 ", duration %" PRId64 ", flags %d\n",
            avio_tell(pb), pkt->size, pkt->pts, pkt->dts, pkt->duration, flags);
     if (codec->codec_id == AV_CODEC_ID_H264 && codec->extradata_size > 0 &&
         (AV_RB24(codec->extradata) == 1 || AV_RB32(codec->extradata) == 1))
@@ -1527,7 +1527,13 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
     } else {
         ebml_master blockgroup = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP,
                                                    mkv_blockgroup_size(pkt->size));
-        duration = pkt->convergence_duration;
+        duration = pkt->duration;
+#if FF_API_CONVERGENCE_DURATION
+FF_DISABLE_DEPRECATION_WARNINGS
+        if (pkt->convergence_duration)
+            duration = pkt->convergence_duration;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
         mkv_write_block(s, pb, MATROSKA_ID_BLOCK, pkt, 0);
         put_ebml_uint(pb, MATROSKA_ID_BLOCKDURATION, duration);
         end_ebml_master(pb, blockgroup);
diff --git a/libavformat/md5enc.c b/libavformat/md5enc.c
index 9249704..bd10df7 100644
--- a/libavformat/md5enc.c
+++ b/libavformat/md5enc.c
@@ -104,7 +104,7 @@ static int framemd5_write_packet(struct AVFormatContext *s, AVPacket *pkt)
     av_md5_init(c->md5);
     av_md5_update(c->md5, pkt->data, pkt->size);
 
-    snprintf(buf, sizeof(buf) - 64, "%d, %10"PRId64", %10"PRId64", %8d, %8d, ",
+    snprintf(buf, sizeof(buf) - 64, "%d, %10"PRId64", %10"PRId64", %8"PRId64", %8d, ",
              pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size);
     md5_finish(s, buf);
     return 0;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index bb99f75..95dc1ee 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3535,7 +3535,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
         goto retry;
     pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? AV_PKT_FLAG_KEY : 0;
     pkt->pos = sample->pos;
-    av_log(s, AV_LOG_TRACE, "stream %d, pts %"PRId64", dts %"PRId64", pos 0x%"PRIx64", duration %d\n",
+    av_log(s, AV_LOG_TRACE, "stream %d, pts %"PRId64", dts %"PRId64", pos 0x%"PRIx64", duration %"PRId64"\n",
             pkt->stream_index, pkt->pts, pkt->dts, pkt->pos, pkt->duration);
     return 0;
 }
diff --git a/libavformat/r3d.c b/libavformat/r3d.c
index a99f265..c56bdc6 100644
--- a/libavformat/r3d.c
+++ b/libavformat/r3d.c
@@ -264,7 +264,7 @@ static int r3d_read_redv(AVFormatContext *s, AVPacket *pkt, Atom *atom)
     if (st->avg_frame_rate.num)
         pkt->duration = (uint64_t)st->time_base.den*
             st->avg_frame_rate.den/st->avg_frame_rate.num;
-    av_log(s, AV_LOG_TRACE, "pkt dts %"PRId64" duration %d\n", pkt->dts, pkt->duration);
+    av_log(s, AV_LOG_TRACE, "pkt dts %"PRId64" duration %"PRId64"\n", pkt->dts, pkt->duration);
 
     return 0;
 }
@@ -313,7 +313,7 @@ static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom)
     pkt->stream_index = 1;
     pkt->dts = dts;
     pkt->duration = av_rescale(samples, st->time_base.den, st->codec->sample_rate);
-    av_log(s, AV_LOG_TRACE, "pkt dts %"PRId64" duration %d samples %d sample rate %d\n",
+    av_log(s, AV_LOG_TRACE, "pkt dts %"PRId64" duration %"PRId64" samples %d sample rate %d\n",
             pkt->dts, pkt->duration, samples, st->codec->sample_rate);
 
     return 0;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 5d4ec62..f8926bd 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -735,8 +735,12 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
     /* update flags */
     if (is_intra_only(st->codec->codec_id))
         pkt->flags |= AV_PKT_FLAG_KEY;
+#if FF_API_CONVERGENCE_DURATION
+FF_DISABLE_DEPRECATION_WARNINGS
     if (pc)
         pkt->convergence_duration = pc->convergence_duration;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 }
 
 static void free_packet_buffer(AVPacketList **pkt_buf, AVPacketList **pkt_buf_end)
@@ -906,7 +910,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
         if (s->debug & FF_FDEBUG_TS)
             av_log(s, AV_LOG_DEBUG,
                    "ff_read_packet stream=%d, pts=%"PRId64", dts=%"PRId64", "
-                   "size=%d, duration=%d, flags=%d\n",
+                   "size=%d, duration=%"PRId64", flags=%d\n",
                    cur_pkt.stream_index, cur_pkt.pts, cur_pkt.dts,
                    cur_pkt.size, cur_pkt.duration, cur_pkt.flags);
 
@@ -955,7 +959,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
     if (s->debug & FF_FDEBUG_TS)
         av_log(s, AV_LOG_DEBUG,
                "read_frame_internal stream=%d, pts=%"PRId64", dts=%"PRId64", "
-               "size=%d, duration=%d, flags=%d\n",
+               "size=%d, duration=%"PRId64", flags=%d\n",
                pkt->stream_index, pkt->pts, pkt->dts,
                pkt->size, pkt->duration, pkt->flags);
 



More information about the ffmpeg-cvslog mailing list