Commit 58bb97a5 authored by Paul Adenot's avatar Paul Adenot
Browse files

Bug 1844741 - Consistently use remaining padding when trimming mp3. r=alwu, a=dsmith

Creating the file was made in the following way:
- Create a VBR file
- Modify the padding field so that it spans multiple packets (greater than 1152
frames in this case)
- Copy and paste the last mp3 packet (starting with 0xfffd) multiple times so
that more packets are found after having trimmed the last packet (marked as
EOS).

Differential Revision: https://phabricator.services.mozilla.com/D184213
parent 24e00c6f
Loading
Loading
Loading
Loading
+2 −1
Changes for dom/media/mp3/MP3Demuxer.cpp: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -165,6 +165,7 @@ UniquePtr<TrackInfo> MP3TrackDemuxer::GetInfo() const { return mInfo->Clone(); }

RefPtr<MP3TrackDemuxer::SeekPromise> MP3TrackDemuxer::Seek(
    const TimeUnit& aTime) {
  mRemainingEncoderPadding = AssertedCast<int32_t>(mEncoderPadding);
  // Efficiently seek to the position.
  FastSeek(aTime);
  // Correct seek position by scanning the next frames.
@@ -735,7 +736,7 @@ already_AddRefed<MediaRawData> MP3TrackDemuxer::GetNextFrame(
  } else if (frame->mEOS &&
             mRemainingEncoderPadding <=
                 frame->mDuration.ToTicksAtRate(mSamplesPerSecond)) {
    frame->mDuration -= Padding();
    frame->mDuration -= TimeUnit(mRemainingEncoderPadding, mSamplesPerSecond);
    MOZ_ASSERT(frame->mDuration.IsPositiveOrZero());
    MP3LOG("Trimming last packet %s to [%s,%s]", Padding().ToString().get(),
           frame->mTime.ToString().get(), frame->GetEndTime().ToString().get());
+7 −0
Changes for dom/media/test/manifest.js: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -531,6 +531,13 @@ var gPlayTests = [
  // tag. The ID3v1 tags should be at the end of the file, but software usually
  // play it anyway.
  { name: "id3v1afterlongid3v2.mp3", type: "audio/mpeg", duration: 0.5 },
  // An VBR file with a padding value that is greater than an mp3 packet, and
  // also subsequent packets after the theoretical EOF computed from metadata,
  // to test padding trimming edge cases.
  {
    name: "padding-spanning-multiple-packets.mp3",
    type: "audio/mpeg",
  },
  // A truncated VBR MP3 with just enough frames to keep most decoders happy.
  // The Xing header reports the length of the file to be around 10 seconds, but
  // there is really only one second worth of data. We want MP3FrameParser to
+1 −0
Changes for dom/media/test/mochitest.ini: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -785,6 +785,7 @@ support-files =
  two-xing-header-no-content-length.mp3^headers^
  single-xing-header-no-content-length.mp3
  single-xing-header-no-content-length.mp3^headers^
  padding-spanning-multiple-packets.mp3

[test_capture_stream_av_sync.html]
skip-if =
+115 KiB

File added.

No diff preview for this file type.

+1 −1
Changes for dom/media/test/test_mp3_broadcast.html: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@
            // This scenario is typical in radio broadcast scenario, when the
            // live-stream has a pre-recorded prelude. The reported duration,
            // after "ended" has been received, is the duration of playback.
            { src: "single-xing-header-no-content-length.mp3", duration: 11.030997 },
            { src: "single-xing-header-no-content-length.mp3", duration: 11.050839},
        ];
        var audio = window.a;
        // Prevent ESLint error about top-level await