Search in sources :

Example 1 with TransformationRequest

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

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(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 2 with TransformationRequest

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

the class TransformerAudioRenderer method ensureConfigured.

/**
 * Attempts to read the input format and to initialize the {@link SamplePipeline}.
 */
@Override
protected boolean ensureConfigured() throws TransformationException {
    if (samplePipeline != null) {
        return true;
    }
    FormatHolder formatHolder = getFormatHolder();
    @ReadDataResult int result = readSource(formatHolder, decoderInputBuffer, /* readFlags= */
    FLAG_REQUIRE_FORMAT);
    if (result != C.RESULT_FORMAT_READ) {
        return false;
    }
    Format inputFormat = checkNotNull(formatHolder.format);
    if (shouldPassthrough(inputFormat)) {
        samplePipeline = new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener);
    } else {
        samplePipeline = new AudioTranscodingSamplePipeline(inputFormat, transformationRequest, decoderFactory, encoderFactory, muxerWrapper.getSupportedSampleMimeTypes(getTrackType()), fallbackListener);
    }
    return true;
}
Also used : Format(com.google.android.exoplayer2.Format) ReadDataResult(com.google.android.exoplayer2.source.SampleStream.ReadDataResult) FormatHolder(com.google.android.exoplayer2.FormatHolder)

Example 3 with TransformationRequest

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

the class TransformerVideoRenderer method ensureConfigured.

/**
 * Attempts to read the input format and to initialize the {@link SamplePipeline}.
 */
@Override
protected boolean ensureConfigured() throws TransformationException {
    if (samplePipeline != null) {
        return true;
    }
    FormatHolder formatHolder = getFormatHolder();
    @ReadDataResult int result = readSource(formatHolder, decoderInputBuffer, /* readFlags= */
    FLAG_REQUIRE_FORMAT);
    if (result != C.RESULT_FORMAT_READ) {
        return false;
    }
    Format inputFormat = checkNotNull(formatHolder.format);
    if (shouldPassthrough(inputFormat)) {
        samplePipeline = new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener);
    } else {
        samplePipeline = new VideoTranscodingSamplePipeline(context, inputFormat, transformationRequest, decoderFactory, encoderFactory, muxerWrapper.getSupportedSampleMimeTypes(getTrackType()), fallbackListener, debugViewProvider);
    }
    if (transformationRequest.flattenForSlowMotion) {
        sefSlowMotionFlattener = new SefSlowMotionFlattener(inputFormat);
    }
    return true;
}
Also used : Format(com.google.android.exoplayer2.Format) ReadDataResult(com.google.android.exoplayer2.source.SampleStream.ReadDataResult) FormatHolder(com.google.android.exoplayer2.FormatHolder)

Example 4 with TransformationRequest

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

the class Transformer method startTransformation.

private void startTransformation(MediaItem mediaItem, Muxer muxer) {
    verifyApplicationThread();
    if (player != null) {
        throw new IllegalStateException("There is already a transformation in progress.");
    }
    MuxerWrapper muxerWrapper = new MuxerWrapper(muxer, muxerFactory, containerMimeType);
    this.muxerWrapper = muxerWrapper;
    DefaultTrackSelector trackSelector = new DefaultTrackSelector(context);
    trackSelector.setParameters(new DefaultTrackSelector.ParametersBuilder(context).setForceHighestSupportedBitrate(true).build());
    // Arbitrarily decrease buffers for playback so that samples start being sent earlier to the
    // muxer (rebuffers are less problematic for the transformation use case).
    DefaultLoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(DEFAULT_MIN_BUFFER_MS, DEFAULT_MAX_BUFFER_MS, DEFAULT_BUFFER_FOR_PLAYBACK_MS / 10, DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS / 10).build();
    ExoPlayer.Builder playerBuilder = new ExoPlayer.Builder(context, new TransformerRenderersFactory(context, muxerWrapper, removeAudio, removeVideo, transformationRequest, encoderFactory, decoderFactory, new FallbackListener(mediaItem, listeners, transformationRequest), debugViewProvider)).setMediaSourceFactory(mediaSourceFactory).setTrackSelector(trackSelector).setLoadControl(loadControl).setLooper(looper);
    if (clock != Clock.DEFAULT) {
        // Transformer.Builder#setClock is also @VisibleForTesting, so if we're using a non-default
        // clock we must be in a test context.
        @SuppressWarnings("VisibleForTests") ExoPlayer.Builder unusedForAnnotation = playerBuilder.setClock(clock);
    }
    player = playerBuilder.build();
    player.setMediaItem(mediaItem);
    player.addListener(new TransformerPlayerListener(mediaItem, muxerWrapper));
    player.prepare();
    progressState = PROGRESS_STATE_WAITING_FOR_AVAILABILITY;
}
Also used : DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) DefaultLoadControl(com.google.android.exoplayer2.DefaultLoadControl)

Example 5 with TransformationRequest

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

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(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Aggregations

Format (com.google.android.exoplayer2.Format)2 FormatHolder (com.google.android.exoplayer2.FormatHolder)2 MediaItem (com.google.android.exoplayer2.MediaItem)2 ReadDataResult (com.google.android.exoplayer2.source.SampleStream.ReadDataResult)2 Test (org.junit.Test)2 DefaultLoadControl (com.google.android.exoplayer2.DefaultLoadControl)1 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)1 DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)1