mirror of
https://github.com/androidx/media.git
synced 2025-05-11 09:39:52 +08:00
TransformerInternal: pass outputformat to sampleExporter in image input
Pass firstAssetLoaderOutputFormat to videoSampleExporter for non-video use cases, so that the downstream components like the videoFrameProcessor can be set up with the right output color. Surface creation is still in the VSP so can't do this for all use cases currently. also moves getDecoderOutputColor() to TransformerUtil, since it is used in multiple places and doesn't make sense for once to have reference to the other. PiperOrigin-RevId: 613113958
This commit is contained in:
parent
11b14d7594
commit
f8c407cfb6
@ -15,9 +15,9 @@
|
||||
*/
|
||||
package androidx.media3.transformer;
|
||||
|
||||
import static androidx.media3.common.ColorInfo.SDR_BT709_LIMITED;
|
||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import static androidx.media3.common.util.Assertions.checkStateNotNull;
|
||||
import static androidx.media3.transformer.TransformerUtil.getDecoderOutputColor;
|
||||
|
||||
import android.media.MediaCodec;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -57,14 +57,6 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
decodeOnlyPresentationTimestamps = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static ColorInfo getDecoderOutputColor(
|
||||
ColorInfo decoderInputColor, boolean isMediaCodecToneMappingRequested) {
|
||||
if (isMediaCodecToneMappingRequested && ColorInfo.isTransferHdr(decoderInputColor)) {
|
||||
return SDR_BT709_LIMITED;
|
||||
}
|
||||
return decoderInputColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return TAG;
|
||||
|
@ -24,7 +24,6 @@ import static androidx.media3.common.util.Util.contains;
|
||||
import static androidx.media3.transformer.AssetLoader.SUPPORTED_OUTPUT_TYPE_DECODED;
|
||||
import static androidx.media3.transformer.AssetLoader.SUPPORTED_OUTPUT_TYPE_ENCODED;
|
||||
import static androidx.media3.transformer.Composition.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC;
|
||||
import static androidx.media3.transformer.ExoAssetLoaderVideoRenderer.getDecoderOutputColor;
|
||||
import static androidx.media3.transformer.ExportException.ERROR_CODE_FAILED_RUNTIME_CHECK;
|
||||
import static androidx.media3.transformer.ExportException.ERROR_CODE_MUXING_FAILED;
|
||||
import static androidx.media3.transformer.MuxerWrapper.MUXER_RELEASE_REASON_CANCELLED;
|
||||
@ -32,6 +31,7 @@ import static androidx.media3.transformer.MuxerWrapper.MUXER_RELEASE_REASON_COMP
|
||||
import static androidx.media3.transformer.MuxerWrapper.MUXER_RELEASE_REASON_ERROR;
|
||||
import static androidx.media3.transformer.Transformer.PROGRESS_STATE_AVAILABLE;
|
||||
import static androidx.media3.transformer.Transformer.PROGRESS_STATE_NOT_STARTED;
|
||||
import static androidx.media3.transformer.TransformerUtil.getDecoderOutputColor;
|
||||
import static androidx.media3.transformer.TransformerUtil.getProcessedTrackType;
|
||||
import static androidx.media3.transformer.TransformerUtil.getValidColor;
|
||||
import static androidx.media3.transformer.TransformerUtil.maybeSetMuxerWrapperAdditionalRotationDegrees;
|
||||
@ -663,13 +663,22 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
muxerWrapper,
|
||||
fallbackListener));
|
||||
} else {
|
||||
// TODO(b/267301878): Pass firstAssetLoaderOutputFormat once surface creation not in VSP.
|
||||
boolean isMediaCodecToneMappingRequested =
|
||||
transformationRequest.hdrMode == HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC;
|
||||
ColorInfo decoderOutputColor =
|
||||
getDecoderOutputColor(
|
||||
getValidColor(firstAssetLoaderInputFormat.colorInfo),
|
||||
isMediaCodecToneMappingRequested);
|
||||
ColorInfo decoderOutputColor;
|
||||
if (MimeTypes.isVideo(assetLoaderOutputFormat.sampleMimeType)) {
|
||||
// TODO(b/267301878): Pass firstAssetLoaderOutputFormat once surface creation not in VSP.
|
||||
boolean isMediaCodecToneMappingRequested =
|
||||
transformationRequest.hdrMode == HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_MEDIACODEC;
|
||||
decoderOutputColor =
|
||||
getDecoderOutputColor(
|
||||
getValidColor(firstAssetLoaderInputFormat.colorInfo),
|
||||
isMediaCodecToneMappingRequested);
|
||||
} else if (MimeTypes.isImage(assetLoaderOutputFormat.sampleMimeType)) {
|
||||
decoderOutputColor = getValidColor(assetLoaderOutputFormat.colorInfo);
|
||||
} else {
|
||||
throw ExportException.createForUnexpected(
|
||||
new IllegalArgumentException(
|
||||
"assetLoaderOutputFormat has to have a audio, video or image mimetype."));
|
||||
}
|
||||
|
||||
assetLoaderInputTracker.registerSampleExporter(
|
||||
C.TRACK_TYPE_VIDEO,
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package androidx.media3.transformer;
|
||||
|
||||
import static androidx.media3.common.ColorInfo.SDR_BT709_LIMITED;
|
||||
import static androidx.media3.transformer.Composition.HDR_MODE_KEEP_HDR;
|
||||
import static java.lang.Math.round;
|
||||
|
||||
@ -223,4 +224,13 @@ import com.google.common.collect.ImmutableList;
|
||||
}
|
||||
return colorInfo;
|
||||
}
|
||||
|
||||
/** Returns the decoder output color taking tone mapping into account. */
|
||||
public static ColorInfo getDecoderOutputColor(
|
||||
ColorInfo decoderInputColor, boolean isMediaCodecToneMappingRequested) {
|
||||
if (isMediaCodecToneMappingRequested && ColorInfo.isTransferHdr(decoderInputColor)) {
|
||||
return SDR_BT709_LIMITED;
|
||||
}
|
||||
return decoderInputColor;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user