Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android: only change capture format for screen if dimen actually changed #8

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
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 @@ -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
Loading