@UnstableApi
class TransformerUtil


Utility methods for Transformer.

Summary

Nested types

Utility for setting LogSessionId on MediaFormat (API 35+).

Public functions

java-static Boolean
containsSpeedChangingEffects(
    effects: Effects!,
    ignoreFirstEffect: Boolean
)

Returns whether Effects contains speed changing effects.

java-static ColorInfo!
getDecoderOutputColor(
    decoderInputColor: ColorInfo!,
    isMediaCodecToneMappingRequested: Boolean
)

Returns the decoder output color taking tone mapping into account.

java-static EditedMediaItem!
getEditedMediaItem(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!
)

Returns the EditedMediaItem corresponding to mediaPeriodId within timeline.

java-static EditedMediaItemSequence!
getEditedMediaItemSequence(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!
)

Returns the EditedMediaItemSequence corresponding to mediaPeriodId within timeline.

java-static String?
getImageMimeType(context: Context!, mediaItem: MediaItem!)

Returns the image MIME type corresponding to a MediaItem.

java-static Int

Returns MediaCodec flags corresponding to C.BufferFlags.

java-static Long
getOffsetToCompositionTimeUs(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    offsetUs: Long
)

Returns the offset between a renderer timestamp and the start of the Composition.

java-static Pair<String!, Int!>!
getOutputMimeTypeAndHdrModeAfterFallback(
    @Composition.HdrMode hdrMode: Int,
    requestedOutputMimeType: String!,
    colorInfo: ColorInfo?
)

Calculate what the MIME type and HdrMode to use, applying fallback measure if necessary.

java-static Int

Returns the track type constant corresponding to how a specified MIME type should be processed, which may be TRACK_TYPE_UNKNOWN if it could not be determined.

java-static ColorInfo!
getValidColor(colorInfo: ColorInfo?)

Adjust for invalid ColorInfo values, by defaulting to SDR_BT709_LIMITED.

java-static Boolean
isImage(context: Context!, mediaItem: MediaItem!)

Returns whether the provided MediaItem corresponds to an image.

java-static Boolean
validateSpeedChangingEffects(
    effects: Effects!,
    speedProvider: SpeedProvider!
)

Checks whether any speed changing effects at the first position of each pipeline match speedProvider.

Public functions

containsSpeedChangingEffects

java-static fun containsSpeedChangingEffects(
    effects: Effects!,
    ignoreFirstEffect: Boolean
): Boolean

Returns whether Effects contains speed changing effects.

ignoreFirstEffect controls whether TimestampAdjustment and SpeedChangingAudioProcessor are ignored as first elements of the video and audio pipelines, respectively.

getDecoderOutputColor

java-static fun getDecoderOutputColor(
    decoderInputColor: ColorInfo!,
    isMediaCodecToneMappingRequested: Boolean
): ColorInfo!

Returns the decoder output color taking tone mapping into account.

getEditedMediaItem

java-static fun getEditedMediaItem(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!
): EditedMediaItem!

Returns the EditedMediaItem corresponding to mediaPeriodId within timeline.

Parameters
timeline: Timeline!

The Timeline associated to the EditedMediaItem.

mediaPeriodId: MediaSource.MediaPeriodId!

The MediaPeriodId associated to the EditedMediaItem.

getEditedMediaItemSequence

java-static fun getEditedMediaItemSequence(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!
): EditedMediaItemSequence!

Returns the EditedMediaItemSequence corresponding to mediaPeriodId within timeline.

If mediaPeriodId does not map to a sequence this method will throw a IllegalStateException.

Parameters
timeline: Timeline!

The Timeline associated to the EditedMediaItemSequence.

mediaPeriodId: MediaSource.MediaPeriodId!

The MediaPeriodId associated to the EditedMediaItemSequence.

getImageMimeType

java-static fun getImageMimeType(context: Context!, mediaItem: MediaItem!): String?

Returns the image MIME type corresponding to a MediaItem.

This method only supports some common image MIME types.

Parameters
context: Context!

The Context.

mediaItem: MediaItem!

The MediaItem to inspect.

Returns
String?

The MIME type.

getMediaCodecFlags

java-static fun getMediaCodecFlags(@C.BufferFlags flags: Int): Int

Returns MediaCodec flags corresponding to C.BufferFlags.

getOffsetToCompositionTimeUs

java-static fun getOffsetToCompositionTimeUs(
    timeline: Timeline!,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    offsetUs: Long
): Long

Returns the offset between a renderer timestamp and the start of the Composition.

Parameters
timeline: Timeline!

The Timeline associated with this renderer.

mediaPeriodId: MediaSource.MediaPeriodId!

The MediaSource.MediaPeriodId.

offsetUs: Long

The offset added to timestamps of buffers to ensure monotonically increasing timestamps, in microseconds. This is the constant offset between the current MediaPeriod timestamps and the renderer timestamp.

See this corresponding topic on timestamps.

getOutputMimeTypeAndHdrModeAfterFallback

java-static fun getOutputMimeTypeAndHdrModeAfterFallback(
    @Composition.HdrMode hdrMode: Int,
    requestedOutputMimeType: String!,
    colorInfo: ColorInfo?
): Pair<String!, Int!>!

Calculate what the MIME type and HdrMode to use, applying fallback measure if necessary.

Parameters
@Composition.HdrMode hdrMode: Int

The HdrMode.

requestedOutputMimeType: String!

The desired output MIME type.

colorInfo: ColorInfo?

The ColorInfo.

Returns
Pair<String!, Int!>!

a Pair of the output MIME type and HdrMode.

getProcessedTrackType

@C.TrackType
java-static fun getProcessedTrackType(mimeType: String?): Int

Returns the track type constant corresponding to how a specified MIME type should be processed, which may be TRACK_TYPE_UNKNOWN if it could not be determined.

Image MIME types are processed as TRACK_TYPE_VIDEO.

See getTrackType for more details.

getValidColor

java-static fun getValidColor(colorInfo: ColorInfo?): ColorInfo!

Adjust for invalid ColorInfo values, by defaulting to SDR_BT709_LIMITED.

isImage

java-static fun isImage(context: Context!, mediaItem: MediaItem!): Boolean

Returns whether the provided MediaItem corresponds to an image.

validateSpeedChangingEffects

java-static fun validateSpeedChangingEffects(
    effects: Effects!,
    speedProvider: SpeedProvider!
): Boolean

Checks whether any speed changing effects at the first position of each pipeline match speedProvider.

The method verifies that any TimestampAdjustment or SpeedChangingAudioProcessor instance set as the first effect of its pipeline has a SpeedProvider equal to speedProvider.

If no speed changing effects are present, this method returns true.