Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to play opus files on v2.17.0. Works fine with previous version of EXOPlayer (IllegalStateException) #10038

Closed
theboubougne opened this issue Mar 9, 2022 · 2 comments
Assignees

Comments

@theboubougne
Copy link

Trying to play the following opus file fails on v2.17.0 with the following stack

  com.google.android.exoplayer2.ExoPlaybackException: Source error
    at com.google.android.exoplayer2.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:640)
    at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:616)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.os.HandlerThread.run(HandlerThread.java:67)
 Caused by: com.google.android.exoplayer2.upstream.Loader$UnexpectedLoaderException: Unexpected IllegalStateException: null
    at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:433)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:920)
 Caused by: java.lang.IllegalStateException
    at com.google.android.exoplayer2.util.Assertions.checkState(Assertions.java:84)
    at com.google.android.exoplayer2.extractor.ogg.OpusReader.readHeaders(OpusReader.java:62)
    at com.google.android.exoplayer2.extractor.ogg.StreamReader.readHeaders(StreamReader.java:151)
    at com.google.android.exoplayer2.extractor.ogg.StreamReader.readHeadersAndUpdateState(StreamReader.java:161)
    at com.google.android.exoplayer2.extractor.ogg.StreamReader.read(StreamReader.java:112)
    at com.google.android.exoplayer2.extractor.ogg.OggExtractor.read(OggExtractor.java:88)
    at com.google.android.exoplayer2.source.BundledExtractorsAdapter.read(BundledExtractorsAdapter.java:127)
    at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1042)

Playing the same file with 2.16.1 (and older versions works fine)
Tested on different devices and android version
seaOfMonsters-09-opus.zip

@theboubougne theboubougne changed the title Failure to play opus files. Work fine with 2.16.1 Failure to play opus files on v2.17.0. Works fine with previous version of EXOPlayer (IllegalStateException) Mar 9, 2022
@icbaker icbaker self-assigned this Mar 9, 2022
@icbaker
Copy link
Collaborator

icbaker commented Mar 9, 2022

The line that's throwing the exception was introduced during the internal code review of PR #9864 and is part of fe7e5b8.

It's failing because it's finding a second Opus identification header in the file, which the spec (RFC7845) clearly forbids. The spec requires the ID header to be in the first Ogg packet:

In section 3:

There are two mandatory header packets. The first packet in the logical Ogg bitstream MUST contain the identification (ID) header, which uniquely identifies a stream as Opus audio.
[...]
All subsequent pages are audio data pages, and the Ogg packets they contain are audio data packets.

In section 5:

An Ogg Opus logical stream contains exactly two mandatory header packets: an identification header and a comment header.

When looking at the file in a binary viewer, you can see two OpusHead magic strings which identify the two ID headers [1].

So I think this media is invalid - but we can tweak ExoPlayer to be more permissive here and only accept the first ID and comment headers it finds, ignoring all subsequent ones - this more closely matches the behaviour from 2.16.1. I'll make that change.


[1]

