Commit 83074c0d by kimvde Committed by microkatz

Rename Transformer callbacks

PiperOrigin-RevId: 506890459
parent eb4b6f81
...@@ -108,7 +108,7 @@ public interface AssetLoader { ...@@ -108,7 +108,7 @@ 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.
*/ */
void onTransformationError(TransformationException exception); void onError(TransformationException exception);
} }
/** /**
......
...@@ -189,8 +189,8 @@ import java.util.concurrent.atomic.AtomicLong; ...@@ -189,8 +189,8 @@ import java.util.concurrent.atomic.AtomicLong;
} }
@Override @Override
public void onTransformationError(TransformationException exception) { public void onError(TransformationException exception) {
compositeAssetLoaderListener.onTransformationError(exception); compositeAssetLoaderListener.onError(exception);
} }
private final class SampleConsumerWrapper implements SampleConsumer { private final class SampleConsumerWrapper implements SampleConsumer {
......
...@@ -103,7 +103,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -103,7 +103,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
} }
} catch (TransformationException e) { } catch (TransformationException e) {
isTransformationRunning = false; isTransformationRunning = false;
assetLoaderListener.onTransformationError(e); assetLoaderListener.onError(e);
} }
} }
......
...@@ -300,7 +300,7 @@ public final class ExoPlayerAssetLoader implements AssetLoader { ...@@ -300,7 +300,7 @@ public final class ExoPlayerAssetLoader implements AssetLoader {
trackCount++; trackCount++;
} }
if (trackCount == 0) { if (trackCount == 0) {
assetLoaderListener.onTransformationError( assetLoaderListener.onError(
TransformationException.createForAssetLoader( TransformationException.createForAssetLoader(
new IllegalStateException("The asset loader has no track to output."), new IllegalStateException("The asset loader has no track to output."),
ERROR_CODE_FAILED_RUNTIME_CHECK)); ERROR_CODE_FAILED_RUNTIME_CHECK));
...@@ -320,8 +320,7 @@ public final class ExoPlayerAssetLoader implements AssetLoader { ...@@ -320,8 +320,7 @@ public final class ExoPlayerAssetLoader implements AssetLoader {
checkNotNull( checkNotNull(
TransformationException.NAME_TO_ERROR_CODE.getOrDefault( TransformationException.NAME_TO_ERROR_CODE.getOrDefault(
error.getErrorCodeName(), ERROR_CODE_UNSPECIFIED)); error.getErrorCodeName(), ERROR_CODE_UNSPECIFIED));
assetLoaderListener.onTransformationError( assetLoaderListener.onError(TransformationException.createForAssetLoader(error, errorCode));
TransformationException.createForAssetLoader(error, errorCode));
} }
} }
} }
...@@ -100,9 +100,9 @@ public final class ImageAssetLoader implements AssetLoader { ...@@ -100,9 +100,9 @@ public final class ImageAssetLoader implements AssetLoader {
bitmap, editedMediaItem.durationUs, editedMediaItem.frameRate); bitmap, editedMediaItem.durationUs, editedMediaItem.frameRate);
sampleConsumer.signalEndOfVideoInput(); sampleConsumer.signalEndOfVideoInput();
} catch (TransformationException e) { } catch (TransformationException e) {
listener.onTransformationError(e); listener.onError(e);
} catch (RuntimeException e) { } catch (RuntimeException e) {
listener.onTransformationError( listener.onError(
TransformationException.createForAssetLoader(e, ERROR_CODE_UNSPECIFIED)); TransformationException.createForAssetLoader(e, ERROR_CODE_UNSPECIFIED));
} }
progress = 100; progress = 100;
...@@ -110,7 +110,7 @@ public final class ImageAssetLoader implements AssetLoader { ...@@ -110,7 +110,7 @@ public final class ImageAssetLoader implements AssetLoader {
@Override @Override
public void onFailure(Throwable t) { public void onFailure(Throwable t) {
listener.onTransformationError( listener.onError(
TransformationException.createForAssetLoader(t, ERROR_CODE_IO_UNSPECIFIED)); TransformationException.createForAssetLoader(t, ERROR_CODE_IO_UNSPECIFIED));
} }
}, },
......
...@@ -53,7 +53,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -53,7 +53,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
void onEnded(long durationMs, long fileSizeBytes); void onEnded(long durationMs, long fileSizeBytes);
void onTransformationError(TransformationException transformationException); void onError(TransformationException transformationException);
} }
/** /**
...@@ -276,7 +276,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -276,7 +276,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
return; return;
} }
isAborted = true; isAborted = true;
listener.onTransformationError( listener.onError(
TransformationException.createForMuxer( TransformationException.createForMuxer(
new IllegalStateException( new IllegalStateException(
"No output sample written in the last " "No output sample written in the last "
......
...@@ -217,7 +217,7 @@ public final class Transformer { ...@@ -217,7 +217,7 @@ public final class Transformer {
} }
/** /**
* Adds a {@link Transformer.Listener} to listen to the transformation events. * Adds a {@link Transformer.Listener} to listen to the export events.
* *
* <p>This is equivalent to {@link Transformer#addListener(Listener)}. * <p>This is equivalent to {@link Transformer#addListener(Listener)}.
* *
...@@ -443,19 +443,17 @@ public final class Transformer { ...@@ -443,19 +443,17 @@ public final class Transformer {
} }
} }
/** A listener for the transformation events. */ /** A listener for the export events. */
public interface Listener { public interface Listener {
/** /**
* @deprecated Use {@link #onTransformationCompleted(Composition, TransformationResult)} * @deprecated Use {@link #onCompleted(Composition, TransformationResult)} instead.
* instead.
*/ */
@Deprecated @Deprecated
default void onTransformationCompleted(MediaItem inputMediaItem) {} default void onTransformationCompleted(MediaItem inputMediaItem) {}
/** /**
* @deprecated Use {@link #onTransformationCompleted(Composition, TransformationResult)} * @deprecated Use {@link #onCompleted(Composition, TransformationResult)} instead.
* instead.
*/ */
@Deprecated @Deprecated
default void onTransformationCompleted(MediaItem inputMediaItem, TransformationResult result) { default void onTransformationCompleted(MediaItem inputMediaItem, TransformationResult result) {
...@@ -463,26 +461,26 @@ public final class Transformer { ...@@ -463,26 +461,26 @@ public final class Transformer {
} }
/** /**
* Called when the transformation is completed successfully. * Called when the export is completed successfully.
* *
* @param composition The {@link Composition} for which the transformation is completed. * @param composition The {@link Composition} for which the export is completed.
* @param result The {@link TransformationResult} of the transformation. * @param result The {@link TransformationResult} of the export.
*/ */
default void onTransformationCompleted(Composition composition, TransformationResult result) { default void onCompleted(Composition composition, TransformationResult result) {
MediaItem mediaItem = composition.sequences.get(0).editedMediaItems.get(0).mediaItem; MediaItem mediaItem = composition.sequences.get(0).editedMediaItems.get(0).mediaItem;
onTransformationCompleted(mediaItem, result); onTransformationCompleted(mediaItem, result);
} }
/** /**
* @deprecated Use {@link #onTransformationError(Composition, TransformationResult, * @deprecated Use {@link #onError(Composition, TransformationResult, TransformationException)}
* TransformationException)} instead. * instead.
*/ */
@Deprecated @Deprecated
default void onTransformationError(MediaItem inputMediaItem, Exception exception) {} default void onTransformationError(MediaItem inputMediaItem, Exception exception) {}
/** /**
* @deprecated Use {@link #onTransformationError(Composition, TransformationResult, * @deprecated Use {@link #onError(Composition, TransformationResult, TransformationException)}
* TransformationException)} instead. * instead.
*/ */
@Deprecated @Deprecated
default void onTransformationError( default void onTransformationError(
...@@ -491,8 +489,8 @@ public final class Transformer { ...@@ -491,8 +489,8 @@ public final class Transformer {
} }
/** /**
* @deprecated Use {@link #onTransformationError(Composition, TransformationResult, * @deprecated Use {@link #onError(Composition, TransformationResult, TransformationException)}
* TransformationException)} instead. * instead.
*/ */
@Deprecated @Deprecated
default void onTransformationError( default void onTransformationError(
...@@ -501,13 +499,15 @@ public final class Transformer { ...@@ -501,13 +499,15 @@ public final class Transformer {
} }
/** /**
* Called if an exception occurs during the transformation. * Called if an exception occurs during the export.
* *
* @param composition The {@link Composition} for which the exception occurs. * @param composition The {@link Composition} for which the exception occurs.
* @param result The {@link TransformationResult} of the transformation. * @param result The {@link TransformationResult} of the export.
* @param exception The {@link TransformationException} describing the exception. * @param exception The {@link TransformationException} describing the exception. This is the
* same instance as the {@linkplain TransformationResult#transformationException exception}
* in {@code result}.
*/ */
default void onTransformationError( default void onError(
Composition composition, TransformationResult result, TransformationException exception) { Composition composition, TransformationResult result, TransformationException exception) {
MediaItem mediaItem = composition.sequences.get(0).editedMediaItems.get(0).mediaItem; MediaItem mediaItem = composition.sequences.get(0).editedMediaItems.get(0).mediaItem;
onTransformationError(mediaItem, result, exception); onTransformationError(mediaItem, result, exception);
...@@ -527,7 +527,7 @@ public final class Transformer { ...@@ -527,7 +527,7 @@ public final class Transformer {
* Called when falling back to an alternative {@link TransformationRequest} or changing the * Called when falling back to an alternative {@link TransformationRequest} or changing the
* video frames' resolution is necessary to comply with muxer or device constraints. * video frames' resolution is necessary to comply with muxer or device constraints.
* *
* @param composition The {@link Composition} for which the transformation is requested. * @param composition The {@link Composition} for which the export is requested.
* @param originalTransformationRequest The unsupported {@link TransformationRequest} used when * @param originalTransformationRequest The unsupported {@link TransformationRequest} used when
* building {@link Transformer}. * building {@link Transformer}.
* @param fallbackTransformationRequest The alternative {@link TransformationRequest}, with * @param fallbackTransformationRequest The alternative {@link TransformationRequest}, with
...@@ -644,7 +644,7 @@ public final class Transformer { ...@@ -644,7 +644,7 @@ public final class Transformer {
} }
/** /**
* Adds a {@link Transformer.Listener} to listen to the transformation events. * Adds a {@link Transformer.Listener} to listen to the export events.
* *
* @param listener A {@link Transformer.Listener}. * @param listener A {@link Transformer.Listener}.
* @throws IllegalStateException If this method is called from the wrong thread. * @throws IllegalStateException If this method is called from the wrong thread.
...@@ -788,8 +788,8 @@ public final class Transformer { ...@@ -788,8 +788,8 @@ public final class Transformer {
* Returns the current {@link ProgressState} and updates {@code progressHolder} with the current * Returns the current {@link ProgressState} and updates {@code progressHolder} with the current
* progress if it is {@link #PROGRESS_STATE_AVAILABLE available}. * progress if it is {@link #PROGRESS_STATE_AVAILABLE available}.
* *
* <p>After a transformation {@linkplain Listener#onTransformationCompleted(Composition, * <p>After a transformation {@linkplain Listener#onCompleted(Composition, TransformationResult)
* TransformationResult) completes}, this method returns {@link #PROGRESS_STATE_NOT_STARTED}. * completes}, this method returns {@link #PROGRESS_STATE_NOT_STARTED}.
* *
* @param progressHolder A {@link ProgressHolder}, updated to hold the percentage progress if * @param progressHolder A {@link ProgressHolder}, updated to hold the percentage progress if
* {@link #PROGRESS_STATE_AVAILABLE available}. * {@link #PROGRESS_STATE_AVAILABLE available}.
...@@ -835,22 +835,21 @@ public final class Transformer { ...@@ -835,22 +835,21 @@ public final class Transformer {
} }
@Override @Override
public void onTransformationCompleted(TransformationResult transformationResult) { public void onCompleted(TransformationResult transformationResult) {
// TODO(b/213341814): Add event flags for Transformer events. // TODO(b/213341814): Add event flags for Transformer events.
transformerInternal = null; transformerInternal = null;
listeners.queueEvent( listeners.queueEvent(
/* eventFlag= */ C.INDEX_UNSET, /* eventFlag= */ C.INDEX_UNSET,
listener -> listener.onTransformationCompleted(composition, transformationResult)); listener -> listener.onCompleted(composition, transformationResult));
listeners.flushEvents(); listeners.flushEvents();
} }
@Override @Override
public void onTransformationError( public void onError(TransformationResult result, TransformationException exception) {
TransformationResult result, TransformationException exception) {
transformerInternal = null; transformerInternal = null;
listeners.queueEvent( listeners.queueEvent(
/* eventFlag= */ C.INDEX_UNSET, /* eventFlag= */ C.INDEX_UNSET,
listener -> listener.onTransformationError(composition, result, exception)); listener -> listener.onError(composition, result, exception));
listeners.flushEvents(); listeners.flushEvents();
} }
} }
......
...@@ -57,9 +57,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -57,9 +57,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
public interface Listener { public interface Listener {
void onTransformationCompleted(TransformationResult result); void onCompleted(TransformationResult result);
void onTransformationError(TransformationResult result, TransformationException exception); void onError(TransformationResult result, TransformationException exception);
} }
/** /**
...@@ -299,12 +299,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -299,12 +299,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
TransformationException finalException = exception; TransformationException finalException = exception;
applicationHandler.post( applicationHandler.post(
() -> () ->
listener.onTransformationError( listener.onError(
transformationResultBuilder.setTransformationException(finalException).build(), transformationResultBuilder.setTransformationException(finalException).build(),
finalException)); finalException));
} else { } else {
applicationHandler.post( applicationHandler.post(() -> listener.onCompleted(transformationResultBuilder.build()));
() -> listener.onTransformationCompleted(transformationResultBuilder.build()));
} }
} }
...@@ -334,7 +333,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -334,7 +333,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
// AssetLoader.Listener and MuxerWrapper.Listener implementation. // AssetLoader.Listener and MuxerWrapper.Listener implementation.
@Override @Override
public void onTransformationError(TransformationException transformationException) { public void onError(TransformationException transformationException) {
internalHandler internalHandler
.obtainMessage(MSG_END, END_REASON_ERROR, /* unused */ 0, transformationException) .obtainMessage(MSG_END, END_REASON_ERROR, /* unused */ 0, transformationException)
.sendToTarget(); .sendToTarget();
...@@ -350,7 +349,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -350,7 +349,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Override @Override
public void onTrackCount(int trackCount) { public void onTrackCount(int trackCount) {
if (trackCount <= 0) { if (trackCount <= 0) {
onTransformationError( onError(
TransformationException.createForAssetLoader( TransformationException.createForAssetLoader(
new IllegalStateException("AssetLoader instances must provide at least 1 track."), new IllegalStateException("AssetLoader instances must provide at least 1 track."),
ERROR_CODE_FAILED_RUNTIME_CHECK)); ERROR_CODE_FAILED_RUNTIME_CHECK));
...@@ -492,7 +491,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -492,7 +491,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
firstEditedMediaItem.effects.frameProcessorFactory, firstEditedMediaItem.effects.frameProcessorFactory,
encoderFactory, encoderFactory,
muxerWrapper, muxerWrapper,
/* errorConsumer= */ this::onTransformationError, /* errorConsumer= */ this::onError,
fallbackListener, fallbackListener,
debugViewProvider); debugViewProvider);
} else { } else {
......
...@@ -85,7 +85,7 @@ public class ExoPlayerAssetLoaderTest { ...@@ -85,7 +85,7 @@ public class ExoPlayerAssetLoaderTest {
} }
@Override @Override
public void onTransformationError(TransformationException e) { public void onError(TransformationException e) {
exceptionRef.set(e); exceptionRef.set(e);
} }
......
...@@ -392,10 +392,10 @@ public final class TransformerEndToEndTest { ...@@ -392,10 +392,10 @@ public final class TransformerEndToEndTest {
transformer.startTransformation(mediaItem, outputPath); transformer.startTransformation(mediaItem, outputPath);
TransformerTestRunner.runLooper(transformer); TransformerTestRunner.runLooper(transformer);
verify(mockListener1).onTransformationCompleted(compositionArgumentCaptor.capture(), any()); verify(mockListener1).onCompleted(compositionArgumentCaptor.capture(), any());
Composition composition = compositionArgumentCaptor.getValue(); Composition composition = compositionArgumentCaptor.getValue();
verify(mockListener2).onTransformationCompleted(eq(composition), any()); verify(mockListener2).onCompleted(eq(composition), any());
verify(mockListener3).onTransformationCompleted(eq(composition), any()); verify(mockListener3).onCompleted(eq(composition), any());
} }
@Test @Test
...@@ -418,11 +418,10 @@ public final class TransformerEndToEndTest { ...@@ -418,11 +418,10 @@ public final class TransformerEndToEndTest {
assertThrows( assertThrows(
TransformationException.class, () -> TransformerTestRunner.runLooper(transformer)); TransformationException.class, () -> TransformerTestRunner.runLooper(transformer));
verify(mockListener1) verify(mockListener1).onError(compositionArgumentCaptor.capture(), any(), eq(exception));
.onTransformationError(compositionArgumentCaptor.capture(), any(), eq(exception));
Composition composition = compositionArgumentCaptor.getValue(); Composition composition = compositionArgumentCaptor.getValue();
verify(mockListener2).onTransformationError(eq(composition), any(), eq(exception)); verify(mockListener2).onError(eq(composition), any(), eq(exception));
verify(mockListener3).onTransformationError(eq(composition), any(), eq(exception)); verify(mockListener3).onError(eq(composition), any(), eq(exception));
} }
@Test @Test
...@@ -579,10 +578,9 @@ public final class TransformerEndToEndTest { ...@@ -579,10 +578,9 @@ public final class TransformerEndToEndTest {
transformer2.startTransformation(mediaItem, outputPath); transformer2.startTransformation(mediaItem, outputPath);
TransformerTestRunner.runLooper(transformer2); TransformerTestRunner.runLooper(transformer2);
verify(mockListener1).onTransformationCompleted(compositionArgumentCaptor.capture(), any()); verify(mockListener1).onCompleted(compositionArgumentCaptor.capture(), any());
verify(mockListener2, never()).onTransformationCompleted(any(Composition.class), any()); verify(mockListener2, never()).onCompleted(any(Composition.class), any());
verify(mockListener3) verify(mockListener3).onCompleted(eq(compositionArgumentCaptor.getValue()), any());
.onTransformationCompleted(eq(compositionArgumentCaptor.getValue()), any());
} }
@Test @Test
......
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