Skip to content

Commit

Permalink
HDR: For HDR videos, enableHdrEditing by default.
Browse files Browse the repository at this point in the history
Previously, tone-mapping was the default.

PiperOrigin-RevId: 488362209
  • Loading branch information
dway123 authored and icbaker committed Nov 14, 2022
1 parent afb7926 commit 5397810
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public final class ConfigurationActivity extends AppCompatActivity {
public static final String ENABLE_DEBUG_PREVIEW = "enable_debug_preview";
public static final String ENABLE_REQUEST_SDR_TONE_MAPPING = "enable_request_sdr_tone_mapping";
public static final String FORCE_INTERPRET_HDR_VIDEO_AS_SDR = "force_interpret_hdr_video_as_sdr";
public static final String ENABLE_HDR_EDITING = "enable_hdr_editing";
public static final String DEMO_EFFECTS_SELECTIONS = "demo_effects_selections";
public static final String PERIODIC_VIGNETTE_CENTER_X = "periodic_vignette_center_x";
public static final String PERIODIC_VIGNETTE_CENTER_Y = "periodic_vignette_center_y";
Expand Down Expand Up @@ -157,7 +156,6 @@ public final class ConfigurationActivity extends AppCompatActivity {
private @MonotonicNonNull CheckBox enableDebugPreviewCheckBox;
private @MonotonicNonNull CheckBox enableRequestSdrToneMappingCheckBox;
private @MonotonicNonNull CheckBox forceInterpretHdrVideoAsSdrCheckBox;
private @MonotonicNonNull CheckBox enableHdrEditingCheckBox;
private @MonotonicNonNull Button selectDemoEffectsButton;
private boolean @MonotonicNonNull [] demoEffectsSelections;
private @Nullable Uri localFileUri;
Expand Down Expand Up @@ -254,7 +252,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
findViewById(R.id.request_sdr_tone_mapping).setEnabled(isRequestSdrToneMappingSupported());
forceInterpretHdrVideoAsSdrCheckBox =
findViewById(R.id.force_interpret_hdr_video_as_sdr_checkbox);
enableHdrEditingCheckBox = findViewById(R.id.hdr_editing_checkbox);

demoEffectsSelections = new boolean[DEMO_EFFECTS.length];
selectDemoEffectsButton = findViewById(R.id.select_demo_effects_button);
Expand Down Expand Up @@ -313,7 +310,6 @@ protected void onNewIntent(Intent intent) {
"enableDebugPreviewCheckBox",
"enableRequestSdrToneMappingCheckBox",
"forceInterpretHdrVideoAsSdrCheckBox",
"enableHdrEditingCheckBox",
"demoEffectsSelections"
})
private void startTransformation(View view) {
Expand Down Expand Up @@ -355,7 +351,6 @@ private void startTransformation(View view) {
ENABLE_REQUEST_SDR_TONE_MAPPING, enableRequestSdrToneMappingCheckBox.isChecked());
bundle.putBoolean(
FORCE_INTERPRET_HDR_VIDEO_AS_SDR, forceInterpretHdrVideoAsSdrCheckBox.isChecked());
bundle.putBoolean(ENABLE_HDR_EDITING, enableHdrEditingCheckBox.isChecked());
bundle.putBooleanArray(DEMO_EFFECTS_SELECTIONS, demoEffectsSelections);
bundle.putInt(COLOR_FILTER_SELECTION, colorFilterSelection);
bundle.putFloat(CONTRAST_VALUE, contrastValue);
Expand Down Expand Up @@ -595,7 +590,6 @@ private void controlPeriodicVignetteSettings() {
"enableDebugPreviewCheckBox",
"enableRequestSdrToneMappingCheckBox",
"forceInterpretHdrVideoAsSdrCheckBox",
"enableHdrEditingCheckBox",
"selectDemoEffectsButton"
})
private void onRemoveAudio(View view) {
Expand All @@ -617,7 +611,6 @@ private void onRemoveAudio(View view) {
"enableDebugPreviewCheckBox",
"enableRequestSdrToneMappingCheckBox",
"forceInterpretHdrVideoAsSdrCheckBox",
"enableHdrEditingCheckBox",
"selectDemoEffectsButton"
})
private void onRemoveVideo(View view) {
Expand All @@ -638,7 +631,6 @@ private void onRemoveVideo(View view) {
"enableDebugPreviewCheckBox",
"enableRequestSdrToneMappingCheckBox",
"forceInterpretHdrVideoAsSdrCheckBox",
"enableHdrEditingCheckBox",
"selectDemoEffectsButton"
})
private void enableTrackSpecificOptions(boolean isAudioEnabled, boolean isVideoEnabled) {
Expand All @@ -651,7 +643,6 @@ private void enableTrackSpecificOptions(boolean isAudioEnabled, boolean isVideoE
enableRequestSdrToneMappingCheckBox.setEnabled(
isRequestSdrToneMappingSupported() && isVideoEnabled);
forceInterpretHdrVideoAsSdrCheckBox.setEnabled(isVideoEnabled);
enableHdrEditingCheckBox.setEnabled(isVideoEnabled);
selectDemoEffectsButton.setEnabled(isVideoEnabled);

findViewById(R.id.audio_mime_text_view).setEnabled(isAudioEnabled);
Expand All @@ -662,7 +653,6 @@ private void enableTrackSpecificOptions(boolean isAudioEnabled, boolean isVideoE
findViewById(R.id.request_sdr_tone_mapping)
.setEnabled(isRequestSdrToneMappingSupported() && isVideoEnabled);
findViewById(R.id.force_interpret_hdr_video_as_sdr).setEnabled(isVideoEnabled);
findViewById(R.id.hdr_editing).setEnabled(isVideoEnabled);
}

private static boolean isRequestSdrToneMappingSupported() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ private Transformer createTransformer(@Nullable Bundle bundle, String filePath)
bundle.getBoolean(ConfigurationActivity.ENABLE_REQUEST_SDR_TONE_MAPPING));
requestBuilder.experimental_setForceInterpretHdrVideoAsSdr(
bundle.getBoolean(ConfigurationActivity.FORCE_INTERPRET_HDR_VIDEO_AS_SDR));
requestBuilder.experimental_setEnableHdrEditing(
bundle.getBoolean(ConfigurationActivity.ENABLE_HDR_EDITING));
transformerBuilder
.setTransformationRequest(requestBuilder.build())
.setRemoveAudio(bundle.getBoolean(ConfigurationActivity.SHOULD_REMOVE_AUDIO))
Expand Down
10 changes: 0 additions & 10 deletions demos/transformer/src/main/res/layout/configuration_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,6 @@
android:id="@+id/request_sdr_tone_mapping_checkbox"
android:layout_gravity="end" />
</TableRow>
<TableRow
android:layout_weight="1">
<TextView
android:layout_gravity="center_vertical"
android:id="@+id/hdr_editing"
android:text="@string/hdr_editing" />
<CheckBox
android:id="@+id/hdr_editing_checkbox"
android:layout_gravity="end" />
</TableRow>
<TableRow
android:layout_weight="1">
<TextView
Expand Down
1 change: 0 additions & 1 deletion demos/transformer/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<string name="trim" translatable="false">Trim</string>
<string name="request_sdr_tone_mapping" translatable="false">Request SDR tone-mapping (API 31+)</string>
<string name="force_interpret_hdr_video_as_sdr" translatable="false">[Experimental] Force interpret HDR video as SDR (API 29+)</string>
<string name="hdr_editing" translatable="false">[Experimental] HDR editing (API 31+)</string>
<string name="select_demo_effects" translatable="false">Add demo effects</string>
<string name="periodic_vignette_options" translatable="false">Periodic vignette options</string>
<string name="no_media_pipe_error" translatable="false">Failed to load MediaPipe processor. Check the README for instructions.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* {@link Transformer} instrumentation test for applying an {@linkplain
* TransformationRequest.Builder#experimental_setEnableHdrEditing HDR frame edit}.
*/
/** {@link Transformer} instrumentation test for applying an HDR frame edit. */
@RunWith(AndroidJUnit4.class)
public class SetHdrEditingTest {
public static final String TAG = "SetHdrEditingTest";
Expand All @@ -68,11 +65,7 @@ public void transform_noRequestedTranscode_hdr10File_transformsOrThrows() throws
String testId = "transform_noRequestedTranscode_hdr10File_transformsOrThrows";
Context context = ApplicationProvider.getApplicationContext();

Transformer transformer =
new Transformer.Builder(context)
.setTransformationRequest(
new TransformationRequest.Builder().experimental_setEnableHdrEditing(true).build())
.build();
Transformer transformer = new Transformer.Builder(context).build();

try {
TransformationTestResult transformationTestResult =
Expand All @@ -95,11 +88,7 @@ public void transform_noRequestedTranscode_hlg10File_transformsOrThrows() throws
String testId = "transform_noRequestedTranscode_hlg10File_transformsOrThrows";
Context context = ApplicationProvider.getApplicationContext();

Transformer transformer =
new Transformer.Builder(context)
.setTransformationRequest(
new TransformationRequest.Builder().experimental_setEnableHdrEditing(true).build())
.build();
Transformer transformer = new Transformer.Builder(context).build();

try {
TransformationTestResult transformationTestResult =
Expand Down Expand Up @@ -130,10 +119,7 @@ public void transformAndTranscode_hdr10File_whenHdrEditingIsSupported_transforms
Transformer transformer =
new Transformer.Builder(context)
.setTransformationRequest(
new TransformationRequest.Builder()
.experimental_setEnableHdrEditing(true)
.setRotationDegrees(180)
.build())
new TransformationRequest.Builder().setRotationDegrees(180).build())
.build();

TransformationTestResult transformationTestResult =
Expand All @@ -156,10 +142,7 @@ public void transformAndTranscode_hlg10File_whenHdrEditingIsSupported_transforms
Transformer transformer =
new Transformer.Builder(context)
.setTransformationRequest(
new TransformationRequest.Builder()
.experimental_setEnableHdrEditing(true)
.setRotationDegrees(180)
.build())
new TransformationRequest.Builder().setRotationDegrees(180).build())
.build();

TransformationTestResult transformationTestResult =
Expand All @@ -184,10 +167,7 @@ public void transformAndTranscode_hdr10File_whenHdrEditingUnsupported_toneMapsOr
Transformer transformer =
new Transformer.Builder(context)
.setTransformationRequest(
new TransformationRequest.Builder()
.experimental_setEnableHdrEditing(true)
.setRotationDegrees(180)
.build())
new TransformationRequest.Builder().setRotationDegrees(180).build())
.addListener(
new Transformer.Listener() {
@Override
Expand Down Expand Up @@ -238,10 +218,7 @@ public void transformAndTranscode_hlg10File_whenHdrEditingUnsupported_toneMapsOr
Transformer transformer =
new Transformer.Builder(context)
.setTransformationRequest(
new TransformationRequest.Builder()
.experimental_setEnableHdrEditing(true)
.setRotationDegrees(180)
.build())
new TransformationRequest.Builder().setRotationDegrees(180).build())
.addListener(
new Transformer.Listener() {
@Override
Expand Down Expand Up @@ -289,11 +266,7 @@ public void transformUnexpectedColorInfo() throws Exception {
return;
}

Transformer transformer =
new Transformer.Builder(context)
.setTransformationRequest(
new TransformationRequest.Builder().experimental_setEnableHdrEditing(true).build())
.build();
Transformer transformer = new Transformer.Builder(context).build();
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ public void onTransformationRequestFinalized(TransformationRequest transformatio
if (transformationRequest.outputHeight != originalTransformationRequest.outputHeight) {
fallbackRequestBuilder.setResolution(transformationRequest.outputHeight);
}
if (transformationRequest.enableHdrEditing != originalTransformationRequest.enableHdrEditing) {
fallbackRequestBuilder.experimental_setEnableHdrEditing(
transformationRequest.enableHdrEditing);
}
if (transformationRequest.enableRequestSdrToneMapping
!= originalTransformationRequest.enableRequestSdrToneMapping) {
fallbackRequestBuilder.setEnableRequestSdrToneMapping(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public Builder() {
scaleX = 1;
scaleY = 1;
outputHeight = C.LENGTH_UNSET;
enableHdrEditing = true;
}

private Builder(TransformationRequest transformationRequest) {
Expand Down Expand Up @@ -218,13 +219,14 @@ public Builder setAudioMimeType(@Nullable String audioMimeType) {
* supported, high dynamic range (HDR) input will be tone-mapped into an SDR opto-electrical
* transfer function before processing.
*
* <p>The default value is {@code true}, which corresponds to tone-mapping output if possible.
* <p>The default value is {@code false}, which corresponds to editing and outputting HDR video
* if possible, and falling back to tone-mapping if not.
*
* <p>The setting has no effect if the input is already in SDR, or if tone-mapping is not
* supported. Currently tone-mapping is only guaranteed to be supported from Android T onwards.
*
* <p>Setting this as {@code true} will set {@linkplain #experimental_setEnableHdrEditing} and
* {@linkplain #forceInterpretHdrVideoAsSdr} to {@code false}.
* <p>Setting this as {@code true} will set {@linkplain #enableHdrEditing} and {@linkplain
* #forceInterpretHdrVideoAsSdr} to {@code false}.
*
* @param enableRequestSdrToneMapping Whether to request tone-mapping down to SDR.
* @return This builder.
Expand All @@ -233,17 +235,17 @@ public Builder setAudioMimeType(@Nullable String audioMimeType) {
public Builder setEnableRequestSdrToneMapping(boolean enableRequestSdrToneMapping) {
this.enableRequestSdrToneMapping = enableRequestSdrToneMapping;
if (enableRequestSdrToneMapping) {
forceInterpretHdrVideoAsSdr = false;
enableHdrEditing = false;
forceInterpretHdrVideoAsSdr = false;
}
return this;
}

/**
* Sets whether to interpret HDR video as SDR, resulting in washed out video.
*
* <p>The default value is {@code false}, with {@link #setEnableRequestSdrToneMapping} being
* applied.
* <p>The default value is {@code false}, which corresponds to editing and outputting HDR video
* if possible, and falling back to tone-mapping if not.
*
* <p>Use of this flag may result in {@code
* TransformationException.ERROR_CODE_HDR_DECODING_UNSUPPORTED} or {@code
Expand All @@ -257,8 +259,8 @@ public Builder setEnableRequestSdrToneMapping(boolean enableRequestSdrToneMappin
*
* <p>The setting has no effect if the input is already in SDR.
*
* <p>Setting this as {@code true} will set {@linkplain #experimental_setEnableHdrEditing} and
* {@linkplain #forceInterpretHdrVideoAsSdr} to {@code false}.
* <p>Setting this as {@code true} will set {@linkplain #enableHdrEditing} and {@linkplain
* #forceInterpretHdrVideoAsSdr} to {@code false}.
*
* @param forceInterpretHdrVideoAsSdr Whether to interpret HDR contents as SDR.
* @return This builder.
Expand All @@ -276,32 +278,12 @@ public Builder experimental_setForceInterpretHdrVideoAsSdr(
}

/**
* Sets whether to allow processing high dynamic range (HDR) input video streams as HDR.
*
* <p>The default value is {@code false}, with {@link #setEnableRequestSdrToneMapping} being
* applied.
*
* <p>This method is experimental, and will be renamed or removed in a future release. The HDR
* editing feature is under development and is intended for developing/testing HDR support.
*
* <p>Setting this as {@code true} will set {@linkplain #experimental_setEnableHdrEditing} and
* {@linkplain #forceInterpretHdrVideoAsSdr} to {@code false}.
*
* <p>With this flag enabled, HDR streams will correctly edit in HDR, convert via tone-mapping
* to SDR, or throw an error, based on the device's HDR support. SDR streams will be interpreted
* the same way regardless of this flag's state.
*
* @param enableHdrEditing Whether to attempt to process any input video stream as a high
* dynamic range (HDR) signal.
* @return This builder.
* @deprecated This method is now a no-op. (@code experimental_setEnableHdrEditing(true)} is now
* the default behavior.
*/
@Deprecated
@CanIgnoreReturnValue
public Builder experimental_setEnableHdrEditing(boolean enableHdrEditing) {
this.enableHdrEditing = enableHdrEditing;
if (enableHdrEditing) {
enableRequestSdrToneMapping = false;
forceInterpretHdrVideoAsSdr = false;
}
return this;
}

Expand Down Expand Up @@ -373,11 +355,7 @@ public TransformationRequest build() {
/** Whether to force interpreting HDR video as SDR. */
public final boolean forceInterpretHdrVideoAsSdr;

/**
* Whether to attempt to process any input video stream as a high dynamic range (HDR) signal.
*
* @see Builder#experimental_setEnableHdrEditing(boolean)
*/
/** Whether to attempt to process any input video stream as a high dynamic range (HDR) signal. */
public final boolean enableHdrEditing;

private TransformationRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,7 @@ private static TransformationRequest createSupportedTransformationRequest(
TransformationRequest.Builder transformationRequestBuilder = transformationRequest.buildUpon();
if (transformationRequest.enableRequestSdrToneMapping != isToneMappedToSdr) {
checkState(isToneMappedToSdr);
transformationRequestBuilder
.setEnableRequestSdrToneMapping(true)
.experimental_setEnableHdrEditing(false);
transformationRequestBuilder.setEnableRequestSdrToneMapping(true);
}
return transformationRequestBuilder
.setVideoMimeType(supportedFormat.sampleMimeType)
Expand Down

0 comments on commit 5397810

Please sign in to comment.