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();
|
||||
long durationMs = usToMs(processedInput.durationUs);
|
||||
mediaItemInfoBuilder.setClipDurationMillis(durationMs);
|
||||
Format format = processedInput.format;
|
||||
if (format != null) {
|
||||
if (format.containerMimeType != null) {
|
||||
mediaItemInfoBuilder.setContainerMimeType(format.containerMimeType);
|
||||
@Nullable Format videoFormat = processedInput.videoFormat;
|
||||
if (videoFormat != null) {
|
||||
if (videoFormat.containerMimeType != null) {
|
||||
mediaItemInfoBuilder.setContainerMimeType(videoFormat.containerMimeType);
|
||||
}
|
||||
if (format.sampleMimeType != null) {
|
||||
mediaItemInfoBuilder.addSampleMimeType(format.sampleMimeType);
|
||||
if (videoFormat.sampleMimeType != null) {
|
||||
mediaItemInfoBuilder.addSampleMimeType(videoFormat.sampleMimeType);
|
||||
}
|
||||
if (format.frameRate != Format.NO_VALUE) {
|
||||
mediaItemInfoBuilder.setVideoFrameRate(format.frameRate);
|
||||
if (videoFormat.frameRate != Format.NO_VALUE) {
|
||||
mediaItemInfoBuilder.setVideoFrameRate(videoFormat.frameRate);
|
||||
}
|
||||
Size videoSize =
|
||||
new Size(
|
||||
format.width != Format.NO_VALUE ? format.width : MediaItemInfo.VALUE_UNSPECIFIED,
|
||||
format.height != Format.NO_VALUE ? format.height : MediaItemInfo.VALUE_UNSPECIFIED);
|
||||
videoFormat.width != Format.NO_VALUE
|
||||
? videoFormat.width
|
||||
: MediaItemInfo.VALUE_UNSPECIFIED,
|
||||
videoFormat.height != Format.NO_VALUE
|
||||
? videoFormat.height
|
||||
: MediaItemInfo.VALUE_UNSPECIFIED);
|
||||
mediaItemInfoBuilder.setVideoSize(videoSize);
|
||||
if (format.colorInfo != null) {
|
||||
ColorInfo colorInfo = format.colorInfo;
|
||||
if (videoFormat.colorInfo != null) {
|
||||
ColorInfo colorInfo = videoFormat.colorInfo;
|
||||
int colorStandard =
|
||||
DATA_SPACE_STANDARD_CONVERSION_MAP.get(
|
||||
colorInfo.colorSpace, DataSpace.STANDARD_UNSPECIFIED);
|
||||
|
@ -285,11 +285,14 @@ public final class ExportResult {
|
||||
/** The processed {@link 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;
|
||||
|
||||
/** The {@link Format} of the media item. */
|
||||
@Nullable public final Format format;
|
||||
/** The audio {@link Format} of the {@link MediaItem}. */
|
||||
@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}
|
||||
@ -307,12 +310,14 @@ public final class ExportResult {
|
||||
public ProcessedInput(
|
||||
MediaItem mediaItem,
|
||||
long durationUs,
|
||||
@Nullable Format format,
|
||||
@Nullable Format audioFormat,
|
||||
@Nullable Format videoFormat,
|
||||
@Nullable String audioDecoderName,
|
||||
@Nullable String videoDecoderName) {
|
||||
this.mediaItem = mediaItem;
|
||||
this.durationUs = durationUs;
|
||||
this.format = format;
|
||||
this.audioFormat = audioFormat;
|
||||
this.videoFormat = videoFormat;
|
||||
this.audioDecoderName = audioDecoderName;
|
||||
this.videoDecoderName = videoDecoderName;
|
||||
}
|
||||
|
@ -98,7 +98,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
private boolean decodeVideo;
|
||||
private int sequenceLoopCount;
|
||||
private int processedInputsSize;
|
||||
private @MonotonicNonNull Format currentInputFormat;
|
||||
private @MonotonicNonNull Format currentAudioInputFormat;
|
||||
private @MonotonicNonNull Format currentVideoInputFormat;
|
||||
|
||||
// Accessed when switching asset loader.
|
||||
private volatile boolean released;
|
||||
@ -195,7 +196,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
new ExportResult.ProcessedInput(
|
||||
mediaItem,
|
||||
currentAssetDurationUs,
|
||||
currentInputFormat,
|
||||
currentAudioInputFormat,
|
||||
currentVideoInputFormat,
|
||||
decoders.get(C.TRACK_TYPE_AUDIO),
|
||||
decoders.get(C.TRACK_TYPE_VIDEO)));
|
||||
processedInputsSize++;
|
||||
@ -234,7 +236,12 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
isAudio ? "audio" : "video",
|
||||
inputFormat);
|
||||
|
||||
currentInputFormat = inputFormat;
|
||||
if (isAudio) {
|
||||
currentAudioInputFormat = inputFormat;
|
||||
} else {
|
||||
currentVideoInputFormat = inputFormat;
|
||||
}
|
||||
|
||||
if (!isCurrentAssetFirstAsset) {
|
||||
boolean decode = isAudio ? decodeAudio : decodeVideo;
|
||||
if (decode) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user