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

native_window_set_buffer_count failed: Invalid argument #6930

Closed
shobanavelmurugan opened this issue Jan 29, 2020 · 16 comments
Closed

native_window_set_buffer_count failed: Invalid argument #6930

shobanavelmurugan opened this issue Jan 29, 2020 · 16 comments
Assignees

Comments

@shobanavelmurugan
Copy link

ExoPlayer-2.11.1: ExoPlayerImplInternal: Internal runtime error. java.lang.IllegalArgumentException at android.media.MediaCodec.native_setSurface:

Now i am using the Exo player 2.11.1. i recorded the video for around 30-mins in landscape and previewed in landscape(The orientationlistener moves activity from portrait to landscape for preview ) .At times in preview activity the player event triggers onPlayerError() and the screen goes blank in android OS 10.
Note: We are recording and previewing the video in loop (eg: 10 videos)
Device.Samsug Galaxy S10

Searched documentation and issues

Getting sometimes an ExoPlayerImplInternal: IllegalArgumentException #6346

Why ExoPlayer in Android OS-10 shows black preview screen while preview

ExoPlayerImplInternal: Internal runtime error #6750

Why can't remove playview from its parent or call clearSurface in 2.8.1 #4335

Can't use Surface if it was used before #6454
Random internal error #642

[REQUIRED] Question

1-Why onPlayerStateChanged() show IDEAL while changing orientation.
2-Here i'm using ProgressiveMediaSource.Factory to load mediaSource from online and as well as local storage. whether this issue created by ProgressiveMediaSource.Factory?
3.When PlayerError occurs how to show the preview again?
4.While player Error occurs Player State will be in IDEAL in this case how to show the preview.

A full bug report captured from the device

E/BufferQueueProducer: [SurfaceTexture-0-22659-29] setMaxDequeuedBufferCount: requested buffer count 2 is less than minimum 3

E/Surface: IGraphicBufferProducer::setBufferCount(2) returned Invalid argument E/ACodec: native_window_set_buffer_count failed: Invalid argument (22)

E/ExoPlayerImplInternal: Internal runtime error. java.lang.IllegalArgumentException at android.media.MediaCodec.native_setSurface(Native Method) at android.media.MediaCodec.setOutputSurface(MediaCodec.java:2042) at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.setOutputSurfaceV23(MediaCodecVideoRenderer.java:1014) at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.setSurface(MediaCodecVideoRenderer.java:422) at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.handleMessage(MediaCodecVideoRenderer.java:387) at com.google.android.exoplayer2.ExoPlayerImplInternal.deliverMessage(ExoPlayerImplInternal.java:864) at com.google.android.exoplayer2.ExoPlayerImplInternal.sendMessageToTarget(ExoPlayerImplInternal.java:835) at com.google.android.exoplayer2.ExoPlayerImplInternal.sendMessageInternal(ExoPlayerImplInternal.java:817) at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:330) at android.os.Handler.dispatchMessage(Handler.java:103) at android.os.Looper.loop(Looper.java:237) at android.os.HandlerThread.run(HandlerThread.java:67)

ExoPlayer 2.9.6 Reproducible Issue

Previously i am using ExoPlayer 2.9.6 at the time i am using DefaultDataSource for showing preview online and Local storage of media. I can able to reproduce the same issue.

@perracodex
Copy link

Possible duplicate of #6874

@AquilesCanta
Copy link
Contributor

AquilesCanta commented Feb 4, 2020

Hi @shobanavelmurugan, in order to help with this, we will need:

  • A sample stream. -- Ideally, it should be the shortest possible video that reproduces the issue.
  • A bugreport as captured by running adb bugreport shortly after seeing the issue.

Thanks!

@shobanavelmurugan
Copy link
Author

@AquilesCanta I use HLS streaming from my api it looks pretty good even shorter length, but problem i face is with previewing the video from Internal storage(Recording using Camera2-Api -(1920x1080 resolution)).

@AquilesCanta
Copy link
Contributor

I don't understand how HLS is involved.

Please provide the items requested above.

@shobanavelmurugan
Copy link
Author

I have Two scenario in my requirement:
Scenario-1: Upload recording video to my server, then i will show preview from server url, here implemented by HLS streaming. This case EXO-player working fine for both short and long duration videos.
Scenario-2: Before Uploading I recorded video, I show preview using EXO-player by .mp4 format.
In this case I record one by one from requested video from my-api. here i have two cases,
1- To save, I maintain recorded path in Sqlite DB and do background upload this case i called continuous record.
2- To cancel, I delete the recorded video from Sqlite DB and file from internal folder.
And do record again and goto preview by this player. At this time this Exception will occur.

