Expose decoder name to analysis files.

PiperOrigin-RevId: 447950623
This commit is contained in:
samrobinson 2022-05-11 11:34:57 +01:00 committed by Ian Baker
parent 1bcabd3450
commit d72ffe4ba1
2 changed files with 65 additions and 9 deletions

View File

@ -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.media3.common.Format; import androidx.media3.common.Format;
import androidx.media3.common.MediaItem; import androidx.media3.common.MediaItem;
@ -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 {
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 {
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,17 +325,44 @@ 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
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 @Override
public Codec createForAudioEncoding(Format format, List<String> allowedMimeTypes) public Codec createForAudioEncoding(Format format, List<String> allowedMimeTypes)
throws TransformationException { throws TransformationException {
@ -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);
} }

View File

@ -110,6 +110,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.
@ -121,6 +122,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();
@ -139,6 +141,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();
@ -158,6 +161,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;
} }
@ -349,6 +353,19 @@ public final class Transformer {
return this; return this;
} }
/**
* 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.
@ -437,7 +454,7 @@ public final class Transformer {
looper, looper,
clock, clock,
encoderFactory, encoderFactory,
Codec.DecoderFactory.DEFAULT, decoderFactory,
debugViewProvider); debugViewProvider);
} }
@ -559,7 +576,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;