Skip to content

Commit 005820e

Browse files
committed
Merge remote-tracking branch 'origin/master' into dependency-descriptor
2 parents 518c0ec + 9d5c46b commit 005820e

27 files changed

+396
-165
lines changed

CMakeLists.txt

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.7)
22
project(libdatachannel
3-
VERSION 0.20.2
3+
VERSION 0.21.0
44
LANGUAGES CXX)
55
set(PROJECT_DESCRIPTION "C/C++ WebRTC network library featuring Data Channels, Media Transport, and WebSockets")
66

@@ -88,6 +88,7 @@ set(LIBDATACHANNEL_SOURCES
8888
${CMAKE_CURRENT_SOURCE_DIR}/src/rtp.cpp
8989
${CMAKE_CURRENT_SOURCE_DIR}/src/capi.cpp
9090
${CMAKE_CURRENT_SOURCE_DIR}/src/plihandler.cpp
91+
${CMAKE_CURRENT_SOURCE_DIR}/src/pacinghandler.cpp
9192
)
9293

9394
set(LIBDATACHANNEL_HEADERS
@@ -125,6 +126,7 @@ set(LIBDATACHANNEL_HEADERS
125126
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtcpnackresponder.hpp
126127
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/utils.hpp
127128
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/plihandler.hpp
129+
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/pacinghandler.hpp
128130
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/version.h
129131
)
130132

@@ -344,7 +346,9 @@ else()
344346
target_link_libraries(datachannel PRIVATE libSRTP::srtp2)
345347
target_link_libraries(datachannel-static PRIVATE libSRTP::srtp2)
346348
else()
347-
add_subdirectory(deps/libsrtp EXCLUDE_FROM_ALL)
349+
if(NOT TARGET srtp2)
350+
add_subdirectory(deps/libsrtp EXCLUDE_FROM_ALL)
351+
endif()
348352
target_compile_definitions(datachannel PRIVATE RTC_SYSTEM_SRTP=0)
349353
target_compile_definitions(datachannel-static PRIVATE RTC_SYSTEM_SRTP=0)
350354
target_link_libraries(datachannel PRIVATE srtp2)
@@ -373,7 +377,9 @@ if (USE_GNUTLS)
373377
target_link_libraries(datachannel-static PRIVATE Nettle::Nettle)
374378
endif()
375379
elseif(USE_MBEDTLS)
376-
find_package(MbedTLS 3 REQUIRED)
380+
if(NOT TARGET MbedTLS::MbedTLS)
381+
find_package(MbedTLS 3 REQUIRED)
382+
endif()
377383
target_compile_definitions(datachannel PRIVATE USE_MBEDTLS=1)
378384
target_compile_definitions(datachannel-static PRIVATE USE_MBEDTLS=1)
379385
target_link_libraries(datachannel PRIVATE MbedTLS::MbedTLS)

examples/streamer/h264fileparser.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "rtc/rtc.hpp"
1212

1313
#include <fstream>
14+
#include <cstring>
1415

1516
#ifdef _WIN32
1617
#include <winsock2.h>
@@ -29,7 +30,9 @@ void H264FileParser::loadNextSample() {
2930
while (i < sample.size()) {
3031
assert(i + 4 < sample.size());
3132
auto lengthPtr = (uint32_t *) (sample.data() + i);
32-
uint32_t length = ntohl(*lengthPtr);
33+
uint32_t length;
34+
std::memcpy(&length, lengthPtr, sizeof(uint32_t));
35+
length = ntohl(length);
3336
auto naluStartIndex = i + 4;
3437
auto naluEndIndex = naluStartIndex + length;
3538
assert(naluEndIndex <= sample.size());
@@ -50,8 +53,8 @@ void H264FileParser::loadNextSample() {
5053
}
5154
}
5255

53-
vector<byte> H264FileParser::initialNALUS() {
54-
vector<byte> units{};
56+
vector<std::byte> H264FileParser::initialNALUS() {
57+
vector<std::byte> units{};
5558
if (previousUnitType7.has_value()) {
5659
auto nalu = previousUnitType7.value();
5760
units.insert(units.end(), nalu.begin(), nalu.end());

include/rtc/configuration.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct RTC_CPP_EXPORT Configuration {
7575
bool enableIceTcp = false; // libnice only
7676
bool enableIceUdpMux = false; // libjuice only
7777
bool disableAutoNegotiation = false;
78+
bool disableAutoGathering = false;
7879
bool forceMediaTransport = false;
7980

8081
// Port range

include/rtc/frameinfo.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
namespace rtc {
1515

1616
struct RTC_CPP_EXPORT FrameInfo {
17-
FrameInfo(uint32_t timestamp) : timestamp(timestamp){};
17+
FrameInfo(uint8_t payloadType, uint32_t timestamp) : payloadType(payloadType), timestamp(timestamp){};
18+
uint8_t payloadType; // Indicates codec of the frame
1819
uint32_t timestamp = 0; // RTP Timestamp
1920
};
2021

include/rtc/h264rtpdepacketizer.hpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "common.hpp"
1616
#include "mediahandler.hpp"
1717
#include "message.hpp"
18+
#include "nalunit.hpp"
1819
#include "rtp.hpp"
1920

2021
#include <iterator>
@@ -24,16 +25,20 @@ namespace rtc {
2425
/// RTP depacketization for H264
2526
class RTC_CPP_EXPORT H264RtpDepacketizer : public MediaHandler {
2627
public:
27-
H264RtpDepacketizer() = default;
28+
using Separator = NalUnit::Separator;
29+
30+
H264RtpDepacketizer(Separator separator = Separator::LongStartSequence);
2831
virtual ~H264RtpDepacketizer() = default;
2932

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

3235
private:
3336
std::vector<message_ptr> mRtpBuffer;
37+
const NalUnit::Separator mSeparator;
3438

39+
void addSeparator(binary &accessUnit);
3540
message_vector buildFrames(message_vector::iterator firstPkt, message_vector::iterator lastPkt,
36-
uint32_t timestamp);
41+
uint8_t payloadType, uint32_t timestamp);
3742
};
3843

3944
} // namespace rtc

include/rtc/pacinghandler.hpp

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright (c) 2024 Sean DuBois <sean@siobud.com>
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*/
8+
9+
#ifndef RTC_PACING_HANDLER_H
10+
#define RTC_PACING_HANDLER_H
11+
12+
#if RTC_ENABLE_MEDIA
13+
14+
#include "mediahandler.hpp"
15+
#include "utils.hpp"
16+
17+
#include <atomic>
18+
#include <queue>
19+
20+
namespace rtc {
21+
22+
// Paced sending of RTP packets. It takes a stream of RTP packets that can have an uneven bitrate
23+
// and delivers them in a smoother manner by sending a fixed size of them on an interval
24+
class RTC_CPP_EXPORT PacingHandler : public MediaHandler {
25+
public:
26+
PacingHandler(double bitsPerSecond, std::chrono::milliseconds sendInterval);
27+
28+
void outgoing(message_vector &messages, const message_callback &send) override;
29+
30+
private:
31+
std::atomic<bool> mHaveScheduled = false;
32+
33+
double mBytesPerSecond;
34+
double mBudget;
35+
36+
std::chrono::milliseconds mSendInterval;
37+
std::chrono::time_point<std::chrono::high_resolution_clock> mLastRun;
38+
39+
std::mutex mMutex;
40+
std::queue<message_ptr> mRtpBuffer;
41+
42+
void schedule(const message_callback &send);
43+
};
44+
45+
} // namespace rtc
46+
47+
#endif // RTC_ENABLE_MEDIA
48+
49+
#endif // RTC_PACING_HANDLER_H

include/rtc/peerconnection.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class RTC_CPP_EXPORT PeerConnection final : CheshireCat<impl::PeerConnection> {
9393
void setLocalDescription(Description::Type type = Description::Type::Unspec);
9494
void setRemoteDescription(Description description);
9595
void addRemoteCandidate(Candidate candidate);
96+
void gatherLocalCandidates(std::vector<IceServer> additionalIceServers = {});
9697

9798
void setMediaHandler(shared_ptr<MediaHandler> handler);
9899
shared_ptr<MediaHandler> getMediaHandler();

include/rtc/rtc.h

+3
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ typedef struct {
341341
// AV1 only
342342
rtcObuPacketization obuPacketization; // OBU paketization for AV1 samples
343343

344+
uint8_t playoutDelayId;
345+
uint16_t playoutDelayMin;
346+
uint16_t playoutDelayMax;
344347
} rtcPacketizerInit;
345348

346349
// Deprecated, do not use

include/rtc/rtc.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "h265rtppacketizer.hpp"
3636
#include "mediahandler.hpp"
3737
#include "plihandler.hpp"
38+
#include "pacinghandler.hpp"
3839
#include "rtcpnackresponder.hpp"
3940
#include "rtcpreceivingsession.hpp"
4041
#include "rtcpsrreporter.hpp"

include/rtc/rtp.hpp

-19
Original file line numberDiff line numberDiff line change
@@ -358,25 +358,6 @@ struct RTC_CPP_EXPORT RtpRtx {
358358
size_t copyTo(RtpHeader *dest, size_t totalSize, uint8_t originalPayloadType);
359359
};
360360

361-
// For backward compatibility, do not use
362-
using RTP_ExtensionHeader [[deprecated]] = RtpExtensionHeader;
363-
using RTP [[deprecated]] = RtpHeader;
364-
using RTCP_ReportBlock [[deprecated]] = RtcpReportBlock;
365-
using RTCP_HEADER [[deprecated]] = RtcpHeader;
366-
using RTCP_FB_HEADER [[deprecated]] = RtcpFbHeader;
367-
using RTCP_SR [[deprecated]] = RtcpSr;
368-
using RTCP_SDES_ITEM [[deprecated]] = RtcpSdesItem;
369-
using RTCP_SDES_CHUNK [[deprecated]] = RtcpSdesChunk;
370-
using RTCP_SDES [[deprecated]] = RtcpSdes;
371-
using RTCP_RR [[deprecated]] = RtcpRr;
372-
using RTCP_REMB [[deprecated]] = RtcpRemb;
373-
using RTCP_PLI [[deprecated]] = RtcpPli;
374-
using RTCP_FIR_PART [[deprecated]] = RtcpFirPart;
375-
using RTCP_FIR [[deprecated]] = RtcpFir;
376-
using RTCP_NACK_PART [[deprecated]] = RtcpNackPart;
377-
using RTCP_NACK [[deprecated]] = RtcpNack;
378-
using RTP_RTX [[deprecated]] = RtpRtx;
379-
380361
#pragma pack(pop)
381362

382363
} // namespace rtc

include/rtc/rtppacketizationconfig.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ class RTC_CPP_EXPORT RtpPacketizationConfig {
6969
std::bitset<32> activeChains;
7070
FrameDependencyStructure structure;
7171
};
72+
7273
optional<DependencyDescriptorContext> dependencyDescriptorContext;
74+
// the negotiated ID of the playout delay header extension
75+
// https://webrtc.googlesource.com/src/+/main/docs/native-code/rtp-hdrext/playout-delay/README.md
76+
uint8_t playoutDelayId;
77+
78+
// Minimum/maxiumum playout delay, in 10ms intervals. A value of 10 would equal a 100ms delay
79+
uint16_t playoutDelayMin;
80+
uint16_t playoutDelayMax;
7381

7482
/// Construct RTP configuration used in packetization process
7583
/// @param ssrc SSRC of source

include/rtc/version.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#define RTC_VERSION_H
33

44
#define RTC_VERSION_MAJOR 0
5-
#define RTC_VERSION_MINOR 20
6-
#define RTC_VERSION_PATCH 2
7-
#define RTC_VERSION "0.20.2"
5+
#define RTC_VERSION_MINOR 21
6+
#define RTC_VERSION_PATCH 0
7+
#define RTC_VERSION "0.21.0"
88

99
#endif

src/capi.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ createRtpPacketizationConfig(const rtcPacketizationHandlerInit *init) {
275275
init->payloadType, init->clockRate);
276276
config->sequenceNumber = init->sequenceNumber;
277277
config->timestamp = init->timestamp;
278+
config->playoutDelayId = init->playoutDelayId;
279+
config->playoutDelayMin = init->playoutDelayMin;
280+
config->playoutDelayMax = init->playoutDelayMax;
278281
return config;
279282
}
280283

0 commit comments

Comments
 (0)