Merge pull request #315 from paullouisageneau/cleanup

Clean up
This commit is contained in:
Paul-Louis Ageneau
2021-01-25 16:10:20 +01:00
committed by GitHub
33 changed files with 239 additions and 206 deletions

View File

@ -59,7 +59,7 @@ set(LIBDATACHANNEL_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/message.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/message.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/peerconnection.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/peerconnection.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/logcounter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/logcounter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/rtcp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/rtcpreceivingsession.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/sctptransport.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/sctptransport.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/threadpool.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/threadpool.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/tls.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/tls.cpp
@ -67,7 +67,7 @@ set(LIBDATACHANNEL_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/processor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/processor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/capi.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/capi.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/rtppacketizationconfig.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/rtppacketizationconfig.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/rtcpsenderreportable.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/rtcpsenderreporter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/rtppacketizer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/rtppacketizer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/opusrtppacketizer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/opusrtppacketizer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/opuspacketizationhandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/opuspacketizationhandler.cpp
@ -92,7 +92,8 @@ set(LIBDATACHANNEL_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/configuration.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/configuration.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/datachannel.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/datachannel.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/description.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/description.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtcp.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtcphandler.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtcpreceivingsession.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/include.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/include.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/init.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/init.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/log.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/log.hpp
@ -311,9 +312,9 @@ if(NOT NO_EXAMPLES AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
set(JSON_BuildTests OFF CACHE INTERNAL "") set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(deps/json) add_subdirectory(deps/json)
add_subdirectory(examples/client) add_subdirectory(examples/client)
if(NOT NO_MEDIA)
add_subdirectory(examples/media) add_subdirectory(examples/media)
add_subdirectory(examples/sfu-media) add_subdirectory(examples/sfu-media)
if(NOT NO_MEDIA)
add_subdirectory(examples/streamer) add_subdirectory(examples/streamer)
endif() endif()
add_subdirectory(examples/copy-paste) add_subdirectory(examples/copy-paste)

View File

@ -60,7 +60,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
using namespace std; using namespace std;
using namespace rtc; using namespace rtc;
ClientTrackData::ClientTrackData(shared_ptr<Track> track, shared_ptr<RTCPSenderReportable> sender) { ClientTrackData::ClientTrackData(shared_ptr<Track> track, shared_ptr<RtcpSenderReporter> sender) {
this->track = track; this->track = track;
this->sender = sender; this->sender = sender;
} }

View File

@ -23,9 +23,9 @@
struct ClientTrackData { struct ClientTrackData {
std::shared_ptr<rtc::Track> track; std::shared_ptr<rtc::Track> track;
std::shared_ptr<rtc::RTCPSenderReportable> sender; std::shared_ptr<rtc::RtcpSenderReporter> sender;
ClientTrackData(std::shared_ptr<rtc::Track> track, std::shared_ptr<rtc::RTCPSenderReportable> sender); ClientTrackData(std::shared_ptr<rtc::Track> track, std::shared_ptr<rtc::RtcpSenderReporter> sender);
}; };
struct Client { struct Client {

View File

@ -217,9 +217,9 @@ shared_ptr<ClientTrackData> addVideo(const shared_ptr<PeerConnection> pc, const
video.addSSRC(ssrc, cname, msid); video.addSSRC(ssrc, cname, msid);
auto track = pc->addTrack(video); auto track = pc->addTrack(video);
// create RTP configuration // create RTP configuration
auto rtpConfig = shared_ptr<RTPPacketizationConfig>(new RTPPacketizationConfig(ssrc, cname, payloadType, H264RTPPacketizer::defaultClockRate)); auto rtpConfig = shared_ptr<RtpPacketizationConfig>(new RtpPacketizationConfig(ssrc, cname, payloadType, H264RtpPacketizer::defaultClockRate));
// create packetizer // create packetizer
auto packetizer = shared_ptr<H264RTPPacketizer>(new H264RTPPacketizer(rtpConfig)); auto packetizer = shared_ptr<H264RtpPacketizer>(new H264RtpPacketizer(rtpConfig));
// create H264 and RTCP SP handler // create H264 and RTCP SP handler
shared_ptr<H264PacketizationHandler> h264Handler(new H264PacketizationHandler(H264PacketizationHandler::Separator::Length, packetizer)); shared_ptr<H264PacketizationHandler> h264Handler(new H264PacketizationHandler(H264PacketizationHandler::Separator::Length, packetizer));
// set handler // set handler
@ -235,9 +235,9 @@ shared_ptr<ClientTrackData> addAudio(const shared_ptr<PeerConnection> pc, const
audio.addSSRC(ssrc, cname, msid); audio.addSSRC(ssrc, cname, msid);
auto track = pc->addTrack(audio); auto track = pc->addTrack(audio);
// create RTP configuration // create RTP configuration
auto rtpConfig = shared_ptr<RTPPacketizationConfig>(new RTPPacketizationConfig(ssrc, cname, payloadType, OpusRTPPacketizer::defaultClockRate)); auto rtpConfig = shared_ptr<RtpPacketizationConfig>(new RtpPacketizationConfig(ssrc, cname, payloadType, OpusRtpPacketizer::defaultClockRate));
// create packetizer // create packetizer
auto packetizer = make_shared<OpusRTPPacketizer>(rtpConfig); auto packetizer = make_shared<OpusRtpPacketizer>(rtpConfig);
// create opus and RTCP SP handler // create opus and RTCP SP handler
auto opusHandler = make_shared<OpusPacketizationHandler>(packetizer); auto opusHandler = make_shared<OpusPacketizationHandler>(packetizer);
// set handler // set handler
@ -449,8 +449,8 @@ void addToStream(shared_ptr<Client> client, bool isAddingVideo) {
auto currentTime_s = currentTime_us / (1000 * 1000); auto currentTime_s = currentTime_us / (1000 * 1000);
// set start time of stream // set start time of stream
video->sender->rtpConfig->setStartTime(currentTime_s, RTPPacketizationConfig::EpochStart::T1970); video->sender->rtpConfig->setStartTime(currentTime_s, RtpPacketizationConfig::EpochStart::T1970);
audio->sender->rtpConfig->setStartTime(currentTime_s, RTPPacketizationConfig::EpochStart::T1970); audio->sender->rtpConfig->setStartTime(currentTime_s, RtpPacketizationConfig::EpochStart::T1970);
// start stat recording of RTCP SR // start stat recording of RTCP SR
video->sender->startRecording(); video->sender->startRecording();

View File

@ -16,22 +16,22 @@
* along with this program; If not, see <http://www.gnu.org/licenses/>. * along with this program; If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef H264PacketizationHandler_hpp #ifndef H264_PACKETIZATION_HANDLER_H
#define H264PacketizationHandler_hpp #define H264_PACKETIZATION_HANDLER_H
#if RTC_ENABLE_MEDIA #if RTC_ENABLE_MEDIA
#include "h264rtppacketizer.hpp" #include "h264rtppacketizer.hpp"
#include "nalunit.hpp" #include "nalunit.hpp"
#include "rtcp.hpp" #include "rtcphandler.hpp"
#include "rtcpsenderreportable.hpp" #include "rtcpsenderreporter.hpp"
namespace rtc { namespace rtc {
/// Handler for H264 packetization /// Handler for H264 packetization
class RTC_CPP_EXPORT H264PacketizationHandler : public RtcpHandler, public RTCPSenderReportable { class RTC_CPP_EXPORT H264PacketizationHandler : public RtcpHandler, public RtcpSenderReporter {
/// RTP packetizer for H264 /// RTP packetizer for H264
const std::shared_ptr<H264RTPPacketizer> packetizer; const std::shared_ptr<H264RtpPacketizer> packetizer;
const uint16_t maximumFragmentSize; const uint16_t maximumFragmentSize;
@ -49,7 +49,7 @@ public:
/// Construct handler for H264 packetization. /// Construct handler for H264 packetization.
/// @param separator Nal units separator /// @param separator Nal units separator
/// @param packetizer RTP packetizer for h264 /// @param packetizer RTP packetizer for h264
H264PacketizationHandler(Separator separator, std::shared_ptr<H264RTPPacketizer> packetizer, H264PacketizationHandler(Separator separator, std::shared_ptr<H264RtpPacketizer> packetizer,
uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize); uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);
/// Returns message unchanged /// Returns message unchanged
@ -73,4 +73,4 @@ private:
#endif /* RTC_ENABLE_MEDIA */ #endif /* RTC_ENABLE_MEDIA */
#endif /* H264PacketizationHandler_hpp */ #endif /* H264_PACKETIZATION_HANDLER_H */

View File

@ -16,8 +16,8 @@
* along with this program; If not, see <http://www.gnu.org/licenses/>. * along with this program; If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef H264RTPPacketizer_hpp #ifndef H264RtpPacketizer_hpp
#define H264RTPPacketizer_hpp #define H264RtpPacketizer_hpp
#if RTC_ENABLE_MEDIA #if RTC_ENABLE_MEDIA
@ -26,7 +26,7 @@
namespace rtc { namespace rtc {
/// RTP packetization of h264 payload /// RTP packetization of h264 payload
class RTC_CPP_EXPORT H264RTPPacketizer : public rtc::RTPPacketizer { class RTC_CPP_EXPORT H264RtpPacketizer : public RtpPacketizer {
public: public:
/// Default clock rate for H264 in RTP /// Default clock rate for H264 in RTP
@ -36,11 +36,11 @@ public:
/// @note RTP configuration is used in packetization process which may change some configuration /// @note RTP configuration is used in packetization process which may change some configuration
/// properties such as sequence number. /// properties such as sequence number.
/// @param rtpConfig RTP configuration /// @param rtpConfig RTP configuration
H264RTPPacketizer(std::shared_ptr<rtc::RTPPacketizationConfig> rtpConfig); H264RtpPacketizer(std::shared_ptr<RtpPacketizationConfig> rtpConfig);
}; };
} // namespace rtc } // namespace rtc
#endif /* RTC_ENABLE_MEDIA */ #endif /* RTC_ENABLE_MEDIA */
#endif /* H264RTPPacketizer_hpp */ #endif /* H264RtpPacketizer_hpp */

View File

@ -60,22 +60,22 @@ private:
#pragma pack(pop) #pragma pack(pop)
/// Nal unit /// Nal unit
struct RTC_CPP_EXPORT NalUnit : rtc::binary { struct RTC_CPP_EXPORT NalUnit : binary {
NalUnit(const NalUnit &unit) = default; NalUnit(const NalUnit &unit) = default;
NalUnit(size_t size, bool includingHeader = true) NalUnit(size_t size, bool includingHeader = true)
: rtc::binary(size + (includingHeader ? 0 : 1)) {} : binary(size + (includingHeader ? 0 : 1)) {}
template <typename Iterator> template <typename Iterator>
NalUnit(Iterator begin_, Iterator end_) : rtc::binary(begin_, end_) {} NalUnit(Iterator begin_, Iterator end_) : binary(begin_, end_) {}
NalUnit(rtc::binary &&data) : rtc::binary(std::move(data)) {} NalUnit(binary &&data) : binary(std::move(data)) {}
NalUnit() : rtc::binary(1) {} NalUnit() : binary(1) {}
bool forbiddenBit() { return header()->forbiddenBit(); } bool forbiddenBit() { return header()->forbiddenBit(); }
uint8_t nri() { return header()->nri(); } uint8_t nri() { return header()->nri(); }
uint8_t unitType() { return header()->unitType(); } uint8_t unitType() { return header()->unitType(); }
rtc::binary payload() { binary payload() {
assert(size() >= 1); assert(size() >= 1);
return {begin() + 1, end()}; return {begin() + 1, end()};
} }
@ -83,7 +83,7 @@ struct RTC_CPP_EXPORT NalUnit : rtc::binary {
void setForbiddenBit(bool isSet) { header()->setForbiddenBit(isSet); } void setForbiddenBit(bool isSet) { header()->setForbiddenBit(isSet); }
void setNRI(uint8_t nri) { header()->setNRI(nri); } void setNRI(uint8_t nri) { header()->setNRI(nri); }
void setUnitType(uint8_t type) { header()->setUnitType(type); } void setUnitType(uint8_t type) { header()->setUnitType(type); }
void setPayload(rtc::binary payload) { void setPayload(binary payload) {
assert(size() >= 1); assert(size() >= 1);
erase(begin() + 1, end()); erase(begin() + 1, end());
insert(end(), payload.begin(), payload.end()); insert(end(), payload.begin(), payload.end());
@ -101,13 +101,13 @@ struct RTC_CPP_EXPORT NalUnitFragmentA : NalUnit {
enum class FragmentType { Start, Middle, End }; enum class FragmentType { Start, Middle, End };
NalUnitFragmentA(FragmentType type, bool forbiddenBit, uint8_t nri, uint8_t unitType, NalUnitFragmentA(FragmentType type, bool forbiddenBit, uint8_t nri, uint8_t unitType,
rtc::binary data); binary data);
static std::vector<NalUnitFragmentA> fragmentsFrom(NalUnit nalu, uint16_t maximumFragmentSize); static std::vector<NalUnitFragmentA> fragmentsFrom(NalUnit nalu, uint16_t maximumFragmentSize);
uint8_t unitType() { return fragmentHeader()->unitType(); } uint8_t unitType() { return fragmentHeader()->unitType(); }
rtc::binary payload() { binary payload() {
assert(size() >= 2); assert(size() >= 2);
return {begin() + 2, end()}; return {begin() + 2, end()};
} }
@ -124,7 +124,7 @@ struct RTC_CPP_EXPORT NalUnitFragmentA : NalUnit {
void setUnitType(uint8_t type) { fragmentHeader()->setUnitType(type); } void setUnitType(uint8_t type) { fragmentHeader()->setUnitType(type); }
void setPayload(rtc::binary payload) { void setPayload(binary payload) {
assert(size() >= 2); assert(size() >= 2);
erase(begin() + 2, end()); erase(begin() + 2, end());
insert(end(), payload.begin(), payload.end()); insert(end(), payload.begin(), payload.end());
@ -145,7 +145,7 @@ protected:
class RTC_CPP_EXPORT NalUnits : public std::vector<NalUnit> { class RTC_CPP_EXPORT NalUnits : public std::vector<NalUnit> {
public: public:
static const uint16_t defaultMaximumFragmentSize = 1400; static const uint16_t defaultMaximumFragmentSize = 1400;
std::vector<rtc::binary> std::vector<binary>
generateFragments(uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize); generateFragments(uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);
}; };

View File

@ -16,26 +16,26 @@
* along with this program; If not, see <http://www.gnu.org/licenses/>. * along with this program; If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef OpusPacketizationHandler_hpp #ifndef RTC_OPUS_PACKETIZATION_HANDLER_H
#define OpusPacketizationHandler_hpp #define RTC_OPUS_PACKETIZATION_HANDLER_H
#if RTC_ENABLE_MEDIA #if RTC_ENABLE_MEDIA
#include "opusrtppacketizer.hpp" #include "opusrtppacketizer.hpp"
#include "rtcp.hpp" #include "rtcphandler.hpp"
#include "rtcpsenderreportable.hpp" #include "rtcpsenderreporter.hpp"
namespace rtc { namespace rtc {
/// Handler for opus packetization /// Handler for opus packetization
class RTC_CPP_EXPORT OpusPacketizationHandler : public RtcpHandler, public RTCPSenderReportable { class RTC_CPP_EXPORT OpusPacketizationHandler : public RtcpHandler, public RtcpSenderReporter {
/// RTP packetizer for opus /// RTP packetizer for opus
const std::shared_ptr<OpusRTPPacketizer> packetizer; const std::shared_ptr<OpusRtpPacketizer> packetizer;
public: public:
/// Construct handler for opus packetization. /// Construct handler for opus packetization.
/// @param packetizer RTP packetizer for opus /// @param packetizer RTP packetizer for opus
OpusPacketizationHandler(std::shared_ptr<OpusRTPPacketizer> packetizer); OpusPacketizationHandler(std::shared_ptr<OpusRtpPacketizer> packetizer);
/// Returns message unchanged /// Returns message unchanged
/// @param ptr message /// @param ptr message
@ -49,4 +49,4 @@ public:
#endif /* RTC_ENABLE_MEDIA */ #endif /* RTC_ENABLE_MEDIA */
#endif /* OpusPacketizationHandler_hpp */ #endif /* RTC_OPUS_PACKETIZATION_HANDLER_H */

View File

@ -16,8 +16,8 @@
* along with this program; If not, see <http://www.gnu.org/licenses/>. * along with this program; If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef OpusRTPPacketizer_hpp #ifndef RTC_OPUS_RTP_PACKETIZER_H
#define OpusRTPPacketizer_hpp #define RTC_OPUS_RTP_PACKETIZER_H
#if RTC_ENABLE_MEDIA #if RTC_ENABLE_MEDIA
@ -26,7 +26,7 @@
namespace rtc { namespace rtc {
/// RTP packetizer for opus /// RTP packetizer for opus
class RTC_CPP_EXPORT OpusRTPPacketizer : public rtc::RTPPacketizer { class RTC_CPP_EXPORT OpusRtpPacketizer : public RtpPacketizer {
public: public:
/// default clock rate used in opus RTP communication /// default clock rate used in opus RTP communication
@ -36,17 +36,17 @@ public:
/// @note RTP configuration is used in packetization process which may change some configuration /// @note RTP configuration is used in packetization process which may change some configuration
/// properties such as sequence number. /// properties such as sequence number.
/// @param rtpConfig RTP configuration /// @param rtpConfig RTP configuration
OpusRTPPacketizer(std::shared_ptr<rtc::RTPPacketizationConfig> rtpConfig); OpusRtpPacketizer(std::shared_ptr<RtpPacketizationConfig> rtpConfig);
/// Creates RTP packet for given payload based on `rtpConfig`. /// Creates RTP packet for given payload based on `rtpConfig`.
/// @note This function increase sequence number after packetization. /// @note This function increase sequence number after packetization.
/// @param payload RTP payload /// @param payload RTP payload
/// @param setMark This needs to be `false` for all RTP packets with opus payload /// @param setMark This needs to be `false` for all RTP packets with opus payload
rtc::message_ptr packetize(rtc::binary payload, bool setMark) override; message_ptr packetize(binary payload, bool setMark) override;
}; };
} // namespace rtc } // namespace rtc
#endif /* RTC_ENABLE_MEDIA */ #endif /* RTC_ENABLE_MEDIA */
#endif /* OpusRTPPacketizer_hpp */ #endif /* RTC_OPUS_RTP_PACKETIZER_H */

View File

@ -31,6 +31,7 @@
#include "track.hpp" #include "track.hpp"
#include <atomic> #include <atomic>
#include <chrono>
#include <functional> #include <functional>
#include <future> #include <future>
#include <list> #include <list>

View File

@ -282,7 +282,7 @@ int rtcSetTrackRTPTimestamp(int id, uint32_t timestamp);
/// @param timestamp Pointer for result /// @param timestamp Pointer for result
int rtcGetPreviousTrackSenderReportTimestamp(int id, uint32_t * timestamp); int rtcGetPreviousTrackSenderReportTimestamp(int id, uint32_t * timestamp);
/// Set `NeedsToReport` flag in RTCPSenderReportable handler identified by given track id /// Set `NeedsToReport` flag in RtcpSenderReporter handler identified by given track id
/// @param id Track id /// @param id Track id
int rtcSetNeedsToSendRTCPSR(int id); int rtcSetNeedsToSendRTCPSR(int id);

View File

@ -27,11 +27,14 @@
#if RTC_ENABLE_MEDIA #if RTC_ENABLE_MEDIA
// opus/h264 streaming // RTCP handling
#include "rtcpreceivingsession.hpp"
// Opus/h264 streaming
#include "h264packetizationhandler.hpp" #include "h264packetizationhandler.hpp"
#include "opuspacketizationhandler.hpp" #include "opuspacketizationhandler.hpp"
#endif /* RTC_ENABLE_MEDIA */ #endif // RTC_ENABLE_MEDIA
// C API // C API
#include "rtc.h" #include "rtc.h"

View File

@ -0,0 +1,50 @@
/**
* Copyright (c) 2020 Staz Modrzynski
* Copyright (c) 2020 Paul-Louis Ageneau
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef RTC_RTCP_HANDLER_H
#define RTC_RTCP_HANDLER_H
#include "include.hpp"
#include "message.hpp"
namespace rtc {
class RTC_CPP_EXPORT RtcpHandler {
protected:
// Use this callback when trying to send custom data (such as RTCP) to the client.
synchronized_callback<message_ptr> outgoingCallback;
public:
// Called when there is traffic coming from the peer
virtual message_ptr incoming(message_ptr ptr) = 0;
// Called when there is traffic that needs to be sent to the peer
virtual message_ptr outgoing(message_ptr ptr) = 0;
// This callback is used to send traffic back to the peer.
void onOutgoing(const std::function<void(message_ptr)> &cb) {
this->outgoingCallback = synchronized_callback<message_ptr>(cb);
}
virtual bool requestKeyframe() { return false; }
};
} // namespace rtc
#endif // RTC_RTCP_HANDLER_H

View File

@ -17,58 +17,24 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#ifndef RTC_RTCP_H #ifndef RTC_RTCP_RECEIVING_SESSION_H
#define RTC_RTCP_H #define RTC_RTCP_RECEIVING_SESSION_H
#include <utility> #if RTC_ENABLE_MEDIA
#include "include.hpp" #include "include.hpp"
#include "log.hpp" #include "rtcphandler.hpp"
#include "message.hpp" #include "message.hpp"
#include "rtp.hpp" #include "rtp.hpp"
namespace rtc { namespace rtc {
class RTC_CPP_EXPORT RtcpHandler {
protected:
/**
* Use this callback when trying to send custom data (such as RTCP) to the client.
*/
synchronized_callback<rtc::message_ptr> outgoingCallback;
public:
/**
* Called when there is traffic coming from the peer
* @param ptr
* @return
*/
virtual rtc::message_ptr incoming(rtc::message_ptr ptr) = 0;
/**
* Called when there is traffic that needs to be sent to the peer
* @param ptr
* @return
*/
virtual rtc::message_ptr outgoing(rtc::message_ptr ptr) = 0;
/**
* This callback is used to send traffic back to the peer.
* This callback skips calling the track's methods.
* @param cb
*/
void onOutgoing(const std::function<void(rtc::message_ptr)> &cb);
virtual bool requestKeyframe() { return false; }
};
class Track;
// An RtcpSession can be plugged into a Track to handle the whole RTCP session // An RtcpSession can be plugged into a Track to handle the whole RTCP session
class RTC_CPP_EXPORT RtcpReceivingSession : public RtcpHandler { class RTC_CPP_EXPORT RtcpReceivingSession : public RtcpHandler {
public: public:
rtc::message_ptr incoming(rtc::message_ptr ptr) override; message_ptr incoming(message_ptr ptr) override;
rtc::message_ptr outgoing(rtc::message_ptr ptr) override; message_ptr outgoing(message_ptr ptr) override;
bool send(rtc::message_ptr ptr); bool send(message_ptr ptr);
void requestBitrate(unsigned int newBitrate); void requestBitrate(unsigned int newBitrate);
@ -88,4 +54,6 @@ protected:
} // namespace rtc } // namespace rtc
#endif // RTC_RTCP_H #endif // RTC_ENABLE_MEDIA
#endif // RTC_RTCP_RECEIVING_SESSION_H

View File

@ -16,8 +16,8 @@
* along with this program; If not, see <http://www.gnu.org/licenses/>. * along with this program; If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef RTCPSenderReporter_hpp #ifndef RTC_RTCP_SENDER_REPORTABLE_H
#define RTCPSenderReporter_hpp #define RTC_RTCP_SENDER_REPORTABLE_H
#if RTC_ENABLE_MEDIA #if RTC_ENABLE_MEDIA
@ -27,7 +27,7 @@
namespace rtc { namespace rtc {
/// Class for sending RTCP SR /// Class for sending RTCP SR
class RTC_CPP_EXPORT RTCPSenderReportable { class RTC_CPP_EXPORT RtcpSenderReporter {
bool needsToReport = false; bool needsToReport = false;
uint32_t packetCount = 0; uint32_t packetCount = 0;
@ -50,9 +50,9 @@ public:
const uint32_t &previousReportedTimestamp = _previousReportedTimestamp; const uint32_t &previousReportedTimestamp = _previousReportedTimestamp;
/// RTP configuration /// RTP configuration
const std::shared_ptr<RTPPacketizationConfig> rtpConfig; const std::shared_ptr<RtpPacketizationConfig> rtpConfig;
RTCPSenderReportable(std::shared_ptr<RTPPacketizationConfig> rtpConfig); RtcpSenderReporter(std::shared_ptr<RtpPacketizationConfig> rtpConfig);
/// Set `needsToReport` flag. Sender report will be sent before next RTP packet with same /// Set `needsToReport` flag. Sender report will be sent before next RTP packet with same
/// timestamp. /// timestamp.
@ -90,4 +90,4 @@ protected:
#endif /* RTC_ENABLE_MEDIA */ #endif /* RTC_ENABLE_MEDIA */
#endif /* RTCPSenderReporter_hpp */ #endif /* RTC_RTCP_SENDER_REPORTABLE_H */

View File

@ -16,8 +16,8 @@
* along with this program; If not, see <http://www.gnu.org/licenses/>. * along with this program; If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef RTPPacketizationConfig_hpp #ifndef RTC_RTP_PACKETIZATION_CONFIG_H
#define RTPPacketizationConfig_hpp #define RTC_RTP_PACKETIZATION_CONFIG_H
#if RTC_ENABLE_MEDIA #if RTC_ENABLE_MEDIA
@ -26,10 +26,10 @@
namespace rtc { namespace rtc {
/// RTP configuration used in packetization process /// RTP configuration used in packetization process
class RTC_CPP_EXPORT RTPPacketizationConfig { class RTC_CPP_EXPORT RtpPacketizationConfig {
uint32_t _startTimestamp = 0; uint32_t _startTimestamp = 0;
double _startTime_s = 0; double _startTime_s = 0;
RTPPacketizationConfig(const RTPPacketizationConfig &) = delete; RtpPacketizationConfig(const RtpPacketizationConfig &) = delete;
public: public:
const SSRC ssrc; const SSRC ssrc;
@ -65,7 +65,7 @@ public:
/// @param sequenceNumber Initial sequence number of RTP packets (random number is choosed if /// @param sequenceNumber Initial sequence number of RTP packets (random number is choosed if
/// nullopt) /// nullopt)
/// @param timestamp Initial timastamp of RTP packets (random number is choosed if nullopt) /// @param timestamp Initial timastamp of RTP packets (random number is choosed if nullopt)
RTPPacketizationConfig(SSRC ssrc, std::string cname, uint8_t payloadType, uint32_t clockRate, RtpPacketizationConfig(SSRC ssrc, std::string cname, uint8_t payloadType, uint32_t clockRate,
std::optional<uint16_t> sequenceNumber = std::nullopt, std::optional<uint16_t> sequenceNumber = std::nullopt,
std::optional<uint32_t> timestamp = std::nullopt); std::optional<uint32_t> timestamp = std::nullopt);
@ -92,4 +92,4 @@ public:
#endif /* RTC_ENABLE_MEDIA */ #endif /* RTC_ENABLE_MEDIA */
#endif /* RTPPacketizationConfig_hpp */ #endif /* RTC_RTP_PACKETIZATION_CONFIG_H */

View File

@ -16,8 +16,8 @@
* along with this program; If not, see <http://www.gnu.org/licenses/>. * along with this program; If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef RTPPacketizer_hpp #ifndef RTC_RTP_PACKETIZER_H
#define RTPPacketizer_hpp #define RTC_RTP_PACKETIZER_H
#if RTC_ENABLE_MEDIA #if RTC_ENABLE_MEDIA
@ -26,19 +26,19 @@
namespace rtc { namespace rtc {
/// Class responsizble for rtp packetization /// Class responsible for RTP packetization
class RTC_CPP_EXPORT RTPPacketizer { class RTC_CPP_EXPORT RtpPacketizer {
static const auto rtpHeaderSize = 12; static const auto rtpHeaderSize = 12;
public: public:
// rtp configuration // RTP configuration
const std::shared_ptr<RTPPacketizationConfig> rtpConfig; const std::shared_ptr<RtpPacketizationConfig> rtpConfig;
/// Constructs packetizer with given RTP configuration. /// Constructs packetizer with given RTP configuration.
/// @note RTP configuration is used in packetization process which may change some configuration /// @note RTP configuration is used in packetization process which may change some configuration
/// properties such as sequence number. /// properties such as sequence number.
/// @param rtpConfig RTP configuration /// @param rtpConfig RTP configuration
RTPPacketizer(std::shared_ptr<RTPPacketizationConfig> rtpConfig); RtpPacketizer(std::shared_ptr<RtpPacketizationConfig> rtpConfig);
/// Creates RTP packet for given payload based on `rtpConfig`. /// Creates RTP packet for given payload based on `rtpConfig`.
/// @note This function increase sequence number after packetization. /// @note This function increase sequence number after packetization.
@ -51,4 +51,4 @@ public:
#endif /* RTC_ENABLE_MEDIA */ #endif /* RTC_ENABLE_MEDIA */
#endif /* RTPPacketizer_hpp */ #endif /* RTC_RTP_PACKETIZER_H */

View File

@ -24,7 +24,7 @@
#include "include.hpp" #include "include.hpp"
#include "message.hpp" #include "message.hpp"
#include "queue.hpp" #include "queue.hpp"
#include "rtcp.hpp" #include "rtcphandler.hpp"
#include <atomic> #include <atomic>
#include <variant> #include <variant>

View File

@ -53,8 +53,8 @@ std::unordered_map<int, shared_ptr<PeerConnection>> peerConnectionMap;
std::unordered_map<int, shared_ptr<DataChannel>> dataChannelMap; std::unordered_map<int, shared_ptr<DataChannel>> dataChannelMap;
std::unordered_map<int, shared_ptr<Track>> trackMap; std::unordered_map<int, shared_ptr<Track>> trackMap;
#if RTC_ENABLE_MEDIA #if RTC_ENABLE_MEDIA
std::unordered_map<int, shared_ptr<RTCPSenderReportable>> rtcpSenderMap; std::unordered_map<int, shared_ptr<RtcpSenderReporter>> rtcpSenderMap;
std::unordered_map<int, shared_ptr<RTPPacketizationConfig>> rtpConfigMap; std::unordered_map<int, shared_ptr<RtpPacketizationConfig>> rtpConfigMap;
#endif #endif
#if RTC_ENABLE_WEBSOCKET #if RTC_ENABLE_WEBSOCKET
std::unordered_map<int, shared_ptr<WebSocket>> webSocketMap; std::unordered_map<int, shared_ptr<WebSocket>> webSocketMap;
@ -149,20 +149,20 @@ void eraseTrack(int tr) {
#if RTC_ENABLE_MEDIA #if RTC_ENABLE_MEDIA
shared_ptr<RTCPSenderReportable> getRTCPSender(int id) { shared_ptr<RtcpSenderReporter> getRTCPSender(int id) {
std::lock_guard lock(mutex); std::lock_guard lock(mutex);
if (auto it = rtcpSenderMap.find(id); it != rtcpSenderMap.end()) if (auto it = rtcpSenderMap.find(id); it != rtcpSenderMap.end())
return it->second; return it->second;
else else
throw std::invalid_argument("RTCPSenderReportable ID does not exist"); throw std::invalid_argument("RtcpSenderReporter ID does not exist");
} }
void emplaceRTCPSender(shared_ptr<RTCPSenderReportable> ptr, int tr) { void emplaceRTCPSender(shared_ptr<RtcpSenderReporter> ptr, int tr) {
std::lock_guard lock(mutex); std::lock_guard lock(mutex);
rtcpSenderMap.emplace(std::make_pair(tr, ptr)); rtcpSenderMap.emplace(std::make_pair(tr, ptr));
} }
shared_ptr<RTPPacketizationConfig> getRTPConfig(int id) { shared_ptr<RtpPacketizationConfig> getRTPConfig(int id) {
std::lock_guard lock(mutex); std::lock_guard lock(mutex);
if (auto it = rtpConfigMap.find(id); it != rtpConfigMap.end()) if (auto it = rtpConfigMap.find(id); it != rtpConfigMap.end())
return it->second; return it->second;
@ -170,7 +170,7 @@ shared_ptr<RTPPacketizationConfig> getRTPConfig(int id) {
throw std::invalid_argument("RTPConfiguration ID does not exist"); throw std::invalid_argument("RTPConfiguration ID does not exist");
} }
void emplaceRTPConfig(shared_ptr<RTPPacketizationConfig> ptr, int tr) { void emplaceRTPConfig(shared_ptr<RtpPacketizationConfig> ptr, int tr) {
std::lock_guard lock(mutex); std::lock_guard lock(mutex);
rtpConfigMap.emplace(std::make_pair(tr, ptr)); rtpConfigMap.emplace(std::make_pair(tr, ptr));
} }
@ -190,14 +190,14 @@ Description::Direction rtcDirectionToDirection(rtcDirection direction) {
} }
} }
shared_ptr<RTPPacketizationConfig> shared_ptr<RtpPacketizationConfig>
getNewRTPPacketizationConfig(uint32_t ssrc, const char *cname, uint8_t payloadType, getNewRtpPacketizationConfig(uint32_t ssrc, const char *cname, uint8_t payloadType,
uint32_t clockRate, uint16_t sequenceNumber, uint32_t timestamp) { uint32_t clockRate, uint16_t sequenceNumber, uint32_t timestamp) {
if (!cname) { if (!cname) {
throw std::invalid_argument("Unexpected null pointer for cname"); throw std::invalid_argument("Unexpected null pointer for cname");
} }
return std::make_shared<RTPPacketizationConfig>(ssrc, cname, payloadType, clockRate, return std::make_shared<RtpPacketizationConfig>(ssrc, cname, payloadType, clockRate,
sequenceNumber, timestamp); sequenceNumber, timestamp);
} }
@ -533,10 +533,10 @@ int rtcSetH264PacketizationHandler(int tr, uint32_t ssrc, const char *cname, uin
return WRAP({ return WRAP({
auto track = getTrack(tr); auto track = getTrack(tr);
// create RTP configuration // create RTP configuration
auto rtpConfig = getNewRTPPacketizationConfig(ssrc, cname, payloadType, clockRate, auto rtpConfig = getNewRtpPacketizationConfig(ssrc, cname, payloadType, clockRate,
sequenceNumber, timestamp); sequenceNumber, timestamp);
// create packetizer // create packetizer
auto packetizer = shared_ptr<H264RTPPacketizer>(new H264RTPPacketizer(rtpConfig)); auto packetizer = shared_ptr<H264RtpPacketizer>(new H264RtpPacketizer(rtpConfig));
// create H264 and RTCP SP handler // create H264 and RTCP SP handler
shared_ptr<H264PacketizationHandler> h264Handler( shared_ptr<H264PacketizationHandler> h264Handler(
new H264PacketizationHandler(H264PacketizationHandler::Separator::Length, packetizer, maxFragmentSize)); new H264PacketizationHandler(H264PacketizationHandler::Separator::Length, packetizer, maxFragmentSize));
@ -553,10 +553,10 @@ int rtcSetOpusPacketizationHandler(int tr, uint32_t ssrc, const char *cname, uin
return WRAP({ return WRAP({
auto track = getTrack(tr); auto track = getTrack(tr);
// create RTP configuration // create RTP configuration
auto rtpConfig = getNewRTPPacketizationConfig(ssrc, cname, payloadType, clockRate, auto rtpConfig = getNewRtpPacketizationConfig(ssrc, cname, payloadType, clockRate,
sequenceNumber, timestamp); sequenceNumber, timestamp);
// create packetizer // create packetizer
auto packetizer = shared_ptr<OpusRTPPacketizer>(new OpusRTPPacketizer(rtpConfig)); auto packetizer = shared_ptr<OpusRtpPacketizer>(new OpusRtpPacketizer(rtpConfig));
// create Opus and RTCP SP handler // create Opus and RTCP SP handler
shared_ptr<OpusPacketizationHandler> opusHandler(new OpusPacketizationHandler(packetizer)); shared_ptr<OpusPacketizationHandler> opusHandler(new OpusPacketizationHandler(packetizer));
emplaceRTCPSender(opusHandler, tr); emplaceRTCPSender(opusHandler, tr);
@ -570,9 +570,9 @@ int rtcSetRtpConfigurationStartTime(int id, double startTime_s, bool timeInterva
uint32_t timestamp) { uint32_t timestamp) {
return WRAP({ return WRAP({
auto config = getRTPConfig(id); auto config = getRTPConfig(id);
auto epoch = RTPPacketizationConfig::EpochStart::T1900; auto epoch = RtpPacketizationConfig::EpochStart::T1900;
if (timeIntervalSince1970) { if (timeIntervalSince1970) {
epoch = RTPPacketizationConfig::EpochStart::T1970; epoch = RtpPacketizationConfig::EpochStart::T1970;
} }
config->setStartTime(startTime_s, epoch, timestamp); config->setStartTime(startTime_s, epoch, timestamp);
}); });

View File

@ -28,10 +28,11 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#endif #endif
rtc::LogCounter COUNTER_USERNEG_OPEN_MESSAGE(
plog::warning, "Number of open messages for a user-negotiated DataChannel received");
namespace rtc { namespace rtc {
LogCounter COUNTER_USERNEG_OPEN_MESSAGE(
plog::warning, "Number of open messages for a user-negotiated DataChannel received");
using std::shared_ptr; using std::shared_ptr;
using std::weak_ptr; using std::weak_ptr;
using std::chrono::milliseconds; using std::chrono::milliseconds;

View File

@ -29,29 +29,29 @@ using std::shared_ptr;
using std::to_integer; using std::to_integer;
using std::to_string; using std::to_string;
static rtc::LogCounter COUNTER_MEDIA_TRUNCATED(plog::warning, namespace rtc {
static LogCounter COUNTER_MEDIA_TRUNCATED(plog::warning,
"Number of truncated SRT(C)P packets received"); "Number of truncated SRT(C)P packets received");
static rtc::LogCounter static LogCounter
COUNTER_UNKNOWN_PACKET_TYPE(plog::warning, COUNTER_UNKNOWN_PACKET_TYPE(plog::warning,
"Number of RTP packets received with an unknown packet type"); "Number of RTP packets received with an unknown packet type");
static rtc::LogCounter COUNTER_SRTCP_REPLAY(plog::warning, static LogCounter COUNTER_SRTCP_REPLAY(plog::warning,
"Number of SRTCP replay packets received"); "Number of SRTCP replay packets received");
static rtc::LogCounter static LogCounter
COUNTER_SRTCP_AUTH_FAIL(plog::warning, COUNTER_SRTCP_AUTH_FAIL(plog::warning,
"Number of SRTCP packets received that failed authentication checks"); "Number of SRTCP packets received that failed authentication checks");
static rtc::LogCounter static LogCounter
COUNTER_SRTCP_FAIL(plog::warning, COUNTER_SRTCP_FAIL(plog::warning,
"Number of SRTCP packets received that had an unknown libSRTP failure"); "Number of SRTCP packets received that had an unknown libSRTP failure");
static rtc::LogCounter COUNTER_SRTP_REPLAY(plog::warning, "Number of SRTP replay packets received"); static LogCounter COUNTER_SRTP_REPLAY(plog::warning, "Number of SRTP replay packets received");
static rtc::LogCounter static LogCounter
COUNTER_SRTP_AUTH_FAIL(plog::warning, COUNTER_SRTP_AUTH_FAIL(plog::warning,
"Number of SRTP packets received that failed authentication checks"); "Number of SRTP packets received that failed authentication checks");
static rtc::LogCounter static rtc::LogCounter
COUNTER_SRTP_FAIL(plog::warning, COUNTER_SRTP_FAIL(plog::warning,
"Number of SRTP packets received that had an unknown libSRTP failure"); "Number of SRTP packets received that had an unknown libSRTP failure");
namespace rtc {
void DtlsSrtpTransport::Init() { srtp_init(); } void DtlsSrtpTransport::Init() { srtp_init(); }
void DtlsSrtpTransport::Cleanup() { srtp_shutdown(); } void DtlsSrtpTransport::Cleanup() { srtp_shutdown(); }

View File

@ -76,7 +76,7 @@ NalUnitStartSequenceMatch StartSequenceMatchSucc(NalUnitStartSequenceMatch match
message_ptr H264PacketizationHandler::incoming(message_ptr ptr) { return ptr; } message_ptr H264PacketizationHandler::incoming(message_ptr ptr) { return ptr; }
shared_ptr<NalUnits> H264PacketizationHandler::splitMessage(rtc::message_ptr message) { shared_ptr<NalUnits> H264PacketizationHandler::splitMessage(message_ptr message) {
auto nalus = make_shared<NalUnits>(); auto nalus = make_shared<NalUnits>();
if (separator == Separator::Length) { if (separator == Separator::Length) {
unsigned long long index = 0; unsigned long long index = 0;
@ -155,9 +155,9 @@ message_ptr H264PacketizationHandler::outgoing(message_ptr ptr) {
} }
H264PacketizationHandler::H264PacketizationHandler(Separator separator, H264PacketizationHandler::H264PacketizationHandler(Separator separator,
std::shared_ptr<H264RTPPacketizer> packetizer, std::shared_ptr<H264RtpPacketizer> packetizer,
uint16_t maximumFragmentSize) uint16_t maximumFragmentSize)
: RtcpHandler(), rtc::RTCPSenderReportable(packetizer->rtpConfig), packetizer(packetizer), : RtcpHandler(), RtcpSenderReporter(packetizer->rtpConfig), packetizer(packetizer),
maximumFragmentSize(maximumFragmentSize), separator(separator) { maximumFragmentSize(maximumFragmentSize), separator(separator) {
senderReportOutgoingCallback = [this](message_ptr msg) { outgoingCallback(msg); }; senderReportOutgoingCallback = [this](message_ptr msg) { outgoingCallback(msg); };

View File

@ -22,8 +22,8 @@
namespace rtc { namespace rtc {
H264RTPPacketizer::H264RTPPacketizer(std::shared_ptr<RTPPacketizationConfig> rtpConfig) H264RtpPacketizer::H264RtpPacketizer(std::shared_ptr<RtpPacketizationConfig> rtpConfig)
: RTPPacketizer(rtpConfig) {} : RtpPacketizer(rtpConfig) {}
} // namespace rtc } // namespace rtc

View File

@ -18,7 +18,9 @@
#include "logcounter.hpp" #include "logcounter.hpp"
rtc::LogCounter::LogCounter(plog::Severity severity, const std::string &text, namespace rtc {
LogCounter::LogCounter(plog::Severity severity, const std::string &text,
std::chrono::seconds duration) { std::chrono::seconds duration) {
mData = std::make_shared<LogData>(); mData = std::make_shared<LogData>();
mData->mDuration = duration; mData->mDuration = duration;
@ -26,7 +28,7 @@ rtc::LogCounter::LogCounter(plog::Severity severity, const std::string &text,
mData->mText = text; mData->mText = text;
} }
rtc::LogCounter &rtc::LogCounter::operator++(int) { LogCounter &LogCounter::operator++(int) {
if (mData->mCount++ == 0) { if (mData->mCount++ == 0) {
ThreadPool::Instance().schedule( ThreadPool::Instance().schedule(
mData->mDuration, mData->mDuration,
@ -44,3 +46,5 @@ rtc::LogCounter &rtc::LogCounter::operator++(int) {
} }
return *this; return *this;
} }
} // namespace rtc

View File

@ -16,13 +16,17 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#ifndef WEBRTC_SERVER_LOGCOUNTER_HPP #ifndef RTC_SERVER_LOGCOUNTER_HPP
#define WEBRTC_SERVER_LOGCOUNTER_HPP #define RTC_SERVER_LOGCOUNTER_HPP
#include "include.hpp" #include "include.hpp"
#include "threadpool.hpp" #include "threadpool.hpp"
#include <atomic>
#include <chrono>
namespace rtc { namespace rtc {
class LogCounter { class LogCounter {
private: private:
struct LogData { struct LogData {
@ -41,6 +45,7 @@ public:
LogCounter &operator++(int); LogCounter &operator++(int);
}; };
} // namespace rtc } // namespace rtc
#endif // WEBRTC_SERVER_LOGCOUNTER_HPP #endif // RTC_SERVER_LOGCOUNTER_HPP

View File

@ -22,8 +22,8 @@
namespace rtc { namespace rtc {
OpusPacketizationHandler::OpusPacketizationHandler(std::shared_ptr<OpusRTPPacketizer> packetizer) OpusPacketizationHandler::OpusPacketizationHandler(std::shared_ptr<OpusRtpPacketizer> packetizer)
: RtcpHandler(), RTCPSenderReportable(packetizer->rtpConfig), packetizer(packetizer) { : RtcpHandler(), RtcpSenderReporter(packetizer->rtpConfig), packetizer(packetizer) {
senderReportOutgoingCallback = [this](message_ptr msg) { outgoingCallback(msg); }; senderReportOutgoingCallback = [this](message_ptr msg) { outgoingCallback(msg); };
} }

View File

@ -22,12 +22,12 @@
namespace rtc { namespace rtc {
OpusRTPPacketizer::OpusRTPPacketizer(std::shared_ptr<RTPPacketizationConfig> rtpConfig) OpusRtpPacketizer::OpusRtpPacketizer(std::shared_ptr<RtpPacketizationConfig> rtpConfig)
: RTPPacketizer(rtpConfig) {} : RtpPacketizer(rtpConfig) {}
message_ptr OpusRTPPacketizer::packetize(binary payload, bool setMark) { message_ptr OpusRtpPacketizer::packetize(binary payload, bool setMark) {
assert(!setMark); assert(!setMark);
return RTPPacketizer::packetize(payload, false); return RtpPacketizer::packetize(payload, false);
} }
} // namespace rtc } // namespace rtc

View File

@ -23,6 +23,7 @@
#include "logcounter.hpp" #include "logcounter.hpp"
#include "processor.hpp" #include "processor.hpp"
#include "threadpool.hpp" #include "threadpool.hpp"
#include "rtp.hpp"
#include "dtlstransport.hpp" #include "dtlstransport.hpp"
#include "icetransport.hpp" #include "icetransport.hpp"

View File

@ -17,10 +17,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "rtcp.hpp" #if RTC_ENABLE_MEDIA
#include "rtcpreceivingsession.hpp"
#include "logcounter.hpp" #include "logcounter.hpp"
#include "track.hpp" #include "track.hpp"
#include <cmath> #include <cmath>
#include <utility> #include <utility>
@ -30,18 +32,17 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#endif #endif
static rtc::LogCounter COUNTER_BAD_RTP_HEADER(plog::warning, "Number of malformed RTP headers");
static rtc::LogCounter COUNTER_UNKNOWN_PPID(plog::warning, "Number of Unknown PPID messages");
static rtc::LogCounter COUNTER_BAD_NOTIF_LEN(plog::warning, "Number of Bad-Lengthed notifications");
static rtc::LogCounter COUNTER_BAD_SCTP_STATUS(plog::warning,
"Number of unknown SCTP_STATUS errors");
namespace rtc { namespace rtc {
rtc::message_ptr RtcpReceivingSession::outgoing(rtc::message_ptr ptr) { return ptr; } static LogCounter COUNTER_BAD_RTP_HEADER(plog::warning, "Number of malformed RTP headers");
static LogCounter COUNTER_UNKNOWN_PPID(plog::warning, "Number of Unknown PPID messages");
static LogCounter COUNTER_BAD_NOTIF_LEN(plog::warning, "Number of Bad-Lengthed notifications");
static LogCounter COUNTER_BAD_SCTP_STATUS(plog::warning, "Number of unknown SCTP_STATUS errors");
rtc::message_ptr RtcpReceivingSession::incoming(rtc::message_ptr ptr) { message_ptr RtcpReceivingSession::outgoing(message_ptr ptr) { return ptr; }
if (ptr->type == rtc::Message::Type::Binary) {
message_ptr RtcpReceivingSession::incoming(message_ptr ptr) {
if (ptr->type == Message::Type::Binary) {
auto rtp = reinterpret_cast<const RTP *>(ptr->data()); auto rtp = reinterpret_cast<const RTP *>(ptr->data());
// https://tools.ietf.org/html/rfc3550#appendix-A.1 // https://tools.ietf.org/html/rfc3550#appendix-A.1
@ -65,7 +66,7 @@ rtc::message_ptr RtcpReceivingSession::incoming(rtc::message_ptr ptr) {
return ptr; return ptr;
} }
assert(ptr->type == rtc::Message::Type::Control); assert(ptr->type == Message::Type::Control);
auto rr = reinterpret_cast<const RTCP_RR *>(ptr->data()); auto rr = reinterpret_cast<const RTCP_RR *>(ptr->data());
if (rr->header.payloadType() == 201) { if (rr->header.payloadType() == 201) {
// RR // RR
@ -95,8 +96,7 @@ void RtcpReceivingSession::requestBitrate(unsigned int newBitrate) {
} }
void RtcpReceivingSession::pushREMB(unsigned int bitrate) { void RtcpReceivingSession::pushREMB(unsigned int bitrate) {
rtc::message_ptr msg = message_ptr msg = make_message(RTCP_REMB::sizeWithSSRCs(1), Message::Type::Control);
rtc::make_message(RTCP_REMB::sizeWithSSRCs(1), rtc::Message::Type::Control);
auto remb = reinterpret_cast<RTCP_REMB *>(msg->data()); auto remb = reinterpret_cast<RTCP_REMB *>(msg->data());
remb->preparePacket(mSsrc, 1, bitrate); remb->preparePacket(mSsrc, 1, bitrate);
remb->setSsrc(0, mSsrc); remb->setSsrc(0, mSsrc);
@ -105,7 +105,7 @@ void RtcpReceivingSession::pushREMB(unsigned int bitrate) {
} }
void RtcpReceivingSession::pushRR(unsigned int lastSR_delay) { void RtcpReceivingSession::pushRR(unsigned int lastSR_delay) {
auto msg = rtc::make_message(RTCP_RR::sizeWithReportBlocks(1), rtc::Message::Type::Control); auto msg = make_message(RTCP_RR::sizeWithReportBlocks(1), Message::Type::Control);
auto rr = reinterpret_cast<RTCP_RR *>(msg->data()); auto rr = reinterpret_cast<RTCP_RR *>(msg->data());
rr->preparePacket(mSsrc, 1); rr->preparePacket(mSsrc, 1);
rr->getReportBlock(0)->preparePacket(mSsrc, 0, 0, uint16_t(mGreatestSeqNo), 0, 0, mSyncNTPTS, rr->getReportBlock(0)->preparePacket(mSsrc, 0, 0, uint16_t(mGreatestSeqNo), 0, 0, mSyncNTPTS,
@ -131,13 +131,12 @@ bool RtcpReceivingSession::requestKeyframe() {
} }
void RtcpReceivingSession::pushPLI() { void RtcpReceivingSession::pushPLI() {
auto msg = rtc::make_message(rtc::RTCP_PLI::size(), rtc::Message::Type::Control); auto msg = make_message(RTCP_PLI::size(), Message::Type::Control);
auto *pli = reinterpret_cast<rtc::RTCP_PLI *>(msg->data()); auto *pli = reinterpret_cast<RTCP_PLI *>(msg->data());
pli->preparePacket(mSsrc); pli->preparePacket(mSsrc);
send(msg); send(msg);
} }
void RtcpHandler::onOutgoing(const std::function<void(rtc::message_ptr)> &cb) {
this->outgoingCallback = synchronized_callback<rtc::message_ptr>(cb);
}
} // namespace rtc } // namespace rtc
#endif // RTC_ENABLE_MEDIA

View File

@ -18,37 +18,37 @@
#if RTC_ENABLE_MEDIA #if RTC_ENABLE_MEDIA
#include "rtcpsenderreportable.hpp" #include "rtcpsenderreporter.hpp"
namespace rtc { namespace rtc {
void RTCPSenderReportable::startRecording() { void RtcpSenderReporter::startRecording() {
_previousReportedTimestamp = rtpConfig->timestamp; _previousReportedTimestamp = rtpConfig->timestamp;
timeOffset = rtpConfig->startTime_s - rtpConfig->timestampToSeconds(rtpConfig->timestamp); timeOffset = rtpConfig->startTime_s - rtpConfig->timestampToSeconds(rtpConfig->timestamp);
} }
void RTCPSenderReportable::sendReport(uint32_t timestamp) { void RtcpSenderReporter::sendReport(uint32_t timestamp) {
auto sr = getSenderReport(timestamp); auto sr = getSenderReport(timestamp);
_previousReportedTimestamp = timestamp; _previousReportedTimestamp = timestamp;
senderReportOutgoingCallback(move(sr)); senderReportOutgoingCallback(move(sr));
} }
void RTCPSenderReportable::addToReport(RTP *rtp, uint32_t rtpSize) { void RtcpSenderReporter::addToReport(RTP *rtp, uint32_t rtpSize) {
packetCount += 1; packetCount += 1;
assert(!rtp->padding()); assert(!rtp->padding());
payloadOctets += rtpSize - rtp->getSize(); payloadOctets += rtpSize - rtp->getSize();
} }
RTCPSenderReportable::RTCPSenderReportable(std::shared_ptr<RTPPacketizationConfig> rtpConfig) RtcpSenderReporter::RtcpSenderReporter(std::shared_ptr<RtpPacketizationConfig> rtpConfig)
: rtpConfig(rtpConfig) {} : rtpConfig(rtpConfig) {}
uint64_t RTCPSenderReportable::secondsToNTP(double seconds) { uint64_t RtcpSenderReporter::secondsToNTP(double seconds) {
return std::round(seconds * double(uint64_t(1) << 32)); return std::round(seconds * double(uint64_t(1) << 32));
} }
void RTCPSenderReportable::setNeedsToReport() { needsToReport = true; } void RtcpSenderReporter::setNeedsToReport() { needsToReport = true; }
message_ptr RTCPSenderReportable::getSenderReport(uint32_t timestamp) { message_ptr RtcpSenderReporter::getSenderReport(uint32_t timestamp) {
auto srSize = RTCP_SR::size(0); auto srSize = RTCP_SR::size(0);
auto msg = make_message(srSize + RTCP_SDES::size({{uint8_t(rtpConfig->cname.size())}}), auto msg = make_message(srSize + RTCP_SDES::size({{uint8_t(rtpConfig->cname.size())}}),
Message::Type::Control); Message::Type::Control);

View File

@ -22,7 +22,7 @@
namespace rtc { namespace rtc {
RTPPacketizationConfig::RTPPacketizationConfig(SSRC ssrc, string cname, uint8_t payloadType, RtpPacketizationConfig::RtpPacketizationConfig(SSRC ssrc, string cname, uint8_t payloadType,
uint32_t clockRate, uint32_t clockRate,
std::optional<uint16_t> sequenceNumber, std::optional<uint16_t> sequenceNumber,
std::optional<uint32_t> timestamp) std::optional<uint32_t> timestamp)
@ -42,7 +42,7 @@ RTPPacketizationConfig::RTPPacketizationConfig(SSRC ssrc, string cname, uint8_t
this->_startTimestamp = this->timestamp; this->_startTimestamp = this->timestamp;
} }
void RTPPacketizationConfig::setStartTime(double startTime_s, EpochStart epochStart, void RtpPacketizationConfig::setStartTime(double startTime_s, EpochStart epochStart,
std::optional<uint32_t> startTimestamp) { std::optional<uint32_t> startTimestamp) {
this->_startTime_s = startTime_s + static_cast<unsigned long long>(epochStart); this->_startTime_s = startTime_s + static_cast<unsigned long long>(epochStart);
if (startTimestamp.has_value()) { if (startTimestamp.has_value()) {
@ -53,20 +53,20 @@ void RTPPacketizationConfig::setStartTime(double startTime_s, EpochStart epochSt
} }
} }
double RTPPacketizationConfig::getSecondsFromTimestamp(uint32_t timestamp, uint32_t clockRate) { double RtpPacketizationConfig::getSecondsFromTimestamp(uint32_t timestamp, uint32_t clockRate) {
return double(timestamp) / double(clockRate); return double(timestamp) / double(clockRate);
} }
double RTPPacketizationConfig::timestampToSeconds(uint32_t timestamp) { double RtpPacketizationConfig::timestampToSeconds(uint32_t timestamp) {
return RTPPacketizationConfig::getSecondsFromTimestamp(timestamp, clockRate); return RtpPacketizationConfig::getSecondsFromTimestamp(timestamp, clockRate);
} }
uint32_t RTPPacketizationConfig::getTimestampFromSeconds(double seconds, uint32_t clockRate) { uint32_t RtpPacketizationConfig::getTimestampFromSeconds(double seconds, uint32_t clockRate) {
return uint32_t(seconds * clockRate); return uint32_t(seconds * clockRate);
} }
uint32_t RTPPacketizationConfig::secondsToTimestamp(double seconds) { uint32_t RtpPacketizationConfig::secondsToTimestamp(double seconds) {
return RTPPacketizationConfig::getTimestampFromSeconds(seconds, clockRate); return RtpPacketizationConfig::getTimestampFromSeconds(seconds, clockRate);
} }
} // namespace rtc } // namespace rtc

View File

@ -22,10 +22,10 @@
namespace rtc { namespace rtc {
RTPPacketizer::RTPPacketizer(std::shared_ptr<RTPPacketizationConfig> rtpConfig) RtpPacketizer::RtpPacketizer(std::shared_ptr<RtpPacketizationConfig> rtpConfig)
: rtpConfig(rtpConfig) {} : rtpConfig(rtpConfig) {}
message_ptr RTPPacketizer::packetize(binary payload, bool setMark) { message_ptr RtpPacketizer::packetize(binary payload, bool setMark) {
auto msg = make_message(rtpHeaderSize + payload.size()); auto msg = make_message(rtpHeaderSize + payload.size());
auto *rtp = (RTP *)msg->data(); auto *rtp = (RTP *)msg->data();
rtp->setPayloadType(rtpConfig->payloadType); rtp->setPayloadType(rtpConfig->payloadType);

View File

@ -56,16 +56,16 @@ using namespace std::chrono;
using std::shared_ptr; using std::shared_ptr;
static rtc::LogCounter COUNTER_UNKNOWN_PPID(plog::warning, namespace rtc {
static LogCounter COUNTER_UNKNOWN_PPID(plog::warning,
"Number of SCTP packets received with an unknown PPID"); "Number of SCTP packets received with an unknown PPID");
static rtc::LogCounter static LogCounter
COUNTER_BAD_NOTIF_LEN(plog::warning, COUNTER_BAD_NOTIF_LEN(plog::warning,
"Number of SCTP packets received with an bad notification length"); "Number of SCTP packets received with an bad notification length");
static rtc::LogCounter COUNTER_BAD_SCTP_STATUS(plog::warning, static LogCounter COUNTER_BAD_SCTP_STATUS(plog::warning,
"Number of SCTP packets received with a bad status"); "Number of SCTP packets received with a bad status");
namespace rtc {
std::unordered_set<SctpTransport *> SctpTransport::Instances; std::unordered_set<SctpTransport *> SctpTransport::Instances;
std::shared_mutex SctpTransport::InstancesMutex; std::shared_mutex SctpTransport::InstancesMutex;