google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.7k stars 6.01k forks source link

Stuttering audio when playing downloaded, encrypted dash content #10682

Open ericharlow opened 1 year ago

ericharlow commented 1 year ago

ExoPlayer Version

2.18.1

Devices that reproduce the issue

Samsung S7 edge running Android 8 Moto g power running Android 11

Devices that do not reproduce the issue

Samsung s9 running Android 10 Samsung s10+ running Android 11 Pixel 4a running Android 13

Reproducible in the demo app?

Not tested

Reproduction steps

When playing downloaded audio at a speed greater than 1.0x and the device screen is off. After a few seconds audio stuttering will start to happen. I didn't test this in the demo app since background audio playback is not supported there, But I did put together a sample project using media from the demo app to reproduce the issue. The sample project can be found at https://github.com/ericharlow/AndroidAudioStutteringExample.

The sample app will download and then start playback of the content. Once playback starts, simply turn the screen off and wait a few seconds to 30 seconds for the stuttering to begin.

Any recommendations on how to stop the stuttering?

Expected result

Audio playing in the background does not stutter.

Actual result

Audio playing in the background does stutter and audio buffer underruns are observed.

Media

I pulled media from the demo app.

https://storage.googleapis.com/wvmedia/cenc/h264/tears/tears.mpd https://proxy.uat.widevine.com/proxy?video_id=2015_tears&provider=widevine_test

Bug Report

icbaker commented 1 year ago

It looks like in your example app you're continuing to decrypt and decode the video in tha background (at least, i didn't spot any logic to disable the video track when going into the background). Is it possible this is too much load for the device? Does the problem still reproduce if you disable the video track when you're playing in the background? This will save all the computation resources currently being used to load this track over the network, decrypt it's DRM and then decode the actual video frames.

ericharlow commented 1 year ago

@icbaker Thanks for the response. I disabled the video track and I am still able to reproduce the issue.

What else should I try?

ericharlow commented 1 year ago

@icbaker Do you need any more info from me on this?

icbaker commented 1 year ago

Given this is device-specific, and I don't have access to either of the mentioned devices, I'm afraid there's very little additional support I can offer.

Do I understand correctly that it only happens when changing playback speed? Does it happen when playing slower than 1x as well as faster?

Is the audio track encrypted as well? It's possible that calls to MediaCodec.queueSecureInputBuffer are taking a long time, and causing the underruns you're seeing. You could try forcing async queueing to see if that mitigates things: https://exoplayer.dev/customization.html#enabling-asynchronous-buffer-queueing

ericharlow commented 1 year ago

That is correct. It happens when playback speed has been set to a value greater than 1.0x and it does not happen when playing at slower speeds like 0.5x or 1.0x.

The audio track is encrypted. I just added a call to forceEnableMediaCodecAsynchronousQueueing() on DefaultRenderersFactory, but that didn't stop the stuttering.

ericharlow commented 1 year ago

I have discovered if I hold onto a FULL_WAKE_LOCK, SCREEN_DIM_WAKE_LOCK, or a SCREEN_BRIGHT_WAKE_LOCK that the stuttering doesn't occur. This isn't a fix as it drains the devices battery and can be circumvented by the user tapping the power button on the device. But does this shed any light on where the issue might be?