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
This commit is contained in:
andrewlewis 2018-05-15 06:56:19 -07:00 committed by Andrew Lewis
parent 0c3b1a6401
commit 75db04d51d
2 changed files with 13 additions and 8 deletions

View file

@ -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 ###

View file

@ -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() {