Skip to content

Commit

Permalink
Merge branch 'paullouisageneau:master' into examples/signaling-server…
Browse files Browse the repository at this point in the history
…-libdatachannel-ws
  • Loading branch information
Tim-S authored Nov 13, 2024
2 parents 8e3ba51 + 770d074 commit 52f3429
Show file tree
Hide file tree
Showing 39 changed files with 785 additions and 183 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build-nomedia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ jobs:
set CL=/MP
nmake
- name: test
run: build/tests.exe
run: |
cd build
./tests
6 changes: 4 additions & 2 deletions .github/workflows/build-openssl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: install packages
run: HOMEBREW_NO_INSTALL_CLEANUP=1 brew reinstall openssl@1.1
run: HOMEBREW_NO_INSTALL_CLEANUP=1 brew reinstall openssl@3
- name: submodules
run: git submodule update --init --recursive --depth 1
- name: cmake
Expand Down Expand Up @@ -52,5 +52,7 @@ jobs:
set CL=/MP
nmake
- name: test
run: build/tests.exe
run: |
cd build
./tests
2 changes: 1 addition & 1 deletion .github/workflows/check-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: submodules
run: git submodule update --init --recursive --depth 1
- name: cmake
run: cmake -B build -DUSE_GNUTLS=0 -DUSE_SYSTEM_SRTP=1 -DWARNINGS_AS_ERRORS=1
run: cmake -B build -DUSE_GNUTLS=0 -DUSE_SYSTEM_SRTP=1 -DWARNINGS_AS_ERRORS=1 -DRTC_UPDATE_VERSION_HEADER=1
- name: check diff
run: |
if ! git diff --exit-code
Expand Down
2 changes: 1 addition & 1 deletion BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ $ make -j2
### Microsoft Windows with Microsoft Visual C++

```bash
$ cmake -B build -G "NMake Makefiles"
$ cmake -B build -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release
$ cd build
$ nmake
```
Expand Down
138 changes: 91 additions & 47 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
cmake_minimum_required(VERSION 3.7)
cmake_minimum_required(VERSION 3.13)
project(libdatachannel
VERSION 0.21.1
VERSION 0.22.2
LANGUAGES CXX)
set(PROJECT_DESCRIPTION "C/C++ WebRTC network library featuring Data Channels, Media Transport, and WebSockets")

include(GNUInstallDirs)

