Commit 220a5b9f by kimvde Committed by Marc Baechinger

Misc small fixes

- Improve AssetLoader Javadoc
- Fix Javadoc of sample pipelines
- Improve Javadoc of Transformer.startTransformation
- Move thread hops for Transformer listener callbacks to
  TransformerInternal

PiperOrigin-RevId: 499156604
parent 46f56546
...@@ -121,14 +121,6 @@ public interface AssetLoader { ...@@ -121,14 +121,6 @@ public interface AssetLoader {
/** /**
* A listener of {@link AssetLoader} events. * A listener of {@link AssetLoader} events.
* *
* <p>This listener is typically used in the following way:
*
* <ul>
* <li>{@linkplain #onDurationUs(long)} Report} the duration of the input media.
* <li>{@linkplain #onTrackCount(int) Report} the number of output tracks.
* <li>{@linkplain #onTrackAdded(Format, int, long, long) Add} the information for each track.
* </ul>
*
* <p>This listener can be called from any thread. * <p>This listener can be called from any thread.
*/ */
interface Listener { interface Listener {
......
...@@ -35,9 +35,7 @@ import java.util.List; ...@@ -35,9 +35,7 @@ import java.util.List;
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf; import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.Pure;
/** /** Pipeline to apply audio processing to raw audio samples, encode them and mux them. */
* Pipeline to decode audio samples, apply audio processing to the raw samples, and re-encode them.
*/
/* package */ final class AudioTranscodingSamplePipeline extends BaseSamplePipeline { /* package */ final class AudioTranscodingSamplePipeline extends BaseSamplePipeline {
private static final int DEFAULT_ENCODER_BITRATE = 128 * 1024; private static final int DEFAULT_ENCODER_BITRATE = 128 * 1024;
......
...@@ -248,7 +248,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -248,7 +248,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
} }
/** /**
* Attempts to read input data and pass the input data to the sample pipeline. * Attempts to read input data and pass it to the sample pipeline.
* *
* @return Whether it may be possible to read more data immediately by calling this method again. * @return Whether it may be possible to read more data immediately by calling this method again.
*/ */
......
...@@ -20,7 +20,7 @@ import androidx.annotation.Nullable; ...@@ -20,7 +20,7 @@ import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
/** Pipeline that passes through the samples without any re-encoding or transformation. */ /** Pipeline that muxes encoded samples without any transcoding or transformation. */
/* package */ final class PassthroughSamplePipeline extends BaseSamplePipeline { /* package */ final class PassthroughSamplePipeline extends BaseSamplePipeline {
private final DecoderInputBuffer buffer; private final DecoderInputBuffer buffer;
......
...@@ -20,7 +20,7 @@ import androidx.annotation.Nullable; ...@@ -20,7 +20,7 @@ import androidx.annotation.Nullable;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
/** /**
* Pipeline for processing {@link DecoderInputBuffer DecoderInputBuffers}. * 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.
*/ */
......
...@@ -34,7 +34,6 @@ import com.google.android.exoplayer2.audio.SonicAudioProcessor; ...@@ -34,7 +34,6 @@ import com.google.android.exoplayer2.audio.SonicAudioProcessor;
import com.google.android.exoplayer2.effect.GlEffect; import com.google.android.exoplayer2.effect.GlEffect;
import com.google.android.exoplayer2.effect.GlEffectsFrameProcessor; import com.google.android.exoplayer2.effect.GlEffectsFrameProcessor;
import com.google.android.exoplayer2.effect.GlMatrixTransformation; import com.google.android.exoplayer2.effect.GlMatrixTransformation;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.DebugViewProvider; import com.google.android.exoplayer2.util.DebugViewProvider;
import com.google.android.exoplayer2.util.Effect; import com.google.android.exoplayer2.util.Effect;
...@@ -693,8 +692,10 @@ public final class Transformer { ...@@ -693,8 +692,10 @@ public final class Transformer {
* *
* <p>Concurrent transformations on the same Transformer object are not allowed. * <p>Concurrent transformations on the same Transformer object are not allowed.
* *
* <p>The output is an MP4 file. It can contain at most one video track and one audio track. Other * <p>If no custom {@link Muxer.Factory} is specified, the output is an MP4 file.
* track types are ignored. For adaptive bitrate {@linkplain MediaSource media sources}, the *
* <p>The output can contain at most one video track and one audio track. Other track types are
* ignored. For adaptive bitrate, if no custom {@link AssetLoader.Factory} is specified, the
* highest bitrate video and audio streams are selected. * highest bitrate video and audio streams are selected.
* *
* @param mediaItem The {@link MediaItem} to transform. * @param mediaItem The {@link MediaItem} to transform.
...@@ -716,8 +717,10 @@ public final class Transformer { ...@@ -716,8 +717,10 @@ public final class Transformer {
* *
* <p>Concurrent transformations on the same Transformer object are not allowed. * <p>Concurrent transformations on the same Transformer object are not allowed.
* *
* <p>The output is an MP4 file. It can contain at most one video track and one audio track. Other * <p>If no custom {@link Muxer.Factory} is specified, the output is an MP4 file.
* track types are ignored. For adaptive bitrate {@linkplain MediaSource media sources}, the *
* <p>The output can contain at most one video track and one audio track. Other track types are
* ignored. For adaptive bitrate, if no custom {@link AssetLoader.Factory} is specified, the
* highest bitrate video and audio streams are selected. * highest bitrate video and audio streams are selected.
* *
* @param mediaItem The {@link MediaItem} to transform. * @param mediaItem The {@link MediaItem} to transform.
...@@ -751,12 +754,9 @@ public final class Transformer { ...@@ -751,12 +754,9 @@ public final class Transformer {
} }
TransformerInternalListener transformerInternalListener = TransformerInternalListener transformerInternalListener =
new TransformerInternalListener(mediaItem); new TransformerInternalListener(mediaItem);
HandlerWrapper applicationHandler = clock.createHandler(looper, /* callback= */ null);
FallbackListener fallbackListener = FallbackListener fallbackListener =
new FallbackListener( new FallbackListener(mediaItem, listeners, applicationHandler, transformationRequest);
mediaItem,
listeners,
clock.createHandler(looper, /* callback= */ null),
transformationRequest);
transformerInternal = transformerInternal =
new TransformerInternal( new TransformerInternal(
context, context,
...@@ -776,6 +776,7 @@ public final class Transformer { ...@@ -776,6 +776,7 @@ public final class Transformer {
muxerFactory, muxerFactory,
transformerInternalListener, transformerInternalListener,
fallbackListener, fallbackListener,
applicationHandler,
debugViewProvider, debugViewProvider,
clock); clock);
transformerInternal.start(); transformerInternal.start();
...@@ -834,37 +835,29 @@ public final class Transformer { ...@@ -834,37 +835,29 @@ public final class Transformer {
private final class TransformerInternalListener implements TransformerInternal.Listener { private final class TransformerInternalListener implements TransformerInternal.Listener {
private final MediaItem mediaItem; private final MediaItem mediaItem;
private final HandlerWrapper handler;
public TransformerInternalListener(MediaItem mediaItem) { public TransformerInternalListener(MediaItem mediaItem) {
this.mediaItem = mediaItem; this.mediaItem = mediaItem;
handler = clock.createHandler(looper, /* callback= */ null);
} }
@Override @Override
public void onTransformationCompleted(TransformationResult transformationResult) { public void onTransformationCompleted(TransformationResult transformationResult) {
// TODO(b/213341814): Add event flags for Transformer events. // TODO(b/213341814): Add event flags for Transformer events.
handler.post(
() -> {
transformerInternal = null; transformerInternal = null;
listeners.queueEvent( listeners.queueEvent(
/* eventFlag= */ C.INDEX_UNSET, /* eventFlag= */ C.INDEX_UNSET,
listener -> listener.onTransformationCompleted(mediaItem, transformationResult)); listener -> listener.onTransformationCompleted(mediaItem, transformationResult));
listeners.flushEvents(); listeners.flushEvents();
});
} }
@Override @Override
public void onTransformationError( public void onTransformationError(
TransformationResult result, TransformationException exception) { TransformationResult result, TransformationException exception) {
handler.post(
() -> {
transformerInternal = null; transformerInternal = null;
listeners.queueEvent( listeners.queueEvent(
/* eventFlag= */ C.INDEX_UNSET, /* eventFlag= */ C.INDEX_UNSET,
listener -> listener.onTransformationError(mediaItem, result, exception)); listener -> listener.onTransformationError(mediaItem, result, exception));
listeners.flushEvents(); listeners.flushEvents();
});
} }
} }
} }
...@@ -100,6 +100,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -100,6 +100,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private final CapturingEncoderFactory encoderFactory; private final CapturingEncoderFactory encoderFactory;
private final FrameProcessor.Factory frameProcessorFactory; private final FrameProcessor.Factory frameProcessorFactory;
private final Listener listener; private final Listener listener;
private final HandlerWrapper applicationHandler;
private final DebugViewProvider debugViewProvider; private final DebugViewProvider debugViewProvider;
private final Clock clock; private final Clock clock;
private final HandlerThread internalHandlerThread; private final HandlerThread internalHandlerThread;
...@@ -137,6 +138,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -137,6 +138,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
Muxer.Factory muxerFactory, Muxer.Factory muxerFactory,
Listener listener, Listener listener,
FallbackListener fallbackListener, FallbackListener fallbackListener,
HandlerWrapper applicationHandler,
DebugViewProvider debugViewProvider, DebugViewProvider debugViewProvider,
Clock clock) { Clock clock) {
this.context = context; this.context = context;
...@@ -148,6 +150,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -148,6 +150,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
this.encoderFactory = new CapturingEncoderFactory(encoderFactory); this.encoderFactory = new CapturingEncoderFactory(encoderFactory);
this.frameProcessorFactory = frameProcessorFactory; this.frameProcessorFactory = frameProcessorFactory;
this.listener = listener; this.listener = listener;
this.applicationHandler = applicationHandler;
this.debugViewProvider = debugViewProvider; this.debugViewProvider = debugViewProvider;
this.clock = clock; this.clock = clock;
internalHandlerThread = new HandlerThread("Transformer:Internal"); internalHandlerThread = new HandlerThread("Transformer:Internal");
...@@ -349,10 +352,15 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -349,10 +352,15 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
if (exception != null) { if (exception != null) {
TransformationException finalException = exception;
applicationHandler.post(
() ->
listener.onTransformationError( listener.onTransformationError(
transformationResultBuilder.setTransformationException(exception).build(), exception); transformationResultBuilder.setTransformationException(finalException).build(),
finalException));
} else { } else {
listener.onTransformationCompleted(transformationResultBuilder.build()); applicationHandler.post(
() -> listener.onTransformationCompleted(transformationResultBuilder.build()));
} }
} }
......
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