amzn / exoplayer-amazon-port

Official port of ExoPlayer for Amazon devices
Apache License 2.0
173 stars 80 forks source link

Switching to Bluetooth headset during playback fails when using Dolby audio content #52

Open nahojkap opened 6 years ago

nahojkap commented 6 years ago

When using SmoothStreaming content with Dolby audio (protected with PlayReady DRM) and connecting a previously paired Bluetooth headset during playback will cause a write exception in the AudioTrack.

Playback works as expected when non-Dolby content is used. Playback is also OK when starting playback with the headset connected already.

Platform Information

Toshiba 43-inch 4K Ultra HD Smart LED TV with HDR - Fire TV Edition (43LF621U19) AFTKMST12/keira/25/Amazon 7.1.2 (25) - Linux/3.10.86/armv8l CPU Vendor: Maxim

08-31 05:37:27.305 4555 5027 E ExoPlayerImplInternal: Playback error: com.google.android.exoplayer2.ExoPlaybackException 08-31 05:37:27.305 4555 5027 E ExoPlayerImplInternal: at com.google.android.exoplayer2.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:573) 08-31 05:37:27.305 4555 5027 E ExoPlayerImplInternal: at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:1214) 08-31 05:37:27.305 4555 5027 E ExoPlayerImplInternal: at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:614) 08-31 05:37:27.305 4555 5027 E ExoPlayerImplInternal: at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:535) 08-31 05:37:27.305 4555 5027 E ExoPlayerImplInternal: at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:303) 08-31 05:37:27.305 4555 5027 E ExoPlayerImplInternal: at android.os.Handler.dispatchMessage(Handler.java:98) 08-31 05:37:27.305 4555 5027 E ExoPlayerImplInternal: at android.os.Looper.loop(Looper.java:154) 08-31 05:37:27.305 4555 5027 E ExoPlayerImplInternal: at android.os.HandlerThread.run(HandlerThread.java:61) 08-31 05:37:27.305 4555 5027 E ExoPlayerImplInternal: Caused by: com.google.android.exoplayer2.audio.AudioSink$WriteException: AudioTrack write failed: -6 08-31 05:37:27.305 4555 5027 E ExoPlayerImplInternal: at com.google.android.exoplayer2.audio.DefaultAudioSink.writeBuffer(DefaultAudioSink.java:869) 08-31 05:37:27.305 4555 5027 E ExoPlayerImplInternal: at com.google.android.exoplayer2.audio.DefaultAudioSink.handleBuffer(DefaultAudioSink.java:756) 08-31 05:37:27.305 4555 5027 E ExoPlayerImplInternal: at com.google.android.exoplayer2.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:562) 08-31 05:37:27.305 4555 5027 E ExoPlayerImplInternal: ... 7 more

Attaching full stacktrace.

nahojkap commented 6 years ago

playback-with-dolby-fails.txt

peddisri commented 6 years ago

Thank you for reporting. This patch is supposed to handle switching between dolby and non-dolby content. We'll investigate this.

nahojkap commented 6 years ago

I have also tested this on the Amazon FireTV 4K Ultra HD and it fails with the same issue.

nahojkap commented 6 years ago

For what it is worth, playback works fine if the headset is connected before playback. It will then also allow you to turn the headset off during playback and audio will correctly switch to normal output.

peddisri commented 6 years ago

We found the root cause and are working on it. There will be two parts to it. One in the OS that will updated in the next system release cycle. One in Exo.

nahojkap commented 6 years ago

Great, thanks for the update.

peddisri commented 6 years ago

Fixed in https://github.com/amzn/exoplayer-amazon-port/commit/2ce7930bf834edbf2aa3de1cb8e445f6625d95c3

Currently, you need to wait for OS update also for this patch to get affect. If you want to test with existing OS, return true in useSurroundSoundFlagV17 function of AudioCapabilities.java

nahojkap commented 6 years ago

Thanks for the quick turn-around - any indication of when the OS update will be rolling out?

peddisri commented 6 years ago

This will be rolled out around end of Feb 2019.

msilva-verimatrix commented 4 years ago

Hi, The same behavior is observable in an Amazon Fire TV Stick 4K (2018) https://developer.amazon.com/docs/fire-tv/device-specifications-fire-tv-stick.html?v=ftvstick4k when using the latest ExoPlayer 2.10.6, even after forcing useSurroundSoundFlagV17() to return 'true' in AudioCapabilities.java: ... 2019-12-17 14:13:05.894 8246-8538/com.insidesecure.drm.android.reference.xoplayer E/AudioTrack-JNI: Error -32 during AudioTrack native read 2019-12-17 14:13:05.896 8246-8538/com.insidesecure.drm.android.reference.xoplayer E/ExoPlayerImplInternal: Playback error. com.insidesecure.android.exoplayer.ExoPlaybackException: com.insidesecure.android.exoplayer.audio.AudioSink$WriteException: AudioTrack write failed: -6 at com.insidesecure.android.exoplayer.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:776) at com.insidesecure.android.exoplayer.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:1614) at com.insidesecure.android.exoplayer.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:681) at com.insidesecure.android.exoplayer.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:591) at com.insidesecure.android.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:328) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:154) at android.os.HandlerThread.run(HandlerThread.java:61) Caused by: com.insidesecure.android.exoplayer.audio.AudioSink$WriteException: AudioTrack write failed: -6 at com.insidesecure.android.exoplayer.audio.DefaultAudioSink.writeBuffer(DefaultAudioSink.java:834) at com.insidesecure.android.exoplayer.audio.DefaultAudioSink.handleBuffer(DefaultAudioSink.java:721) at com.insidesecure.android.exoplayer.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:765) at com.insidesecure.android.exoplayer.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:1614)  at com.insidesecure.android.exoplayer.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:681)  at com.insidesecure.android.exoplayer.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:591)  at com.insidesecure.android.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:328)  ... Updating the device OS version to the latest (Fire OS 6.2.6.8 (NS6268/2315)) did not help. Thanks,

Moacir

msilva-verimatrix commented 4 years ago

Hi, Do you have any updates regarding the OS update related to this issue? Thanks,

Moacir