1616
1717package androidx .media3 .common ;
1818
19+ import android .content .Context ;
20+ import android .graphics .Bitmap ;
21+ import android .view .Surface ;
1922import androidx .annotation .IntRange ;
2023import androidx .annotation .Nullable ;
24+ import androidx .media3 .common .VideoFrameProcessor .InputType ;
25+ import androidx .media3 .common .util .TimestampIterator ;
2126import androidx .media3 .common .util .UnstableApi ;
27+ import java .util .List ;
28+ import java .util .concurrent .Executor ;
2229
2330/** Represents a graph for processing raw video frames. */
2431@ UnstableApi
2532public interface VideoGraph {
2633
34+ /** A factory for {@link VideoGraph} instances. */
35+ interface Factory {
36+ /**
37+ * Creates a new {@link VideoGraph} instance.
38+ *
39+ * @param context A {@link Context}.
40+ * @param outputColorInfo The {@link ColorInfo} for the output frames.
41+ * @param debugViewProvider A {@link DebugViewProvider}.
42+ * @param listener A {@link Listener}.
43+ * @param listenerExecutor The {@link Executor} on which the {@code listener} is invoked.
44+ * @param videoCompositorSettings The {@link VideoCompositorSettings} to apply to the
45+ * composition.
46+ * @param compositionEffects A list of {@linkplain Effect effects} to apply to the composition.
47+ * @param initialTimestampOffsetUs The timestamp offset for the first frame, in microseconds.
48+ * @param renderFramesAutomatically If {@code true}, the instance will render output frames to
49+ * the {@linkplain VideoGraph#setOutputSurfaceInfo(SurfaceInfo) output surface}
50+ * automatically as the instance is done processing them. If {@code false}, the instance
51+ * will block until {@code VideoGraph#renderOutputFrameWithMediaPresentationTime()} is
52+ * called, to render the frame.
53+ * @return A new instance.
54+ */
55+ VideoGraph create (
56+ Context context ,
57+ ColorInfo outputColorInfo ,
58+ DebugViewProvider debugViewProvider ,
59+ Listener listener ,
60+ Executor listenerExecutor ,
61+ VideoCompositorSettings videoCompositorSettings ,
62+ List <Effect > compositionEffects ,
63+ long initialTimestampOffsetUs ,
64+ boolean renderFramesAutomatically );
65+
66+ /**
67+ * Returns whether the {@linkplain #create created} {@link VideoGraph} supports multiple video
68+ * {@linkplain VideoGraph#registerInputStream inputs}.
69+ */
70+ boolean supportsMultipleInputs ();
71+ }
72+
2773 /** Listener for video frame processing events. */
28- @ UnstableApi
2974 interface Listener {
3075 /**
3176 * Called when the output size changes.
@@ -79,11 +124,8 @@ default void onError(VideoFrameProcessingException exception) {}
79124 /**
80125 * Registers a new input to the {@code VideoGraph}.
81126 *
82- * <p>A underlying processing {@link VideoFrameProcessor} is created every time this method is
83- * called.
84- *
85- * <p>All inputs must be registered before rendering frames to the underlying {@link
86- * #getProcessor(int) VideoFrameProcessor}.
127+ * <p>All inputs must be registered before rendering frames by calling {@link
128+ * #registerInputFrame}, {@link #queueInputBitmap} or {@link #queueInputTexture}.
87129 *
88130 * <p>If the method throws, the caller must call {@link #release}.
89131 *
@@ -92,13 +134,6 @@ default void onError(VideoFrameProcessingException exception) {}
92134 */
93135 void registerInput (@ IntRange (from = 0 ) int inputIndex ) throws VideoFrameProcessingException ;
94136
95- /**
96- * Returns the {@link VideoFrameProcessor} that handles the processing for an input registered via
97- * {@link #registerInput(int)}. If the {@code inputIndex} is not {@linkplain #registerInput(int)
98- * registered} before, this method will throw an {@link IllegalStateException}.
99- */
100- VideoFrameProcessor getProcessor (int inputIndex );
101-
102137 /**
103138 * Sets the output surface and supporting information.
104139 *
@@ -116,11 +151,111 @@ default void onError(VideoFrameProcessingException exception) {}
116151 */
117152 void setOutputSurfaceInfo (@ Nullable SurfaceInfo outputSurfaceInfo );
118153
154+ /**
155+ * Sets a listener that's called when the {@linkplain #getInputSurface input surface} is ready to
156+ * use at {@code inputIndex}.
157+ */
158+ void setOnInputSurfaceReadyListener (int inputIndex , Runnable listener );
159+
160+ /** Returns the input {@link Surface} at {@code inputIndex}. */
161+ Surface getInputSurface (int inputIndex );
162+
163+ /** Sets the {@link OnInputFrameProcessedListener} at {@code inputIndex}. */
164+ void setOnInputFrameProcessedListener (int inputIndex , OnInputFrameProcessedListener listener );
165+
166+ /**
167+ * Informs the graph that a new input stream will be queued to the graph input corresponding to
168+ * {@code inputIndex}.
169+ *
170+ * <p>After registering the first input stream, this method must only be called for the same index
171+ * after the last frame of the already-registered input stream has been {@linkplain
172+ * #registerInputFrame registered}, last bitmap {@linkplain #queueInputBitmap queued} or last
173+ * texture id {@linkplain #queueInputTexture queued}.
174+ *
175+ * <p>This method blocks the calling thread until the previous input stream corresponding to the
176+ * same {@code inputIndex} has been fully registered internally.
177+ *
178+ * @param inputIndex The index of the input for which a new input stream should be registered.
179+ * This index must start from 0.
180+ * @param inputType The {@link InputType} of the new input stream.
181+ * @param format The {@link Format} of the new input stream. The {@link Format#colorInfo}, the
182+ * {@link Format#width}, the {@link Format#height} and the {@link
183+ * Format#pixelWidthHeightRatio} must be set.
184+ * @param effects The list of {@link Effect effects} to apply to the new input stream.
185+ * @param offsetToAddUs The offset that must be added to the frame presentation timestamps, in
186+ * microseconds. This offset is not part of the input timestamps. It is added to the frame
187+ * timestamps before processing, and is retained in the output timestamps.
188+ */
189+ void registerInputStream (
190+ int inputIndex ,
191+ @ InputType int inputType ,
192+ Format format ,
193+ List <Effect > effects ,
194+ long offsetToAddUs );
195+
196+ /**
197+ * Returns the number of pending input frames at {@code inputIndex} that has not been processed
198+ * yet.
199+ */
200+ int getPendingInputFrameCount (int inputIndex );
201+
202+ /**
203+ * Registers a new input frame at {@code inputIndex}.
204+ *
205+ * @see VideoFrameProcessor#registerInputFrame()
206+ */
207+ boolean registerInputFrame (int inputIndex );
208+
209+ /**
210+ * Queues the input {@link Bitmap} at {@code inputIndex}.
211+ *
212+ * @see VideoFrameProcessor#queueInputBitmap(Bitmap, TimestampIterator)
213+ */
214+ boolean queueInputBitmap (int inputIndex , Bitmap inputBitmap , TimestampIterator timestampIterator );
215+
216+ /**
217+ * Queues the input texture at {@code inputIndex}.
218+ *
219+ * @see VideoFrameProcessor#queueInputTexture(int, long)
220+ */
221+ boolean queueInputTexture (int inputIndex , int textureId , long presentationTimeUs );
222+
223+ /**
224+ * Renders the output frame from the {@code VideoGraph}.
225+ *
226+ * <p>This method must be called only for frames that have become {@linkplain
227+ * Listener#onOutputFrameAvailableForRendering(long) available}, calling the method renders the
228+ * frame that becomes available the earliest but not yet rendered.
229+ *
230+ * @see VideoFrameProcessor#renderOutputFrame(long)
231+ */
232+ void renderOutputFrame (long renderTimeNs );
233+
234+ /**
235+ * Updates an {@linkplain Listener#onOutputFrameAvailableForRendering available frame} with the
236+ * modified effects.
237+ */
238+ void redraw ();
239+
119240 /**
120241 * Returns whether the {@code VideoGraph} has produced a frame with zero presentation timestamp.
121242 */
122243 boolean hasProducedFrameWithTimestampZero ();
123244
245+ /**
246+ * Flushes the {@linkplain #registerInput inputs} of the {@code VideoGraph}.
247+ *
248+ * @see VideoFrameProcessor#flush()
249+ */
250+ void flush ();
251+
252+ /**
253+ * Informs that no further inputs should be accepted at {@code inputIndex}.
254+ *
255+ * @see VideoFrameProcessor#signalEndOfInput()
256+ */
257+ void signalEndOfInput (int inputIndex );
258+
124259 /**
125260 * Releases the associated resources.
126261 *
0 commit comments