mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Separate ProcessedInput
's format
into audio and video
Before the change, `SequenceAssetLoader#onTrackAdded` was being called twice, for audio and video. `ExportResult.ProcessedInput` took one format, which was the latest to be written. The change leads to capturing both, the audio and video formats of the input, and prevents the issue of a format overwriting the other. PiperOrigin-RevId: 720487697
This commit is contained in:
parent
0b9ca1e70b
commit
80e6fa2aa7
@ -254,24 +254,28 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
MediaItemInfo.Builder mediaItemInfoBuilder = new MediaItemInfo.Builder();
|
MediaItemInfo.Builder mediaItemInfoBuilder = new MediaItemInfo.Builder();
|
||||||
long durationMs = usToMs(processedInput.durationUs);
|
long durationMs = usToMs(processedInput.durationUs);
|
||||||
mediaItemInfoBuilder.setClipDurationMillis(durationMs);
|
mediaItemInfoBuilder.setClipDurationMillis(durationMs);
|
||||||
Format format = processedInput.format;
|
@Nullable Format videoFormat = processedInput.videoFormat;
|
||||||
if (format != null) {
|
if (videoFormat != null) {
|
||||||
if (format.containerMimeType != null) {
|
if (videoFormat.containerMimeType != null) {
|
||||||
mediaItemInfoBuilder.setContainerMimeType(format.containerMimeType);
|
mediaItemInfoBuilder.setContainerMimeType(videoFormat.containerMimeType);
|
||||||
}
|
}
|
||||||
if (format.sampleMimeType != null) {
|
if (videoFormat.sampleMimeType != null) {
|
||||||
mediaItemInfoBuilder.addSampleMimeType(format.sampleMimeType);
|
mediaItemInfoBuilder.addSampleMimeType(videoFormat.sampleMimeType);
|
||||||
}
|
}
|
||||||
if (format.frameRate != Format.NO_VALUE) {
|
if (videoFormat.frameRate != Format.NO_VALUE) {
|
||||||
mediaItemInfoBuilder.setVideoFrameRate(format.frameRate);
|
mediaItemInfoBuilder.setVideoFrameRate(videoFormat.frameRate);
|
||||||
}
|
}
|
||||||
Size videoSize =
|
Size videoSize =
|
||||||
new Size(
|
new Size(
|
||||||
format.width != Format.NO_VALUE ? format.width : MediaItemInfo.VALUE_UNSPECIFIED,
|
videoFormat.width != Format.NO_VALUE
|
||||||
format.height != Format.NO_VALUE ? format.height : MediaItemInfo.VALUE_UNSPECIFIED);
|
? videoFormat.width
|
||||||
|
: MediaItemInfo.VALUE_UNSPECIFIED,
|
||||||
|
videoFormat.height != Format.NO_VALUE
|
||||||
|
? videoFormat.height
|
||||||
|
: MediaItemInfo.VALUE_UNSPECIFIED);
|
||||||
mediaItemInfoBuilder.setVideoSize(videoSize);
|
mediaItemInfoBuilder.setVideoSize(videoSize);
|
||||||
if (format.colorInfo != null) {
|
if (videoFormat.colorInfo != null) {
|
||||||
ColorInfo colorInfo = format.colorInfo;
|
ColorInfo colorInfo = videoFormat.colorInfo;
|
||||||
int colorStandard =
|
int colorStandard =
|
||||||
DATA_SPACE_STANDARD_CONVERSION_MAP.get(
|
DATA_SPACE_STANDARD_CONVERSION_MAP.get(
|
||||||
colorInfo.colorSpace, DataSpace.STANDARD_UNSPECIFIED);
|
colorInfo.colorSpace, DataSpace.STANDARD_UNSPECIFIED);
|
||||||
|
@ -285,11 +285,14 @@ public final class ExportResult {
|
|||||||
/** The processed {@link MediaItem}. */
|
/** The processed {@link MediaItem}. */
|
||||||
public final MediaItem mediaItem;
|
public final MediaItem mediaItem;
|
||||||
|
|
||||||
/** The duration of the media item, in microseconds. */
|
/** The duration of the {@link MediaItem}, in microseconds. */
|
||||||
public final long durationUs;
|
public final long durationUs;
|
||||||
|
|
||||||
/** The {@link Format} of the media item. */
|
/** The audio {@link Format} of the {@link MediaItem}. */
|
||||||
@Nullable public final Format format;
|
@Nullable public final Format audioFormat;
|
||||||
|
|
||||||
|
/** The video {@link Format} of the {@link MediaItem}. */
|
||||||
|
@Nullable public final Format videoFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the audio decoder used to process {@code mediaItem}. This field is {@code null}
|
* The name of the audio decoder used to process {@code mediaItem}. This field is {@code null}
|
||||||
@ -307,12 +310,14 @@ public final class ExportResult {
|
|||||||
public ProcessedInput(
|
public ProcessedInput(
|
||||||
MediaItem mediaItem,
|
MediaItem mediaItem,
|
||||||
long durationUs,
|
long durationUs,
|
||||||
@Nullable Format format,
|
@Nullable Format audioFormat,
|
||||||
|
@Nullable Format videoFormat,
|
||||||
@Nullable String audioDecoderName,
|
@Nullable String audioDecoderName,
|
||||||
@Nullable String videoDecoderName) {
|
@Nullable String videoDecoderName) {
|
||||||
this.mediaItem = mediaItem;
|
this.mediaItem = mediaItem;
|
||||||
this.durationUs = durationUs;
|
this.durationUs = durationUs;
|
||||||
this.format = format;
|
this.audioFormat = audioFormat;
|
||||||
|
this.videoFormat = videoFormat;
|
||||||
this.audioDecoderName = audioDecoderName;
|
this.audioDecoderName = audioDecoderName;
|
||||||
this.videoDecoderName = videoDecoderName;
|
this.videoDecoderName = videoDecoderName;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
private boolean decodeVideo;
|
private boolean decodeVideo;
|
||||||
private int sequenceLoopCount;
|
private int sequenceLoopCount;
|
||||||
private int processedInputsSize;
|
private int processedInputsSize;
|
||||||
private @MonotonicNonNull Format currentInputFormat;
|
private @MonotonicNonNull Format currentAudioInputFormat;
|
||||||
|
private @MonotonicNonNull Format currentVideoInputFormat;
|
||||||
|
|
||||||
// Accessed when switching asset loader.
|
// Accessed when switching asset loader.
|
||||||
private volatile boolean released;
|
private volatile boolean released;
|
||||||
@ -195,7 +196,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
new ExportResult.ProcessedInput(
|
new ExportResult.ProcessedInput(
|
||||||
mediaItem,
|
mediaItem,
|
||||||
currentAssetDurationUs,
|
currentAssetDurationUs,
|
||||||
currentInputFormat,
|
currentAudioInputFormat,
|
||||||
|
currentVideoInputFormat,
|
||||||
decoders.get(C.TRACK_TYPE_AUDIO),
|
decoders.get(C.TRACK_TYPE_AUDIO),
|
||||||
decoders.get(C.TRACK_TYPE_VIDEO)));
|
decoders.get(C.TRACK_TYPE_VIDEO)));
|
||||||
processedInputsSize++;
|
processedInputsSize++;
|
||||||
@ -234,7 +236,12 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
isAudio ? "audio" : "video",
|
isAudio ? "audio" : "video",
|
||||||
inputFormat);
|
inputFormat);
|
||||||
|
|
||||||
currentInputFormat = inputFormat;
|
if (isAudio) {
|
||||||
|
currentAudioInputFormat = inputFormat;
|
||||||
|
} else {
|
||||||
|
currentVideoInputFormat = inputFormat;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isCurrentAssetFirstAsset) {
|
if (!isCurrentAssetFirstAsset) {
|
||||||
boolean decode = isAudio ? decodeAudio : decodeVideo;
|
boolean decode = isAudio ? decodeAudio : decodeVideo;
|
||||||
if (decode) {
|
if (decode) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user