diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FallbackListener.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FallbackListener.java index 226065e41e6..69063d990a4 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FallbackListener.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FallbackListener.java @@ -65,11 +65,15 @@ public void registerTrack() { } /** - * Updates the fallback {@link TransformationRequest}. + * Updates the {@link TransformationRequest}, if fallback is applied. * - *

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. + *

Should be called with the final {@link TransformationRequest} for each track, after any + * track-specific fallback changes have been applied. + * + *

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 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 aca208750ee..5bd6f3c16fa 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 @@ -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; @@ -232,27 +233,27 @@ 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 @@ -260,7 +261,8 @@ private static TransformationRequest createFallbackTransformationRequest( 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 @@ public SurfaceInfo getSurfaceInfo(int requestedWidth, int requestedHeight) ColorInfo.isTransferHdr(inputFormat.colorInfo) && !ColorInfo.isTransferHdr(requestedEncoderFormat.colorInfo); fallbackListener.onTransformationRequestFinalized( - createFallbackTransformationRequest( + createSupportedTransformationRequest( transformationRequest, /* hasOutputFormatRotation= */ flipOrientation, requestedEncoderFormat,