Skip to content

Use MediaCodec as decoder#9

Merged
devgianlu merged 5 commits intomasterfrom
android-decoder
May 5, 2021
Merged

Use MediaCodec as decoder#9
devgianlu merged 5 commits intomasterfrom
android-decoder

Conversation

@devgianlu
Copy link
Copy Markdown
Owner

@devgianlu devgianlu commented May 2, 2021

  • Write vorbis decoder
  • Configure the decoder with the correct audio format data (sample rate, # channels, ...)
  • Fix presentation time
  • Write MP3 decoder

@devgianlu devgianlu linked an issue May 2, 2021 that may be closed by this pull request
@devgianlu
Copy link
Copy Markdown
Owner Author

@funtax @mitschwimmer It's working! Feel free to make changes if needed.

To force it to use the native decoder change this line:

buildConfigField "boolean", "FORCE_NATIVE_DECODER", "false"

@mitschwimmer
Copy link
Copy Markdown
Collaborator

@devgianlu great to hear that this worked out! Sadly it does not on my test device. The extractor is not finding a track in my case. Do you have an idea why?

2021-05-03 20:32:04.325 13829-13934/xyz.gianlu.librespot.android E/x.g.l.a.d.Decoders: Failed initializing Codec instance for VORBIS
    java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at xyz.gianlu.librespot.audio.decoders.Decoders.initDecoder(Decoders.java:54)
        at xyz.gianlu.librespot.player.playback.PlayerQueueEntry.load(PlayerQueueEntry.java:140)
        at xyz.gianlu.librespot.player.playback.PlayerQueueEntry.run(PlayerQueueEntry.java:271)
        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:923)
     Caused by: xyz.gianlu.librespot.player.decoders.Decoder$CodecException: No tracks found.
        at xyz.gianlu.librespot.player.decoders.AndroidNativeDecoder.<init>(AndroidNativeDecoder.java:51)
        at java.lang.reflect.Constructor.newInstance0(Native Methodat java.lang.reflect.Constructor.newInstance(Constructor.java:343at xyz.gianlu.librespot.audio.decoders.Decoders.initDecoder(Decoders.java:54at xyz.gianlu.librespot.player.playback.PlayerQueueEntry.load(PlayerQueueEntry.java:140at xyz.gianlu.librespot.player.playback.PlayerQueueEntry.run(PlayerQueueEntry.java:271at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641at java.lang.Thread.run(Thread.java:9232021-05-03 20:32:04.325 13829-13934/xyz.gianlu.librespot.android E/x.g.l.p.Player: Failed loading track.
    java.io.UnsupportedEncodingException: VORBIS
        at xyz.gianlu.librespot.player.playback.PlayerQueueEntry.load(PlayerQueueEntry.java:142)
        at xyz.gianlu.librespot.player.playback.PlayerQueueEntry.run(PlayerQueueEntry.java:271)
        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:923)
2021-05-03 20:32:04.325 13829-13866/xyz.gianlu.librespot.android D/AudioTrack: stop(73): called with 0 frames delivered

@devgianlu
Copy link
Copy Markdown
Owner Author

@mitschwimmer What are you trying to play?

@mitschwimmer
Copy link
Copy Markdown
Collaborator

Rick as given in the app module.

@devgianlu
Copy link
Copy Markdown
Owner Author

Is there anything more in the logs coming directly from the extractor? Also, could you try playing something else?

@mitschwimmer
Copy link
Copy Markdown
Collaborator

Played some different URI's but same result. I went through the debugger but only found that there is indeed no track found by the extractor.
I am attaching a log file. I can't seem to relate a message to the extractor but filtering for "audio" shows some messages that might reveal something. I need to leave now but tomorrow I could try to compare the logs between tremolo and mediacodec to see which messages actually differ.
librespot android log 3-5-21.txt

@devgianlu
Copy link
Copy Markdown
Owner Author

I see some

2021-05-03 21:36:34.910 1156-1903/? E/Utils: did not find mime type

But not entirely sure. Will have a closer look when possible. FYI, I tested on Android 6 (Samsung device).

@funtax
Copy link
Copy Markdown
Collaborator

funtax commented May 3, 2021

FYI, I tested on Android 6 (Samsung device).

Yearh you got it down to Android 6?
When I tested librespot-java on Android last year, Android 8+ was required because of Java-Streams or so, happy to see it's working now on a lower version!

With the predefined track it's working on my Android 10-device.
Hope I can find some time tomorrow to check again with other songs.

@mitschwimmer
Copy link
Copy Markdown
Collaborator

It seems to me the issue is somehow related to Android 11. @devgianlu, my suggestion would be to open an issue that this needs fixing. I do not think this should keep you from merging as Android 11 is kind of niche, still.

@devgianlu
Copy link
Copy Markdown
Owner Author

I can try it on Android 11 as my main device runs that.

On merging, I wanted to make an MP3 decoder too since it should be supported already.

@funtax
Copy link
Copy Markdown
Collaborator

funtax commented May 5, 2021

On Android 7, after patching the Base64-stuff, I get this Exception:

E/x.g.l.a.d.Decoders: Failed initializing Codec instance for VORBIS
    java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
        at xyz.gianlu.librespot.audio.decoders.Decoders.initDecoder(Decoders.java:54)
        at xyz.gianlu.librespot.player.playback.PlayerQueueEntry.load(PlayerQueueEntry.java:140)
        at xyz.gianlu.librespot.player.playback.PlayerQueueEntry.run(PlayerQueueEntry.java:271)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
        at java.lang.Thread.run(Thread.java:761)
     Caused by: xyz.gianlu.librespot.player.decoders.Decoder$CodecException: No tracks found.
        at xyz.gianlu.librespot.player.decoders.AndroidNativeDecoder.<init>(AndroidNativeDecoder.java:51)
        at java.lang.reflect.Constructor.newInstance0(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
        at xyz.gianlu.librespot.audio.decoders.Decoders.initDecoder(Decoders.java:54) 
        at xyz.gianlu.librespot.player.playback.PlayerQueueEntry.load(PlayerQueueEntry.java:140) 
        at xyz.gianlu.librespot.player.playback.PlayerQueueEntry.run(PlayerQueueEntry.java:271) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
        at java.lang.Thread.run(Thread.java:761) 
E/x.g.l.p.Player: Failed loading track.
    java.io.UnsupportedEncodingException: VORBIS
        at xyz.gianlu.librespot.player.playback.PlayerQueueEntry.load(PlayerQueueEntry.java:142)
        at xyz.gianlu.librespot.player.playback.PlayerQueueEntry.run(PlayerQueueEntry.java:271)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)

With libtremolo it seems to work fine.

@devgianlu
Copy link
Copy Markdown
Owner Author

Mhh, guess this is quite common. I'll make some changes so that if a decoder doesn't manage to initialize, it'll try the next one.

devgianlu added a commit to librespot-org/librespot-java that referenced this pull request May 5, 2021
@devgianlu
Copy link
Copy Markdown
Owner Author

@funtax @mitschwimmer Should work everywhere now.

@mitschwimmer
Copy link
Copy Markdown
Collaborator

Hm, could you add logging? Right now it is hard to see which decoder is in use. Under which circumstances would it be the Android Native vorbis decoder?

devgianlu added a commit to librespot-org/librespot-java that referenced this pull request May 5, 2021
@devgianlu
Copy link
Copy Markdown
Owner Author

They are "evaluated" in this order:

  • (if ARM) TremoloVorbisDecoder
  • AndroidNativeDecoder
  • built-in librespot-java decoder

I have also added the decoder name to the logs.

@devgianlu devgianlu merged commit ef1e5cd into master May 5, 2021
@devgianlu devgianlu deleted the android-decoder branch May 5, 2021 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Android native decoders

3 participants