HDR: Check isToneMappingApplied in HDR editing test.

Assert that tone mapping is applied when an HDR edit cannot be HDR, but is successfully tone mapped. Meanwhile, assert that fallback, which is applied after codec configuration (which throws the "Tone-mapping requested but not supported by the decoder" error) is not applied when that error is called.

PiperOrigin-RevId: 478762951
(cherry picked from commit 36e41059ea9e98aeab105375a683f7cd7481c5a8)
This commit is contained in:
huangdarwin 2022-10-04 13:01:27 +00:00 committed by microkatz
parent c3a6943373
commit a06b0ba5f6

View File

@ -85,8 +85,9 @@ public class SetHdrEditingTest {
} }
@Test @Test
public void transformAndTranscode_hdr10File_whenHdrEditingIsSupported() throws Exception { public void transformAndTranscode_hdr10File_whenHdrEditingIsSupported_transforms()
String testId = "transformAndTranscode_hdr10File_whenHdrEditingIsSupported"; throws Exception {
String testId = "transformAndTranscode_hdr10File_whenHdrEditingIsSupported_transforms";
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
if (!deviceSupportsHdrEditing(VIDEO_H265, HDR10_DEFAULT_COLOR_INFO)) { if (!deviceSupportsHdrEditing(VIDEO_H265, HDR10_DEFAULT_COLOR_INFO)) {
recordTestSkipped(context, testId, /* reason= */ "Device lacks HDR10 editing support."); recordTestSkipped(context, testId, /* reason= */ "Device lacks HDR10 editing support.");
@ -110,15 +111,16 @@ public class SetHdrEditingTest {
} }
@Test @Test
public void transformAndTranscode_hdr10File_toneMapsOrThrows_whenHdrEditingUnsupported() public void transformAndTranscode_hdr10File_whenHdrEditingUnsupported_toneMapsOrThrows()
throws Exception { throws Exception {
String testId = "transformAndTranscode_hdr10File_toneMapsOrThrows_whenHdrEditingUnsupported"; String testId = "transformAndTranscode_hdr10File_whenHdrEditingUnsupported_toneMapsOrThrows";
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
if (deviceSupportsHdrEditing(VIDEO_H265, HDR10_DEFAULT_COLOR_INFO)) { if (deviceSupportsHdrEditing(VIDEO_H265, HDR10_DEFAULT_COLOR_INFO)) {
recordTestSkipped(context, testId, /* reason= */ "Device supports HDR10 editing."); recordTestSkipped(context, testId, /* reason= */ "Device supports HDR10 editing.");
return; return;
} }
AtomicBoolean isFallbackListenerInvoked = new AtomicBoolean();
AtomicBoolean isToneMappingFallbackApplied = new AtomicBoolean(); AtomicBoolean isToneMappingFallbackApplied = new AtomicBoolean();
Transformer transformer = Transformer transformer =
new Transformer.Builder(context) new Transformer.Builder(context)
@ -134,10 +136,10 @@ public class SetHdrEditingTest {
MediaItem inputMediaItem, MediaItem inputMediaItem,
TransformationRequest originalTransformationRequest, TransformationRequest originalTransformationRequest,
TransformationRequest fallbackTransformationRequest) { TransformationRequest fallbackTransformationRequest) {
isFallbackListenerInvoked.set(true);
assertThat(originalTransformationRequest.enableRequestSdrToneMapping).isFalse(); assertThat(originalTransformationRequest.enableRequestSdrToneMapping).isFalse();
if (fallbackTransformationRequest.enableRequestSdrToneMapping) { isToneMappingFallbackApplied.set(
isToneMappingFallbackApplied.set(true); fallbackTransformationRequest.enableRequestSdrToneMapping);
}
} }
}) })
.build(); .build();
@ -148,12 +150,11 @@ public class SetHdrEditingTest {
.build() .build()
.run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10))); .run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_1080P_4_SECOND_HDR10)));
Log.i(TAG, "Tone mapped."); Log.i(TAG, "Tone mapped.");
assertThat(isToneMappingFallbackApplied.get()).isTrue();
assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR); assertFileHasColorTransfer(transformationTestResult.filePath, C.COLOR_TRANSFER_SDR);
} catch (TransformationException exception) { } catch (TransformationException exception) {
Log.i(TAG, checkNotNull(exception.getCause()).toString()); Log.i(TAG, checkNotNull(exception.getCause()).toString());
assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class); assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
// TODO(b/245364266): After fixing the bug, replace the API version check with a check that
// isToneMappingFallbackApplied.get() is true.
if (Util.SDK_INT < 31) { if (Util.SDK_INT < 31) {
assertThat(exception.errorCode) assertThat(exception.errorCode)
.isEqualTo(TransformationException.ERROR_CODE_HDR_EDITING_UNSUPPORTED); .isEqualTo(TransformationException.ERROR_CODE_HDR_EDITING_UNSUPPORTED);
@ -168,6 +169,7 @@ public class SetHdrEditingTest {
.hasCauseThat() .hasCauseThat()
.hasMessageThat() .hasMessageThat()
.isEqualTo("Tone-mapping requested but not supported by the decoder."); .isEqualTo("Tone-mapping requested but not supported by the decoder.");
assertThat(isFallbackListenerInvoked.get()).isFalse();
} }
return; return;
} }