Search in sources :

Example 36 with Transformer

use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.

the class TransformerEndToEndTest method startTransformation_removeAudio_completesSuccessfully.

@Test
public void startTransformation_removeAudio_completesSuccessfully() throws Exception {
    Transformer transformer = createTransformerBuilder().setRemoveAudio(true).build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_VIDEO);
    transformer.startTransformation(mediaItem, outputPath);
    TransformerTestRunner.runUntilCompleted(transformer);
    DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_AUDIO_VIDEO + ".noaudio"));
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 37 with Transformer

use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.

the class TransformerEndToEndTest method startTransformation_withMultipleListeners_callsEachOnError.

@Test
public void startTransformation_withMultipleListeners_callsEachOnError() throws Exception {
    Transformer.Listener mockListener1 = mock(Transformer.Listener.class);
    Transformer.Listener mockListener2 = mock(Transformer.Listener.class);
    Transformer.Listener mockListener3 = mock(Transformer.Listener.class);
    Transformer transformer = createTransformerBuilder().addListener(mockListener1).addListener(mockListener2).addListener(mockListener3).setTransformationRequest(new TransformationRequest.Builder().setAudioMimeType(MimeTypes.AUDIO_AAC).build()).build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_UNSUPPORTED_BY_DECODER);
    transformer.startTransformation(mediaItem, outputPath);
    TransformationException exception = TransformerTestRunner.runUntilError(transformer);
    verify(mockListener1, times(1)).onTransformationError(mediaItem, exception);
    verify(mockListener2, times(1)).onTransformationError(mediaItem, exception);
    verify(mockListener3, times(1)).onTransformationError(mediaItem, exception);
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 38 with Transformer

use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.

the class TransformerEndToEndTest method startTransformation_withAudioEncoderFormatUnsupported_completesWithError.

@Test
public void startTransformation_withAudioEncoderFormatUnsupported_completesWithError() throws Exception {
    Transformer transformer = createTransformerBuilder().setTransformationRequest(new TransformationRequest.Builder().setAudioMimeType(// unsupported by encoder, supported by muxer
    MimeTypes.AUDIO_AMR_NB).build()).build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_UNSUPPORTED_BY_MUXER);
    transformer.startTransformation(mediaItem, outputPath);
    TransformationException exception = TransformerTestRunner.runUntilError(transformer);
    assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
    assertThat(exception.errorCode).isEqualTo(TransformationException.ERROR_CODE_OUTPUT_FORMAT_UNSUPPORTED);
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 39 with Transformer

use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.

the class TransformerEndToEndTest method startTransformation_afterCancellation_completesSuccessfully.

// TODO(b/214012830): Add a test to check that the correct exception is thrown when the muxer
// doesn't support the output sample MIME type inferred from the input once it is possible to
// disable fallback.
@Test
public void startTransformation_afterCancellation_completesSuccessfully() throws Exception {
    Transformer transformer = createTransformerBuilder().build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_VIDEO);
    transformer.startTransformation(mediaItem, outputPath);
    transformer.cancel();
    Files.delete(Paths.get(outputPath));
    // This would throw if the previous transformation had not been cancelled.
    transformer.startTransformation(mediaItem, outputPath);
    TransformerTestRunner.runUntilCompleted(transformer);
    DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_AUDIO_VIDEO));
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 40 with Transformer

use of com.google.android.exoplayer2.transformer.Transformer in project ExoPlayer by google.

the class TransformerEndToEndTest method startTransformation_audioAndVideo_completesSuccessfully.

@Test
public void startTransformation_audioAndVideo_completesSuccessfully() throws Exception {
    Transformer transformer = createTransformerBuilder().build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_VIDEO);
    transformer.startTransformation(mediaItem, outputPath);
    TransformerTestRunner.runUntilCompleted(transformer);
    DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_AUDIO_VIDEO));
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)37 MediaItem (com.google.android.exoplayer2.MediaItem)29 Context (android.content.Context)10 AndroidTestUtil.runTransformer (com.google.android.exoplayer2.transformer.AndroidTestUtil.runTransformer)10 Transformer (com.google.android.exoplayer2.transformer.Transformer)10 Handler (android.os.Handler)6 Matrix (android.graphics.Matrix)5 IOException (java.io.IOException)4 Message (android.os.Message)3 Nullable (androidx.annotation.Nullable)3 AndroidTestUtil (com.google.android.exoplayer2.transformer.AndroidTestUtil)3 HashSet (java.util.HashSet)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Uri (android.net.Uri)2 HandlerThread (android.os.HandlerThread)2 TransformationRequest (com.google.android.exoplayer2.transformer.TransformationRequest)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)2