[fix] fix compile error on Linux

This commit is contained in:
dijunkun
2025-05-06 18:39:30 +08:00
parent a9084ba98d
commit f3451a5fa1
7 changed files with 27 additions and 21 deletions

View File

@@ -1,6 +1,6 @@
#include "mouse_controller.h" #include "mouse_controller.h"
#include "log.h" #include "rd_log.h"
MouseController::MouseController() {} MouseController::MouseController() {}
@@ -80,13 +80,13 @@ int MouseController::SendMouseCommand(RemoteAction remote_action) {
event.type = EV_REL; event.type = EV_REL;
event.code = REL_WHEEL; event.code = REL_WHEEL;
event.value = remote_action.m.s; event.value = remote_action.m.s;
write(uinput_fd_, &event, sizeof(event)); (void)write(uinput_fd_, &event, sizeof(event));
break; break;
case MouseFlag::wheel_horizontal: case MouseFlag::wheel_horizontal:
event.type = EV_REL; event.type = EV_REL;
event.code = REL_HWHEEL; event.code = REL_HWHEEL;
event.value = remote_action.m.s; event.value = remote_action.m.s;
write(uinput_fd_, &event, sizeof(event)); (void)write(uinput_fd_, &event, sizeof(event));
break; break;
default: default:
SetMousePosition(uinput_fd_, mouse_pos_x, mouse_pos_y); SetMousePosition(uinput_fd_, mouse_pos_x, mouse_pos_y);
@@ -148,4 +148,4 @@ void MouseController::SetMousePosition(int fd, int x, int y) {
ev_sync.value = 0; ev_sync.value = 0;
ev_sync.code = 0; ev_sync.code = 0;
int res_ev_sync = write(fd, &ev_sync, sizeof(ev_sync)); int res_ev_sync = write(fd, &ev_sync, sizeof(ev_sync));
} }

View File

@@ -2,7 +2,7 @@
#include <iostream> #include <iostream>
#include "log.h" #include "rd_log.h"
#define NV12_BUFFER_SIZE 1280 * 720 * 3 / 2 #define NV12_BUFFER_SIZE 1280 * 720 * 3 / 2
unsigned char nv12_buffer_[NV12_BUFFER_SIZE]; unsigned char nv12_buffer_[NV12_BUFFER_SIZE];
@@ -16,8 +16,7 @@ ScreenCapturerX11::~ScreenCapturerX11() {
} }
} }
int ScreenCapturerX11::Init(const RECORD_DESKTOP_RECT &rect, const int fps, int ScreenCapturerX11::Init(const int fps, cb_desktop_data cb) {
cb_desktop_data cb) {
if (cb) { if (cb) {
_on_data = cb; _on_data = cb;
} }
@@ -44,14 +43,22 @@ int ScreenCapturerX11::Init(const RECORD_DESKTOP_RECT &rect, const int fps,
LOG_ERROR("Couldn't find_input_format [{}]", capture_method.c_str()); LOG_ERROR("Couldn't find_input_format [{}]", capture_method.c_str());
} }
const char *display = std::getenv("DISPLAY");
// Grab at position 10,20 // Grab at position 10,20
if (avformat_open_input(&pFormatCtx_, ":0.0", ifmt_, &options_) != 0) { if (display) {
printf("Couldn't open input stream.\n"); if (avformat_open_input(&pFormatCtx_, display, ifmt_, &options_) != 0) {
LOG_ERROR("Couldn't open input stream {}", display);
return -1;
} else {
LOG_INFO("Open input stream [{}]", display);
}
} else {
LOG_ERROR("DISPLAY environment variable not set");
return -1; return -1;
} }
if (avformat_find_stream_info(pFormatCtx_, NULL) < 0) { if (avformat_find_stream_info(pFormatCtx_, NULL) < 0) {
printf("Couldn't find stream information.\n"); LOG_ERROR("Couldn't find stream information");
return -1; return -1;
} }
@@ -62,7 +69,7 @@ int ScreenCapturerX11::Init(const RECORD_DESKTOP_RECT &rect, const int fps,
break; break;
} }
if (videoindex_ == -1) { if (videoindex_ == -1) {
printf("Didn't find a video stream.\n"); LOG_ERROR("Didn't find a video stream");
return -1; return -1;
} }
@@ -73,11 +80,11 @@ int ScreenCapturerX11::Init(const RECORD_DESKTOP_RECT &rect, const int fps,
pCodec_ = const_cast<AVCodec *>(avcodec_find_decoder(pCodecCtx_->codec_id)); pCodec_ = const_cast<AVCodec *>(avcodec_find_decoder(pCodecCtx_->codec_id));
if (pCodec_ == NULL) { if (pCodec_ == NULL) {
printf("Codec not found.\n"); LOG_ERROR("Codec not found");
return -1; return -1;
} }
if (avcodec_open2(pCodecCtx_, pCodec_, NULL) < 0) { if (avcodec_open2(pCodecCtx_, pCodec_, NULL) < 0) {
printf("Could not open codec.\n"); LOG_ERROR("Could not open codec");
return -1; return -1;
} }
@@ -109,6 +116,7 @@ int ScreenCapturerX11::Destroy() {
} }
int ScreenCapturerX11::Start() { int ScreenCapturerX11::Start() {
running_ = true;
capture_thread_ = std::thread([this]() { capture_thread_ = std::thread([this]() {
while (running_) { while (running_) {
if (av_read_frame(pFormatCtx_, packet_) >= 0) { if (av_read_frame(pFormatCtx_, packet_) >= 0) {

View File

@@ -25,8 +25,7 @@ class ScreenCapturerX11 : public ScreenCapturer {
~ScreenCapturerX11(); ~ScreenCapturerX11();
public: public:
virtual int Init(const RECORD_DESKTOP_RECT &rect, const int fps, virtual int Init(const int fps, cb_desktop_data cb) override;
cb_desktop_data cb) override;
virtual int Destroy() override; virtual int Destroy() override;
virtual int Start() override; virtual int Start() override;
virtual int Stop() override; virtual int Stop() override;
@@ -48,8 +47,6 @@ class ScreenCapturerX11 : public ScreenCapturer {
std::string _device_name; std::string _device_name;
RECORD_DESKTOP_RECT _rect;
int _fps; int _fps;
cb_desktop_data _on_data; cb_desktop_data _on_data;

View File

@@ -12,6 +12,7 @@
#include <atomic> #include <atomic>
#include <chrono> #include <chrono>
#include <fstream> #include <fstream>
#include <mutex>
#include <optional> #include <optional>
#include <string> #include <string>

View File

@@ -11,6 +11,7 @@
#include <filesystem> #include <filesystem>
#include <map> #include <map>
#include <vector>
class Thumbnail { class Thumbnail {
public: public:

View File

@@ -18,7 +18,6 @@ end
add_requires("spdlog 1.14.1", {system = false}) add_requires("spdlog 1.14.1", {system = false})
add_requires("imgui v1.91.5-docking", {configs = {sdl2 = true, sdl2_renderer = true}}) add_requires("imgui v1.91.5-docking", {configs = {sdl2 = true, sdl2_renderer = true}})
add_requires("miniaudio 0.11.21")
add_requires("openssl3 3.3.2", {system = false}) add_requires("openssl3 3.3.2", {system = false})
if is_os("windows") then if is_os("windows") then
@@ -30,7 +29,7 @@ if is_os("windows") then
elseif is_os("linux") then elseif is_os("linux") then
add_requires("ffmpeg 5.1.2", {system = false}) add_requires("ffmpeg 5.1.2", {system = false})
add_syslinks("pthread", "dl") add_syslinks("pthread", "dl")
add_linkdirs("thirdparty/projectx/thirdparty/nvcodec/Lib/x64") add_linkdirs("thirdparty/projectx/thirdparty/nvcodec/lib/x64")
add_links("SDL2", "cuda", "nvidia-encode", "nvcuvid") add_links("SDL2", "cuda", "nvidia-encode", "nvcuvid")
add_ldflags("-lavformat", "-lavdevice", "-lavfilter", "-lavcodec", add_ldflags("-lavformat", "-lavdevice", "-lavfilter", "-lavcodec",
"-lswscale", "-lavutil", "-lswresample", "-lswscale", "-lavutil", "-lswresample",
@@ -224,4 +223,4 @@ target("remote_desk")
-- target("mouse_control") -- target("mouse_control")
-- set_kind("binary") -- set_kind("binary")
-- add_files("test/linux_mouse_control/mouse_control.cpp") -- add_files("test/linux_mouse_control/mouse_control.cpp")
-- add_includedirs("test/linux_mouse_control") -- add_includedirs("test/linux_mouse_control")