Skip to content

Commit

Permalink
android: only change capture format for screen if dimen actually chan…
Browse files Browse the repository at this point in the history
…ged (#8)
  • Loading branch information
davidliu authored May 25, 2024
1 parent 03ab65b commit 651373e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import org.webrtc.VideoCapturer;

public abstract class AbstractVideoCaptureController {
private final int width;
private final int height;
protected int width;
protected int height;
private final int fps;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,21 @@ public void onOrientationChanged(int orientation) {
DisplayMetrics displayMetrics = DisplayUtils.getDisplayMetrics((Activity) context);
final int width = displayMetrics.widthPixels;
final int height = displayMetrics.heightPixels;

// Pivot to the executor thread because videoCapturer.changeCaptureFormat runs in the main
// thread and may deadlock.
ThreadUtils.runOnExecutor(() -> {
try {
videoCapturer.changeCaptureFormat(width, height, DEFAULT_FPS);
} catch (Exception ex) {
// We ignore exceptions here. The video capturer runs on its own
// thread and we cannot synchronize with it.
}
});
if (width != ScreenCaptureController.this.width || height != ScreenCaptureController.this.height) {
ScreenCaptureController.this.width = width;
ScreenCaptureController.this.height = height;

// Pivot to the executor thread because videoCapturer.changeCaptureFormat runs in the main
// thread and may deadlock.
ThreadUtils.runOnExecutor(() -> {
try {
videoCapturer.changeCaptureFormat(width, height, DEFAULT_FPS);
} catch (Exception ex) {
// We ignore exceptions here. The video capturer runs on its own
// thread and we cannot synchronize with it.
}
});
}
}
};

Expand Down

0 comments on commit 651373e

Please sign in to comment.