Commit 43aace03 by kimvde Committed by christosts

Make setResolution package private

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

PiperOrigin-RevId: 505043425
parent c3934c53
......@@ -129,7 +129,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.
*/
......
......@@ -23,6 +23,7 @@ import static java.lang.annotation.RetentionPolicy.SOURCE;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.media3.common.C;
import androidx.media3.common.MediaItem;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.common.util.Util;
......@@ -131,29 +132,6 @@ public final class TransformationRequest {
}
/**
* 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.
*
* <p>The default value is {@code null} which corresponds to using the same MIME type as the
......@@ -249,6 +227,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);
......@@ -256,9 +241,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.
*
* <p>This field is
*
* @see Builder#setResolution(int)
* <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;
/**
......
......@@ -498,8 +498,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
......@@ -660,6 +660,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.
......@@ -686,6 +690,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.
......
......@@ -44,7 +44,6 @@ import androidx.media3.common.util.Consumer;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.Util;
import androidx.media3.decoder.DecoderInputBuffer;
import androidx.media3.effect.Presentation;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.MoreExecutors;
import java.nio.ByteBuffer;
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment