diff --git a/RELEASENOTES.md b/RELEASENOTES.md index f5ed04a933..bf708bfa32 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -24,8 +24,8 @@ ([#9458](https://github.com/google/ExoPlayer/issues/9458)). * Remove final dependency on `jcenter()`. * Adjust `ExoPlayer` `MediaMetadata` update priority, such that values - input through the `MediaItem.MediaMetadata` are used above media - derived values. + input through the `MediaItem.MediaMetadata` are used above media derived + values. * Video: * Fix bug in `MediaCodecVideoRenderer` that resulted in re-using a released `Surface` when playing without an app-provided `Surface` @@ -61,6 +61,9 @@ * MP4: Correctly handle HEVC tracks with pixel aspect ratios other than 1. * MP4: Add support for Dolby TrueHD (only for unfragmented streams) ([#9496](https://github.com/google/ExoPlayer/issues/9496)). + * MP4: Avoid throwing `ArrayIndexOutOfBoundsException` when parsing + invalid `colr` boxes produced by some device cameras + ([#9332](https://github.com/google/ExoPlayer/issues/9332)). * TS: Correctly handle HEVC tracks with pixel aspect ratios other than 1. * TS: Map stream type 0x80 to H262 ([#9472](https://github.com/google/ExoPlayer/issues/9472)). diff --git a/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/mp4/AtomParsers.java b/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/mp4/AtomParsers.java index 93b9c5b77a..bc5fa10fe3 100644 --- a/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/mp4/AtomParsers.java +++ b/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/mp4/AtomParsers.java @@ -1198,14 +1198,19 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; } } else if (childAtomType == Atom.TYPE_colr) { int colorType = parent.readInt(); - boolean isNclx = colorType == TYPE_nclx; - if (isNclx || colorType == TYPE_nclc) { + if (colorType == TYPE_nclx || colorType == TYPE_nclc) { // For more info on syntax, see Section 8.5.2.2 in ISO/IEC 14496-12:2012(E) and // https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html. int colorPrimaries = parent.readUnsignedShort(); int transferCharacteristics = parent.readUnsignedShort(); parent.skipBytes(2); // matrix_coefficients. - boolean fullRangeFlag = isNclx && (parent.readUnsignedByte() & 0b10000000) != 0; + + // Only try and read full_range_flag if the box is long enough. It should be present in + // all colr boxes with type=nclx (Section 8.5.2.2 in ISO/IEC 14496-12:2012(E)) but some + // device cameras record videos with type=nclx without this final flag (and therefore + // size=18): https://github.com/google/ExoPlayer/issues/9332 + boolean fullRangeFlag = + childAtomSize == 19 && (parent.readUnsignedByte() & 0b10000000) != 0; colorInfo = new ColorInfo( ColorInfo.isoColorPrimariesToColorSpace(colorPrimaries), diff --git a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/mp4/Mp4ExtractorTest.java b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/mp4/Mp4ExtractorTest.java index 9c41d361ad..911f3f477e 100644 --- a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/mp4/Mp4ExtractorTest.java +++ b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/mp4/Mp4ExtractorTest.java @@ -103,6 +103,17 @@ public final class Mp4ExtractorTest { Mp4Extractor::new, "media/mp4/sample_with_color_info.mp4", simulationConfig); } + /** + * Test case for https://github.com/google/ExoPlayer/issues/9332. The file contains a colr box + * with size=18 and type=nclx. This is not valid according to the spec (size must be 19), but + * files like this exist in the wild. + */ + @Test + public void mp4Sample18ByteNclxColr() throws Exception { + ExtractorAsserts.assertBehavior( + Mp4Extractor::new, "media/mp4/sample_18byte_nclx_colr.mp4", simulationConfig); + } + @Test public void mp4SampleWithDolbyTrueHDTrack() throws Exception { ExtractorAsserts.assertBehavior( diff --git a/testdata/src/test/assets/extractordumps/mp4/sample_18byte_nclx_colr.mp4.0.dump b/testdata/src/test/assets/extractordumps/mp4/sample_18byte_nclx_colr.mp4.0.dump new file mode 100644 index 0000000000..30748b0761 --- /dev/null +++ b/testdata/src/test/assets/extractordumps/mp4/sample_18byte_nclx_colr.mp4.0.dump @@ -0,0 +1,148 @@ +seekMap: + isSeekable = true + duration = 1001000 + getPosition(0) = [[timeUs=0, position=1160]] + getPosition(1) = [[timeUs=0, position=1160]] + getPosition(500500) = [[timeUs=0, position=1160]] + getPosition(1001000) = [[timeUs=0, position=1160]] +numberOfTracks = 1 +track 0: + total output bytes = 89876 + sample count = 30 + format 0: + id = 1 + sampleMimeType = video/avc + codecs = avc1.64001F + maxInputSize = 36722 + width = 1080 + height = 720 + frameRate = 29.970028 + colorInfo: + colorSpace = 1 + colorRange = 2 + colorTransfer = 3 + hdrStaticInfo = length 0, hash 0 + initializationData: + data = length 29, hash 4746B5D9 + data = length 10, hash 7A0D0F2B + sample 0: + time = 0 + flags = 1 + data = length 36692, hash D216076E + sample 1: + time = 66733 + flags = 0 + data = length 5312, hash D45D3CA0 + sample 2: + time = 33366 + flags = 0 + data = length 599, hash 1BE7812D + sample 3: + time = 200200 + flags = 0 + data = length 7735, hash 4490F110 + sample 4: + time = 133466 + flags = 0 + data = length 987, hash 560B5036 + sample 5: + time = 100100 + flags = 0 + data = length 673, hash ED7CD8C7 + sample 6: + time = 166833 + flags = 0 + data = length 523, hash 3020DF50 + sample 7: + time = 333666 + flags = 0 + data = length 6061, hash 736C72B2 + sample 8: + time = 266933 + flags = 0 + data = length 992, hash FE132F23 + sample 9: + time = 233566 + flags = 0 + data = length 623, hash 5B2C1816 + sample 10: + time = 300300 + flags = 0 + data = length 421, hash 742E69C1 + sample 11: + time = 433766 + flags = 0 + data = length 4899, hash F72F86A1 + sample 12: + time = 400400 + flags = 0 + data = length 568, hash 519A8E50 + sample 13: + time = 367033 + flags = 0 + data = length 620, hash 3990AA39 + sample 14: + time = 567233 + flags = 0 + data = length 5450, hash F06EC4AA + sample 15: + time = 500500 + flags = 0 + data = length 1051, hash 92DFA63A + sample 16: + time = 467133 + flags = 0 + data = length 874, hash 69587FB4 + sample 17: + time = 533866 + flags = 0 + data = length 781, hash 36BE495B + sample 18: + time = 700700 + flags = 0 + data = length 4725, hash AC0C8CD3 + sample 19: + time = 633966 + flags = 0 + data = length 1022, hash 5D8BFF34 + sample 20: + time = 600600 + flags = 0 + data = length 790, hash 99413A99 + sample 21: + time = 667333 + flags = 0 + data = length 610, hash 5E129290 + sample 22: + time = 834166 + flags = 0 + data = length 2751, hash 769974CB + sample 23: + time = 767433 + flags = 0 + data = length 745, hash B78A477A + sample 24: + time = 734066 + flags = 0 + data = length 621, hash CF741E7A + sample 25: + time = 800800 + flags = 0 + data = length 505, hash 1DB4894E + sample 26: + time = 967633 + flags = 0 + data = length 1268, hash C15348DC + sample 27: + time = 900900 + flags = 0 + data = length 880, hash C2DE85D0 + sample 28: + time = 867533 + flags = 0 + data = length 530, hash C98BC6A8 + sample 29: + time = 934266 + flags = 536870912 + data = length 568, hash 4FE5C8EA +tracksEnded = true diff --git a/testdata/src/test/assets/extractordumps/mp4/sample_18byte_nclx_colr.mp4.1.dump b/testdata/src/test/assets/extractordumps/mp4/sample_18byte_nclx_colr.mp4.1.dump new file mode 100644 index 0000000000..30748b0761 --- /dev/null +++ b/testdata/src/test/assets/extractordumps/mp4/sample_18byte_nclx_colr.mp4.1.dump @@ -0,0 +1,148 @@ +seekMap: + isSeekable = true + duration = 1001000 + getPosition(0) = [[timeUs=0, position=1160]] + getPosition(1) = [[timeUs=0, position=1160]] + getPosition(500500) = [[timeUs=0, position=1160]] + getPosition(1001000) = [[timeUs=0, position=1160]] +numberOfTracks = 1 +track 0: + total output bytes = 89876 + sample count = 30 + format 0: + id = 1 + sampleMimeType = video/avc + codecs = avc1.64001F + maxInputSize = 36722 + width = 1080 + height = 720 + frameRate = 29.970028 + colorInfo: + colorSpace = 1 + colorRange = 2 + colorTransfer = 3 + hdrStaticInfo = length 0, hash 0 + initializationData: + data = length 29, hash 4746B5D9 + data = length 10, hash 7A0D0F2B + sample 0: + time = 0 + flags = 1 + data = length 36692, hash D216076E + sample 1: + time = 66733 + flags = 0 + data = length 5312, hash D45D3CA0 + sample 2: + time = 33366 + flags = 0 + data = length 599, hash 1BE7812D + sample 3: + time = 200200 + flags = 0 + data = length 7735, hash 4490F110 + sample 4: + time = 133466 + flags = 0 + data = length 987, hash 560B5036 + sample 5: + time = 100100 + flags = 0 + data = length 673, hash ED7CD8C7 + sample 6: + time = 166833 + flags = 0 + data = length 523, hash 3020DF50 + sample 7: + time = 333666 + flags = 0 + data = length 6061, hash 736C72B2 + sample 8: + time = 266933 + flags = 0 + data = length 992, hash FE132F23 + sample 9: + time = 233566 + flags = 0 + data = length 623, hash 5B2C1816 + sample 10: + time = 300300 + flags = 0 + data = length 421, hash 742E69C1 + sample 11: + time = 433766 + flags = 0 + data = length 4899, hash F72F86A1 + sample 12: + time = 400400 + flags = 0 + data = length 568, hash 519A8E50 + sample 13: + time = 367033 + flags = 0 + data = length 620, hash 3990AA39 + sample 14: + time = 567233 + flags = 0 + data = length 5450, hash F06EC4AA + sample 15: + time = 500500 + flags = 0 + data = length 1051, hash 92DFA63A + sample 16: + time = 467133 + flags = 0 + data = length 874, hash 69587FB4 + sample 17: + time = 533866 + flags = 0 + data = length 781, hash 36BE495B + sample 18: + time = 700700 + flags = 0 + data = length 4725, hash AC0C8CD3 + sample 19: + time = 633966 + flags = 0 + data = length 1022, hash 5D8BFF34 + sample 20: + time = 600600 + flags = 0 + data = length 790, hash 99413A99 + sample 21: + time = 667333 + flags = 0 + data = length 610, hash 5E129290 + sample 22: + time = 834166 + flags = 0 + data = length 2751, hash 769974CB + sample 23: + time = 767433 + flags = 0 + data = length 745, hash B78A477A + sample 24: + time = 734066 + flags = 0 + data = length 621, hash CF741E7A + sample 25: + time = 800800 + flags = 0 + data = length 505, hash 1DB4894E + sample 26: + time = 967633 + flags = 0 + data = length 1268, hash C15348DC + sample 27: + time = 900900 + flags = 0 + data = length 880, hash C2DE85D0 + sample 28: + time = 867533 + flags = 0 + data = length 530, hash C98BC6A8 + sample 29: + time = 934266 + flags = 536870912 + data = length 568, hash 4FE5C8EA +tracksEnded = true diff --git a/testdata/src/test/assets/extractordumps/mp4/sample_18byte_nclx_colr.mp4.2.dump b/testdata/src/test/assets/extractordumps/mp4/sample_18byte_nclx_colr.mp4.2.dump new file mode 100644 index 0000000000..30748b0761 --- /dev/null +++ b/testdata/src/test/assets/extractordumps/mp4/sample_18byte_nclx_colr.mp4.2.dump @@ -0,0 +1,148 @@ +seekMap: + isSeekable = true + duration = 1001000 + getPosition(0) = [[timeUs=0, position=1160]] + getPosition(1) = [[timeUs=0, position=1160]] + getPosition(500500) = [[timeUs=0, position=1160]] + getPosition(1001000) = [[timeUs=0, position=1160]] +numberOfTracks = 1 +track 0: + total output bytes = 89876 + sample count = 30 + format 0: + id = 1 + sampleMimeType = video/avc + codecs = avc1.64001F + maxInputSize = 36722 + width = 1080 + height = 720 + frameRate = 29.970028 + colorInfo: + colorSpace = 1 + colorRange = 2 + colorTransfer = 3 + hdrStaticInfo = length 0, hash 0 + initializationData: + data = length 29, hash 4746B5D9 + data = length 10, hash 7A0D0F2B + sample 0: + time = 0 + flags = 1 + data = length 36692, hash D216076E + sample 1: + time = 66733 + flags = 0 + data = length 5312, hash D45D3CA0 + sample 2: + time = 33366 + flags = 0 + data = length 599, hash 1BE7812D + sample 3: + time = 200200 + flags = 0 + data = length 7735, hash 4490F110 + sample 4: + time = 133466 + flags = 0 + data = length 987, hash 560B5036 + sample 5: + time = 100100 + flags = 0 + data = length 673, hash ED7CD8C7 + sample 6: + time = 166833 + flags = 0 + data = length 523, hash 3020DF50 + sample 7: + time = 333666 + flags = 0 + data = length 6061, hash 736C72B2 + sample 8: + time = 266933 + flags = 0 + data = length 992, hash FE132F23 + sample 9: + time = 233566 + flags = 0 + data = length 623, hash 5B2C1816 + sample 10: + time = 300300 + flags = 0 + data = length 421, hash 742E69C1 + sample 11: + time = 433766 + flags = 0 + data = length 4899, hash F72F86A1 + sample 12: + time = 400400 + flags = 0 + data = length 568, hash 519A8E50 + sample 13: + time = 367033 + flags = 0 + data = length 620, hash 3990AA39 + sample 14: + time = 567233 + flags = 0 + data = length 5450, hash F06EC4AA + sample 15: + time = 500500 + flags = 0 + data = length 1051, hash 92DFA63A + sample 16: + time = 467133 + flags = 0 + data = length 874, hash 69587FB4 + sample 17: + time = 533866 + flags = 0 + data = length 781, hash 36BE495B + sample 18: + time = 700700 + flags = 0 + data = length 4725, hash AC0C8CD3 + sample 19: + time = 633966 + flags = 0 + data = length 1022, hash 5D8BFF34 + sample 20: + time = 600600 + flags = 0 + data = length 790, hash 99413A99 + sample 21: + time = 667333 + flags = 0 + data = length 610, hash 5E129290 + sample 22: + time = 834166 + flags = 0 + data = length 2751, hash 769974CB + sample 23: + time = 767433 + flags = 0 + data = length 745, hash B78A477A + sample 24: + time = 734066 + flags = 0 + data = length 621, hash CF741E7A + sample 25: + time = 800800 + flags = 0 + data = length 505, hash 1DB4894E + sample 26: + time = 967633 + flags = 0 + data = length 1268, hash C15348DC + sample 27: + time = 900900 + flags = 0 + data = length 880, hash C2DE85D0 + sample 28: + time = 867533 + flags = 0 + data = length 530, hash C98BC6A8 + sample 29: + time = 934266 + flags = 536870912 + data = length 568, hash 4FE5C8EA +tracksEnded = true diff --git a/testdata/src/test/assets/extractordumps/mp4/sample_18byte_nclx_colr.mp4.3.dump b/testdata/src/test/assets/extractordumps/mp4/sample_18byte_nclx_colr.mp4.3.dump new file mode 100644 index 0000000000..30748b0761 --- /dev/null +++ b/testdata/src/test/assets/extractordumps/mp4/sample_18byte_nclx_colr.mp4.3.dump @@ -0,0 +1,148 @@ +seekMap: + isSeekable = true + duration = 1001000 + getPosition(0) = [[timeUs=0, position=1160]] + getPosition(1) = [[timeUs=0, position=1160]] + getPosition(500500) = [[timeUs=0, position=1160]] + getPosition(1001000) = [[timeUs=0, position=1160]] +numberOfTracks = 1 +track 0: + total output bytes = 89876 + sample count = 30 + format 0: + id = 1 + sampleMimeType = video/avc + codecs = avc1.64001F + maxInputSize = 36722 + width = 1080 + height = 720 + frameRate = 29.970028 + colorInfo: + colorSpace = 1 + colorRange = 2 + colorTransfer = 3 + hdrStaticInfo = length 0, hash 0 + initializationData: + data = length 29, hash 4746B5D9 + data = length 10, hash 7A0D0F2B + sample 0: + time = 0 + flags = 1 + data = length 36692, hash D216076E + sample 1: + time = 66733 + flags = 0 + data = length 5312, hash D45D3CA0 + sample 2: + time = 33366 + flags = 0 + data = length 599, hash 1BE7812D + sample 3: + time = 200200 + flags = 0 + data = length 7735, hash 4490F110 + sample 4: + time = 133466 + flags = 0 + data = length 987, hash 560B5036 + sample 5: + time = 100100 + flags = 0 + data = length 673, hash ED7CD8C7 + sample 6: + time = 166833 + flags = 0 + data = length 523, hash 3020DF50 + sample 7: + time = 333666 + flags = 0 + data = length 6061, hash 736C72B2 + sample 8: + time = 266933 + flags = 0 + data = length 992, hash FE132F23 + sample 9: + time = 233566 + flags = 0 + data = length 623, hash 5B2C1816 + sample 10: + time = 300300 + flags = 0 + data = length 421, hash 742E69C1 + sample 11: + time = 433766 + flags = 0 + data = length 4899, hash F72F86A1 + sample 12: + time = 400400 + flags = 0 + data = length 568, hash 519A8E50 + sample 13: + time = 367033 + flags = 0 + data = length 620, hash 3990AA39 + sample 14: + time = 567233 + flags = 0 + data = length 5450, hash F06EC4AA + sample 15: + time = 500500 + flags = 0 + data = length 1051, hash 92DFA63A + sample 16: + time = 467133 + flags = 0 + data = length 874, hash 69587FB4 + sample 17: + time = 533866 + flags = 0 + data = length 781, hash 36BE495B + sample 18: + time = 700700 + flags = 0 + data = length 4725, hash AC0C8CD3 + sample 19: + time = 633966 + flags = 0 + data = length 1022, hash 5D8BFF34 + sample 20: + time = 600600 + flags = 0 + data = length 790, hash 99413A99 + sample 21: + time = 667333 + flags = 0 + data = length 610, hash 5E129290 + sample 22: + time = 834166 + flags = 0 + data = length 2751, hash 769974CB + sample 23: + time = 767433 + flags = 0 + data = length 745, hash B78A477A + sample 24: + time = 734066 + flags = 0 + data = length 621, hash CF741E7A + sample 25: + time = 800800 + flags = 0 + data = length 505, hash 1DB4894E + sample 26: + time = 967633 + flags = 0 + data = length 1268, hash C15348DC + sample 27: + time = 900900 + flags = 0 + data = length 880, hash C2DE85D0 + sample 28: + time = 867533 + flags = 0 + data = length 530, hash C98BC6A8 + sample 29: + time = 934266 + flags = 536870912 + data = length 568, hash 4FE5C8EA +tracksEnded = true diff --git a/testdata/src/test/assets/extractordumps/mp4/sample_18byte_nclx_colr.mp4.unknown_length.dump b/testdata/src/test/assets/extractordumps/mp4/sample_18byte_nclx_colr.mp4.unknown_length.dump new file mode 100644 index 0000000000..30748b0761 --- /dev/null +++ b/testdata/src/test/assets/extractordumps/mp4/sample_18byte_nclx_colr.mp4.unknown_length.dump @@ -0,0 +1,148 @@ +seekMap: + isSeekable = true + duration = 1001000 + getPosition(0) = [[timeUs=0, position=1160]] + getPosition(1) = [[timeUs=0, position=1160]] + getPosition(500500) = [[timeUs=0, position=1160]] + getPosition(1001000) = [[timeUs=0, position=1160]] +numberOfTracks = 1 +track 0: + total output bytes = 89876 + sample count = 30 + format 0: + id = 1 + sampleMimeType = video/avc + codecs = avc1.64001F + maxInputSize = 36722 + width = 1080 + height = 720 + frameRate = 29.970028 + colorInfo: + colorSpace = 1 + colorRange = 2 + colorTransfer = 3 + hdrStaticInfo = length 0, hash 0 + initializationData: + data = length 29, hash 4746B5D9 + data = length 10, hash 7A0D0F2B + sample 0: + time = 0 + flags = 1 + data = length 36692, hash D216076E + sample 1: + time = 66733 + flags = 0 + data = length 5312, hash D45D3CA0 + sample 2: + time = 33366 + flags = 0 + data = length 599, hash 1BE7812D + sample 3: + time = 200200 + flags = 0 + data = length 7735, hash 4490F110 + sample 4: + time = 133466 + flags = 0 + data = length 987, hash 560B5036 + sample 5: + time = 100100 + flags = 0 + data = length 673, hash ED7CD8C7 + sample 6: + time = 166833 + flags = 0 + data = length 523, hash 3020DF50 + sample 7: + time = 333666 + flags = 0 + data = length 6061, hash 736C72B2 + sample 8: + time = 266933 + flags = 0 + data = length 992, hash FE132F23 + sample 9: + time = 233566 + flags = 0 + data = length 623, hash 5B2C1816 + sample 10: + time = 300300 + flags = 0 + data = length 421, hash 742E69C1 + sample 11: + time = 433766 + flags = 0 + data = length 4899, hash F72F86A1 + sample 12: + time = 400400 + flags = 0 + data = length 568, hash 519A8E50 + sample 13: + time = 367033 + flags = 0 + data = length 620, hash 3990AA39 + sample 14: + time = 567233 + flags = 0 + data = length 5450, hash F06EC4AA + sample 15: + time = 500500 + flags = 0 + data = length 1051, hash 92DFA63A + sample 16: + time = 467133 + flags = 0 + data = length 874, hash 69587FB4 + sample 17: + time = 533866 + flags = 0 + data = length 781, hash 36BE495B + sample 18: + time = 700700 + flags = 0 + data = length 4725, hash AC0C8CD3 + sample 19: + time = 633966 + flags = 0 + data = length 1022, hash 5D8BFF34 + sample 20: + time = 600600 + flags = 0 + data = length 790, hash 99413A99 + sample 21: + time = 667333 + flags = 0 + data = length 610, hash 5E129290 + sample 22: + time = 834166 + flags = 0 + data = length 2751, hash 769974CB + sample 23: + time = 767433 + flags = 0 + data = length 745, hash B78A477A + sample 24: + time = 734066 + flags = 0 + data = length 621, hash CF741E7A + sample 25: + time = 800800 + flags = 0 + data = length 505, hash 1DB4894E + sample 26: + time = 967633 + flags = 0 + data = length 1268, hash C15348DC + sample 27: + time = 900900 + flags = 0 + data = length 880, hash C2DE85D0 + sample 28: + time = 867533 + flags = 0 + data = length 530, hash C98BC6A8 + sample 29: + time = 934266 + flags = 536870912 + data = length 568, hash 4FE5C8EA +tracksEnded = true diff --git a/testdata/src/test/assets/media/mp4/sample_18byte_nclx_colr.mp4 b/testdata/src/test/assets/media/mp4/sample_18byte_nclx_colr.mp4 new file mode 100644 index 0000000000..1a2afa2c40 Binary files /dev/null and b/testdata/src/test/assets/media/mp4/sample_18byte_nclx_colr.mp4 differ