@shobanavelmurugan
Copy link
Author

Anyone have tested those scenarios.can you please update what are other information required from my end.

@shobanavelmurugan
Copy link
Author

shobanavelmurugan commented Feb 19, 2020

Possible duplicate of #6874

but no solutions posted yet

@dryganets
Copy link

The solution is to override the method codecNeedsSetOutputSurfaceWorkaround of class MediaCodecVideoRenderer to always return true.

The codec can't be reused in this case, so there are some performance implications of doing that but not every app needs it.

@menscikov
Copy link

menscikov commented Apr 20, 2020

Hello @AquilesCanta,

I'm able to reproduce this Internal runtime error with demo app without modifying any code inside. ExoPlayer version 2.11.4.

I have Xiaomi Mi Box S Android 9.0 TV Box and Cube X3 Android 9.0 TV Box.
Just open any video in HLS tab, and press "Back" button on the remote control.

This error will NOT appear on emulators, only on real devices.

2020-04-20 17:58:16.019 12551-12906/com.google.android.exoplayer2.demo D/SurfaceUtils: connecting to surface 0x8ed09008, reason connectToSurface
2020-04-20 17:58:16.019 12551-12906/com.google.android.exoplayer2.demo I/MediaCodec: [OMX.amlogic.avc.decoder.awesome] setting surface generation to 12852232
2020-04-20 17:58:16.020 12551-12906/com.google.android.exoplayer2.demo D/SurfaceUtils: disconnecting from surface 0x8ed09008, reason connectToSurface(reconnect)
2020-04-20 17:58:16.020 12551-12906/com.google.android.exoplayer2.demo D/SurfaceUtils: connecting to surface 0x8ed09008, reason connectToSurface(reconnect)
2020-04-20 17:58:16.021 12551-12907/com.google.android.exoplayer2.demo D/SurfaceUtils: disconnecting from surface 0x8ed09008, reason setNativeWindowSizeFormatAndUsage
2020-04-20 17:58:16.021 12551-12907/com.google.android.exoplayer2.demo D/SurfaceUtils: connecting to surface 0x8ed09008, reason setNativeWindowSizeFormatAndUsage
2020-04-20 17:58:16.021 12551-12907/com.google.android.exoplayer2.demo D/SurfaceUtils: set up nativeWindow 0x8ed09008 for 1920x1080, color 0x11, rotation 0, usage 0x402b00
2020-04-20 17:58:16.021 12551-12907/com.google.android.exoplayer2.demo W/ACodec: cannot change usage from 0x402933 to 0x402b00
2020-04-20 17:58:16.023 12551-12551/com.google.android.exoplayer2.demo D/EventLogger: surfaceSize [eventTime=5.04, mediaPos=1.50, window=0, period=0, 0, 0]
2020-04-20 17:58:16.023 12551-12890/com.google.android.exoplayer2.demo E/ExoPlayerImplInternal: Internal runtime error
      java.lang.IllegalArgumentException
        at android.media.MediaCodec.native_setSurface(Native Method)
        at android.media.MediaCodec.setOutputSurface(MediaCodec.java:1979)
        at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.setOutputSurfaceV23(MediaCodecVideoRenderer.java:1308)
        at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.setSurface(MediaCodecVideoRenderer.java:627)
        at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.handleMessage(MediaCodecVideoRenderer.java:593)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.deliverMessage(ExoPlayerImplInternal.java:1018)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.sendMessageToTarget(ExoPlayerImplInternal.java:984)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.sendMessageInternal(ExoPlayerImplInternal.java:966)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:367)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:193)
        at android.os.HandlerThread.run(HandlerThread.java:65)
2020-04-20 17:58:16.029 12551-12617/com.google.android.exoplayer2.demo W/libEGL: EGLNativeWindowType 0x909f0808 disconnect failed
2020-04-20 17:58:16.050 12551-12551/com.google.android.exoplayer2.demo I/ExoPlayerImpl: Release 737d25e [ExoPlayerLib/2.11.4] [X3, Model-X3, X3, 28] [goog.exo.core, goog.exo.ui, goog.exo.hls]
2020-04-20 17:58:16.231 12551-12906/com.google.android.exoplayer2.demo D/SurfaceUtils: disconnecting from surface 0x90945808, reason disconnectFromSurface
2020-04-20 17:58:16.237 12551-12906/com.google.android.exoplayer2.demo E/SurfaceUtils: Failed to disconnect from surface 0x90945808, err -19
2020-04-20 17:58:16.237 12551-12906/com.google.android.exoplayer2.demo W/MediaCodec: nativeWindowDisconnect returned an error: No such device (-19)

