From 59166cce9c67b6a0b8d620d24b42671bcbc1ab10 Mon Sep 17 00:00:00 2001 From: samrobinson Date: Wed, 21 Dec 2022 14:39:22 +0000 Subject: [PATCH] Ensure supported request only updates changes fields. The TransformationRequest passed to FallbackListener (and createSupportedTransformationRequest) can have null for values that are inferred from source. Within fallback, this can be height, width, video mime type and audio mime type (HDR mode is not linked to source). requestedFormat has these values populated from source, and supportedFormat then finds the closest supported values to the requested. If any of the values in supportedFormat do not match the requestedFormat, then this method would build upon the TransformationRequest and update ALL possible fallback fields. This is a problem because the fallback listener compares the original request to the fallback one and notifies about all the fields that have changed. This CL changes this so that only the values that are not the same as requested are changed in the supported request that is given to the fallback listener. PiperOrigin-RevId: 496908492 --- .../VideoTranscodingSamplePipeline.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/VideoTranscodingSamplePipeline.java b/libraries/transformer/src/main/java/androidx/media3/transformer/VideoTranscodingSamplePipeline.java index 4823dc2419..fbbd63dada 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/VideoTranscodingSamplePipeline.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/VideoTranscodingSamplePipeline.java @@ -348,19 +348,25 @@ import org.checkerframework.dataflow.qual.Pure; Format supportedFormat, @TransformationRequest.HdrMode int supportedHdrMode) { // TODO(b/259570024): Consider including bitrate in the revised fallback design. - if (transformationRequest.hdrMode == supportedHdrMode - && Util.areEqual(requestedFormat.sampleMimeType, supportedFormat.sampleMimeType) - && (hasOutputFormatRotation - ? requestedFormat.width == supportedFormat.width - : requestedFormat.height == supportedFormat.height)) { - return transformationRequest; + + TransformationRequest.Builder supportedRequestBuilder = transformationRequest.buildUpon(); + if (transformationRequest.hdrMode != supportedHdrMode) { + supportedRequestBuilder.setHdrMode(supportedHdrMode); } - return transformationRequest - .buildUpon() - .setVideoMimeType(supportedFormat.sampleMimeType) - .setResolution(hasOutputFormatRotation ? requestedFormat.width : requestedFormat.height) - .setHdrMode(supportedHdrMode) - .build(); + + if (!Util.areEqual(requestedFormat.sampleMimeType, supportedFormat.sampleMimeType)) { + supportedRequestBuilder.setVideoMimeType(supportedFormat.sampleMimeType); + } + + if (hasOutputFormatRotation) { + if (requestedFormat.width != supportedFormat.width) { + supportedRequestBuilder.setResolution(/* outputHeight= */ supportedFormat.width); + } + } else if (requestedFormat.height != supportedFormat.height) { + supportedRequestBuilder.setResolution(supportedFormat.height); + } + + return supportedRequestBuilder.build(); } private static boolean deviceNeedsNoToneMappingWorkaround() {