From 75db04d51d383a104f7e2b24e1b69286c1a5545f Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Tue, 15 May 2018 06:56:19 -0700 Subject: [PATCH] Fix extraction of PCM (sowt) in MP4/MOV The sample size from the stsd box takes precedence over the sample size in the stsz box. Also remove assumption that C.INDEX_UNSET is -1 in ChunkIterator (which is a no-op change). Issue: #4228 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=196661751 --- RELEASENOTES.md | 2 ++ .../exoplayer2/extractor/mp4/AtomParsers.java | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index cf184da968..e657289cef 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -11,6 +11,8 @@ ([#2843](https://github.com/google/ExoPlayer/issues/2843)). * Fix crash when switching surface on Moto E(4) ([#4134](https://github.com/google/ExoPlayer/issues/4134)). +* Audio: Fix extraction of PCM in MP4/MOV + ([#4228](https://github.com/google/ExoPlayer/issues/4228)). ### 2.8.0 ### diff --git a/library/core/src/main/java/com/google/android/exoplayer2/extractor/mp4/AtomParsers.java b/library/core/src/main/java/com/google/android/exoplayer2/extractor/mp4/AtomParsers.java index a6e2524f0b..a2b787d6b0 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/extractor/mp4/AtomParsers.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/extractor/mp4/AtomParsers.java @@ -189,11 +189,13 @@ import java.util.List; } } - // True if we can rechunk fixed-sample-size data. Note that we only rechunk raw audio. - boolean isRechunkable = sampleSizeBox.isFixedSampleSize() - && MimeTypes.AUDIO_RAW.equals(track.format.sampleMimeType) - && remainingTimestampDeltaChanges == 0 && remainingTimestampOffsetChanges == 0 - && remainingSynchronizationSamples == 0; + // Fixed sample size raw audio may need to be rechunked. + boolean isFixedSampleSizeRawAudio = + sampleSizeBox.isFixedSampleSize() + && MimeTypes.AUDIO_RAW.equals(track.format.sampleMimeType) + && remainingTimestampDeltaChanges == 0 + && remainingTimestampOffsetChanges == 0 + && remainingSynchronizationSamples == 0; long[] offsets; int[] sizes; @@ -203,7 +205,7 @@ import java.util.List; long timestampTimeUnits = 0; long duration; - if (!isRechunkable) { + if (!isFixedSampleSizeRawAudio) { offsets = new long[sampleCount]; sizes = new int[sampleCount]; timestamps = new long[sampleCount]; @@ -296,7 +298,8 @@ import java.util.List; chunkOffsetsBytes[chunkIterator.index] = chunkIterator.offset; chunkSampleCounts[chunkIterator.index] = chunkIterator.numSamples; } - int fixedSampleSize = sampleSizeBox.readNextSampleSize(); + int fixedSampleSize = + Util.getPcmFrameSize(track.format.pcmEncoding, track.format.channelCount); FixedSampleSizeRechunker.Results rechunkedResults = FixedSampleSizeRechunker.rechunk( fixedSampleSize, chunkOffsetsBytes, chunkSampleCounts, timestampDeltaInTimeUnits); offsets = rechunkedResults.offsets; @@ -1224,7 +1227,7 @@ import java.util.List; stsc.setPosition(Atom.FULL_HEADER_SIZE); remainingSamplesPerChunkChanges = stsc.readUnsignedIntToInt(); Assertions.checkState(stsc.readInt() == 1, "first_chunk must be 1"); - index = C.INDEX_UNSET; + index = -1; } public boolean moveNext() {