mirror of
https://github.com/samsonjs/media.git
synced 2026-03-26 09:35:47 +00:00
Add regression test forcing encode/decode.
PiperOrigin-RevId: 432928418
This commit is contained in:
parent
461effc6c2
commit
04ed774bef
3 changed files with 52 additions and 0 deletions
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue