]> git.sesse.net Git - ffmpeg/commitdiff
avformat: add common mechanism for skipping samples at the start of file
authorwm4 <nfxjfg@googlemail.com>
Wed, 22 Apr 2015 10:24:36 +0000 (12:24 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 22 Apr 2015 12:05:46 +0000 (14:05 +0200)
This makes using the generic indexing code with mp3 easier at a later
point.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavformat/avformat.h
libavformat/utils.c

index 514e64626d138231b151883b768161c7f1619d46..c2f798d6495a6985325316620fe77e547136c840 100644 (file)
@@ -1082,6 +1082,15 @@ typedef struct AVStream {
      */
     int skip_samples;
 
+    /**
+     * If not 0, the number of samples that should be skipped from the start of
+     * the stream (the samples are removed from packets with pts==0, which also
+     * assumes negative timestamps do not happen).
+     * Intended for use with formats such as mp3 with ad-hoc gapless audio
+     * support.
+     */
+    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
index 950b3c67e4dac80f0c1a40f53d6b57ca8151783c..2f6122d7d65fb15300e342ee2c8c17cdc46b70cc 100644 (file)
@@ -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;
     }
 }