Commit 25e793ff by kimvde Committed by Tofunmi Adigun-Hameed

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
parent e10270e6
......@@ -28,6 +28,7 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.VideoFrameProcessor.OnInputFrameProcessedListener;
import com.google.common.collect.ImmutableMap;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/**
* An {@link AssetLoader} implementation that loads videos from {@linkplain
......@@ -44,11 +45,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.
*
......@@ -74,6 +77,7 @@ public final class TextureAssetLoader implements AssetLoader {
progressState = PROGRESS_STATE_AVAILABLE;
assetLoaderListener.onDurationUs(editedMediaItem.durationUs);
assetLoaderListener.onTrackCount(1);
isStarted = true;
}
@Override
......@@ -92,9 +96,7 @@ public final class TextureAssetLoader implements AssetLoader {
@Override
public void release() {
isTrackAdded = false;
progressState = PROGRESS_STATE_NOT_STARTED;
sampleConsumer = null;
}
/**
......@@ -110,14 +112,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);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment