Miscellaneous small fixes in Transformer
PiperOrigin-RevId: 412286692
This commit is contained in:
parent
a4c12ca97d
commit
a520e7f559
@ -21,9 +21,6 @@ import androidx.annotation.Nullable;
|
|||||||
/** A media transformation configuration. */
|
/** A media transformation configuration. */
|
||||||
/* package */ final class Transformation {
|
/* package */ final class Transformation {
|
||||||
|
|
||||||
/** A value for various fields to indicate that the field's value is unknown or not set. */
|
|
||||||
public static final int NO_VALUE = -1;
|
|
||||||
|
|
||||||
public final boolean removeAudio;
|
public final boolean removeAudio;
|
||||||
public final boolean removeVideo;
|
public final boolean removeVideo;
|
||||||
public final boolean flattenForSlowMotion;
|
public final boolean flattenForSlowMotion;
|
||||||
|
@ -35,6 +35,7 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
|
import androidx.media3.common.Format;
|
||||||
import androidx.media3.common.MediaItem;
|
import androidx.media3.common.MediaItem;
|
||||||
import androidx.media3.common.MediaLibraryInfo;
|
import androidx.media3.common.MediaLibraryInfo;
|
||||||
import androidx.media3.common.MimeTypes;
|
import androidx.media3.common.MimeTypes;
|
||||||
@ -109,15 +110,11 @@ public final class Transformer {
|
|||||||
private Looper looper;
|
private Looper looper;
|
||||||
private Clock clock;
|
private Clock clock;
|
||||||
|
|
||||||
/**
|
/** @deprecated Use {@link #Builder(Context)} instead. */
|
||||||
* Creates a builder with default values.
|
|
||||||
*
|
|
||||||
* @deprecated Use {@link #Builder(Context)} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Builder() {
|
public Builder() {
|
||||||
muxerFactory = new FrameworkMuxer.Factory();
|
muxerFactory = new FrameworkMuxer.Factory();
|
||||||
outputHeight = Transformation.NO_VALUE;
|
outputHeight = Format.NO_VALUE;
|
||||||
containerMimeType = MimeTypes.VIDEO_MP4;
|
containerMimeType = MimeTypes.VIDEO_MP4;
|
||||||
listener = new Listener() {};
|
listener = new Listener() {};
|
||||||
looper = Util.getCurrentOrMainLooper();
|
looper = Util.getCurrentOrMainLooper();
|
||||||
@ -128,12 +125,11 @@ public final class Transformer {
|
|||||||
* Creates a builder with default values.
|
* Creates a builder with default values.
|
||||||
*
|
*
|
||||||
* @param context The {@link Context}.
|
* @param context The {@link Context}.
|
||||||
* @throws NullPointerException If the {@link Context} has not been provided.
|
|
||||||
*/
|
*/
|
||||||
public Builder(Context context) {
|
public Builder(Context context) {
|
||||||
this.context = context.getApplicationContext();
|
this.context = context.getApplicationContext();
|
||||||
muxerFactory = new FrameworkMuxer.Factory();
|
muxerFactory = new FrameworkMuxer.Factory();
|
||||||
outputHeight = Transformation.NO_VALUE;
|
outputHeight = Format.NO_VALUE;
|
||||||
containerMimeType = MimeTypes.VIDEO_MP4;
|
containerMimeType = MimeTypes.VIDEO_MP4;
|
||||||
listener = new Listener() {};
|
listener = new Listener() {};
|
||||||
looper = Util.getCurrentOrMainLooper();
|
looper = Util.getCurrentOrMainLooper();
|
||||||
@ -157,15 +153,7 @@ public final class Transformer {
|
|||||||
this.clock = transformer.clock;
|
this.clock = transformer.clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @deprecated Use {@link #Builder(Context)} instead. */
|
||||||
* Sets the {@link Context}.
|
|
||||||
*
|
|
||||||
* <p>This parameter is mandatory.
|
|
||||||
*
|
|
||||||
* @param context The {@link Context}.
|
|
||||||
* @return This builder.
|
|
||||||
* @deprecated Use {@link #Builder(Context)} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Builder setContext(Context context) {
|
public Builder setContext(Context context) {
|
||||||
this.context = context.getApplicationContext();
|
this.context = context.getApplicationContext();
|
||||||
@ -174,8 +162,8 @@ public final class Transformer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the {@link MediaSourceFactory} to be used to retrieve the inputs to transform. The
|
* Sets the {@link MediaSourceFactory} to be used to retrieve the inputs to transform. The
|
||||||
* default value is a {@link DefaultMediaSourceFactory} built with the context provided in the
|
* default value is a {@link DefaultMediaSourceFactory} built with the context provided in
|
||||||
* constructor.
|
* {@link #Builder(Context) the constructor}.
|
||||||
*
|
*
|
||||||
* @param mediaSourceFactory A {@link MediaSourceFactory}.
|
* @param mediaSourceFactory A {@link MediaSourceFactory}.
|
||||||
* @return This builder.
|
* @return This builder.
|
||||||
@ -244,9 +232,8 @@ public final class Transformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the output resolution using the output height. The default value is {@link
|
* Sets the output resolution using the output height. The default value is the same height as
|
||||||
* Transformation#NO_VALUE}, which will use the same height as the input. Output width will
|
* the input. Output width will scale to preserve the input video's aspect ratio.
|
||||||
* scale to preserve the input video's aspect ratio.
|
|
||||||
*
|
*
|
||||||
* <p>For now, only "popular" heights like 240, 360, 480, 720, 1080, 1440, or 2160 are
|
* <p>For now, only "popular" heights like 240, 360, 480, 720, 1080, 1440, or 2160 are
|
||||||
* supported, to ensure compatibility on different devices.
|
* supported, to ensure compatibility on different devices.
|
||||||
|
@ -46,7 +46,7 @@ import androidx.media3.exoplayer.source.SampleStream.ReadDataResult;
|
|||||||
return TAG;
|
return TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Attempts to read the input format and to initialize the sample or passthrough pipeline. */
|
/** Attempts to read the input format and to initialize the {@link SamplePipeline}. */
|
||||||
@Override
|
@Override
|
||||||
protected boolean ensureConfigured() throws ExoPlaybackException {
|
protected boolean ensureConfigured() throws ExoPlaybackException {
|
||||||
if (samplePipeline != null) {
|
if (samplePipeline != null) {
|
||||||
|
@ -80,13 +80,13 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean isReady() {
|
public final MediaClock getMediaClock() {
|
||||||
return isSourceReady();
|
return mediaClock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final MediaClock getMediaClock() {
|
public final boolean isReady() {
|
||||||
return mediaClock;
|
return isSourceReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -108,15 +108,6 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
this.streamOffsetUs = offsetUs;
|
this.streamOffsetUs = offsetUs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final void onReset() {
|
|
||||||
if (samplePipeline != null) {
|
|
||||||
samplePipeline.release();
|
|
||||||
}
|
|
||||||
muxerWrapperTrackAdded = false;
|
|
||||||
muxerWrapperTrackEnded = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final void onEnabled(boolean joining, boolean mayRenderStartOfStream) {
|
protected final void onEnabled(boolean joining, boolean mayRenderStartOfStream) {
|
||||||
muxerWrapper.registerTrack();
|
muxerWrapper.registerTrack();
|
||||||
@ -133,6 +124,15 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
isRendererStarted = false;
|
isRendererStarted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final void onReset() {
|
||||||
|
if (samplePipeline != null) {
|
||||||
|
samplePipeline.release();
|
||||||
|
}
|
||||||
|
muxerWrapperTrackAdded = false;
|
||||||
|
muxerWrapperTrackEnded = false;
|
||||||
|
}
|
||||||
|
|
||||||
@EnsuresNonNullIf(expression = "samplePipeline", result = true)
|
@EnsuresNonNullIf(expression = "samplePipeline", result = true)
|
||||||
protected abstract boolean ensureConfigured() throws ExoPlaybackException;
|
protected abstract boolean ensureConfigured() throws ExoPlaybackException;
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
return TAG;
|
return TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Attempts to read the input format and to initialize the sample or passthrough pipeline. */
|
/** Attempts to read the input format and to initialize the {@link SamplePipeline}. */
|
||||||
@Override
|
@Override
|
||||||
protected boolean ensureConfigured() throws ExoPlaybackException {
|
protected boolean ensureConfigured() throws ExoPlaybackException {
|
||||||
if (samplePipeline != null) {
|
if (samplePipeline != null) {
|
||||||
@ -72,7 +72,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
Format inputFormat = checkNotNull(formatHolder.format);
|
Format inputFormat = checkNotNull(formatHolder.format);
|
||||||
if ((transformation.videoMimeType != null
|
if ((transformation.videoMimeType != null
|
||||||
&& !transformation.videoMimeType.equals(inputFormat.sampleMimeType))
|
&& !transformation.videoMimeType.equals(inputFormat.sampleMimeType))
|
||||||
|| (transformation.outputHeight != Transformation.NO_VALUE
|
|| (transformation.outputHeight != Format.NO_VALUE
|
||||||
&& transformation.outputHeight != inputFormat.height)) {
|
&& transformation.outputHeight != inputFormat.height)) {
|
||||||
samplePipeline = new VideoSamplePipeline(context, inputFormat, transformation, getIndex());
|
samplePipeline = new VideoSamplePipeline(context, inputFormat, transformation, getIndex());
|
||||||
} else {
|
} else {
|
||||||
|
@ -58,7 +58,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
int outputWidth = inputFormat.width;
|
int outputWidth = inputFormat.width;
|
||||||
int outputHeight = inputFormat.height;
|
int outputHeight = inputFormat.height;
|
||||||
if (transformation.outputHeight != Transformation.NO_VALUE
|
if (transformation.outputHeight != Format.NO_VALUE
|
||||||
&& transformation.outputHeight != inputFormat.height) {
|
&& transformation.outputHeight != inputFormat.height) {
|
||||||
outputWidth = inputFormat.width * transformation.outputHeight / inputFormat.height;
|
outputWidth = inputFormat.width * transformation.outputHeight / inputFormat.height;
|
||||||
outputHeight = transformation.outputHeight;
|
outputHeight = transformation.outputHeight;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user