Small fixes in TextureAssetLoader

The texture input tests in TransformerEndToEndTest were not passing on
Pixel 7. Implemented a fix and fixed other minor threading issues I
spotted while looking at the code.

PiperOrigin-RevId: 531141659
This commit is contained in:
kimvde 2023-05-11 09:19:47 +00:00 committed by Tofunmi Adigun-Hameed
parent e8072ca2c7
commit 203450d244

View File

@ -29,6 +29,7 @@ import androidx.media3.common.MimeTypes;
import androidx.media3.common.VideoFrameProcessor.OnInputFrameProcessedListener;
import androidx.media3.common.util.UnstableApi;
import com.google.common.collect.ImmutableMap;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/**
* An {@link AssetLoader} implementation that loads videos from {@linkplain
@ -46,11 +47,13 @@ public final class TextureAssetLoader implements AssetLoader {
private final Format format;
private final OnInputFrameProcessedListener frameProcessedListener;
@Nullable private SampleConsumer sampleConsumer;
private @MonotonicNonNull SampleConsumer sampleConsumer;
private @Transformer.ProgressState int progressState;
private long lastQueuedPresentationTimeUs;
private boolean isTrackAdded;
private volatile boolean isStarted;
private volatile long lastQueuedPresentationTimeUs;
/**
* Creates an instance.
*
@ -76,6 +79,7 @@ public final class TextureAssetLoader implements AssetLoader {
progressState = PROGRESS_STATE_AVAILABLE;
assetLoaderListener.onDurationUs(editedMediaItem.durationUs);
assetLoaderListener.onTrackCount(1);
isStarted = true;
}
@Override
@ -94,9 +98,7 @@ public final class TextureAssetLoader implements AssetLoader {
@Override
public void release() {
isTrackAdded = false;
progressState = PROGRESS_STATE_NOT_STARTED;
sampleConsumer = null;
}
/**
@ -112,14 +114,18 @@ public final class TextureAssetLoader implements AssetLoader {
public boolean queueInputTexture(int texId, long presentationTimeUs) {
try {
if (!isTrackAdded) {
if (!isStarted) {
return false;
}
assetLoaderListener.onTrackAdded(format, SUPPORTED_OUTPUT_TYPE_DECODED);
isTrackAdded = true;
}
if (sampleConsumer == null) {
sampleConsumer = assetLoaderListener.onOutputFormat(format);
@Nullable SampleConsumer sampleConsumer = assetLoaderListener.onOutputFormat(format);
if (sampleConsumer == null) {
return false;
} else {
this.sampleConsumer = sampleConsumer;
sampleConsumer.setOnInputFrameProcessedListener(frameProcessedListener);
}
}