Add regression test forcing encode/decode.

PiperOrigin-RevId: 432928418
This commit is contained in:
samrobinson 2022-03-07 14:21:07 +00:00 committed by Ian Baker
parent 461effc6c2
commit 04ed774bef
3 changed files with 52 additions and 0 deletions

View file

@ -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 android.content.Context;
import androidx.media3.common.Format;
import androidx.media3.common.util.Log;
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.Transformer;
import androidx.media3.transformer.TransformerAndroidTestRunner;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -49,6 +53,46 @@ public class TransformationTest {
.run(testId, MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING);
}
@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 {
final String testId = TAG + "_transform4K60";

View file

@ -107,6 +107,11 @@ public interface Codec {
Codec createForVideoEncoding(Format format, List<String> allowedMimeTypes)
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. */
default boolean videoNeedsEncoding() {
return false;

View file

@ -85,6 +85,9 @@ import androidx.media3.extractor.metadata.mp4.SlowMotionData;
}
private boolean shouldPassthrough(Format inputFormat) {
if (encoderFactory.audioNeedsEncoding()) {
return false;
}
if (transformationRequest.audioMimeType != null
&& !transformationRequest.audioMimeType.equals(inputFormat.sampleMimeType)) {
return false;