Error on changing to/from some audio tracks after upgrade to Android 8
Issue description
After upgrade to official realease of Android 8 on Nvidia Shield TV 2017 switching to/from some audio tracks causes an error. Always worked flawless on all previous Android versions. All tracks plays through audio passthrough to Pioneer AVR. For example, switching from AC3 383 kb/s to AC3 484 kb/s audio track finished with error. Switching between AC3 383 kb/s tracks is ok.
Reproduction steps
Start video playback and then switch to some specific audio track.
Version of ExoPlayer being used
2.8.1
Device(s) and version(s) of Android being used
Nvidia Shield TV 2017 with Android 8
A full bug report captured from the device
06-29 00:44:34.630 466-1141/? I/OMXMaster: makeComponentInstance(OMX.google.raw.decoder) in android.hardwar process
06-29 00:44:34.636 466-1199/? E/OMXNodeInstance: setConfig(0x4be23200:google.raw.decoder, ConfigPriority(0x6f800002)) ERROR: Undefined(0x80001001)
06-29 00:44:34.636 9033-15635/com.name.app I/ACodec: codec does not support config priority (err -2147483648)
06-29 00:44:34.637 466-1141/? E/OMXNodeInstance: getConfig(0x4be23200:google.raw.decoder, ConfigAndroidVendorExtension(0x6f100004)) ERROR: Undefined(0x80001001)
06-29 00:44:34.646 454-500/? I/NvAudioPolicyManager: getOutputForAttr() device 0x400, samplingRate 48000, format 9000000, channelMask 3f, flags 1 strategy 0x0
06-29 00:44:34.646 454-500/? W/APM_AudioPolicyManager: getOutput() could not find output for stream 3, samplingRate 48000,format 150994944, channels 3f, flags 1
06-29 00:44:34.646 9033-15588/com.name.app E/AudioTrack: Could not get audio output for session 417, stream type -1, usage 1, sample rate 48000, format 0x9000000, channel mask 0x3f, flags 0x1
06-29 00:44:34.647 9033-15588/com.name.app E/AudioTrack-JNI: Error -22 initializing AudioTrack
06-29 00:44:34.647 9033-15588/com.name.app E/android.media.AudioTrack: Error code -20 when initializing AudioTrack.
06-29 00:44:34.648 9033-15588/com.name.app E/ExoPlayerImplInternal: Playback error.
com.google.android.exoplayer2.ExoPlaybackException
at com.google.android.exoplayer2.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:535)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:1088)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:573)
at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:518)
at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:301)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: com.google.android.exoplayer2.audio.AudioSink$InitializationException: AudioTrack init failed: 0, Config(48000, 252, 20480)
at com.google.android.exoplayer2.audio.DefaultAudioSink.initializeAudioTrack(DefaultAudioSink.java:1130)
at com.google.android.exoplayer2.audio.DefaultAudioSink.initialize(DefaultAudioSink.java:561)
at com.google.android.exoplayer2.audio.DefaultAudioSink.handleBuffer(DefaultAudioSink.java:617)
at com.google.android.exoplayer2.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:529)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:1088)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:573)
at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:518)
at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:301)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
06-29 00:44:34.650 466-15597/? D/NvOsDebugPrintf: NVMEDIA: NVMEDIAFrameStatusReporting: 1807: Closing NVMEDIA Frame Status Thread -------------
06-29 00:44:34.650 466-15598/? D/NvOsDebugPrintf: NVMEDIA: NVMEDIAVPRFloorSizeSettingThread: 1628: Closing NVMEDIAVPRFloorSizeSettingThread -------------
06-29 00:44:34.650 466-15596/? D/NvOsDebugPrintf: NVMEDIA: NVMEDIAFrameDelivery: 1662: Closing NVMEDIA Frame Delivery Thread -------------
06-29 00:44:34.668 466-15593/? D/NvOsDebugPrintf: NVMEDIA: NvMMLiteTVMRDecBlockClose: 3345: Done
06-29 00:44:34.670 9033-15591/com.name.app D/SurfaceUtils: disconnecting from surface 0x21958d1010, reason disconnectFromSurface
06-29 00:44:34.705 9033-9033/com.name.app I/ExoPlayerImpl: Release 5468831 [ExoPlayerLib/2.8.1] [darcy, SHIELD Android TV, NVIDIA, 26] [goog.exo.core, goog.exo.hls]
- By "switching" do you mean adding a track selection override that disables/re-enables the renderer, or an adaptive switch, or something else?
- If you just play the 484 kb/s track (without switching) does it work?
- Was this a regression after the system update, or did anything else change too (e.g., ExoPlayer version)?
- It would be useful to have a full bug report (
adb bugreport) and a link to the media you're trying to play.
- Yes, "switching" means setting specific audio track by setting track selection override.
TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter());
DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackSelectionFactory);
...
DefaultTrackSelector.SelectionOverride override = tracks == null ? null :
new DefaultTrackSelector.SelectionOverride(alAudioTracksIndices.get(index), tracks);
DefaultTrackSelector.ParametersBuilder parametersBuilder = trackSelector.buildUponParameters();
if (override != null) {
parametersBuilder.setSelectionOverride(audioRenderedIndex, trackGroups, override);
} else {
parametersBuilder.clearSelectionOverrides(audioRenderedIndex);
}
trackSelector.setParameters(parametersBuilder);
-
If just play 448 kb/s right away, then there is error when switching to any other 384 kb/s track.
-
Nothing was changed, but Nvidia Shield TV upgraded to Android 8 (Firmware SW version 7.0.2).
-
Will prepare and send you a bug report and video sample.
@andrewlewis
- Do we need to run
adb bugreportduring the issue or right after the issue's happened? - Do you need all the files from report or only some specific?
- Right after reproducing the issue would be good. Thanks!
- It would be easiest just to include the whole report, but some specific bits that may be useful are the system logs, kernel logs and dumpsys for the audio flinger.
@andrewlewis sent you a bug report and two sample videos.
The workaround is to disable audio renderer before switching audio track (settings track selection override) and then enable audio renderer after 100-500ms. Timeout of 5-50ms could not be enough.
@andrewlewis any news on the issue? I'd add, it happens both when Nvidia Shield TV connected through AVR or directly to TV (Sony Bravia).
I was able to reproduce this using the demo app on NVIDIA/foster_e_hdd/foster:8.0.0/OPR6.170623.010/3019194_1174.8512:user/release-keys with the first sample you sent over, when switching from 'English, Surround sound' to 'Russian, Surround sound'. It looks like a platform issue so I've filed [internal: b/111744359] and will follow up with any updates.
Note: tentatively marking as a platform bug, as I was able to reproduce this on a Nexus Player running Oreo too.
Saw this on a different hardware running 8.0.
In my case - I'm switching from playing content 1 that has different AudioTrack profile to another with a different profile
08-12 16:45:23.696 4250-5240/com.example.company.testatv E/AudioTrack: Could not get audio output for session 65, stream type -1, usage 1, sample rate 48000, format 0x1, channel mask 0x3, flags 0x41
08-12 16:45:23.696 4250-5240/com.example.company.testatv E/AudioTrack-JNI: Error -22 initializing AudioTrack
08-12 16:45:23.696 4250-5240/com.example.company.testatv E/android.media.AudioTrack: Error code -20 when initializing AudioTrack.
08-12 16:45:23.697 6226-6226/? I/netcoal: set-eth0: ro.nx.eth.tx_frames=256, ro.nx.eth.rx_frames=256, ro.nx.eth.rx_usecs=4096
irq 131 affinity: 0xf->0xc
08-12 16:45:23.698 6226-6226/? I/netcoal: irq 132 affinity: 0xf->0xc
08-12 16:45:23.708 4250-5240/com.example.company.testatv E/ExoPlayerImplInternal: Playback error.
com.google.android.exoplayer2.ExoPlaybackException
at com.google.android.exoplayer2.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:535)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:1145)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:604)
at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:518)
at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:301)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: com.google.android.exoplayer2.audio.AudioSink$InitializationException: AudioTrack init failed: 0, Config(48000, 12, 48000)
at com.google.android.exoplayer2.audio.DefaultAudioSink.initializeAudioTrack(DefaultAudioSink.java:1130)
at com.google.android.exoplayer2.audio.DefaultAudioSink.initialize(DefaultAudioSink.java:561)
at com.google.android.exoplayer2.audio.DefaultAudioSink.handleBuffer(DefaultAudioSink.java:617)
at com.google.android.exoplayer2.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:529)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:1145)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:604)
at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:518)
at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:301)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
The root cause of this issue seems to be that audio tracks may retain some resources even after AudioTrack.release() has returned.
We might work around this by retrying AudioTrack creation if it fails. [Internal: b/122356421]
@andrewlewis What's the plan/status for this issue, can I ask what does it mean by [Internal: b/122356421]. Somewhere we can track the progress?
@andrewlewis What's the plan/status for this issue, can I ask what does it mean by [Internal: b/122356421]. Somewhere we can track the progress?
I'm afraid this is not a publicly visible issue, but there is no ongoing work tracked there so it is not really relevant any more.
@krocard What is the status of AudioTrack recovery? Do you think it will address this issue? Thanks.
@krocard What is the status of AudioTrack recovery? Do you think it will address this issue? Thanks.
No it will not as it only tries to recover if the AudioTrack fails with the specific error DEAD_OBJECT that is return when it needs to be recreated. In this case, there is no error code indicating the track needs recreation. Plus here a delay needs to be introduced.
I have created [internal: b/167682058] to track the enhancement of retrying to create the AudioTrack after a short time if it fails to be built/init. I'm thinking of retrying with an exponential backoff (10ms, 20, 40...) and then give up when it would become noticeable to the user (eg 100ms).
Audio track retry has been implemented in ExoPlayer ~v2.12.0~ and will be release in v2.13*. ExoPlayer will now attempt to recreate a track after it fails to be created for 100ms. Please reopen if your issue is not fixed.
- EDIT: see https://github.com/google/ExoPlayer/issues/4448#issuecomment-707061435
Hello, which one refers to the submission record for solving this problem?
If by "submission record" you mean the commit that implements the retry, there it is: https://github.com/google/ExoPlayer/commit/7dfdde9246b28ad977ebe712e485033ee688652d.
Nevertheless, the commit is not part of v2.12 as I though and have previously witten. It was merged after the branch cut. Thus it will be part of the next release 2.13.0 that should be published at the beginning of next year.
Sorry for the confusion.
Thank you for your answer, I will try to solve it according to your ideas
Hello, the solution you provided, the method of not throwing an exception within 100ms and retrying does not solve this problem. Our data statistics still have such error messages. Do I need to modify others? In addition to this submission
If AudioTrack still fails to be created with https://github.com/google/ExoPlayer/commit/7dfdde9246b28ad977ebe712e485033ee688652d applied, aka you are still seeing the error
AudioSink$InitializationException: AudioTrack init failed:, you can try to increase the AUDIO_TRACK_RETRY_DURATION_MS timeout (from 100ms to 500ms for example as you suggested in https://github.com/google/ExoPlayer/issues/4448#issuecomment-403636214).
Additionally, you should test that you correctly applied the patch by checking that the AudioSink$InitializationException: AudioTrack init failed: error is thrown 100ms after the first W/APM_AudioPolicyManager: getOutput() could not find output for stream error.
If the error still occurs after that, please send us a bug report of the error with the patch applied.