Commit 379c3e1e by kimvde Committed by Andrew Lewis

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
parent 9a8026f2
...@@ -64,17 +64,21 @@ public interface AssetLoader { ...@@ -64,17 +64,21 @@ public interface AssetLoader {
EditedMediaItem editedMediaItem, Looper looper, Listener listener); EditedMediaItem editedMediaItem, Looper looper, Listener listener);
} }
/** /** A listener of {@link AssetLoader} events. */
* A listener of {@link AssetLoader} events.
*
* <p>This listener can be called from any thread.
*/
interface Listener { 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); 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); void onTrackCount(@IntRange(from = 1) int trackCount);
/** /**
...@@ -85,6 +89,10 @@ public interface AssetLoader { ...@@ -85,6 +89,10 @@ public interface AssetLoader {
* *
* <p>Must be called once per {@linkplain #onTrackCount(int) declared} track. * <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 * @param format The {@link Format} of the input media (prior to video slow motion flattening or
* to decoding). * to decoding).
* @param supportedOutputTypes The output {@linkplain SupportedOutputTypes types} supported by * @param supportedOutputTypes The output {@linkplain SupportedOutputTypes types} supported by
...@@ -107,6 +115,8 @@ public interface AssetLoader { ...@@ -107,6 +115,8 @@ public interface AssetLoader {
/** /**
* Called if an error occurs in the asset loader. In this case, the asset loader will be * Called if an error occurs in the asset loader. In this case, the asset loader will be
* {@linkplain #release() released} automatically. * {@linkplain #release() released} automatically.
*
* <p>Can be called from any thread.
*/ */
void onError(ExportException exportException); void onError(ExportException exportException);
} }
......
...@@ -37,7 +37,8 @@ import java.util.concurrent.atomic.AtomicLong; ...@@ -37,7 +37,8 @@ import java.util.concurrent.atomic.AtomicLong;
private final Queue<DecoderInputBuffer> availableInputBuffers; private final Queue<DecoderInputBuffer> availableInputBuffers;
private final Queue<DecoderInputBuffer> pendingInputBuffers; private final Queue<DecoderInputBuffer> pendingInputBuffers;
private volatile long mediaItemOffsetUs; private long mediaItemOffsetUs;
private volatile boolean inputEnded; private volatile boolean inputEnded;
public EncodedSamplePipeline( public EncodedSamplePipeline(
......
...@@ -26,8 +26,6 @@ import com.google.android.exoplayer2.MediaItem; ...@@ -26,8 +26,6 @@ import com.google.android.exoplayer2.MediaItem;
* Called when the {@link MediaItem} whose samples are passed to the {@link SamplePipeline} * Called when the {@link MediaItem} whose samples are passed to the {@link SamplePipeline}
* changes. * changes.
* *
* <p>Can be called from any thread.
*
* @param editedMediaItem The {@link MediaItem} with the transformations to apply to it. * @param editedMediaItem The {@link MediaItem} with the transformations to apply to it.
* @param durationUs The duration of the {@link MediaItem}, in microseconds. * @param durationUs The duration of the {@link MediaItem}, in microseconds.
* @param trackFormat The {@link Format} of the {@link MediaItem} track corresponding to the * @param trackFormat The {@link Format} of the {@link MediaItem} track corresponding to the
......
...@@ -21,11 +21,7 @@ import androidx.annotation.Nullable; ...@@ -21,11 +21,7 @@ import androidx.annotation.Nullable;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.video.ColorInfo; import com.google.android.exoplayer2.video.ColorInfo;
/** /** Consumer of encoded media samples, raw audio or raw video frames. */
* Consumer of encoded media samples, raw audio or raw video frames.
*
* <p>All the methods in this class can be called from any thread.
*/
public interface SampleConsumer { public interface SampleConsumer {
/** /**
......
...@@ -36,6 +36,11 @@ import java.util.List; ...@@ -36,6 +36,11 @@ import java.util.List;
* Pipeline for processing media data. * Pipeline for processing media data.
* *
* <p>This pipeline can be used to implement transformations of audio or video samples. * <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 { /* package */ abstract class SamplePipeline implements SampleConsumer, OnMediaItemChangedListener {
......
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