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
This commit is contained in:
andrewlewis 2023-04-11 15:57:37 +01:00 committed by Rohit Singh
parent ba2c32738f
commit 0b40bc37ab

View file

@ -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);