mirror of
https://github.com/samsonjs/media.git
synced 2026-04-19 13:35:47 +00:00
Rename Transformer callbacks
PiperOrigin-RevId: 506890459
This commit is contained in:
parent
0b7679ed88
commit
dce83d70c5
10 changed files with 56 additions and 61 deletions
|
|
@ -110,7 +110,7 @@ public interface AssetLoader {
|
|||
* Called if an error occurs in the asset loader. In this case, the asset loader will be
|
||||
* {@linkplain #release() released} automatically.
|
||||
*/
|
||||
void onTransformationError(TransformationException exception);
|
||||
void onError(TransformationException exception);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -189,8 +189,8 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onTransformationError(TransformationException exception) {
|
||||
compositeAssetLoaderListener.onTransformationError(exception);
|
||||
public void onError(TransformationException exception) {
|
||||
compositeAssetLoaderListener.onError(exception);
|
||||
}
|
||||
|
||||
private final class SampleConsumerWrapper implements SampleConsumer {
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||
}
|
||||
} catch (TransformationException e) {
|
||||
isTransformationRunning = false;
|
||||
assetLoaderListener.onTransformationError(e);
|
||||
assetLoaderListener.onError(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@ public final class ExoPlayerAssetLoader implements AssetLoader {
|
|||
trackCount++;
|
||||
}
|
||||
if (trackCount == 0) {
|
||||
assetLoaderListener.onTransformationError(
|
||||
assetLoaderListener.onError(
|
||||
TransformationException.createForAssetLoader(
|
||||
new IllegalStateException("The asset loader has no track to output."),
|
||||
ERROR_CODE_FAILED_RUNTIME_CHECK));
|
||||
|
|
@ -322,8 +322,7 @@ public final class ExoPlayerAssetLoader implements AssetLoader {
|
|||
checkNotNull(
|
||||
TransformationException.NAME_TO_ERROR_CODE.getOrDefault(
|
||||
error.getErrorCodeName(), ERROR_CODE_UNSPECIFIED));
|
||||
assetLoaderListener.onTransformationError(
|
||||
TransformationException.createForAssetLoader(error, errorCode));
|
||||
assetLoaderListener.onError(TransformationException.createForAssetLoader(error, errorCode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,9 +102,9 @@ public final class ImageAssetLoader implements AssetLoader {
|
|||
bitmap, editedMediaItem.durationUs, editedMediaItem.frameRate);
|
||||
sampleConsumer.signalEndOfVideoInput();
|
||||
} catch (TransformationException e) {
|
||||
listener.onTransformationError(e);
|
||||
listener.onError(e);
|
||||
} catch (RuntimeException e) {
|
||||
listener.onTransformationError(
|
||||
listener.onError(
|
||||
TransformationException.createForAssetLoader(e, ERROR_CODE_UNSPECIFIED));
|
||||
}
|
||||
progress = 100;
|
||||
|
|
@ -112,7 +112,7 @@ public final class ImageAssetLoader implements AssetLoader {
|
|||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
listener.onTransformationError(
|
||||
listener.onError(
|
||||
TransformationException.createForAssetLoader(t, ERROR_CODE_IO_UNSPECIFIED));
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||
|
||||
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;
|
|||
return;
|
||||
}
|
||||
isAborted = true;
|
||||
listener.onTransformationError(
|
||||
listener.onError(
|
||||
TransformationException.createForMuxer(
|
||||
new IllegalStateException(
|
||||
"No output sample written in the last "
|
||||
|
|
|
|||
|
|
@ -219,7 +219,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)}.
|
||||
*
|
||||
|
|
@ -445,19 +445,17 @@ public final class Transformer {
|
|||
}
|
||||
}
|
||||
|
||||
/** A listener for the transformation events. */
|
||||
/** A listener for the export events. */
|
||||
public interface Listener {
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #onTransformationCompleted(Composition, TransformationResult)}
|
||||
* instead.
|
||||
* @deprecated Use {@link #onCompleted(Composition, TransformationResult)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
default void onTransformationCompleted(MediaItem inputMediaItem) {}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #onTransformationCompleted(Composition, TransformationResult)}
|
||||
* instead.
|
||||
* @deprecated Use {@link #onCompleted(Composition, TransformationResult)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
default void onTransformationCompleted(MediaItem inputMediaItem, TransformationResult result) {
|
||||
|
|
@ -465,26 +463,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 result The {@link TransformationResult} of the transformation.
|
||||
* @param composition The {@link Composition} for which the export is completed.
|
||||
* @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;
|
||||
onTransformationCompleted(mediaItem, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #onTransformationError(Composition, TransformationResult,
|
||||
* TransformationException)} instead.
|
||||
* @deprecated Use {@link #onError(Composition, TransformationResult, TransformationException)}
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
default void onTransformationError(MediaItem inputMediaItem, Exception exception) {}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #onTransformationError(Composition, TransformationResult,
|
||||
* TransformationException)} instead.
|
||||
* @deprecated Use {@link #onError(Composition, TransformationResult, TransformationException)}
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
default void onTransformationError(
|
||||
|
|
@ -493,8 +491,8 @@ public final class Transformer {
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #onTransformationError(Composition, TransformationResult,
|
||||
* TransformationException)} instead.
|
||||
* @deprecated Use {@link #onError(Composition, TransformationResult, TransformationException)}
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
default void onTransformationError(
|
||||
|
|
@ -503,13 +501,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 result The {@link TransformationResult} of the transformation.
|
||||
* @param exception The {@link TransformationException} describing the exception.
|
||||
* @param result The {@link TransformationResult} of the export.
|
||||
* @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) {
|
||||
MediaItem mediaItem = composition.sequences.get(0).editedMediaItems.get(0).mediaItem;
|
||||
onTransformationError(mediaItem, result, exception);
|
||||
|
|
@ -529,7 +529,7 @@ public final class Transformer {
|
|||
* Called when falling back to an alternative {@link TransformationRequest} or changing the
|
||||
* 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
|
||||
* building {@link Transformer}.
|
||||
* @param fallbackTransformationRequest The alternative {@link TransformationRequest}, with
|
||||
|
|
@ -646,7 +646,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}.
|
||||
* @throws IllegalStateException If this method is called from the wrong thread.
|
||||
|
|
@ -790,8 +790,8 @@ public final class Transformer {
|
|||
* Returns the current {@link ProgressState} and updates {@code progressHolder} with the current
|
||||
* progress if it is {@link #PROGRESS_STATE_AVAILABLE available}.
|
||||
*
|
||||
* <p>After a transformation {@linkplain Listener#onTransformationCompleted(Composition,
|
||||
* TransformationResult) completes}, this method returns {@link #PROGRESS_STATE_NOT_STARTED}.
|
||||
* <p>After a transformation {@linkplain Listener#onCompleted(Composition, TransformationResult)
|
||||
* completes}, this method returns {@link #PROGRESS_STATE_NOT_STARTED}.
|
||||
*
|
||||
* @param progressHolder A {@link ProgressHolder}, updated to hold the percentage progress if
|
||||
* {@link #PROGRESS_STATE_AVAILABLE available}.
|
||||
|
|
@ -837,22 +837,21 @@ public final class Transformer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onTransformationCompleted(TransformationResult transformationResult) {
|
||||
public void onCompleted(TransformationResult transformationResult) {
|
||||
// TODO(b/213341814): Add event flags for Transformer events.
|
||||
transformerInternal = null;
|
||||
listeners.queueEvent(
|
||||
/* eventFlag= */ C.INDEX_UNSET,
|
||||
listener -> listener.onTransformationCompleted(composition, transformationResult));
|
||||
listener -> listener.onCompleted(composition, transformationResult));
|
||||
listeners.flushEvents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransformationError(
|
||||
TransformationResult result, TransformationException exception) {
|
||||
public void onError(TransformationResult result, TransformationException exception) {
|
||||
transformerInternal = null;
|
||||
listeners.queueEvent(
|
||||
/* eventFlag= */ C.INDEX_UNSET,
|
||||
listener -> listener.onTransformationError(composition, result, exception));
|
||||
listener -> listener.onError(composition, result, exception));
|
||||
listeners.flushEvents();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,9 +57,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
|
||||
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;
|
|||
TransformationException finalException = exception;
|
||||
applicationHandler.post(
|
||||
() ->
|
||||
listener.onTransformationError(
|
||||
listener.onError(
|
||||
transformationResultBuilder.setTransformationException(finalException).build(),
|
||||
finalException));
|
||||
} else {
|
||||
applicationHandler.post(
|
||||
() -> listener.onTransformationCompleted(transformationResultBuilder.build()));
|
||||
applicationHandler.post(() -> listener.onCompleted(transformationResultBuilder.build()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -334,7 +333,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
// AssetLoader.Listener and MuxerWrapper.Listener implementation.
|
||||
|
||||
@Override
|
||||
public void onTransformationError(TransformationException transformationException) {
|
||||
public void onError(TransformationException transformationException) {
|
||||
internalHandler
|
||||
.obtainMessage(MSG_END, END_REASON_ERROR, /* unused */ 0, transformationException)
|
||||
.sendToTarget();
|
||||
|
|
@ -350,7 +349,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
@Override
|
||||
public void onTrackCount(int trackCount) {
|
||||
if (trackCount <= 0) {
|
||||
onTransformationError(
|
||||
onError(
|
||||
TransformationException.createForAssetLoader(
|
||||
new IllegalStateException("AssetLoader instances must provide at least 1 track."),
|
||||
ERROR_CODE_FAILED_RUNTIME_CHECK));
|
||||
|
|
@ -492,7 +491,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||
firstEditedMediaItem.effects.frameProcessorFactory,
|
||||
encoderFactory,
|
||||
muxerWrapper,
|
||||
/* errorConsumer= */ this::onTransformationError,
|
||||
/* errorConsumer= */ this::onError,
|
||||
fallbackListener,
|
||||
debugViewProvider);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public class ExoPlayerAssetLoaderTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onTransformationError(TransformationException e) {
|
||||
public void onError(TransformationException e) {
|
||||
exceptionRef.set(e);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -392,10 +392,10 @@ public final class TransformerEndToEndTest {
|
|||
transformer.startTransformation(mediaItem, outputPath);
|
||||
TransformerTestRunner.runLooper(transformer);
|
||||
|
||||
verify(mockListener1).onTransformationCompleted(compositionArgumentCaptor.capture(), any());
|
||||
verify(mockListener1).onCompleted(compositionArgumentCaptor.capture(), any());
|
||||
Composition composition = compositionArgumentCaptor.getValue();
|
||||
verify(mockListener2).onTransformationCompleted(eq(composition), any());
|
||||
verify(mockListener3).onTransformationCompleted(eq(composition), any());
|
||||
verify(mockListener2).onCompleted(eq(composition), any());
|
||||
verify(mockListener3).onCompleted(eq(composition), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -418,11 +418,10 @@ public final class TransformerEndToEndTest {
|
|||
assertThrows(
|
||||
TransformationException.class, () -> TransformerTestRunner.runLooper(transformer));
|
||||
|
||||
verify(mockListener1)
|
||||
.onTransformationError(compositionArgumentCaptor.capture(), any(), eq(exception));
|
||||
verify(mockListener1).onError(compositionArgumentCaptor.capture(), any(), eq(exception));
|
||||
Composition composition = compositionArgumentCaptor.getValue();
|
||||
verify(mockListener2).onTransformationError(eq(composition), any(), eq(exception));
|
||||
verify(mockListener3).onTransformationError(eq(composition), any(), eq(exception));
|
||||
verify(mockListener2).onError(eq(composition), any(), eq(exception));
|
||||
verify(mockListener3).onError(eq(composition), any(), eq(exception));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -579,10 +578,9 @@ public final class TransformerEndToEndTest {
|
|||
transformer2.startTransformation(mediaItem, outputPath);
|
||||
TransformerTestRunner.runLooper(transformer2);
|
||||
|
||||
verify(mockListener1).onTransformationCompleted(compositionArgumentCaptor.capture(), any());
|
||||
verify(mockListener2, never()).onTransformationCompleted(any(Composition.class), any());
|
||||
verify(mockListener3)
|
||||
.onTransformationCompleted(eq(compositionArgumentCaptor.getValue()), any());
|
||||
verify(mockListener1).onCompleted(compositionArgumentCaptor.capture(), any());
|
||||
verify(mockListener2, never()).onCompleted(any(Composition.class), any());
|
||||
verify(mockListener3).onCompleted(eq(compositionArgumentCaptor.getValue()), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in a new issue