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

TimestampWrapper Effect with exoPlayer.setVideoEffects causes crash #821

Closed
1 task
pawaom opened this issue Nov 18, 2023 · 5 comments
Closed
1 task

TimestampWrapper Effect with exoPlayer.setVideoEffects causes crash #821

pawaom opened this issue Nov 18, 2023 · 5 comments
Assignees

Comments

@pawaom
Copy link

pawaom commented Nov 18, 2023

Version

Media3 1.2.0

More version details

TimestampWrapper Effect with exoPlayer.setVideoEffects causes crash

I am trying this code

@OptIn(UnstableApi::class)
   private fun initializePlayer() {
       // ExoPlayer implements the Player interface
       player = ExoPlayer.Builder(this)
           .build()
           .also { exoPlayer ->
               viewBinding.videoView.player = exoPlayer
               // Update the track selection parameters to only pick standard definition tracks
               exoPlayer.trackSelectionParameters = exoPlayer.trackSelectionParameters
                   .buildUpon()
                   .setMaxVideoSizeSd()
                   .build()


               val timeWrappedEffect: GlEffect = TimestampWrapper(
                   createOverlayEffect(),
                   (1000 * 1000).toLong(),
                   (5000 * 1000).toLong()
               )
               val effects = ImmutableList.Builder<Effect>()
               effects.add(timeWrappedEffect)


               exoPlayer.setMediaItems(abcd2())
               exoPlayer.playWhenReady = playWhenReady

               exoPlayer.setVideoEffects(effects.build())

               exoPlayer.addListener(playbackStateListener)
               exoPlayer.prepare()
               exoPlayer.play()


           }
   }
@OptIn(UnstableApi::class)

   fun createOverlayEffect(): OverlayEffect {
       val overlaysBuilder = ImmutableList.Builder<TextureOverlay>()
       val logoSettings =
           OverlaySettings.Builder()
               // Place the logo in the bottom left corner of the screen with some padding from the
               // edges.
               .setOverlayFrameAnchor(/* x= */ 1f, /* y= */ 1f)
               .setBackgroundFrameAnchor(/* x= */ -0.95f, /* y= */ -0.95f)
               .build()


       val logo = packageManager.getApplicationIcon(packageName);

       logo.setBounds(
           /* left= */ 0, /* top= */ 0, logo.getIntrinsicWidth(), logo.getIntrinsicHeight()
       );
       val logoOverlay = DrawableOverlay.createStaticDrawableOverlay(logo, logoSettings);

       overlaysBuilder.add(logoOverlay);
       val overlays = overlaysBuilder.build()
       return OverlayEffect(overlays)
   }

