mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
Remote desk client supports Linux platform
This commit is contained in:
@@ -7,9 +7,16 @@
|
|||||||
#include <net/if_types.h>
|
#include <net/if_types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#elif __linux__
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -211,8 +218,8 @@ std::string GetMac(char *mac_addr) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#elif __APPLE__
|
||||||
std::string ifName = "en0";
|
std::string if_name = "en0";
|
||||||
|
|
||||||
struct ifaddrs *addrs;
|
struct ifaddrs *addrs;
|
||||||
struct ifaddrs *cursor;
|
struct ifaddrs *cursor;
|
||||||
@@ -225,7 +232,7 @@ std::string GetMac(char *mac_addr) {
|
|||||||
(const struct sockaddr_dl *)cursor->ifa_addr;
|
(const struct sockaddr_dl *)cursor->ifa_addr;
|
||||||
if ((cursor->ifa_addr->sa_family == AF_LINK) &&
|
if ((cursor->ifa_addr->sa_family == AF_LINK) &&
|
||||||
(socAddr->sdl_type == IFT_ETHER) &&
|
(socAddr->sdl_type == IFT_ETHER) &&
|
||||||
strcmp("en0", cursor->ifa_name) == 0) {
|
strcmp(if_name, cursor->ifa_name) == 0) {
|
||||||
dlAddr = (const struct sockaddr_dl *)cursor->ifa_addr;
|
dlAddr = (const struct sockaddr_dl *)cursor->ifa_addr;
|
||||||
const unsigned char *base =
|
const unsigned char *base =
|
||||||
(const unsigned char *)&dlAddr->sdl_data[dlAddr->sdl_nlen];
|
(const unsigned char *)&dlAddr->sdl_data[dlAddr->sdl_nlen];
|
||||||
@@ -237,6 +244,40 @@ std::string GetMac(char *mac_addr) {
|
|||||||
}
|
}
|
||||||
freeifaddrs(addrs);
|
freeifaddrs(addrs);
|
||||||
}
|
}
|
||||||
|
#elif __linux__
|
||||||
|
int sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
if (sock < 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
struct ifreq ifr;
|
||||||
|
struct ifconf ifc;
|
||||||
|
char buf[1024];
|
||||||
|
ifc.ifc_len = sizeof(buf);
|
||||||
|
ifc.ifc_buf = buf;
|
||||||
|
if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) {
|
||||||
|
close(sock);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
struct ifreq *it = ifc.ifc_req;
|
||||||
|
const struct ifreq *const end = it + (ifc.ifc_len / sizeof(struct ifreq));
|
||||||
|
for (; it != end; ++it) {
|
||||||
|
std::strcpy(ifr.ifr_name, it->ifr_name);
|
||||||
|
if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ifr.ifr_flags & IFF_LOOPBACK) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
std::string mac_address;
|
||||||
|
for (int i = 0; i < 6; ++i) {
|
||||||
|
len += sprintf(mac_addr + len, "%.2X", ifr.ifr_hwaddr.sa_data[i] & 0xff);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
close(sock);
|
||||||
#endif
|
#endif
|
||||||
return mac_addr;
|
return mac_addr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,8 +60,7 @@ target("remote_desk_client")
|
|||||||
add_packages("log")
|
add_packages("log")
|
||||||
if is_os("windows") then
|
if is_os("windows") then
|
||||||
add_packages("vcpkg::sdl2")
|
add_packages("vcpkg::sdl2")
|
||||||
elseif is_os("macosx") then
|
elseif is_os("macosx") or is_os("linux")then
|
||||||
-- add_packages("vcpkg::sdl2")
|
|
||||||
add_packages("sdl2")
|
add_packages("sdl2")
|
||||||
add_packages("ffmpeg")
|
add_packages("ffmpeg")
|
||||||
end
|
end
|
||||||
@@ -70,7 +69,7 @@ target("remote_desk_client")
|
|||||||
if is_os("windows") then
|
if is_os("windows") then
|
||||||
add_links("SDL2-static", "SDL2main", "gdi32", "winmm",
|
add_links("SDL2-static", "SDL2main", "gdi32", "winmm",
|
||||||
"setupapi", "version", "Imm32", "iphlpapi")
|
"setupapi", "version", "Imm32", "iphlpapi")
|
||||||
elseif is_os("macosx") then
|
elseif is_os("macosx") or is_os("linux") then
|
||||||
add_links("SDL2")
|
add_links("SDL2")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "frame.h"
|
#include "frame.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
VideoFrame::VideoFrame() {}
|
VideoFrame::VideoFrame() {}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef _VIDEO_DECODER_FACTORY_H_
|
#ifndef _VIDEO_DECODER_FACTORY_H_
|
||||||
#define _VIDEO_DECODER_FACTORY_H_
|
#define _VIDEO_DECODER_FACTORY_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "video_decoder.h"
|
#include "video_decoder.h"
|
||||||
class VideoDecoderFactory {
|
class VideoDecoderFactory {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef _VIDEO_ENCODER_FACTORY_H_
|
#ifndef _VIDEO_ENCODER_FACTORY_H_
|
||||||
#define _VIDEO_ENCODER_FACTORY_H_
|
#define _VIDEO_ENCODER_FACTORY_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "video_encoder.h"
|
#include "video_encoder.h"
|
||||||
class VideoEncoderFactory {
|
class VideoEncoderFactory {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -6,12 +6,8 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include "ice_transmission.h"
|
#include "ice_transmission.h"
|
||||||
#ifdef _WIN32
|
|
||||||
|
|
||||||
#include "video_decoder_factory.h"
|
#include "video_decoder_factory.h"
|
||||||
#include "video_encoder_factory.h"
|
#include "video_encoder_factory.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "ws_transmission.h"
|
#include "ws_transmission.h"
|
||||||
|
|
||||||
enum SignalStatus { Connecting = 0, Connected, Closed };
|
enum SignalStatus { Connecting = 0, Connected, Closed };
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#ifndef _RTP_PACKET_H_
|
#ifndef _RTP_PACKET_H_
|
||||||
#define _RTP_PACKET_H_
|
#define _RTP_PACKET_H_
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ class ThreadBase {
|
|||||||
private:
|
private:
|
||||||
std::unique_ptr<std::thread> thread_ = nullptr;
|
std::unique_ptr<std::thread> thread_ = nullptr;
|
||||||
|
|
||||||
std::atomic<bool> stop_ = false;
|
std::atomic<bool> stop_{false};
|
||||||
std::atomic<bool> pause_ = false;
|
std::atomic<bool> pause_{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
23
xmake.lua
23
xmake.lua
@@ -102,15 +102,14 @@ target("ws")
|
|||||||
target("media")
|
target("media")
|
||||||
set_kind("static")
|
set_kind("static")
|
||||||
add_deps("log", "frame")
|
add_deps("log", "frame")
|
||||||
if is_os("windows") or is_os(("linux")) then
|
if is_os("windows") then
|
||||||
add_packages("cuda")
|
add_packages("cuda")
|
||||||
add_files("src/media/video/encode/*.cpp",
|
add_files("src/media/video/encode/*.cpp",
|
||||||
"src/media/video/decode/*.cpp",
|
"src/media/video/decode/*.cpp",
|
||||||
"src/media/video/encode/nvcodec/*.cpp",
|
"src/media/video/encode/nvcodec/*.cpp",
|
||||||
"src/media/video/decode/nvcodec/*.cpp",
|
"src/media/video/decode/nvcodec/*.cpp",
|
||||||
"src/media/video/encode/ffmpeg/*.cpp",
|
"src/media/video/encode/ffmpeg/*.cpp",
|
||||||
"src/media/video/decode/ffmpeg/*.cpp"
|
"src/media/video/decode/ffmpeg/*.cpp")
|
||||||
)
|
|
||||||
add_includedirs("src/media/video/encode",
|
add_includedirs("src/media/video/encode",
|
||||||
"src/media/video/decode",
|
"src/media/video/decode",
|
||||||
"src/media/video/encode/nvcodec",
|
"src/media/video/encode/nvcodec",
|
||||||
@@ -121,6 +120,24 @@ target("media")
|
|||||||
"thirdparty/nvcodec/Samples", {public = true})
|
"thirdparty/nvcodec/Samples", {public = true})
|
||||||
add_linkdirs("thirdparty/nvcodec/Lib/x64")
|
add_linkdirs("thirdparty/nvcodec/Lib/x64")
|
||||||
add_links("cuda", "nvencodeapi", "nvcuvid")
|
add_links("cuda", "nvencodeapi", "nvcuvid")
|
||||||
|
elseif is_os(("linux")) then
|
||||||
|
add_packages("cuda")
|
||||||
|
add_files("src/media/video/encode/*.cpp",
|
||||||
|
"src/media/video/decode/*.cpp",
|
||||||
|
"src/media/video/encode/nvcodec/*.cpp",
|
||||||
|
"src/media/video/decode/nvcodec/*.cpp",
|
||||||
|
"src/media/video/encode/ffmpeg/*.cpp",
|
||||||
|
"src/media/video/decode/ffmpeg/*.cpp")
|
||||||
|
add_includedirs("src/media/video/encode",
|
||||||
|
"src/media/video/decode",
|
||||||
|
"src/media/video/encode/nvcodec",
|
||||||
|
"src/media/video/decode/nvcodec",
|
||||||
|
"src/media/video/encode/ffmpeg",
|
||||||
|
"src/media/video/decode/ffmpeg",
|
||||||
|
"thirdparty/nvcodec/Interface",
|
||||||
|
"thirdparty/nvcodec/Samples", {public = true})
|
||||||
|
add_linkdirs("thirdparty/nvcodec/Lib/x64")
|
||||||
|
add_links("cuda", "nvidia-encode", "nvcuvid")
|
||||||
elseif is_os("macosx") then
|
elseif is_os("macosx") then
|
||||||
add_files("src/media/video/encode/ffmpeg/*.cpp",
|
add_files("src/media/video/encode/ffmpeg/*.cpp",
|
||||||
"src/media/video/decode/ffmpeg/*.cpp")
|
"src/media/video/decode/ffmpeg/*.cpp")
|
||||||
|
|||||||
Reference in New Issue
Block a user