Skip to content

Commit

Permalink
HDR: Disable tone mapping on unsupported pixel build ID.
Browse files Browse the repository at this point in the history
Also, update tests to allow AnyOf error codes, and no longer check exception messages, which caused quite a bit of churn.

PiperOrigin-RevId: 479570861
  • Loading branch information
dway123 authored and marcbaechinger committed Oct 20, 2022
1 parent 7c68b8d commit faa796d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ public void transform_noRequestedTranscode_hdr10File_transformsOrThrows() throws
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.");
}
}

Expand Down Expand Up @@ -155,22 +151,11 @@ public void onFallbackApplied(
} 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
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;

Expand Down Expand Up @@ -76,21 +75,10 @@ public void onFallbackApplied(
} 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;
}
}
Expand Down Expand Up @@ -133,21 +121,10 @@ public void onFallbackApplied(
} 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import android.content.Context;
import android.media.MediaCodec;
import android.os.Build;
import android.view.Surface;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
Expand Down Expand Up @@ -76,9 +77,10 @@ public VideoTranscodingSamplePipeline(
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,
Expand Down Expand Up @@ -290,6 +292,11 @@ private static TransformationRequest createSupportedTransformationRequest(
.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.
*
Expand Down

0 comments on commit faa796d

Please sign in to comment.