diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/GlEffectsFrameProcessorPixelTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/GlEffectsFrameProcessorPixelTest.java index e77ae2dfa2..910e724981 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/GlEffectsFrameProcessorPixelTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/GlEffectsFrameProcessorPixelTest.java @@ -367,8 +367,6 @@ public final class GlEffectsFrameProcessorPixelTest { } }, pixelWidthHeightRatio, - inputWidth, - inputHeight, /* streamOffsetUs= */ 0L, effects, /* outputSurfaceProvider= */ (requestedWidth, requestedHeight) -> { @@ -383,6 +381,7 @@ public final class GlEffectsFrameProcessorPixelTest { }, Transformer.DebugViewProvider.NONE, /* enableExperimentalHdrEditing= */ false)); + glEffectsFrameProcessor.setInputFrameInfo(new FrameInfo(inputWidth, inputHeight)); glEffectsFrameProcessor.registerInputFrame(); // Queue the first video frame from the extractor. diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameInfo.java b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameInfo.java new file mode 100644 index 0000000000..0b0af7821b --- /dev/null +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameInfo.java @@ -0,0 +1,37 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package androidx.media3.transformer; + +import static androidx.media3.common.util.Assertions.checkArgument; + +/** Value class specifying information about a decoded video frame. */ +/* package */ class FrameInfo { + /** The width of the frame, in pixels. */ + public final int width; + /** The height of the frame, in pixels. */ + public final int height; + + // TODO(b/227625423): Add pixelWidthHeightRatio. + // TODO(b/227624622): Add color space information for HDR. + + public FrameInfo(int width, int height) { + checkArgument(width > 0, "width must be positive, but is: " + width); + checkArgument(height > 0, "height must be positive, but is: " + height); + + this.width = width; + this.height = height; + } +} diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameProcessor.java b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameProcessor.java index a4338cd6a2..db0a3bec7b 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameProcessor.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameProcessor.java @@ -41,12 +41,21 @@ import android.view.Surface; /** Returns the input {@link Surface}. */ Surface getInputSurface(); + /** + * Sets information about the input frames. + * + *
The new input information is applied from the next frame {@linkplain #registerInputFrame() + * registered} onwards. + */ + void setInputFrameInfo(FrameInfo inputFrameInfo); + /** * Informs the {@code FrameProcessor} that a frame will be queued to its input surface. * *
Must be called before rendering a frame to the frame processor's input surface.
*
- * @throws IllegalStateException If called after {@link #signalEndOfInputStream()}.
+ * @throws IllegalStateException If called after {@link #signalEndOfInputStream()} or before
+ * {@link #setInputFrameInfo(FrameInfo)}.
*/
void registerInputFrame();
diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/GlEffectsFrameProcessor.java b/libraries/transformer/src/main/java/androidx/media3/transformer/GlEffectsFrameProcessor.java
index fc73daeb36..75b9b80d25 100644
--- a/libraries/transformer/src/main/java/androidx/media3/transformer/GlEffectsFrameProcessor.java
+++ b/libraries/transformer/src/main/java/androidx/media3/transformer/GlEffectsFrameProcessor.java
@@ -15,8 +15,8 @@
*/
package androidx.media3.transformer;
-import static androidx.media3.common.util.Assertions.checkArgument;
import static androidx.media3.common.util.Assertions.checkState;
+import static androidx.media3.common.util.Assertions.checkStateNotNull;
import android.content.Context;
import android.graphics.SurfaceTexture;
@@ -31,10 +31,11 @@ import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.Util;
import com.google.common.collect.ImmutableList;
import java.util.List;
+import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
-import java.util.concurrent.atomic.AtomicInteger;
+import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/**
* A {@link FrameProcessor} implementation that applies {@link GlEffect} instances using OpenGL on a
@@ -51,8 +52,6 @@ import java.util.concurrent.atomic.AtomicInteger;
* @param listener A {@link Listener}.
* @param pixelWidthHeightRatio The ratio of width over height for each pixel. Pixels are expanded
* by this ratio so that the output frame's pixels have a ratio of 1.
- * @param inputWidth The input frame width, in pixels.
- * @param inputHeight The input frame height, in pixels.
* @param effects The {@link GlEffect GlEffects} to apply to each frame.
* @param outputSurfaceProvider A {@link SurfaceInfo.Provider} managing the output {@link
* Surface}.
@@ -66,16 +65,12 @@ import java.util.concurrent.atomic.AtomicInteger;
Context context,
FrameProcessor.Listener listener,
float pixelWidthHeightRatio,
- int inputWidth,
- int inputHeight,
long streamOffsetUs,
List