Commit 75db04d5 by andrewlewis Committed by Andrew Lewis

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
parent 0c3b1a64
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
([#2843](https://github.com/google/ExoPlayer/issues/2843)). ([#2843](https://github.com/google/ExoPlayer/issues/2843)).
* Fix crash when switching surface on Moto E(4) * Fix crash when switching surface on Moto E(4)
([#4134](https://github.com/google/ExoPlayer/issues/4134)). ([#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 ### ### 2.8.0 ###
......
...@@ -189,11 +189,13 @@ import java.util.List; ...@@ -189,11 +189,13 @@ import java.util.List;
} }
} }
// True if we can rechunk fixed-sample-size data. Note that we only rechunk raw audio. // Fixed sample size raw audio may need to be rechunked.
boolean isRechunkable = sampleSizeBox.isFixedSampleSize() boolean isFixedSampleSizeRawAudio =
&& MimeTypes.AUDIO_RAW.equals(track.format.sampleMimeType) sampleSizeBox.isFixedSampleSize()
&& remainingTimestampDeltaChanges == 0 && remainingTimestampOffsetChanges == 0 && MimeTypes.AUDIO_RAW.equals(track.format.sampleMimeType)
&& remainingSynchronizationSamples == 0; && remainingTimestampDeltaChanges == 0
&& remainingTimestampOffsetChanges == 0
&& remainingSynchronizationSamples == 0;
long[] offsets; long[] offsets;
int[] sizes; int[] sizes;
...@@ -203,7 +205,7 @@ import java.util.List; ...@@ -203,7 +205,7 @@ import java.util.List;
long timestampTimeUnits = 0; long timestampTimeUnits = 0;
long duration; long duration;
if (!isRechunkable) { if (!isFixedSampleSizeRawAudio) {
offsets = new long[sampleCount]; offsets = new long[sampleCount];
sizes = new int[sampleCount]; sizes = new int[sampleCount];
timestamps = new long[sampleCount]; timestamps = new long[sampleCount];
...@@ -296,7 +298,8 @@ import java.util.List; ...@@ -296,7 +298,8 @@ import java.util.List;
chunkOffsetsBytes[chunkIterator.index] = chunkIterator.offset; chunkOffsetsBytes[chunkIterator.index] = chunkIterator.offset;
chunkSampleCounts[chunkIterator.index] = chunkIterator.numSamples; chunkSampleCounts[chunkIterator.index] = chunkIterator.numSamples;
} }
int fixedSampleSize = sampleSizeBox.readNextSampleSize(); int fixedSampleSize =
Util.getPcmFrameSize(track.format.pcmEncoding, track.format.channelCount);
FixedSampleSizeRechunker.Results rechunkedResults = FixedSampleSizeRechunker.rechunk( FixedSampleSizeRechunker.Results rechunkedResults = FixedSampleSizeRechunker.rechunk(
fixedSampleSize, chunkOffsetsBytes, chunkSampleCounts, timestampDeltaInTimeUnits); fixedSampleSize, chunkOffsetsBytes, chunkSampleCounts, timestampDeltaInTimeUnits);
offsets = rechunkedResults.offsets; offsets = rechunkedResults.offsets;
...@@ -1224,7 +1227,7 @@ import java.util.List; ...@@ -1224,7 +1227,7 @@ import java.util.List;
stsc.setPosition(Atom.FULL_HEADER_SIZE); stsc.setPosition(Atom.FULL_HEADER_SIZE);
remainingSamplesPerChunkChanges = stsc.readUnsignedIntToInt(); remainingSamplesPerChunkChanges = stsc.readUnsignedIntToInt();
Assertions.checkState(stsc.readInt() == 1, "first_chunk must be 1"); Assertions.checkState(stsc.readInt() == 1, "first_chunk must be 1");
index = C.INDEX_UNSET; index = -1;
} }
public boolean moveNext() { public boolean moveNext() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment