From 8ffdf6a020fa6840ad3f7c94c796e2f9008bfaa1 Mon Sep 17 00:00:00 2001 From: Paul-Louis Ageneau Date: Sat, 21 Mar 2020 17:00:36 +0100 Subject: [PATCH] Added RTC_ENABLE_MEDIA guard --- CMakeLists.txt | 35 +++++++++++++++++++++++++++-------- Jamfile | 1 + Makefile | 8 ++++++++ include/rtc/include.hpp | 4 ++++ include/rtc/rtc.h | 4 ++++ src/dtlssrtptransport.cpp | 6 ++++-- src/dtlssrtptransport.hpp | 4 ++++ src/tcptransport.cpp | 4 ++-- src/tcptransport.hpp | 4 ++-- src/tlstransport.cpp | 4 ++-- src/tlstransport.hpp | 5 ++--- src/wstransport.cpp | 5 ++--- src/wstransport.hpp | 4 ++-- 13 files changed, 64 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e223db..7fdefcb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ set(LIBDATACHANNEL_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/configuration.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/datachannel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/description.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/dtlssrtptransport.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/dtlstransport.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/icetransport.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/init.cpp @@ -81,6 +82,7 @@ set(TESTS_ANSWERER_SOURCES set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) +find_package(SRTP) add_subdirectory(deps/usrsctp EXCLUDE_FROM_ALL) if (MSYS OR MINGW) @@ -137,39 +139,56 @@ if(WIN32) target_link_libraries(datachannel-static "wsock32" "ws2_32") # winsock2 endif() +if(SRTP_FOUND) + if(NOT TARGET SRTP::SRTP) + add_library(SRTP::SRTP UNKNOWN IMPORTED) + set_target_properties(SRTP::SRTP PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${SRTP_INCLUDE_DIRS} + IMPORTED_LINK_INTERFACE_LANGUAGES C + IMPORTED_LOCATION ${SRTP_LIBRARIES}) + endif() + target_compile_definitions(datachannel PUBLIC RTC_ENABLE_MEDIA=1) + target_compile_definitions(datachannel-static PUBLIC RTC_ENABLE_MEDIA=1) + target_link_libraries(datachannel SRTP::SRTP) + target_link_libraries(datachannel-static SRTP::SRTP) +else() + target_compile_definitions(datachannel PUBLIC RTC_ENABLE_MEDIA=0) + target_compile_definitions(datachannel-static PUBLIC RTC_ENABLE_MEDIA=0) +endif() + if (USE_GNUTLS) find_package(GnuTLS REQUIRED) if(NOT TARGET GnuTLS::GnuTLS) add_library(GnuTLS::GnuTLS UNKNOWN IMPORTED) set_target_properties(GnuTLS::GnuTLS PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${GNUTLS_INCLUDE_DIRS}" - INTERFACE_COMPILE_DEFINITIONS "${GNUTLS_DEFINITIONS}" - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${GNUTLS_LIBRARIES}") + INTERFACE_INCLUDE_DIRECTORIES ${GNUTLS_INCLUDE_DIRS} + INTERFACE_COMPILE_DEFINITIONS ${GNUTLS_DEFINITIONS} + IMPORTED_LINK_INTERFACE_LANGUAGES C + IMPORTED_LOCATION ${GNUTLS_LIBRARIES}) endif() target_compile_definitions(datachannel PRIVATE USE_GNUTLS=1) - target_link_libraries(datachannel GnuTLS::GnuTLS) target_compile_definitions(datachannel-static PRIVATE USE_GNUTLS=1) + target_link_libraries(datachannel GnuTLS::GnuTLS) target_link_libraries(datachannel-static GnuTLS::GnuTLS) else() find_package(OpenSSL REQUIRED) target_compile_definitions(datachannel PRIVATE USE_GNUTLS=0) - target_link_libraries(datachannel OpenSSL::SSL) target_compile_definitions(datachannel-static PRIVATE USE_GNUTLS=0) + target_link_libraries(datachannel OpenSSL::SSL) target_link_libraries(datachannel-static OpenSSL::SSL) endif() if (USE_JUICE) add_subdirectory(deps/libjuice EXCLUDE_FROM_ALL) target_compile_definitions(datachannel PRIVATE USE_JUICE=1) - target_link_libraries(datachannel LibJuice::LibJuiceStatic) target_compile_definitions(datachannel-static PRIVATE USE_JUICE=1) + target_link_libraries(datachannel LibJuice::LibJuiceStatic) target_link_libraries(datachannel-static LibJuice::LibJuiceStatic) else() find_package(LibNice REQUIRED) target_compile_definitions(datachannel PRIVATE USE_JUICE=0) - target_link_libraries(datachannel LibNice::LibNice) target_compile_definitions(datachannel-static PRIVATE USE_JUICE=0) + target_link_libraries(datachannel LibNice::LibNice) target_link_libraries(datachannel-static LibNice::LibNice) endif() diff --git a/Jamfile b/Jamfile index 6b905b1..7d6b81d 100644 --- a/Jamfile +++ b/Jamfile @@ -10,6 +10,7 @@ lib libdatachannel 17 ./include/rtc USE_JUICE=1 + RTC_ENABLE_MEDIA=0 RTC_ENABLE_WEBSOCKET=0 /libdatachannel//usrsctp /libdatachannel//juice diff --git a/Makefile b/Makefile index c0a83e9..6cc3cc8 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,14 @@ else LIBS+=glib-2.0 gobject-2.0 nice endif +RTC_ENABLE_MEDIA ?= 0 +ifneq ($(RTC_ENABLE_MEDIA), 0) + CPPFLAGS+=-DRTC_ENABLE_MEDIA=1 + LIBS+=srtp +else + CPPFLAGS+=-DRTC_ENABLE_MEDIA=0 +endif + RTC_ENABLE_WEBSOCKET ?= 1 ifneq ($(RTC_ENABLE_WEBSOCKET), 0) CPPFLAGS+=-DRTC_ENABLE_WEBSOCKET=1 diff --git a/include/rtc/include.hpp b/include/rtc/include.hpp index d588ae7..df690dc 100644 --- a/include/rtc/include.hpp +++ b/include/rtc/include.hpp @@ -19,6 +19,10 @@ #ifndef RTC_INCLUDE_H #define RTC_INCLUDE_H +#ifndef RTC_ENABLE_MEDIA +#define RTC_ENABLE_MEDIA 1 +#endif + #ifndef RTC_ENABLE_WEBSOCKET #define RTC_ENABLE_WEBSOCKET 1 #endif diff --git a/include/rtc/rtc.h b/include/rtc/rtc.h index 833ee08..21d4f90 100644 --- a/include/rtc/rtc.h +++ b/include/rtc/rtc.h @@ -27,6 +27,10 @@ extern "C" { // libdatachannel C API +#ifndef RTC_ENABLE_MEDIA +#define RTC_ENABLE_MEDIA 1 +#endif + #ifndef RTC_ENABLE_WEBSOCKET #define RTC_ENABLE_WEBSOCKET 1 #endif diff --git a/src/dtlssrtptransport.cpp b/src/dtlssrtptransport.cpp index 1d14fb8..2f79f5c 100644 --- a/src/dtlssrtptransport.cpp +++ b/src/dtlssrtptransport.cpp @@ -19,11 +19,11 @@ #include "dtlssrtptransport.hpp" #include "tls.hpp" +#if RTC_ENABLE_MEDIA + #include #include -#include - using std::shared_ptr; using std::to_string; @@ -180,3 +180,5 @@ void DtlsSrtpTransport::postHandshake() { } } // namespace rtc + +#endif diff --git a/src/dtlssrtptransport.hpp b/src/dtlssrtptransport.hpp index c9bb131..92e9091 100644 --- a/src/dtlssrtptransport.hpp +++ b/src/dtlssrtptransport.hpp @@ -22,6 +22,8 @@ #include "dtlstransport.hpp" #include "include.hpp" +#if RTC_ENABLE_MEDIA + #include namespace rtc { @@ -50,3 +52,5 @@ private: } // namespace rtc #endif + +#endif diff --git a/src/tcptransport.cpp b/src/tcptransport.cpp index cc6defc..5dd166b 100644 --- a/src/tcptransport.cpp +++ b/src/tcptransport.cpp @@ -16,10 +16,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#if RTC_ENABLE_WEBSOCKET - #include "tcptransport.hpp" +#if RTC_ENABLE_WEBSOCKET + #include #ifndef _WIN32 #include diff --git a/src/tcptransport.hpp b/src/tcptransport.hpp index 565916a..6549f81 100644 --- a/src/tcptransport.hpp +++ b/src/tcptransport.hpp @@ -19,12 +19,12 @@ #ifndef RTC_TCP_TRANSPORT_H #define RTC_TCP_TRANSPORT_H -#if RTC_ENABLE_WEBSOCKET - #include "include.hpp" #include "queue.hpp" #include "transport.hpp" +#if RTC_ENABLE_WEBSOCKET + #include #include diff --git a/src/tlstransport.cpp b/src/tlstransport.cpp index a385f78..213bc10 100644 --- a/src/tlstransport.cpp +++ b/src/tlstransport.cpp @@ -16,11 +16,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#if RTC_ENABLE_WEBSOCKET - #include "tlstransport.hpp" #include "tcptransport.hpp" +#if RTC_ENABLE_WEBSOCKET + #include #include #include diff --git a/src/tlstransport.hpp b/src/tlstransport.hpp index 2d2227f..36be96c 100644 --- a/src/tlstransport.hpp +++ b/src/tlstransport.hpp @@ -19,14 +19,13 @@ #ifndef RTC_TLS_TRANSPORT_H #define RTC_TLS_TRANSPORT_H -#if RTC_ENABLE_WEBSOCKET - #include "include.hpp" #include "queue.hpp" #include "tls.hpp" #include "transport.hpp" -#include +#if RTC_ENABLE_WEBSOCKET + #include #include diff --git a/src/wstransport.cpp b/src/wstransport.cpp index 74fb90b..6b1b084 100644 --- a/src/wstransport.cpp +++ b/src/wstransport.cpp @@ -16,14 +16,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#if RTC_ENABLE_WEBSOCKET - #include "wstransport.hpp" #include "tcptransport.hpp" #include "tlstransport.hpp" - #include "base64.hpp" +#if RTC_ENABLE_WEBSOCKET + #include #include #include diff --git a/src/wstransport.hpp b/src/wstransport.hpp index 5397a28..c04fb98 100644 --- a/src/wstransport.hpp +++ b/src/wstransport.hpp @@ -19,11 +19,11 @@ #ifndef RTC_WS_TRANSPORT_H #define RTC_WS_TRANSPORT_H -#if RTC_ENABLE_WEBSOCKET - #include "include.hpp" #include "transport.hpp" +#if RTC_ENABLE_WEBSOCKET + namespace rtc { class TcpTransport;