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
This commit is contained in:
huangdarwin 2022-03-15 13:24:28 +00:00 committed by Ian Baker
parent 36cef2b496
commit 8763843c84

View File

@ -152,7 +152,7 @@ import org.checkerframework.dataflow.qual.Pure;
fallbackListener.onTransformationRequestFinalized( fallbackListener.onTransformationRequestFinalized(
createFallbackTransformationRequest( createFallbackTransformationRequest(
transformationRequest, transformationRequest,
/* resolutionIsHeight= */ !swapEncodingDimensions, /* hasOutputFormatRotation= */ swapEncodingDimensions,
requestedEncoderFormat, requestedEncoderFormat,
encoderSupportedFormat)); encoderSupportedFormat));
@ -301,23 +301,33 @@ import org.checkerframework.dataflow.qual.Pure;
encoder.release(); 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 @Pure
private static TransformationRequest createFallbackTransformationRequest( private static TransformationRequest createFallbackTransformationRequest(
TransformationRequest transformationRequest, TransformationRequest transformationRequest,
boolean resolutionIsHeight, boolean hasOutputFormatRotation,
Format requestedFormat, Format requestedFormat,
Format actualFormat) { Format supportedFormat) {
// TODO(b/210591626): Also update bitrate etc. once encoder configuration and fallback are // TODO(b/210591626): Also update bitrate etc. once encoder configuration and fallback are
// implemented. // implemented.
if (Util.areEqual(requestedFormat.sampleMimeType, actualFormat.sampleMimeType) if (Util.areEqual(requestedFormat.sampleMimeType, supportedFormat.sampleMimeType)
&& ((!resolutionIsHeight && requestedFormat.width == actualFormat.width) && (hasOutputFormatRotation
|| (resolutionIsHeight && requestedFormat.height == actualFormat.height))) { ? requestedFormat.width == supportedFormat.width
: requestedFormat.height == supportedFormat.height)) {
return transformationRequest; return transformationRequest;
} }
return transformationRequest return transformationRequest
.buildUpon() .buildUpon()
.setVideoMimeType(actualFormat.sampleMimeType) .setVideoMimeType(supportedFormat.sampleMimeType)
.setResolution(resolutionIsHeight ? requestedFormat.height : requestedFormat.width) .setResolution(hasOutputFormatRotation ? requestedFormat.width : requestedFormat.height)
.build(); .build();
} }