MPEG4Extractor: Overwrite opus version as 1
mp4 Opus Specific box says Version should be 0.
OpusHead requires this to 1.
MPEG4Extractor now validates that version before
overwriting it with 1.
Bug: 133448278
Test: Extract an mp4 file with opus track
Test: Mux the extracted file to ogg
Test: Extract opus from the muxed ogg file
Change-Id: Iee31eed69ea906b8f34f75f01a4d2c77b3e32077
diff --git a/media/extractors/mp4/MPEG4Extractor.cpp b/media/extractors/mp4/MPEG4Extractor.cpp
index f54690d..527bb77 100755
--- a/media/extractors/mp4/MPEG4Extractor.cpp
+++ b/media/extractors/mp4/MPEG4Extractor.cpp
@@ -1754,6 +1754,15 @@
// http://wiki.xiph.org/OggOpus#ID_Header
strncpy((char *)opusInfo, "OpusHead", 8);
+ // Version shall be 0 as per mp4 Opus Specific Box
+ // (https://opus-codec.org/docs/opus_in_isobmff.html#4.3.2)
+ if (opusInfo[8]) {
+ return ERROR_MALFORMED;
+ }
+ // Force version to 1 as per OpusHead definition
+ // (http://wiki.xiph.org/OggOpus#ID_Header)
+ opusInfo[8] = 1;
+
// Read Opus Specific Box values
size_t opusOffset = 10;
uint16_t pre_skip = U16_AT(&opusInfo[opusOffset]);