mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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:
parent
f4d470ac4c
commit
bede06546d
5 changed files with 25 additions and 15 deletions
|
|
@ -66,17 +66,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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -87,6 +91,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
|
||||||
|
|
@ -109,6 +117,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;
|
||||||
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 androidx.media3.common.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
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,7 @@ import androidx.media3.common.ColorInfo;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import androidx.media3.decoder.DecoderInputBuffer;
|
import androidx.media3.decoder.DecoderInputBuffer;
|
||||||
|
|
||||||
/**
|
/** 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.
|
|
||||||
*/
|
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public interface SampleConsumer {
|
public interface SampleConsumer {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue