mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[fix] use original screen render resolution to capturing and fix cursor mapping error
This commit is contained in:
@@ -30,6 +30,10 @@
|
|||||||
<key>NSCameraUseContinuityCameraDeviceType</key>
|
<key>NSCameraUseContinuityCameraDeviceType</key>
|
||||||
<string>Your usage description here</string>
|
<string>Your usage description here</string>
|
||||||
|
|
||||||
|
<!-- High DPI -->>
|
||||||
|
<key>NSHighResolutionCapable</key>
|
||||||
|
<true/>
|
||||||
|
|
||||||
<!-- 其他权限和配置可以在这里添加 -->
|
<!-- 其他权限和配置可以在这里添加 -->
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
@@ -12,14 +12,19 @@ int MouseController::Init(int screen_width, int screen_height) {
|
|||||||
screen_width_ = screen_width;
|
screen_width_ = screen_width;
|
||||||
screen_height_ = screen_height;
|
screen_height_ = screen_height;
|
||||||
|
|
||||||
|
pixel_width_ =
|
||||||
|
CGDisplayModeGetPixelWidth(CGDisplayCopyDisplayMode(CGMainDisplayID()));
|
||||||
|
pixel_height_ =
|
||||||
|
CGDisplayModeGetPixelHeight(CGDisplayCopyDisplayMode(CGMainDisplayID()));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MouseController::Destroy() { return 0; }
|
int MouseController::Destroy() { return 0; }
|
||||||
|
|
||||||
int MouseController::SendCommand(RemoteAction remote_action) {
|
int MouseController::SendCommand(RemoteAction remote_action) {
|
||||||
int mouse_pos_x = remote_action.m.x;
|
int mouse_pos_x = remote_action.m.x * screen_width_ / pixel_width_;
|
||||||
int mouse_pos_y = remote_action.m.y;
|
int mouse_pos_y = remote_action.m.y * screen_height_ / pixel_height_;
|
||||||
|
|
||||||
if (remote_action.type == ControlType::mouse) {
|
if (remote_action.type == ControlType::mouse) {
|
||||||
CGEventRef mouse_event;
|
CGEventRef mouse_event;
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ class MouseController : public DeviceController {
|
|||||||
private:
|
private:
|
||||||
int screen_width_ = 0;
|
int screen_width_ = 0;
|
||||||
int screen_height_ = 0;
|
int screen_height_ = 0;
|
||||||
|
|
||||||
|
int pixel_width_ = 0;
|
||||||
|
int pixel_height_ = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include "rd_log.h"
|
#include "rd_log.h"
|
||||||
|
|
||||||
|
#define USE_SCALE_FACTOR 0
|
||||||
|
|
||||||
ScreenCapturerAvf::ScreenCapturerAvf() {}
|
ScreenCapturerAvf::ScreenCapturerAvf() {}
|
||||||
|
|
||||||
ScreenCapturerAvf::~ScreenCapturerAvf() {
|
ScreenCapturerAvf::~ScreenCapturerAvf() {
|
||||||
@@ -44,7 +46,7 @@ ScreenCapturerAvf::~ScreenCapturerAvf() {
|
|||||||
packet_ = nullptr;
|
packet_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 1
|
#if USE_SCALE_FACTOR
|
||||||
if (img_convert_ctx_) {
|
if (img_convert_ctx_) {
|
||||||
sws_freeContext(img_convert_ctx_);
|
sws_freeContext(img_convert_ctx_);
|
||||||
img_convert_ctx_ = nullptr;
|
img_convert_ctx_ = nullptr;
|
||||||
@@ -122,7 +124,7 @@ int ScreenCapturerAvf::Init(const int fps, cb_desktop_data cb) {
|
|||||||
pFrame_->width = screen_w;
|
pFrame_->width = screen_w;
|
||||||
pFrame_->height = screen_h;
|
pFrame_->height = screen_h;
|
||||||
|
|
||||||
#if 1
|
#if USE_SCALE_FACTOR
|
||||||
pFrame_resized_ = av_frame_alloc();
|
pFrame_resized_ = av_frame_alloc();
|
||||||
pFrame_resized_->width = CGDisplayPixelsWide(CGMainDisplayID());
|
pFrame_resized_->width = CGDisplayPixelsWide(CGMainDisplayID());
|
||||||
pFrame_resized_->height = CGDisplayPixelsHigh(CGMainDisplayID());
|
pFrame_resized_->height = CGDisplayPixelsHigh(CGMainDisplayID());
|
||||||
@@ -164,17 +166,7 @@ int ScreenCapturerAvf::Start() {
|
|||||||
got_picture_ = avcodec_receive_frame(pCodecCtx_, pFrame_);
|
got_picture_ = avcodec_receive_frame(pCodecCtx_, pFrame_);
|
||||||
|
|
||||||
if (!got_picture_) {
|
if (!got_picture_) {
|
||||||
#if 0
|
#if USE_SCALE_FACTOR
|
||||||
memcpy(nv12_frame_, pFrame_->data[0],
|
|
||||||
pFrame_->linesize[0] * pFrame_->height);
|
|
||||||
memcpy(nv12_frame_ + pFrame_->linesize[0] * pFrame_->height,
|
|
||||||
pFrame_->data[1],
|
|
||||||
pFrame_->linesize[1] * pFrame_->height / 2);
|
|
||||||
LOG_ERROR("size {} {}", pFrame_->width, pFrame_->height);
|
|
||||||
_on_data((unsigned char *)nv12_frame_,
|
|
||||||
pFrame_->width * pFrame_->height * 3 / 2, pFrame_->width,
|
|
||||||
pFrame_->height);
|
|
||||||
#else
|
|
||||||
av_image_fill_arrays(pFrame_resized_->data,
|
av_image_fill_arrays(pFrame_resized_->data,
|
||||||
pFrame_resized_->linesize, nv12_frame_,
|
pFrame_resized_->linesize, nv12_frame_,
|
||||||
AV_PIX_FMT_NV12, pFrame_resized_->width,
|
AV_PIX_FMT_NV12, pFrame_resized_->width,
|
||||||
@@ -187,6 +179,15 @@ int ScreenCapturerAvf::Start() {
|
|||||||
_on_data((unsigned char *)nv12_frame_,
|
_on_data((unsigned char *)nv12_frame_,
|
||||||
pFrame_resized_->width * pFrame_resized_->height * 3 / 2,
|
pFrame_resized_->width * pFrame_resized_->height * 3 / 2,
|
||||||
pFrame_resized_->width, pFrame_resized_->height);
|
pFrame_resized_->width, pFrame_resized_->height);
|
||||||
|
#else
|
||||||
|
memcpy(nv12_frame_, pFrame_->data[0],
|
||||||
|
pFrame_->linesize[0] * pFrame_->height);
|
||||||
|
memcpy(nv12_frame_ + pFrame_->linesize[0] * pFrame_->height,
|
||||||
|
pFrame_->data[1],
|
||||||
|
pFrame_->linesize[1] * pFrame_->height / 2);
|
||||||
|
_on_data((unsigned char *)nv12_frame_,
|
||||||
|
pFrame_->width * pFrame_->height * 3 / 2, pFrame_->width,
|
||||||
|
pFrame_->height);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user