From 1f551502a2e271da044f7e4be4be7ddca7f30bc1 Mon Sep 17 00:00:00 2001
From: Dale Curtis <dalecurtis@chromium.org>
Date: Thu, 23 Apr 2020 16:18:18 -0700
Subject: [PATCH] Don't adjust start time for MP3 files; packets are not
 adjusted.

This is a patch Chromium has carried for a while, we forgot to send it
upstream. 7546ac2fee4 made it so that the start_time for mp3 files is
adjusted for skip_samples. However, this appears incorrect because
subsequent packet timestamps are not adjusted and skip_samples are
applied by deleting data from a packet without changing the timestamp.

E.g., we are told the start_time is ~25ms and we get a packet with a
timestamp of 0 that has had the skip_samples discarded from it. As such
rendering engines may incorrectly discard everything prior to the
25ms thinking that is where playback should officially start. Since the
samples were deleted without adjusting timestamps though, the true
start_time is still 0.

Other formats like MP4 with edit lists will adjust both the start
time and the timestamps of subsequent packets to avoid this issue.

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
---
 libavformat/mp3dec.c       | 4 ----
 tests/ref/fate/gapless-mp3 | 2 +-
 2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c
index b044679c02..efbf836bcc 100644
--- a/libavformat/mp3dec.c
+++ b/libavformat/mp3dec.c
@@ -260,10 +260,6 @@ static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st,
             st->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf;
             st->last_discard_sample = mp3->frames * (int64_t)spf;
         }
-        if (!st->start_time)
-            st->start_time = av_rescale_q(st->start_skip_samples,
-                                            (AVRational){1, c->sample_rate},
-                                            st->time_base);
         av_log(s, AV_LOG_DEBUG, "pad %d %d\n", mp3->start_pad, mp3->  end_pad);
     }

diff --git a/tests/ref/fate/gapless-mp3 b/tests/ref/fate/gapless-mp3
index ab4f1a0456..e784391153 100644
--- a/tests/ref/fate/gapless-mp3
+++ b/tests/ref/fate/gapless-mp3
@@ -1,4 +1,4 @@
-44b42cc3a898b45507d856d0813f4f26 *tests/data/fate/gapless-mp3.out-1
+ec876434ed65e338e07234e54d136caf *tests/data/fate/gapless-mp3.out-1
 c96c3ae7bd3300fd2f4debac222de5b7
 ec876434ed65e338e07234e54d136caf *tests/data/fate/gapless-mp3.out-2
 c96c3ae7bd3300fd2f4debac222de5b7
--
2.26.2.303.gf8c07b1a785-goog

