Miscellaneous small fixes in Transformer

PiperOrigin-RevId: 412286692
This commit is contained in:
kimvde 2021-11-25 16:11:58 +00:00 committed by kim-vde
parent 276f103c89
commit e846e9f06c
6 changed files with 26 additions and 42 deletions

View File

@ -21,9 +21,6 @@ import androidx.annotation.Nullable;
/** A media transformation configuration. */
/* 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 removeVideo;
public final boolean flattenForSlowMotion;

View File

@ -38,6 +38,7 @@ import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.Player;
@ -107,15 +108,11 @@ public final class Transformer {
private Looper looper;
private Clock clock;
/**
* Creates a builder with default values.
*
* @deprecated Use {@link #Builder(Context)} instead.
*/
/** @deprecated Use {@link #Builder(Context)} instead. */
@Deprecated
public Builder() {
muxerFactory = new FrameworkMuxer.Factory();
outputHeight = Transformation.NO_VALUE;
outputHeight = Format.NO_VALUE;
containerMimeType = MimeTypes.VIDEO_MP4;
listener = new Listener() {};
looper = Util.getCurrentOrMainLooper();
@ -126,12 +123,11 @@ public final class Transformer {
* Creates a builder with default values.
*
* @param context The {@link Context}.
* @throws NullPointerException If the {@link Context} has not been provided.
*/
public Builder(Context context) {
this.context = context.getApplicationContext();
muxerFactory = new FrameworkMuxer.Factory();
outputHeight = Transformation.NO_VALUE;
outputHeight = Format.NO_VALUE;
containerMimeType = MimeTypes.VIDEO_MP4;
listener = new Listener() {};
looper = Util.getCurrentOrMainLooper();
@ -155,15 +151,7 @@ public final class Transformer {
this.clock = transformer.clock;
}
/**
* Sets the {@link Context}.
*
* <p>This parameter is mandatory.
*
* @param context The {@link Context}.
* @return This builder.
* @deprecated Use {@link #Builder(Context)} instead.
*/
/** @deprecated Use {@link #Builder(Context)} instead. */
@Deprecated
public Builder setContext(Context context) {
this.context = context.getApplicationContext();
@ -172,8 +160,8 @@ public final class Transformer {
/**
* 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
* constructor.
* default value is a {@link DefaultMediaSourceFactory} built with the context provided in
* {@link #Builder(Context) the constructor}.
*
* @param mediaSourceFactory A {@link MediaSourceFactory}.
* @return This builder.
@ -242,9 +230,8 @@ public final class Transformer {
}
/**
* Sets the output resolution using the output height. The default value is {@link
* Transformation#NO_VALUE}, which will use the same height as the input. Output width will
* scale to preserve the input video's aspect ratio.
* Sets the output resolution using the output height. The default value is the same height as
* the input. Output width will 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
* supported, to ensure compatibility on different devices.

View File

@ -46,7 +46,7 @@ import com.google.android.exoplayer2.source.SampleStream.ReadDataResult;
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
protected boolean ensureConfigured() throws ExoPlaybackException {
if (samplePipeline != null) {

View File

@ -80,13 +80,13 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
}
@Override
public final boolean isReady() {
return isSourceReady();
public final MediaClock getMediaClock() {
return mediaClock;
}
@Override
public final MediaClock getMediaClock() {
return mediaClock;
public final boolean isReady() {
return isSourceReady();
}
@Override
@ -108,15 +108,6 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
this.streamOffsetUs = offsetUs;
}
@Override
protected final void onReset() {
if (samplePipeline != null) {
samplePipeline.release();
}
muxerWrapperTrackAdded = false;
muxerWrapperTrackEnded = false;
}
@Override
protected final void onEnabled(boolean joining, boolean mayRenderStartOfStream) {
muxerWrapper.registerTrack();
@ -133,6 +124,15 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
isRendererStarted = false;
}
@Override
protected final void onReset() {
if (samplePipeline != null) {
samplePipeline.release();
}
muxerWrapperTrackAdded = false;
muxerWrapperTrackEnded = false;
}
@EnsuresNonNullIf(expression = "samplePipeline", result = true)
protected abstract boolean ensureConfigured() throws ExoPlaybackException;

View File

@ -57,7 +57,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
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
protected boolean ensureConfigured() throws ExoPlaybackException {
if (samplePipeline != null) {
@ -72,7 +72,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
Format inputFormat = checkNotNull(formatHolder.format);
if ((transformation.videoMimeType != null
&& !transformation.videoMimeType.equals(inputFormat.sampleMimeType))
|| (transformation.outputHeight != Transformation.NO_VALUE
|| (transformation.outputHeight != Format.NO_VALUE
&& transformation.outputHeight != inputFormat.height)) {
samplePipeline = new VideoSamplePipeline(context, inputFormat, transformation, getIndex());
} else {

View File

@ -58,7 +58,7 @@ import java.io.IOException;
int outputWidth = inputFormat.width;
int outputHeight = inputFormat.height;
if (transformation.outputHeight != Transformation.NO_VALUE
if (transformation.outputHeight != Format.NO_VALUE
&& transformation.outputHeight != inputFormat.height) {
outputWidth = inputFormat.width * transformation.outputHeight / inputFormat.height;
outputHeight = transformation.outputHeight;