From 8763843c840bd6e65dfaf6063bfc264f0d45aebc Mon Sep 17 00:00:00 2001 From: huangdarwin Date: Tue, 15 Mar 2022 13:24:28 +0000 Subject: [PATCH] Transformer: Add javadoc to VideoTranscodingSamplePipeline. As pointed out in a previous review, createFallbackTransformationRequest can be a bit confusing to parse. Added javadocs and renamed parameters appropriately, to make it slightly more easy to understand. PiperOrigin-RevId: 434733313 --- .../VideoTranscodingSamplePipeline.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoTranscodingSamplePipeline.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoTranscodingSamplePipeline.java index c94380a073..98ff515a2e 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoTranscodingSamplePipeline.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoTranscodingSamplePipeline.java @@ -152,7 +152,7 @@ import org.checkerframework.dataflow.qual.Pure; fallbackListener.onTransformationRequestFinalized( createFallbackTransformationRequest( transformationRequest, - /* resolutionIsHeight= */ !swapEncodingDimensions, + /* hasOutputFormatRotation= */ swapEncodingDimensions, requestedEncoderFormat, encoderSupportedFormat)); @@ -301,23 +301,33 @@ import org.checkerframework.dataflow.qual.Pure; encoder.release(); } + /** + * Creates a fallback transformation request to execute, based on device-specific support. + * + * @param transformationRequest The requested transformation. + * @param hasOutputFormatRotation Whether the input video will be rotated to landscape during + * processing, with {@link Format#rotationDegrees} of 90 added to the output format. + * @param requestedFormat The requested format. + * @param supportedFormat A format supported by the device. + */ @Pure private static TransformationRequest createFallbackTransformationRequest( TransformationRequest transformationRequest, - boolean resolutionIsHeight, + boolean hasOutputFormatRotation, Format requestedFormat, - Format actualFormat) { + Format supportedFormat) { // TODO(b/210591626): Also update bitrate etc. once encoder configuration and fallback are // implemented. - if (Util.areEqual(requestedFormat.sampleMimeType, actualFormat.sampleMimeType) - && ((!resolutionIsHeight && requestedFormat.width == actualFormat.width) - || (resolutionIsHeight && requestedFormat.height == actualFormat.height))) { + if (Util.areEqual(requestedFormat.sampleMimeType, supportedFormat.sampleMimeType) + && (hasOutputFormatRotation + ? requestedFormat.width == supportedFormat.width + : requestedFormat.height == supportedFormat.height)) { return transformationRequest; } return transformationRequest .buildUpon() - .setVideoMimeType(actualFormat.sampleMimeType) - .setResolution(resolutionIsHeight ? requestedFormat.height : requestedFormat.width) + .setVideoMimeType(supportedFormat.sampleMimeType) + .setResolution(hasOutputFormatRotation ? requestedFormat.width : requestedFormat.height) .build(); }