$ hexdump -C seaOfMonsters-09.opus  |  less
00000000  4f 67 67 53 00 02 00 00  00 00 00 00 00 00 4e 38  |OggS..........N8|
00000010  b8 3f 00 00 00 00 c6 c9  2c 3a 01 13 4f 70 75 73  |.?......,:..Opus|
00000020  48 65 61 64 01 02 38 01  44 ac 00 00 00 00 00 4f  |Head..8.D......O|
00000030  67 67 53 00 00 00 00 00  00 00 00 00 00 4e 38 b8  |ggS..........N8.|
00000040  3f 01 00 00 00 f2 19 0d  48 01 e5 4f 70 75 73 54  |?.......H..OpusT|
00000050  61 67 73 1f 00 00 00 6c  69 62 6f 70 75 73 20 31  |ags....libopus 1|
00000060  2e 33 2e 31 2c 20 6c 69  62 6f 70 75 73 65 6e 63  |.3.1, libopusenc|
00000070  20 30 2e 32 2e 31 07 00  00 00 0f 00 00 00 54 49  | 0.2.1........TI|
00000080  54 4c 45 3d 43 68 61 70  74 65 72 20 38 13 00 00  |TLE=Chapter 8...|
00000090  00 41 52 54 49 53 54 3d  52 69 63 6b 20 52 69 6f  |.ARTIST=Rick Rio|
000000a0  72 64 61 6e 19 00 00 00  41 4c 42 55 4d 3d 54 68  |rdan....ALBUM=Th|
000000b0  65 20 53 65 61 20 6f 66  20 4d 6f 6e 73 74 65 72  |e Sea of Monster|
000000c0  73 09 00 00 00 44 41 54  45 3d 32 30 30 36 0e 00  |s....DATE=2006..|
000000d0  00 00 54 52 41 43 4b 4e  55 4d 42 45 52 3d 30 39  |..TRACKNUMBER=09|
000000e0  0d 00 00 00 54 52 41 43  4b 54 4f 54 41 4c 3d 32  |....TRACKTOTAL=2|
000000f0  32 3a 00 00 00 44 45 53  43 52 49 50 54 49 4f 4e  |2:...DESCRIPTION|
00000100  3d 50 65 72 63 79 20 4a  61 63 6b 73 6f 6e 20 61  |=Percy Jackson a|
00000110  6e 64 20 74 68 65 20 4f  6c 79 6d 70 69 61 6e 73  |nd the Olympians|
00000120  20 53 65 72 69 65 73 2c  20 42 6f 6f 6b 20 32 01  | Series, Book 2.|
00000130  4f 67 67 53 00 00 00 00  00 00 00 00 00 00 4e 38  |OggS..........N8|
00000140  b8 3f 02 00 00 00 9a df  f5 cc 01 13 4f 70 75 73  |.?..........Opus|
00000150  48 65 61 64 01 02 38 01  44 ac 00 00 00 00 00 4f  |Head..8.D......O|
00000160  67 67 53 00 00 00 00 00  00 00 00 00 00 4e 38 b8  |ggS..........N8.|
00000170  3f 03 00 00 00 f8 84 63  5f 03 ff ff fe 4f 70 75  |?......c_....Opu|
00000180  73 54 61 67 73 1f 00 00  00 6c 69 62 6f 70 75 73  |sTags....libopus|
00000190  20 31 2e 33 2e 31 2c 20  6c 69 62 6f 70 75 73 65  | 1.3.1, libopuse|
000001a0  6e 63 20 30 2e 32 2e 31  02 00 00 00 23 00 00 00  |nc 0.2.1....#...|
000001b0  45 4e 43 4f 44 45 52 3d  6f 70 75 73 65 6e 63 20  |ENCODER=opusenc |
000001c0  66 72 6f 6d 20 6f 70 75  73 2d 74 6f 6f 6c 73 20  |from opus-tools |
000001d0  30 2e 32 15 00 00 00 45  4e 43 4f 44 45 52 5f 4f  |0.2....ENCODER_O|
000001e0  50 54 49 4f 4e 53 3d 2d  2d 76 62 72 00 00 00 00  |PTIONS=--vbr....|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000470  00 00 00 00 00 00 00 00  00 4f 67 67 53 00 00 80  |.........OggS...|

@theboubougne
Copy link
Author

theboubougne commented Mar 9, 2022 via email

marcbaechinger pushed a commit to androidx/media that referenced this issue May 31, 2022
This reinstates the permissive behaviour removed by
fe7e5b8

Test file created by opening bear.opus in a hex editor and naively
duplicating the two header packets, starting at (and including) the
first `OggS` in the file and ending just before the third `OggS`.

#minor-release

Issue: google/ExoPlayer#10038
PiperOrigin-RevId: 452015662
marcbaechinger pushed a commit that referenced this issue May 31, 2022
This reinstates the permissive behaviour removed by
fe7e5b8

Test file created by opening bear.opus in a hex editor and naively
duplicating the two header packets, starting at (and including) the
first `OggS` in the file and ending just before the third `OggS`.

#minor-release

Issue: #10038
PiperOrigin-RevId: 452015662
marcbaechinger pushed a commit that referenced this issue Jun 15, 2022
This reinstates the permissive behaviour removed by
fe7e5b8

Test file created by opening bear.opus in a hex editor and naively
duplicating the two header packets, starting at (and including) the
first `OggS` in the file and ending just before the third `OggS`.

#minor-release

Issue: #10038
PiperOrigin-RevId: 452015662
(cherry picked from commit b6b2826)
marcbaechinger pushed a commit to androidx/media that referenced this issue Jun 15, 2022
This reinstates the permissive behaviour removed by
fe7e5b8

Test file created by opening bear.opus in a hex editor and naively
duplicating the two header packets, starting at (and including) the
first `OggS` in the file and ending just before the third `OggS`.

#minor-release

Issue: google/ExoPlayer#10038
PiperOrigin-RevId: 452015662
(cherry picked from commit 1282175)
@icbaker icbaker closed this as completed Aug 30, 2022
@google google locked and limited conversation to collaborators Oct 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants