Skip to content

Commit

Permalink
Add TransformationRequest.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 417786661
  • Loading branch information
hmsch authored and tonihei committed Jan 4, 2022
1 parent 5c8b5e5 commit 4240da5
Show file tree
Hide file tree
Showing 15 changed files with 487 additions and 252 deletions.
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
* Increase required min API version to 21.
* `TransformationException` is now used to describe errors that occur
during a transformation.
* Add `TransformationRequest` for specifying the transformation options.
* MediaSession extension:
* Remove deprecated call to `onStop(/* reset= */ true)` and provide an
opt-out flag for apps that don't want to clear the playlist on stop.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.graphics.Matrix;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.transformer.TransformationRequest;
import com.google.android.exoplayer2.transformer.Transformer;
import com.google.android.exoplayer2.util.MimeTypes;
import java.util.HashSet;
Expand All @@ -43,9 +44,12 @@ public void repeatedTranscode_givesConsistentLengthOutput() throws Exception {
transformationMatrix.postTranslate((float) 0.1, (float) 0.1);
Transformer transformer =
new Transformer.Builder(context)
.setVideoMimeType(MimeTypes.VIDEO_H265)
.setTransformationMatrix(transformationMatrix)
.setAudioMimeType(MimeTypes.AUDIO_AMR_NB)
.setTransformationRequest(
new TransformationRequest.Builder()
.setVideoMimeType(MimeTypes.VIDEO_H265)
.setTransformationMatrix(transformationMatrix)
.setAudioMimeType(MimeTypes.AUDIO_AMR_NB)
.build())
.build();

Set<Long> differentOutputSizesBytes = new HashSet<>();
Expand Down Expand Up @@ -74,9 +78,12 @@ public void repeatedTranscodeNoAudio_givesConsistentLengthOutput() throws Except
transformationMatrix.postTranslate((float) 0.1, (float) 0.1);
Transformer transformer =
new Transformer.Builder(context)
.setVideoMimeType(MimeTypes.VIDEO_H265)
.setTransformationMatrix(transformationMatrix)
.setRemoveAudio(true)
.setTransformationRequest(
new TransformationRequest.Builder()
.setVideoMimeType(MimeTypes.VIDEO_H265)
.setTransformationMatrix(transformationMatrix)
.build())
.build();

Set<Long> differentOutputSizesBytes = new HashSet<>();
Expand All @@ -103,8 +110,11 @@ public void repeatedTranscodeNoVideo_givesConsistentLengthOutput() throws Except
Context context = ApplicationProvider.getApplicationContext();
Transformer transcodingTransformer =
new Transformer.Builder(context)
.setAudioMimeType(MimeTypes.AUDIO_AMR_NB)
.setRemoveVideo(true)
.setTransformationRequest(
new TransformationRequest.Builder()
.setAudioMimeType(MimeTypes.AUDIO_AMR_NB)
.build())
.build();

Set<Long> differentOutputSizesBytes = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.transformer.TransformationRequest;
import com.google.android.exoplayer2.transformer.Transformer;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -32,7 +33,10 @@ public class SefTransformationTest {
public void sefTransform() throws Exception {
Context context = ApplicationProvider.getApplicationContext();
Transformer transformer =
new Transformer.Builder(context).setFlattenForSlowMotion(true).build();
new Transformer.Builder(context)
.setTransformationRequest(
new TransformationRequest.Builder().setFlattenForSlowMotion(true).build())
.build();
runTransformer(
context,
/* testId = */ "sefTransform",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.graphics.Matrix;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.transformer.TransformationRequest;
import com.google.android.exoplayer2.transformer.Transformer;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -35,7 +36,12 @@ public void setTransformationMatrixTransform() throws Exception {
Matrix transformationMatrix = new Matrix();
transformationMatrix.postTranslate(/* dx= */ .2f, /* dy= */ .1f);
Transformer transformer =
new Transformer.Builder(context).setTransformationMatrix(transformationMatrix).build();
new Transformer.Builder(context)
.setTransformationRequest(
new TransformationRequest.Builder()
.setTransformationMatrix(transformationMatrix)
.build())
.build();

runTransformer(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
private static final int DEFAULT_ENCODER_BITRATE = 128 * 1024;

private final Format inputFormat;
private final Transformation transformation;
private final TransformationRequest transformationRequest;
private final Codec.EncoderFactory encoderFactory;

private final Codec decoder;
Expand All @@ -66,12 +66,12 @@

public AudioSamplePipeline(
Format inputFormat,
Transformation transformation,
TransformationRequest transformationRequest,
Codec.EncoderFactory encoderFactory,
Codec.DecoderFactory decoderFactory)
throws TransformationException {
this.inputFormat = inputFormat;
this.transformation = transformation;
this.transformationRequest = transformationRequest;
this.encoderFactory = encoderFactory;
decoderInputBuffer =
new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED);
Expand Down Expand Up @@ -294,7 +294,7 @@ private boolean ensureEncoderAndAudioProcessingConfigured() throws Transformatio
decoderOutputFormat.sampleRate,
decoderOutputFormat.channelCount,
decoderOutputFormat.pcmEncoding);
if (transformation.flattenForSlowMotion) {
if (transformationRequest.flattenForSlowMotion) {
try {
outputAudioFormat = sonicAudioProcessor.configure(outputAudioFormat);
flushSonicAndSetSpeed(currentSpeed);
Expand All @@ -310,9 +310,9 @@ private boolean ensureEncoderAndAudioProcessingConfigured() throws Transformatio
encoderFactory.createForAudioEncoding(
new Format.Builder()
.setSampleMimeType(
transformation.audioMimeType == null
transformationRequest.audioMimeType == null
? inputFormat.sampleMimeType
: transformation.audioMimeType)
: transformationRequest.audioMimeType)
.setSampleRate(outputAudioFormat.sampleRate)
.setChannelCount(outputAudioFormat.channelCount)
.setAverageBitrate(DEFAULT_ENCODER_BITRATE)
Expand All @@ -322,7 +322,7 @@ private boolean ensureEncoderAndAudioProcessingConfigured() throws Transformatio
}

private boolean isSpeedChanging(BufferInfo bufferInfo) {
if (!transformation.flattenForSlowMotion) {
if (!transformationRequest.flattenForSlowMotion) {
return false;
}
float newSpeed = speedProvider.getSpeed(bufferInfo.presentationTimeUs);
Expand Down

This file was deleted.

Loading

0 comments on commit 4240da5

Please sign in to comment.