Search in sources :

Example 21 with Transformer

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

the class TransformerEndToEndTest method startTransformation_withAudioDecoderFormatUnsupported_completesWithError.

@Test
public void startTransformation_withAudioDecoderFormatUnsupported_completesWithError() 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_DECODER);
    transformer.startTransformation(mediaItem, outputPath);
    TransformationException exception = TransformerTestRunner.runUntilError(transformer);
    assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
    assertThat(exception.errorCode).isEqualTo(TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED);
}
Also used : MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 22 with Transformer

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

the class TransformerEndToEndTest method getProgress_unknownDuration_returnsConsistentStates.

@Test
public void getProgress_unknownDuration_returnsConsistentStates() throws Exception {
    Transformer transformer = createTransformerBuilder().build();
    MediaItem mediaItem = MediaItem.fromUri(URI_PREFIX + FILE_UNKNOWN_DURATION);
    AtomicInteger previousProgressState = new AtomicInteger(PROGRESS_STATE_WAITING_FOR_AVAILABILITY);
    AtomicBoolean foundInconsistentState = new AtomicBoolean();
    Handler progressHandler = new Handler(Looper.myLooper()) {

        @Override
        public void handleMessage(Message msg) {
            @Transformer.ProgressState int progressState = transformer.getProgress(progressHolder);
            switch(previousProgressState.get()) {
                case PROGRESS_STATE_WAITING_FOR_AVAILABILITY:
                    break;
                case PROGRESS_STATE_UNAVAILABLE:
                case // See [Internal: b/176145097].
                PROGRESS_STATE_AVAILABLE:
                    if (progressState == PROGRESS_STATE_WAITING_FOR_AVAILABILITY) {
                        foundInconsistentState.set(true);
                        return;
                    }
                    break;
                case PROGRESS_STATE_NO_TRANSFORMATION:
                    if (progressState != PROGRESS_STATE_NO_TRANSFORMATION) {
                        foundInconsistentState.set(true);
                        return;
                    }
                    break;
                default:
                    throw new IllegalStateException();
            }
            previousProgressState.set(progressState);
            sendEmptyMessage(0);
        }
    };
    transformer.startTransformation(mediaItem, outputPath);
    progressHandler.sendEmptyMessage(0);
    TransformerTestRunner.runUntilCompleted(transformer);
    assertThat(foundInconsistentState.get()).isFalse();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Message(android.os.Message) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MediaItem(androidx.media3.common.MediaItem) Handler(android.os.Handler) Test(org.junit.Test)

Example 23 with Transformer

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

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(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 24 with Transformer

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

the class TransformerEndToEndTest method startTransformation_audioOnlyPassthrough_completesSuccessfully.

@Test
public void startTransformation_audioOnlyPassthrough_completesSuccessfully() throws Exception {
    Transformer transformer = createTransformerBuilder().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));
}
Also used : MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 25 with Transformer

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

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(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