diff --git a/application/remote_desk/remote_desk_client/remote_desk_client.cpp b/application/remote_desk/remote_desk_client/remote_desk_client.cpp index 25909c4..99a4ed3 100644 --- a/application/remote_desk/remote_desk_client/remote_desk_client.cpp +++ b/application/remote_desk/remote_desk_client/remote_desk_client.cpp @@ -7,9 +7,16 @@ #include #include #include +#elif __linux__ +#include +#include +#include #endif +#include + #include +#include #include #include #include @@ -211,8 +218,8 @@ std::string GetMac(char *mac_addr) { break; } } -#else - std::string ifName = "en0"; +#elif __APPLE__ + std::string if_name = "en0"; struct ifaddrs *addrs; struct ifaddrs *cursor; @@ -225,7 +232,7 @@ std::string GetMac(char *mac_addr) { (const struct sockaddr_dl *)cursor->ifa_addr; if ((cursor->ifa_addr->sa_family == AF_LINK) && (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; const unsigned char *base = (const unsigned char *)&dlAddr->sdl_data[dlAddr->sdl_nlen]; @@ -237,6 +244,40 @@ std::string GetMac(char *mac_addr) { } 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 return mac_addr; } diff --git a/application/remote_desk/xmake.lua b/application/remote_desk/xmake.lua index 3cfcb86..698e898 100644 --- a/application/remote_desk/xmake.lua +++ b/application/remote_desk/xmake.lua @@ -60,8 +60,7 @@ target("remote_desk_client") add_packages("log") if is_os("windows") then add_packages("vcpkg::sdl2") - elseif is_os("macosx") then - -- add_packages("vcpkg::sdl2") + elseif is_os("macosx") or is_os("linux")then add_packages("sdl2") add_packages("ffmpeg") end @@ -70,7 +69,7 @@ target("remote_desk_client") if is_os("windows") then add_links("SDL2-static", "SDL2main", "gdi32", "winmm", "setupapi", "version", "Imm32", "iphlpapi") - elseif is_os("macosx") then + elseif is_os("macosx") or is_os("linux") then add_links("SDL2") end diff --git a/src/frame/frame.cpp b/src/frame/frame.cpp index a0cd09f..eac78bc 100644 --- a/src/frame/frame.cpp +++ b/src/frame/frame.cpp @@ -1,5 +1,7 @@ #include "frame.h" +#include + #include VideoFrame::VideoFrame() {} diff --git a/src/media/video/decode/video_decoder_factory.h b/src/media/video/decode/video_decoder_factory.h index ae903e1..c4e0e51 100644 --- a/src/media/video/decode/video_decoder_factory.h +++ b/src/media/video/decode/video_decoder_factory.h @@ -1,6 +1,8 @@ #ifndef _VIDEO_DECODER_FACTORY_H_ #define _VIDEO_DECODER_FACTORY_H_ +#include + #include "video_decoder.h" class VideoDecoderFactory { public: diff --git a/src/media/video/encode/video_encoder_factory.h b/src/media/video/encode/video_encoder_factory.h index c2d3a96..638b7f1 100644 --- a/src/media/video/encode/video_encoder_factory.h +++ b/src/media/video/encode/video_encoder_factory.h @@ -1,6 +1,8 @@ #ifndef _VIDEO_ENCODER_FACTORY_H_ #define _VIDEO_ENCODER_FACTORY_H_ +#include + #include "video_encoder.h" class VideoEncoderFactory { public: diff --git a/src/pc/peer_connection.h b/src/pc/peer_connection.h index 0bc8bc3..7283826 100644 --- a/src/pc/peer_connection.h +++ b/src/pc/peer_connection.h @@ -6,12 +6,8 @@ #include #include "ice_transmission.h" -#ifdef _WIN32 - #include "video_decoder_factory.h" #include "video_encoder_factory.h" -#endif - #include "ws_transmission.h" enum SignalStatus { Connecting = 0, Connected, Closed }; diff --git a/src/rtp/rtp_packet.h b/src/rtp/rtp_packet.h index 32770ac..a042f5a 100644 --- a/src/rtp/rtp_packet.h +++ b/src/rtp/rtp_packet.h @@ -1,7 +1,9 @@ #ifndef _RTP_PACKET_H_ #define _RTP_PACKET_H_ +#include #include +#include #include diff --git a/src/thread/thread_base.h b/src/thread/thread_base.h index c2ddd1d..bd6533f 100644 --- a/src/thread/thread_base.h +++ b/src/thread/thread_base.h @@ -24,8 +24,8 @@ class ThreadBase { private: std::unique_ptr thread_ = nullptr; - std::atomic stop_ = false; - std::atomic pause_ = false; + std::atomic stop_{false}; + std::atomic pause_{false}; }; #endif \ No newline at end of file diff --git a/xmake.lua b/xmake.lua index cc8faff..91c4afd 100644 --- a/xmake.lua +++ b/xmake.lua @@ -102,15 +102,14 @@ target("ws") target("media") set_kind("static") add_deps("log", "frame") - if is_os("windows") or is_os(("linux")) then + if is_os("windows") 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" - ) + "src/media/video/decode/ffmpeg/*.cpp") add_includedirs("src/media/video/encode", "src/media/video/decode", "src/media/video/encode/nvcodec", @@ -121,6 +120,24 @@ target("media") "thirdparty/nvcodec/Samples", {public = true}) add_linkdirs("thirdparty/nvcodec/Lib/x64") 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 add_files("src/media/video/encode/ffmpeg/*.cpp", "src/media/video/decode/ffmpeg/*.cpp")