mirror of
https://github.com/androidx/media.git
synced 2025-05-08 08:00:49 +08:00
Add regression test forcing encode/decode.
PiperOrigin-RevId: 432928418
This commit is contained in:
parent
e5c229be00
commit
8adc145fa2
@ -23,11 +23,15 @@ import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_REMO
|
||||
import android.content.Context;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.transformer.Codec;
|
||||
import com.google.android.exoplayer2.transformer.TransformationException;
|
||||
import com.google.android.exoplayer2.transformer.TransformationRequest;
|
||||
import com.google.android.exoplayer2.transformer.Transformer;
|
||||
import com.google.android.exoplayer2.transformer.TransformerAndroidTestRunner;
|
||||
import com.google.android.exoplayer2.util.Log;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
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";
|
||||
|
@ -105,6 +105,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;
|
||||
|
@ -85,6 +85,9 @@ import com.google.android.exoplayer2.source.SampleStream.ReadDataResult;
|
||||
}
|
||||
|
||||
private boolean shouldPassthrough(Format inputFormat) {
|
||||
if (encoderFactory.audioNeedsEncoding()) {
|
||||
return false;
|
||||
}
|
||||
if (transformationRequest.audioMimeType != null
|
||||
&& !transformationRequest.audioMimeType.equals(inputFormat.sampleMimeType)) {
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user