# Options
option(BUILD_SHARED_LIBS "Build shared library" ON)
option(BUILD_SHARED_DEPS_LIBS "Build submodules as shared libraries" OFF)
option(USE_GNUTLS "Use GnuTLS instead of OpenSSL" OFF)
option(USE_MBEDTLS "Use Mbed TLS instead of OpenSSL" OFF)
option(USE_NICE "Use libnice instead of libjuice" OFF)
option(PREFER_SYSTEM_LIB "Prefer system libraries over deps folder" OFF)
option(PREFER_SYSTEM_LIB "Prefer system libraries over submodules" OFF)
option(USE_SYSTEM_SRTP "Use system libSRTP" ${PREFER_SYSTEM_LIB})
option(USE_SYSTEM_JUICE "Use system libjuice" ${PREFER_SYSTEM_LIB})
option(USE_SYSTEM_USRSCTP "Use system libusrsctp" ${PREFER_SYSTEM_LIB})
Expand All @@ -23,6 +25,7 @@ option(NO_TESTS "Disable tests build" OFF)
option(WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
option(CAPI_STDCALL "Set calling convention of C API callbacks stdcall" OFF)
option(SCTP_DEBUG "Enable SCTP debugging output to verbose log" OFF)
option(RTC_UPDATE_VERSION_HEADER "Enable updating the version header" OFF)

if (USE_GNUTLS AND USE_MBEDTLS)
message(FATAL_ERROR "Both USE_MBEDTLS and USE_GNUTLS cannot be enabled at the same time")
Expand All @@ -48,7 +51,6 @@ endif()

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(BUILD_SHARED_LIBS OFF) # to force usrsctp to be built static

if(WIN32)
add_definitions(-DWIN32_LEAN_AND_MEAN)
Expand Down Expand Up @@ -80,13 +82,15 @@ set(LIBDATACHANNEL_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/h264rtpdepacketizer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/nalunit.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/h265rtppacketizer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/h265rtpdepacketizer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/h265nalunit.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/av1rtppacketizer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/rtcpnackresponder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/rtp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/capi.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/plihandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pacinghandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/rembhandler.cpp
)

set(LIBDATACHANNEL_HEADERS
Expand Down Expand Up @@ -117,12 +121,14 @@ set(LIBDATACHANNEL_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/h264rtpdepacketizer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/nalunit.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/h265rtppacketizer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/h265rtpdepacketizer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/h265nalunit.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/av1rtppacketizer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtcpnackresponder.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/utils.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/plihandler.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/pacinghandler.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rembhandler.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/version.h
)

Expand Down Expand Up @@ -227,6 +233,52 @@ set(BENCHMARK_UWP_RESOURCES
${CMAKE_CURRENT_SOURCE_DIR}/test/uwp/benchmark/Windows_TemporaryKey.pfx
)

if(RTC_UPDATE_VERSION_HEADER)
configure_file (
${PROJECT_SOURCE_DIR}/cmake/version.h.in
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/version.h
)
endif()

add_library(datachannel
${LIBDATACHANNEL_SOURCES}
${LIBDATACHANNEL_HEADERS}
${LIBDATACHANNEL_IMPL_SOURCES}
${LIBDATACHANNEL_IMPL_HEADERS})
set_target_properties(datachannel PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
CXX_STANDARD 17
CXX_VISIBILITY_PRESET default)
if(APPLE)
set_target_properties(datachannel PROPERTIES
VERSION ${PROJECT_VERSION_MAJOR}
SOVERSION ${PROJECT_VERSION_MAJOR})
endif()

add_library(datachannel-static STATIC EXCLUDE_FROM_ALL
${LIBDATACHANNEL_SOURCES}
${LIBDATACHANNEL_HEADERS}
${LIBDATACHANNEL_IMPL_SOURCES}
${LIBDATACHANNEL_IMPL_HEADERS})
set_target_properties(datachannel-static PROPERTIES
VERSION ${PROJECT_VERSION}
CXX_STANDARD 17)

target_compile_definitions(datachannel PRIVATE RTC_EXPORTS)
if (NOT BUILD_SHARED_LIBS)
target_compile_definitions(datachannel PUBLIC RTC_STATIC)
endif()
target_compile_definitions(datachannel-static PRIVATE RTC_EXPORTS)
target_compile_definitions(datachannel-static PUBLIC RTC_STATIC)

if(BUILD_SHARED_LIBS AND NOT BUILD_SHARED_DEPS_LIBS)
set(BUILD_SHARED_LIBS OFF)
set(INSTALL_DEPS_LIBS OFF)
else()
set(INSTALL_DEPS_LIBS ON)
endif()

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
Expand Down Expand Up @@ -256,58 +308,44 @@ else()
target_compile_definitions(usrsctp PUBLIC -DSCTP_STDINT_INCLUDE=<stdint.h>)
endif()
add_library(Usrsctp::Usrsctp ALIAS usrsctp)
endif()

configure_file (
${PROJECT_SOURCE_DIR}/cmake/version.h.in
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/version.h
)

add_library(datachannel SHARED
${LIBDATACHANNEL_SOURCES}
${LIBDATACHANNEL_HEADERS}
${LIBDATACHANNEL_IMPL_SOURCES}
${LIBDATACHANNEL_IMPL_HEADERS})
set_target_properties(datachannel PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
CXX_STANDARD 17
CXX_VISIBILITY_PRESET default)

if(APPLE)
set_target_properties(datachannel PROPERTIES
VERSION ${PROJECT_VERSION_MAJOR}
SOVERSION ${PROJECT_VERSION_MAJOR})
if(INSTALL_DEPS_LIBS)
# usrsctp lacks an export set
install(TARGETS usrsctp EXPORT UsrsctpTargets)
install(EXPORT UsrsctpTargets
FILE UsrsctpTargets.cmake
NAMESPACE Usrsctp::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/usrsctp
EXCLUDE_FROM_ALL)
# Fix directories
set_target_properties(usrsctp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "")
target_include_directories(usrsctp INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/usrsctp/usrsctplib>
$<INSTALL_INTERFACE:>)
endif()
endif()

target_compile_definitions(datachannel PRIVATE RTC_EXPORTS)

add_library(datachannel-static STATIC EXCLUDE_FROM_ALL
${LIBDATACHANNEL_SOURCES}
${LIBDATACHANNEL_HEADERS}
${LIBDATACHANNEL_IMPL_SOURCES}
${LIBDATACHANNEL_IMPL_HEADERS})
set_target_properties(datachannel-static PROPERTIES
VERSION ${PROJECT_VERSION}
CXX_STANDARD 17)
target_compile_definitions(datachannel-static PRIVATE RTC_EXPORTS)
target_compile_definitions(datachannel-static PUBLIC RTC_STATIC)

target_include_directories(datachannel PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_include_directories(datachannel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc)
target_include_directories(datachannel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(datachannel PRIVATE Threads::Threads)
target_link_libraries(datachannel PRIVATE Usrsctp::Usrsctp plog::plog)
target_include_directories(datachannel PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc
${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(datachannel PRIVATE
Threads::Threads
Usrsctp::Usrsctp
$<BUILD_INTERFACE:plog::plog>)

target_include_directories(datachannel-static PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_include_directories(datachannel-static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc)
target_include_directories(datachannel-static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(datachannel-static PRIVATE Threads::Threads)
target_link_libraries(datachannel-static PRIVATE Usrsctp::Usrsctp plog::plog)
target_include_directories(datachannel-static PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc
${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(datachannel-static PRIVATE
Threads::Threads
Usrsctp::Usrsctp
$<BUILD_INTERFACE:plog::plog>)

if(WIN32)
target_link_libraries(datachannel PUBLIC ws2_32) # winsock2
Expand Down Expand Up @@ -344,6 +382,9 @@ else()
else()
if(NOT TARGET srtp2)
add_subdirectory(deps/libsrtp EXCLUDE_FROM_ALL)
if(INSTALL_DEPS_LIBS)
install(TARGETS srtp2)
endif()
endif()
target_compile_definitions(datachannel PRIVATE RTC_SYSTEM_SRTP=0)
target_compile_definitions(datachannel-static PRIVATE RTC_SYSTEM_SRTP=0)
Expand Down Expand Up @@ -421,9 +462,12 @@ else()
target_link_libraries(datachannel-static PRIVATE LibJuice::LibJuice)
else()
add_subdirectory(deps/libjuice EXCLUDE_FROM_ALL)
if(INSTALL_DEPS_LIBS)
install(TARGETS juice)
endif()
target_compile_definitions(datachannel PRIVATE RTC_SYSTEM_JUICE=0)
target_compile_definitions(datachannel-static PRIVATE RTC_SYSTEM_JUICE=0)
target_link_libraries(datachannel PRIVATE LibJuice::LibJuiceStatic)
target_link_libraries(datachannel PRIVATE LibJuice::LibJuice)
target_link_libraries(datachannel-static PRIVATE LibJuice::LibJuiceStatic)
endif()
endif()
Expand Down
12 changes: 12 additions & 0 deletions DOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,18 @@ Return value: the maximun length of strings copied in buffers (including the ter

If `local`, `remote`, or both, are `NULL`, the corresponding candidate is not copied, but the maximum length is still returned.

#### rtcIsNegotiationNeeded
```
bool rtcIsNegotiationNeeded(int pc);
```

Return true if negotiation needs to be started or restarted, for instance to signal new tracks. If so, the user may call `rtcSetLocalDescription()` to start it.

Arguments:
- `pc`: the Peer Connection identifier

Return value: true if negotiation is needed

#### rtcGetMaxDataChannelStream
```
int rtcGetMaxDataChannelStream(int pc);
Expand Down
4 changes: 2 additions & 2 deletions Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ rule make_libusrsctp ( targets * : sources * : properties * )
}
actions make_libusrsctp
{
(cd $(CWD)/deps/usrsctp && mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=$(VARIANT) -DCMAKE_C_FLAGS="-fPIC -Wno-unknown-warning-option -Wno-format-truncation" -Dsctp_build_shared_lib=0 -Dsctp_build_programs=0 -Dsctp_inet=0 -Dsctp_inet6=0 .. && make -j2 usrsctp)
(cd $(CWD)/deps/usrsctp && mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=$(VARIANT) -DCMAKE_C_FLAGS="-fPIC" -Dsctp_werror=0 -Dsctp_build_shared_lib=0 -Dsctp_build_programs=0 -Dsctp_inet=0 -Dsctp_inet6=0 .. && make -j2 usrsctp)
cp $(CWD)/deps/usrsctp/$(BUILD_DIR)/usrsctplib/libusrsctp.a $(<)
}
rule make_libusrsctp_msvc ( targets * : sources * : properties * )
Expand All @@ -118,7 +118,7 @@ actions make_libusrsctp_msvc
cd $(CWD)/deps/usrsctp
mkdir $(BUILD_DIR)
cd $(BUILD_DIR)
cmake -G "Visual Studio 16 2019" -Dsctp_build_shared_lib=0 -Dsctp_build_programs=0 ..
cmake -G "Visual Studio 16 2019" -Dsctp_werror=0 -Dsctp_build_shared_lib=0 -Dsctp_build_programs=0 -Dsctp_inet=0 -Dsctp_inet6=0 ..
msbuild usrsctplib.sln /property:Configuration=$(VARIANT)
cd %OLDD%
cp $(CWD)/deps/usrsctp/$(BUILD_DIR)/usrsctplib/Release/usrsctp.lib $(<)
Expand Down
2 changes: 1 addition & 1 deletion deps/libjuice
6 changes: 3 additions & 3 deletions include/rtc/description.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ class RTC_CPP_EXPORT Description {
int addAudio(string mid = "audio", Direction dir = Direction::SendOnly);
void clearMedia();

variant<Media *, Application *> media(unsigned int index);
variant<const Media *, const Application *> media(unsigned int index) const;
unsigned int mediaCount() const;
variant<Media *, Application *> media(int index);
variant<const Media *, const Application *> media(int index) const;
int mediaCount() const;

const Application *application() const;
Application *application();
Expand Down
49 changes: 49 additions & 0 deletions include/rtc/h265rtpdepacketizer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright (c) 2020 Staz Modrzynski
* Copyright (c) 2020-2024 Paul-Louis Ageneau
* Copyright (c) 2024 Robert Edmonds
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#ifndef RTC_H265_RTP_DEPACKETIZER_H
#define RTC_H265_RTP_DEPACKETIZER_H

#if RTC_ENABLE_MEDIA

#include "common.hpp"
#include "h265nalunit.hpp"
#include "mediahandler.hpp"
#include "message.hpp"
#include "rtp.hpp"

#include <iterator>

namespace rtc {

/// RTP depacketization for H265
class RTC_CPP_EXPORT H265RtpDepacketizer : public MediaHandler {
public:
using Separator = NalUnit::Separator;

H265RtpDepacketizer(Separator separator = Separator::LongStartSequence);
virtual ~H265RtpDepacketizer() = default;

void incoming(message_vector &messages, const message_callback &send) override;

private:
std::vector<message_ptr> mRtpBuffer;
const NalUnit::Separator separator;

void addSeparator(binary& accessUnit);
message_vector buildFrames(message_vector::iterator firstPkt, message_vector::iterator lastPkt,
uint8_t payloadType, uint32_t timestamp);
};

} // namespace rtc

#endif // RTC_ENABLE_MEDIA

#endif // RTC_H265_RTP_DEPACKETIZER_H
Loading

0 comments on commit 52f3429

Please sign in to comment.