fun abcd2(): List<MediaItem> {

       return selectedList.map { uri: AssetInfo ->
           MediaItem.Builder()
               .setUri(uri.uriString)
               .setClippingConfiguration(
                   MediaItem.ClippingConfiguration.Builder()
                       .setStartPositionMs(0)
                       .setEndPositionMs(10000)
                       .build()
               )
               .build()
       }

When we try to use createOverlayEffect() directly the video is rendered , however it causes a crash when we try to use TimestampWrapper this is the error log

Playback error androidx.media3.exoplayer.ExoPlaybackException: MediaCodecVideoRenderer error, index=0, format=Format(null, null, null, video/raw, null, -1, null, [0, 0, -1.0, null], [-1, -1]), format_supported=NO_UNSUPPORTED_TYPE at androidx.media3.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:608) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.os.HandlerThread.run(HandlerThread.java:67) Caused by: androidx.media3.exoplayer.video.VideoSink$VideoSinkException: androidx.media3.common.VideoFrameProcessingException: java.lang.IllegalStateException: Textures are all in use. Please release in-use textures before calling useTexture. at androidx.media3.exoplayer.video.CompositingVideoSinkProvider$VideoSinkImpl.lambda$onError$0$androidx-media3-exoplayer-video-CompositingVideoSinkProvider$VideoSinkImpl(CompositingVideoSinkProvider.java:462) at androidx.media3.exoplayer.video.CompositingVideoSinkProvider$VideoSinkImpl$$ExternalSyntheticLambda2.run(Unknown Source:4) at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:31) at androidx.media3.exoplayer.video.CompositingVideoSinkProvider$VideoSinkImpl.onError(CompositingVideoSinkProvider.java:451) at androidx.media3.effect.SingleInputVideoGraph$1.lambda$onError$2$androidx-media3-effect-SingleInputVideoGraph$1(SingleInputVideoGraph.java:143) at androidx.media3.effect.SingleInputVideoGraph$1$$ExternalSyntheticLambda0.run(Unknown Source:4) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:226)  at android.os.Looper.loop(Looper.java:313)  at android.os.HandlerThread.run(HandlerThread.java:67)  Caused by: androidx.media3.common.VideoFrameProcessingException: java.lang.IllegalStateException: Textures are all in use. Please release in-use textures before calling useTexture. at androidx.media3.effect.VideoFrameProcessingTaskExecutor.handleException(VideoFrameProcessingTaskExecutor.java:224) at androidx.media3.effect.VideoFrameProcessingTaskExecutor.lambda$wrapTaskAndSubmitToExecutorService$2$androidx-media3-effect-VideoFrameProcessingTaskExecutor(VideoFrameProcessingTaskExecutor.java:210) at androidx.media3.effect.VideoFrameProcessingTaskExecutor$$ExternalSyntheticLambda2.run(Unknown Source:6) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:463) at java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637) at java.lang.Thread.run(Thread.java:1012) Caused by: java.lang.IllegalStateException: Textures are all in use. Please release in-use textures before calling useTexture. at androidx.media3.effect.TexturePool.useTexture(TexturePool.java:89) at androidx.media3.effect.BaseGlShaderProgram.queueInputFrame(BaseGlShaderProgram.java:144) at androidx.media3.effect.TimestampWrapperShaderProgram.queueInputFrame(TimestampWrapperShaderProgram.java:84) at androidx.media3.effect.FrameConsumptionManager.lambda$queueInputFrame$1$androidx-media3-effect-FrameConsumptionManager(FrameConsumptionManager.java:96) at androidx.media3.effect.FrameConsumptionManager$$ExternalSyntheticLambda1.run(Unknown Source:6) at androidx.media3.effect.VideoFrameProcessingTaskExecutor.lambda$wrapTaskAndSubmitToExecutorService$2$androidx-media3-effect-VideoFrameProcessingTaskExecutor(VideoFrameProcessingTaskExecutor.java:208) at androidx.media3.effect.VideoFrameProcessingTaskExecutor$$ExternalSyntheticLambda2.run(Unknown Source:6)  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:463)  at java.util.concurrent.FutureTask.run(FutureTask.java:264)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)  at java.lang.Thread.run(Thread.java:1012)  2023-11-18 11:26:57.219 1262-3355 WindowManager system_server E win=Window{3c1e04c u0 com.trywork.video.MainActivity} destroySurfaces: appStopped=true cleanupOnResume=false win.mWindowRemovalAllowed=false win.mRemoveOnExit=false win.mViewVisibility=8 caller=com.android.server.wm.ActivityRecord.destroySurfaces:6776 com.android.server.wm.ActivityRecord.destroySurfaces:6757 com.android.server.wm.ActivityRecord.notifyAppStopped:6821 com.android.server.wm.ActivityRecord.activityStopped:7427 com.android.server.wm.ActivityClientController.activityStopped:263 android.app.IActivityClientController$Stub.onTransact:621 com.android.server.wm.ActivityClientController.onTransact:141

Devices that reproduce the issue

Samsung Galaxy tab A7 lite Android 13

Devices that do not reproduce the issue

did no try

Reproducible in the demo app?

Yes

Reproduction steps

