diff --git a/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java b/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java index 785f241b67..0e9ac3dd5a 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java @@ -124,8 +124,8 @@ import org.checkerframework.checker.nullness.qual.PolyNull; public final class Util { /** - * Like {@link android.os.Build.VERSION#SDK_INT}, but in a place where it can be conveniently - * overridden for local testing. + * Like {@link Build.VERSION#SDK_INT}, but in a place where it can be conveniently overridden for + * local testing. */ public static final int SDK_INT = Build.VERSION.SDK_INT; diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/SetHdrEditingTest.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/SetHdrEditingTest.java index 33d54581a5..7ba778f2f5 100644 --- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/SetHdrEditingTest.java +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/SetHdrEditingTest.java @@ -77,10 +77,6 @@ public class SetHdrEditingTest { assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class); assertThat(exception.errorCode) .isEqualTo(TransformationException.ERROR_CODE_HDR_EDITING_UNSUPPORTED); - assertThat(exception) - .hasCauseThat() - .hasMessageThat() - .isEqualTo("HDR editing and tone mapping not supported under API 31."); } } @@ -155,22 +151,11 @@ public class SetHdrEditingTest { } catch (TransformationException exception) { Log.i(TAG, checkNotNull(exception.getCause()).toString()); assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class); - if (Util.SDK_INT < 31) { - assertThat(exception.errorCode) - .isEqualTo(TransformationException.ERROR_CODE_HDR_EDITING_UNSUPPORTED); - assertThat(exception) - .hasCauseThat() - .hasMessageThat() - .isEqualTo("HDR editing and tone mapping not supported under API 31."); - } else { - assertThat(exception.errorCode) - .isEqualTo(TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED); - assertThat(exception) - .hasCauseThat() - .hasMessageThat() - .isEqualTo("Tone-mapping requested but not supported by the decoder."); - assertThat(isFallbackListenerInvoked.get()).isFalse(); - } + assertThat(exception.errorCode) + .isAnyOf( + TransformationException.ERROR_CODE_HDR_EDITING_UNSUPPORTED, + TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED); + assertThat(isFallbackListenerInvoked.get()).isFalse(); return; } } diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/SetHdrToSdrToneMapTest.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/SetHdrToSdrToneMapTest.java index 2ba107d7ce..cf2716325b 100644 --- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/SetHdrToSdrToneMapTest.java +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/SetHdrToSdrToneMapTest.java @@ -32,7 +32,6 @@ import com.google.android.exoplayer2.transformer.TransformationTestResult; import com.google.android.exoplayer2.transformer.Transformer; import com.google.android.exoplayer2.transformer.TransformerAndroidTestRunner; import com.google.android.exoplayer2.util.Log; -import com.google.android.exoplayer2.util.Util; import org.junit.Test; import org.junit.runner.RunWith; @@ -76,21 +75,10 @@ public class SetHdrToSdrToneMapTest { } catch (TransformationException exception) { Log.i(TAG, checkNotNull(exception.getCause()).toString()); assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class); - if (Util.SDK_INT < 31) { - assertThat(exception.errorCode) - .isEqualTo(TransformationException.ERROR_CODE_HDR_EDITING_UNSUPPORTED); - assertThat(exception) - .hasCauseThat() - .hasMessageThat() - .isEqualTo("HDR editing and tone mapping not supported under API 31."); - } else { - assertThat(exception.errorCode) - .isEqualTo(TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED); - assertThat(exception) - .hasCauseThat() - .hasMessageThat() - .isEqualTo("Tone-mapping requested but not supported by the decoder."); - } + assertThat(exception.errorCode) + .isAnyOf( + TransformationException.ERROR_CODE_HDR_EDITING_UNSUPPORTED, + TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED); return; } } @@ -133,21 +121,10 @@ public class SetHdrToSdrToneMapTest { } catch (TransformationException exception) { Log.i(TAG, checkNotNull(exception.getCause()).toString()); assertThat(exception).hasCauseThat().isInstanceOf(IllegalArgumentException.class); - if (Util.SDK_INT < 31) { - assertThat(exception.errorCode) - .isEqualTo(TransformationException.ERROR_CODE_HDR_EDITING_UNSUPPORTED); - assertThat(exception) - .hasCauseThat() - .hasMessageThat() - .isEqualTo("HDR editing and tone mapping not supported under API 31."); - } else { - assertThat(exception.errorCode) - .isEqualTo(TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED); - assertThat(exception) - .hasCauseThat() - .hasMessageThat() - .isEqualTo("Tone-mapping requested but not supported by the decoder."); - } + assertThat(exception.errorCode) + .isAnyOf( + TransformationException.ERROR_CODE_HDR_EDITING_UNSUPPORTED, + TransformationException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED); return; } } 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 476a848e3c..e18a4986d1 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 @@ -22,6 +22,7 @@ import static com.google.android.exoplayer2.util.Util.SDK_INT; import android.content.Context; import android.media.MediaCodec; +import android.os.Build; import android.view.Surface; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; @@ -76,9 +77,10 @@ import org.checkerframework.dataflow.qual.Pure; Transformer.AsyncErrorListener asyncErrorListener, DebugViewProvider debugViewProvider) throws TransformationException { - if (SDK_INT < 31 && ColorInfo.isTransferHdr(inputFormat.colorInfo)) { + if (ColorInfo.isTransferHdr(inputFormat.colorInfo) + && (SDK_INT < 31 || deviceNeedsNoToneMappingWorkaround())) { throw TransformationException.createForCodec( - new IllegalArgumentException("HDR editing and tone mapping not supported under API 31."), + new IllegalArgumentException("HDR editing and tone mapping not supported."), /* isVideo= */ true, /* isDecoder= */ false, inputFormat, @@ -290,6 +292,11 @@ import org.checkerframework.dataflow.qual.Pure; .build(); } + private static boolean deviceNeedsNoToneMappingWorkaround() { + // Pixel build ID does not support tone mapping. See http://b/249297370#comment8. + return Build.ID.startsWith("TP1A.220905.004"); + } + /** * Feeds at most one decoder output frame to the next step of the pipeline. *