@Turalllb
Copy link

Turalllb commented Nov 19, 2020

@ojw28 Hello! You worked with similar problems, so I decided to tag you. I have some useful information on this issue. The same bug trace that @menscikov cited above repeats both for me and only on real android tv (Xiaomi Mi Box S Android 9.0). I have localized my problem. When I want to display an advertisement over the player, I set playerView.videoSurfaceView.visibility = View.INVISIBLE and immediately get an error. If you change the visibility, a second after the player has paused, then there is no problem. Tell me at what point can I already hide the display? exoPlayer version 11.7

@saurabharora90
Copy link

@Turalllb you shouldn't toggle the visibility of the playerView. For ads, try using the AdsMediaSource. If that doesn't work for you, then are you using a VideoView?

@Turalllb
Copy link

@saurabharora90 I'm not sure if I can use AdsMediaSource for ads. For advertising, we have our own asSDK with our exoPlayer inside, and the very logic of advertising placement is specific. For the first time I hear about VideoView, I looked at what this class is. I am using PLayerView from exoPlayer. Of course, I can hide the video under another view, but I think it's not right that when the visibility changes, problems arise.

@saurabharora90
Copy link

saurabharora90 commented Nov 20, 2020

@Turalllb somebody can correct me if I am wrong: From my understanding, a surface view is destroyed when you toggle its visibility, which is why you shouldn't do it and hence it causes issues since the Surfaceview is destroyed by the time Exoplayer accesses it. When you do it after pause, it's not an issue anymore.

@Turalllb
Copy link

@saurabharora90 You are right, if you do it after a pause with a delay of 2 seconds, then everything is fine. But if right after the pause, then the problem still arises. In any case, I decided not to do this, I will use alpha or another view on top.

@jlmari
Copy link

jlmari commented Nov 25, 2020

Hello, I have a very similar issue that the one described by @menscikov .

Tested on latest exoplayer version (2.12.1). Reproducing a video with Xiaomi MiBox 3 (Android 9), it works great until home button pressed. Then the following exception is produced:

 com.google.android.exoplayer2.ExoPlaybackException: Unexpected runtime error
 com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:564)
 android.os.Handler.dispatchMessage(Handler.java:102)
 android.os.Looper.loop(Looper.java:193)
 android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: java.lang.IllegalArgumentException
 android.media.MediaCodec.native_setSurface(Native Method)
 android.media.MediaCodec.setOutputSurface(MediaCodec.java:1979)
 com.google.android.exoplayer2.video.MediaCodecVideoRenderer.setOutputSurfaceV23(MediaCodecVideoRenderer.java:1242)
 com.google.android.exoplayer2.video.MediaCodecVideoRenderer.setSurface(MediaCodecVideoRenderer.java:516)
 com.google.android.exoplayer2.video.MediaCodecVideoRenderer.handleMessage(MediaCodecVideoRenderer.java:478)
 com.google.android.exoplayer2.ExoPlayerImplInternal.deliverMessage(ExoPlayerImplInternal.java:1402)
 com.google.android.exoplayer2.ExoPlayerImplInternal.sendMessageToTarget(ExoPlayerImplInternal.java:1368)
 com.google.android.exoplayer2.ExoPlayerImplInternal.sendMessageInternal(ExoPlayerImplInternal.java:1343)
 com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:499)

Also, in Android emulators and mobile phones Xiaomi Mi A3 (Android 10), Xiaomi Redmi Note 8 (Android 9), Xiaomi Mi Max (Android 7) and Motorola One Action (Android 10) it works correctly. After returning from background, the video continues playing on the last position.

@AquilesCanta AquilesCanta changed the title ExoPlayer-2.11.1: ExoPlayerImplInternal: Internal runtime error. java.lang.IllegalArgumentException at android.media.MediaCodec.native_setSurface native_window_set_buffer_count failed: Invalid argument Nov 25, 2020
@AquilesCanta
Copy link
Contributor

I am closing this issue because it is now almost impossible to follow and there seem to be two different and unrelated issues being reported:

  • Issue with rotation on custom app in samsung devices.
  • Issue with navigation (pressing the home button) in the ExoPlayer demo app in Xiaomi devices.

All of the reports have ignored the issue template and failed to include steps to reproduce the issue (including a piece of media, saying "any piece of media" doesn't help) and a bugreport. A bugreport is what adb outputs when you run adb bugreport in the console shortly after reproducing the issue.

If you are still having issues with this, please file a fresh issue and please follow the issue template.

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

No branches or pull requests

10 participants