just try code from this or any other simple video playback example from exoplayer

https://www.youtube.com/watch?v=Hw0Jeq42FNU&t=315s

and added the above code for effects

First try the simple exoPlayer.setVideoEffects(createOverlayEffect()) the video plays perfectly

Then try

val effects = ImmutableList.Builder<Effect>()
                effects.add(timeWrappedEffect)
 

                exoPlayer.setVideoEffects(effects.build())

this will crash the app

Expected result

video should render with overlay for the selected duration in imeWrappedEffect

Actual result

video doesnot render and app crashed after that

Media

https://www.youtube.com/api/manifest/dash/id/bf5bb2419360daf1/source/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=51AF5F39AB0CEC3E5497CD9C900EBFEAECCCB5C7.8506521BFC350652163895D4C26DEE124209AA9E&key=ik0]

it is the same url used in the example shared by google itself in the video on youtube the link of which I have shared above

Bug Report

@pawaom
Copy link
Author

pawaom commented Nov 21, 2023

Any updates , is it possible to use TimestampWrapper with setVideoEffects

@droid-girl
Copy link
Contributor

The team is looking into the issue, no updates yet

@dway123
Copy link
Contributor

dway123 commented Nov 22, 2023

Thanks for the bug report. It seems TimestampWrapper works for Transformer.export but not for Exoplayer.setVideoEffects. I suspect that this is because TimestampWrapper incorrectly overreports input capacity improperly to its InputListeners, and ExoPlayer eagerly feeds frames into its VideoFrameProcessor.

Sorry, I'm not sure we'll be able to prioritize this in Q42023, but hope we can take a look at this next quarter. In the meantime, I'll update javadoc for the class to mention that it shouldn't be used in ExoPlayer.setVideoEffects, and you can implement functionality similar to this by looking at the ExoPlayer timestamp most recently (via ExoPlayer.setVideoFrameMetadataListener()), and calling ExoPlayer.setVideoEffects with that effect applied on the start timestamp you previously input into the TimestampWrapper, and with an empty list of effects on the end timestamp you previously input into the TimestampWrapper

More information on this specific issue:
TimestampWrapper reports an input capacity of 2 (one from its wrappedGlShaderProgram and one from its copyShaderProgram), but only has a real input capacity of 1 in its initial copyShaderProgram. When a 2nd frame is pushed into copyShaderProgram before the first is released, this error occurs. This was known in internal b/277726418, but we haven't been able to prioritize that in the past, partly because we hadn't seen any real failures from that yet.

@pawaom
Copy link
Author

pawaom commented Nov 23, 2023

@dway123 thanks for the info please check if exoplayer supports other effects which can be used with transformer, we have not checked all of them however if its tested it will be helpful

copybara-service bot pushed a commit that referenced this issue Nov 27, 2023
Mentioned in #821

PiperOrigin-RevId: 585595948
copybara-service bot pushed a commit to google/ExoPlayer that referenced this issue Nov 27, 2023
@dway123
Copy link
Contributor

dway123 commented Nov 27, 2023

All geometric-only (ex. MatrixTransformation-based) effects work with exoplayer.setVideoEffects, and I believe most effects in general should work with exoplayer.setVideoEffects.

I suspect that only TimestampWrapper should have an issue like this specific one with previewing, because that's the only effect that differs in how it signals frame capacity in this way.

Otherwise, color effects don't work with exoplayer+HDR input easily, due to these effects not supporting HDR input, and exoplayer not having an easy way to setVideoEffects while customizing the output color to be SDR. Because of this, these effects (code search link) are not supported, unless you force only having SDR output, by following instructions like seen here: Brightness, HSL, Overlay, and ColorLut.

@androidx androidx locked and limited conversation to collaborators Feb 4, 2024
copybara-service bot pushed a commit that referenced this issue Apr 19, 2024
fixes #821

PiperOrigin-RevId: 626407880
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

3 participants