mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Generalize getSupportedEncodersForHdr to return List<MediaCodecInfo>.
This now matches EncoderUtil.getSupportedEncoders return type. PiperOrigin-RevId: 509222078
This commit is contained in:
parent
77e651ad27
commit
dcd1f6bc6b
4 changed files with 33 additions and 31 deletions
|
|
@ -295,6 +295,6 @@ public class HdrEditingTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean deviceSupportsHdrEditing(String mimeType, ColorInfo colorInfo) {
|
private static boolean deviceSupportsHdrEditing(String mimeType, ColorInfo colorInfo) {
|
||||||
return !EncoderUtil.getSupportedEncoderNamesForHdrEditing(mimeType, colorInfo).isEmpty();
|
return !EncoderUtil.getSupportedEncodersForHdrEditing(mimeType, colorInfo).isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,10 +78,11 @@ public final class EncoderUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the names of encoders that support HDR editing for the given {@code mimeType} and
|
* Returns a list of {@linkplain MediaCodecInfo encoders} that support HDR editing for the given
|
||||||
* {@code ColorInfo}, or an empty list if the format is unknown or not supported for HDR encoding.
|
* {@code mimeType} and {@code ColorInfo}, or an empty list if the format is unknown or not
|
||||||
|
* supported for HDR encoding.
|
||||||
*/
|
*/
|
||||||
public static ImmutableList<String> getSupportedEncoderNamesForHdrEditing(
|
public static ImmutableList<MediaCodecInfo> getSupportedEncodersForHdrEditing(
|
||||||
String mimeType, @Nullable ColorInfo colorInfo) {
|
String mimeType, @Nullable ColorInfo colorInfo) {
|
||||||
if (Util.SDK_INT < 31 || colorInfo == null) {
|
if (Util.SDK_INT < 31 || colorInfo == null) {
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
|
|
@ -90,7 +91,7 @@ public final class EncoderUtil {
|
||||||
ImmutableList<MediaCodecInfo> encoders = getSupportedEncoders(mimeType);
|
ImmutableList<MediaCodecInfo> encoders = getSupportedEncoders(mimeType);
|
||||||
ImmutableList<Integer> allowedColorProfiles =
|
ImmutableList<Integer> allowedColorProfiles =
|
||||||
getCodecProfilesForHdrFormat(mimeType, colorInfo.colorTransfer);
|
getCodecProfilesForHdrFormat(mimeType, colorInfo.colorTransfer);
|
||||||
ImmutableList.Builder<String> resultBuilder = new ImmutableList.Builder<>();
|
ImmutableList.Builder<MediaCodecInfo> resultBuilder = new ImmutableList.Builder<>();
|
||||||
for (int i = 0; i < encoders.size(); i++) {
|
for (int i = 0; i < encoders.size(); i++) {
|
||||||
MediaCodecInfo mediaCodecInfo = encoders.get(i);
|
MediaCodecInfo mediaCodecInfo = encoders.get(i);
|
||||||
if (mediaCodecInfo.isAlias()
|
if (mediaCodecInfo.isAlias()
|
||||||
|
|
@ -101,7 +102,7 @@ public final class EncoderUtil {
|
||||||
for (MediaCodecInfo.CodecProfileLevel codecProfileLevel :
|
for (MediaCodecInfo.CodecProfileLevel codecProfileLevel :
|
||||||
mediaCodecInfo.getCapabilitiesForType(mimeType).profileLevels) {
|
mediaCodecInfo.getCapabilitiesForType(mimeType).profileLevels) {
|
||||||
if (allowedColorProfiles.contains(codecProfileLevel.profile)) {
|
if (allowedColorProfiles.contains(codecProfileLevel.profile)) {
|
||||||
resultBuilder.add(mediaCodecInfo.getName());
|
resultBuilder.add(mediaCodecInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package com.google.android.exoplayer2.transformer;
|
package com.google.android.exoplayer2.transformer;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.transformer.EncoderUtil.getSupportedEncoders;
|
||||||
|
import static com.google.android.exoplayer2.transformer.EncoderUtil.getSupportedEncodersForHdrEditing;
|
||||||
import static com.google.android.exoplayer2.transformer.TransformationRequest.HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR;
|
import static com.google.android.exoplayer2.transformer.TransformationRequest.HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR;
|
||||||
import static com.google.android.exoplayer2.transformer.TransformationRequest.HDR_MODE_KEEP_HDR;
|
import static com.google.android.exoplayer2.transformer.TransformationRequest.HDR_MODE_KEEP_HDR;
|
||||||
import static com.google.android.exoplayer2.transformer.TransformationRequest.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC;
|
import static com.google.android.exoplayer2.transformer.TransformationRequest.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC;
|
||||||
|
|
@ -23,6 +25,7 @@ import static com.google.android.exoplayer2.transformer.TransformationRequest.HD
|
||||||
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
|
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
|
||||||
import static com.google.android.exoplayer2.util.Assertions.checkState;
|
import static com.google.android.exoplayer2.util.Assertions.checkState;
|
||||||
import static com.google.android.exoplayer2.util.Util.SDK_INT;
|
import static com.google.android.exoplayer2.util.Util.SDK_INT;
|
||||||
|
import static com.google.android.exoplayer2.video.ColorInfo.isTransferHdr;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
|
@ -84,7 +87,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
||||||
super(firstInputFormat, streamStartPositionUs, muxerWrapper);
|
super(firstInputFormat, streamStartPositionUs, muxerWrapper);
|
||||||
|
|
||||||
boolean isGlToneMapping = false;
|
boolean isGlToneMapping = false;
|
||||||
if (ColorInfo.isTransferHdr(firstInputFormat.colorInfo)) {
|
if (isTransferHdr(firstInputFormat.colorInfo)) {
|
||||||
if (transformationRequest.hdrMode == HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR) {
|
if (transformationRequest.hdrMode == HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR) {
|
||||||
if (SDK_INT < 29) {
|
if (SDK_INT < 29) {
|
||||||
throw TransformationException.createForCodec(
|
throw TransformationException.createForCodec(
|
||||||
|
|
@ -339,7 +342,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
||||||
private final TransformationRequest transformationRequest;
|
private final TransformationRequest transformationRequest;
|
||||||
private final FallbackListener fallbackListener;
|
private final FallbackListener fallbackListener;
|
||||||
private final String requestedOutputMimeType;
|
private final String requestedOutputMimeType;
|
||||||
private final ImmutableList<String> supportedEncoderNamesForHdrEditing;
|
private final boolean isHdrEditingEnabled;
|
||||||
|
|
||||||
private @MonotonicNonNull SurfaceInfo encoderSurfaceInfo;
|
private @MonotonicNonNull SurfaceInfo encoderSurfaceInfo;
|
||||||
|
|
||||||
|
|
@ -358,7 +361,6 @@ import org.checkerframework.dataflow.qual.Pure;
|
||||||
this.muxerSupportedMimeTypes = muxerSupportedMimeTypes;
|
this.muxerSupportedMimeTypes = muxerSupportedMimeTypes;
|
||||||
this.transformationRequest = transformationRequest;
|
this.transformationRequest = transformationRequest;
|
||||||
this.fallbackListener = fallbackListener;
|
this.fallbackListener = fallbackListener;
|
||||||
|
|
||||||
String inputSampleMimeType = checkNotNull(inputFormat.sampleMimeType);
|
String inputSampleMimeType = checkNotNull(inputFormat.sampleMimeType);
|
||||||
|
|
||||||
if (transformationRequest.videoMimeType != null) {
|
if (transformationRequest.videoMimeType != null) {
|
||||||
|
|
@ -368,18 +370,17 @@ import org.checkerframework.dataflow.qual.Pure;
|
||||||
} else {
|
} else {
|
||||||
requestedOutputMimeType = inputSampleMimeType;
|
requestedOutputMimeType = inputSampleMimeType;
|
||||||
}
|
}
|
||||||
supportedEncoderNamesForHdrEditing =
|
|
||||||
EncoderUtil.getSupportedEncoderNamesForHdrEditing(
|
isHdrEditingEnabled =
|
||||||
requestedOutputMimeType, inputFormat.colorInfo);
|
transformationRequest.hdrMode == HDR_MODE_KEEP_HDR
|
||||||
|
&& !getSupportedEncodersForHdrEditing(requestedOutputMimeType, inputFormat.colorInfo)
|
||||||
|
.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the {@link ColorInfo} expected from the input surface. */
|
/** Returns the {@link ColorInfo} expected from the input surface. */
|
||||||
public ColorInfo getSupportedInputColor() {
|
public ColorInfo getSupportedInputColor() {
|
||||||
boolean isHdrEditingEnabled =
|
|
||||||
transformationRequest.hdrMode == HDR_MODE_KEEP_HDR
|
boolean isInputToneMapped = !isHdrEditingEnabled && isTransferHdr(inputFormat.colorInfo);
|
||||||
&& !supportedEncoderNamesForHdrEditing.isEmpty();
|
|
||||||
boolean isInputToneMapped =
|
|
||||||
!isHdrEditingEnabled && ColorInfo.isTransferHdr(inputFormat.colorInfo);
|
|
||||||
if (isInputToneMapped) {
|
if (isInputToneMapped) {
|
||||||
// When tone-mapping HDR to SDR is enabled, assume we get BT.709 to avoid having the encoder
|
// When tone-mapping HDR to SDR is enabled, assume we get BT.709 to avoid having the encoder
|
||||||
// populate default color info, which depends on the resolution.
|
// populate default color info, which depends on the resolution.
|
||||||
|
|
@ -440,8 +441,8 @@ import org.checkerframework.dataflow.qual.Pure;
|
||||||
checkState(supportedMimeType.equals(encoderSupportedFormat.sampleMimeType));
|
checkState(supportedMimeType.equals(encoderSupportedFormat.sampleMimeType));
|
||||||
|
|
||||||
boolean isInputToneMapped =
|
boolean isInputToneMapped =
|
||||||
ColorInfo.isTransferHdr(inputFormat.colorInfo)
|
isTransferHdr(inputFormat.colorInfo) && !isTransferHdr(requestedEncoderFormat.colorInfo);
|
||||||
&& !ColorInfo.isTransferHdr(requestedEncoderFormat.colorInfo);
|
|
||||||
// HdrMode fallback is only supported from HDR_MODE_KEEP_HDR to
|
// HdrMode fallback is only supported from HDR_MODE_KEEP_HDR to
|
||||||
// HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC.
|
// HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC.
|
||||||
@TransformationRequest.HdrMode
|
@TransformationRequest.HdrMode
|
||||||
|
|
@ -557,10 +558,10 @@ import org.checkerframework.dataflow.qual.Pure;
|
||||||
if (!muxerSupportedMimeTypes.contains(mimeType)) {
|
if (!muxerSupportedMimeTypes.contains(mimeType)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (ColorInfo.isTransferHdr(colorInfo)) {
|
|
||||||
return !EncoderUtil.getSupportedEncoderNamesForHdrEditing(mimeType, colorInfo).isEmpty();
|
return isTransferHdr(colorInfo)
|
||||||
}
|
? !getSupportedEncodersForHdrEditing(mimeType, colorInfo).isEmpty()
|
||||||
return !EncoderUtil.getSupportedEncoders(mimeType).isEmpty();
|
: !getSupportedEncoders(mimeType).isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -165,23 +165,23 @@ public class EncoderUtilTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see EncoderUtil#getSupportedEncoderNamesForHdrEditing(String, ColorInfo)
|
* @see EncoderUtil#getSupportedEncodersForHdrEditing(String, ColorInfo)
|
||||||
*/
|
*/
|
||||||
@Config(sdk = {30, 31})
|
@Config(sdk = {30, 31})
|
||||||
@Test
|
@Test
|
||||||
public void getSupportedEncoderNamesForHdrEditing_returnsEmptyList() {
|
public void getSupportedEncodersForHdrEditing_returnsEmptyList() {
|
||||||
// This test is run on 30 and 31 because the tested logic differentiate at API31.
|
// This test is run on 30 and 31 because the tested logic differentiate at API31.
|
||||||
// getSupportedEncoderNamesForHdrEditing returns an empty list for API < 31. It returns an empty
|
// getSupportedEncoderNamesForHdrEditing returns an empty list for API < 31. It returns an empty
|
||||||
// list for API >= 31 as well, because currently it is not possible to make ShadowMediaCodec
|
// list for API >= 31 as well, because currently it is not possible to make ShadowMediaCodec
|
||||||
// support HDR.
|
// support HDR.
|
||||||
assertThat(
|
assertThat(
|
||||||
EncoderUtil.getSupportedEncoderNamesForHdrEditing(
|
EncoderUtil.getSupportedEncodersForHdrEditing(
|
||||||
MIME_TYPE,
|
MIME_TYPE,
|
||||||
new ColorInfo(
|
new ColorInfo.Builder()
|
||||||
C.COLOR_SPACE_BT2020,
|
.setColorSpace(C.COLOR_SPACE_BT2020)
|
||||||
C.COLOR_RANGE_FULL,
|
.setColorRange(C.COLOR_RANGE_FULL)
|
||||||
C.COLOR_TRANSFER_HLG,
|
.setColorTransfer(C.COLOR_TRANSFER_HLG)
|
||||||
/* hdrStaticInfo= */ null)))
|
.build()))
|
||||||
.isEmpty();
|
.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue