mirror of
https://github.com/samsonjs/media.git
synced 2026-03-31 10:25:48 +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) {
|
||||
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
|
||||
* {@code ColorInfo}, or an empty list if the format is unknown or not supported for HDR encoding.
|
||||
* Returns a list of {@linkplain MediaCodecInfo encoders} that support HDR editing for the given
|
||||
* {@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) {
|
||||
if (Util.SDK_INT < 31 || colorInfo == null) {
|
||||
return ImmutableList.of();
|
||||
|
|
@ -90,7 +91,7 @@ public final class EncoderUtil {
|
|||
ImmutableList<MediaCodecInfo> encoders = getSupportedEncoders(mimeType);
|
||||
ImmutableList<Integer> allowedColorProfiles =
|
||||
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++) {
|
||||
MediaCodecInfo mediaCodecInfo = encoders.get(i);
|
||||
if (mediaCodecInfo.isAlias()
|
||||
|
|
@ -101,7 +102,7 @@ public final class EncoderUtil {
|
|||
for (MediaCodecInfo.CodecProfileLevel codecProfileLevel :
|
||||
mediaCodecInfo.getCapabilitiesForType(mimeType).profileLevels) {
|
||||
if (allowedColorProfiles.contains(codecProfileLevel.profile)) {
|
||||
resultBuilder.add(mediaCodecInfo.getName());
|
||||
resultBuilder.add(mediaCodecInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
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_KEEP_HDR;
|
||||
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.checkState;
|
||||
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.graphics.Bitmap;
|
||||
|
|
@ -84,7 +87,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||
super(firstInputFormat, streamStartPositionUs, muxerWrapper);
|
||||
|
||||
boolean isGlToneMapping = false;
|
||||
if (ColorInfo.isTransferHdr(firstInputFormat.colorInfo)) {
|
||||
if (isTransferHdr(firstInputFormat.colorInfo)) {
|
||||
if (transformationRequest.hdrMode == HDR_MODE_EXPERIMENTAL_FORCE_INTERPRET_HDR_AS_SDR) {
|
||||
if (SDK_INT < 29) {
|
||||
throw TransformationException.createForCodec(
|
||||
|
|
@ -339,7 +342,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||
private final TransformationRequest transformationRequest;
|
||||
private final FallbackListener fallbackListener;
|
||||
private final String requestedOutputMimeType;
|
||||
private final ImmutableList<String> supportedEncoderNamesForHdrEditing;
|
||||
private final boolean isHdrEditingEnabled;
|
||||
|
||||
private @MonotonicNonNull SurfaceInfo encoderSurfaceInfo;
|
||||
|
||||
|
|
@ -358,7 +361,6 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||
this.muxerSupportedMimeTypes = muxerSupportedMimeTypes;
|
||||
this.transformationRequest = transformationRequest;
|
||||
this.fallbackListener = fallbackListener;
|
||||
|
||||
String inputSampleMimeType = checkNotNull(inputFormat.sampleMimeType);
|
||||
|
||||
if (transformationRequest.videoMimeType != null) {
|
||||
|
|
@ -368,18 +370,17 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||
} else {
|
||||
requestedOutputMimeType = inputSampleMimeType;
|
||||
}
|
||||
supportedEncoderNamesForHdrEditing =
|
||||
EncoderUtil.getSupportedEncoderNamesForHdrEditing(
|
||||
requestedOutputMimeType, inputFormat.colorInfo);
|
||||
|
||||
isHdrEditingEnabled =
|
||||
transformationRequest.hdrMode == HDR_MODE_KEEP_HDR
|
||||
&& !getSupportedEncodersForHdrEditing(requestedOutputMimeType, inputFormat.colorInfo)
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
/** Returns the {@link ColorInfo} expected from the input surface. */
|
||||
public ColorInfo getSupportedInputColor() {
|
||||
boolean isHdrEditingEnabled =
|
||||
transformationRequest.hdrMode == HDR_MODE_KEEP_HDR
|
||||
&& !supportedEncoderNamesForHdrEditing.isEmpty();
|
||||
boolean isInputToneMapped =
|
||||
!isHdrEditingEnabled && ColorInfo.isTransferHdr(inputFormat.colorInfo);
|
||||
|
||||
boolean isInputToneMapped = !isHdrEditingEnabled && isTransferHdr(inputFormat.colorInfo);
|
||||
if (isInputToneMapped) {
|
||||
// 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.
|
||||
|
|
@ -440,8 +441,8 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||
checkState(supportedMimeType.equals(encoderSupportedFormat.sampleMimeType));
|
||||
|
||||
boolean isInputToneMapped =
|
||||
ColorInfo.isTransferHdr(inputFormat.colorInfo)
|
||||
&& !ColorInfo.isTransferHdr(requestedEncoderFormat.colorInfo);
|
||||
isTransferHdr(inputFormat.colorInfo) && !isTransferHdr(requestedEncoderFormat.colorInfo);
|
||||
|
||||
// HdrMode fallback is only supported from HDR_MODE_KEEP_HDR to
|
||||
// HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC.
|
||||
@TransformationRequest.HdrMode
|
||||
|
|
@ -557,10 +558,10 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||
if (!muxerSupportedMimeTypes.contains(mimeType)) {
|
||||
return false;
|
||||
}
|
||||
if (ColorInfo.isTransferHdr(colorInfo)) {
|
||||
return !EncoderUtil.getSupportedEncoderNamesForHdrEditing(mimeType, colorInfo).isEmpty();
|
||||
}
|
||||
return !EncoderUtil.getSupportedEncoders(mimeType).isEmpty();
|
||||
|
||||
return isTransferHdr(colorInfo)
|
||||
? !getSupportedEncodersForHdrEditing(mimeType, colorInfo).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})
|
||||
@Test
|
||||
public void getSupportedEncoderNamesForHdrEditing_returnsEmptyList() {
|
||||
public void getSupportedEncodersForHdrEditing_returnsEmptyList() {
|
||||
// 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
|
||||
// list for API >= 31 as well, because currently it is not possible to make ShadowMediaCodec
|
||||
// support HDR.
|
||||
assertThat(
|
||||
EncoderUtil.getSupportedEncoderNamesForHdrEditing(
|
||||
EncoderUtil.getSupportedEncodersForHdrEditing(
|
||||
MIME_TYPE,
|
||||
new ColorInfo(
|
||||
C.COLOR_SPACE_BT2020,
|
||||
C.COLOR_RANGE_FULL,
|
||||
C.COLOR_TRANSFER_HLG,
|
||||
/* hdrStaticInfo= */ null)))
|
||||
new ColorInfo.Builder()
|
||||
.setColorSpace(C.COLOR_SPACE_BT2020)
|
||||
.setColorRange(C.COLOR_RANGE_FULL)
|
||||
.setColorTransfer(C.COLOR_TRANSFER_HLG)
|
||||
.build()))
|
||||
.isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue