mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
Fix MacOSX compile error
This commit is contained in:
@@ -215,7 +215,7 @@ void ReceiveDataBuffer(const char *data, size_t size, const char *user_id,
|
||||
std::cout << "remote_action: " << remote_action.type << " "
|
||||
<< remote_action.m.flag << " " << remote_action.m.x << " "
|
||||
<< remote_action.m.y << std::endl;
|
||||
|
||||
#ifdef _WIN32
|
||||
INPUT ip;
|
||||
|
||||
if (remote_action.type == ControlType::mouse) {
|
||||
@@ -247,6 +247,7 @@ void ReceiveDataBuffer(const char *data, size_t size, const char *user_id,
|
||||
<< ip.mi.dwFlags << " " << ip.mi.dx << " " << ip.mi.dy
|
||||
<< std::endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string GetMac(char *mac_addr) {
|
||||
@@ -470,7 +471,7 @@ int main() {
|
||||
CreateConnection(peer_server, mac_addr, user_id.c_str());
|
||||
|
||||
nv12_buffer_ = new char[NV12_BUFFER_SIZE];
|
||||
|
||||
#ifdef _WIN32
|
||||
screen_capture = new ScreenCaptureWgc();
|
||||
|
||||
RECORD_DESKTOP_RECT rect;
|
||||
@@ -504,6 +505,7 @@ int main() {
|
||||
});
|
||||
|
||||
screen_capture->Start();
|
||||
#endif
|
||||
} else {
|
||||
LeaveConnection(peer_server);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "screen_capture_wgc.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
ScreenCaptureWgc::ScreenCaptureWgc() {}
|
||||
|
||||
ScreenCaptureWgc::~ScreenCaptureWgc() {}
|
||||
|
||||
bool ScreenCaptureWgc::IsWgcSupported() { return false; }
|
||||
|
||||
int ScreenCaptureWgc::Init(const RECORD_DESKTOP_RECT &rect, const int fps,
|
||||
cb_desktop_data cb) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ScreenCaptureWgc::Start() { return 0; }
|
||||
|
||||
int ScreenCaptureWgc::Pause() { return 0; }
|
||||
|
||||
int ScreenCaptureWgc::Resume() { return 0; }
|
||||
|
||||
int ScreenCaptureWgc::Stop() { return 0; }
|
||||
|
||||
void ScreenCaptureWgc::OnFrame() {}
|
||||
|
||||
void ScreenCaptureWgc::CleanUp() {}
|
||||
@@ -0,0 +1,56 @@
|
||||
#ifndef _SCREEN_CAPTURE_WGC_H_
|
||||
#define _SCREEN_CAPTURE_WGC_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
typedef struct {
|
||||
int left;
|
||||
int top;
|
||||
int right;
|
||||
int bottom;
|
||||
} RECORD_DESKTOP_RECT;
|
||||
|
||||
typedef std::function<void(unsigned char *, int, int, int)> cb_desktop_data;
|
||||
typedef std::function<void(int)> cb_desktop_error;
|
||||
|
||||
class ScreenCaptureWgc {
|
||||
public:
|
||||
ScreenCaptureWgc();
|
||||
~ScreenCaptureWgc();
|
||||
|
||||
public:
|
||||
bool IsWgcSupported();
|
||||
|
||||
int Init(const RECORD_DESKTOP_RECT &rect, const int fps, cb_desktop_data cb);
|
||||
|
||||
int Start();
|
||||
int Pause();
|
||||
int Resume();
|
||||
int Stop();
|
||||
|
||||
void OnFrame();
|
||||
|
||||
protected:
|
||||
void CleanUp();
|
||||
|
||||
private:
|
||||
std::atomic_bool _running;
|
||||
std::atomic_bool _paused;
|
||||
std::atomic_bool _inited;
|
||||
|
||||
std::thread _thread;
|
||||
|
||||
std::string _device_name;
|
||||
|
||||
RECORD_DESKTOP_RECT _rect;
|
||||
|
||||
int _fps;
|
||||
|
||||
cb_desktop_data _on_data;
|
||||
cb_desktop_error _on_error;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "screen_capture_wgc.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
ScreenCaptureWgc::ScreenCaptureWgc() {}
|
||||
|
||||
ScreenCaptureWgc::~ScreenCaptureWgc() {}
|
||||
|
||||
bool ScreenCaptureWgc::IsWgcSupported() { return false; }
|
||||
|
||||
int ScreenCaptureWgc::Init(const RECORD_DESKTOP_RECT &rect, const int fps,
|
||||
cb_desktop_data cb) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ScreenCaptureWgc::Start() { return 0; }
|
||||
|
||||
int ScreenCaptureWgc::Pause() { return 0; }
|
||||
|
||||
int ScreenCaptureWgc::Resume() { return 0; }
|
||||
|
||||
int ScreenCaptureWgc::Stop() { return 0; }
|
||||
|
||||
void ScreenCaptureWgc::OnFrame() {}
|
||||
|
||||
void ScreenCaptureWgc::CleanUp() {}
|
||||
@@ -0,0 +1,56 @@
|
||||
#ifndef _SCREEN_CAPTURE_WGC_H_
|
||||
#define _SCREEN_CAPTURE_WGC_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
typedef struct {
|
||||
int left;
|
||||
int top;
|
||||
int right;
|
||||
int bottom;
|
||||
} RECORD_DESKTOP_RECT;
|
||||
|
||||
typedef std::function<void(unsigned char *, int, int, int)> cb_desktop_data;
|
||||
typedef std::function<void(int)> cb_desktop_error;
|
||||
|
||||
class ScreenCaptureWgc {
|
||||
public:
|
||||
ScreenCaptureWgc();
|
||||
~ScreenCaptureWgc();
|
||||
|
||||
public:
|
||||
bool IsWgcSupported();
|
||||
|
||||
int Init(const RECORD_DESKTOP_RECT &rect, const int fps, cb_desktop_data cb);
|
||||
|
||||
int Start();
|
||||
int Pause();
|
||||
int Resume();
|
||||
int Stop();
|
||||
|
||||
void OnFrame();
|
||||
|
||||
protected:
|
||||
void CleanUp();
|
||||
|
||||
private:
|
||||
std::atomic_bool _running;
|
||||
std::atomic_bool _paused;
|
||||
std::atomic_bool _inited;
|
||||
|
||||
std::thread _thread;
|
||||
|
||||
std::string _device_name;
|
||||
|
||||
RECORD_DESKTOP_RECT _rect;
|
||||
|
||||
int _fps;
|
||||
|
||||
cb_desktop_data _on_data;
|
||||
cb_desktop_error _on_error;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,134 +0,0 @@
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "screen_capture_wgc.h"
|
||||
|
||||
extern "C" {
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libswscale/swscale.h>
|
||||
};
|
||||
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include "SDL2/SDL.h"
|
||||
|
||||
int screen_w = 2560, screen_h = 1440;
|
||||
const int pixel_w = 2560, pixel_h = 1440;
|
||||
|
||||
unsigned char dst_buffer[pixel_w * pixel_h * 3 / 2];
|
||||
SDL_Texture *sdlTexture = nullptr;
|
||||
SDL_Renderer *sdlRenderer = nullptr;
|
||||
SDL_Rect sdlRect;
|
||||
|
||||
// Refresh Event
|
||||
#define REFRESH_EVENT (SDL_USEREVENT + 1)
|
||||
#define QUIT_EVENT (SDL_USEREVENT + 2)
|
||||
|
||||
int thread_exit = 0;
|
||||
|
||||
int refresh_video(void *opaque) {
|
||||
SDL_Event event;
|
||||
while (thread_exit == 0) {
|
||||
event.type = REFRESH_EVENT;
|
||||
SDL_PushEvent(&event);
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
event.type = QUIT_EVENT;
|
||||
SDL_PushEvent(&event);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BGRAToNV12FFmpeg(unsigned char *src_buffer, int width, int height,
|
||||
unsigned char *dst_buffer) {
|
||||
AVFrame *Input_pFrame = av_frame_alloc();
|
||||
AVFrame *Output_pFrame = av_frame_alloc();
|
||||
struct SwsContext *img_convert_ctx = sws_getContext(
|
||||
width, height, AV_PIX_FMT_BGRA, width, height, AV_PIX_FMT_NV12,
|
||||
SWS_FAST_BILINEAR, nullptr, nullptr, nullptr);
|
||||
|
||||
av_image_fill_arrays(Input_pFrame->data, Input_pFrame->linesize, src_buffer,
|
||||
AV_PIX_FMT_BGRA, width, height, 1);
|
||||
av_image_fill_arrays(Output_pFrame->data, Output_pFrame->linesize, dst_buffer,
|
||||
AV_PIX_FMT_NV12, width, height, 1);
|
||||
|
||||
sws_scale(img_convert_ctx, (uint8_t const **)Input_pFrame->data,
|
||||
Input_pFrame->linesize, 0, height, Output_pFrame->data,
|
||||
Output_pFrame->linesize);
|
||||
|
||||
if (Input_pFrame) av_free(Input_pFrame);
|
||||
if (Output_pFrame) av_free(Output_pFrame);
|
||||
if (img_convert_ctx) sws_freeContext(img_convert_ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void OnFrame(unsigned char *data, int size, int width, int height) {
|
||||
BGRAToNV12FFmpeg(data, width, height, dst_buffer);
|
||||
}
|
||||
|
||||
int main() {
|
||||
ScreenCaptureWgc *recorder = new ScreenCaptureWgc();
|
||||
|
||||
RECORD_DESKTOP_RECT rect;
|
||||
rect.left = 0;
|
||||
rect.top = 0;
|
||||
rect.right = GetSystemMetrics(SM_CXSCREEN);
|
||||
rect.bottom = GetSystemMetrics(SM_CYSCREEN);
|
||||
|
||||
recorder->Init(rect, 60, OnFrame);
|
||||
|
||||
recorder->Start();
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO)) {
|
||||
printf("Could not initialize SDL - %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_Window *screen;
|
||||
screen = SDL_CreateWindow("RTS Receiver", SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED, screen_w / 2, screen_h / 2,
|
||||
SDL_WINDOW_RESIZABLE);
|
||||
if (!screen) {
|
||||
printf("SDL: could not create window - exiting:%s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
sdlRenderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_ACCELERATED);
|
||||
|
||||
Uint32 pixformat = 0;
|
||||
pixformat = SDL_PIXELFORMAT_NV12;
|
||||
|
||||
sdlTexture = SDL_CreateTexture(sdlRenderer, pixformat,
|
||||
SDL_TEXTUREACCESS_STREAMING, pixel_w, pixel_h);
|
||||
|
||||
SDL_Thread *refresh_thread = SDL_CreateThread(refresh_video, NULL, NULL);
|
||||
SDL_Event event;
|
||||
while (1) {
|
||||
// Wait
|
||||
SDL_WaitEvent(&event);
|
||||
if (event.type == REFRESH_EVENT) {
|
||||
sdlRect.x = 0;
|
||||
sdlRect.y = 0;
|
||||
sdlRect.w = screen_w;
|
||||
sdlRect.h = screen_h;
|
||||
|
||||
SDL_UpdateTexture(sdlTexture, NULL, dst_buffer, pixel_w);
|
||||
SDL_RenderClear(sdlRenderer);
|
||||
SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, &sdlRect);
|
||||
SDL_RenderPresent(sdlRenderer);
|
||||
} else if (event.type == SDL_WINDOWEVENT) {
|
||||
// If Resize
|
||||
SDL_GetWindowSize(screen, &screen_w, &screen_h);
|
||||
printf("Resize windows: %dx%d\n", screen_w, screen_h);
|
||||
} else if (event.type == SDL_QUIT) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "screen_capture_wgc.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <d3d11_4.h>
|
||||
#include <winrt/Windows.Foundation.Metadata.h>
|
||||
#include <winrt/Windows.Graphics.Capture.h>
|
||||
@@ -1,16 +1,11 @@
|
||||
#ifndef _SCREEN_CAPTURE_WGC_H_
|
||||
#define _SCREEN_CAPTURE_WGC_H_
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include "wgc_session.h"
|
||||
#include "wgc_session_impl.h"
|
||||
|
||||
typedef struct {
|
||||
int left;
|
||||
int top;
|
||||
@@ -21,7 +16,7 @@ typedef struct {
|
||||
typedef std::function<void(unsigned char *, int, int, int)> cb_desktop_data;
|
||||
typedef std::function<void(int)> cb_desktop_error;
|
||||
|
||||
class ScreenCaptureWgc : public WgcSession::wgc_session_observer {
|
||||
class ScreenCaptureWgc {
|
||||
public:
|
||||
ScreenCaptureWgc();
|
||||
~ScreenCaptureWgc();
|
||||
@@ -35,45 +35,17 @@ target("log")
|
||||
target("screen_capture")
|
||||
set_kind("static")
|
||||
add_packages("log")
|
||||
add_files("screen_capture/*.cpp")
|
||||
add_includedirs("screen_capture", {public = true})
|
||||
|
||||
target("remote_desk_server")
|
||||
set_kind("binary")
|
||||
add_packages("log", "vcpkg::ffmpeg", "sdl2")
|
||||
add_deps("projectx", "screen_capture")
|
||||
add_files("remote_desk_server/*.cpp")
|
||||
add_includedirs("../../src/interface")
|
||||
add_links("swscale", "avutil")
|
||||
add_defines("WIN32_LEAN_AND_MEAN")
|
||||
if is_os("windows") then
|
||||
add_links("SDL2-static", "SDL2main", "gdi32", "winmm",
|
||||
"setupapi", "version", "Imm32", "iphlpapi")
|
||||
end
|
||||
|
||||
|
||||
target("remote_desk_client")
|
||||
set_kind("binary")
|
||||
add_deps("projectx")
|
||||
add_packages("log")
|
||||
if is_os("windows") then
|
||||
add_packages("sdl2")
|
||||
elseif is_os("macosx") or is_os("linux")then
|
||||
add_packages("sdl2")
|
||||
add_packages("ffmpeg")
|
||||
end
|
||||
add_files("remote_desk_client/*.cpp")
|
||||
add_includedirs("../../src/interface")
|
||||
if is_os("windows") then
|
||||
add_links("SDL2-static", "SDL2main", "gdi32", "winmm",
|
||||
"setupapi", "version", "Imm32", "iphlpapi")
|
||||
add_files("screen_capture/windows/*.cpp")
|
||||
add_includedirs("screen_capture/windows", {public = true})
|
||||
elseif is_os("macosx") then
|
||||
add_links("SDL2")
|
||||
add_files("screen_capture/macosx/*.cpp")
|
||||
add_includedirs("screen_capture/macosx", {public = true})
|
||||
elseif is_os("linux") then
|
||||
add_links("SDL2")
|
||||
add_files("screen_capture/linux/*.cpp")
|
||||
add_includedirs("screen_capture/linux", {public = true})
|
||||
end
|
||||
|
||||
|
||||
target("remote_desk_gui")
|
||||
set_kind("binary")
|
||||
add_deps("projectx", "screen_capture")
|
||||
|
||||
Reference in New Issue
Block a user