Optimize build script

This commit is contained in:
dijunkun
2023-11-22 17:00:52 +08:00
parent c8d404ea7d
commit d79720532d
4 changed files with 98 additions and 85 deletions

View File

@@ -1,6 +1,12 @@
#ifndef _X_H_ #ifndef _X_H_
#define _X_H_ #define _X_H_
#ifdef DLL_EXPORTS
#define DLLAPI __declspec(dllexport)
#else
#define DLLAPI __declspec(dllimport)
#endif
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@@ -34,19 +40,19 @@ typedef struct {
NetStatusReport net_status_report; NetStatusReport net_status_report;
} Params; } Params;
PeerPtr* CreatePeer(const Params* params); DLLAPI PeerPtr* CreatePeer(const Params* params);
int Init(PeerPtr* peer_ptr, const char* user_id); DLLAPI int Init(PeerPtr* peer_ptr, const char* user_id);
int CreateConnection(PeerPtr* peer_ptr, const char* transmission_id, DLLAPI int CreateConnection(PeerPtr* peer_ptr, const char* transmission_id,
const char* password); const char* password);
int JoinConnection(PeerPtr* peer_ptr, const char* transmission_id, DLLAPI int JoinConnection(PeerPtr* peer_ptr, const char* transmission_id,
const char* password); const char* password);
int LeaveConnection(PeerPtr* peer_ptr); DLLAPI int LeaveConnection(PeerPtr* peer_ptr);
int SendData(PeerPtr* peer_ptr, DATA_TYPE data_type, const char* data, DLLAPI int SendData(PeerPtr* peer_ptr, DATA_TYPE data_type, const char* data,
size_t size); size_t size);
#ifdef __cplusplus #ifdef __cplusplus

View File

