@UnstableApi
public final class TransformerUtil


Utility methods for Transformer.

Summary

Nested types

@RequiresApi(value = 35)
public final class TransformerUtil.Api35

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

Public methods

static boolean
containsSpeedChangingEffects(
    Effects effects,
    boolean ignoreFirstEffect
)

Returns whether Effects contains speed changing effects.

static ColorInfo
getDecoderOutputColor(
    ColorInfo decoderInputColor,
    boolean isMediaCodecToneMappingRequested
)

Returns the decoder output color taking tone mapping into account.

static EditedMediaItem
getEditedMediaItem(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId
)

Returns the EditedMediaItem corresponding to mediaPeriodId within timeline.

static EditedMediaItemSequence
getEditedMediaItemSequence(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId
)

Returns the EditedMediaItemSequence corresponding to mediaPeriodId within timeline.

static @Nullable String
getImageMimeType(Context context, MediaItem mediaItem)

Returns the image MIME type corresponding to a MediaItem.

static int

Returns MediaCodec flags corresponding to C.BufferFlags.

static long
getOffsetToCompositionTimeUs(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId,
    long offsetUs
)

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

static Pair<StringInteger>
getOutputMimeTypeAndHdrModeAfterFallback(
    @Composition.HdrMode int hdrMode,
    String requestedOutputMimeType,
    @Nullable ColorInfo colorInfo
)

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

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.

static ColorInfo

Adjust for invalid ColorInfo values, by defaulting to SDR_BT709_LIMITED.

static boolean
isImage(Context context, MediaItem mediaItem)

Returns whether the provided MediaItem corresponds to an image.

static boolean
validateSpeedChangingEffects(
    Effects effects,
    SpeedProvider speedProvider
)

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

Public methods

containsSpeedChangingEffects

public static boolean containsSpeedChangingEffects(
    Effects effects,
    boolean ignoreFirstEffect
)

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

public static ColorInfo getDecoderOutputColor(
    ColorInfo decoderInputColor,
    boolean isMediaCodecToneMappingRequested
)

Returns the decoder output color taking tone mapping into account.

getEditedMediaItem

public static EditedMediaItem getEditedMediaItem(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId
)

Returns the EditedMediaItem corresponding to mediaPeriodId within timeline.

Parameters
Timeline timeline

The Timeline associated to the EditedMediaItem.

MediaSource.MediaPeriodId mediaPeriodId

The MediaPeriodId associated to the EditedMediaItem.

getEditedMediaItemSequence

public static EditedMediaItemSequence getEditedMediaItemSequence(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId
)

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.

MediaSource.MediaPeriodId mediaPeriodId

The MediaPeriodId associated to the EditedMediaItemSequence.

getImageMimeType

public static @Nullable String getImageMimeType(Context context, MediaItem mediaItem)

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
@Nullable String

The MIME type.

getMediaCodecFlags

public static int getMediaCodecFlags(@C.BufferFlags int flags)

Returns MediaCodec flags corresponding to C.BufferFlags.

getOffsetToCompositionTimeUs

public static long getOffsetToCompositionTimeUs(
    Timeline timeline,
    MediaSource.MediaPeriodId mediaPeriodId,
    long offsetUs
)

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

Parameters
Timeline timeline

The Timeline associated with this renderer.

MediaSource.MediaPeriodId mediaPeriodId

The MediaSource.MediaPeriodId.

long offsetUs

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

public static Pair<StringIntegergetOutputMimeTypeAndHdrModeAfterFallback(
    @Composition.HdrMode int hdrMode,
    String requestedOutputMimeType,
    @Nullable ColorInfo colorInfo
)

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

Parameters
@Composition.HdrMode int hdrMode

The HdrMode.

String requestedOutputMimeType

The desired output MIME type.

@Nullable ColorInfo colorInfo

The ColorInfo.

Returns
Pair<StringInteger>

a Pair of the output MIME type and HdrMode.

getProcessedTrackType

@C.TrackType
public static int getProcessedTrackType(@Nullable String mimeType)

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

public static ColorInfo getValidColor(@Nullable ColorInfo colorInfo)

Adjust for invalid ColorInfo values, by defaulting to SDR_BT709_LIMITED.

isImage

public static boolean isImage(Context context, MediaItem mediaItem)

Returns whether the provided MediaItem corresponds to an image.

validateSpeedChangingEffects

public static boolean validateSpeedChangingEffects(
    Effects effects,
    SpeedProvider speedProvider
)

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.