Restrict SampleConsumer and OnMediaItemChanged threading

This is more future-proof because it is likely to simplify the upcoming
changes to the sample pipelines.

PiperOrigin-RevId: 511492014
This commit is contained in:
kimvde 2023-02-22 15:37:53 +00:00 committed by tonihei
parent f4d470ac4c
commit bede06546d
5 changed files with 25 additions and 15 deletions

View file

@ -66,17 +66,21 @@ public interface AssetLoader {
EditedMediaItem editedMediaItem, Looper looper, Listener listener);
}
/**
* A listener of {@link AssetLoader} events.
*
* <p>This listener can be called from any thread.
*/
/** A listener of {@link AssetLoader} events. */
interface Listener {
/** Called when the duration of the input media is known. */
/**
* Called when the duration of the input media is known.
*
* <p>Can be called from any thread.
*/
void onDurationUs(long durationUs);
/** Called when the number of tracks output by the asset loader is known. */
/**
* Called when the number of tracks output by the asset loader is known.
*
* <p>Can be called from any thread.
*/
void onTrackCount(@IntRange(from = 1) int trackCount);
/**
@ -87,6 +91,10 @@ public interface AssetLoader {
*
* <p>Must be called once per {@linkplain #onTrackCount(int) declared} track.
*
* <p>Must be called from the thread that will be used to call the returned {@link
* SampleConsumer}'s methods. This thread is generally different from the one used to access the
* {@link AssetLoader} methods.
*
* @param format The {@link Format} of the input media (prior to video slow motion flattening or
* to decoding).
* @param supportedOutputTypes The output {@linkplain SupportedOutputTypes types} supported by
@ -109,6 +117,8 @@ public interface AssetLoader {
/**
* Called if an error occurs in the asset loader. In this case, the asset loader will be
* {@linkplain #release() released} automatically.
*
* <p>Can be called from any thread.
*/
void onError(ExportException exportException);
}

View file

@ -37,7 +37,8 @@ import java.util.concurrent.atomic.AtomicLong;
private final Queue<DecoderInputBuffer> availableInputBuffers;
private final Queue<DecoderInputBuffer> pendingInputBuffers;
private volatile long mediaItemOffsetUs;
private long mediaItemOffsetUs;
private volatile boolean inputEnded;
public EncodedSamplePipeline(

View file

@ -26,8 +26,6 @@ import androidx.media3.common.MediaItem;
* Called when the {@link MediaItem} whose samples are passed to the {@link SamplePipeline}
* changes.
*
* <p>Can be called from any thread.
*
* @param editedMediaItem The {@link MediaItem} with the transformations to apply to it.
* @param durationUs The duration of the {@link MediaItem}, in microseconds.
* @param trackFormat The {@link Format} of the {@link MediaItem} track corresponding to the

View file

@ -22,11 +22,7 @@ import androidx.media3.common.ColorInfo;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.decoder.DecoderInputBuffer;
/**
* Consumer of encoded media samples, raw audio or raw video frames.
*
* <p>All the methods in this class can be called from any thread.
*/
/** Consumer of encoded media samples, raw audio or raw video frames. */
@UnstableApi
public interface SampleConsumer {

View file

@ -36,6 +36,11 @@ import java.util.List;
* Pipeline for processing media data.
*
* <p>This pipeline can be used to implement transformations of audio or video samples.
*
* <p>The {@link SampleConsumer} and {@link OnMediaItemChangedListener} methods must be called from
* the same thread. This thread can change when the {@link
* OnMediaItemChangedListener#onMediaItemChanged(EditedMediaItem, Format, long) MediaItem} changes,
* and can be different from the thread used to call the other {@code SamplePipeline} methods.
*/
/* package */ abstract class SamplePipeline implements SampleConsumer, OnMediaItemChangedListener {