Commit 9ecab028 by samrobinson Committed by Andrew Lewis

Expand and refactor `TransformerInternal#shouldTranscode`.

* Account for `AssetLoader` output types.
* Consider cases that are not audio/video specific.
* Use `Format#sampleMimeType` for track specific conditions to check.
* Untangle `SamplePipeline` initilization from `AssetLoader` state.

PiperOrigin-RevId: 511020865
parent 79d32c24
...@@ -21,6 +21,7 @@ import static com.google.android.exoplayer2.transformer.AssetLoader.SUPPORTED_OU ...@@ -21,6 +21,7 @@ import static com.google.android.exoplayer2.transformer.AssetLoader.SUPPORTED_OU
import static com.google.android.exoplayer2.transformer.ExportException.ERROR_CODE_FAILED_RUNTIME_CHECK; import static com.google.android.exoplayer2.transformer.ExportException.ERROR_CODE_FAILED_RUNTIME_CHECK;
import static com.google.android.exoplayer2.transformer.ExportException.ERROR_CODE_MUXING_FAILED; import static com.google.android.exoplayer2.transformer.ExportException.ERROR_CODE_MUXING_FAILED;
import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_NOT_STARTED; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_NOT_STARTED;
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import static com.google.android.exoplayer2.util.Assertions.checkState; import static com.google.android.exoplayer2.util.Assertions.checkState;
import static java.lang.annotation.ElementType.TYPE_USE; import static java.lang.annotation.ElementType.TYPE_USE;
...@@ -372,7 +373,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -372,7 +373,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
SamplePipeline samplePipeline = SamplePipeline samplePipeline =
getSamplePipeline( getSamplePipeline(
firstInputFormat, supportedOutputTypes, streamStartPositionUs, streamOffsetUs); firstInputFormat,
shouldTranscode(
firstInputFormat, supportedOutputTypes, streamStartPositionUs, streamOffsetUs),
streamStartPositionUs,
streamOffsetUs);
compositeAssetLoader.addOnMediaItemChangedListener(samplePipeline, trackType); compositeAssetLoader.addOnMediaItemChangedListener(samplePipeline, trackType);
internalHandler.obtainMessage(MSG_REGISTER_SAMPLE_PIPELINE, samplePipeline).sendToTarget(); internalHandler.obtainMessage(MSG_REGISTER_SAMPLE_PIPELINE, samplePipeline).sendToTarget();
...@@ -421,59 +426,74 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -421,59 +426,74 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private SamplePipeline getSamplePipeline( private SamplePipeline getSamplePipeline(
Format firstInputFormat, Format firstInputFormat,
@AssetLoader.SupportedOutputTypes int supportedOutputTypes, boolean shouldTranscode,
long streamStartPositionUs, long streamStartPositionUs,
long streamOffsetUs) long streamOffsetUs)
throws ExportException { throws ExportException {
checkState(supportedOutputTypes != 0); if (shouldTranscode) {
boolean isAudio = MimeTypes.isAudio(firstInputFormat.sampleMimeType); if (MimeTypes.isAudio(firstInputFormat.sampleMimeType)) {
boolean shouldTranscode; return new AudioSamplePipeline(
if (mediaItemCount > 1 && !transmux) { firstInputFormat,
shouldTranscode = true; streamStartPositionUs,
} else { streamOffsetUs,
shouldTranscode = transformationRequest,
isAudio firstEditedMediaItem.flattenForSlowMotion,
? shouldTranscodeAudio(firstInputFormat) firstEditedMediaItem.effects.audioProcessors,
: shouldTranscodeVideo(firstInputFormat, streamStartPositionUs, streamOffsetUs); encoderFactory,
muxerWrapper,
fallbackListener);
}
if (MimeTypes.isVideo(firstInputFormat.sampleMimeType)) {
return new VideoSamplePipeline(
context,
firstInputFormat,
streamStartPositionUs,
streamOffsetUs,
transformationRequest,
firstEditedMediaItem.effects.videoEffects,
firstEditedMediaItem.effects.videoFrameProcessorFactory,
encoderFactory,
muxerWrapper,
/* errorConsumer= */ this::onError,
fallbackListener,
debugViewProvider);
}
} }
boolean assetLoaderNeverDecodes = (supportedOutputTypes & SUPPORTED_OUTPUT_TYPE_DECODED) == 0;
checkState(!shouldTranscode || !assetLoaderNeverDecodes); return new EncodedSamplePipeline(
boolean assetLoaderAlwaysDecodes = firstInputFormat,
(supportedOutputTypes & SUPPORTED_OUTPUT_TYPE_ENCODED) == 0; streamStartPositionUs,
boolean shouldUseTranscodingPipeline = shouldTranscode || assetLoaderAlwaysDecodes; transformationRequest,
if (isAudio && shouldUseTranscodingPipeline) { muxerWrapper,
return new AudioSamplePipeline( fallbackListener);
firstInputFormat, }
streamStartPositionUs,
streamOffsetUs, private boolean shouldTranscode(
transformationRequest, Format inputFormat,
firstEditedMediaItem.flattenForSlowMotion, @AssetLoader.SupportedOutputTypes int supportedOutputTypes,
firstEditedMediaItem.effects.audioProcessors, long streamStartPositionUs,
encoderFactory, long streamOffsetUs) {
muxerWrapper, boolean assetLoaderCanOutputDecoded =
fallbackListener); (supportedOutputTypes & SUPPORTED_OUTPUT_TYPE_DECODED) != 0;
} else if (shouldUseTranscodingPipeline) { boolean assetLoaderCanOutputEncoded =
return new VideoSamplePipeline( (supportedOutputTypes & SUPPORTED_OUTPUT_TYPE_ENCODED) != 0;
context, checkArgument(assetLoaderCanOutputDecoded || assetLoaderCanOutputEncoded);
firstInputFormat,
streamStartPositionUs, boolean shouldTranscode = false;
streamOffsetUs, if (!assetLoaderCanOutputEncoded) {
transformationRequest, shouldTranscode = true;
firstEditedMediaItem.effects.videoEffects, } else if (mediaItemCount > 1 && !transmux) {
firstEditedMediaItem.effects.videoFrameProcessorFactory, shouldTranscode = true;
encoderFactory, } else if (MimeTypes.isAudio(inputFormat.sampleMimeType)) {
muxerWrapper, shouldTranscode = shouldTranscodeAudio(inputFormat);
/* errorConsumer= */ this::onError, } else if (MimeTypes.isVideo(inputFormat.sampleMimeType)) {
fallbackListener, shouldTranscode = shouldTranscodeVideo(inputFormat, streamStartPositionUs, streamOffsetUs);
debugViewProvider);
} else {
return new EncodedSamplePipeline(
firstInputFormat,
streamStartPositionUs,
transformationRequest,
muxerWrapper,
fallbackListener);
} }
checkState(!shouldTranscode || assetLoaderCanOutputDecoded);
return shouldTranscode;
} }
private boolean shouldTranscodeAudio(Format inputFormat) { private boolean shouldTranscodeAudio(Format inputFormat) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment