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

E/MediaCodecVideoRenderer: Video codec error #9476

Closed
KostyaLyapochkin opened this issue Sep 23, 2021 · 6 comments
Closed

E/MediaCodecVideoRenderer: Video codec error #9476

KostyaLyapochkin opened this issue Sep 23, 2021 · 6 comments
Assignees
Labels

Comments

@KostyaLyapochkin
Copy link

KostyaLyapochkin commented Sep 23, 2021

Hello. I've stuck with this error. Full description:

E/ExoPlayerImplInternal: Playback error
      com.google.android.exoplayer2.ExoPlaybackException: MediaCodecVideoRenderer error, index=0, format=Format(4, null, null, video/avc, avc1.64002A, 18320008, null, [1920, 856, 24.0], [-1, -1]), format_supported=YES
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:558)
        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.google.android.exoplayer2.mediacodec.MediaCodecRenderer$DecoderInitializationException: Decoder init failed: OMX.Exynos.avc.dec.secure, Format(4, null, null, video/avc, avc1.64002A, 18320008, null, [1920, 856, 24.0], [-1, -1])
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecWithFallback(MediaCodecRenderer.java:1034)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecOrBypass(MediaCodecRenderer.java:585)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.reinitializeCodec(MediaCodecRenderer.java:2142)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.processEndOfStream(MediaCodecRenderer.java:2017)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:1848)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:823)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:978)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:482)
        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: java.lang.IllegalArgumentException: The surface has been released
        at android.media.MediaCodec.native_configure(Native Method)
        at android.media.MediaCodec.configure(MediaCodec.java:1882)
        at com.google.android.exoplayer2.mediacodec.SynchronousMediaCodecAdapter$Factory.createAdapter(SynchronousMediaCodecAdapter.java:50)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.initCodec(MediaCodecRenderer.java:1121)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecWithFallback(MediaCodecRenderer.java:1027)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecOrBypass(MediaCodecRenderer.java:585) 
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.reinitializeCodec(MediaCodecRenderer.java:2142) 
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.processEndOfStream(MediaCodecRenderer.java:2017) 
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:1848) 
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:823) 
        at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:978) 
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:482) 
        at android.os.Handler.dispatchMessage(Handler.java:98) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.os.HandlerThread.run(HandlerThread.java:61) 

Shortly speaking, A VideoService holds my player inside to support background playing that is when an application is in the background. When the application goes to the background mode ad must play. When player intents to change source in the background mode I have this error. I think that it can be similar with this issue #8776 which had been fixed.

https://github.com/KostyaLyapochkin/ExoPlayerErrorExample - I've pushed new commit with tag #9476.
Please, Take a look.

@icbaker
Copy link
Collaborator

icbaker commented Sep 23, 2021

Thanks for the repro project. I tried it on a Pixel 5 and backgrounded the app a few times during both ad and content playback and didn't see any failures.

Are there more specific repro steps I should be taking?

What device(s) do you see this problem on?

Could you capture an adb bugreport immediately after reproducing and either upload it here or send to [email protected] using a subject in the format Issue #1234 (where #1234 should be replaced with this issue number.) Please also update this issue to indicate you’ve done this.

@KostyaLyapochkin
Copy link
Author

KostyaLyapochkin commented Sep 23, 2021

@icbaker Oh, sorry I've forgotten to specify list of devices. Pixels and Android Emulators work perfectly as usual but I have this issue on Pixel 2 XL( Android 10), Xiaomi Redmi note 7 Pro 10 (Android 10), Galaxy Tab S2 SM-T810 (Android 7), Galaxy S8 (Android 9).

bugreport-2021-09-23-18-05-08.zip

I can record a video if you need.

@icbaker
Copy link
Collaborator

icbaker commented Sep 23, 2021

I can record a video if you need.

That would be really helpful, just so i can understand exactly when the failure happens.

Thanks!

@KostyaLyapochkin
Copy link
Author

20210924_092214.mp4

@icbaker
Copy link
Collaborator

icbaker commented Sep 28, 2021

Thanks for the video, I didn't realise you were waiting for the ads to fully play out while the app was in the background. I'm now able to reproduce a failure on both a Pixel 5 and a OnePlus AC2003 by:

  1. Opening the app, the ad starts playing
  2. Background the app, the ad audio is still audible
  3. Wait for the ad audio to stop playing (and the error appears in the logcat here)
  4. Re-foreground the app and the content doesn't play.

