Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;

public class ExternalTextureFlutterActivity extends TestActivity {
Expand All @@ -60,6 +61,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

String surfaceRenderer = getIntent().getStringExtra("surface_renderer");
assert surfaceRenderer != null;
surfaceViewRenderer = selectSurfaceRenderer(surfaceRenderer, getIntent().getExtras());
flutterRenderer = selectSurfaceRenderer(surfaceRenderer, getIntent().getExtras());

Expand Down Expand Up @@ -92,7 +94,9 @@ public void waitUntilFlutterRendered() {
super.waitUntilFlutterRendered();

try {
firstFrameLatch.await(10, java.util.concurrent.TimeUnit.SECONDS);
if (!firstFrameLatch.await(10, java.util.concurrent.TimeUnit.SECONDS)) {
throw new RuntimeException("Timeout waiting for firstFrameLatch to signal");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a checked exception though, I don't think we actually want our callers to catch anything (it's not actionable).

}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -127,8 +131,9 @@ private MediaExtractor createMediaExtractor() {
// -profile:v main -level:v 5.2 -t 1 -r 1 -vf scale=192:256 -b:v 1M sample.mp4
try {
MediaExtractor extractor = new MediaExtractor();
AssetFileDescriptor afd = getAssets().openFd("sample.mp4");
extractor.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
try (AssetFileDescriptor afd = getAssets().openFd("sample.mp4")) {
extractor.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
}
return extractor;
} catch (IOException e) {
e.printStackTrace();
Expand All @@ -146,7 +151,8 @@ public void onPause() {

@Override
public void onFlutterUiDisplayed() {
surfaceTextureEntry = getFlutterEngine().getRenderer().createSurfaceTexture();
surfaceTextureEntry =
Objects.requireNonNull(getFlutterEngine()).getRenderer().createSurfaceTexture();
SurfaceTexture surfaceTexture = surfaceTextureEntry.surfaceTexture();
surfaceTexture.setDefaultBufferSize(SURFACE_WIDTH, SURFACE_HEIGHT);
flutterRenderer.attach(new Surface(surfaceTexture), firstFrameLatch);
Expand Down Expand Up @@ -256,7 +262,9 @@ public void attach(Surface surface, CountDownLatch onFirstFrame) {

private void decodeThreadMain() {
try {
MediaCodec codec = MediaCodec.createDecoderByType(format.getString(MediaFormat.KEY_MIME));
MediaCodec codec =
MediaCodec.createDecoderByType(
Objects.requireNonNull(format.getString(MediaFormat.KEY_MIME)));
codec.configure(format, surface, null, 0);
codec.start();

Expand All @@ -274,6 +282,7 @@ private void decodeThreadMain() {
if (!seenEOS) {
int inputBufferIndex = codec.dequeueInputBuffer(-1);
ByteBuffer inputBuffer = codec.getInputBuffer(inputBufferIndex);
assert inputBuffer != null;
int sampleSize = extractor.readSampleData(inputBuffer, 0);
if (sampleSize >= 0) {
long presentationTimeUs = extractor.getSampleTime();
Expand Down