Skip to content

Commit

Permalink
Implement MP3 ConstantBitrateSeeker.getDataEndPosition()
Browse files Browse the repository at this point in the history
This is needed to correctly handle files with trailing non-MP3 data
(which is indicated by the length in the `Info` frame being shorter than
the overall length of the file).

The test file was generated by appending 150kB of `DEADBEEF` onto the
end of `test-cbr-info-header.mp3`, and the test asserts that the
extracted samples are identical.

Issue: #1480

#cherrypick

PiperOrigin-RevId: 658727595
  • Loading branch information
icbaker authored and copybara-github committed Aug 2, 2024
1 parent 018d048 commit b09cea9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
* Extractors:
* Allow `Mp4Extractor` and `FragmentedMp4Extractor` to identify H264
samples that are not used as reference by subsequent samples.
* MP3: Fix `Searched too many bytes` error by correctly ignoring trailing
non-MP3 data based on the length field in an `Info` frame
([#1480](https://github.com/androidx/media/issues/1480)).
* DataSource:
* Update `HttpEngineDataSource` to allow use starting at version S
extension 7 instead of API level 34
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
/* package */ final class ConstantBitrateSeeker extends ConstantBitrateSeekMap implements Seeker {

private final int bitrate;
private final long dataEndPosition;

/**
* Constructs an instance.
Expand Down Expand Up @@ -60,6 +61,7 @@ public ConstantBitrateSeeker(
boolean allowSeeksIfLengthUnknown) {
super(inputLength, firstFramePosition, bitrate, frameSize, allowSeeksIfLengthUnknown);
this.bitrate = bitrate;
dataEndPosition = inputLength != C.LENGTH_UNSET ? inputLength : C.INDEX_UNSET;
}

@Override
Expand All @@ -69,7 +71,7 @@ public long getTimeUs(long position) {

@Override
public long getDataEndPosition() {
return C.INDEX_UNSET;
return dataEndPosition;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ public void mp3SampleWithInfoHeaderAndPcutFrame() throws Exception {
Mp3Extractor::new, "media/mp3/test-cbr-info-header-pcut-frame.mp3", simulationConfig);
}

// https://github.com/androidx/media/issues/1480
@Test
public void mp3SampleWithInfoHeaderAndTrailingGarbage() throws Exception {
// This test file is test-cbr-info-header.mp3 with 150kB of 0xDEADBEEF garbage appended on the
// end. The test asserts that the extracted samples are the same as for
// test-cbr-info-header.mp3.
ExtractorAsserts.assertBehavior(
Mp3Extractor::new,
"media/mp3/test-cbr-info-header-trailing-garbage.mp3",
new AssertionConfig.Builder()
.setDumpFilesPrefix("extractordumps/mp3/test-cbr-info-header.mp3")
.build(),
simulationConfig);
}

@Test
public void mp3SampleWithCbrSeeker() throws Exception {
ExtractorAsserts.assertBehavior(
Expand Down
Binary file not shown.

0 comments on commit b09cea9

Please sign in to comment.