Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bc9e34f

Browse files
committed
Update goldens and add comments
1 parent 61d4b7d commit bc9e34f

13 files changed

+19
-0
lines changed

testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/ExternalTextureFlutterActivity.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public class ExternalTextureFlutterActivity extends TestActivity {
4646
private static final int SURFACE_HEIGHT = 256;
4747

4848
private SurfaceRenderer surfaceViewRenderer, flutterRenderer;
49+
50+
// Latch used to ensure both SurfaceRenderers produce a frame before taking a screenshot.
4951
private final CountDownLatch firstFrameLatch = new CountDownLatch(2);
5052

5153
private long textureId = 0;
@@ -172,6 +174,9 @@ default boolean canProduceFrames() {
172174
void destroy();
173175
}
174176

177+
/**
178+
* Paints a simple gradient onto the attached Surface.
179+
*/
175180
private static class CanvasSurfaceRenderer implements SurfaceRenderer {
176181
private Surface surface;
177182
private CountDownLatch onFirstFrame;
@@ -218,6 +223,9 @@ public void repaint() {
218223
public void destroy() {}
219224
}
220225

226+
/**
227+
* Decodes a sample video into the attached Surface.
228+
*/
221229
@RequiresApi(VERSION_CODES.LOLLIPOP)
222230
private static class MediaSurfaceRenderer implements SurfaceRenderer {
223231
private final Supplier<MediaExtractor> extractorSupplier;
@@ -262,13 +270,16 @@ private void decodeThreadMain() {
262270
codec.configure(format, surface, null, 0);
263271
codec.start();
264272

273+
// Track 0 is always the video track, since the sample video doesn't contain audio.
265274
extractor.selectTrack(0);
266275

267276
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
268277
boolean seenEOS = false;
269278
long startTimeNs = System.nanoTime();
270279

271280
while (true) {
281+
// Move samples (video frames) from the extractor into the decoder, as long as we haven't
282+
// consumed all samples.
272283
if (!seenEOS) {
273284
int inputBufferIndex = codec.dequeueInputBuffer(-1);
274285
ByteBuffer inputBuffer = codec.getInputBuffer(inputBufferIndex);
@@ -284,6 +295,8 @@ private void decodeThreadMain() {
284295
}
285296
}
286297

298+
// Then consume decoded video frames from the decoder. These frames are automatically
299+
// pushed to the attached Surface, so this schedules them for present.
287300
int outputBufferIndex = codec.dequeueOutputBuffer(bufferInfo, 10000);
288301
boolean lastBuffer = (bufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0;
289302
if (outputBufferIndex >= 0) {
@@ -298,6 +311,8 @@ private void decodeThreadMain() {
298311
}
299312
}
300313

314+
// Once we present the last frame, mark this renderer as no longer producing frames and
315+
// exit the loop.
301316
if (lastBuffer) {
302317
atomicCanProduceFrames.set(false);
303318
break;
@@ -327,6 +342,10 @@ public void destroy() {
327342
}
328343
}
329344

345+
/**
346+
* Takes frames from the inner SurfaceRenderer and feeds it through an ImageReader and
347+
* ImageWriter pair.
348+
*/
330349
@RequiresApi(VERSION_CODES.M)
331350
private static class ImageSurfaceRenderer implements SurfaceRenderer {
332351
private final SurfaceRenderer inner;

0 commit comments

Comments
 (0)