From af6e144adc5bb4dbf7d2022e56c01baf0879396e Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Tue, 12 Aug 2014 21:35:13 +0100 Subject: [PATCH] Fix bug introduced supporting self-contained media chunks. The equals check we perform needs to ignore the max dimensions. This tended to work in practice because formats would be the same object, but in the case where different format objects are used, things can break. --- .../google/android/exoplayer/MediaFormat.java | 25 ++++++++++++++----- .../exoplayer/chunk/ChunkSampleSource.java | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/MediaFormat.java b/library/src/main/java/com/google/android/exoplayer/MediaFormat.java index f53defdf93..3188e36db0 100644 --- a/library/src/main/java/com/google/android/exoplayer/MediaFormat.java +++ b/library/src/main/java/com/google/android/exoplayer/MediaFormat.java @@ -148,12 +148,25 @@ public class MediaFormat { if (obj == null || getClass() != obj.getClass()) { return false; } - MediaFormat other = (MediaFormat) obj; - if (maxInputSize != other.maxInputSize || width != other.width || height != other.height || - maxWidth != other.maxWidth || maxHeight != other.maxHeight || - channelCount != other.channelCount || sampleRate != other.sampleRate || - !Util.areEqual(mimeType, other.mimeType) || - initializationData.size() != other.initializationData.size()) { + return equalsInternal((MediaFormat) obj, false); + } + + public boolean equals(MediaFormat other, boolean ignoreMaxDimensions) { + if (this == other) { + return true; + } + if (other == null) { + return false; + } + return equalsInternal(other, ignoreMaxDimensions); + } + + private boolean equalsInternal(MediaFormat other, boolean ignoreMaxDimensions) { + if (maxInputSize != other.maxInputSize || width != other.width || height != other.height + || (!ignoreMaxDimensions && (maxWidth != other.maxWidth || maxHeight != other.maxHeight)) + || channelCount != other.channelCount || sampleRate != other.sampleRate + || !Util.areEqual(mimeType, other.mimeType) + || initializationData.size() != other.initializationData.size()) { return false; } for (int i = 0; i < initializationData.size(); i++) { diff --git a/library/src/main/java/com/google/android/exoplayer/chunk/ChunkSampleSource.java b/library/src/main/java/com/google/android/exoplayer/chunk/ChunkSampleSource.java index 860de3c179..069f5c69dc 100644 --- a/library/src/main/java/com/google/android/exoplayer/chunk/ChunkSampleSource.java +++ b/library/src/main/java/com/google/android/exoplayer/chunk/ChunkSampleSource.java @@ -319,7 +319,7 @@ public class ChunkSampleSource implements SampleSource, Loader.Listener { } MediaFormat mediaFormat = mediaChunk.getMediaFormat(); - if (mediaFormat != null && !mediaFormat.equals(downstreamMediaFormat)) { + if (mediaFormat != null && !mediaFormat.equals(downstreamMediaFormat, true)) { chunkSource.getMaxVideoDimensions(mediaFormat); formatHolder.format = mediaFormat; formatHolder.drmInitData = mediaChunk.getPsshInfo();