Make setResolution package private

- Usages in 1P apps have been removed.
- setResolution should be removed when refactoring fallback.

PiperOrigin-RevId: 505043425
This commit is contained in:
kimvde 2023-01-27 08:14:08 +00:00 committed by christosts
parent 341f2d6b3a
commit 9759849001
4 changed files with 36 additions and 42 deletions

View file

@ -127,7 +127,7 @@ public final class Presentation implements MatrixTransformation {
* Creates a new {@link Presentation} instance.
*
* <p>The output frame will have the given height. Width will scale to preserve the input aspect
* ratio.
* ratio. For example, a 1920x1440 video can be scaled to 640x480 by passing a height of 480.
*
* @param height The height of the output frame, in pixels.
*/

View file

@ -23,6 +23,7 @@ import static java.lang.annotation.RetentionPolicy.SOURCE;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
@ -128,29 +129,6 @@ public final class TransformationRequest {
this.hdrMode = transformationRequest.hdrMode;
}
/**
* Sets the output resolution using the output height of the displayed video.
*
* <p>Output width of the displayed video will scale to preserve the video's aspect ratio after
* other transformations.
*
* <p>For example, a 1920x1440 video can be scaled to 640x480 by calling setResolution(480).
*
* <p>The default value, {@link C#LENGTH_UNSET}, leaves the width and height unchanged.
*
* <p>Note that the output encoded video's dimensions may be swapped from the displayed video's
* dimensions, if the displayed video's height > width. This is to improve compatibility among
* different device encoders.
*
* @param outputHeight The output height of the displayed video, in pixels.
* @return This builder.
*/
@CanIgnoreReturnValue
public Builder setResolution(int outputHeight) {
this.outputHeight = outputHeight;
return this;
}
/**
* Sets the video MIME type of the output.
*
@ -247,6 +225,13 @@ public final class TransformationRequest {
return this;
}
@CanIgnoreReturnValue
// TODO(b/255953153): remove this method once fallback has been refactored.
/* package */ Builder setResolution(int outputHeight) {
this.outputHeight = outputHeight;
return this;
}
/** Builds a {@link TransformationRequest} instance. */
public TransformationRequest build() {
return new TransformationRequest(outputHeight, audioMimeType, videoMimeType, hdrMode);
@ -254,9 +239,18 @@ public final class TransformationRequest {
}
/**
* The requested height of the output video, or {@link C#LENGTH_UNSET} if inferred from the input.
* The requested height of the output video.
*
* @see Builder#setResolution(int)
* <p>This field is
*
* <ul>
* <li>Always set to {@link C#LENGTH_UNSET} in the {@code originalTransformationRequest}
* parameter of {@link Transformer.Listener#onFallbackApplied(MediaItem,
* TransformationRequest, TransformationRequest)}.
* <li>Set to {@link C#LENGTH_UNSET} in the {@code fallbackTransformationRequest} parameter of
* {@link Transformer.Listener#onFallbackApplied(MediaItem, TransformationRequest,
* TransformationRequest)} to indicate that it is inferred from the input.
* </ul>
*/
public final int outputHeight;
/**

View file

@ -496,8 +496,8 @@ public final class Transformer {
}
/**
* Called when fallback to an alternative {@link TransformationRequest} is necessary to comply
* with muxer or device constraints.
* Called when falling back to an alternative {@link TransformationRequest} or changing the
* video frames' resolution is necessary to comply with muxer or device constraints.
*
* @param inputMediaItem The {@link MediaItem} for which the transformation is requested.
* @param originalTransformationRequest The unsupported {@link TransformationRequest} used when
@ -658,6 +658,10 @@ public final class Transformer {
* ignored. For adaptive bitrate, if no custom {@link AssetLoader.Factory} is specified, the
* highest bitrate video and audio streams are selected.
*
* <p>If encoding the output's video track is needed, the output frames' dimensions will be
* swapped if the height is larger than the width. This is to improve compatibility among
* different device encoders.
*
* @param editedMediaItem The {@link MediaItem} to transform, with the transformations to apply to
* it.
* @param path The path to the output file.
@ -684,6 +688,10 @@ public final class Transformer {
* ignored. For adaptive bitrate, if no custom {@link AssetLoader.Factory} is specified, the
* highest bitrate video and audio streams are selected.
*
* <p>If encoding the output's video track is needed, the output frames' dimensions will be
* swapped if the height is larger than the width. This is to improve compatibility among
* different device encoders.
*
* @param editedMediaItem The {@link MediaItem} to transform, with the transformations to apply to
* it.
* @param parcelFileDescriptor A readable and writable {@link ParcelFileDescriptor} of the output.

View file

@ -33,7 +33,6 @@ import androidx.annotation.VisibleForTesting;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.effect.Presentation;
import com.google.android.exoplayer2.util.Consumer;
import com.google.android.exoplayer2.util.DebugViewProvider;
import com.google.android.exoplayer2.util.Effect;
@ -125,18 +124,6 @@ import org.checkerframework.dataflow.qual.Pure;
encoderOutputBuffer =
new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED);
// The decoder rotates encoded frames for display by inputFormat.rotationDegrees.
int decodedWidth =
(inputFormat.rotationDegrees % 180 == 0) ? inputFormat.width : inputFormat.height;
int decodedHeight =
(inputFormat.rotationDegrees % 180 == 0) ? inputFormat.height : inputFormat.width;
ImmutableList.Builder<Effect> effectsListBuilder =
new ImmutableList.Builder<Effect>().addAll(effects);
if (transformationRequest.outputHeight != C.LENGTH_UNSET) {
effectsListBuilder.add(Presentation.createForHeight(transformationRequest.outputHeight));
}
encoderWrapper =
new EncoderWrapper(
encoderFactory,
@ -165,7 +152,7 @@ import org.checkerframework.dataflow.qual.Pure;
frameProcessor =
frameProcessorFactory.create(
context,
effectsListBuilder.build(),
effects,
debugViewProvider,
frameProcessorInputColor,
frameProcessorOutputColor,
@ -212,6 +199,11 @@ import org.checkerframework.dataflow.qual.Pure;
throw TransformationException.createForFrameProcessingException(
e, TransformationException.ERROR_CODE_FRAME_PROCESSING_FAILED);
}
// The decoder rotates encoded frames for display by inputFormat.rotationDegrees.
int decodedWidth =
(inputFormat.rotationDegrees % 180 == 0) ? inputFormat.width : inputFormat.height;
int decodedHeight =
(inputFormat.rotationDegrees % 180 == 0) ? inputFormat.height : inputFormat.width;
firstFrameInfo =
new FrameInfo.Builder(decodedWidth, decodedHeight)
.setPixelWidthHeightRatio(inputFormat.pixelWidthHeightRatio)