Skip to content

Commit

Permalink
HDR: Clarify tone mapping fallback.
Browse files Browse the repository at this point in the history
createSupportedTransformationRequest is more accurate than
createFallbackTransformationRequest, as a TransformationRequest will be returned
regardless of whether any fallback is applied.

PiperOrigin-RevId: 466641277
  • Loading branch information
dway123 authored and marcbaechinger committed Oct 19, 2022
1 parent 9c366b3 commit 70972bb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
Expand Up @@ -65,11 +65,15 @@ public void registerTrack() {
}

/**
* 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
Expand Down
Expand Up @@ -17,6 +17,7 @@
package com.google.android.exoplayer2.transformer;

import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.android.exoplayer2.util.Assertions.checkState;

import android.content.Context;
import android.media.MediaCodec;
Expand Down Expand Up @@ -232,35 +233,36 @@ public void release() {
}

/**
* 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
: requestedFormat.height == supportedFormat.height)) {
return transformationRequest;
}
TransformationRequest.Builder transformationRequestBuilder = transformationRequest.buildUpon();
if (fallbackToSdr) {
if (transformationRequest.enableRequestSdrToneMapping != isToneMappedToSdr) {
checkState(isToneMappedToSdr);
transformationRequestBuilder
.setEnableRequestSdrToneMapping(true)
.experimental_setEnableHdrEditing(false);
Expand Down Expand Up @@ -429,7 +431,7 @@ public SurfaceInfo getSurfaceInfo(int requestedWidth, int requestedHeight)
ColorInfo.isTransferHdr(inputFormat.colorInfo)
&& !ColorInfo.isTransferHdr(requestedEncoderFormat.colorInfo);
fallbackListener.onTransformationRequestFinalized(
createFallbackTransformationRequest(
createSupportedTransformationRequest(
transformationRequest,
/* hasOutputFormatRotation= */ flipOrientation,
requestedEncoderFormat,
Expand Down

0 comments on commit 70972bb

Please sign in to comment.