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 * <p>Should be called with the final {@link TransformationRequest} for each track, after any
* fallback has been applied. Calls {@link Transformer.Listener#onFallbackApplied(MediaItem, * track-specific fallback changes have been applied.
* TransformationRequest, TransformationRequest)} once this method has been called for each track. *
* <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. * @param transformationRequest The final {@link TransformationRequest} for a track.
* @throws IllegalStateException If called for more tracks than registered using {@link * @throws IllegalStateException If called for more tracks than registered using {@link

View File

@ -17,6 +17,7 @@
package androidx.media3.transformer; package androidx.media3.transformer;
import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState;
import android.content.Context; import android.content.Context;
import android.media.MediaCodec; 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 transformationRequest The requested transformation.
* @param hasOutputFormatRotation Whether the input video will be rotated to landscape during * @param hasOutputFormatRotation Whether the input video will be rotated to landscape during
* processing, with {@link Format#rotationDegrees} of 90 added to the output format. * processing, with {@link Format#rotationDegrees} of 90 added to the output format.
* @param requestedFormat The requested format. * @param requestedFormat The requested format.
* @param supportedFormat A format supported by the device. * @param supportedFormat A format supported by the device.
* @param fallbackToSdr Whether HDR editing was requested via the TransformationRequest or * @param isToneMappedToSdr Whether tone mapping to SDR will be applied.
* inferred from the input and tone-mapping to SDR was used instead due to lack of encoder * @return The created instance.
* capabilities.
*/ */
@Pure @Pure
private static TransformationRequest createFallbackTransformationRequest( private static TransformationRequest createSupportedTransformationRequest(
TransformationRequest transformationRequest, TransformationRequest transformationRequest,
boolean hasOutputFormatRotation, boolean hasOutputFormatRotation,
Format requestedFormat, Format requestedFormat,
Format supportedFormat, Format supportedFormat,
boolean fallbackToSdr) { boolean isToneMappedToSdr) {
// 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 (!fallbackToSdr if (transformationRequest.enableRequestSdrToneMapping == isToneMappedToSdr
&& Util.areEqual(requestedFormat.sampleMimeType, supportedFormat.sampleMimeType) && Util.areEqual(requestedFormat.sampleMimeType, supportedFormat.sampleMimeType)
&& (hasOutputFormatRotation && (hasOutputFormatRotation
? requestedFormat.width == supportedFormat.width ? requestedFormat.width == supportedFormat.width
@ -260,7 +261,8 @@ import org.checkerframework.dataflow.qual.Pure;
return transformationRequest; return transformationRequest;
} }
TransformationRequest.Builder transformationRequestBuilder = transformationRequest.buildUpon(); TransformationRequest.Builder transformationRequestBuilder = transformationRequest.buildUpon();
if (fallbackToSdr) { if (transformationRequest.enableRequestSdrToneMapping != isToneMappedToSdr) {
checkState(isToneMappedToSdr);
transformationRequestBuilder transformationRequestBuilder
.setEnableRequestSdrToneMapping(true) .setEnableRequestSdrToneMapping(true)
.experimental_setEnableHdrEditing(false); .experimental_setEnableHdrEditing(false);
@ -429,7 +431,7 @@ import org.checkerframework.dataflow.qual.Pure;
ColorInfo.isTransferHdr(inputFormat.colorInfo) ColorInfo.isTransferHdr(inputFormat.colorInfo)
&& !ColorInfo.isTransferHdr(requestedEncoderFormat.colorInfo); && !ColorInfo.isTransferHdr(requestedEncoderFormat.colorInfo);
fallbackListener.onTransformationRequestFinalized( fallbackListener.onTransformationRequestFinalized(
createFallbackTransformationRequest( createSupportedTransformationRequest(
transformationRequest, transformationRequest,
/* hasOutputFormatRotation= */ flipOrientation, /* hasOutputFormatRotation= */ flipOrientation,
requestedEncoderFormat, requestedEncoderFormat,