mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
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:
parent
e8072ca2c7
commit
203450d244
@ -29,6 +29,7 @@ import androidx.media3.common.MimeTypes;
|
|||||||
import androidx.media3.common.VideoFrameProcessor.OnInputFrameProcessedListener;
|
import androidx.media3.common.VideoFrameProcessor.OnInputFrameProcessedListener;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link AssetLoader} implementation that loads videos from {@linkplain
|
* 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 Format format;
|
||||||
private final OnInputFrameProcessedListener frameProcessedListener;
|
private final OnInputFrameProcessedListener frameProcessedListener;
|
||||||
|
|
||||||
@Nullable private SampleConsumer sampleConsumer;
|
private @MonotonicNonNull SampleConsumer sampleConsumer;
|
||||||
private @Transformer.ProgressState int progressState;
|
private @Transformer.ProgressState int progressState;
|
||||||
private long lastQueuedPresentationTimeUs;
|
|
||||||
private boolean isTrackAdded;
|
private boolean isTrackAdded;
|
||||||
|
|
||||||
|
private volatile boolean isStarted;
|
||||||
|
private volatile long lastQueuedPresentationTimeUs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance.
|
* Creates an instance.
|
||||||
*
|
*
|
||||||
@ -76,6 +79,7 @@ public final class TextureAssetLoader implements AssetLoader {
|
|||||||
progressState = PROGRESS_STATE_AVAILABLE;
|
progressState = PROGRESS_STATE_AVAILABLE;
|
||||||
assetLoaderListener.onDurationUs(editedMediaItem.durationUs);
|
assetLoaderListener.onDurationUs(editedMediaItem.durationUs);
|
||||||
assetLoaderListener.onTrackCount(1);
|
assetLoaderListener.onTrackCount(1);
|
||||||
|
isStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -94,9 +98,7 @@ public final class TextureAssetLoader implements AssetLoader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void release() {
|
public void release() {
|
||||||
isTrackAdded = false;
|
|
||||||
progressState = PROGRESS_STATE_NOT_STARTED;
|
progressState = PROGRESS_STATE_NOT_STARTED;
|
||||||
sampleConsumer = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,14 +114,18 @@ public final class TextureAssetLoader implements AssetLoader {
|
|||||||
public boolean queueInputTexture(int texId, long presentationTimeUs) {
|
public boolean queueInputTexture(int texId, long presentationTimeUs) {
|
||||||
try {
|
try {
|
||||||
if (!isTrackAdded) {
|
if (!isTrackAdded) {
|
||||||
|
if (!isStarted) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
assetLoaderListener.onTrackAdded(format, SUPPORTED_OUTPUT_TYPE_DECODED);
|
assetLoaderListener.onTrackAdded(format, SUPPORTED_OUTPUT_TYPE_DECODED);
|
||||||
isTrackAdded = true;
|
isTrackAdded = true;
|
||||||
}
|
}
|
||||||
if (sampleConsumer == null) {
|
if (sampleConsumer == null) {
|
||||||
sampleConsumer = assetLoaderListener.onOutputFormat(format);
|
@Nullable SampleConsumer sampleConsumer = assetLoaderListener.onOutputFormat(format);
|
||||||
if (sampleConsumer == null) {
|
if (sampleConsumer == null) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
this.sampleConsumer = sampleConsumer;
|
||||||
sampleConsumer.setOnInputFrameProcessedListener(frameProcessedListener);
|
sampleConsumer.setOnInputFrameProcessedListener(frameProcessedListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user