diff --git a/CMakeLists.txt b/CMakeLists.txt index bfedefa..69b0338 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,7 +59,7 @@ set(LIBDATACHANNEL_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/message.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/peerconnection.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/threadpool.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/capi.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/opusrtppacketizer.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/datachannel.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/init.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 "") add_subdirectory(deps/json) add_subdirectory(examples/client) +if(NOT NO_MEDIA) add_subdirectory(examples/media) add_subdirectory(examples/sfu-media) -if(NOT NO_MEDIA) add_subdirectory(examples/streamer) endif() add_subdirectory(examples/copy-paste) diff --git a/examples/streamer/helpers.cpp b/examples/streamer/helpers.cpp index a6b063e..be51e45 100644 --- a/examples/streamer/helpers.cpp +++ b/examples/streamer/helpers.cpp @@ -60,7 +60,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) using namespace std; using namespace rtc; -ClientTrackData::ClientTrackData(shared_ptr track, shared_ptr sender) { +ClientTrackData::ClientTrackData(shared_ptr track, shared_ptr sender) { this->track = track; this->sender = sender; } diff --git a/examples/streamer/helpers.hpp b/examples/streamer/helpers.hpp index 557a897..4d09cef 100644 --- a/examples/streamer/helpers.hpp +++ b/examples/streamer/helpers.hpp @@ -23,9 +23,9 @@ struct ClientTrackData { std::shared_ptr track; - std::shared_ptr sender; + std::shared_ptr sender; - ClientTrackData(std::shared_ptr track, std::shared_ptr sender); + ClientTrackData(std::shared_ptr track, std::shared_ptr sender); }; struct Client { diff --git a/examples/streamer/main.cpp b/examples/streamer/main.cpp index e0a3986..b9c2954 100644 --- a/examples/streamer/main.cpp +++ b/examples/streamer/main.cpp @@ -217,9 +217,9 @@ shared_ptr addVideo(const shared_ptr pc, const video.addSSRC(ssrc, cname, msid); auto track = pc->addTrack(video); // create RTP configuration - auto rtpConfig = shared_ptr(new RTPPacketizationConfig(ssrc, cname, payloadType, H264RTPPacketizer::defaultClockRate)); + auto rtpConfig = shared_ptr(new RtpPacketizationConfig(ssrc, cname, payloadType, H264RtpPacketizer::defaultClockRate)); // create packetizer - auto packetizer = shared_ptr(new H264RTPPacketizer(rtpConfig)); + auto packetizer = shared_ptr(new H264RtpPacketizer(rtpConfig)); // create H264 and RTCP SP handler shared_ptr h264Handler(new H264PacketizationHandler(H264PacketizationHandler::Separator::Length, packetizer)); // set handler @@ -235,9 +235,9 @@ shared_ptr addAudio(const shared_ptr pc, const audio.addSSRC(ssrc, cname, msid); auto track = pc->addTrack(audio); // create RTP configuration - auto rtpConfig = shared_ptr(new RTPPacketizationConfig(ssrc, cname, payloadType, OpusRTPPacketizer::defaultClockRate)); + auto rtpConfig = shared_ptr(new RtpPacketizationConfig(ssrc, cname, payloadType, OpusRtpPacketizer::defaultClockRate)); // create packetizer - auto packetizer = make_shared(rtpConfig); + auto packetizer = make_shared(rtpConfig); // create opus and RTCP SP handler auto opusHandler = make_shared(packetizer); // set handler @@ -449,8 +449,8 @@ void addToStream(shared_ptr client, bool isAddingVideo) { auto currentTime_s = currentTime_us / (1000 * 1000); // set start time of stream - video->sender->rtpConfig->setStartTime(currentTime_s, RTPPacketizationConfig::EpochStart::T1970); - audio->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); // start stat recording of RTCP SR video->sender->startRecording(); diff --git a/include/rtc/h264packetizationhandler.hpp b/include/rtc/h264packetizationhandler.hpp index c0bcf97..06b50bb 100644 --- a/include/rtc/h264packetizationhandler.hpp +++ b/include/rtc/h264packetizationhandler.hpp @@ -16,22 +16,22 @@ * along with this program; If not, see . */ -#ifndef H264PacketizationHandler_hpp -#define H264PacketizationHandler_hpp +#ifndef H264_PACKETIZATION_HANDLER_H +#define H264_PACKETIZATION_HANDLER_H #if RTC_ENABLE_MEDIA #include "h264rtppacketizer.hpp" #include "nalunit.hpp" -#include "rtcp.hpp" -#include "rtcpsenderreportable.hpp" +#include "rtcphandler.hpp" +#include "rtcpsenderreporter.hpp" namespace rtc { /// 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 - const std::shared_ptr packetizer; + const std::shared_ptr packetizer; const uint16_t maximumFragmentSize; @@ -49,7 +49,7 @@ public: /// Construct handler for H264 packetization. /// @param separator Nal units separator /// @param packetizer RTP packetizer for h264 - H264PacketizationHandler(Separator separator, std::shared_ptr packetizer, + H264PacketizationHandler(Separator separator, std::shared_ptr packetizer, uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize); /// Returns message unchanged @@ -73,4 +73,4 @@ private: #endif /* RTC_ENABLE_MEDIA */ -#endif /* H264PacketizationHandler_hpp */ +#endif /* H264_PACKETIZATION_HANDLER_H */ diff --git a/include/rtc/h264rtppacketizer.hpp b/include/rtc/h264rtppacketizer.hpp index 3e2e804..0741208 100644 --- a/include/rtc/h264rtppacketizer.hpp +++ b/include/rtc/h264rtppacketizer.hpp @@ -16,8 +16,8 @@ * along with this program; If not, see . */ -#ifndef H264RTPPacketizer_hpp -#define H264RTPPacketizer_hpp +#ifndef H264RtpPacketizer_hpp +#define H264RtpPacketizer_hpp #if RTC_ENABLE_MEDIA @@ -26,7 +26,7 @@ namespace rtc { /// RTP packetization of h264 payload -class RTC_CPP_EXPORT H264RTPPacketizer : public rtc::RTPPacketizer { +class RTC_CPP_EXPORT H264RtpPacketizer : public RtpPacketizer { public: /// 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 /// properties such as sequence number. /// @param rtpConfig RTP configuration - H264RTPPacketizer(std::shared_ptr rtpConfig); + H264RtpPacketizer(std::shared_ptr rtpConfig); }; } // namespace rtc #endif /* RTC_ENABLE_MEDIA */ -#endif /* H264RTPPacketizer_hpp */ +#endif /* H264RtpPacketizer_hpp */ diff --git a/include/rtc/nalunit.hpp b/include/rtc/nalunit.hpp index 1ea40e3..e309e49 100644 --- a/include/rtc/nalunit.hpp +++ b/include/rtc/nalunit.hpp @@ -60,22 +60,22 @@ private: #pragma pack(pop) /// Nal unit -struct RTC_CPP_EXPORT NalUnit : rtc::binary { +struct RTC_CPP_EXPORT NalUnit : binary { NalUnit(const NalUnit &unit) = default; NalUnit(size_t size, bool includingHeader = true) - : rtc::binary(size + (includingHeader ? 0 : 1)) {} + : binary(size + (includingHeader ? 0 : 1)) {} template - 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(); } uint8_t nri() { return header()->nri(); } uint8_t unitType() { return header()->unitType(); } - rtc::binary payload() { + binary payload() { assert(size() >= 1); return {begin() + 1, end()}; } @@ -83,7 +83,7 @@ struct RTC_CPP_EXPORT NalUnit : rtc::binary { void setForbiddenBit(bool isSet) { header()->setForbiddenBit(isSet); } void setNRI(uint8_t nri) { header()->setNRI(nri); } void setUnitType(uint8_t type) { header()->setUnitType(type); } - void setPayload(rtc::binary payload) { + void setPayload(binary payload) { assert(size() >= 1); erase(begin() + 1, end()); insert(end(), payload.begin(), payload.end()); @@ -101,13 +101,13 @@ struct RTC_CPP_EXPORT NalUnitFragmentA : NalUnit { enum class FragmentType { Start, Middle, End }; NalUnitFragmentA(FragmentType type, bool forbiddenBit, uint8_t nri, uint8_t unitType, - rtc::binary data); + binary data); static std::vector fragmentsFrom(NalUnit nalu, uint16_t maximumFragmentSize); uint8_t unitType() { return fragmentHeader()->unitType(); } - rtc::binary payload() { + binary payload() { assert(size() >= 2); return {begin() + 2, end()}; } @@ -124,7 +124,7 @@ struct RTC_CPP_EXPORT NalUnitFragmentA : NalUnit { void setUnitType(uint8_t type) { fragmentHeader()->setUnitType(type); } - void setPayload(rtc::binary payload) { + void setPayload(binary payload) { assert(size() >= 2); erase(begin() + 2, end()); insert(end(), payload.begin(), payload.end()); @@ -145,7 +145,7 @@ protected: class RTC_CPP_EXPORT NalUnits : public std::vector { public: static const uint16_t defaultMaximumFragmentSize = 1400; - std::vector + std::vector generateFragments(uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize); }; diff --git a/include/rtc/opuspacketizationhandler.hpp b/include/rtc/opuspacketizationhandler.hpp index 7191a76..ff9c89a 100644 --- a/include/rtc/opuspacketizationhandler.hpp +++ b/include/rtc/opuspacketizationhandler.hpp @@ -16,26 +16,26 @@ * along with this program; If not, see . */ -#ifndef OpusPacketizationHandler_hpp -#define OpusPacketizationHandler_hpp +#ifndef RTC_OPUS_PACKETIZATION_HANDLER_H +#define RTC_OPUS_PACKETIZATION_HANDLER_H #if RTC_ENABLE_MEDIA #include "opusrtppacketizer.hpp" -#include "rtcp.hpp" -#include "rtcpsenderreportable.hpp" +#include "rtcphandler.hpp" +#include "rtcpsenderreporter.hpp" namespace rtc { /// 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 - const std::shared_ptr packetizer; + const std::shared_ptr packetizer; public: /// Construct handler for opus packetization. /// @param packetizer RTP packetizer for opus - OpusPacketizationHandler(std::shared_ptr packetizer); + OpusPacketizationHandler(std::shared_ptr packetizer); /// Returns message unchanged /// @param ptr message @@ -49,4 +49,4 @@ public: #endif /* RTC_ENABLE_MEDIA */ -#endif /* OpusPacketizationHandler_hpp */ +#endif /* RTC_OPUS_PACKETIZATION_HANDLER_H */ diff --git a/include/rtc/opusrtppacketizer.hpp b/include/rtc/opusrtppacketizer.hpp index 510b020..b47b90d 100644 --- a/include/rtc/opusrtppacketizer.hpp +++ b/include/rtc/opusrtppacketizer.hpp @@ -16,8 +16,8 @@ * along with this program; If not, see . */ -#ifndef OpusRTPPacketizer_hpp -#define OpusRTPPacketizer_hpp +#ifndef RTC_OPUS_RTP_PACKETIZER_H +#define RTC_OPUS_RTP_PACKETIZER_H #if RTC_ENABLE_MEDIA @@ -26,7 +26,7 @@ namespace rtc { /// RTP packetizer for opus -class RTC_CPP_EXPORT OpusRTPPacketizer : public rtc::RTPPacketizer { +class RTC_CPP_EXPORT OpusRtpPacketizer : public RtpPacketizer { public: /// 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 /// properties such as sequence number. /// @param rtpConfig RTP configuration - OpusRTPPacketizer(std::shared_ptr rtpConfig); + OpusRtpPacketizer(std::shared_ptr rtpConfig); /// Creates RTP packet for given payload based on `rtpConfig`. /// @note This function increase sequence number after packetization. /// @param payload RTP 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 #endif /* RTC_ENABLE_MEDIA */ -#endif /* OpusRTPPacketizer_hpp */ +#endif /* RTC_OPUS_RTP_PACKETIZER_H */ diff --git a/include/rtc/peerconnection.hpp b/include/rtc/peerconnection.hpp index 4f4b5bc..e80528f 100644 --- a/include/rtc/peerconnection.hpp +++ b/include/rtc/peerconnection.hpp @@ -31,6 +31,7 @@ #include "track.hpp" #include +#include #include #include #include diff --git a/include/rtc/rtc.h b/include/rtc/rtc.h index 27650d2..52ec440 100644 --- a/include/rtc/rtc.h +++ b/include/rtc/rtc.h @@ -282,7 +282,7 @@ int rtcSetTrackRTPTimestamp(int id, uint32_t timestamp); /// @param timestamp Pointer for result 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 int rtcSetNeedsToSendRTCPSR(int id); diff --git a/include/rtc/rtc.hpp b/include/rtc/rtc.hpp index f945817..1019c78 100644 --- a/include/rtc/rtc.hpp +++ b/include/rtc/rtc.hpp @@ -27,11 +27,14 @@ #if RTC_ENABLE_MEDIA -// opus/h264 streaming +// RTCP handling +#include "rtcpreceivingsession.hpp" + +// Opus/h264 streaming #include "h264packetizationhandler.hpp" #include "opuspacketizationhandler.hpp" -#endif /* RTC_ENABLE_MEDIA */ +#endif // RTC_ENABLE_MEDIA // C API #include "rtc.h" diff --git a/include/rtc/rtcphandler.hpp b/include/rtc/rtcphandler.hpp new file mode 100644 index 0000000..2c7ee3e --- /dev/null +++ b/include/rtc/rtcphandler.hpp @@ -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 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 &cb) { + this->outgoingCallback = synchronized_callback(cb); + } + + virtual bool requestKeyframe() { return false; } +}; + +} // namespace rtc + +#endif // RTC_RTCP_HANDLER_H diff --git a/include/rtc/rtcp.hpp b/include/rtc/rtcpreceivingsession.hpp similarity index 57% rename from include/rtc/rtcp.hpp rename to include/rtc/rtcpreceivingsession.hpp index 04aed8f..2e2595a 100644 --- a/include/rtc/rtcp.hpp +++ b/include/rtc/rtcpreceivingsession.hpp @@ -17,58 +17,24 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef RTC_RTCP_H -#define RTC_RTCP_H +#ifndef RTC_RTCP_RECEIVING_SESSION_H +#define RTC_RTCP_RECEIVING_SESSION_H -#include +#if RTC_ENABLE_MEDIA #include "include.hpp" -#include "log.hpp" +#include "rtcphandler.hpp" #include "message.hpp" #include "rtp.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 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 &cb); - - virtual bool requestKeyframe() { return false; } -}; - -class Track; - // An RtcpSession can be plugged into a Track to handle the whole RTCP session class RTC_CPP_EXPORT RtcpReceivingSession : public RtcpHandler { public: - rtc::message_ptr incoming(rtc::message_ptr ptr) override; - rtc::message_ptr outgoing(rtc::message_ptr ptr) override; - bool send(rtc::message_ptr ptr); + message_ptr incoming(message_ptr ptr) override; + message_ptr outgoing(message_ptr ptr) override; + bool send(message_ptr ptr); void requestBitrate(unsigned int newBitrate); @@ -88,4 +54,6 @@ protected: } // namespace rtc -#endif // RTC_RTCP_H +#endif // RTC_ENABLE_MEDIA + +#endif // RTC_RTCP_RECEIVING_SESSION_H diff --git a/include/rtc/rtcpsenderreportable.hpp b/include/rtc/rtcpsenderreporter.hpp similarity index 90% rename from include/rtc/rtcpsenderreportable.hpp rename to include/rtc/rtcpsenderreporter.hpp index 9303ac3..2aad1c2 100644 --- a/include/rtc/rtcpsenderreportable.hpp +++ b/include/rtc/rtcpsenderreporter.hpp @@ -16,8 +16,8 @@ * along with this program; If not, see . */ -#ifndef RTCPSenderReporter_hpp -#define RTCPSenderReporter_hpp +#ifndef RTC_RTCP_SENDER_REPORTABLE_H +#define RTC_RTCP_SENDER_REPORTABLE_H #if RTC_ENABLE_MEDIA @@ -27,7 +27,7 @@ namespace rtc { /// Class for sending RTCP SR -class RTC_CPP_EXPORT RTCPSenderReportable { +class RTC_CPP_EXPORT RtcpSenderReporter { bool needsToReport = false; uint32_t packetCount = 0; @@ -50,9 +50,9 @@ public: const uint32_t &previousReportedTimestamp = _previousReportedTimestamp; /// RTP configuration - const std::shared_ptr rtpConfig; + const std::shared_ptr rtpConfig; - RTCPSenderReportable(std::shared_ptr rtpConfig); + RtcpSenderReporter(std::shared_ptr rtpConfig); /// Set `needsToReport` flag. Sender report will be sent before next RTP packet with same /// timestamp. @@ -90,4 +90,4 @@ protected: #endif /* RTC_ENABLE_MEDIA */ -#endif /* RTCPSenderReporter_hpp */ +#endif /* RTC_RTCP_SENDER_REPORTABLE_H */ diff --git a/include/rtc/rtppacketizationconfig.hpp b/include/rtc/rtppacketizationconfig.hpp index 5a871b6..0f5ed0e 100644 --- a/include/rtc/rtppacketizationconfig.hpp +++ b/include/rtc/rtppacketizationconfig.hpp @@ -16,8 +16,8 @@ * along with this program; If not, see . */ -#ifndef RTPPacketizationConfig_hpp -#define RTPPacketizationConfig_hpp +#ifndef RTC_RTP_PACKETIZATION_CONFIG_H +#define RTC_RTP_PACKETIZATION_CONFIG_H #if RTC_ENABLE_MEDIA @@ -26,10 +26,10 @@ namespace rtc { /// RTP configuration used in packetization process -class RTC_CPP_EXPORT RTPPacketizationConfig { +class RTC_CPP_EXPORT RtpPacketizationConfig { uint32_t _startTimestamp = 0; double _startTime_s = 0; - RTPPacketizationConfig(const RTPPacketizationConfig &) = delete; + RtpPacketizationConfig(const RtpPacketizationConfig &) = delete; public: const SSRC ssrc; @@ -65,7 +65,7 @@ public: /// @param sequenceNumber Initial sequence number 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 sequenceNumber = std::nullopt, std::optional timestamp = std::nullopt); @@ -92,4 +92,4 @@ public: #endif /* RTC_ENABLE_MEDIA */ -#endif /* RTPPacketizationConfig_hpp */ +#endif /* RTC_RTP_PACKETIZATION_CONFIG_H */ diff --git a/include/rtc/rtppacketizer.hpp b/include/rtc/rtppacketizer.hpp index 4ebdd82..85fabda 100644 --- a/include/rtc/rtppacketizer.hpp +++ b/include/rtc/rtppacketizer.hpp @@ -16,8 +16,8 @@ * along with this program; If not, see . */ -#ifndef RTPPacketizer_hpp -#define RTPPacketizer_hpp +#ifndef RTC_RTP_PACKETIZER_H +#define RTC_RTP_PACKETIZER_H #if RTC_ENABLE_MEDIA @@ -26,19 +26,19 @@ namespace rtc { -/// Class responsizble for rtp packetization -class RTC_CPP_EXPORT RTPPacketizer { +/// Class responsible for RTP packetization +class RTC_CPP_EXPORT RtpPacketizer { static const auto rtpHeaderSize = 12; public: - // rtp configuration - const std::shared_ptr rtpConfig; + // RTP configuration + const std::shared_ptr rtpConfig; /// Constructs packetizer with given RTP configuration. /// @note RTP configuration is used in packetization process which may change some configuration /// properties such as sequence number. /// @param rtpConfig RTP configuration - RTPPacketizer(std::shared_ptr rtpConfig); + RtpPacketizer(std::shared_ptr rtpConfig); /// Creates RTP packet for given payload based on `rtpConfig`. /// @note This function increase sequence number after packetization. @@ -51,4 +51,4 @@ public: #endif /* RTC_ENABLE_MEDIA */ -#endif /* RTPPacketizer_hpp */ +#endif /* RTC_RTP_PACKETIZER_H */ diff --git a/include/rtc/track.hpp b/include/rtc/track.hpp index 21d9a07..a6c0636 100644 --- a/include/rtc/track.hpp +++ b/include/rtc/track.hpp @@ -24,7 +24,7 @@ #include "include.hpp" #include "message.hpp" #include "queue.hpp" -#include "rtcp.hpp" +#include "rtcphandler.hpp" #include #include diff --git a/src/capi.cpp b/src/capi.cpp index f409be8..2247ee0 100644 --- a/src/capi.cpp +++ b/src/capi.cpp @@ -53,8 +53,8 @@ std::unordered_map> peerConnectionMap; std::unordered_map> dataChannelMap; std::unordered_map> trackMap; #if RTC_ENABLE_MEDIA -std::unordered_map> rtcpSenderMap; -std::unordered_map> rtpConfigMap; +std::unordered_map> rtcpSenderMap; +std::unordered_map> rtpConfigMap; #endif #if RTC_ENABLE_WEBSOCKET std::unordered_map> webSocketMap; @@ -149,20 +149,20 @@ void eraseTrack(int tr) { #if RTC_ENABLE_MEDIA -shared_ptr getRTCPSender(int id) { +shared_ptr getRTCPSender(int id) { std::lock_guard lock(mutex); if (auto it = rtcpSenderMap.find(id); it != rtcpSenderMap.end()) return it->second; else - throw std::invalid_argument("RTCPSenderReportable ID does not exist"); + throw std::invalid_argument("RtcpSenderReporter ID does not exist"); } -void emplaceRTCPSender(shared_ptr ptr, int tr) { +void emplaceRTCPSender(shared_ptr ptr, int tr) { std::lock_guard lock(mutex); rtcpSenderMap.emplace(std::make_pair(tr, ptr)); } -shared_ptr getRTPConfig(int id) { +shared_ptr getRTPConfig(int id) { std::lock_guard lock(mutex); if (auto it = rtpConfigMap.find(id); it != rtpConfigMap.end()) return it->second; @@ -170,7 +170,7 @@ shared_ptr getRTPConfig(int id) { throw std::invalid_argument("RTPConfiguration ID does not exist"); } -void emplaceRTPConfig(shared_ptr ptr, int tr) { +void emplaceRTPConfig(shared_ptr ptr, int tr) { std::lock_guard lock(mutex); rtpConfigMap.emplace(std::make_pair(tr, ptr)); } @@ -190,14 +190,14 @@ Description::Direction rtcDirectionToDirection(rtcDirection direction) { } } -shared_ptr -getNewRTPPacketizationConfig(uint32_t ssrc, const char *cname, uint8_t payloadType, +shared_ptr +getNewRtpPacketizationConfig(uint32_t ssrc, const char *cname, uint8_t payloadType, uint32_t clockRate, uint16_t sequenceNumber, uint32_t timestamp) { if (!cname) { throw std::invalid_argument("Unexpected null pointer for cname"); } - return std::make_shared(ssrc, cname, payloadType, clockRate, + return std::make_shared(ssrc, cname, payloadType, clockRate, sequenceNumber, timestamp); } @@ -533,10 +533,10 @@ int rtcSetH264PacketizationHandler(int tr, uint32_t ssrc, const char *cname, uin return WRAP({ auto track = getTrack(tr); // create RTP configuration - auto rtpConfig = getNewRTPPacketizationConfig(ssrc, cname, payloadType, clockRate, + auto rtpConfig = getNewRtpPacketizationConfig(ssrc, cname, payloadType, clockRate, sequenceNumber, timestamp); // create packetizer - auto packetizer = shared_ptr(new H264RTPPacketizer(rtpConfig)); + auto packetizer = shared_ptr(new H264RtpPacketizer(rtpConfig)); // create H264 and RTCP SP handler shared_ptr h264Handler( new H264PacketizationHandler(H264PacketizationHandler::Separator::Length, packetizer, maxFragmentSize)); @@ -553,10 +553,10 @@ int rtcSetOpusPacketizationHandler(int tr, uint32_t ssrc, const char *cname, uin return WRAP({ auto track = getTrack(tr); // create RTP configuration - auto rtpConfig = getNewRTPPacketizationConfig(ssrc, cname, payloadType, clockRate, + auto rtpConfig = getNewRtpPacketizationConfig(ssrc, cname, payloadType, clockRate, sequenceNumber, timestamp); // create packetizer - auto packetizer = shared_ptr(new OpusRTPPacketizer(rtpConfig)); + auto packetizer = shared_ptr(new OpusRtpPacketizer(rtpConfig)); // create Opus and RTCP SP handler shared_ptr opusHandler(new OpusPacketizationHandler(packetizer)); emplaceRTCPSender(opusHandler, tr); @@ -570,9 +570,9 @@ int rtcSetRtpConfigurationStartTime(int id, double startTime_s, bool timeInterva uint32_t timestamp) { return WRAP({ auto config = getRTPConfig(id); - auto epoch = RTPPacketizationConfig::EpochStart::T1900; + auto epoch = RtpPacketizationConfig::EpochStart::T1900; if (timeIntervalSince1970) { - epoch = RTPPacketizationConfig::EpochStart::T1970; + epoch = RtpPacketizationConfig::EpochStart::T1970; } config->setStartTime(startTime_s, epoch, timestamp); }); diff --git a/src/datachannel.cpp b/src/datachannel.cpp index 93c1e95..98b0d45 100644 --- a/src/datachannel.cpp +++ b/src/datachannel.cpp @@ -28,10 +28,11 @@ #include #endif -rtc::LogCounter COUNTER_USERNEG_OPEN_MESSAGE( - plog::warning, "Number of open messages for a user-negotiated DataChannel received"); 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::weak_ptr; using std::chrono::milliseconds; diff --git a/src/dtlssrtptransport.cpp b/src/dtlssrtptransport.cpp index 3232c36..aa02a75 100644 --- a/src/dtlssrtptransport.cpp +++ b/src/dtlssrtptransport.cpp @@ -29,29 +29,29 @@ using std::shared_ptr; using std::to_integer; 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"); -static rtc::LogCounter +static LogCounter COUNTER_UNKNOWN_PACKET_TYPE(plog::warning, "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"); -static rtc::LogCounter +static LogCounter COUNTER_SRTCP_AUTH_FAIL(plog::warning, "Number of SRTCP packets received that failed authentication checks"); -static rtc::LogCounter +static LogCounter COUNTER_SRTCP_FAIL(plog::warning, "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 rtc::LogCounter +static LogCounter COUNTER_SRTP_REPLAY(plog::warning, "Number of SRTP replay packets received"); +static LogCounter COUNTER_SRTP_AUTH_FAIL(plog::warning, "Number of SRTP packets received that failed authentication checks"); static rtc::LogCounter COUNTER_SRTP_FAIL(plog::warning, "Number of SRTP packets received that had an unknown libSRTP failure"); -namespace rtc { - void DtlsSrtpTransport::Init() { srtp_init(); } void DtlsSrtpTransport::Cleanup() { srtp_shutdown(); } diff --git a/src/h264packetizationhandler.cpp b/src/h264packetizationhandler.cpp index a0208d2..a391de9 100644 --- a/src/h264packetizationhandler.cpp +++ b/src/h264packetizationhandler.cpp @@ -76,7 +76,7 @@ NalUnitStartSequenceMatch StartSequenceMatchSucc(NalUnitStartSequenceMatch match message_ptr H264PacketizationHandler::incoming(message_ptr ptr) { return ptr; } -shared_ptr H264PacketizationHandler::splitMessage(rtc::message_ptr message) { +shared_ptr H264PacketizationHandler::splitMessage(message_ptr message) { auto nalus = make_shared(); if (separator == Separator::Length) { unsigned long long index = 0; @@ -155,9 +155,9 @@ message_ptr H264PacketizationHandler::outgoing(message_ptr ptr) { } H264PacketizationHandler::H264PacketizationHandler(Separator separator, - std::shared_ptr packetizer, + std::shared_ptr packetizer, uint16_t maximumFragmentSize) - : RtcpHandler(), rtc::RTCPSenderReportable(packetizer->rtpConfig), packetizer(packetizer), + : RtcpHandler(), RtcpSenderReporter(packetizer->rtpConfig), packetizer(packetizer), maximumFragmentSize(maximumFragmentSize), separator(separator) { senderReportOutgoingCallback = [this](message_ptr msg) { outgoingCallback(msg); }; diff --git a/src/h264rtppacketizer.cpp b/src/h264rtppacketizer.cpp index 3eabef8..0c2e681 100644 --- a/src/h264rtppacketizer.cpp +++ b/src/h264rtppacketizer.cpp @@ -22,8 +22,8 @@ namespace rtc { -H264RTPPacketizer::H264RTPPacketizer(std::shared_ptr rtpConfig) - : RTPPacketizer(rtpConfig) {} +H264RtpPacketizer::H264RtpPacketizer(std::shared_ptr rtpConfig) + : RtpPacketizer(rtpConfig) {} } // namespace rtc diff --git a/src/logcounter.cpp b/src/logcounter.cpp index ae3e562..dd226f5 100644 --- a/src/logcounter.cpp +++ b/src/logcounter.cpp @@ -18,15 +18,17 @@ #include "logcounter.hpp" -rtc::LogCounter::LogCounter(plog::Severity severity, const std::string &text, - std::chrono::seconds duration) { +namespace rtc { + +LogCounter::LogCounter(plog::Severity severity, const std::string &text, + std::chrono::seconds duration) { mData = std::make_shared(); mData->mDuration = duration; mData->mSeverity = severity; mData->mText = text; } -rtc::LogCounter &rtc::LogCounter::operator++(int) { +LogCounter &LogCounter::operator++(int) { if (mData->mCount++ == 0) { ThreadPool::Instance().schedule( mData->mDuration, @@ -43,4 +45,6 @@ rtc::LogCounter &rtc::LogCounter::operator++(int) { mData); } return *this; -} \ No newline at end of file +} + +} // namespace rtc diff --git a/src/logcounter.hpp b/src/logcounter.hpp index d34407a..cd0e0bd 100644 --- a/src/logcounter.hpp +++ b/src/logcounter.hpp @@ -16,13 +16,17 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef WEBRTC_SERVER_LOGCOUNTER_HPP -#define WEBRTC_SERVER_LOGCOUNTER_HPP +#ifndef RTC_SERVER_LOGCOUNTER_HPP +#define RTC_SERVER_LOGCOUNTER_HPP #include "include.hpp" #include "threadpool.hpp" +#include +#include + namespace rtc { + class LogCounter { private: struct LogData { @@ -41,6 +45,7 @@ public: LogCounter &operator++(int); }; + } // namespace rtc -#endif // WEBRTC_SERVER_LOGCOUNTER_HPP +#endif // RTC_SERVER_LOGCOUNTER_HPP diff --git a/src/opuspacketizationhandler.cpp b/src/opuspacketizationhandler.cpp index b14987f..e058fdd 100644 --- a/src/opuspacketizationhandler.cpp +++ b/src/opuspacketizationhandler.cpp @@ -22,8 +22,8 @@ namespace rtc { -OpusPacketizationHandler::OpusPacketizationHandler(std::shared_ptr packetizer) - : RtcpHandler(), RTCPSenderReportable(packetizer->rtpConfig), packetizer(packetizer) { +OpusPacketizationHandler::OpusPacketizationHandler(std::shared_ptr packetizer) + : RtcpHandler(), RtcpSenderReporter(packetizer->rtpConfig), packetizer(packetizer) { senderReportOutgoingCallback = [this](message_ptr msg) { outgoingCallback(msg); }; } diff --git a/src/opusrtppacketizer.cpp b/src/opusrtppacketizer.cpp index 0c0fcec..aa9fce0 100644 --- a/src/opusrtppacketizer.cpp +++ b/src/opusrtppacketizer.cpp @@ -22,12 +22,12 @@ namespace rtc { -OpusRTPPacketizer::OpusRTPPacketizer(std::shared_ptr rtpConfig) - : RTPPacketizer(rtpConfig) {} +OpusRtpPacketizer::OpusRtpPacketizer(std::shared_ptr rtpConfig) + : RtpPacketizer(rtpConfig) {} -message_ptr OpusRTPPacketizer::packetize(binary payload, bool setMark) { +message_ptr OpusRtpPacketizer::packetize(binary payload, bool setMark) { assert(!setMark); - return RTPPacketizer::packetize(payload, false); + return RtpPacketizer::packetize(payload, false); } } // namespace rtc diff --git a/src/peerconnection.cpp b/src/peerconnection.cpp index 626205e..3dc9f1a 100644 --- a/src/peerconnection.cpp +++ b/src/peerconnection.cpp @@ -23,6 +23,7 @@ #include "logcounter.hpp" #include "processor.hpp" #include "threadpool.hpp" +#include "rtp.hpp" #include "dtlstransport.hpp" #include "icetransport.hpp" diff --git a/src/rtcp.cpp b/src/rtcpreceivingsession.cpp similarity index 72% rename from src/rtcp.cpp rename to src/rtcpreceivingsession.cpp index 1f92658..b4ae27f 100644 --- a/src/rtcp.cpp +++ b/src/rtcpreceivingsession.cpp @@ -17,10 +17,12 @@ * 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 "track.hpp" + #include #include @@ -30,18 +32,17 @@ #include #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 { -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) { - if (ptr->type == rtc::Message::Type::Binary) { +message_ptr RtcpReceivingSession::outgoing(message_ptr ptr) { return ptr; } + +message_ptr RtcpReceivingSession::incoming(message_ptr ptr) { + if (ptr->type == Message::Type::Binary) { auto rtp = reinterpret_cast(ptr->data()); // https://tools.ietf.org/html/rfc3550#appendix-A.1 @@ -65,7 +66,7 @@ rtc::message_ptr RtcpReceivingSession::incoming(rtc::message_ptr ptr) { return ptr; } - assert(ptr->type == rtc::Message::Type::Control); + assert(ptr->type == Message::Type::Control); auto rr = reinterpret_cast(ptr->data()); if (rr->header.payloadType() == 201) { // RR @@ -95,8 +96,7 @@ void RtcpReceivingSession::requestBitrate(unsigned int newBitrate) { } void RtcpReceivingSession::pushREMB(unsigned int bitrate) { - rtc::message_ptr msg = - rtc::make_message(RTCP_REMB::sizeWithSSRCs(1), rtc::Message::Type::Control); + message_ptr msg = make_message(RTCP_REMB::sizeWithSSRCs(1), Message::Type::Control); auto remb = reinterpret_cast(msg->data()); remb->preparePacket(mSsrc, 1, bitrate); remb->setSsrc(0, mSsrc); @@ -105,7 +105,7 @@ void RtcpReceivingSession::pushREMB(unsigned int bitrate) { } 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(msg->data()); rr->preparePacket(mSsrc, 1); rr->getReportBlock(0)->preparePacket(mSsrc, 0, 0, uint16_t(mGreatestSeqNo), 0, 0, mSyncNTPTS, @@ -131,13 +131,12 @@ bool RtcpReceivingSession::requestKeyframe() { } void RtcpReceivingSession::pushPLI() { - auto msg = rtc::make_message(rtc::RTCP_PLI::size(), rtc::Message::Type::Control); - auto *pli = reinterpret_cast(msg->data()); + auto msg = make_message(RTCP_PLI::size(), Message::Type::Control); + auto *pli = reinterpret_cast(msg->data()); pli->preparePacket(mSsrc); send(msg); } -void RtcpHandler::onOutgoing(const std::function &cb) { - this->outgoingCallback = synchronized_callback(cb); -} } // namespace rtc + +#endif // RTC_ENABLE_MEDIA diff --git a/src/rtcpsenderreportable.cpp b/src/rtcpsenderreporter.cpp similarity index 80% rename from src/rtcpsenderreportable.cpp rename to src/rtcpsenderreporter.cpp index f48e751..2fcc175 100644 --- a/src/rtcpsenderreportable.cpp +++ b/src/rtcpsenderreporter.cpp @@ -18,37 +18,37 @@ #if RTC_ENABLE_MEDIA -#include "rtcpsenderreportable.hpp" +#include "rtcpsenderreporter.hpp" namespace rtc { -void RTCPSenderReportable::startRecording() { +void RtcpSenderReporter::startRecording() { _previousReportedTimestamp = 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); _previousReportedTimestamp = timestamp; senderReportOutgoingCallback(move(sr)); } -void RTCPSenderReportable::addToReport(RTP *rtp, uint32_t rtpSize) { +void RtcpSenderReporter::addToReport(RTP *rtp, uint32_t rtpSize) { packetCount += 1; assert(!rtp->padding()); payloadOctets += rtpSize - rtp->getSize(); } -RTCPSenderReportable::RTCPSenderReportable(std::shared_ptr rtpConfig) +RtcpSenderReporter::RtcpSenderReporter(std::shared_ptr rtpConfig) : rtpConfig(rtpConfig) {} -uint64_t RTCPSenderReportable::secondsToNTP(double seconds) { +uint64_t RtcpSenderReporter::secondsToNTP(double seconds) { 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 msg = make_message(srSize + RTCP_SDES::size({{uint8_t(rtpConfig->cname.size())}}), Message::Type::Control); diff --git a/src/rtppacketizationconfig.cpp b/src/rtppacketizationconfig.cpp index 6f1dcd4..09c1fd9 100644 --- a/src/rtppacketizationconfig.cpp +++ b/src/rtppacketizationconfig.cpp @@ -22,7 +22,7 @@ namespace rtc { -RTPPacketizationConfig::RTPPacketizationConfig(SSRC ssrc, string cname, uint8_t payloadType, +RtpPacketizationConfig::RtpPacketizationConfig(SSRC ssrc, string cname, uint8_t payloadType, uint32_t clockRate, std::optional sequenceNumber, std::optional timestamp) @@ -42,7 +42,7 @@ RTPPacketizationConfig::RTPPacketizationConfig(SSRC ssrc, string cname, uint8_t this->_startTimestamp = this->timestamp; } -void RTPPacketizationConfig::setStartTime(double startTime_s, EpochStart epochStart, +void RtpPacketizationConfig::setStartTime(double startTime_s, EpochStart epochStart, std::optional startTimestamp) { this->_startTime_s = startTime_s + static_cast(epochStart); 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); } -double RTPPacketizationConfig::timestampToSeconds(uint32_t timestamp) { - return RTPPacketizationConfig::getSecondsFromTimestamp(timestamp, clockRate); +double RtpPacketizationConfig::timestampToSeconds(uint32_t timestamp) { + 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); } -uint32_t RTPPacketizationConfig::secondsToTimestamp(double seconds) { - return RTPPacketizationConfig::getTimestampFromSeconds(seconds, clockRate); +uint32_t RtpPacketizationConfig::secondsToTimestamp(double seconds) { + return RtpPacketizationConfig::getTimestampFromSeconds(seconds, clockRate); } } // namespace rtc diff --git a/src/rtppacketizer.cpp b/src/rtppacketizer.cpp index d8163f2..1e92c10 100644 --- a/src/rtppacketizer.cpp +++ b/src/rtppacketizer.cpp @@ -22,10 +22,10 @@ namespace rtc { -RTPPacketizer::RTPPacketizer(std::shared_ptr rtpConfig) +RtpPacketizer::RtpPacketizer(std::shared_ptr 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 *rtp = (RTP *)msg->data(); rtp->setPayloadType(rtpConfig->payloadType); diff --git a/src/sctptransport.cpp b/src/sctptransport.cpp index 8e01563..994eb20 100644 --- a/src/sctptransport.cpp +++ b/src/sctptransport.cpp @@ -56,15 +56,15 @@ using namespace std::chrono; using std::shared_ptr; -static rtc::LogCounter COUNTER_UNKNOWN_PPID(plog::warning, - "Number of SCTP packets received with an unknown PPID"); -static rtc::LogCounter +namespace rtc { + +static LogCounter COUNTER_UNKNOWN_PPID(plog::warning, + "Number of SCTP packets received with an unknown PPID"); +static LogCounter COUNTER_BAD_NOTIF_LEN(plog::warning, "Number of SCTP packets received with an bad notification length"); -static rtc::LogCounter COUNTER_BAD_SCTP_STATUS(plog::warning, - "Number of SCTP packets received with a bad status"); - -namespace rtc { +static LogCounter COUNTER_BAD_SCTP_STATUS(plog::warning, + "Number of SCTP packets received with a bad status"); std::unordered_set SctpTransport::Instances; std::shared_mutex SctpTransport::InstancesMutex;