Commit 041c3e99 by hschlueter Committed by tonihei

Use audio passthrough if flattening is requested but not needed.

When the input is not a slow motion video, then flattening should do
nothing, so there is no need to re-encode audio.

PiperOrigin-RevId: 412443097
parent 51762a47
...@@ -19,12 +19,15 @@ package com.google.android.exoplayer2.transformer; ...@@ -19,12 +19,15 @@ package com.google.android.exoplayer2.transformer;
import static com.google.android.exoplayer2.source.SampleStream.FLAG_REQUIRE_FORMAT; import static com.google.android.exoplayer2.source.SampleStream.FLAG_REQUIRE_FORMAT;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull; import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.FormatHolder; import com.google.android.exoplayer2.FormatHolder;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.mp4.SlowMotionData;
import com.google.android.exoplayer2.source.SampleStream.ReadDataResult; import com.google.android.exoplayer2.source.SampleStream.ReadDataResult;
@RequiresApi(18) @RequiresApi(18)
...@@ -59,13 +62,29 @@ import com.google.android.exoplayer2.source.SampleStream.ReadDataResult; ...@@ -59,13 +62,29 @@ import com.google.android.exoplayer2.source.SampleStream.ReadDataResult;
return false; return false;
} }
Format inputFormat = checkNotNull(formatHolder.format); Format inputFormat = checkNotNull(formatHolder.format);
if ((transformation.audioMimeType != null boolean shouldChangeMimeType =
&& !transformation.audioMimeType.equals(inputFormat.sampleMimeType)) transformation.audioMimeType != null
|| transformation.flattenForSlowMotion) { && !transformation.audioMimeType.equals(inputFormat.sampleMimeType);
boolean shouldFlattenForSlowMotion =
transformation.flattenForSlowMotion && isSlowMotion(inputFormat);
if (shouldChangeMimeType || shouldFlattenForSlowMotion) {
samplePipeline = new AudioSamplePipeline(inputFormat, transformation, getIndex()); samplePipeline = new AudioSamplePipeline(inputFormat, transformation, getIndex());
} else { } else {
samplePipeline = new PassthroughSamplePipeline(inputFormat); samplePipeline = new PassthroughSamplePipeline(inputFormat);
} }
return true; return true;
} }
private static boolean isSlowMotion(Format format) {
@Nullable Metadata metadata = format.metadata;
if (metadata == null) {
return false;
}
for (int i = 0; i < metadata.length(); i++) {
if (metadata.get(i) instanceof SlowMotionData) {
return true;
}
}
return false;
}
} }
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