HDR: Clarify tone mapping fallback.

createSupportedTransformationRequest is more accurate than
createFallbackTransformationRequest, as a TransformationRequest will be returned
regardless of whether any fallback is applied.

PiperOrigin-RevId: 466641277
(cherry picked from commit c5a5364673749cb737be3df92c9521fc15207658)
This commit is contained in:
huangdarwin 2022-08-10 11:25:56 +00:00 committed by microkatz
parent 6b4d174cde
commit da10c96229
2 changed files with 19 additions and 13 deletions

View File

@ -65,11 +65,15 @@ import androidx.media3.common.util.Util;
}
/**
* Updates the fallback {@link TransformationRequest}.
* Updates the {@link TransformationRequest}, if fallback is applied.
*
* <p>Should be called with the final {@link TransformationRequest} for each track after all
* fallback has been applied. Calls {@link Transformer.Listener#onFallbackApplied(MediaItem,
* TransformationRequest, TransformationRequest)} once this method has been called for each track.
* <p>Should be called with the final {@link TransformationRequest} for each track, after any
* track-specific fallback changes have been applied.
*
* <p>Fallback is applied if the finalized {@code TransformationRequest} is different from the
* original {@code TransformationRequest}. If fallback is applied, calls {@link
* Transformer.Listener#onFallbackApplied(MediaItem, TransformationRequest,
* TransformationRequest)} once this method has been called for each track.
*
* @param transformationRequest The final {@link TransformationRequest} for a track.
* @throws IllegalStateException If called for more tracks than registered using {@link

View File

@ -17,6 +17,7 @@
package androidx.media3.transformer;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState;
import android.content.Context;
import android.media.MediaCodec;
@ -232,27 +233,27 @@ import org.checkerframework.dataflow.qual.Pure;
}
/**
* Creates a fallback transformation request to execute, based on device-specific support.
* Creates a {@link TransformationRequest}, based on an original {@code TransformationRequest} and
* parameters specifying alterations to it that indicate device 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.
* @param fallbackToSdr Whether HDR editing was requested via the TransformationRequest or
* inferred from the input and tone-mapping to SDR was used instead due to lack of encoder
* capabilities.
* @param isToneMappedToSdr Whether tone mapping to SDR will be applied.
* @return The created instance.
*/
@Pure
private static TransformationRequest createFallbackTransformationRequest(
private static TransformationRequest createSupportedTransformationRequest(
TransformationRequest transformationRequest,
boolean hasOutputFormatRotation,
Format requestedFormat,
Format supportedFormat,
boolean fallbackToSdr) {
boolean isToneMappedToSdr) {
// TODO(b/210591626): Also update bitrate etc. once encoder configuration and fallback are
// implemented.
if (!fallbackToSdr
if (transformationRequest.enableRequestSdrToneMapping == isToneMappedToSdr
&& Util.areEqual(requestedFormat.sampleMimeType, supportedFormat.sampleMimeType)
&& (hasOutputFormatRotation
? requestedFormat.width == supportedFormat.width
@ -260,7 +261,8 @@ import org.checkerframework.dataflow.qual.Pure;
return transformationRequest;
}
TransformationRequest.Builder transformationRequestBuilder = transformationRequest.buildUpon();
if (fallbackToSdr) {
if (transformationRequest.enableRequestSdrToneMapping != isToneMappedToSdr) {
checkState(isToneMappedToSdr);
transformationRequestBuilder
.setEnableRequestSdrToneMapping(true)
.experimental_setEnableHdrEditing(false);
@ -429,7 +431,7 @@ import org.checkerframework.dataflow.qual.Pure;
ColorInfo.isTransferHdr(inputFormat.colorInfo)
&& !ColorInfo.isTransferHdr(requestedEncoderFormat.colorInfo);
fallbackListener.onTransformationRequestFinalized(
createFallbackTransformationRequest(
createSupportedTransformationRequest(
transformationRequest,
/* hasOutputFormatRotation= */ flipOrientation,
requestedEncoderFormat,