[FFmpeg-devel] [PATCH 1/5] avformat: add common mechanism for skipping samples at the start of file

wm4 nfxjfg at googlemail.com
Tue Apr 21 21:33:50 CEST 2015


This makes using the generic indexing code with mp3 easier at a later
point.
---
 libavformat/avformat.h | 8 ++++++++
 libavformat/utils.c    | 4 ++++
 2 files changed, 12 insertions(+)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 514e646..93cfb20 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1083,6 +1083,14 @@ typedef struct AVStream {
     int skip_samples;
 
     /**
+     * The number of samples that should be skipped from the start of the stream
+     * (i.e. the timestamp of the first sample that should be actually output).
+     * Intended for use with formats such as mp3 with ad-hoc gapless audio
+     * support. It is assumed that negative timestamps do not exist.
+     */
+    int64_t start_skip_samples;
+
+    /**
      * If not 0, the first audio sample that should be discarded from the stream.
      * This is broken by design (needs global sample count), but can't be
      * avoided for broken by design formats such as mp3 with ad-hoc gapless
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 950b3c6..2f6122d 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1416,6 +1416,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
                 sample < st->last_discard_sample)
                 discard_padding = FFMIN(end_sample - st->first_discard_sample, duration);
         }
+        if (st->start_skip_samples && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE))
+            st->skip_samples = st->start_skip_samples;
         if (st->skip_samples || discard_padding) {
             uint8_t *p = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10);
             if (p) {
@@ -1645,6 +1647,8 @@ void ff_read_frame_flush(AVFormatContext *s)
 
         if (s->internal->inject_global_side_data)
             st->inject_global_side_data = 1;
+
+        st->skip_samples = 0;
     }
 }
 
-- 
2.1.4



More information about the ffmpeg-devel mailing list