HDR: Have @C.ColorTransfer check consider NO_VALUE as SDR.
Format.NO_VALUE is a placeholder value for an invalid @C.ColorTransfer, used for example when the decoder doesn't support this transfer function. When encountering this invalid value, interpret this as COLOR_TRANSFER_SDR. Confirmed locally that an exception is thrown when transcoding on p4head, and no exception is thrown when transcoding with this CL. PiperOrigin-RevId: 464135080
This commit is contained in:
parent
480c129c54
commit
687a50e9b3
@ -213,6 +213,8 @@ public final class MediaFormatUtil {
|
|||||||
@Nullable
|
@Nullable
|
||||||
byte[] hdrStaticInfo =
|
byte[] hdrStaticInfo =
|
||||||
hdrStaticInfoByteBuffer != null ? getArray(hdrStaticInfoByteBuffer) : null;
|
hdrStaticInfoByteBuffer != null ? getArray(hdrStaticInfoByteBuffer) : null;
|
||||||
|
// Some devices may produce invalid values from MediaFormat#getInteger.
|
||||||
|
// See b/239435670 for more information.
|
||||||
if (!isValidColorSpace(colorSpace)) {
|
if (!isValidColorSpace(colorSpace)) {
|
||||||
colorSpace = Format.NO_VALUE;
|
colorSpace = Format.NO_VALUE;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package androidx.media3.transformer.mh;
|
package androidx.media3.transformer.mh;
|
||||||
|
|
||||||
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_1080P_1_SECOND_HDR10_VIDEO_SDR_CONTAINER;
|
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_1080P_1_SECOND_HDR10_VIDEO_SDR_CONTAINER;
|
||||||
|
import static androidx.media3.transformer.AndroidTestUtil.recordTestSkipped;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.junit.Assert.assertThrows;
|
import static org.junit.Assert.assertThrows;
|
||||||
|
|
||||||
@ -36,9 +37,14 @@ import org.junit.runner.RunWith;
|
|||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class SetHdrEditingTransformationTest {
|
public class SetHdrEditingTransformationTest {
|
||||||
@Test
|
@Test
|
||||||
public void videoDecoderUnexpectedColorInfo_completesWithError() {
|
public void videoDecoderUnexpectedColorInfo_completesWithError() throws Exception {
|
||||||
Context context = ApplicationProvider.getApplicationContext();
|
Context context = ApplicationProvider.getApplicationContext();
|
||||||
if (Util.SDK_INT < 24) {
|
if (Util.SDK_INT < 29) {
|
||||||
|
recordTestSkipped(
|
||||||
|
context,
|
||||||
|
"SetHdrEditingTransformationTest",
|
||||||
|
/* reason= */ "Skipping on this API version due to lack of support for"
|
||||||
|
+ " MediaFormat#getInteger(String, int).");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,7 +320,7 @@ public final class DefaultCodec implements Codec {
|
|||||||
if (outputBufferIndex < 0) {
|
if (outputBufferIndex < 0) {
|
||||||
if (outputBufferIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
|
if (outputBufferIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
|
||||||
outputFormat = convertToFormat(mediaCodec.getOutputFormat());
|
outputFormat = convertToFormat(mediaCodec.getOutputFormat());
|
||||||
if (!isColorTransferEqual(configuredOutputColor, outputFormat.colorInfo)) {
|
if (!areColorTransfersEqual(configuredOutputColor, outputFormat.colorInfo)) {
|
||||||
// TODO(b/237674316): These exceptions throw when the container ColorInfo doesn't match
|
// TODO(b/237674316): These exceptions throw when the container ColorInfo doesn't match
|
||||||
// the video ColorInfo. Instead of throwing when seeing unexpected ColorInfos, consider
|
// the video ColorInfo. Instead of throwing when seeing unexpected ColorInfos, consider
|
||||||
// reconfiguring downstream components (ex. FrameProcessor and encoder) when different
|
// reconfiguring downstream components (ex. FrameProcessor and encoder) when different
|
||||||
@ -374,12 +374,16 @@ public final class DefaultCodec implements Codec {
|
|||||||
: TransformationException.ERROR_CODE_ENCODING_FAILED);
|
: TransformationException.ERROR_CODE_ENCODING_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isColorTransferEqual(
|
private static boolean areColorTransfersEqual(
|
||||||
@Nullable ColorInfo colorInfo1, @Nullable ColorInfo colorInfo2) {
|
@Nullable ColorInfo colorInfo1, @Nullable ColorInfo colorInfo2) {
|
||||||
@C.ColorTransfer
|
@C.ColorTransfer int transfer1 = C.COLOR_TRANSFER_SDR;
|
||||||
int transfer1 = (colorInfo1 != null) ? colorInfo1.colorTransfer : C.COLOR_TRANSFER_SDR;
|
if (colorInfo1 != null && colorInfo1.colorTransfer != Format.NO_VALUE) {
|
||||||
@C.ColorTransfer
|
transfer1 = colorInfo1.colorTransfer;
|
||||||
int transfer2 = (colorInfo2 != null) ? colorInfo2.colorTransfer : C.COLOR_TRANSFER_SDR;
|
}
|
||||||
|
@C.ColorTransfer int transfer2 = C.COLOR_TRANSFER_SDR;
|
||||||
|
if (colorInfo2 != null && colorInfo2.colorTransfer != Format.NO_VALUE) {
|
||||||
|
transfer2 = colorInfo2.colorTransfer;
|
||||||
|
}
|
||||||
return transfer1 == transfer2;
|
return transfer1 == transfer2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user