Commit 04ed774b by samrobinson Committed by Ian Baker

Add regression test forcing encode/decode.

PiperOrigin-RevId: 432928418
parent 461effc6
...@@ -21,13 +21,17 @@ import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_WITH_INCREAS ...@@ -21,13 +21,17 @@ import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_WITH_INCREAS
import static androidx.media3.transformer.AndroidTestUtil.MP4_REMOTE_4K60_PORTRAIT_URI_STRING; import static androidx.media3.transformer.AndroidTestUtil.MP4_REMOTE_4K60_PORTRAIT_URI_STRING;
import android.content.Context; import android.content.Context;
import androidx.media3.common.Format;
import androidx.media3.common.util.Log; import androidx.media3.common.util.Log;
import androidx.media3.common.util.Util; import androidx.media3.common.util.Util;
import androidx.media3.transformer.Codec;
import androidx.media3.transformer.TransformationException;
import androidx.media3.transformer.TransformationRequest; import androidx.media3.transformer.TransformationRequest;
import androidx.media3.transformer.Transformer; import androidx.media3.transformer.Transformer;
import androidx.media3.transformer.TransformerAndroidTestRunner; import androidx.media3.transformer.TransformerAndroidTestRunner;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.util.List;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -50,6 +54,46 @@ public class TransformationTest { ...@@ -50,6 +54,46 @@ public class TransformationTest {
} }
@Test @Test
public void transformWithDecodeEncode() throws Exception {
final String testId = TAG + "_transformForceCodecUse";
Context context = ApplicationProvider.getApplicationContext();
Transformer transformer =
new Transformer.Builder(context)
.setEncoderFactory(
new Codec.EncoderFactory() {
@Override
public Codec createForAudioEncoding(Format format, List<String> allowedMimeTypes)
throws TransformationException {
return Codec.EncoderFactory.DEFAULT.createForAudioEncoding(
format, allowedMimeTypes);
}
@Override
public Codec createForVideoEncoding(Format format, List<String> allowedMimeTypes)
throws TransformationException {
return Codec.EncoderFactory.DEFAULT.createForVideoEncoding(
format, allowedMimeTypes);
}
@Override
public boolean audioNeedsEncoding() {
return true;
}
@Override
public boolean videoNeedsEncoding() {
return true;
}
})
.build();
new TransformerAndroidTestRunner.Builder(context, transformer)
.setCalculateSsim(true)
.build()
.run(testId, MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING);
}
@Test
public void transform4K60() throws Exception { public void transform4K60() throws Exception {
final String testId = TAG + "_transform4K60"; final String testId = TAG + "_transform4K60";
......
...@@ -107,6 +107,11 @@ public interface Codec { ...@@ -107,6 +107,11 @@ public interface Codec {
Codec createForVideoEncoding(Format format, List<String> allowedMimeTypes) Codec createForVideoEncoding(Format format, List<String> allowedMimeTypes)
throws TransformationException; throws TransformationException;
/** Returns whether the audio needs to be encoded because of encoder specific configuration. */
default boolean audioNeedsEncoding() {
return false;
}
/** Returns whether the video needs to be encoded because of encoder specific configuration. */ /** Returns whether the video needs to be encoded because of encoder specific configuration. */
default boolean videoNeedsEncoding() { default boolean videoNeedsEncoding() {
return false; return false;
......
...@@ -85,6 +85,9 @@ import androidx.media3.extractor.metadata.mp4.SlowMotionData; ...@@ -85,6 +85,9 @@ import androidx.media3.extractor.metadata.mp4.SlowMotionData;
} }
private boolean shouldPassthrough(Format inputFormat) { private boolean shouldPassthrough(Format inputFormat) {
if (encoderFactory.audioNeedsEncoding()) {
return false;
}
if (transformationRequest.audioMimeType != null if (transformationRequest.audioMimeType != null
&& !transformationRequest.audioMimeType.equals(inputFormat.sampleMimeType)) { && !transformationRequest.audioMimeType.equals(inputFormat.sampleMimeType)) {
return false; 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