@@ -8,9 +8,9 @@
#define SAVE_H264_STREAM 0 #define SAVE_H264_STREAM 0
#define YUV420P_BUFFER_SIZE 1280 * 720 * 3 / 2 #define YUV420P_BUFFER_SIZE 1280 * 720 * 3 / 2
unsigned char yuv420p_buffer[YUV420P_BUFFER_SIZE]; static unsigned char yuv420p_buffer[YUV420P_BUFFER_SIZE];
int NV12ToYUV420PFFmpeg(unsigned char *src_buffer, int width, int height, static int NV12ToYUV420PFFmpeg(unsigned char *src_buffer, int width, int height,
unsigned char *dst_buffer) { unsigned char *dst_buffer) {
AVFrame *Input_pFrame = av_frame_alloc(); AVFrame *Input_pFrame = av_frame_alloc();
AVFrame *Output_pFrame = av_frame_alloc(); AVFrame *Output_pFrame = av_frame_alloc();

View File

@@ -23,9 +23,9 @@ extern "C" {
#define SAVE_H264_STREAM 0 #define SAVE_H264_STREAM 0
#define YUV420P_BUFFER_SIZE 1280 * 720 * 3 / 2 #define YUV420P_BUFFER_SIZE 1280 * 720 * 3 / 2
unsigned char yuv420p_buffer[YUV420P_BUFFER_SIZE]; static unsigned char yuv420p_buffer[YUV420P_BUFFER_SIZE];
int NV12ToYUV420PFFmpeg(unsigned char *src_buffer, int width, int height, static int NV12ToYUV420PFFmpeg(unsigned char *src_buffer, int width, int height,
unsigned char *dst_buffer) { unsigned char *dst_buffer) {
AVFrame *Input_pFrame = av_frame_alloc(); AVFrame *Input_pFrame = av_frame_alloc();
AVFrame *Output_pFrame = av_frame_alloc(); AVFrame *Output_pFrame = av_frame_alloc();

147
xmake.lua
View File

@@ -15,126 +15,116 @@ add_defines("ASIO_STANDALONE", "ASIO_HAS_STD_TYPE_TRAITS", "ASIO_HAS_STD_SHARED_
"ASIO_HAS_STD_ADDRESSOF", "ASIO_HAS_STD_ATOMIC", "ASIO_HAS_STD_CHRONO", "ASIO_HAS_STD_ADDRESSOF", "ASIO_HAS_STD_ATOMIC", "ASIO_HAS_STD_CHRONO",
"ASIO_HAS_CSTDINT", "ASIO_HAS_STD_ARRAY", "ASIO_HAS_STD_SYSTEM_ERROR") "ASIO_HAS_CSTDINT", "ASIO_HAS_STD_ARRAY", "ASIO_HAS_STD_SYSTEM_ERROR")
if is_os("windows") then
add_defines("_WEBSOCKETPP_CPP11_INTERNAL_")
add_links("ws2_32", "Bcrypt")
add_links("windowsapp", "User32", "Strmiids", "Mfuuid", "Secur32", "Bcrypt")
add_requires("cuda")
elseif is_os("linux") then
add_cxflags("-fPIC")
add_syslinks("pthread")
elseif is_os("macosx") then
add_ldflags("-ld_classic", {force = true})
end
add_requires("asio 1.24.0", "nlohmann_json", "spdlog 1.11.0", "openfec", "libopus 1.4") add_requires("asio 1.24.0", "nlohmann_json", "spdlog 1.11.0", "openfec", "libopus 1.4")
add_packages("spdlog", "openfec") add_packages("asio", "nlohmann_json", "spdlog", "openfec", "opus")
includes("thirdparty") includes("thirdparty")
if is_os("windows") then if is_os("windows") then
add_requires("vcpkg::ffmpeg 5.1.2", {configs = {shared = false}}) add_requires("vcpkg::ffmpeg 5.1.2", {configs = {shared = false}})
add_requires("vcpkg::libnice 0.1.21") add_requires("vcpkg::libnice 0.1.21")
add_packages("vcpkg::libnice")
add_requires("openh264 2.1.1", {configs = {shared = false}}) add_requires("openh264 2.1.1", {configs = {shared = false}})
add_packages("vcpkg::ffmpeg", "vcpkg::libnice", "openh264", "cuda")
add_defines("_WEBSOCKETPP_CPP11_INTERNAL_")
add_requires("cuda")
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_requires("glib", {system = true}) add_requires("glib", {system = true})
add_requires("vcpkg::libnice 0.1.21") add_requires("vcpkg::libnice 0.1.21")
add_requires("openh264 2.1.1", {configs = {shared = false}}) add_requires("openh264 2.1.1", {configs = {shared = false}})
add_packages("glib", "vcpkg::libnice") add_packages("ffmpeg", "glib", "vcpkg::libnice", "openh264", "cuda")
add_cxflags("-fPIC")
add_syslinks("pthread")
elseif is_os("macosx") then elseif is_os("macosx") then
add_requires("ffmpeg 5.1.2", {system = false}) add_requires("ffmpeg 5.1.2", {system = false})
add_requires("brew::libnice", "brew::glib") add_requires("brew::libnice", "brew::glib")
add_requires("brew::openh264", {configs = {shared = false}}) add_requires("brew::openh264", {configs = {shared = false}})
add_packages("ffmpeg", "glib", "libnice")
add_ldflags("-ld_classic", {force = true})
end end
target("log") target("log")
set_kind("static") set_kind("object")
add_packages("spdlog")
add_files("src/log/log.cpp") add_files("src/log/log.cpp")
add_includedirs("src/log", {public = true}) add_includedirs("src/log", {public = true})
target("common") target("common")
set_kind("static") set_kind("object")
add_files("src/common/common.cpp") add_files("src/common/common.cpp")
add_includedirs("src/common", {public = true}) add_includedirs("src/common", {public = true})
target("inih") target("inih")
set_kind("static") set_kind("object")
add_files("src/inih/ini.c", "src/inih/INIReader.cpp") add_files("src/inih/ini.c", "src/inih/INIReader.cpp")
add_includedirs("src/inih", {public = true}) add_includedirs("src/inih", {public = true})
target("ringbuffer") target("ringbuffer")
set_kind("static") set_kind("object")
add_files("src/ringbuffer/ringbuffer.cpp") add_files("src/ringbuffer/ringbuffer.cpp")
add_includedirs("src/ringbuffer", {public = true}) add_includedirs("src/ringbuffer", {public = true})
target("thread") target("thread")
set_kind("static") set_kind("object")
add_deps("log") add_deps("log")
add_files("src/thread/*.cpp") add_files("src/thread/*.cpp")
add_includedirs("src/thread", {public = true}) add_includedirs("src/thread", {public = true})
target("frame") target("frame")
set_kind("static") set_kind("object")
add_files("src/frame/*.cpp") add_files("src/frame/*.cpp")
add_includedirs("src/frame", {public = true}) add_includedirs("src/frame", {public = true})
target("fec") target("fec")
set_kind("static") set_kind("object")
add_deps("log") add_deps("log")
add_files("src/fec/*.cpp") add_files("src/fec/*.cpp")
add_includedirs("src/fec", {public = true}) add_includedirs("src/fec", {public = true})
target("rtcp") target("rtcp")
set_kind("static") set_kind("object")
add_deps("log") add_deps("log")
add_files("src/rtcp/*.cpp") add_files("src/rtcp/*.cpp")
add_includedirs("src/rtcp", {public = true}) add_includedirs("src/rtcp", {public = true})
target("rtp") target("rtp")
set_kind("static") set_kind("object")
add_deps("log", "frame", "ringbuffer", "thread", "rtcp", "fec") add_deps("log", "frame", "ringbuffer", "thread", "rtcp", "fec")
add_files("src/rtp/*.cpp") add_files("src/rtp/*.cpp")
add_includedirs("src/rtp", {public = true}) add_includedirs("src/rtp", {public = true})
target("ice") target("ice")
set_kind("static") set_kind("object")
add_deps("log", "common", "ws") add_deps("log", "common", "ws")
add_packages("asio", "nlohmann_json")
add_files("src/ice/*.cpp") add_files("src/ice/*.cpp")
add_includedirs("src/ws", "src/ice", {public = true}) add_includedirs("src/ws", "src/ice", {public = true})
if is_os("windows") then if is_os("windows") then
add_includedirs(path.join(os.getenv("VCPKG_ROOT"), "installed/x64-windows-static/include/glib-2.0"), {public = true}) add_includedirs(path.join(os.getenv("VCPKG_ROOT"),
add_includedirs(path.join(os.getenv("VCPKG_ROOT"), "installed/x64-windows-static/lib/glib-2.0/include"), {public = true}) "installed/x64-windows-static/include/glib-2.0"), {public = true})
add_links("nice", "glib-2.0", "gio-2.0", "gmodule-2.0", "gobject-2.0", add_includedirs(path.join(os.getenv("VCPKG_ROOT"),
"pcre2-8", "pcre2-16", "pcre2-32", "pcre2-posix", "installed/x64-windows-static/lib/glib-2.0/include"), {public = true})
"zlib", "ffi", "libcrypto", "libssl", "intl", "iconv", "charset", "bz2",
"Shell32", "Advapi32", "Dnsapi", "Shlwapi", "Iphlpapi")
elseif is_os("macosx") then elseif is_os("macosx") then
add_packages("glib", "libnice") add_includedirs(path.join("$(shell brew --cellar)",
add_includedirs(path.join("$(shell brew --cellar)", "glib/2.78.0/include/glib-2.0"), {public = true}) "glib/2.78.0/include/glib-2.0"), {public = true})
add_includedirs(path.join("$(shell brew --cellar)", "glib/2.78.0/lib/glib-2.0/include"), {public = true}) add_includedirs(path.join("$(shell brew --cellar)",
add_includedirs(path.join("$(shell brew --cellar)", "glib/2.78.0/lib/glib-2.0/include"), {public = true}) "glib/2.78.0/lib/glib-2.0/include"), {public = true})
add_includedirs(path.join("$(shell brew --cellar)", "glib/2.78.0/include"), {public = true}) add_includedirs(path.join("$(shell brew --cellar)",
add_includedirs(path.join("$(shell brew --cellar)", "libnice/0.1.21/include"), {public = true}) "glib/2.78.0/lib/glib-2.0/include"), {public = true})
add_linkdirs(path.join("$(shell brew --cellar)", "glib/2.78.0/lib")) add_includedirs(path.join("$(shell brew --cellar)",
add_linkdirs(path.join("$(shell brew --cellar)", "libnice/0.1.21/lib")) "glib/2.78.0/include"), {public = true})
add_links("nice", "glib-2.0", "gio-2.0", "gobject-2.0") add_includedirs(path.join("$(shell brew --cellar)",
"libnice/0.1.21/include"), {public = true})
end end
target("ws") target("ws")
set_kind("static") set_kind("object")
add_deps("log") add_deps("log")
add_files("src/ws/*.cpp") add_files("src/ws/*.cpp")
add_packages("asio")
add_includedirs("thirdparty/websocketpp/include", {public = true}) add_includedirs("thirdparty/websocketpp/include", {public = true})
target("media") target("media")
set_kind("static") set_kind("object")
add_deps("log", "frame") add_deps("log", "frame")
if is_os("windows") then if is_os("windows") then
add_packages("cuda", "vcpkg::ffmpeg", "openh264")
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",
@@ -153,10 +143,7 @@ target("media")
"src/media/video/decode/openh264", "src/media/video/decode/openh264",
"thirdparty/nvcodec/Interface", "thirdparty/nvcodec/Interface",
"thirdparty/nvcodec/Samples", {public = true}) "thirdparty/nvcodec/Samples", {public = true})
add_linkdirs("thirdparty/nvcodec/Lib/x64")
add_links("cuda", "nvencodeapi", "nvcuvid")
elseif is_os(("linux")) then elseif is_os(("linux")) then
add_packages("cuda", "ffmpeg", "openh264")
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",
@@ -175,10 +162,7 @@ target("media")
"src/media/video/decode/openh264", "src/media/video/decode/openh264",
"thirdparty/nvcodec/Interface", "thirdparty/nvcodec/Interface",
"thirdparty/nvcodec/Samples", {public = true}) "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_packages("ffmpeg")
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/ffmpeg/*.cpp", "src/media/video/encode/ffmpeg/*.cpp",
@@ -188,42 +172,65 @@ target("media")
"src/media/video/encode/ffmpeg", "src/media/video/encode/ffmpeg",
"src/media/video/decode/ffmpeg", {public = true}) "src/media/video/decode/ffmpeg", {public = true})
end end
add_packages("opus")
add_files("src/media/audio/encode/*.cpp", add_files("src/media/audio/encode/*.cpp",
"src/media/audio/decode/*.cpp") "src/media/audio/decode/*.cpp")
add_includedirs("src/media/audio/encode", add_includedirs("src/media/audio/encode",
"src/media/audio/decode", {public = true}) "src/media/audio/decode", {public = true})
target("qos") target("qos")
set_kind("static") set_kind("object")
add_deps("log") add_deps("log")
add_files("src/qos/kcp/*.c") add_files("src/qos/kcp/*.c")
add_includedirs("src/qos/kcp", {public = true}) add_includedirs("src/qos/kcp", {public = true})
target("transmission") target("transmission")
set_kind("static") set_kind("object")
add_deps("log", "ws", "ice", "qos", "rtp", "rtcp") add_deps("log", "ws", "ice", "qos", "rtp", "rtcp")
add_files("src/transmission/*.cpp") add_files("src/transmission/*.cpp")
add_packages("asio", "nlohmann_json")
add_includedirs("src/ws", "src/ice", "src/qos", {public = true}) add_includedirs("src/ws", "src/ice", "src/qos", {public = true})
target("pc") target("pc")
set_kind("static") set_kind("object")
add_deps("log") add_deps("log")
add_deps("ws", "ice", "transmission", "inih", "common", "media") add_deps("ws", "ice", "transmission", "inih", "common", "media")
add_files("src/pc/*.cpp") add_files("src/pc/*.cpp")
add_packages("asio", "nlohmann_json", "cuda")
add_includedirs("src/transmission", "src/interface", {public = true}) add_includedirs("src/transmission", "src/interface", {public = true})
target("projectx") target("projectx")
set_kind("shared") set_kind("shared")
add_deps("log") add_deps("log", "pc")
add_deps("pc")
add_installfiles("src/interface/*.h", {prefixdir = "include"})
add_files("src/rtc/*.cpp") add_files("src/rtc/*.cpp")
add_packages("asio", "nlohmann_json", "cuda")
add_includedirs("src/rtc", "src/pc", "src/interface") add_includedirs("src/rtc", "src/pc", "src/interface")
add_rules("utils.symbols.export_all", {export_classes = true})
if is_os("windows") then
add_linkdirs("thirdparty/nvcodec/Lib/x64")
add_links("nice", "glib-2.0", "gio-2.0", "gmodule-2.0", "gobject-2.0",
"pcre2-8", "pcre2-16", "pcre2-32", "pcre2-posix",
"zlib", "ffi", "libcrypto", "libssl", "intl", "iconv", "charset", "bz2",
"Shell32", "Advapi32", "Dnsapi", "Shlwapi", "Iphlpapi",
"cuda", "nvencodeapi", "nvcuvid",
"ws2_32", "Bcrypt", "windowsapp", "User32", "Strmiids", "Mfuuid",
"Secur32", "Bcrypt")
elseif is_os(("linux")) then
add_linkdirs("thirdparty/nvcodec/Lib/x64")
add_links("cuda", "nvidia-encode", "nvcuvid")
elseif is_os("macosx") then
add_linkdirs(path.join("$(shell brew --cellar)", "glib/2.78.0/lib"))
add_linkdirs(path.join("$(shell brew --cellar)", "libnice/0.1.21/lib"))
add_links("nice", "glib-2.0", "gio-2.0", "gobject-2.0")
end
add_installfiles("src/interface/*.h", {prefixdir = "include"})
add_rules("utils.symbols.export_list", {symbols = {
"CreatePeer",
"Init",
"CreateConnection",
"JoinConnection",
"LeaveConnection",
"SendData"}})
-- add_rules("utils.symbols.export_all", {export_classes = true})
-- after_install(function (target) -- after_install(function (target)
-- os.rm("$(projectdir)/out/lib/*.a") -- os.rm("$(projectdir)/out/lib/*.a")
-- os.rm("$(projectdir)/out/include/log.h") -- os.rm("$(projectdir)/out/include/log.h")
@@ -264,10 +271,10 @@ target("projectx")
-- add_files("tests/fec/simple_server.cpp") -- add_files("tests/fec/simple_server.cpp")
-- add_includedirs("tests/fec") -- add_includedirs("tests/fec")
target("opus_test") -- target("opus_test")
set_kind("binary") -- set_kind("binary")
add_packages("libopus") -- add_packages("libopus")
add_files("tests/opus/OpusEncoderImpl.cpp", -- add_files("tests/opus/OpusEncoderImpl.cpp",
"tests/opus/OpusDecoderImpl.cpp", -- "tests/opus/OpusDecoderImpl.cpp",
"tests/opus/main.cpp") -- "tests/opus/main.cpp")
add_includedirs("tests/opus") -- add_includedirs("tests/opus")