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

Silence Skipping Audio Processor Exceptions #1352

Closed
1 task
dabluck opened this issue May 8, 2024 · 7 comments
Closed
1 task

Silence Skipping Audio Processor Exceptions #1352

dabluck opened this issue May 8, 2024 · 7 comments
Assignees

Comments

@dabluck
Copy link

dabluck commented May 8, 2024

Version

Media3 1.3.1

More version details

This is still in 1.3.1. I believe it was either a new issue in 1.3 or it became much worse after 1.3

Devices that reproduce the issue

Android 14, several manufacturers

Devices that do not reproduce the issue

I attached firebase screenshot.

Reproducible in the demo app?

Not tested

Reproduction steps

This happens during playlist transitions. I see it in production data and reports from users. I've definitely had it happen but can't reproduce easily or 100%

Caused by java.lang.IllegalArgumentException: sizeToOutput is not aligned to frame size: 8466
       at androidx.media3.common.util.Assertions.checkArgument(Assertions.java:55)
       at androidx.media3.exoplayer.audio.SilenceSkippingAudioProcessor.outputSilence(SilenceSkippingAudioProcessor.java:632)
       at androidx.media3.exoplayer.audio.SilenceSkippingAudioProcessor.outputShortenedSilenceBuffer(SilenceSkippingAudioProcessor.java:471)
       at androidx.media3.exoplayer.audio.SilenceSkippingAudioProcessor.onQueueEndOfStream(SilenceSkippingAudioProcessor.java:302)
       at androidx.media3.common.audio.BaseAudioProcessor.queueEndOfStream(BaseAudioProcessor.java:68)
       at androidx.media3.common.audio.AudioProcessingPipeline.processData(AudioProcessingPipeline.java:327)
       at androidx.media3.common.audio.AudioProcessingPipeline.getOutput(AudioProcessingPipeline.java:229)
       at androidx.media3.exoplayer.audio.DefaultAudioSink.processBuffers(DefaultAudioSink.java:1110)
       at androidx.media3.exoplayer.audio.DefaultAudioSink.drainToEndOfStream(DefaultAudioSink.java:1139)
       at androidx.media3.exoplayer.audio.DefaultAudioSink.handleBuffer(DefaultAudioSink.java:890)
       at androidx.media3.exoplayer.audio.MediaCodecAudioRenderer.processOutputBuffer(MediaCodecAudioRenderer.java:743)
       at androidx.media3.exoplayer.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:2010)
       at androidx.media3.exoplayer.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:827)
       at androidx.media3.exoplayer.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:1102)
       at androidx.media3.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:541)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loopOnce(Looper.java:224)
       at android.os.Looper.loop(Looper.java:318)
       at android.os.HandlerThread.run(HandlerThread.java:67)

I get this exception in production sporadically, and it causes audio to stop playback. It only happens when transitioningg from
playlist item to another. Disabling the silence skipper resolves it, so I'm fairly positive that is the cause. Here is my RendererFactory


    override fun buildAudioSink(
        context: Context,
        enableFloatOutput: Boolean,
        enableAudioTrackPlaybackParams: Boolean,
    ): AudioSink? {
        val mySilenceSkippingProcessor = SilenceSkippingAudioProcessor(
                    DEFAULT_MINIMUM_SILENCE_DURATION_US * 2,
                    DEFAULT_PADDING_SILENCE_US * 5,
                    (DEFAULT_SILENCE_THRESHOLD_LEVEL / 2).toShort()
)

        val chain = DefaultAudioSink.DefaultAudioProcessorChain(
            emptyArray(),
            mySilenceSkippingProcessor,
            SonicAudioProcessor()
        )

        val sink = DefaultAudioSink.Builder(context)
            .setEnableFloatOutput(enableFloatOutput)
            .setAudioOffloadSupportProvider(DefaultAudioOffloadSupportProvider(context))
            .setEnableAudioTrackPlaybackParams(enableAudioTrackPlaybackParams)
            .setAudioProcessorChain(chain)
            .build()
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            sink.setOffloadMode(OFFLOAD_MODE_ENABLED_GAPLESS_NOT_REQUIRED)
        }
        return sink
    }


Only happens on Android 14
Screenshot 2024-05-07 at 10 10 08 PM

Expected result

Exception should not be thrown, and playlist transition should occur

Actual result

Exception is thrown and playback stops

Media

My app is a podcast app. I don't have a particular audio file

Bug Report

  • You will email the zip file produced by adb bugreport to [email protected] after filing this issue.
@icbaker
Copy link
Collaborator

icbaker commented May 8, 2024

Assigning to @tonihei as the author of dfe4721

@tonihei
Copy link
Collaborator

tonihei commented May 10, 2024

Thanks for reporting. I can reproduce a very similar issue, but not exactly the same one. I believe they both have the same root cause though and the exact manifestation depends on the media files and their silences.

The problem is that SilenceSkippingAudioProcessor updates its internal value for the current format too early (where it should have relied on the existing handling in the base class). This causes issues where the audio format changes, e.g. from stereo to mono. Not sure how well you can see or check the properties of the media items you transition between in the error cases, but I guess these issues happen in cases where the channel count of the media is different.

@dabluck
Copy link
Author

dabluck commented May 10, 2024

Thanks for getting back to me @tonihei I could check the media formats if necessary, but basically any media file could show up in an RSS feed.

Is there a workaround you suggest?

@tonihei
Copy link
Collaborator

tonihei commented May 10, 2024

I'm about to submit a fix, but don't know a good workaround for the existing code (except to disable silence skipping shortly before the transition)

@dabluck
Copy link
Author

dabluck commented May 10, 2024

Thanks for getting to it so quickly.

copybara-service bot pushed a commit that referenced this issue May 13, 2024
The class currently tracks the input format itself, updating it too
early in onConfigure() instead of onFlush(). This causes issues when
the format changes and the new values are applied to the silence
skipping logic of the old format. The fix is to use the base class
input format handling instead.

Issue: #1352
PiperOrigin-RevId: 633232368
@tonihei tonihei closed this as completed May 14, 2024
@aljohnston112
Copy link

What release will the fix be in?

@tonihei
Copy link
Collaborator

tonihei commented May 23, 2024

The upcoming 1.4.0 releases (starting with 1.4.0-alpha02 later this week or next week)

@androidx androidx locked and limited conversation to collaborators Jul 14, 2024
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

4 participants