Turns out there's another bug in MediaCodecVideoRenderer - similar to #8776 as you say. Basically the fix for that issue missed a possible combination of events:

  • If we're currently using the dummy surface (e.g. because the app is in the background) then this.dummySurface == this.surface.
  • And then if we realise we need a new DummySurface because we're switching to secure content
    • Then the fix for 8776 nulls out dummySurface and releases it
    • But this.surface is still pointing to the old, released surface instance.
  • The fix is to null out surface as well if surface == dummySurface.

I've sent a fix for this, it should be linked below shortly.

As a workaround I was able to make things work on a Pixel 5 by calling MediaItem.Builder#setDrmSessionForClearPeriods(true). This works because the dummy surface is configured to be secure from the beginning, so we never need to reinstantiate it. However it resulted in a different error on the OnePlus - the same as #8696:

2021-09-27 12:28:50.156 10764-14693/com.example.exoplayererrorcodecsample D/SurfaceUtils: connecting to surface 0xb400007c989b6d00, reason connectToSurface
2021-09-27 12:28:50.156 10764-14693/com.example.exoplayererrorcodecsample E/BufferQueueProducer: [SurfaceTexture-1-10764-0](id:2a0c00000000,api:3,p:10764,c:10764) connect: already connected (cur=3 req=3)
2021-09-27 12:28:50.156 10764-14693/com.example.exoplayererrorcodecsample E/SurfaceUtils: Failed to connect to surface 0xb400007c989b6d00, err -22
2021-09-27 12:28:50.156 10764-14693/com.example.exoplayererrorcodecsample E/MediaCodec: nativeWindowConnect returned an error: Invalid argument (-22)
2021-09-27 12:28:50.156 10764-14503/com.example.exoplayererrorcodecsample E/MediaCodec: configure failed with err 0xffffffea, resetting...
2021-09-27 12:28:50.163 10764-14694/com.example.exoplayererrorcodecsample I/OMXClient: IOmx service obtained
2021-09-27 12:28:50.179 10764-14628/com.example.exoplayererrorcodecsample D/SurfaceUtils: disconnecting from surface 0xb400007c989b28e0, reason pushBlankBuffersToNativeWindow
2021-09-27 12:28:50.185 10764-14503/com.example.exoplayererrorcodecsample W/MediaCodecRenderer: Failed to initialize decoder: OMX.qcom.video.decoder.avc.secure
      java.lang.IllegalArgumentException
        at android.media.MediaCodec.native_configure(Native Method)
        at android.media.MediaCodec.configure(MediaCodec.java:2128)
        at android.media.MediaCodec.configure(MediaCodec.java:2044)
        at com.google.android.exoplayer2.mediacodec.SynchronousMediaCodecAdapter$Factory.createAdapter(SynchronousMediaCodecAdapter.java:50)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.initCodec(MediaCodecRenderer.java:1121)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecWithFallback(MediaCodecRenderer.java:1027)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecOrBypass(MediaCodecRenderer.java:585)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.reinitializeCodec(MediaCodecRenderer.java:2142)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.processEndOfStream(MediaCodecRenderer.java:2017)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.drainOutputBuffer(MediaCodecRenderer.java:1848)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:823)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:978)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:482)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:245)
        at android.os.HandlerThread.run(HandlerThread.java:67)

marcbaechinger pushed a commit that referenced this issue Sep 28, 2021
The fix for Issue: #8776 was to release and null-out dummySurface if
it doesn't match the security level of the decoder. But it's possible
that this.surface is already set to this.dummySurface, in which case we
must also null out this.surface otherwise we will later try and re-use
the old, released DummySurface instance.

This logic already exists in MCVR#onReset, so I pulled it into a
releaseDummySurface() helper function.

Issue: #9476
#minor-release
PiperOrigin-RevId: 399420476
@icbaker icbaker closed this as completed Sep 30, 2021
@KostyaLyapochkin
Copy link
Author

KostyaLyapochkin commented Oct 18, 2021

@icbaker Hi. setDrmSessionForClearPeriods(true) - workaround has helped me, on the one hand it's pretty restricted solution because when VAST contains webm format, so IMA SDK can return this format for playing, for instance, Samsung devices do not select secure decoder for playing webm format (OMX.Exynos.vp8.dec) as a result I am stuck with the same error. On the other hand Sony F3112 Android 7 uses OMX.MTK.VIDEO.DECODER.AVC with mp4 it means that setDrmSessionForClearPeriods does not help at all.

@google google locked and limited conversation to collaborators Nov 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants