Commit d254967a by samrobinson Committed by Ian Baker

Expose decoder name to analysis files.

PiperOrigin-RevId: 447950623
parent 271cdbed
...@@ -20,6 +20,7 @@ import static java.util.concurrent.TimeUnit.SECONDS; ...@@ -20,6 +20,7 @@ import static java.util.concurrent.TimeUnit.SECONDS;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import android.view.Surface;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.platform.app.InstrumentationRegistry;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
...@@ -143,7 +144,7 @@ public class TransformerAndroidTestRunner { ...@@ -143,7 +144,7 @@ public class TransformerAndroidTestRunner {
} }
private final Context context; private final Context context;
private final CodecNameForwardingEncoderFactory transformerEncoderFactory; private final CodecNameForwardingCodecFactory transformerCodecFactory;
private final Transformer transformer; private final Transformer transformer;
private final int timeoutSeconds; private final int timeoutSeconds;
private final boolean calculateSsim; private final boolean calculateSsim;
...@@ -158,9 +159,14 @@ public class TransformerAndroidTestRunner { ...@@ -158,9 +159,14 @@ public class TransformerAndroidTestRunner {
boolean suppressAnalysisExceptions, boolean suppressAnalysisExceptions,
@Nullable Map<String, Object> inputValues) { @Nullable Map<String, Object> inputValues) {
this.context = context; this.context = context;
this.transformerEncoderFactory = this.transformerCodecFactory =
new CodecNameForwardingEncoderFactory(transformer.encoderFactory); new CodecNameForwardingCodecFactory(transformer.decoderFactory, transformer.encoderFactory);
this.transformer = transformer.buildUpon().setEncoderFactory(transformerEncoderFactory).build(); this.transformer =
transformer
.buildUpon()
.setDecoderFactory(transformerCodecFactory)
.setEncoderFactory(transformerCodecFactory)
.build();
this.timeoutSeconds = timeoutSeconds; this.timeoutSeconds = timeoutSeconds;
this.calculateSsim = calculateSsim; this.calculateSsim = calculateSsim;
this.suppressAnalysisExceptions = suppressAnalysisExceptions; this.suppressAnalysisExceptions = suppressAnalysisExceptions;
...@@ -192,7 +198,7 @@ public class TransformerAndroidTestRunner { ...@@ -192,7 +198,7 @@ public class TransformerAndroidTestRunner {
resultJson.put("exception", AndroidTestUtil.exceptionAsJsonObject(e)); resultJson.put("exception", AndroidTestUtil.exceptionAsJsonObject(e));
throw e; throw e;
} finally { } finally {
resultJson.put("codecDetails", transformerEncoderFactory.getCodecNamesAsJsonObject()); resultJson.put("codecDetails", transformerCodecFactory.getCodecNamesAsJsonObject());
AndroidTestUtil.writeTestSummaryToFile(context, testId, resultJson); AndroidTestUtil.writeTestSummaryToFile(context, testId, resultJson);
} }
} }
...@@ -319,18 +325,45 @@ public class TransformerAndroidTestRunner { ...@@ -319,18 +325,45 @@ public class TransformerAndroidTestRunner {
* A {@link Codec.EncoderFactory} that forwards all methods to another encoder factory, whilst * A {@link Codec.EncoderFactory} that forwards all methods to another encoder factory, whilst
* providing visibility into the names of last codecs created by it. * providing visibility into the names of last codecs created by it.
*/ */
private static class CodecNameForwardingEncoderFactory implements Codec.EncoderFactory { private static class CodecNameForwardingCodecFactory
implements Codec.DecoderFactory, Codec.EncoderFactory {
/** The name of the last audio {@link Codec decoder} created. */
@Nullable public String audioDecoderName;
/** The name of the last video {@link Codec decoder} created. */
@Nullable public String videoDecoderName;
/** The name of the last audio {@link Codec encoder} created. */
@Nullable public String audioEncoderName; @Nullable public String audioEncoderName;
/** The name of the last video {@link Codec encoder} created. */
@Nullable public String videoEncoderName; @Nullable public String videoEncoderName;
private final Codec.DecoderFactory decoderFactory;
private final Codec.EncoderFactory encoderFactory; private final Codec.EncoderFactory encoderFactory;
public CodecNameForwardingEncoderFactory(Codec.EncoderFactory encoderFactory) { public CodecNameForwardingCodecFactory(
Codec.DecoderFactory decoderFactory, Codec.EncoderFactory encoderFactory) {
this.decoderFactory = decoderFactory;
this.encoderFactory = encoderFactory; this.encoderFactory = encoderFactory;
} }
@Override @Override
public Codec createForAudioDecoding(Format format) throws TransformationException {
Codec audioDecoder = decoderFactory.createForAudioDecoding(format);
audioDecoderName = audioDecoder.getName();
return audioDecoder;
}
@Override
public Codec createForVideoDecoding(
Format format, Surface outputSurface, boolean enableRequestSdrToneMapping)
throws TransformationException {
Codec videoDecoder =
decoderFactory.createForVideoDecoding(format, outputSurface, enableRequestSdrToneMapping);
videoDecoderName = videoDecoder.getName();
return videoDecoder;
}
@Override
public Codec createForAudioEncoding(Format format, List<String> allowedMimeTypes) public Codec createForAudioEncoding(Format format, List<String> allowedMimeTypes)
throws TransformationException { throws TransformationException {
Codec audioEncoder = encoderFactory.createForAudioEncoding(format, allowedMimeTypes); Codec audioEncoder = encoderFactory.createForAudioEncoding(format, allowedMimeTypes);
...@@ -358,6 +391,12 @@ public class TransformerAndroidTestRunner { ...@@ -358,6 +391,12 @@ public class TransformerAndroidTestRunner {
public JSONObject getCodecNamesAsJsonObject() throws JSONException { public JSONObject getCodecNamesAsJsonObject() throws JSONException {
JSONObject detailsJson = new JSONObject(); JSONObject detailsJson = new JSONObject();
if (audioDecoderName != null) {
detailsJson.put("audioDecoderName", audioDecoderName);
}
if (videoDecoderName != null) {
detailsJson.put("videoDecoderName", videoDecoderName);
}
if (audioEncoderName != null) { if (audioEncoderName != null) {
detailsJson.put("audioEncoderName", audioEncoderName); detailsJson.put("audioEncoderName", audioEncoderName);
} }
......
...@@ -108,6 +108,7 @@ public final class Transformer { ...@@ -108,6 +108,7 @@ public final class Transformer {
private Looper looper; private Looper looper;
private Clock clock; private Clock clock;
private Codec.EncoderFactory encoderFactory; private Codec.EncoderFactory encoderFactory;
private Codec.DecoderFactory decoderFactory;
/** /**
* @deprecated Use {@link #Builder(Context)} instead. * @deprecated Use {@link #Builder(Context)} instead.
...@@ -119,6 +120,7 @@ public final class Transformer { ...@@ -119,6 +120,7 @@ public final class Transformer {
clock = Clock.DEFAULT; clock = Clock.DEFAULT;
listeners = new ListenerSet<>(looper, clock, (listener, flags) -> {}); listeners = new ListenerSet<>(looper, clock, (listener, flags) -> {});
encoderFactory = Codec.EncoderFactory.DEFAULT; encoderFactory = Codec.EncoderFactory.DEFAULT;
decoderFactory = Codec.DecoderFactory.DEFAULT;
debugViewProvider = DebugViewProvider.NONE; debugViewProvider = DebugViewProvider.NONE;
containerMimeType = MimeTypes.VIDEO_MP4; containerMimeType = MimeTypes.VIDEO_MP4;
transformationRequest = new TransformationRequest.Builder().build(); transformationRequest = new TransformationRequest.Builder().build();
...@@ -137,6 +139,7 @@ public final class Transformer { ...@@ -137,6 +139,7 @@ public final class Transformer {
clock = Clock.DEFAULT; clock = Clock.DEFAULT;
listeners = new ListenerSet<>(looper, clock, (listener, flags) -> {}); listeners = new ListenerSet<>(looper, clock, (listener, flags) -> {});
encoderFactory = Codec.EncoderFactory.DEFAULT; encoderFactory = Codec.EncoderFactory.DEFAULT;
decoderFactory = Codec.DecoderFactory.DEFAULT;
debugViewProvider = DebugViewProvider.NONE; debugViewProvider = DebugViewProvider.NONE;
containerMimeType = MimeTypes.VIDEO_MP4; containerMimeType = MimeTypes.VIDEO_MP4;
transformationRequest = new TransformationRequest.Builder().build(); transformationRequest = new TransformationRequest.Builder().build();
...@@ -156,6 +159,7 @@ public final class Transformer { ...@@ -156,6 +159,7 @@ public final class Transformer {
this.listeners = transformer.listeners; this.listeners = transformer.listeners;
this.looper = transformer.looper; this.looper = transformer.looper;
this.encoderFactory = transformer.encoderFactory; this.encoderFactory = transformer.encoderFactory;
this.decoderFactory = transformer.decoderFactory;
this.debugViewProvider = transformer.debugViewProvider; this.debugViewProvider = transformer.debugViewProvider;
this.clock = transformer.clock; this.clock = transformer.clock;
} }
...@@ -348,6 +352,19 @@ public final class Transformer { ...@@ -348,6 +352,19 @@ public final class Transformer {
} }
/** /**
* Sets the {@link Codec.DecoderFactory} that will be used by the transformer.
*
* <p>The default value is {@link Codec.DecoderFactory#DEFAULT}.
*
* @param decoderFactory The {@link Codec.DecoderFactory} instance.
* @return This builder.
*/
public Builder setDecoderFactory(Codec.DecoderFactory decoderFactory) {
this.decoderFactory = decoderFactory;
return this;
}
/**
* Sets a provider for views to show diagnostic information (if available) during * Sets a provider for views to show diagnostic information (if available) during
* transformation. * transformation.
* *
...@@ -435,7 +452,7 @@ public final class Transformer { ...@@ -435,7 +452,7 @@ public final class Transformer {
looper, looper,
clock, clock,
encoderFactory, encoderFactory,
Codec.DecoderFactory.DEFAULT, decoderFactory,
debugViewProvider); debugViewProvider);
} }
...@@ -557,7 +574,7 @@ public final class Transformer { ...@@ -557,7 +574,7 @@ public final class Transformer {
private final Clock clock; private final Clock clock;
private final Transformer.DebugViewProvider debugViewProvider; private final Transformer.DebugViewProvider debugViewProvider;
private final ListenerSet<Transformer.Listener> listeners; private final ListenerSet<Transformer.Listener> listeners;
private final Codec.DecoderFactory decoderFactory; @VisibleForTesting /* package */ final Codec.DecoderFactory decoderFactory;
@VisibleForTesting /* package */ final Codec.EncoderFactory encoderFactory; @VisibleForTesting /* package */ final Codec.EncoderFactory encoderFactory;
@Nullable private MuxerWrapper muxerWrapper; @Nullable private MuxerWrapper muxerWrapper;
......
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