From 0b40bc37ab0405dc7673702a9ac035a0a5c4cb63 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Tue, 11 Apr 2023 15:57:37 +0100 Subject: [PATCH] Release sample pipelines before asset loaders The video asset loader renders decoder output to a surface texture, and if the video sample pipeline is in the process of updating the surface texture image at the moment when the asset loader video decoder is released this seems to cause `MediaCodec.release` to get stuck. Swap the release order so that we stop updating the texture before trying to release the codec. PiperOrigin-RevId: 523401619 --- .../media3/transformer/TransformerInternal.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerInternal.java b/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerInternal.java index 494cf283f5..7d9256c934 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerInternal.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerInternal.java @@ -343,9 +343,12 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; boolean releasedPreviously = released; if (!released) { released = true; - for (int i = 0; i < sequenceAssetLoaders.size(); i++) { + // The video sample pipeline can hold buffers from the asset loader's decoder in a surface + // texture, so we release the video sample pipeline first to avoid releasing the codec while + // its buffers are pending processing. + for (int i = 0; i < samplePipelines.size(); i++) { try { - sequenceAssetLoaders.get(i).release(); + samplePipelines.get(i).release(); } catch (RuntimeException e) { if (releaseExportException == null) { releaseExportException = ExportException.createForUnexpected(e); @@ -355,9 +358,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; } } } - for (int i = 0; i < samplePipelines.size(); i++) { + for (int i = 0; i < sequenceAssetLoaders.size(); i++) { try { - samplePipelines.get(i).release(); + sequenceAssetLoaders.get(i).release(); } catch (RuntimeException e) { if (releaseExportException == null) { releaseExportException = ExportException.createForUnexpected(e);