Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dependency-descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed Apr 27, 2024
2 parents 518c0ec + 9d5c46b commit 005820e
Show file tree
Hide file tree
Showing 27 changed files with 396 additions and 165 deletions.
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.7)
project(libdatachannel
VERSION 0.20.2
VERSION 0.21.0
LANGUAGES CXX)
set(PROJECT_DESCRIPTION "C/C++ WebRTC network library featuring Data Channels, Media Transport, and WebSockets")

Expand Down Expand Up @@ -88,6 +88,7 @@ set(LIBDATACHANNEL_SOURCES
${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
)

set(LIBDATACHANNEL_HEADERS
Expand Down Expand Up @@ -125,6 +126,7 @@ set(LIBDATACHANNEL_HEADERS
${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/version.h
)

Expand Down Expand Up @@ -344,7 +346,9 @@ else()
target_link_libraries(datachannel PRIVATE libSRTP::srtp2)
target_link_libraries(datachannel-static PRIVATE libSRTP::srtp2)
else()
add_subdirectory(deps/libsrtp EXCLUDE_FROM_ALL)
if(NOT TARGET srtp2)
add_subdirectory(deps/libsrtp EXCLUDE_FROM_ALL)
endif()
target_compile_definitions(datachannel PRIVATE RTC_SYSTEM_SRTP=0)
target_compile_definitions(datachannel-static PRIVATE RTC_SYSTEM_SRTP=0)
target_link_libraries(datachannel PRIVATE srtp2)
Expand Down Expand Up @@ -373,7 +377,9 @@ if (USE_GNUTLS)
target_link_libraries(datachannel-static PRIVATE Nettle::Nettle)
endif()
elseif(USE_MBEDTLS)
find_package(MbedTLS 3 REQUIRED)
if(NOT TARGET MbedTLS::MbedTLS)
find_package(MbedTLS 3 REQUIRED)
endif()
target_compile_definitions(datachannel PRIVATE USE_MBEDTLS=1)
target_compile_definitions(datachannel-static PRIVATE USE_MBEDTLS=1)
target_link_libraries(datachannel PRIVATE MbedTLS::MbedTLS)
Expand Down
2 changes: 1 addition & 1 deletion deps/libjuice
9 changes: 6 additions & 3 deletions examples/streamer/h264fileparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "rtc/rtc.hpp"

#include <fstream>
#include <cstring>

#ifdef _WIN32
#include <winsock2.h>
Expand All @@ -29,7 +30,9 @@ void H264FileParser::loadNextSample() {
while (i < sample.size()) {
assert(i + 4 < sample.size());
auto lengthPtr = (uint32_t *) (sample.data() + i);
uint32_t length = ntohl(*lengthPtr);
uint32_t length;
std::memcpy(&length, lengthPtr, sizeof(uint32_t));
length = ntohl(length);
auto naluStartIndex = i + 4;
auto naluEndIndex = naluStartIndex + length;
assert(naluEndIndex <= sample.size());
Expand All @@ -50,8 +53,8 @@ void H264FileParser::loadNextSample() {
}
}

vector<byte> H264FileParser::initialNALUS() {
vector<byte> units{};
vector<std::byte> H264FileParser::initialNALUS() {
vector<std::byte> units{};
if (previousUnitType7.has_value()) {
auto nalu = previousUnitType7.value();
units.insert(units.end(), nalu.begin(), nalu.end());
Expand Down
1 change: 1 addition & 0 deletions include/rtc/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct RTC_CPP_EXPORT Configuration {
bool enableIceTcp = false; // libnice only
bool enableIceUdpMux = false; // libjuice only
bool disableAutoNegotiation = false;
bool disableAutoGathering = false;
bool forceMediaTransport = false;

// Port range
Expand Down
3 changes: 2 additions & 1 deletion include/rtc/frameinfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
namespace rtc {

struct RTC_CPP_EXPORT FrameInfo {
FrameInfo(uint32_t timestamp) : timestamp(timestamp){};
FrameInfo(uint8_t payloadType, uint32_t timestamp) : payloadType(payloadType), timestamp(timestamp){};
uint8_t payloadType; // Indicates codec of the frame
uint32_t timestamp = 0; // RTP Timestamp
};

Expand Down
9 changes: 7 additions & 2 deletions include/rtc/h264rtpdepacketizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "common.hpp"
#include "mediahandler.hpp"
#include "message.hpp"
#include "nalunit.hpp"
#include "rtp.hpp"

#include <iterator>
Expand All @@ -24,16 +25,20 @@ namespace rtc {
/// RTP depacketization for H264
class RTC_CPP_EXPORT H264RtpDepacketizer : public MediaHandler {
public:
H264RtpDepacketizer() = default;
using Separator = NalUnit::Separator;

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

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

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

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

} // namespace rtc
Expand Down
49 changes: 49 additions & 0 deletions include/rtc/pacinghandler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright (c) 2024 Sean DuBois <[email protected]>
*
* 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_PACING_HANDLER_H
#define RTC_PACING_HANDLER_H

#if RTC_ENABLE_MEDIA

#include "mediahandler.hpp"
#include "utils.hpp"

#include <atomic>
#include <queue>

namespace rtc {

// Paced sending of RTP packets. It takes a stream of RTP packets that can have an uneven bitrate
// and delivers them in a smoother manner by sending a fixed size of them on an interval
class RTC_CPP_EXPORT PacingHandler : public MediaHandler {
public:
PacingHandler(double bitsPerSecond, std::chrono::milliseconds sendInterval);

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

private:
std::atomic<bool> mHaveScheduled = false;

double mBytesPerSecond;
double mBudget;

std::chrono::milliseconds mSendInterval;
std::chrono::time_point<std::chrono::high_resolution_clock> mLastRun;

std::mutex mMutex;
std::queue<message_ptr> mRtpBuffer;

void schedule(const message_callback &send);
};

} // namespace rtc

#endif // RTC_ENABLE_MEDIA

#endif // RTC_PACING_HANDLER_H
1 change: 1 addition & 0 deletions include/rtc/peerconnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class RTC_CPP_EXPORT PeerConnection final : CheshireCat<impl::PeerConnection> {
void setLocalDescription(Description::Type type = Description::Type::Unspec);
void setRemoteDescription(Description description);
void addRemoteCandidate(Candidate candidate);
void gatherLocalCandidates(std::vector<IceServer> additionalIceServers = {});

void setMediaHandler(shared_ptr<MediaHandler> handler);
shared_ptr<MediaHandler> getMediaHandler();
Expand Down
3 changes: 3 additions & 0 deletions include/rtc/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ typedef struct {
// AV1 only
rtcObuPacketization obuPacketization; // OBU paketization for AV1 samples

uint8_t playoutDelayId;
uint16_t playoutDelayMin;
uint16_t playoutDelayMax;
} rtcPacketizerInit;

// Deprecated, do not use
Expand Down
1 change: 1 addition & 0 deletions include/rtc/rtc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "h265rtppacketizer.hpp"
#include "mediahandler.hpp"
#include "plihandler.hpp"
#include "pacinghandler.hpp"
#include "rtcpnackresponder.hpp"
#include "rtcpreceivingsession.hpp"
#include "rtcpsrreporter.hpp"
Expand Down
19 changes: 0 additions & 19 deletions include/rtc/rtp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,25 +358,6 @@ struct RTC_CPP_EXPORT RtpRtx {
size_t copyTo(RtpHeader *dest, size_t totalSize, uint8_t originalPayloadType);
};

// For backward compatibility, do not use
using RTP_ExtensionHeader [[deprecated]] = RtpExtensionHeader;
using RTP [[deprecated]] = RtpHeader;
using RTCP_ReportBlock [[deprecated]] = RtcpReportBlock;
using RTCP_HEADER [[deprecated]] = RtcpHeader;
using RTCP_FB_HEADER [[deprecated]] = RtcpFbHeader;
using RTCP_SR [[deprecated]] = RtcpSr;
using RTCP_SDES_ITEM [[deprecated]] = RtcpSdesItem;
using RTCP_SDES_CHUNK [[deprecated]] = RtcpSdesChunk;
using RTCP_SDES [[deprecated]] = RtcpSdes;
using RTCP_RR [[deprecated]] = RtcpRr;
using RTCP_REMB [[deprecated]] = RtcpRemb;
using RTCP_PLI [[deprecated]] = RtcpPli;
using RTCP_FIR_PART [[deprecated]] = RtcpFirPart;
using RTCP_FIR [[deprecated]] = RtcpFir;
using RTCP_NACK_PART [[deprecated]] = RtcpNackPart;
using RTCP_NACK [[deprecated]] = RtcpNack;
using RTP_RTX [[deprecated]] = RtpRtx;

#pragma pack(pop)

} // namespace rtc
Expand Down
8 changes: 8 additions & 0 deletions include/rtc/rtppacketizationconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ class RTC_CPP_EXPORT RtpPacketizationConfig {
std::bitset<32> activeChains;
FrameDependencyStructure structure;
};

optional<DependencyDescriptorContext> dependencyDescriptorContext;
// the negotiated ID of the playout delay header extension
// https://webrtc.googlesource.com/src/+/main/docs/native-code/rtp-hdrext/playout-delay/README.md
uint8_t playoutDelayId;

// Minimum/maxiumum playout delay, in 10ms intervals. A value of 10 would equal a 100ms delay
uint16_t playoutDelayMin;
uint16_t playoutDelayMax;

/// Construct RTP configuration used in packetization process
/// @param ssrc SSRC of source
Expand Down
6 changes: 3 additions & 3 deletions include/rtc/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define RTC_VERSION_H

#define RTC_VERSION_MAJOR 0
#define RTC_VERSION_MINOR 20
#define RTC_VERSION_PATCH 2
#define RTC_VERSION "0.20.2"
#define RTC_VERSION_MINOR 21
#define RTC_VERSION_PATCH 0
#define RTC_VERSION "0.21.0"

#endif
3 changes: 3 additions & 0 deletions src/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ createRtpPacketizationConfig(const rtcPacketizationHandlerInit *init) {
init->payloadType, init->clockRate);
config->sequenceNumber = init->sequenceNumber;
config->timestamp = init->timestamp;
config->playoutDelayId = init->playoutDelayId;
config->playoutDelayMin = init->playoutDelayMin;
config->playoutDelayMax = init->playoutDelayMax;
return config;
}

Expand Down
Loading

0 comments on commit 005820e

Please sign in to comment.