Search in sources :

Example 16 with Transformer

use of androidx.media3.transformer.Transformer in project media by androidx.

the class TransformerEndToEndTest method startTransformation_videoOnlyPassthrough_completesSuccessfully.

@Test
public void startTransformation_videoOnlyPassthrough_completesSuccessfully() throws Exception {
    Transformer transformer = createTransformerBuilder().build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_VIDEO_ONLY);
    transformer.startTransformation(mediaItem, outputPath);
    TransformerTestRunner.runUntilCompleted(transformer);
    DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_VIDEO_ONLY));
}
Also used : MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 17 with Transformer

use of androidx.media3.transformer.Transformer in project media by androidx.

the class TransformerEndToEndTest method startTransformation_audioOnlyTranscoding_completesSuccessfully.

@Test
public void startTransformation_audioOnlyTranscoding_completesSuccessfully() throws Exception {
    Transformer transformer = createTransformerBuilder().setTransformationRequest(new TransformationRequest.Builder().setAudioMimeType(// supported by encoder and muxer
    MimeTypes.AUDIO_AAC).build()).build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_UNSUPPORTED_BY_ENCODER);
    transformer.startTransformation(mediaItem, outputPath);
    TransformerTestRunner.runUntilCompleted(transformer);
    DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_AUDIO_UNSUPPORTED_BY_ENCODER + ".aac"));
}
Also used : MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 18 with Transformer

use of androidx.media3.transformer.Transformer in project media by androidx.

the class TransformerEndToEndTest method startTransformation_afterBuildUponWithListenerRemoved_onlyCallsRemainingListeners.

@Test
public void startTransformation_afterBuildUponWithListenerRemoved_onlyCallsRemainingListeners() throws Exception {
    Transformer.Listener mockListener1 = mock(Transformer.Listener.class);
    Transformer.Listener mockListener2 = mock(Transformer.Listener.class);
    Transformer.Listener mockListener3 = mock(Transformer.Listener.class);
    Transformer transformer1 = createTransformerBuilder().addListener(mockListener1).addListener(mockListener2).addListener(mockListener3).build();
    Transformer transformer2 = transformer1.buildUpon().removeListener(mockListener2).build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_VIDEO);
    transformer2.startTransformation(mediaItem, outputPath);
    TransformerTestRunner.runUntilCompleted(transformer2);
    verify(mockListener1, times(1)).onTransformationCompleted(mediaItem);
    verify(mockListener2, never()).onTransformationCompleted(mediaItem);
    verify(mockListener3, times(1)).onTransformationCompleted(mediaItem);
}
Also used : MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 19 with Transformer

use of androidx.media3.transformer.Transformer in project media by androidx.

the class TransformerEndToEndTest method startTransformation_withAudioMuxerFormatFallback_completesSuccessfully.

@Test
public void startTransformation_withAudioMuxerFormatFallback_completesSuccessfully() throws Exception {
    Transformer.Listener mockListener = mock(Transformer.Listener.class);
    TransformationRequest originalTransformationRequest = new TransformationRequest.Builder().build();
    TransformationRequest fallbackTransformationRequest = new TransformationRequest.Builder().setAudioMimeType(MimeTypes.AUDIO_AAC).build();
    Transformer transformer = createTransformerBuilder().addListener(mockListener).build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_UNSUPPORTED_BY_MUXER);
    transformer.startTransformation(mediaItem, outputPath);
    TransformerTestRunner.runUntilCompleted(transformer);
    DumpFileAsserts.assertOutput(context, testMuxer, getDumpFileName(FILE_AUDIO_UNSUPPORTED_BY_MUXER + ".fallback"));
    verify(mockListener, times(1)).onFallbackApplied(mediaItem, originalTransformationRequest, fallbackTransformationRequest);
}
Also used : MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 20 with Transformer

use of androidx.media3.transformer.Transformer in project media by androidx.

the class TransformerEndToEndTest method startTransformation_withMultipleListeners_callsEachOnFallback.

@Test
public void startTransformation_withMultipleListeners_callsEachOnFallback() throws Exception {
    Transformer.Listener mockListener1 = mock(Transformer.Listener.class);
    Transformer.Listener mockListener2 = mock(Transformer.Listener.class);
    Transformer.Listener mockListener3 = mock(Transformer.Listener.class);
    TransformationRequest originalTransformationRequest = new TransformationRequest.Builder().build();
    TransformationRequest fallbackTransformationRequest = new TransformationRequest.Builder().setAudioMimeType(MimeTypes.AUDIO_AAC).build();
    Transformer transformer = createTransformerBuilder().addListener(mockListener1).addListener(mockListener2).addListener(mockListener3).build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_AUDIO_UNSUPPORTED_BY_MUXER);
    transformer.startTransformation(mediaItem, outputPath);
    TransformerTestRunner.runUntilCompleted(transformer);
    verify(mockListener1, times(1)).onFallbackApplied(mediaItem, originalTransformationRequest, fallbackTransformationRequest);
    verify(mockListener2, times(1)).onFallbackApplied(mediaItem, originalTransformationRequest, fallbackTransformationRequest);
    verify(mockListener3, times(1)).onFallbackApplied(mediaItem, originalTransformationRequest, fallbackTransformationRequest);
}
Also used : MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)45 MediaItem (androidx.media3.common.MediaItem)29 Context (android.content.Context)18 AndroidTestUtil.runTransformer (androidx.media3.transformer.AndroidTestUtil.runTransformer)10 Transformer (androidx.media3.transformer.Transformer)10 Transformer (com.google.android.exoplayer2.transformer.Transformer)10 Matrix (android.graphics.Matrix)9 AndroidTestUtil.runTransformer (com.google.android.exoplayer2.transformer.AndroidTestUtil.runTransformer)8 Handler (android.os.Handler)7 HashSet (java.util.HashSet)7 Nullable (androidx.annotation.Nullable)5 IOException (java.io.IOException)5 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)4 Uri (android.net.Uri)3 Message (android.os.Message)3 AndroidTestUtil (androidx.media3.transformer.AndroidTestUtil)3 AndroidTestUtil (com.google.android.exoplayer2.transformer.AndroidTestUtil)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3