Unverified 提交 e3427a6b authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

C++: Remove inline methods (#371)

Instead, directly define the method in the method declaration within the class declaration.
上级 1ad97057
...@@ -314,11 +314,6 @@ ...@@ -314,11 +314,6 @@
"directory": "PATH/out", "directory": "PATH/out",
"file": "PATH/src/RTC/WebRtcTransport.cpp" "file": "PATH/src/RTC/WebRtcTransport.cpp"
}, },
{
"command": "c++ -c -DMS_LITTLE_ENDIAN -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -IPATH/include -IPATH/deps/json/single_include/nlohmann -IPATH/deps/netstring/netstring-c -IPATH/deps/libuv/include -IPATH/deps/openssl/openssl/include -IPATH/deps/libsrtp/srtp/include -IPATH/deps/usrsctp/usrsctp/usrsctplib -IPATH/deps/libwebrtc -IPATH/deps/libwebrtc/libwebrtc -IPATH/deps/libwebrtc/deps/abseil-cpp/abseil-cpp -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -m64 -g -Wno-unknown-warning-option -fPIC -o PATH/out/Release/obj.target/mediasoup-worker/src/RTC/Codecs/Codecs.o PATH/src/RTC/Codecs/Codecs.cpp",
"directory": "PATH/out",
"file": "PATH/src/RTC/Codecs/Codecs.cpp"
},
{ {
"command": "c++ -c -DMS_LITTLE_ENDIAN -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -IPATH/include -IPATH/deps/json/single_include/nlohmann -IPATH/deps/netstring/netstring-c -IPATH/deps/libuv/include -IPATH/deps/openssl/openssl/include -IPATH/deps/libsrtp/srtp/include -IPATH/deps/usrsctp/usrsctp/usrsctplib -IPATH/deps/libwebrtc -IPATH/deps/libwebrtc/libwebrtc -IPATH/deps/libwebrtc/deps/abseil-cpp/abseil-cpp -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -m64 -g -Wno-unknown-warning-option -fPIC -o PATH/out/Release/obj.target/mediasoup-worker/src/RTC/Codecs/H264.o PATH/src/RTC/Codecs/H264.cpp", "command": "c++ -c -DMS_LITTLE_ENDIAN -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -IPATH/include -IPATH/deps/json/single_include/nlohmann -IPATH/deps/netstring/netstring-c -IPATH/deps/libuv/include -IPATH/deps/openssl/openssl/include -IPATH/deps/libsrtp/srtp/include -IPATH/deps/usrsctp/usrsctp/usrsctplib -IPATH/deps/libwebrtc -IPATH/deps/libwebrtc/libwebrtc -IPATH/deps/libwebrtc/deps/abseil-cpp/abseil-cpp -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -m64 -g -Wno-unknown-warning-option -fPIC -o PATH/out/Release/obj.target/mediasoup-worker/src/RTC/Codecs/H264.o PATH/src/RTC/Codecs/H264.cpp",
"directory": "PATH/out", "directory": "PATH/out",
...@@ -534,4 +529,4 @@ ...@@ -534,4 +529,4 @@
"directory": "PATH/out", "directory": "PATH/out",
"file": "PATH/src/main.cpp" "file": "PATH/src/main.cpp"
} }
] ]
\ No newline at end of file
...@@ -29,13 +29,14 @@ namespace Channel ...@@ -29,13 +29,14 @@ namespace Channel
// Passed by argument. // Passed by argument.
Listener* listener{ nullptr }; Listener* listener{ nullptr };
// Others. // Others.
size_t msgStart{ 0 }; // Where the latest message starts. size_t msgStart{ 0u }; // Where the latest message starts.
}; };
class ProducerSocket : public ::UnixStreamSocket class ProducerSocket : public ::UnixStreamSocket
{ {
public: public:
ProducerSocket(int fd, size_t bufferSize); ProducerSocket(int fd, size_t bufferSize);
/* Pure virtual methods inherited from ::UnixStreamSocket. */ /* Pure virtual methods inherited from ::UnixStreamSocket. */
public: public:
void UserOnUnixStreamRead() override void UserOnUnixStreamRead() override
......
...@@ -9,24 +9,18 @@ class DepLibSRTP ...@@ -9,24 +9,18 @@ class DepLibSRTP
public: public:
static void ClassInit(); static void ClassInit();
static void ClassDestroy(); static void ClassDestroy();
static bool IsError(srtp_err_status_t code); static bool IsError(srtp_err_status_t code)
static const char* GetErrorString(srtp_err_status_t code); {
return (code != srtp_err_status_ok);
}
static const char* GetErrorString(srtp_err_status_t code)
{
// This throws out_of_range if the given index is not in the vector.
return DepLibSRTP::errors.at(code);
}
private: private:
static std::vector<const char*> errors; static std::vector<const char*> errors;
}; };
/* Inline static methods. */
inline bool DepLibSRTP::IsError(srtp_err_status_t code)
{
return (code != srtp_err_status_ok);
}
inline const char* DepLibSRTP::GetErrorString(srtp_err_status_t code)
{
// This throws out_of_range if the given index is not in the vector.
return DepLibSRTP::errors.at(code);
}
#endif #endif
...@@ -11,35 +11,25 @@ public: ...@@ -11,35 +11,25 @@ public:
static void ClassDestroy(); static void ClassDestroy();
static void PrintVersion(); static void PrintVersion();
static void RunLoop(); static void RunLoop();
static uv_loop_t* GetLoop(); static uv_loop_t* GetLoop()
static uint64_t GetTimeMs(); {
static uint64_t GetTimeUs(); return DepLibUV::loop;
static uint64_t GetTimeNs(); }
static uint64_t GetTimeMs()
{
return static_cast<uint64_t>(uv_hrtime() / 1000000u);
}
static uint64_t GetTimeUs()
{
return static_cast<uint64_t>(uv_hrtime() / 1000u);
}
static uint64_t GetTimeNs()
{
return uv_hrtime();
}
private: private:
static uv_loop_t* loop; static uv_loop_t* loop;
}; };
/* Inline static methods. */
inline uv_loop_t* DepLibUV::GetLoop()
{
return DepLibUV::loop;
}
inline uint64_t DepLibUV::GetTimeMs()
{
return static_cast<uint64_t>(uv_hrtime() / 1000000u);
}
inline uint64_t DepLibUV::GetTimeUs()
{
return static_cast<uint64_t>(uv_hrtime() / 1000u);
}
inline uint64_t DepLibUV::GetTimeNs()
{
return uv_hrtime();
}
#endif #endif
...@@ -8,27 +8,19 @@ ...@@ -8,27 +8,19 @@
class MediaSoupError : public std::runtime_error class MediaSoupError : public std::runtime_error
{ {
public: public:
explicit MediaSoupError(const char* description); explicit MediaSoupError(const char* description) : std::runtime_error(description)
{
}
}; };
/* Inline methods. */
inline MediaSoupError::MediaSoupError(const char* description) : std::runtime_error(description)
{
}
class MediaSoupTypeError : public MediaSoupError class MediaSoupTypeError : public MediaSoupError
{ {
public: public:
explicit MediaSoupTypeError(const char* description); explicit MediaSoupTypeError(const char* description) : MediaSoupError(description)
{
}
}; };
/* Inline methods. */
inline MediaSoupTypeError::MediaSoupTypeError(const char* description) : MediaSoupError(description)
{
}
// clang-format off // clang-format off
#define MS_THROW_ERROR(desc, ...) \ #define MS_THROW_ERROR(desc, ...) \
do \ do \
......
...@@ -15,8 +15,8 @@ namespace RTC ...@@ -15,8 +15,8 @@ namespace RTC
private: private:
struct DBovs struct DBovs
{ {
uint16_t totalSum{ 0 }; // Sum of dBvos (positive integer). uint16_t totalSum{ 0u }; // Sum of dBvos (positive integer).
size_t count{ 0 }; // Number of dBvos entries in totalSum. size_t count{ 0u }; // Number of dBvos entries in totalSum.
}; };
public: public:
...@@ -42,9 +42,9 @@ namespace RTC ...@@ -42,9 +42,9 @@ namespace RTC
private: private:
// Passed by argument. // Passed by argument.
uint16_t maxEntries{ 1 }; uint16_t maxEntries{ 1u };
int8_t threshold{ -80 }; int8_t threshold{ -80 };
uint16_t interval{ 1000 }; uint16_t interval{ 1000u };
// Allocated by this. // Allocated by this.
Timer* periodicTimer{ nullptr }; Timer* periodicTimer{ nullptr };
// Others. // Others.
......
#ifndef MS_RTC_CODECS_HPP
#define MS_RTC_CODECS_HPP
#include "common.hpp"
#include "RTC/Codecs/H264.hpp"
#include "RTC/Codecs/PayloadDescriptorHandler.hpp"
#include "RTC/Codecs/VP8.hpp"
#include "RTC/Codecs/VP9.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
namespace RTC
{
namespace Codecs
{
bool CanBeKeyFrame(const RTC::RtpCodecMimeType& mimeType);
void ProcessRtpPacket(RTC::RtpPacket* packet, const RTC::RtpCodecMimeType& mimeType);
bool IsValidTypeForCodec(RTC::RtpParameters::Type type, const RTC::RtpCodecMimeType& mimeType);
EncodingContext* GetEncodingContext(
const RTC::RtpCodecMimeType& mimeType, uint8_t spatialLayers, uint8_t temporalLayers);
/* Inline namespace methods. */
inline bool CanBeKeyFrame(const RTC::RtpCodecMimeType& mimeType)
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
case RTC::RtpCodecMimeType::Subtype::VP9:
case RTC::RtpCodecMimeType::Subtype::H264:
return true;
default:
return false;
}
}
default:
{
return false;
}
}
}
inline bool IsValidTypeForCodec(RTC::RtpParameters::Type type, const RTC::RtpCodecMimeType& mimeType)
{
switch (type)
{
case RTC::RtpParameters::Type::NONE:
{
return false;
}
case RTC::RtpParameters::Type::SIMPLE:
{
return true;
}
case RTC::RtpParameters::Type::SIMULCAST:
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
case RTC::RtpCodecMimeType::Subtype::H264:
return true;
default:
return false;
}
}
default:
{
return false;
}
}
}
case RTC::RtpParameters::Type::SVC:
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP9:
return true;
default:
return false;
}
}
default:
{
return false;
}
}
}
case RTC::RtpParameters::Type::PIPE:
{
return true;
}
default:
{
return false;
}
}
}
inline EncodingContext* GetEncodingContext(
const RTC::RtpCodecMimeType& mimeType, RTC::Codecs::EncodingContext::Params& params)
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
return new RTC::Codecs::VP8::EncodingContext(params);
case RTC::RtpCodecMimeType::Subtype::VP9:
return new RTC::Codecs::VP9::EncodingContext(params);
case RTC::RtpCodecMimeType::Subtype::H264:
return new RTC::Codecs::H264::EncodingContext(params);
default:
return nullptr;
}
}
default:
{
return nullptr;
}
}
}
} // namespace Codecs
} // namespace RTC
#endif
...@@ -47,12 +47,17 @@ namespace RTC ...@@ -47,12 +47,17 @@ namespace RTC
class EncodingContext : public RTC::Codecs::EncodingContext class EncodingContext : public RTC::Codecs::EncodingContext
{ {
public: public:
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params); explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
~EncodingContext() = default; ~EncodingContext() = default;
/* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */ /* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */
public: public:
void SyncRequired() override; void SyncRequired() override
{
}
}; };
public: public:
...@@ -63,50 +68,29 @@ namespace RTC ...@@ -63,50 +68,29 @@ namespace RTC
~PayloadDescriptorHandler() = default; ~PayloadDescriptorHandler() = default;
public: public:
void Dump() const override; void Dump() const override
{
this->payloadDescriptor->Dump();
}
bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override; bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override;
void Restore(uint8_t* data) override; void Restore(uint8_t* data) override;
uint8_t GetSpatialLayer() const override; uint8_t GetSpatialLayer() const override
uint8_t GetTemporalLayer() const override; {
bool IsKeyFrame() const override; return 0u;
}
uint8_t GetTemporalLayer() const override
{
return this->payloadDescriptor->tid;
}
bool IsKeyFrame() const override
{
return this->payloadDescriptor->isKeyFrame;
}
private: private:
std::unique_ptr<PayloadDescriptor> payloadDescriptor; std::unique_ptr<PayloadDescriptor> payloadDescriptor;
}; };
}; };
/* Inline EncondingContext methods. */
inline H264::EncodingContext::EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
inline void H264::EncodingContext::SyncRequired()
{
}
/* Inline PayloadDescriptorHandler methods. */
inline void H264::PayloadDescriptorHandler::Dump() const
{
this->payloadDescriptor->Dump();
}
inline uint8_t H264::PayloadDescriptorHandler::GetSpatialLayer() const
{
return 0u;
}
inline uint8_t H264::PayloadDescriptorHandler::GetTemporalLayer() const
{
return this->payloadDescriptor->tid;
}
inline bool H264::PayloadDescriptorHandler::IsKeyFrame() const
{
return this->payloadDescriptor->isKeyFrame;
}
} // namespace Codecs } // namespace Codecs
} // namespace RTC } // namespace RTC
......
#ifndef MS_RTC_PAYLOAD_DESCRIPTOR_HANDLER_HPP #ifndef MS_RTC_CODECS_PAYLOAD_DESCRIPTOR_HANDLER_HPP
#define MS_RTC_PAYLOAD_DESCRIPTOR_HANDLER_HPP #define MS_RTC_CODECS_PAYLOAD_DESCRIPTOR_HANDLER_HPP
#include "common.hpp" #include "common.hpp"
...@@ -27,21 +27,56 @@ namespace RTC ...@@ -27,21 +27,56 @@ namespace RTC
}; };
public: public:
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params); explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params) : params(params)
{
}
virtual ~EncodingContext() = default; virtual ~EncodingContext() = default;
public: public:
uint8_t GetSpatialLayers() const; uint8_t GetSpatialLayers() const
uint8_t GetTemporalLayers() const; {
bool IsKSvc() const; return this->params.spatialLayers;
int16_t GetTargetSpatialLayer() const; }
int16_t GetTargetTemporalLayer() const; uint8_t GetTemporalLayers() const
int16_t GetCurrentSpatialLayer() const; {
int16_t GetCurrentTemporalLayer() const; return this->params.temporalLayers;
void SetTargetSpatialLayer(int16_t spatialLayer); }
void SetTargetTemporalLayer(int16_t temporalLayer); bool IsKSvc() const
void SetCurrentSpatialLayer(int16_t spatialLayer); {
void SetCurrentTemporalLayer(int16_t temporalLayer); return this->params.ksvc;
}
int16_t GetTargetSpatialLayer() const
{
return this->targetSpatialLayer;
}
int16_t GetTargetTemporalLayer() const
{
return this->targetTemporalLayer;
}
int16_t GetCurrentSpatialLayer() const
{
return this->currentSpatialLayer;
}
int16_t GetCurrentTemporalLayer() const
{
return this->currentTemporalLayer;
}
void SetTargetSpatialLayer(int16_t spatialLayer)
{
this->targetSpatialLayer = spatialLayer;
}
void SetTargetTemporalLayer(int16_t temporalLayer)
{
this->targetTemporalLayer = temporalLayer;
}
void SetCurrentSpatialLayer(int16_t spatialLayer)
{
this->currentSpatialLayer = spatialLayer;
}
void SetCurrentTemporalLayer(int16_t temporalLayer)
{
this->currentTemporalLayer = temporalLayer;
}
virtual void SyncRequired() = 0; virtual void SyncRequired() = 0;
private: private:
...@@ -52,68 +87,6 @@ namespace RTC ...@@ -52,68 +87,6 @@ namespace RTC
int16_t currentTemporalLayer{ -1 }; int16_t currentTemporalLayer{ -1 };
}; };
/* Inline instance methods. */
inline EncodingContext::EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: params(params)
{
}
inline uint8_t EncodingContext::GetSpatialLayers() const
{
return this->params.spatialLayers;
}
inline uint8_t EncodingContext::GetTemporalLayers() const
{
return this->params.temporalLayers;
}
inline bool EncodingContext::IsKSvc() const
{
return this->params.ksvc;
}
inline int16_t EncodingContext::GetTargetSpatialLayer() const
{
return this->targetSpatialLayer;
}
inline int16_t EncodingContext::GetTargetTemporalLayer() const
{
return this->targetTemporalLayer;
}
inline int16_t EncodingContext::GetCurrentSpatialLayer() const
{
return this->currentSpatialLayer;
}
inline int16_t EncodingContext::GetCurrentTemporalLayer() const
{
return this->currentTemporalLayer;
}
inline void EncodingContext::SetTargetSpatialLayer(int16_t spatialLayer)
{
this->targetSpatialLayer = spatialLayer;
}
inline void EncodingContext::SetTargetTemporalLayer(int16_t temporalLayer)
{
this->targetTemporalLayer = temporalLayer;
}
inline void EncodingContext::SetCurrentSpatialLayer(int16_t spatialLayer)
{
this->currentSpatialLayer = spatialLayer;
}
inline void EncodingContext::SetCurrentTemporalLayer(int16_t temporalLayer)
{
this->currentTemporalLayer = temporalLayer;
}
class PayloadDescriptorHandler class PayloadDescriptorHandler
{ {
public: public:
......
#ifndef MS_RTC_CODECS_TOOLS_HPP
#define MS_RTC_CODECS_TOOLS_HPP
#include "common.hpp"
#include "RTC/Codecs/H264.hpp"
#include "RTC/Codecs/PayloadDescriptorHandler.hpp"
#include "RTC/Codecs/VP8.hpp"
#include "RTC/Codecs/VP9.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
namespace RTC
{
namespace Codecs
{
class Tools
{
public:
static bool CanBeKeyFrame(const RTC::RtpCodecMimeType& mimeType)
{
MS_TRACE();
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
case RTC::RtpCodecMimeType::Subtype::VP9:
case RTC::RtpCodecMimeType::Subtype::H264:
return true;
default:
return false;
}
}
default:
{
return false;
}
}
}
static void ProcessRtpPacket(RTC::RtpPacket* packet, const RTC::RtpCodecMimeType& mimeType)
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
{
RTC::Codecs::VP8::ProcessRtpPacket(packet);
break;
}
case RTC::RtpCodecMimeType::Subtype::VP9:
{
RTC::Codecs::VP9::ProcessRtpPacket(packet);
break;
}
case RTC::RtpCodecMimeType::Subtype::H264:
{
RTC::Codecs::H264::ProcessRtpPacket(packet);
break;
}
default:;
}
}
default:;
}
}
static bool IsValidTypeForCodec(RTC::RtpParameters::Type type, const RTC::RtpCodecMimeType& mimeType)
{
switch (type)
{
case RTC::RtpParameters::Type::NONE:
{
return false;
}
case RTC::RtpParameters::Type::SIMPLE:
{
return true;
}
case RTC::RtpParameters::Type::SIMULCAST:
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
case RTC::RtpCodecMimeType::Subtype::H264:
return true;
default:
return false;
}
}
default:
{
return false;
}
}
}
case RTC::RtpParameters::Type::SVC:
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP9:
return true;
default:
return false;
}
}
default:
{
return false;
}
}
}
case RTC::RtpParameters::Type::PIPE:
{
return true;
}
default:
{
return false;
}
}
}
static EncodingContext* GetEncodingContext(
const RTC::RtpCodecMimeType& mimeType, RTC::Codecs::EncodingContext::Params& params)
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
return new RTC::Codecs::VP8::EncodingContext(params);
case RTC::RtpCodecMimeType::Subtype::VP9:
return new RTC::Codecs::VP9::EncodingContext(params);
case RTC::RtpCodecMimeType::Subtype::H264:
return new RTC::Codecs::H264::EncodingContext(params);
default:
return nullptr;
}
}
default:
{
return nullptr;
}
}
}
};
} // namespace Codecs
} // namespace RTC
#endif
...@@ -82,12 +82,18 @@ namespace RTC ...@@ -82,12 +82,18 @@ namespace RTC
class EncodingContext : public RTC::Codecs::EncodingContext class EncodingContext : public RTC::Codecs::EncodingContext
{ {
public: public:
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params); explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
~EncodingContext() = default; ~EncodingContext() = default;
/* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */ /* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */
public: public:
void SyncRequired() override; void SyncRequired() override
{
this->syncRequired = true;
}
public: public:
RTC::SeqManager<uint16_t> pictureIdManager; RTC::SeqManager<uint16_t> pictureIdManager;
...@@ -103,51 +109,29 @@ namespace RTC ...@@ -103,51 +109,29 @@ namespace RTC
~PayloadDescriptorHandler() = default; ~PayloadDescriptorHandler() = default;
public: public:
void Dump() const override; void Dump() const override
{
this->payloadDescriptor->Dump();
}
bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override; bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override;
void Restore(uint8_t* data) override; void Restore(uint8_t* data) override;
uint8_t GetSpatialLayer() const override; uint8_t GetSpatialLayer() const override
uint8_t GetTemporalLayer() const override; {
bool IsKeyFrame() const override; return 0u;
}
uint8_t GetTemporalLayer() const override
{
return this->payloadDescriptor->hasTlIndex ? this->payloadDescriptor->tlIndex : 0u;
}
bool IsKeyFrame() const override
{
return this->payloadDescriptor->isKeyFrame;
}
private: private:
std::unique_ptr<PayloadDescriptor> payloadDescriptor; std::unique_ptr<PayloadDescriptor> payloadDescriptor;
}; };
}; };
/* Inline EncondingContext methods. */
inline VP8::EncodingContext::EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
inline void VP8::EncodingContext::SyncRequired()
{
this->syncRequired = true;
}
/* Inline PayloadDescriptorHandler methods. */
inline void VP8::PayloadDescriptorHandler::Dump() const
{
this->payloadDescriptor->Dump();
}
inline uint8_t VP8::PayloadDescriptorHandler::GetSpatialLayer() const
{
return 0u;
}
inline uint8_t VP8::PayloadDescriptorHandler::GetTemporalLayer() const
{
return this->payloadDescriptor->hasTlIndex ? this->payloadDescriptor->tlIndex : 0u;
}
inline bool VP8::PayloadDescriptorHandler::IsKeyFrame() const
{
return this->payloadDescriptor->isKeyFrame;
}
} // namespace Codecs } // namespace Codecs
} // namespace RTC } // namespace RTC
......
...@@ -99,12 +99,18 @@ namespace RTC ...@@ -99,12 +99,18 @@ namespace RTC
class EncodingContext : public RTC::Codecs::EncodingContext class EncodingContext : public RTC::Codecs::EncodingContext
{ {
public: public:
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params); explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
~EncodingContext() = default; ~EncodingContext() = default;
/* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */ /* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */
public: public:
void SyncRequired() override; void SyncRequired() override
{
this->syncRequired = true;
}
public: public:
RTC::SeqManager<uint16_t> pictureIdManager; RTC::SeqManager<uint16_t> pictureIdManager;
...@@ -118,51 +124,29 @@ namespace RTC ...@@ -118,51 +124,29 @@ namespace RTC
~PayloadDescriptorHandler() = default; ~PayloadDescriptorHandler() = default;
public: public:
void Dump() const override; void Dump() const override
{
this->payloadDescriptor->Dump();
}
bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override; bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override;
void Restore(uint8_t* data) override; void Restore(uint8_t* data) override;
uint8_t GetSpatialLayer() const override; uint8_t GetSpatialLayer() const override
uint8_t GetTemporalLayer() const override; {
bool IsKeyFrame() const override; return this->payloadDescriptor->hasSlIndex ? this->payloadDescriptor->slIndex : 0u;
}
uint8_t GetTemporalLayer() const override
{
return this->payloadDescriptor->hasTlIndex ? this->payloadDescriptor->tlIndex : 0u;
}
bool IsKeyFrame() const override
{
return this->payloadDescriptor->isKeyFrame;
}
private: private:
std::unique_ptr<PayloadDescriptor> payloadDescriptor; std::unique_ptr<PayloadDescriptor> payloadDescriptor;
}; };
}; };
/* Inline EncondingContext methods. */
inline VP9::EncodingContext::EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
inline void VP9::EncodingContext::SyncRequired()
{
this->syncRequired = true;
}
/* Inline PayloadDescriptorHandler methods. */
inline void VP9::PayloadDescriptorHandler::Dump() const
{
this->payloadDescriptor->Dump();
}
inline uint8_t VP9::PayloadDescriptorHandler::GetSpatialLayer() const
{
return this->payloadDescriptor->hasSlIndex ? this->payloadDescriptor->slIndex : 0u;
}
inline uint8_t VP9::PayloadDescriptorHandler::GetTemporalLayer() const
{
return this->payloadDescriptor->hasTlIndex ? this->payloadDescriptor->tlIndex : 0u;
}
inline bool VP9::PayloadDescriptorHandler::IsKeyFrame() const
{
return this->payloadDescriptor->isKeyFrame;
}
} // namespace Codecs } // namespace Codecs
} // namespace RTC } // namespace RTC
......
...@@ -67,18 +67,60 @@ namespace RTC ...@@ -67,18 +67,60 @@ namespace RTC
virtual void FillJsonStats(json& jsonArray) const = 0; virtual void FillJsonStats(json& jsonArray) const = 0;
virtual void FillJsonScore(json& jsonObject) const = 0; virtual void FillJsonScore(json& jsonObject) const = 0;
virtual void HandleRequest(Channel::Request* request); virtual void HandleRequest(Channel::Request* request);
RTC::Media::Kind GetKind() const; RTC::Media::Kind GetKind() const
const RTC::RtpParameters& GetRtpParameters() const; {
const struct RTC::RtpHeaderExtensionIds& GetRtpHeaderExtensionIds() const; return this->kind;
RTC::RtpParameters::Type GetType() const; }
virtual Layers GetPreferredLayers() const; const RTC::RtpParameters& GetRtpParameters() const
const std::vector<uint32_t>& GetMediaSsrcs() const; {
const std::vector<uint32_t>& GetRtxSsrcs() const; return this->rtpParameters;
virtual bool IsActive() const; }
const struct RTC::RtpHeaderExtensionIds& GetRtpHeaderExtensionIds() const
{
return this->rtpHeaderExtensionIds;
}
RTC::RtpParameters::Type GetType() const
{
return this->type;
}
virtual Layers GetPreferredLayers() const
{
// By default return 1:1.
Consumer::Layers layers;
return layers;
}
const std::vector<uint32_t>& GetMediaSsrcs() const
{
return this->mediaSsrcs;
}
const std::vector<uint32_t>& GetRtxSsrcs() const
{
return this->rtxSsrcs;
}
virtual bool IsActive() const
{
// The parent Consumer just checks whether Consumer and Producer are
// not paused and the transport connected.
// clang-format off
return (
this->transportConnected &&
!this->paused &&
!this->producerPaused &&
!this->producerClosed
);
// clang-format on
}
void TransportConnected(); void TransportConnected();
void TransportDisconnected(); void TransportDisconnected();
bool IsPaused() const; bool IsPaused() const
bool IsProducerPaused() const; {
return this->paused;
}
bool IsProducerPaused() const
{
return this->producerPaused;
}
void ProducerPaused(); void ProducerPaused();
void ProducerResumed(); void ProducerResumed();
virtual void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) = 0; virtual void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) = 0;
...@@ -87,7 +129,10 @@ namespace RTC ...@@ -87,7 +129,10 @@ namespace RTC
RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) = 0; RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) = 0;
virtual void ProducerRtcpSenderReport(RTC::RtpStream* rtpStream, bool first) = 0; virtual void ProducerRtcpSenderReport(RTC::RtpStream* rtpStream, bool first) = 0;
void ProducerClosed(); void ProducerClosed();
void SetExternallyManagedBitrate(); void SetExternallyManagedBitrate()
{
this->externallyManagedBitrate = true;
}
virtual uint8_t GetBitratePriority() const = 0; virtual uint8_t GetBitratePriority() const = 0;
virtual uint32_t IncreaseLayer(uint32_t bitrate, bool considerLoss) = 0; virtual uint32_t IncreaseLayer(uint32_t bitrate, bool considerLoss) = 0;
virtual void ApplyLayers() = 0; virtual void ApplyLayers() = 0;
...@@ -146,75 +191,6 @@ namespace RTC ...@@ -146,75 +191,6 @@ namespace RTC
bool producerPaused{ false }; bool producerPaused{ false };
bool producerClosed{ false }; bool producerClosed{ false };
}; };
/* Inline methods. */
inline RTC::Media::Kind Consumer::GetKind() const
{
return this->kind;
}
inline const RTC::RtpParameters& Consumer::GetRtpParameters() const
{
return this->rtpParameters;
}
inline const struct RTC::RtpHeaderExtensionIds& Consumer::GetRtpHeaderExtensionIds() const
{
return this->rtpHeaderExtensionIds;
}
inline RTC::RtpParameters::Type Consumer::GetType() const
{
return this->type;
}
inline Consumer::Layers Consumer::GetPreferredLayers() const
{
// By default return 1:1.
Consumer::Layers layers;
return layers;
}
inline const std::vector<uint32_t>& Consumer::GetMediaSsrcs() const
{
return this->mediaSsrcs;
}
inline const std::vector<uint32_t>& Consumer::GetRtxSsrcs() const
{
return this->rtxSsrcs;
}
inline bool Consumer::IsActive() const
{
// The parent Consumer just checks whether Consumer and Producer are
// not paused and the transport connected.
// clang-format off
return (
this->transportConnected &&
!this->paused &&
!this->producerPaused &&
!this->producerClosed
);
// clang-format on
}
inline bool Consumer::IsPaused() const
{
return this->paused;
}
inline bool Consumer::IsProducerPaused() const
{
return this->producerPaused;
}
inline void Consumer::SetExternallyManagedBitrate()
{
this->externallyManagedBitrate = true;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -32,8 +32,20 @@ namespace RTC ...@@ -32,8 +32,20 @@ namespace RTC
void FillJson(json& jsonObject) const; void FillJson(json& jsonObject) const;
void FillJsonStats(json& jsonArray) const; void FillJsonStats(json& jsonArray) const;
void HandleRequest(Channel::Request* request); void HandleRequest(Channel::Request* request);
const RTC::SctpStreamParameters& GetSctpStreamParameters() const; const RTC::SctpStreamParameters& GetSctpStreamParameters() const
bool IsActive() const; {
return this->sctpStreamParameters;
}
bool IsActive() const
{
// clang-format off
return (
this->transportConnected &&
this->sctpAssociationConnected &&
!this->dataProducerClosed
);
// clang-format on
}
void TransportConnected(); void TransportConnected();
void TransportDisconnected(); void TransportDisconnected();
void SctpAssociationConnected(); void SctpAssociationConnected();
...@@ -48,7 +60,7 @@ namespace RTC ...@@ -48,7 +60,7 @@ namespace RTC
private: private:
// Passed by argument. // Passed by argument.
RTC::DataConsumer::Listener* listener{ nullptr }; RTC::DataConsumer::Listener* listener{ nullptr };
size_t maxSctpMessageSize{ 0 }; size_t maxSctpMessageSize{ 0u };
// Others. // Others.
RTC::SctpStreamParameters sctpStreamParameters; RTC::SctpStreamParameters sctpStreamParameters;
std::string label; std::string label;
...@@ -56,27 +68,9 @@ namespace RTC ...@@ -56,27 +68,9 @@ namespace RTC
bool transportConnected{ false }; bool transportConnected{ false };
bool sctpAssociationConnected{ false }; bool sctpAssociationConnected{ false };
bool dataProducerClosed{ false }; bool dataProducerClosed{ false };
size_t messagesSent{ 0 }; size_t messagesSent{ 0u };
size_t bytesSent{ 0 }; size_t bytesSent{ 0u };
}; };
/* Inline methods. */
inline const RTC::SctpStreamParameters& DataConsumer::GetSctpStreamParameters() const
{
return this->sctpStreamParameters;
}
inline bool DataConsumer::IsActive() const
{
// clang-format off
return (
this->transportConnected &&
this->sctpAssociationConnected &&
!this->dataProducerClosed
);
// clang-format on
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -27,7 +27,10 @@ namespace RTC ...@@ -27,7 +27,10 @@ namespace RTC
void FillJson(json& jsonObject) const; void FillJson(json& jsonObject) const;
void FillJsonStats(json& jsonArray) const; void FillJsonStats(json& jsonArray) const;
void HandleRequest(Channel::Request* request); void HandleRequest(Channel::Request* request);
const RTC::SctpStreamParameters& GetSctpStreamParameters() const; const RTC::SctpStreamParameters& GetSctpStreamParameters() const
{
return this->sctpStreamParameters;
}
void ReceiveSctpMessage(uint32_t ppid, const uint8_t* msg, size_t len); void ReceiveSctpMessage(uint32_t ppid, const uint8_t* msg, size_t len);
public: public:
...@@ -41,16 +44,9 @@ namespace RTC ...@@ -41,16 +44,9 @@ namespace RTC
RTC::SctpStreamParameters sctpStreamParameters; RTC::SctpStreamParameters sctpStreamParameters;
std::string label; std::string label;
std::string protocol; std::string protocol;
size_t messagesReceived{ 0 }; size_t messagesReceived{ 0u };
size_t bytesReceived{ 0 }; size_t bytesReceived{ 0u };
}; };
/* Inline methods. */
inline const RTC::SctpStreamParameters& DataProducer::GetSctpStreamParameters() const
{
return this->sctpStreamParameters;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -94,10 +94,41 @@ namespace RTC ...@@ -94,10 +94,41 @@ namespace RTC
public: public:
static void ClassInit(); static void ClassInit();
static void ClassDestroy(); static void ClassDestroy();
static Role StringToRole(const std::string& role); static Role StringToRole(const std::string& role)
static FingerprintAlgorithm GetFingerprintAlgorithm(const std::string& fingerprint); {
static std::string& GetFingerprintAlgorithmString(FingerprintAlgorithm fingerprint); auto it = DtlsTransport::string2Role.find(role);
static bool IsDtls(const uint8_t* data, size_t len);
if (it != DtlsTransport::string2Role.end())
return it->second;
else
return DtlsTransport::Role::NONE;
}
static FingerprintAlgorithm GetFingerprintAlgorithm(const std::string& fingerprint)
{
auto it = DtlsTransport::string2FingerprintAlgorithm.find(fingerprint);
if (it != DtlsTransport::string2FingerprintAlgorithm.end())
return it->second;
else
return DtlsTransport::FingerprintAlgorithm::NONE;
}
static std::string& GetFingerprintAlgorithmString(FingerprintAlgorithm fingerprint)
{
auto it = DtlsTransport::fingerprintAlgorithm2String.find(fingerprint);
return it->second;
}
static bool IsDtls(const uint8_t* data, size_t len)
{
// clang-format off
return (
// Minimum DTLS record length is 13 bytes.
(len >= 13) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 19 && data[0] < 64)
);
// clang-format on
}
private: private:
static void GenerateCertificateAndPrivateKey(); static void GenerateCertificateAndPrivateKey();
...@@ -123,15 +154,40 @@ namespace RTC ...@@ -123,15 +154,40 @@ namespace RTC
public: public:
void Dump() const; void Dump() const;
void Run(Role localRole); void Run(Role localRole);
std::vector<Fingerprint>& GetLocalFingerprints() const; std::vector<Fingerprint>& GetLocalFingerprints() const
{
return DtlsTransport::localFingerprints;
}
bool SetRemoteFingerprint(Fingerprint fingerprint); bool SetRemoteFingerprint(Fingerprint fingerprint);
void ProcessDtlsData(const uint8_t* data, size_t len); void ProcessDtlsData(const uint8_t* data, size_t len);
DtlsState GetState() const; DtlsState GetState() const
Role GetLocalRole() const; {
return this->state;
}
Role GetLocalRole() const
{
return this->localRole;
}
void SendApplicationData(const uint8_t* data, size_t len); void SendApplicationData(const uint8_t* data, size_t len);
private: private:
bool IsRunning() const; bool IsRunning() const
{
switch (this->state)
{
case DtlsState::NEW:
return false;
case DtlsState::CONNECTING:
case DtlsState::CONNECTED:
return true;
case DtlsState::FAILED:
case DtlsState::CLOSED:
return false;
}
// Make GCC 4.9 happy.
return false;
}
void Reset(); void Reset();
bool CheckStatus(int returnCode); bool CheckStatus(int returnCode);
void SendPendingOutgoingDtlsData(); void SendPendingOutgoingDtlsData();
...@@ -165,84 +221,6 @@ namespace RTC ...@@ -165,84 +221,6 @@ namespace RTC
bool handshakeDoneNow{ false }; bool handshakeDoneNow{ false };
std::string remoteCert; std::string remoteCert;
}; };
/* Inline static methods. */
inline DtlsTransport::Role DtlsTransport::StringToRole(const std::string& role)
{
auto it = DtlsTransport::string2Role.find(role);
if (it != DtlsTransport::string2Role.end())
return it->second;
else
return DtlsTransport::Role::NONE;
}
inline DtlsTransport::FingerprintAlgorithm DtlsTransport::GetFingerprintAlgorithm(
const std::string& fingerprint)
{
auto it = DtlsTransport::string2FingerprintAlgorithm.find(fingerprint);
if (it != DtlsTransport::string2FingerprintAlgorithm.end())
return it->second;
else
return DtlsTransport::FingerprintAlgorithm::NONE;
}
inline std::string& DtlsTransport::GetFingerprintAlgorithmString(
DtlsTransport::FingerprintAlgorithm fingerprint)
{
auto it = DtlsTransport::fingerprintAlgorithm2String.find(fingerprint);
return it->second;
}
inline bool DtlsTransport::IsDtls(const uint8_t* data, size_t len)
{
// clang-format off
return (
// Minimum DTLS record length is 13 bytes.
(len >= 13) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 19 && data[0] < 64)
);
// clang-format on
}
/* Inline instance methods. */
inline std::vector<DtlsTransport::Fingerprint>& DtlsTransport::GetLocalFingerprints() const
{
return DtlsTransport::localFingerprints;
}
inline DtlsTransport::DtlsState DtlsTransport::GetState() const
{
return this->state;
}
inline DtlsTransport::Role DtlsTransport::GetLocalRole() const
{
return this->localRole;
}
inline bool DtlsTransport::IsRunning() const
{
switch (this->state)
{
case DtlsState::NEW:
return false;
case DtlsState::CONNECTING:
case DtlsState::CONNECTED:
return true;
case DtlsState::FAILED:
case DtlsState::CLOSED:
return false;
}
// Make GCC 4.9 happy.
return false;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -33,50 +33,44 @@ namespace RTC ...@@ -33,50 +33,44 @@ namespace RTC
}; };
public: public:
IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority); IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority)
IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority, std::string& announcedIp); : foundation("udpcandidate"), priority(priority), ip(udpSocket->GetLocalIp()),
IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority); protocol(Protocol::UDP), port(udpSocket->GetLocalPort()), type(CandidateType::HOST)
IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority, std::string& announcedIp); {
}
IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority, std::string& announcedIp)
: foundation("udpcandidate"), priority(priority), ip(announcedIp), protocol(Protocol::UDP),
port(udpSocket->GetLocalPort()), type(CandidateType::HOST)
{
}
IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority)
: foundation("tcpcandidate"), priority(priority), ip(tcpServer->GetLocalIp()),
protocol(Protocol::TCP), port(tcpServer->GetLocalPort()), type(CandidateType::HOST),
tcpType(TcpCandidateType::PASSIVE)
{
}
IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority, std::string& announcedIp)
: foundation("tcpcandidate"), priority(priority), ip(announcedIp), protocol(Protocol::TCP),
port(tcpServer->GetLocalPort()), type(CandidateType::HOST),
tcpType(TcpCandidateType::PASSIVE)
{
}
void FillJson(json& jsonObject) const; void FillJson(json& jsonObject) const;
private: private:
// Others. // Others.
std::string foundation; std::string foundation;
uint32_t priority{ 0 }; uint32_t priority{ 0u };
std::string ip; std::string ip;
Protocol protocol; Protocol protocol;
uint16_t port{ 0 }; uint16_t port{ 0u };
CandidateType type{ CandidateType::HOST }; CandidateType type{ CandidateType::HOST };
TcpCandidateType tcpType{ TcpCandidateType::PASSIVE }; TcpCandidateType tcpType{ TcpCandidateType::PASSIVE };
}; };
/* Inline methods. */
inline IceCandidate::IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority)
: foundation("udpcandidate"), priority(priority), ip(udpSocket->GetLocalIp()),
protocol(Protocol::UDP), port(udpSocket->GetLocalPort()), type(CandidateType::HOST)
{
}
inline IceCandidate::IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority, std::string& announcedIp)
: foundation("udpcandidate"), priority(priority), ip(announcedIp), protocol(Protocol::UDP),
port(udpSocket->GetLocalPort()), type(CandidateType::HOST)
{
}
inline IceCandidate::IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority)
: foundation("tcpcandidate"), priority(priority), ip(tcpServer->GetLocalIp()),
protocol(Protocol::TCP), port(tcpServer->GetLocalPort()), type(CandidateType::HOST),
tcpType(TcpCandidateType::PASSIVE)
{
}
inline IceCandidate::IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority, std::string& announcedIp)
: foundation("tcpcandidate"), priority(priority), ip(announcedIp), protocol(Protocol::TCP),
port(tcpServer->GetLocalPort()), type(CandidateType::HOST), tcpType(TcpCandidateType::PASSIVE)
{
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -45,12 +45,32 @@ namespace RTC ...@@ -45,12 +45,32 @@ namespace RTC
public: public:
void ProcessStunPacket(RTC::StunPacket* packet, RTC::TransportTuple* tuple); void ProcessStunPacket(RTC::StunPacket* packet, RTC::TransportTuple* tuple);
const std::string& GetUsernameFragment() const; const std::string& GetUsernameFragment() const
const std::string& GetPassword() const; {
IceState GetState() const; return this->usernameFragment;
RTC::TransportTuple* GetSelectedTuple() const; }
void SetUsernameFragment(const std::string& usernameFragment); const std::string& GetPassword() const
void SetPassword(const std::string& password); {
return this->password;
}
IceState GetState() const
{
return this->state;
}
RTC::TransportTuple* GetSelectedTuple() const
{
return this->selectedTuple;
}
void SetUsernameFragment(const std::string& usernameFragment)
{
this->oldUsernameFragment = this->usernameFragment;
this->usernameFragment = usernameFragment;
}
void SetPassword(const std::string& password)
{
this->oldPassword = this->password;
this->password = password;
}
bool IsValidTuple(const RTC::TransportTuple* tuple) const; bool IsValidTuple(const RTC::TransportTuple* tuple) const;
void RemoveTuple(RTC::TransportTuple* tuple); void RemoveTuple(RTC::TransportTuple* tuple);
// This should be just called in 'connected' or completed' state // This should be just called in 'connected' or completed' state
...@@ -85,40 +105,6 @@ namespace RTC ...@@ -85,40 +105,6 @@ namespace RTC
std::list<RTC::TransportTuple> tuples; std::list<RTC::TransportTuple> tuples;
RTC::TransportTuple* selectedTuple{ nullptr }; RTC::TransportTuple* selectedTuple{ nullptr };
}; };
/* Inline instance methods. */
inline const std::string& IceServer::GetUsernameFragment() const
{
return this->usernameFragment;
}
inline const std::string& IceServer::GetPassword() const
{
return this->password;
}
inline IceServer::IceState IceServer::GetState() const
{
return this->state;
}
inline RTC::TransportTuple* IceServer::GetSelectedTuple() const
{
return this->selectedTuple;
}
inline void IceServer::SetUsernameFragment(const std::string& usernameFragment)
{
this->oldUsernameFragment = this->usernameFragment;
this->usernameFragment = usernameFragment;
}
inline void IceServer::SetPassword(const std::string& password)
{
this->oldPassword = this->password;
this->password = password;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -19,10 +19,22 @@ namespace RTC ...@@ -19,10 +19,22 @@ namespace RTC
PendingKeyFrameInfo(Listener* listener, uint32_t ssrc); PendingKeyFrameInfo(Listener* listener, uint32_t ssrc);
~PendingKeyFrameInfo(); ~PendingKeyFrameInfo();
uint32_t GetSsrc() const; uint32_t GetSsrc() const
void SetRetryOnTimeout(bool notify); {
bool GetRetryOnTimeout() const; return this->ssrc;
void Restart(); }
void SetRetryOnTimeout(bool notify)
{
this->retryOnTimeout = notify;
}
bool GetRetryOnTimeout() const
{
return this->retryOnTimeout;
}
void Restart()
{
return this->timer->Restart();
}
/* Pure virtual methods inherited from Timer::Listener. */ /* Pure virtual methods inherited from Timer::Listener. */
public: public:
...@@ -48,9 +60,18 @@ namespace RTC ...@@ -48,9 +60,18 @@ namespace RTC
KeyFrameRequestDelayer(Listener* listener, uint32_t ssrc, uint32_t delay); KeyFrameRequestDelayer(Listener* listener, uint32_t ssrc, uint32_t delay);
~KeyFrameRequestDelayer(); ~KeyFrameRequestDelayer();
uint32_t GetSsrc() const; uint32_t GetSsrc() const
bool GetKeyFrameRequested() const; {
void SetKeyFrameRequested(bool flag); return this->ssrc;
}
bool GetKeyFrameRequested() const
{
return this->keyFrameRequested;
}
void SetKeyFrameRequested(bool flag)
{
this->keyFrameRequested = flag;
}
/* Pure virtual methods inherited from Timer::Listener. */ /* Pure virtual methods inherited from Timer::Listener. */
public: public:
...@@ -97,39 +118,4 @@ namespace RTC ...@@ -97,39 +118,4 @@ namespace RTC
}; };
} // namespace RTC } // namespace RTC
inline uint32_t RTC::PendingKeyFrameInfo::GetSsrc() const
{
return this->ssrc;
}
inline void RTC::PendingKeyFrameInfo::SetRetryOnTimeout(bool notify)
{
this->retryOnTimeout = notify;
}
inline bool RTC::PendingKeyFrameInfo::GetRetryOnTimeout() const
{
return this->retryOnTimeout;
}
inline void RTC::PendingKeyFrameInfo::Restart()
{
return this->timer->Restart();
}
inline uint32_t RTC::KeyFrameRequestDelayer::GetSsrc() const
{
return this->ssrc;
}
inline bool RTC::KeyFrameRequestDelayer::GetKeyFrameRequested() const
{
return this->keyFrameRequested;
}
inline void RTC::KeyFrameRequestDelayer::SetKeyFrameRequested(bool flag)
{
this->keyFrameRequested = flag;
}
#endif #endif
...@@ -25,7 +25,9 @@ namespace RTC ...@@ -25,7 +25,9 @@ namespace RTC
struct NackInfo struct NackInfo
{ {
NackInfo() = default; NackInfo() = default;
explicit NackInfo(uint16_t seq, uint16_t sendAtSeq); explicit NackInfo(uint16_t seq, uint16_t sendAtSeq) : seq(seq), sendAtSeq(sendAtSeq)
{
}
uint16_t seq{ 0u }; uint16_t seq{ 0u };
uint16_t sendAtSeq{ 0u }; uint16_t sendAtSeq{ 0u };
...@@ -44,8 +46,14 @@ namespace RTC ...@@ -44,8 +46,14 @@ namespace RTC
~NackGenerator() override; ~NackGenerator() override;
bool ReceivePacket(RTC::RtpPacket* packet, bool isRecovered); bool ReceivePacket(RTC::RtpPacket* packet, bool isRecovered);
size_t GetNackListLength() const; size_t GetNackListLength() const
void UpdateRtt(uint32_t rtt); {
return this->nackList.size();
}
void UpdateRtt(uint32_t rtt)
{
this->rtt = rtt;
}
void Reset(); void Reset();
private: private:
...@@ -71,23 +79,6 @@ namespace RTC ...@@ -71,23 +79,6 @@ namespace RTC
uint16_t lastSeq{ 0u }; // Seq number of last valid packet. uint16_t lastSeq{ 0u }; // Seq number of last valid packet.
uint32_t rtt{ 0u }; // Round trip time (ms). uint32_t rtt{ 0u }; // Round trip time (ms).
}; };
// Inline instance methods.
inline void NackGenerator::UpdateRtt(uint32_t rtt)
{
this->rtt = rtt;
}
inline NackGenerator::NackInfo::NackInfo(uint16_t seq, uint16_t sendAtSeq)
: seq(seq), sendAtSeq(sendAtSeq)
{
}
inline size_t NackGenerator::GetNackListLength() const
{
return this->nackList.size();
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -28,7 +28,10 @@ namespace RTC ...@@ -28,7 +28,10 @@ namespace RTC
uint32_t GetDesiredBitrate() const override; uint32_t GetDesiredBitrate() const override;
void SendRtpPacket(RTC::RtpPacket* packet) override; void SendRtpPacket(RTC::RtpPacket* packet) override;
void GetRtcp(RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t nowMs) override; void GetRtcp(RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t nowMs) override;
std::vector<RTC::RtpStreamSend*> GetRtpStreams() override; std::vector<RTC::RtpStreamSend*> GetRtpStreams() override
{
return this->rtpStreams;
}
void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override; void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override;
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override; void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override;
void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType, uint32_t ssrc) override; void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType, uint32_t ssrc) override;
...@@ -58,13 +61,6 @@ namespace RTC ...@@ -58,13 +61,6 @@ namespace RTC
std::unordered_map<RTC::RtpStreamSend*, bool> mapRtpStreamSyncRequired; std::unordered_map<RTC::RtpStreamSend*, bool> mapRtpStreamSyncRequired;
std::unordered_map<RTC::RtpStreamSend*, RTC::SeqManager<uint16_t>> mapRtpStreamRtpSeqManager; std::unordered_map<RTC::RtpStreamSend*, RTC::SeqManager<uint16_t>> mapRtpStreamRtpSeqManager;
}; };
// Inline methods.
inline std::vector<RTC::RtpStreamSend*> PipeConsumer::GetRtpStreams()
{
return this->rtpStreams;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -21,10 +21,22 @@ namespace RTC ...@@ -21,10 +21,22 @@ namespace RTC
}; };
public: public:
static uv_udp_t* BindUdp(std::string& ip); static uv_udp_t* BindUdp(std::string& ip)
static uv_tcp_t* BindTcp(std::string& ip); {
static void UnbindUdp(std::string& ip, uint16_t port); return reinterpret_cast<uv_udp_t*>(Bind(Transport::UDP, ip));
static void UnbindTcp(std::string& ip, uint16_t port); }
static uv_tcp_t* BindTcp(std::string& ip)
{
return reinterpret_cast<uv_tcp_t*>(Bind(Transport::TCP, ip));
}
static void UnbindUdp(std::string& ip, uint16_t port)
{
return Unbind(Transport::UDP, ip, port);
}
static void UnbindTcp(std::string& ip, uint16_t port)
{
return Unbind(Transport::TCP, ip, port);
}
static void FillJson(json& jsonObject); static void FillJson(json& jsonObject);
private: private:
...@@ -36,28 +48,6 @@ namespace RTC ...@@ -36,28 +48,6 @@ namespace RTC
static std::unordered_map<std::string, std::vector<bool>> mapUdpIpPorts; static std::unordered_map<std::string, std::vector<bool>> mapUdpIpPorts;
static std::unordered_map<std::string, std::vector<bool>> mapTcpIpPorts; static std::unordered_map<std::string, std::vector<bool>> mapTcpIpPorts;
}; };
/* Inline static methods. */
inline uv_udp_t* PortManager::BindUdp(std::string& ip)
{
return reinterpret_cast<uv_udp_t*>(Bind(Transport::UDP, ip));
}
inline uv_tcp_t* PortManager::BindTcp(std::string& ip)
{
return reinterpret_cast<uv_tcp_t*>(Bind(Transport::TCP, ip));
}
inline void PortManager::UnbindUdp(std::string& ip, uint16_t port)
{
return Unbind(Transport::UDP, ip, port);
}
inline void PortManager::UnbindTcp(std::string& ip, uint16_t port)
{
return Unbind(Transport::TCP, ip, port);
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -90,12 +90,30 @@ namespace RTC ...@@ -90,12 +90,30 @@ namespace RTC
void FillJson(json& jsonObject) const; void FillJson(json& jsonObject) const;
void FillJsonStats(json& jsonArray) const; void FillJsonStats(json& jsonArray) const;
void HandleRequest(Channel::Request* request); void HandleRequest(Channel::Request* request);
RTC::Media::Kind GetKind() const; RTC::Media::Kind GetKind() const
const RTC::RtpParameters& GetRtpParameters() const; {
const struct RTC::RtpHeaderExtensionIds& GetRtpHeaderExtensionIds() const; return this->kind;
RTC::RtpParameters::Type GetType() const; }
bool IsPaused() const; const RTC::RtpParameters& GetRtpParameters() const
std::map<RTC::RtpStreamRecv*, uint32_t>& GetRtpStreams(); {
return this->rtpParameters;
}
const struct RTC::RtpHeaderExtensionIds& GetRtpHeaderExtensionIds() const
{
return this->rtpHeaderExtensionIds;
}
RTC::RtpParameters::Type GetType() const
{
return this->type;
}
bool IsPaused() const
{
return this->paused;
}
std::map<RTC::RtpStreamRecv*, uint32_t>& GetRtpStreams()
{
return this->mapRtpStreamMappedSsrc;
}
ReceiveRtpPacketResult ReceiveRtpPacket(RTC::RtpPacket* packet); ReceiveRtpPacketResult ReceiveRtpPacket(RTC::RtpPacket* packet);
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report); void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void ReceiveRtcpXrDelaySinceLastRr(RTC::RTCP::DelaySinceLastRr::SsrcInfo* ssrcInfo); void ReceiveRtcpXrDelaySinceLastRr(RTC::RTCP::DelaySinceLastRr::SsrcInfo* ssrcInfo);
...@@ -150,45 +168,13 @@ namespace RTC ...@@ -150,45 +168,13 @@ namespace RTC
bool paused{ false }; bool paused{ false };
RTC::RtpPacket* currentRtpPacket{ nullptr }; RTC::RtpPacket* currentRtpPacket{ nullptr };
// Timestamp when last RTCP was sent. // Timestamp when last RTCP was sent.
uint64_t lastRtcpSentTime{ 0 }; uint64_t lastRtcpSentTime{ 0u };
uint16_t maxRtcpInterval{ 0 }; uint16_t maxRtcpInterval{ 0u };
// Video orientation. // Video orientation.
bool videoOrientationDetected{ false }; bool videoOrientationDetected{ false };
struct VideoOrientation videoOrientation; struct VideoOrientation videoOrientation;
struct TraceEventTypes traceEventTypes; struct TraceEventTypes traceEventTypes;
}; };
/* Inline methods. */
inline RTC::Media::Kind Producer::GetKind() const
{
return this->kind;
}
inline const RTC::RtpParameters& Producer::GetRtpParameters() const
{
return this->rtpParameters;
}
inline const struct RTC::RtpHeaderExtensionIds& Producer::GetRtpHeaderExtensionIds() const
{
return this->rtpHeaderExtensionIds;
}
inline RTC::RtpParameters::Type Producer::GetType() const
{
return this->type;
}
inline bool Producer::IsPaused() const
{
return this->paused;
}
inline std::map<RTC::RtpStreamRecv*, uint32_t>& Producer::GetRtpStreams()
{
return this->mapRtpStreamMappedSsrc;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -19,84 +19,64 @@ namespace RTC ...@@ -19,84 +19,64 @@ namespace RTC
static ByePacket* Parse(const uint8_t* data, size_t len); static ByePacket* Parse(const uint8_t* data, size_t len);
public: public:
ByePacket(); ByePacket() : Packet(Type::BYE)
explicit ByePacket(CommonHeader* commonHeader); {
}
explicit ByePacket(CommonHeader* commonHeader) : Packet(commonHeader)
{
}
~ByePacket() override = default; ~ByePacket() override = default;
void AddSsrc(uint32_t ssrc); void AddSsrc(uint32_t ssrc)
void SetReason(const std::string& reason); {
const std::string& GetReason() const; this->ssrcs.push_back(ssrc);
Iterator Begin(); }
Iterator End(); void SetReason(const std::string& reason)
{
this->reason = reason;
}
const std::string& GetReason() const
{
return this->reason;
}
Iterator Begin()
{
return this->ssrcs.begin();
}
Iterator End()
{
return this->ssrcs.end();
}
/* Pure virtual methods inherited from Packet. */ /* Pure virtual methods inherited from Packet. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override; size_t GetCount() const override
size_t GetSize() const override;
private:
std::vector<uint32_t> ssrcs;
std::string reason;
};
/* Inline instance methods. */
inline ByePacket::ByePacket() : Packet(Type::BYE)
{
}
inline ByePacket::ByePacket(CommonHeader* commonHeader) : Packet(commonHeader)
{
}
inline size_t ByePacket::GetCount() const
{
return this->ssrcs.size();
}
inline size_t ByePacket::GetSize() const
{
size_t size = sizeof(Packet::CommonHeader);
size += ssrcs.size() * 4u;
if (!this->reason.empty())
{ {
size += 1u; // Length field. return this->ssrcs.size();
size += this->reason.length();
} }
size_t GetSize() const override
{
size_t size = sizeof(Packet::CommonHeader);
// http://stackoverflow.com/questions/11642210/computing-padding-required-for-n-byte-alignment size += ssrcs.size() * 4u;
// Consider pading to 32 bits (4 bytes) boundary.
return (size + 3) & ~3;
}
inline void ByePacket::AddSsrc(uint32_t ssrc)
{
this->ssrcs.push_back(ssrc);
}
inline void ByePacket::SetReason(const std::string& reason)
{
this->reason = reason;
}
inline const std::string& ByePacket::GetReason() const if (!this->reason.empty())
{ {
return this->reason; size += 1u; // Length field.
} size += this->reason.length();
}
inline ByePacket::Iterator ByePacket::Begin() // http://stackoverflow.com/questions/11642210/computing-padding-required-for-n-byte-alignment
{ // Consider pading to 32 bits (4 bytes) boundary.
return this->ssrcs.begin(); return (size + 3) & ~3;
} }
inline ByePacket::Iterator ByePacket::End() private:
{ std::vector<uint32_t> ssrcs;
return this->ssrcs.end(); std::string reason;
} };
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -18,17 +18,38 @@ namespace RTC ...@@ -18,17 +18,38 @@ namespace RTC
CompoundPacket() = default; CompoundPacket() = default;
public: public:
const uint8_t* GetData() const; const uint8_t* GetData() const
size_t GetSize() const; {
size_t GetSenderReportCount() const; return this->header;
size_t GetReceiverReportCount() const; }
size_t GetSize() const
{
return this->size;
}
size_t GetSenderReportCount() const
{
return this->senderReportPacket.GetCount();
}
size_t GetReceiverReportCount() const
{
return this->receiverReportPacket.GetCount();
}
void Dump(); void Dump();
void AddSenderReport(SenderReport* report); void AddSenderReport(SenderReport* report);
void AddReceiverReport(ReceiverReport* report); void AddReceiverReport(ReceiverReport* report);
void AddSdesChunk(SdesChunk* chunk); void AddSdesChunk(SdesChunk* chunk);
void AddReceiverReferenceTime(ReceiverReferenceTime* report); void AddReceiverReferenceTime(ReceiverReferenceTime* report);
bool HasSenderReport(); bool HasSenderReport()
bool HasReceiverReferenceTime(); {
return this->senderReportPacket.Begin() != this->senderReportPacket.End();
}
bool HasReceiverReferenceTime()
{
return std::any_of(
this->xrPacket.Begin(), this->xrPacket.End(), [](const ExtendedReportBlock* report) {
return report->GetType() == ExtendedReportBlock::Type::RRT;
});
}
void Serialize(uint8_t* data); void Serialize(uint8_t* data);
private: private:
...@@ -39,56 +60,6 @@ namespace RTC ...@@ -39,56 +60,6 @@ namespace RTC
SdesPacket sdesPacket; SdesPacket sdesPacket;
ExtendedReportPacket xrPacket; ExtendedReportPacket xrPacket;
}; };
/* Inline methods. */
inline const uint8_t* CompoundPacket::GetData() const
{
return this->header;
}
inline size_t CompoundPacket::GetSize() const
{
return this->size;
}
inline size_t CompoundPacket::GetSenderReportCount() const
{
return this->senderReportPacket.GetCount();
}
inline size_t CompoundPacket::GetReceiverReportCount() const
{
return this->receiverReportPacket.GetCount();
}
inline void CompoundPacket::AddReceiverReport(ReceiverReport* report)
{
this->receiverReportPacket.AddReport(report);
}
inline void CompoundPacket::AddSdesChunk(SdesChunk* chunk)
{
this->sdesPacket.AddChunk(chunk);
}
inline void CompoundPacket::AddReceiverReferenceTime(ReceiverReferenceTime* report)
{
this->xrPacket.AddReport(report);
}
inline bool CompoundPacket::HasSenderReport()
{
return this->senderReportPacket.Begin() != this->senderReportPacket.End();
}
inline bool CompoundPacket::HasReceiverReferenceTime()
{
return std::any_of(
this->xrPacket.Begin(), this->xrPacket.End(), [](const ExtendedReportBlock* report) {
return report->GetType() == ExtendedReportBlock::Type::RRT;
});
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -29,18 +29,39 @@ namespace RTC ...@@ -29,18 +29,39 @@ namespace RTC
static std::map<typename T::MessageType, std::string> type2String; static std::map<typename T::MessageType, std::string> type2String;
public: public:
typename T::MessageType GetMessageType() const; typename T::MessageType GetMessageType() const
uint32_t GetSenderSsrc() const; {
void SetSenderSsrc(uint32_t ssrc); return this->messageType;
uint32_t GetMediaSsrc() const; }
void SetMediaSsrc(uint32_t ssrc); uint32_t GetSenderSsrc() const
{
return uint32_t{ ntohl(this->header->senderSsrc) };
}
void SetSenderSsrc(uint32_t ssrc)
{
this->header->senderSsrc = uint32_t{ htonl(ssrc) };
}
uint32_t GetMediaSsrc() const
{
return uint32_t{ ntohl(this->header->mediaSsrc) };
}
void SetMediaSsrc(uint32_t ssrc)
{
this->header->mediaSsrc = uint32_t{ htonl(ssrc) };
}
/* Pure virtual methods inherited from Packet. */ /* Pure virtual methods inherited from Packet. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override; size_t GetCount() const override
size_t GetSize() const override; {
return static_cast<size_t>(GetMessageType());
}
size_t GetSize() const override
{
return sizeof(CommonHeader) + sizeof(Header);
}
protected: protected:
explicit FeedbackPacket(CommonHeader* commonHeader); explicit FeedbackPacket(CommonHeader* commonHeader);
...@@ -92,50 +113,6 @@ namespace RTC ...@@ -92,50 +113,6 @@ namespace RTC
using FeedbackPsPacket = FeedbackPacket<RTC::RTCP::FeedbackPs>; using FeedbackPsPacket = FeedbackPacket<RTC::RTCP::FeedbackPs>;
using FeedbackRtpPacket = FeedbackPacket<RTC::RTCP::FeedbackRtp>; using FeedbackRtpPacket = FeedbackPacket<RTC::RTCP::FeedbackRtp>;
/* Inline instance methods. */
template<typename T>
inline typename T::MessageType FeedbackPacket<T>::GetMessageType() const
{
return this->messageType;
}
template<typename T>
inline size_t FeedbackPacket<T>::GetCount() const
{
return static_cast<size_t>(this->GetMessageType());
}
template<typename T>
inline size_t FeedbackPacket<T>::GetSize() const
{
return sizeof(CommonHeader) + sizeof(Header);
}
template<typename T>
inline uint32_t FeedbackPacket<T>::GetSenderSsrc() const
{
return uint32_t{ ntohl(this->header->senderSsrc) };
}
template<typename T>
inline void FeedbackPacket<T>::SetSenderSsrc(uint32_t ssrc)
{
this->header->senderSsrc = uint32_t{ htonl(ssrc) };
}
template<typename T>
inline uint32_t FeedbackPacket<T>::GetMediaSsrc() const
{
return uint32_t{ ntohl(this->header->mediaSsrc) };
}
template<typename T>
inline void FeedbackPacket<T>::SetMediaSsrc(uint32_t ssrc)
{
this->header->mediaSsrc = uint32_t{ htonl(ssrc) };
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -11,17 +11,39 @@ namespace RTC ...@@ -11,17 +11,39 @@ namespace RTC
{ {
public: public:
template<typename Item> template<typename Item>
static Item* Parse(const uint8_t* data, size_t len); static Item* Parse(const uint8_t* data, size_t len)
{
// data size must be >= header.
if (sizeof(typename Item::Header) > len)
return nullptr;
auto* header =
const_cast<typename Item::Header*>(reinterpret_cast<const typename Item::Header*>(data));
return new Item(header);
}
public: public:
bool IsCorrect() const; bool IsCorrect() const
{
return this->isCorrect;
}
protected: protected:
virtual ~FeedbackItem(); virtual ~FeedbackItem()
{
delete[] this->raw;
}
public: public:
virtual void Dump() const = 0; virtual void Dump() const = 0;
virtual void Serialize(); virtual void Serialize()
{
delete[] this->raw;
this->raw = new uint8_t[this->GetSize()];
this->Serialize(this->raw);
}
virtual size_t Serialize(uint8_t* buffer) = 0; virtual size_t Serialize(uint8_t* buffer) = 0;
virtual size_t GetSize() const = 0; virtual size_t GetSize() const = 0;
...@@ -29,40 +51,6 @@ namespace RTC ...@@ -29,40 +51,6 @@ namespace RTC
uint8_t* raw{ nullptr }; uint8_t* raw{ nullptr };
bool isCorrect{ true }; bool isCorrect{ true };
}; };
/* Inline static methods */
template<typename Item>
Item* FeedbackItem::Parse(const uint8_t* data, size_t len)
{
// data size must be >= header.
if (sizeof(typename Item::Header) > len)
return nullptr;
auto* header =
const_cast<typename Item::Header*>(reinterpret_cast<const typename Item::Header*>(data));
return new Item(header);
}
/* Inline instance methods */
inline FeedbackItem::~FeedbackItem()
{
delete[] this->raw;
}
inline void FeedbackItem::Serialize()
{
delete[] this->raw;
this->raw = new uint8_t[this->GetSize()];
this->Serialize(this->raw);
}
inline bool FeedbackItem::IsCorrect() const
{
return this->isCorrect;
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -20,77 +20,53 @@ namespace RTC ...@@ -20,77 +20,53 @@ namespace RTC
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackPsItemsPacket(CommonHeader* commonHeader); explicit FeedbackPsItemsPacket(CommonHeader* commonHeader) : FeedbackPsPacket(commonHeader)
explicit FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0); {
~FeedbackPsItemsPacket(); }
explicit FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0)
: FeedbackPsPacket(Item::messageType, senderSsrc, mediaSsrc)
{
}
~FeedbackPsItemsPacket()
{
for (auto* item : this->items)
{
delete item;
}
}
void AddItem(Item* item); void AddItem(Item* item)
Iterator Begin(); {
Iterator End(); this->items.push_back(item);
}
Iterator Begin()
{
return this->items.begin();
}
Iterator End()
{
return this->items.end();
}
/* Pure virtual methods inherited from Packet. */ /* Pure virtual methods inherited from Packet. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
private:
std::vector<Item*> items;
};
/* Inline instance methods. */
template<typename Item>
inline FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(CommonHeader* commonHeader)
: FeedbackPsPacket(commonHeader)
{
}
template<typename Item>
inline FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackPsPacket(Item::messageType, senderSsrc, mediaSsrc)
{
}
template<typename Item>
FeedbackPsItemsPacket<Item>::~FeedbackPsItemsPacket()
{
for (auto* item : this->items)
{ {
delete item; size_t size = FeedbackPsPacket::GetSize();
}
}
template<typename Item> for (auto* item : this->items)
inline size_t FeedbackPsItemsPacket<Item>::GetSize() const {
{ size += item->GetSize();
size_t size = FeedbackPsPacket::GetSize(); }
for (auto* item : this->items) return size;
{
size += item->GetSize();
} }
return size; private:
} std::vector<Item*> items;
};
template<typename Item>
inline void FeedbackPsItemsPacket<Item>::AddItem(Item* item)
{
this->items.push_back(item);
}
template<typename Item>
inline typename FeedbackPsItemsPacket<Item>::Iterator FeedbackPsItemsPacket<Item>::Begin()
{
return this->items.begin();
}
template<typename Item>
inline typename FeedbackPsItemsPacket<Item>::Iterator FeedbackPsItemsPacket<Item>::End()
{
return this->items.end();
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -23,54 +23,43 @@ namespace RTC ...@@ -23,54 +23,43 @@ namespace RTC
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackPsAfbPacket( explicit FeedbackPsAfbPacket(
CommonHeader* commonHeader, Application application = Application::UNKNOWN); CommonHeader* commonHeader, Application application = Application::UNKNOWN)
: FeedbackPsPacket(commonHeader)
{
this->size = ((static_cast<size_t>(ntohs(commonHeader->length)) + 1) * 4) -
(sizeof(CommonHeader) + sizeof(FeedbackPacket::Header));
this->data = (uint8_t*)commonHeader + sizeof(CommonHeader) + sizeof(FeedbackPacket::Header);
this->application = application;
}
FeedbackPsAfbPacket( FeedbackPsAfbPacket(
uint32_t senderSsrc, uint32_t mediaSsrc, Application application = Application::UNKNOWN); uint32_t senderSsrc, uint32_t mediaSsrc, Application application = Application::UNKNOWN)
: FeedbackPsPacket(FeedbackPs::MessageType::AFB, senderSsrc, mediaSsrc)
{
this->application = application;
}
~FeedbackPsAfbPacket() override = default; ~FeedbackPsAfbPacket() override = default;
Application GetApplication() const; Application GetApplication() const
{
return this->application;
}
/* Pure virtual methods inherited from Packet. */ /* Pure virtual methods inherited from Packet. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return FeedbackPsPacket::GetSize() + this->size;
}
private: private:
Application application{ Application::UNKNOWN }; Application application{ Application::UNKNOWN };
uint8_t* data{ nullptr }; uint8_t* data{ nullptr };
size_t size{ 0 }; size_t size{ 0 };
}; };
/* Inline instance methods. */
inline FeedbackPsAfbPacket::FeedbackPsAfbPacket(CommonHeader* commonHeader, Application application)
: FeedbackPsPacket(commonHeader)
{
this->size = ((static_cast<size_t>(ntohs(commonHeader->length)) + 1) * 4) -
(sizeof(CommonHeader) + sizeof(FeedbackPacket::Header));
this->data = (uint8_t*)commonHeader + sizeof(CommonHeader) + sizeof(FeedbackPacket::Header);
this->application = application;
}
inline FeedbackPsAfbPacket::FeedbackPsAfbPacket(
uint32_t senderSsrc, uint32_t mediaSsrc, Application application)
: FeedbackPsPacket(FeedbackPs::MessageType::AFB, senderSsrc, mediaSsrc)
{
this->application = application;
}
inline FeedbackPsAfbPacket::Application FeedbackPsAfbPacket::GetApplication() const
{
return this->application;
}
inline size_t FeedbackPsAfbPacket::GetSize() const
{
return FeedbackPsPacket::GetSize() + this->size;
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -38,19 +38,32 @@ namespace RTC ...@@ -38,19 +38,32 @@ namespace RTC
static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::FIR }; static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::FIR };
public: public:
explicit FeedbackPsFirItem(Header* header); explicit FeedbackPsFirItem(Header* header) : header(header)
explicit FeedbackPsFirItem(FeedbackPsFirItem* item); {
}
explicit FeedbackPsFirItem(FeedbackPsFirItem* item) : header(item->header)
{
}
FeedbackPsFirItem(uint32_t ssrc, uint8_t sequenceNumber); FeedbackPsFirItem(uint32_t ssrc, uint8_t sequenceNumber);
~FeedbackPsFirItem() override = default; ~FeedbackPsFirItem() override = default;
uint32_t GetSsrc() const; uint32_t GetSsrc() const
uint8_t GetSequenceNumber() const; {
return uint32_t{ ntohl(this->header->ssrc) };
}
uint8_t GetSequenceNumber() const
{
return this->header->sequenceNumber;
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return sizeof(Header);
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -58,31 +71,6 @@ namespace RTC ...@@ -58,31 +71,6 @@ namespace RTC
// Fir packet declaration. // Fir packet declaration.
using FeedbackPsFirPacket = FeedbackPsItemsPacket<FeedbackPsFirItem>; using FeedbackPsFirPacket = FeedbackPsItemsPacket<FeedbackPsFirItem>;
/* Inline instance methods. */
inline FeedbackPsFirItem::FeedbackPsFirItem(Header* header) : header(header)
{
}
inline FeedbackPsFirItem::FeedbackPsFirItem(FeedbackPsFirItem* item) : header(item->header)
{
}
inline size_t FeedbackPsFirItem::GetSize() const
{
return sizeof(Header);
}
inline uint32_t FeedbackPsFirItem::GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
inline uint8_t FeedbackPsFirItem::GetSequenceNumber() const
{
return this->header->sequenceNumber;
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -29,18 +29,28 @@ namespace RTC ...@@ -29,18 +29,28 @@ namespace RTC
static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::PSLEI }; static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::PSLEI };
public: public:
explicit FeedbackPsLeiItem(Header* header); explicit FeedbackPsLeiItem(Header* header) : header(header)
explicit FeedbackPsLeiItem(FeedbackPsLeiItem* item); {
}
explicit FeedbackPsLeiItem(FeedbackPsLeiItem* item) : header(item->header)
{
}
explicit FeedbackPsLeiItem(uint32_t ssrc); explicit FeedbackPsLeiItem(uint32_t ssrc);
~FeedbackPsLeiItem() override = default; ~FeedbackPsLeiItem() override = default;
uint32_t GetSsrc() const; uint32_t GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return sizeof(Header);
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -48,26 +58,6 @@ namespace RTC ...@@ -48,26 +58,6 @@ namespace RTC
// Lei packet declaration. // Lei packet declaration.
using FeedbackPsLeiPacket = FeedbackPsItemsPacket<FeedbackPsLeiItem>; using FeedbackPsLeiPacket = FeedbackPsItemsPacket<FeedbackPsLeiItem>;
/* Inline instance methods. */
inline FeedbackPsLeiItem::FeedbackPsLeiItem(Header* header) : header(header)
{
}
inline FeedbackPsLeiItem::FeedbackPsLeiItem(FeedbackPsLeiItem* item) : header(item->header)
{
}
inline size_t FeedbackPsLeiItem::GetSize() const
{
return sizeof(Header);
}
inline uint32_t FeedbackPsLeiItem::GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -15,25 +15,18 @@ namespace RTC ...@@ -15,25 +15,18 @@ namespace RTC
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackPsPliPacket(CommonHeader* commonHeader); explicit FeedbackPsPliPacket(CommonHeader* commonHeader) : FeedbackPsPacket(commonHeader)
FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc); {
}
FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackPsPacket(FeedbackPs::MessageType::PLI, senderSsrc, mediaSsrc)
{
}
~FeedbackPsPliPacket() override = default; ~FeedbackPsPliPacket() override = default;
public: public:
void Dump() const override; void Dump() const override;
}; };
/* Inline instance methods. */
inline FeedbackPsPliPacket::FeedbackPsPliPacket(CommonHeader* commonHeader)
: FeedbackPsPacket(commonHeader)
{
}
inline FeedbackPsPliPacket::FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackPsPacket(FeedbackPs::MessageType::PLI, senderSsrc, mediaSsrc)
{
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -40,21 +40,42 @@ namespace RTC ...@@ -40,21 +40,42 @@ namespace RTC
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
FeedbackPsRembPacket(uint32_t senderSsrc, uint32_t mediaSsrc); FeedbackPsRembPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackPsAfbPacket(senderSsrc, mediaSsrc, FeedbackPsAfbPacket::Application::REMB)
{
}
FeedbackPsRembPacket(CommonHeader* commonHeader, size_t availableLen); FeedbackPsRembPacket(CommonHeader* commonHeader, size_t availableLen);
~FeedbackPsRembPacket() override = default; ~FeedbackPsRembPacket() override = default;
bool IsCorrect(); bool IsCorrect() const
void SetBitrate(uint64_t bitrate); {
void SetSsrcs(const std::vector<uint32_t>& ssrcs); return this->isCorrect;
uint64_t GetBitrate(); }
const std::vector<uint32_t>& GetSsrcs(); void SetBitrate(uint64_t bitrate)
{
this->bitrate = bitrate;
}
void SetSsrcs(const std::vector<uint32_t>& ssrcs)
{
this->ssrcs = ssrcs;
}
uint64_t GetBitrate()
{
return this->bitrate;
}
const std::vector<uint32_t>& GetSsrcs()
{
return this->ssrcs;
}
/* Pure virtual methods inherited from Packet. */ /* Pure virtual methods inherited from Packet. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return FeedbackPsPacket::GetSize() + 8 + (4u * this->ssrcs.size());
}
private: private:
std::vector<uint32_t> ssrcs; std::vector<uint32_t> ssrcs;
...@@ -62,43 +83,6 @@ namespace RTC ...@@ -62,43 +83,6 @@ namespace RTC
uint64_t bitrate{ 0 }; uint64_t bitrate{ 0 };
bool isCorrect{ true }; bool isCorrect{ true };
}; };
/* Inline instance methods. */
inline FeedbackPsRembPacket::FeedbackPsRembPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackPsAfbPacket(senderSsrc, mediaSsrc, FeedbackPsAfbPacket::Application::REMB)
{
}
inline bool FeedbackPsRembPacket::IsCorrect()
{
return this->isCorrect;
}
inline void FeedbackPsRembPacket::SetBitrate(uint64_t bitrate)
{
this->bitrate = bitrate;
}
inline void FeedbackPsRembPacket::SetSsrcs(const std::vector<uint32_t>& ssrcs)
{
this->ssrcs = ssrcs;
}
inline uint64_t FeedbackPsRembPacket::GetBitrate()
{
return this->bitrate;
}
inline const std::vector<uint32_t>& FeedbackPsRembPacket::GetSsrcs()
{
return this->ssrcs;
}
inline size_t FeedbackPsRembPacket::GetSize() const
{
return FeedbackPsPacket::GetSize() + 8 + (4u * this->ssrcs.size());
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -40,20 +40,37 @@ namespace RTC ...@@ -40,20 +40,37 @@ namespace RTC
public: public:
explicit FeedbackPsRpsiItem(Header* header); explicit FeedbackPsRpsiItem(Header* header);
explicit FeedbackPsRpsiItem(FeedbackPsRpsiItem* item); explicit FeedbackPsRpsiItem(FeedbackPsRpsiItem* item) : header(item->header)
{
}
FeedbackPsRpsiItem(uint8_t payloadType, uint8_t* bitString, size_t length); FeedbackPsRpsiItem(uint8_t payloadType, uint8_t* bitString, size_t length);
~FeedbackPsRpsiItem() override = default; ~FeedbackPsRpsiItem() override = default;
bool IsCorrect() const; bool IsCorrect() const
uint8_t GetPayloadType() const; {
uint8_t* GetBitString() const; return this->isCorrect;
size_t GetLength() const; }
uint8_t GetPayloadType() const
{
return this->header->payloadType;
}
uint8_t* GetBitString() const
{
return this->header->bitString;
}
size_t GetLength() const
{
return this->length;
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return sizeof(Header);
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -62,37 +79,6 @@ namespace RTC ...@@ -62,37 +79,6 @@ namespace RTC
// Rpsi packet declaration. // Rpsi packet declaration.
using FeedbackPsRpsiPacket = FeedbackPsItemsPacket<FeedbackPsRpsiItem>; using FeedbackPsRpsiPacket = FeedbackPsItemsPacket<FeedbackPsRpsiItem>;
/* Inline instance methods. */
inline FeedbackPsRpsiItem::FeedbackPsRpsiItem(FeedbackPsRpsiItem* item) : header(item->header)
{
}
inline size_t FeedbackPsRpsiItem::GetSize() const
{
return sizeof(Header);
}
inline uint8_t FeedbackPsRpsiItem::GetPayloadType() const
{
return this->header->payloadType;
}
inline uint8_t* FeedbackPsRpsiItem::GetBitString() const
{
return this->header->bitString;
}
inline size_t FeedbackPsRpsiItem::GetLength() const
{
return this->length;
}
inline bool FeedbackPsRpsiItem::IsCorrect() const
{
return this->isCorrect;
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -34,18 +34,39 @@ namespace RTC ...@@ -34,18 +34,39 @@ namespace RTC
FeedbackPsSliItem(uint16_t first, uint16_t number, uint8_t pictureId); FeedbackPsSliItem(uint16_t first, uint16_t number, uint8_t pictureId);
~FeedbackPsSliItem() override = default; ~FeedbackPsSliItem() override = default;
uint16_t GetFirst() const; uint16_t GetFirst() const
void SetFirst(uint16_t first); {
uint16_t GetNumber() const; return this->first;
void SetNumber(uint16_t number); }
uint8_t GetPictureId() const; void SetFirst(uint16_t first)
void SetPictureId(uint8_t pictureId); {
this->first = first;
}
uint16_t GetNumber() const
{
return this->number;
}
void SetNumber(uint16_t number)
{
this->number = number;
}
uint8_t GetPictureId() const
{
return this->pictureId;
}
void SetPictureId(uint8_t pictureId)
{
this->pictureId = pictureId;
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return sizeof(Header);
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -56,43 +77,6 @@ namespace RTC ...@@ -56,43 +77,6 @@ namespace RTC
// Sli packet declaration. // Sli packet declaration.
using FeedbackPsSliPacket = FeedbackPsItemsPacket<FeedbackPsSliItem>; using FeedbackPsSliPacket = FeedbackPsItemsPacket<FeedbackPsSliItem>;
/* Inline instance methods. */
inline size_t FeedbackPsSliItem::GetSize() const
{
return sizeof(Header);
}
inline uint16_t FeedbackPsSliItem::GetFirst() const
{
return this->first;
}
inline void FeedbackPsSliItem::SetFirst(uint16_t first)
{
this->first = first;
}
inline uint16_t FeedbackPsSliItem::GetNumber() const
{
return this->number;
}
inline void FeedbackPsSliItem::SetNumber(uint16_t number)
{
this->number = number;
}
inline uint8_t FeedbackPsSliItem::GetPictureId() const
{
return this->pictureId;
}
inline void FeedbackPsSliItem::SetPictureId(uint8_t pictureId)
{
this->pictureId = pictureId;
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -37,20 +37,36 @@ namespace RTC ...@@ -37,20 +37,36 @@ namespace RTC
static const FeedbackPs::MessageType messageType; static const FeedbackPs::MessageType messageType;
public: public:
explicit FeedbackPsTstItem(Header* header); explicit FeedbackPsTstItem(Header* header) : header(header)
explicit FeedbackPsTstItem(FeedbackPsTstItem* item); {
}
explicit FeedbackPsTstItem(FeedbackPsTstItem* item) : header(item->header)
{
}
FeedbackPsTstItem(uint32_t ssrc, uint8_t sequenceNumber, uint8_t index); FeedbackPsTstItem(uint32_t ssrc, uint8_t sequenceNumber, uint8_t index);
~FeedbackPsTstItem() override = default; ~FeedbackPsTstItem() override = default;
uint32_t GetSsrc() const; uint32_t GetSsrc() const
uint8_t GetSequenceNumber() const; {
uint8_t GetIndex() const; return uint32_t{ ntohl(this->header->ssrc) };
}
uint8_t GetSequenceNumber() const
{
return static_cast<uint8_t>(this->header->sequenceNumber);
}
uint8_t GetIndex() const
{
return static_cast<uint8_t>(this->header->index);
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return sizeof(Header);
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -71,42 +87,6 @@ namespace RTC ...@@ -71,42 +87,6 @@ namespace RTC
// Tst packets declaration. // Tst packets declaration.
using FeedbackPsTstrPacket = FeedbackPsItemsPacket<FeedbackPsTstrItem>; using FeedbackPsTstrPacket = FeedbackPsItemsPacket<FeedbackPsTstrItem>;
using FeedbackPsTstnPacket = FeedbackPsItemsPacket<FeedbackPsTstnItem>; using FeedbackPsTstnPacket = FeedbackPsItemsPacket<FeedbackPsTstnItem>;
/* Inline instance methods. */
template<typename T>
inline FeedbackPsTstItem<T>::FeedbackPsTstItem(Header* header) : header(header)
{
}
template<typename T>
inline FeedbackPsTstItem<T>::FeedbackPsTstItem(FeedbackPsTstItem* item) : header(item->header)
{
}
template<typename T>
inline size_t FeedbackPsTstItem<T>::GetSize() const
{
return sizeof(Header);
}
template<typename T>
inline uint32_t FeedbackPsTstItem<T>::GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
template<typename T>
inline uint8_t FeedbackPsTstItem<T>::GetSequenceNumber() const
{
return static_cast<uint8_t>(this->header->sequenceNumber);
}
template<typename T>
inline uint8_t FeedbackPsTstItem<T>::GetIndex() const
{
return static_cast<uint8_t>(this->header->index);
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -40,23 +40,48 @@ namespace RTC ...@@ -40,23 +40,48 @@ namespace RTC
static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::FIR }; static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::FIR };
public: public:
explicit FeedbackPsVbcmItem(Header* header); explicit FeedbackPsVbcmItem(Header* header) : header(header)
explicit FeedbackPsVbcmItem(FeedbackPsVbcmItem* item); {
}
explicit FeedbackPsVbcmItem(FeedbackPsVbcmItem* item) : header(item->header)
{
}
FeedbackPsVbcmItem( FeedbackPsVbcmItem(
uint32_t ssrc, uint8_t sequenceNumber, uint8_t payloadType, uint16_t length, uint8_t* value); uint32_t ssrc, uint8_t sequenceNumber, uint8_t payloadType, uint16_t length, uint8_t* value);
~FeedbackPsVbcmItem() override = default; ~FeedbackPsVbcmItem() override = default;
uint32_t GetSsrc() const; uint32_t GetSsrc() const
uint8_t GetSequenceNumber() const; {
uint8_t GetPayloadType() const; return uint32_t{ ntohl(this->header->ssrc) };
uint16_t GetLength() const; }
uint8_t* GetValue() const; uint8_t GetSequenceNumber() const
{
return uint8_t{ this->header->sequenceNumber };
}
uint8_t GetPayloadType() const
{
return uint8_t{ this->header->payloadType };
}
uint16_t GetLength() const
{
return uint16_t{ ntohs(this->header->length) };
}
uint8_t* GetValue() const
{
return this->header->value;
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
size_t size = 8 + static_cast<size_t>(GetLength());
// Consider pading to 32 bits (4 bytes) boundary.
return (size + 3) & ~3;
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -64,49 +89,6 @@ namespace RTC ...@@ -64,49 +89,6 @@ namespace RTC
// Vbcm packet declaration. // Vbcm packet declaration.
using FeedbackPsVbcmPacket = FeedbackPsItemsPacket<FeedbackPsVbcmItem>; using FeedbackPsVbcmPacket = FeedbackPsItemsPacket<FeedbackPsVbcmItem>;
/* Inline instance methods. */
inline FeedbackPsVbcmItem::FeedbackPsVbcmItem(Header* header) : header(header)
{
}
inline FeedbackPsVbcmItem::FeedbackPsVbcmItem(FeedbackPsVbcmItem* item) : header(item->header)
{
}
inline size_t FeedbackPsVbcmItem::GetSize() const
{
size_t size = 8 + static_cast<size_t>(GetLength());
// Consider pading to 32 bits (4 bytes) boundary.
return (size + 3) & ~3;
}
inline uint32_t FeedbackPsVbcmItem::GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
inline uint8_t FeedbackPsVbcmItem::GetSequenceNumber() const
{
return uint8_t{ this->header->sequenceNumber };
}
inline uint8_t FeedbackPsVbcmItem::GetPayloadType() const
{
return uint8_t{ this->header->payloadType };
}
inline uint16_t FeedbackPsVbcmItem::GetLength() const
{
return uint16_t{ ntohs(this->header->length) };
}
inline uint8_t* FeedbackPsVbcmItem::GetValue() const
{
return this->header->value;
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -20,77 +20,53 @@ namespace RTC ...@@ -20,77 +20,53 @@ namespace RTC
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackRtpItemsPacket(CommonHeader* commonHeader); explicit FeedbackRtpItemsPacket(CommonHeader* commonHeader) : FeedbackRtpPacket(commonHeader)
explicit FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0); {
~FeedbackRtpItemsPacket(); }
explicit FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0)
: FeedbackRtpPacket(Item::messageType, senderSsrc, mediaSsrc)
{
}
~FeedbackRtpItemsPacket()
{
for (auto* item : this->items)
{
delete item;
}
}
void AddItem(Item* item); void AddItem(Item* item)
Iterator Begin(); {
Iterator End(); this->items.push_back(item);
}
Iterator Begin()
{
return this->items.begin();
}
Iterator End()
{
return this->items.end();
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
private:
std::vector<Item*> items;
};
/* Inline instance methods. */
template<typename Item>
inline FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(CommonHeader* commonHeader)
: FeedbackRtpPacket(commonHeader)
{
}
template<typename Item>
inline FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackRtpPacket(Item::messageType, senderSsrc, mediaSsrc)
{
}
template<typename Item>
FeedbackRtpItemsPacket<Item>::~FeedbackRtpItemsPacket()
{
for (auto* item : this->items)
{ {
delete item; size_t size = FeedbackRtpPacket::GetSize();
}
}
template<typename Item> for (auto* item : this->items)
inline size_t FeedbackRtpItemsPacket<Item>::GetSize() const {
{ size += item->GetSize();
size_t size = FeedbackRtpPacket::GetSize(); }
for (auto* item : this->items) return size;
{
size += item->GetSize();
} }
return size; private:
} std::vector<Item*> items;
};
template<typename Item>
inline void FeedbackRtpItemsPacket<Item>::AddItem(Item* item)
{
this->items.push_back(item);
}
template<typename Item>
inline typename FeedbackRtpItemsPacket<Item>::Iterator FeedbackRtpItemsPacket<Item>::Begin()
{
return this->items.begin();
}
template<typename Item>
inline typename FeedbackRtpItemsPacket<Item>::Iterator FeedbackRtpItemsPacket<Item>::End()
{
return this->items.end();
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -45,23 +45,51 @@ namespace RTC ...@@ -45,23 +45,51 @@ namespace RTC
static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::ECN }; static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::ECN };
public: public:
explicit FeedbackRtpEcnItem(Header* header); explicit FeedbackRtpEcnItem(Header* header) : header(header)
explicit FeedbackRtpEcnItem(FeedbackRtpEcnItem* item); {
}
explicit FeedbackRtpEcnItem(FeedbackRtpEcnItem* item) : header(item->header)
{
}
~FeedbackRtpEcnItem() override = default; ~FeedbackRtpEcnItem() override = default;
uint32_t GetSequenceNumber() const; uint32_t GetSequenceNumber() const
uint32_t GetEct0Counter() const; {
uint32_t GetEct1Counter() const; return uint32_t{ ntohl(this->header->sequenceNumber) };
uint16_t GetEcnCeCounter() const; }
uint16_t GetNotEctCounter() const; uint32_t GetEct0Counter() const
uint16_t GetLostPackets() const; {
uint16_t GetDuplicatedPackets() const; return uint32_t{ ntohl(this->header->ect0Counter) };
}
uint32_t GetEct1Counter() const
{
return uint32_t{ ntohl(this->header->ect1Counter) };
}
uint16_t GetEcnCeCounter() const
{
return uint16_t{ ntohs(this->header->ecnCeCounter) };
}
uint16_t GetNotEctCounter() const
{
return uint16_t{ ntohs(this->header->notEctCounter) };
}
uint16_t GetLostPackets() const
{
return uint16_t{ ntohs(this->header->lostPackets) };
}
uint16_t GetDuplicatedPackets() const
{
return uint16_t{ ntohs(this->header->duplicatedPackets) };
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return sizeof(Header);
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -69,56 +97,6 @@ namespace RTC ...@@ -69,56 +97,6 @@ namespace RTC
// Ecn packet declaration. // Ecn packet declaration.
using FeedbackRtpEcnPacket = FeedbackRtpItemsPacket<FeedbackRtpEcnItem>; using FeedbackRtpEcnPacket = FeedbackRtpItemsPacket<FeedbackRtpEcnItem>;
/* Inline instance methods. */
inline FeedbackRtpEcnItem::FeedbackRtpEcnItem(Header* header) : header(header)
{
}
inline FeedbackRtpEcnItem::FeedbackRtpEcnItem(FeedbackRtpEcnItem* item) : header(item->header)
{
}
inline size_t FeedbackRtpEcnItem::GetSize() const
{
return sizeof(Header);
}
inline uint32_t FeedbackRtpEcnItem::GetSequenceNumber() const
{
return uint32_t{ ntohl(this->header->sequenceNumber) };
}
inline uint32_t FeedbackRtpEcnItem::GetEct0Counter() const
{
return uint32_t{ ntohl(this->header->ect0Counter) };
}
inline uint32_t FeedbackRtpEcnItem::GetEct1Counter() const
{
return uint32_t{ ntohl(this->header->ect1Counter) };
}
inline uint16_t FeedbackRtpEcnItem::GetEcnCeCounter() const
{
return uint16_t{ ntohs(this->header->ecnCeCounter) };
}
inline uint16_t FeedbackRtpEcnItem::GetNotEctCounter() const
{
return uint16_t{ ntohs(this->header->notEctCounter) };
}
inline uint16_t FeedbackRtpEcnItem::GetLostPackets() const
{
return uint16_t{ ntohs(this->header->lostPackets) };
}
inline uint16_t FeedbackRtpEcnItem::GetDuplicatedPackets() const
{
return uint16_t{ ntohs(this->header->duplicatedPackets) };
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -31,20 +31,36 @@ namespace RTC ...@@ -31,20 +31,36 @@ namespace RTC
static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::NACK }; static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::NACK };
public: public:
explicit FeedbackRtpNackItem(Header* header); explicit FeedbackRtpNackItem(Header* header) : header(header)
explicit FeedbackRtpNackItem(FeedbackRtpNackItem* item); {
}
explicit FeedbackRtpNackItem(FeedbackRtpNackItem* item) : header(item->header)
{
}
FeedbackRtpNackItem(uint16_t packetId, uint16_t lostPacketBitmask); FeedbackRtpNackItem(uint16_t packetId, uint16_t lostPacketBitmask);
~FeedbackRtpNackItem() override = default; ~FeedbackRtpNackItem() override = default;
uint16_t GetPacketId() const; uint16_t GetPacketId() const
uint16_t GetLostPacketBitmask() const; {
size_t CountRequestedPackets() const; return uint16_t{ ntohs(this->header->packetId) };
}
uint16_t GetLostPacketBitmask() const
{
return uint16_t{ ntohs(this->header->lostPacketBitmask) };
}
size_t CountRequestedPackets() const
{
return Utils::Bits::CountSetBits(this->header->lostPacketBitmask) + 1;
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return sizeof(Header);
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -52,37 +68,6 @@ namespace RTC ...@@ -52,37 +68,6 @@ namespace RTC
// Nack packet declaration. // Nack packet declaration.
using FeedbackRtpNackPacket = FeedbackRtpItemsPacket<FeedbackRtpNackItem>; using FeedbackRtpNackPacket = FeedbackRtpItemsPacket<FeedbackRtpNackItem>;
/* Inline instance methods. */
inline FeedbackRtpNackItem::FeedbackRtpNackItem(Header* header) : header(header)
{
}
inline FeedbackRtpNackItem::FeedbackRtpNackItem(FeedbackRtpNackItem* item)
: header(item->header)
{
}
inline size_t FeedbackRtpNackItem::GetSize() const
{
return sizeof(Header);
}
inline uint16_t FeedbackRtpNackItem::GetPacketId() const
{
return uint16_t{ ntohs(this->header->packetId) };
}
inline uint16_t FeedbackRtpNackItem::GetLostPacketBitmask() const
{
return uint16_t{ ntohs(this->header->lostPacketBitmask) };
}
inline size_t FeedbackRtpNackItem::CountRequestedPackets() const
{
return Utils::Bits::CountSetBits(this->header->lostPacketBitmask) + 1;
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -15,24 +15,17 @@ namespace RTC ...@@ -15,24 +15,17 @@ namespace RTC
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackRtpSrReqPacket(CommonHeader* commonHeader); explicit FeedbackRtpSrReqPacket(CommonHeader* commonHeader) : FeedbackRtpPacket(commonHeader)
FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc); {
}
FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackRtpPacket(FeedbackRtp::MessageType::SR_REQ, senderSsrc, mediaSsrc)
{
}
~FeedbackRtpSrReqPacket() override = default; ~FeedbackRtpSrReqPacket() override = default;
void Dump() const override; void Dump() const override;
}; };
/* Inline instance methods. */
inline FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(CommonHeader* commonHeader)
: FeedbackRtpPacket(commonHeader)
{
}
inline FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackRtpPacket(FeedbackRtp::MessageType::SR_REQ, senderSsrc, mediaSsrc)
{
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -30,19 +30,32 @@ namespace RTC ...@@ -30,19 +30,32 @@ namespace RTC
static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::TLLEI }; static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::TLLEI };
public: public:
explicit FeedbackRtpTlleiItem(Header* header); explicit FeedbackRtpTlleiItem(Header* header) : header(header)
explicit FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item); {
}
explicit FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item) : header(item->header)
{
}
FeedbackRtpTlleiItem(uint16_t packetId, uint16_t lostPacketBitmask); FeedbackRtpTlleiItem(uint16_t packetId, uint16_t lostPacketBitmask);
~FeedbackRtpTlleiItem() override = default; ~FeedbackRtpTlleiItem() override = default;
uint16_t GetPacketId() const; uint16_t GetPacketId() const
uint16_t GetLostPacketBitmask() const; {
return uint16_t{ ntohs(this->header->packetId) };
}
uint16_t GetLostPacketBitmask() const
{
return uint16_t{ ntohs(this->header->lostPacketBitmask) };
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return sizeof(Header);
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -50,32 +63,6 @@ namespace RTC ...@@ -50,32 +63,6 @@ namespace RTC
// Tllei packet declaration. // Tllei packet declaration.
using FeedbackRtpTlleiPacket = FeedbackRtpItemsPacket<FeedbackRtpTlleiItem>; using FeedbackRtpTlleiPacket = FeedbackRtpItemsPacket<FeedbackRtpTlleiItem>;
/* Inline instance methods. */
inline FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(Header* header) : header(header)
{
}
inline FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item)
: header(item->header)
{
}
inline size_t FeedbackRtpTlleiItem::GetSize() const
{
return sizeof(Header);
}
inline uint16_t FeedbackRtpTlleiItem::GetPacketId() const
{
return uint16_t{ ntohs(this->header->packetId) };
}
inline uint16_t FeedbackRtpTlleiItem::GetLostPacketBitmask() const
{
return uint16_t{ ntohs(this->header->lostPacketBitmask) };
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -34,23 +34,44 @@ namespace RTC ...@@ -34,23 +34,44 @@ namespace RTC
static const FeedbackRtp::MessageType messageType; static const FeedbackRtp::MessageType messageType;
public: public:
FeedbackRtpTmmbItem() = default;
explicit FeedbackRtpTmmbItem(const uint8_t* data); explicit FeedbackRtpTmmbItem(const uint8_t* data);
explicit FeedbackRtpTmmbItem(const Header* header); explicit FeedbackRtpTmmbItem(const Header* header);
FeedbackRtpTmmbItem();
~FeedbackRtpTmmbItem() override = default; ~FeedbackRtpTmmbItem() override = default;
uint32_t GetSsrc() const; uint32_t GetSsrc() const
void SetSsrc(uint32_t ssrc); {
uint64_t GetBitrate() const; return this->ssrc;
void SetBitrate(uint64_t bitrate); }
uint16_t GetOverhead() const; void SetSsrc(uint32_t ssrc)
void SetOverhead(uint16_t overhead); {
this->ssrc = ssrc;
}
uint64_t GetBitrate() const
{
return this->bitrate;
}
void SetBitrate(uint64_t bitrate)
{
this->bitrate = bitrate;
}
uint16_t GetOverhead() const
{
return this->overhead;
}
void SetOverhead(uint16_t overhead)
{
this->overhead = overhead;
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return sizeof(Header);
}
private: private:
uint32_t ssrc{ 0 }; uint32_t ssrc{ 0 };
...@@ -73,53 +94,6 @@ namespace RTC ...@@ -73,53 +94,6 @@ namespace RTC
// Tmmbn packets declaration. // Tmmbn packets declaration.
using FeedbackRtpTmmbrPacket = FeedbackRtpItemsPacket<FeedbackRtpTmmbrItem>; using FeedbackRtpTmmbrPacket = FeedbackRtpItemsPacket<FeedbackRtpTmmbrItem>;
using FeedbackRtpTmmbnPacket = FeedbackRtpItemsPacket<FeedbackRtpTmmbnItem>; using FeedbackRtpTmmbnPacket = FeedbackRtpItemsPacket<FeedbackRtpTmmbnItem>;
/* Inline instance methods. */
template<typename T>
inline FeedbackRtpTmmbItem<T>::FeedbackRtpTmmbItem() = default;
template<typename T>
inline size_t FeedbackRtpTmmbItem<T>::GetSize() const
{
return sizeof(Header);
}
template<typename T>
inline uint32_t FeedbackRtpTmmbItem<T>::GetSsrc() const
{
return this->ssrc;
}
template<typename T>
inline void FeedbackRtpTmmbItem<T>::SetSsrc(uint32_t ssrc)
{
this->ssrc = ssrc;
}
template<typename T>
inline uint64_t FeedbackRtpTmmbItem<T>::GetBitrate() const
{
return this->bitrate;
}
template<typename T>
inline void FeedbackRtpTmmbItem<T>::SetBitrate(uint64_t bitrate)
{
this->bitrate = bitrate;
}
template<typename T>
inline uint16_t FeedbackRtpTmmbItem<T>::GetOverhead() const
{
return this->overhead;
}
template<typename T>
inline void FeedbackRtpTmmbItem<T>::SetOverhead(uint16_t overhead)
{
this->overhead = overhead;
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -105,15 +105,23 @@ namespace RTC ...@@ -105,15 +105,23 @@ namespace RTC
class RunLengthChunk : public Chunk class RunLengthChunk : public Chunk
{ {
public: public:
RunLengthChunk(Status status, uint16_t count); RunLengthChunk(Status status, uint16_t count) : status(status), count(count)
{
}
explicit RunLengthChunk(uint16_t buffer); explicit RunLengthChunk(uint16_t buffer);
public: public:
bool AddDeltas( bool AddDeltas(
const uint8_t* data, size_t len, std::vector<int16_t>& deltas, size_t& offset) override; const uint8_t* data, size_t len, std::vector<int16_t>& deltas, size_t& offset) override;
Status GetStatus() const; Status GetStatus() const
{
return this->status;
}
void Dump() const override; void Dump() const override;
uint16_t GetCount() const override; uint16_t GetCount() const override
{
return this->count;
}
uint16_t GetReceivedStatusCount() const override; uint16_t GetReceivedStatusCount() const override;
void FillResults( void FillResults(
std::vector<struct PacketResult>& packetResults, std::vector<struct PacketResult>& packetResults,
...@@ -129,14 +137,19 @@ namespace RTC ...@@ -129,14 +137,19 @@ namespace RTC
class OneBitVectorChunk : public Chunk class OneBitVectorChunk : public Chunk
{ {
public: public:
explicit OneBitVectorChunk(const std::vector<Status>& statuses); explicit OneBitVectorChunk(const std::vector<Status>& statuses) : statuses(statuses)
{
}
OneBitVectorChunk(uint16_t buffer, uint16_t count); OneBitVectorChunk(uint16_t buffer, uint16_t count);
public: public:
bool AddDeltas( bool AddDeltas(
const uint8_t* data, size_t len, std::vector<int16_t>& deltas, size_t& offset) override; const uint8_t* data, size_t len, std::vector<int16_t>& deltas, size_t& offset) override;
void Dump() const override; void Dump() const override;
uint16_t GetCount() const override; uint16_t GetCount() const override
{
return this->statuses.size();
}
uint16_t GetReceivedStatusCount() const override; uint16_t GetReceivedStatusCount() const override;
void FillResults( void FillResults(
std::vector<struct PacketResult>& packetResults, std::vector<struct PacketResult>& packetResults,
...@@ -151,14 +164,19 @@ namespace RTC ...@@ -151,14 +164,19 @@ namespace RTC
class TwoBitVectorChunk : public Chunk class TwoBitVectorChunk : public Chunk
{ {
public: public:
explicit TwoBitVectorChunk(const std::vector<Status>& statuses); explicit TwoBitVectorChunk(const std::vector<Status>& statuses) : statuses(statuses)
{
}
TwoBitVectorChunk(uint16_t buffer, uint16_t count); TwoBitVectorChunk(uint16_t buffer, uint16_t count);
public: public:
bool AddDeltas( bool AddDeltas(
const uint8_t* data, size_t len, std::vector<int16_t>& deltas, size_t& offset) override; const uint8_t* data, size_t len, std::vector<int16_t>& deltas, size_t& offset) override;
void Dump() const override; void Dump() const override;
uint16_t GetCount() const override; uint16_t GetCount() const override
{
return this->statuses.size();
}
uint16_t GetReceivedStatusCount() const override; uint16_t GetReceivedStatusCount() const override;
void FillResults( void FillResults(
std::vector<struct PacketResult>& packetResults, std::vector<struct PacketResult>& packetResults,
...@@ -182,24 +200,63 @@ namespace RTC ...@@ -182,24 +200,63 @@ namespace RTC
static std::map<Status, std::string> status2String; static std::map<Status, std::string> status2String;
public: public:
FeedbackRtpTransportPacket(uint32_t senderSsrc, uint32_t mediaSsrc); FeedbackRtpTransportPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackRtpPacket(RTC::RTCP::FeedbackRtp::MessageType::TCC, senderSsrc, mediaSsrc)
{
}
FeedbackRtpTransportPacket(CommonHeader* commonHeader, size_t availableLen); FeedbackRtpTransportPacket(CommonHeader* commonHeader, size_t availableLen);
~FeedbackRtpTransportPacket(); ~FeedbackRtpTransportPacket();
public: public:
AddPacketResult AddPacket(uint16_t sequenceNumber, uint64_t timestamp, size_t maxRtcpPacketLen); AddPacketResult AddPacket(uint16_t sequenceNumber, uint64_t timestamp, size_t maxRtcpPacketLen);
void Finish(); // Just for locally generated packets. void Finish(); // Just for locally generated packets.
bool IsFull(); bool IsFull()
bool IsSerializable(); {
bool IsCorrect(); // Just for locally generated packets. // NOTE: Since AddPendingChunks() is called at the end, we cannot track
uint16_t GetBaseSequenceNumber() const; // the exact ongoing value of packetStatusCount. Hence, let's reserve 7
uint16_t GetPacketStatusCount() const; // packets just in case.
int32_t GetReferenceTime() const; return this->packetStatusCount >= FeedbackRtpTransportPacket::maxPacketStatusCount - 7;
int64_t GetReferenceTimestamp() const; // Reference time in ms. }
uint8_t GetFeedbackPacketCount() const; bool IsSerializable() const
void SetFeedbackPacketCount(uint8_t count); {
uint16_t GetLatestSequenceNumber() const; // Just for locally generated packets. return this->deltas.size() > 0;
uint64_t GetLatestTimestamp() const; // Just for locally generated packets. }
bool IsCorrect() const // Just for locally generated packets.
{
return this->isCorrect;
}
uint16_t GetBaseSequenceNumber() const
{
return this->baseSequenceNumber;
}
uint16_t GetPacketStatusCount() const
{
return this->packetStatusCount;
}
int32_t GetReferenceTime() const
{
return this->referenceTime;
}
int64_t GetReferenceTimestamp() const // Reference time in ms.
{
return static_cast<int64_t>(this->referenceTime) * 64;
}
uint8_t GetFeedbackPacketCount() const
{
return this->feedbackPacketCount;
}
void SetFeedbackPacketCount(uint8_t count)
{
this->feedbackPacketCount = count;
}
uint16_t GetLatestSequenceNumber() const // Just for locally generated packets.
{
return this->latestSequenceNumber;
}
uint64_t GetLatestTimestamp() const // Just for locally generated packets.
{
return this->latestTimestamp;
}
std::vector<struct PacketResult> GetPacketResults() const; std::vector<struct PacketResult> GetPacketResults() const;
uint8_t GetPacketFractionLost() const; uint8_t GetPacketFractionLost() const;
...@@ -207,7 +264,22 @@ namespace RTC ...@@ -207,7 +264,22 @@ namespace RTC
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
if (this->size)
return this->size;
// Fixed packet size.
size_t size = FeedbackRtpPacket::GetSize();
size += FeedbackRtpTransportPacket::fixedHeaderSize;
size += this->deltasAndChunksSize;
// 32 bits padding.
size += (-size) & 3;
return size;
}
private: private:
void FillChunk(uint16_t previousSequenceNumber, uint16_t sequenceNumber, int16_t delta); void FillChunk(uint16_t previousSequenceNumber, uint16_t sequenceNumber, int16_t delta);
...@@ -230,125 +302,6 @@ namespace RTC ...@@ -230,125 +302,6 @@ namespace RTC
size_t size{ 0 }; size_t size{ 0 };
bool isCorrect{ true }; bool isCorrect{ true };
}; };
/* Inline instance methods. */
inline FeedbackRtpTransportPacket::FeedbackRtpTransportPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackRtpPacket(RTC::RTCP::FeedbackRtp::MessageType::TCC, senderSsrc, mediaSsrc)
{
}
inline bool FeedbackRtpTransportPacket::IsFull()
{
// NOTE: Since AddPendingChunks() is called at the end, we cannot track
// the exact ongoing value of packetStatusCount. Hence, let's reserve 7
// packets just in case.
return this->packetStatusCount >= FeedbackRtpTransportPacket::maxPacketStatusCount - 7;
}
inline bool FeedbackRtpTransportPacket::IsSerializable()
{
return this->deltas.size() > 0;
}
inline bool FeedbackRtpTransportPacket::IsCorrect()
{
return this->isCorrect;
}
inline uint16_t FeedbackRtpTransportPacket::GetBaseSequenceNumber() const
{
return this->baseSequenceNumber;
}
inline uint16_t FeedbackRtpTransportPacket::GetPacketStatusCount() const
{
return this->packetStatusCount;
}
inline int32_t FeedbackRtpTransportPacket::GetReferenceTime() const
{
return this->referenceTime;
}
inline int64_t FeedbackRtpTransportPacket::GetReferenceTimestamp() const
{
return static_cast<int64_t>(this->referenceTime) * 64;
}
inline uint8_t FeedbackRtpTransportPacket::GetFeedbackPacketCount() const
{
return this->feedbackPacketCount;
}
inline void FeedbackRtpTransportPacket::SetFeedbackPacketCount(uint8_t count)
{
this->feedbackPacketCount = count;
}
inline uint16_t FeedbackRtpTransportPacket::GetLatestSequenceNumber() const
{
return this->latestSequenceNumber;
}
inline uint64_t FeedbackRtpTransportPacket::GetLatestTimestamp() const
{
return this->latestTimestamp;
}
inline size_t FeedbackRtpTransportPacket::GetSize() const
{
if (this->size)
return this->size;
// Fixed packet size.
size_t size = FeedbackRtpPacket::GetSize();
size += FeedbackRtpTransportPacket::fixedHeaderSize;
size += this->deltasAndChunksSize;
// 32 bits padding.
size += (-size) & 3;
return size;
}
inline FeedbackRtpTransportPacket::RunLengthChunk::RunLengthChunk(Status status, uint16_t count)
: status(status), count(count)
{
}
inline uint16_t FeedbackRtpTransportPacket::RunLengthChunk::GetCount() const
{
return this->count;
}
inline FeedbackRtpTransportPacket::Status FeedbackRtpTransportPacket::RunLengthChunk::GetStatus() const
{
return this->status;
}
inline FeedbackRtpTransportPacket::TwoBitVectorChunk::TwoBitVectorChunk(
const std::vector<Status>& statuses)
: statuses(statuses)
{
}
inline uint16_t FeedbackRtpTransportPacket::TwoBitVectorChunk::GetCount() const
{
return this->statuses.size();
}
inline FeedbackRtpTransportPacket::OneBitVectorChunk::OneBitVectorChunk(
const std::vector<Status>& statuses)
: statuses(statuses)
{
}
inline uint16_t FeedbackRtpTransportPacket::OneBitVectorChunk::GetCount() const
{
return this->statuses.size();
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -49,7 +49,24 @@ namespace RTC ...@@ -49,7 +49,24 @@ namespace RTC
}; };
public: public:
static bool IsRtcp(const uint8_t* data, size_t len); static bool IsRtcp(const uint8_t* data, size_t len)
{
auto header = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data));
// clang-format off
return (
(len >= sizeof(CommonHeader)) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 127 && data[0] < 192) &&
// RTP Version must be 2.
(header->version == 2) &&
// RTCP packet types defined by IANA:
// http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4
// RFC 5761 (RTCP-mux) states this range for secure RTCP/RTP detection.
(header->packetType >= 192 && header->packetType <= 223)
);
// clang-format on
}
static Packet* Parse(const uint8_t* data, size_t len); static Packet* Parse(const uint8_t* data, size_t len);
static const std::string& Type2String(Type type); static const std::string& Type2String(Type type);
...@@ -57,86 +74,47 @@ namespace RTC ...@@ -57,86 +74,47 @@ namespace RTC
static std::map<Type, std::string> type2String; static std::map<Type, std::string> type2String;
public: public:
explicit Packet(Type type); explicit Packet(Type type) : type(type)
explicit Packet(CommonHeader* commonHeader); {
virtual ~Packet(); }
explicit Packet(CommonHeader* commonHeader)
{
this->type = RTCP::Type(commonHeader->packetType);
this->header = commonHeader;
}
virtual ~Packet() = default;
void SetNext(Packet* packet); void SetNext(Packet* packet)
Packet* GetNext() const; {
const uint8_t* GetData() const; this->next = packet;
}
Packet* GetNext() const
{
return this->next;
}
const uint8_t* GetData() const
{
return reinterpret_cast<uint8_t*>(this->header);
}
public: public:
virtual void Dump() const = 0; virtual void Dump() const = 0;
virtual size_t Serialize(uint8_t* buffer) = 0; virtual size_t Serialize(uint8_t* buffer) = 0;
virtual Type GetType() const; virtual Type GetType() const
virtual size_t GetCount() const = 0; {
virtual size_t GetSize() const = 0; return this->type;
}
virtual size_t GetCount() const
{
return 0u;
}
virtual size_t GetSize() const = 0;
private: private:
Type type; Type type;
Packet* next{ nullptr }; Packet* next{ nullptr };
CommonHeader* header{ nullptr }; CommonHeader* header{ nullptr };
}; };
/* Inline static methods. */
inline bool Packet::IsRtcp(const uint8_t* data, size_t len)
{
auto header = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data));
// clang-format off
return (
(len >= sizeof(CommonHeader)) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 127 && data[0] < 192) &&
// RTP Version must be 2.
(header->version == 2) &&
// RTCP packet types defined by IANA:
// http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4
// RFC 5761 (RTCP-mux) states this range for secure RTCP/RTP detection.
(header->packetType >= 192 && header->packetType <= 223)
);
// clang-format on
}
/* Inline instance methods. */
inline Packet::Packet(Type type) : type(type)
{
}
inline Packet::Packet(CommonHeader* commonHeader)
{
this->type = RTCP::Type(commonHeader->packetType);
this->header = commonHeader;
}
inline Packet::~Packet() = default;
inline Packet* Packet::GetNext() const
{
return this->next;
}
inline void Packet::SetNext(Packet* packet)
{
this->next = packet;
}
inline Type Packet::GetType() const
{
return this->type;
}
inline size_t Packet::GetCount() const
{
return 0;
}
inline const uint8_t* Packet::GetData() const
{
return reinterpret_cast<uint8_t*>(this->header);
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -29,29 +29,97 @@ namespace RTC ...@@ -29,29 +29,97 @@ namespace RTC
static ReceiverReport* Parse(const uint8_t* data, size_t len); static ReceiverReport* Parse(const uint8_t* data, size_t len);
public: public:
// Parsed Report. Points to an external data.
explicit ReceiverReport(Header* header);
explicit ReceiverReport(ReceiverReport* report);
// Locally generated Report. Holds the data internally. // Locally generated Report. Holds the data internally.
ReceiverReport(); ReceiverReport()
{
this->header = reinterpret_cast<Header*>(this->raw);
}
// Parsed Report. Points to an external data.
explicit ReceiverReport(Header* header) : header(header)
{
}
explicit ReceiverReport(ReceiverReport* report) : header(report->header)
{
}
void Dump() const; void Dump() const;
size_t Serialize(uint8_t* buffer); size_t Serialize(uint8_t* buffer);
size_t GetSize() const; size_t GetSize() const
uint32_t GetSsrc() const; {
void SetSsrc(uint32_t ssrc); return sizeof(Header);
uint8_t GetFractionLost() const; }
void SetFractionLost(uint8_t fractionLost); uint32_t GetSsrc() const
int32_t GetTotalLost() const; {
void SetTotalLost(int32_t totalLost); return uint32_t{ ntohl(this->header->ssrc) };
uint32_t GetLastSeq() const; }
void SetLastSeq(uint32_t lastSeq); void SetSsrc(uint32_t ssrc)
uint32_t GetJitter() const; {
void SetJitter(uint32_t jitter); this->header->ssrc = uint32_t{ htonl(ssrc) };
uint32_t GetLastSenderReport() const; }
void SetLastSenderReport(uint32_t lsr); uint8_t GetFractionLost() const
uint32_t GetDelaySinceLastSenderReport() const; {
void SetDelaySinceLastSenderReport(uint32_t dlsr); return uint8_t{ Utils::Byte::Get1Byte((uint8_t*)this->header, 4) };
}
void SetFractionLost(uint8_t fractionLost)
{
Utils::Byte::Set1Byte((uint8_t*)this->header, 4, fractionLost);
}
int32_t GetTotalLost() const
{
auto value = uint32_t{ Utils::Byte::Get3Bytes((uint8_t*)this->header, 5) };
// Possitive value.
if (((value >> 23) & 1) == 0)
return value;
// Negative value.
if (value != 0x0800000)
value &= ~(1 << 23);
return -value;
}
void SetTotalLost(int32_t totalLost)
{
// Get the limit value for possitive and negative totalLost.
int32_t clamp = (totalLost >= 0) ? totalLost > 0x07FFFFF ? 0x07FFFFF : totalLost
: -totalLost > 0x0800000 ? 0x0800000 : -totalLost;
uint32_t value = (totalLost >= 0) ? (clamp & 0x07FFFFF) : (clamp | 0x0800000);
Utils::Byte::Set3Bytes(reinterpret_cast<uint8_t*>(this->header), 5, value);
}
uint32_t GetLastSeq() const
{
return uint32_t{ ntohl(this->header->lastSeq) };
}
void SetLastSeq(uint32_t lastSeq)
{
this->header->lastSeq = uint32_t{ htonl(lastSeq) };
}
uint32_t GetJitter() const
{
return uint32_t{ ntohl(this->header->jitter) };
}
void SetJitter(uint32_t jitter)
{
this->header->jitter = uint32_t{ htonl(jitter) };
}
uint32_t GetLastSenderReport() const
{
return uint32_t{ ntohl(this->header->lsr) };
}
void SetLastSenderReport(uint32_t lsr)
{
this->header->lsr = uint32_t{ htonl(lsr) };
}
uint32_t GetDelaySinceLastSenderReport() const
{
return uint32_t{ ntohl(this->header->dlsr) };
}
void SetDelaySinceLastSenderReport(uint32_t dlsr)
{
this->header->dlsr = uint32_t{ htonl(dlsr) };
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -67,203 +135,74 @@ namespace RTC ...@@ -67,203 +135,74 @@ namespace RTC
static ReceiverReportPacket* Parse(const uint8_t* data, size_t len, size_t offset = 0); static ReceiverReportPacket* Parse(const uint8_t* data, size_t len, size_t offset = 0);
public: public:
ReceiverReportPacket(); ReceiverReportPacket() : Packet(Type::RR)
explicit ReceiverReportPacket(CommonHeader* commonHeader); {
~ReceiverReportPacket() override; }
explicit ReceiverReportPacket(CommonHeader* commonHeader) : Packet(commonHeader)
{
}
~ReceiverReportPacket() override
{
for (auto* report : this->reports)
{
delete report;
}
}
uint32_t GetSsrc() const; uint32_t GetSsrc() const
void SetSsrc(uint32_t ssrc); {
void AddReport(ReceiverReport* report); return this->ssrc;
Iterator Begin(); }
Iterator End(); void SetSsrc(uint32_t ssrc)
{
this->ssrc = ssrc;
}
void AddReport(ReceiverReport* report)
{
this->reports.push_back(report);
}
Iterator Begin()
{
return this->reports.begin();
}
Iterator End()
{
return this->reports.end();
}
/* Pure virtual methods inherited from Packet. */ /* Pure virtual methods inherited from Packet. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
Type GetType() const override; // NOTE: We need to force this since when we parse a SenderReportPacket that
size_t GetCount() const override; // contains receive report blocks we also generate a second ReceiverReportPacket
size_t GetSize() const override; // from same data and len, so parent Packet::GetType() would return
// this->type which would be SR instead of RR.
private: Type GetType() const override
// SSRC of packet sender.
uint32_t ssrc{ 0u };
std::vector<ReceiverReport*> reports;
};
/* Inline instance methods. */
inline ReceiverReport::ReceiverReport()
{
this->header = reinterpret_cast<Header*>(this->raw);
}
inline ReceiverReport::ReceiverReport(Header* header) : header(header)
{
}
inline ReceiverReport::ReceiverReport(ReceiverReport* report) : header(report->header)
{
}
inline size_t ReceiverReport::GetSize() const
{
return sizeof(Header);
}
inline uint32_t ReceiverReport::GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
inline void ReceiverReport::SetSsrc(uint32_t ssrc)
{
this->header->ssrc = uint32_t{ htonl(ssrc) };
}
inline uint8_t ReceiverReport::GetFractionLost() const
{
return uint8_t{ Utils::Byte::Get1Byte((uint8_t*)this->header, 4) };
}
inline void ReceiverReport::SetFractionLost(uint8_t fractionLost)
{
Utils::Byte::Set1Byte((uint8_t*)this->header, 4, fractionLost);
}
inline int32_t ReceiverReport::GetTotalLost() const
{
auto value = uint32_t{ Utils::Byte::Get3Bytes((uint8_t*)this->header, 5) };
// Possitive value.
if (((value >> 23) & 1) == 0)
return value;
// Negative value.
if (value != 0x0800000)
value &= ~(1 << 23);
return -value;
}
inline void ReceiverReport::SetTotalLost(int32_t totalLost)
{
// Get the limit value for possitive and negative totalLost.
int32_t clamp = (totalLost >= 0) ? totalLost > 0x07FFFFF ? 0x07FFFFF : totalLost
: -totalLost > 0x0800000 ? 0x0800000 : -totalLost;
uint32_t value = (totalLost >= 0) ? (clamp & 0x07FFFFF) : (clamp | 0x0800000);
Utils::Byte::Set3Bytes(reinterpret_cast<uint8_t*>(this->header), 5, value);
}
inline uint32_t ReceiverReport::GetLastSeq() const
{
return uint32_t{ ntohl(this->header->lastSeq) };
}
inline void ReceiverReport::SetLastSeq(uint32_t lastSeq)
{
this->header->lastSeq = uint32_t{ htonl(lastSeq) };
}
inline uint32_t ReceiverReport::GetJitter() const
{
return uint32_t{ ntohl(this->header->jitter) };
}
inline void ReceiverReport::SetJitter(uint32_t jitter)
{
this->header->jitter = uint32_t{ htonl(jitter) };
}
inline uint32_t ReceiverReport::GetLastSenderReport() const
{
return uint32_t{ ntohl(this->header->lsr) };
}
inline void ReceiverReport::SetLastSenderReport(uint32_t lsr)
{
this->header->lsr = uint32_t{ htonl(lsr) };
}
inline uint32_t ReceiverReport::GetDelaySinceLastSenderReport() const
{
return uint32_t{ ntohl(this->header->dlsr) };
}
inline void ReceiverReport::SetDelaySinceLastSenderReport(uint32_t dlsr)
{
this->header->dlsr = uint32_t{ htonl(dlsr) };
}
inline ReceiverReportPacket::ReceiverReportPacket() : Packet(Type::RR)
{
}
inline ReceiverReportPacket::ReceiverReportPacket(CommonHeader* commonHeader)
: Packet(commonHeader)
{
}
inline ReceiverReportPacket::~ReceiverReportPacket()
{
for (auto* report : this->reports)
{ {
delete report; return Type::RR;
} }
} size_t GetCount() const override
// NOTE: We need to force this since when we parse a SenderReportPacket that
// contains receive report blocks we also generate a second ReceiverReportPacket
// from same data and len, so parent Packet::GetType() would return
// this->type which would be SR instead of RR.
inline Type ReceiverReportPacket::GetType() const
{
return Type::RR;
}
inline size_t ReceiverReportPacket::GetCount() const
{
return this->reports.size();
}
inline size_t ReceiverReportPacket::GetSize() const
{
size_t size = sizeof(Packet::CommonHeader) + 4u /* this->ssrc */;
for (auto* report : reports)
{ {
size += report->GetSize(); return this->reports.size();
} }
size_t GetSize() const override
{
size_t size = sizeof(Packet::CommonHeader) + 4u /* this->ssrc */;
return size; for (auto* report : reports)
} {
size += report->GetSize();
inline uint32_t ReceiverReportPacket::GetSsrc() const }
{
return this->ssrc;
}
inline void ReceiverReportPacket::SetSsrc(uint32_t ssrc)
{
this->ssrc = ssrc;
}
inline void ReceiverReportPacket::AddReport(ReceiverReport* report)
{
this->reports.push_back(report);
}
inline ReceiverReportPacket::Iterator ReceiverReportPacket::Begin() return size;
{ }
return this->reports.begin();
}
inline ReceiverReportPacket::Iterator ReceiverReportPacket::End() private:
{ // SSRC of packet sender.
return this->reports.end(); uint32_t ssrc{ 0u };
} std::vector<ReceiverReport*> reports;
};
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -41,18 +41,34 @@ namespace RTC ...@@ -41,18 +41,34 @@ namespace RTC
static const std::string& Type2String(SdesItem::Type type); static const std::string& Type2String(SdesItem::Type type);
public: public:
explicit SdesItem(Header* header); explicit SdesItem(Header* header) : header(header)
explicit SdesItem(SdesItem* item); {
}
explicit SdesItem(SdesItem* item) : header(item->header)
{
}
SdesItem(SdesItem::Type type, size_t len, const char* value); SdesItem(SdesItem::Type type, size_t len, const char* value);
~SdesItem() = default; ~SdesItem() = default;
void Dump() const; void Dump() const;
size_t Serialize(uint8_t* buffer); size_t Serialize(uint8_t* buffer);
size_t GetSize() const; size_t GetSize() const
{
return 2 + size_t{ this->header->length };
}
SdesItem::Type GetType() const; SdesItem::Type GetType() const
uint8_t GetLength() const; {
char* GetValue() const; return this->header->type;
}
uint8_t GetLength() const
{
return this->header->length;
}
char* GetValue() const
{
return this->header->value;
}
private: private:
// Passed by argument. // Passed by argument.
...@@ -72,19 +88,63 @@ namespace RTC ...@@ -72,19 +88,63 @@ namespace RTC
static SdesChunk* Parse(const uint8_t* data, size_t len); static SdesChunk* Parse(const uint8_t* data, size_t len);
public: public:
explicit SdesChunk(uint32_t ssrc); explicit SdesChunk(uint32_t ssrc)
explicit SdesChunk(SdesChunk* chunk); {
~SdesChunk(); this->ssrc = ssrc;
}
explicit SdesChunk(SdesChunk* chunk)
{
this->ssrc = chunk->ssrc;
for (auto it = chunk->Begin(); it != chunk->End(); ++it)
{
this->AddItem(new SdesItem(*it));
}
}
~SdesChunk()
{
for (auto* item : this->items)
{
delete item;
}
}
void Dump() const; void Dump() const;
void Serialize(); void Serialize();
size_t Serialize(uint8_t* buffer); size_t Serialize(uint8_t* buffer);
size_t GetSize() const; size_t GetSize() const
uint32_t GetSsrc() const; {
void SetSsrc(uint32_t ssrc); size_t size = 4u /*ssrc*/;
void AddItem(SdesItem* item);
Iterator Begin(); for (auto* item : this->items)
Iterator End(); {
size += item->GetSize();
}
// Consider pading to 32 bits (4 bytes) boundary.
// http://stackoverflow.com/questions/11642210/computing-padding-required-for-n-byte-alignment
return (size + 3) & ~3;
}
uint32_t GetSsrc() const
{
return this->ssrc;
}
void SetSsrc(uint32_t ssrc)
{
this->ssrc = htonl(ssrc);
}
void AddItem(SdesItem* item)
{
this->items.push_back(item);
}
Iterator Begin()
{
return this->items.begin();
}
Iterator End()
{
return this->items.end();
}
private: private:
uint32_t ssrc{ 0u }; uint32_t ssrc{ 0u };
...@@ -100,168 +160,56 @@ namespace RTC ...@@ -100,168 +160,56 @@ namespace RTC
static SdesPacket* Parse(const uint8_t* data, size_t len); static SdesPacket* Parse(const uint8_t* data, size_t len);
public: public:
SdesPacket(); SdesPacket() : Packet(RTCP::Type::SDES)
explicit SdesPacket(CommonHeader* commonHeader);
~SdesPacket() override;
void AddChunk(SdesChunk* chunk);
Iterator Begin();
Iterator End();
/* Pure virtual methods inherited from Packet. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override;
size_t GetSize() const override;
private:
std::vector<SdesChunk*> chunks;
};
/* SDES Item inline instance methods */
inline SdesItem::SdesItem(Header* header) : header(header)
{
}
inline SdesItem::SdesItem(SdesItem* item) : header(item->header)
{
}
inline size_t SdesItem::GetSize() const
{
return 2 + size_t{ this->header->length };
}
inline SdesItem::Type SdesItem::GetType() const
{
return this->header->type;
}
inline uint8_t SdesItem::GetLength() const
{
return this->header->length;
}
inline char* SdesItem::GetValue() const
{
return this->header->value;
}
/* Inline instance methods. */
inline SdesChunk::SdesChunk(uint32_t ssrc)
{
this->ssrc = ssrc;
}
inline SdesChunk::SdesChunk(SdesChunk* chunk)
{
this->ssrc = chunk->ssrc;
for (auto it = chunk->Begin(); it != chunk->End(); ++it)
{ {
this->AddItem(new SdesItem(*it));
} }
} explicit SdesPacket(CommonHeader* commonHeader) : Packet(commonHeader)
inline SdesChunk::~SdesChunk()
{
for (auto* item : this->items)
{ {
delete item;
} }
} ~SdesPacket() override
inline size_t SdesChunk::GetSize() const
{
size_t size = 4u /*ssrc*/;
for (auto* item : this->items)
{ {
size += item->GetSize(); for (auto* chunk : this->chunks)
{
delete chunk;
}
} }
// Consider pading to 32 bits (4 bytes) boundary. void AddChunk(SdesChunk* chunk)
// http://stackoverflow.com/questions/11642210/computing-padding-required-for-n-byte-alignment
return (size + 3) & ~3;
}
inline uint32_t SdesChunk::GetSsrc() const
{
return this->ssrc;
}
inline void SdesChunk::SetSsrc(uint32_t ssrc)
{
this->ssrc = htonl(ssrc);
}
inline void SdesChunk::AddItem(SdesItem* item)
{
this->items.push_back(item);
}
inline SdesChunk::Iterator SdesChunk::Begin()
{
return this->items.begin();
}
inline SdesChunk::Iterator SdesChunk::End()
{
return this->items.end();
}
/* Inline instance methods. */
inline SdesPacket::SdesPacket() : Packet(RTCP::Type::SDES)
{
}
inline SdesPacket::SdesPacket(CommonHeader* commonHeader) : Packet(commonHeader)
{
}
inline SdesPacket::~SdesPacket()
{
for (auto* chunk : this->chunks)
{ {
delete chunk; this->chunks.push_back(chunk);
} }
} Iterator Begin()
inline size_t SdesPacket::GetCount() const
{
return this->chunks.size();
}
inline size_t SdesPacket::GetSize() const
{
size_t size = sizeof(Packet::CommonHeader);
for (auto* chunk : this->chunks)
{ {
size += chunk->GetSize(); return this->chunks.begin();
}
Iterator End()
{
return this->chunks.end();
} }
return size; /* Pure virtual methods inherited from Packet. */
} public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override
{
return this->chunks.size();
}
size_t GetSize() const override
{
size_t size = sizeof(Packet::CommonHeader);
inline void SdesPacket::AddChunk(SdesChunk* chunk) for (auto* chunk : this->chunks)
{ {
this->chunks.push_back(chunk); size += chunk->GetSize();
} }
inline SdesPacket::Iterator SdesPacket::Begin() return size;
{ }
return this->chunks.begin();
}
inline SdesPacket::Iterator SdesPacket::End() private:
{ std::vector<SdesChunk*> chunks;
return this->chunks.end(); };
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -27,27 +27,73 @@ namespace RTC ...@@ -27,27 +27,73 @@ namespace RTC
static SenderReport* Parse(const uint8_t* data, size_t len); static SenderReport* Parse(const uint8_t* data, size_t len);
public: public:
// Parsed Report. Points to an external data.
explicit SenderReport(Header* header);
explicit SenderReport(SenderReport* report);
// Locally generated Report. Holds the data internally. // Locally generated Report. Holds the data internally.
SenderReport(); SenderReport()
{
this->header = reinterpret_cast<Header*>(this->raw);
}
// Parsed Report. Points to an external data.
explicit SenderReport(Header* header) : header(header)
{
}
explicit SenderReport(SenderReport* report) : header(report->header)
{
}
void Dump() const; void Dump() const;
size_t Serialize(uint8_t* buffer); size_t Serialize(uint8_t* buffer);
size_t GetSize() const; size_t GetSize() const
uint32_t GetSsrc() const; {
void SetSsrc(uint32_t ssrc); return sizeof(Header);
uint32_t GetNtpSec() const; }
void SetNtpSec(uint32_t ntpSec); uint32_t GetSsrc() const
uint32_t GetNtpFrac() const; {
void SetNtpFrac(uint32_t ntpFrac); return uint32_t{ ntohl(this->header->ssrc) };
uint32_t GetRtpTs() const; }
void SetRtpTs(uint32_t rtpTs); void SetSsrc(uint32_t ssrc)
uint32_t GetPacketCount() const; {
void SetPacketCount(uint32_t packetCount); this->header->ssrc = uint32_t{ htonl(ssrc) };
uint32_t GetOctetCount() const; }
void SetOctetCount(uint32_t octetCount); uint32_t GetNtpSec() const
{
return uint32_t{ ntohl(this->header->ntpSec) };
}
void SetNtpSec(uint32_t ntpSec)
{
this->header->ntpSec = uint32_t{ htonl(ntpSec) };
}
uint32_t GetNtpFrac() const
{
return uint32_t{ ntohl(this->header->ntpFrac) };
}
void SetNtpFrac(uint32_t ntpFrac)
{
this->header->ntpFrac = uint32_t{ htonl(ntpFrac) };
}
uint32_t GetRtpTs() const
{
return uint32_t{ ntohl(this->header->rtpTs) };
}
void SetRtpTs(uint32_t rtpTs)
{
this->header->rtpTs = uint32_t{ htonl(rtpTs) };
}
uint32_t GetPacketCount() const
{
return uint32_t{ ntohl(this->header->packetCount) };
}
void SetPacketCount(uint32_t packetCount)
{
this->header->packetCount = uint32_t{ htonl(packetCount) };
}
uint32_t GetOctetCount() const
{
return uint32_t{ ntohl(this->header->octetCount) };
}
void SetOctetCount(uint32_t octetCount)
{
this->header->octetCount = uint32_t{ htonl(octetCount) };
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -63,154 +109,56 @@ namespace RTC ...@@ -63,154 +109,56 @@ namespace RTC
static SenderReportPacket* Parse(const uint8_t* data, size_t len); static SenderReportPacket* Parse(const uint8_t* data, size_t len);
public: public:
SenderReportPacket(); SenderReportPacket() : Packet(Type::SR)
explicit SenderReportPacket(CommonHeader* commonHeader); {
~SenderReportPacket() override; }
explicit SenderReportPacket(CommonHeader* commonHeader) : Packet(commonHeader)
{
}
~SenderReportPacket() override
{
for (auto* report : this->reports)
{
delete report;
}
}
void AddReport(SenderReport* report); void AddReport(SenderReport* report)
Iterator Begin(); {
Iterator End(); this->reports.push_back(report);
}
Iterator Begin()
{
return this->reports.begin();
}
Iterator End()
{
return this->reports.end();
}
/* Pure virtual methods inherited from Packet. */ /* Pure virtual methods inherited from Packet. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override; size_t GetCount() const override
size_t GetSize() const override;
private:
std::vector<SenderReport*> reports;
};
/* Inline instance methods. */
inline SenderReport::SenderReport()
{
this->header = reinterpret_cast<Header*>(this->raw);
}
inline SenderReport::SenderReport(Header* header) : header(header)
{
}
inline SenderReport::SenderReport(SenderReport* report) : header(report->header)
{
}
inline size_t SenderReport::GetSize() const
{
return sizeof(Header);
}
inline uint32_t SenderReport::GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
inline void SenderReport::SetSsrc(uint32_t ssrc)
{
this->header->ssrc = uint32_t{ htonl(ssrc) };
}
inline uint32_t SenderReport::GetNtpSec() const
{
return uint32_t{ ntohl(this->header->ntpSec) };
}
inline void SenderReport::SetNtpSec(uint32_t ntpSec)
{
this->header->ntpSec = uint32_t{ htonl(ntpSec) };
}
inline uint32_t SenderReport::GetNtpFrac() const
{
return uint32_t{ ntohl(this->header->ntpFrac) };
}
inline void SenderReport::SetNtpFrac(uint32_t ntpFrac)
{
this->header->ntpFrac = uint32_t{ htonl(ntpFrac) };
}
inline uint32_t SenderReport::GetRtpTs() const
{
return uint32_t{ ntohl(this->header->rtpTs) };
}
inline void SenderReport::SetRtpTs(uint32_t rtpTs)
{
this->header->rtpTs = uint32_t{ htonl(rtpTs) };
}
inline uint32_t SenderReport::GetPacketCount() const
{
return uint32_t{ ntohl(this->header->packetCount) };
}
inline void SenderReport::SetPacketCount(uint32_t packetCount)
{
this->header->packetCount = uint32_t{ htonl(packetCount) };
}
inline uint32_t SenderReport::GetOctetCount() const
{
return uint32_t{ ntohl(this->header->octetCount) };
}
inline void SenderReport::SetOctetCount(uint32_t octetCount)
{
this->header->octetCount = uint32_t{ htonl(octetCount) };
}
/* Inline instance methods. */
inline SenderReportPacket::SenderReportPacket() : Packet(Type::SR)
{
}
inline SenderReportPacket::SenderReportPacket(CommonHeader* commonHeader) : Packet(commonHeader)
{
}
inline SenderReportPacket::~SenderReportPacket()
{
for (auto* report : this->reports)
{ {
delete report; return 0;
} }
} size_t GetSize() const override
inline size_t SenderReportPacket::GetCount() const
{
return 0;
}
inline size_t SenderReportPacket::GetSize() const
{
size_t size = sizeof(Packet::CommonHeader);
for (auto* report : this->reports)
{ {
size += report->GetSize(); size_t size = sizeof(Packet::CommonHeader);
}
return size;
}
inline void SenderReportPacket::AddReport(SenderReport* report) for (auto* report : this->reports)
{ {
this->reports.push_back(report); size += report->GetSize();
} }
inline SenderReportPacket::Iterator SenderReportPacket::Begin() return size;
{ }
return this->reports.begin();
}
inline SenderReportPacket::Iterator SenderReportPacket::End() private:
{ std::vector<SenderReport*> reports;
return this->reports.end(); };
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -49,14 +49,22 @@ namespace RTC ...@@ -49,14 +49,22 @@ namespace RTC
static ExtendedReportBlock* Parse(const uint8_t* data, size_t len); static ExtendedReportBlock* Parse(const uint8_t* data, size_t len);
public: public:
ExtendedReportBlock(Type type); ExtendedReportBlock(Type type) : type(type)
{
this->header = reinterpret_cast<CommonHeader*>(this->raw);
this->header->reserved = 0;
}
virtual ~ExtendedReportBlock() = default; virtual ~ExtendedReportBlock() = default;
public: public:
virtual void Dump() const = 0; virtual void Dump() const = 0;
virtual size_t Serialize(uint8_t* buffer) = 0; virtual size_t Serialize(uint8_t* buffer) = 0;
virtual size_t GetSize() const = 0; virtual size_t GetSize() const = 0;
ExtendedReportBlock::Type GetType() const; ExtendedReportBlock::Type GetType() const
{
return this->type;
}
protected: protected:
Type type; Type type;
...@@ -75,102 +83,65 @@ namespace RTC ...@@ -75,102 +83,65 @@ namespace RTC
static ExtendedReportPacket* Parse(const uint8_t* data, size_t len); static ExtendedReportPacket* Parse(const uint8_t* data, size_t len);
public: public:
ExtendedReportPacket(); ExtendedReportPacket() : Packet(Type::XR)
explicit ExtendedReportPacket(CommonHeader* commonHeader); {
~ExtendedReportPacket() override; }
explicit ExtendedReportPacket(CommonHeader* commonHeader) : Packet(commonHeader)
{
}
~ExtendedReportPacket() override
{
for (auto* report : this->reports)
{
delete report;
}
}
void AddReport(ExtendedReportBlock* report); void AddReport(ExtendedReportBlock* report)
uint32_t GetSsrc() const; {
void SetSsrc(uint32_t ssrc); this->reports.push_back(report);
Iterator Begin(); }
Iterator End(); uint32_t GetSsrc() const
{
return this->ssrc;
}
void SetSsrc(uint32_t ssrc)
{
this->ssrc = ssrc;
}
Iterator Begin()
{
return this->reports.begin();
}
Iterator End()
{
return this->reports.end();
}
/* Pure virtual methods inherited from Packet. */ /* Pure virtual methods inherited from Packet. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override; size_t GetCount() const override
size_t GetSize() const override;
private:
uint32_t ssrc{ 0u };
std::vector<ExtendedReportBlock*> reports;
};
/* Inline ExtendedReportBlock instance methods. */
inline ExtendedReportBlock::ExtendedReportBlock(Type type) : type(type)
{
this->header = reinterpret_cast<CommonHeader*>(this->raw);
this->header->reserved = 0;
}
inline ExtendedReportBlock::Type ExtendedReportBlock::GetType() const
{
return this->type;
}
inline void ExtendedReportPacket::AddReport(ExtendedReportBlock* report)
{
this->reports.push_back(report);
}
inline uint32_t ExtendedReportPacket::GetSsrc() const
{
return this->ssrc;
}
inline void ExtendedReportPacket::SetSsrc(uint32_t ssrc)
{
this->ssrc = ssrc;
}
/* Inline ExtendedReportPacket instance methods. */
inline ExtendedReportPacket::ExtendedReportPacket() : Packet(Type::XR)
{
}
inline ExtendedReportPacket::ExtendedReportPacket(CommonHeader* commonHeader)
: Packet(commonHeader)
{
}
inline ExtendedReportPacket::~ExtendedReportPacket()
{
for (auto* report : this->reports)
{ {
delete report; return 0;
} }
} size_t GetSize() const override
{
inline ExtendedReportPacket::Iterator ExtendedReportPacket::Begin() size_t size = sizeof(Packet::CommonHeader) + 4u /*ssrc*/;
{
return this->reports.begin();
}
inline ExtendedReportPacket::Iterator ExtendedReportPacket::End()
{
return this->reports.end();
}
inline size_t ExtendedReportPacket::GetCount() const
{
return 0;
}
inline size_t ExtendedReportPacket::GetSize() const for (auto* report : this->reports)
{ {
size_t size = sizeof(Packet::CommonHeader) + 4u /*ssrc*/; size += report->GetSize();
}
for (auto* report : this->reports) return size;
{
size += report->GetSize();
} }
return size; private:
} uint32_t ssrc{ 0u };
std::vector<ExtendedReportBlock*> reports;
};
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -47,21 +47,46 @@ namespace RTC ...@@ -47,21 +47,46 @@ namespace RTC
}; };
public: public:
// Parsed Report. Points to an external data.
explicit SsrcInfo(Body* body);
// Locally generated Report. Holds the data internally. // Locally generated Report. Holds the data internally.
SsrcInfo(); SsrcInfo()
{
this->body = reinterpret_cast<Body*>(this->raw);
}
// Parsed Report. Points to an external data.
explicit SsrcInfo(Body* body) : body(body)
{
}
void Dump() const; void Dump() const;
size_t Serialize(uint8_t* buffer); size_t Serialize(uint8_t* buffer);
size_t GetSize() const; size_t GetSize() const
uint32_t GetSsrc() const; {
void SetSsrc(uint32_t ssrc); return sizeof(Body);
uint32_t GetLastReceiverReport() const; }
void SetLastReceiverReport(uint32_t lrr); uint32_t GetSsrc() const
uint32_t GetDelaySinceLastReceiverReport() const; {
void SetDelaySinceLastReceiverReport(uint32_t dlrr); return uint32_t{ ntohl(this->body->ssrc) };
}
void SetSsrc(uint32_t ssrc)
{
this->body->ssrc = uint32_t{ htonl(ssrc) };
}
uint32_t GetLastReceiverReport() const
{
return uint32_t{ ntohl(this->body->lrr) };
}
void SetLastReceiverReport(uint32_t lrr)
{
this->body->lrr = uint32_t{ htonl(lrr) };
}
uint32_t GetDelaySinceLastReceiverReport() const
{
return uint32_t{ ntohl(this->body->dlrr) };
}
void SetDelaySinceLastReceiverReport(uint32_t dlrr)
{
this->body->dlrr = uint32_t{ htonl(dlrr) };
}
private: private:
Body* body{ nullptr }; Body* body{ nullptr };
...@@ -72,118 +97,55 @@ namespace RTC ...@@ -72,118 +97,55 @@ namespace RTC
using Iterator = std::vector<SsrcInfo*>::iterator; using Iterator = std::vector<SsrcInfo*>::iterator;
public: public:
explicit DelaySinceLastRr(CommonHeader* header); DelaySinceLastRr() : ExtendedReportBlock(ExtendedReportBlock::Type::DLRR)
DelaySinceLastRr(); {
~DelaySinceLastRr(); }
explicit DelaySinceLastRr(CommonHeader* header)
: ExtendedReportBlock(ExtendedReportBlock::Type::DLRR)
{
this->header = header;
}
~DelaySinceLastRr()
{
for (auto* ssrcInfo : this->ssrcInfos)
{
delete ssrcInfo;
}
}
public: public:
void AddSsrcInfo(SsrcInfo* ssrcInfo); void AddSsrcInfo(SsrcInfo* ssrcInfo)
Iterator Begin(); {
Iterator End(); this->ssrcInfos.push_back(ssrcInfo);
}
Iterator Begin()
{
return this->ssrcInfos.begin();
}
Iterator End()
{
return this->ssrcInfos.end();
}
/* Pure virtual methods inherited from ExtendedReportBlock. */ /* Pure virtual methods inherited from ExtendedReportBlock. */
public: public:
virtual void Dump() const override; virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override; virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override; virtual size_t GetSize() const override
private:
std::vector<SsrcInfo*> ssrcInfos;
};
/* Inline SsrcInfo instance methods. */
inline DelaySinceLastRr::SsrcInfo::SsrcInfo()
{
this->body = reinterpret_cast<Body*>(this->raw);
}
inline DelaySinceLastRr::SsrcInfo::SsrcInfo(Body* body) : body(body)
{
}
inline size_t DelaySinceLastRr::SsrcInfo::GetSize() const
{
return sizeof(Body);
}
inline uint32_t DelaySinceLastRr::SsrcInfo::GetSsrc() const
{
return uint32_t{ ntohl(this->body->ssrc) };
}
inline void DelaySinceLastRr::SsrcInfo::SetSsrc(uint32_t ssrc)
{
this->body->ssrc = uint32_t{ htonl(ssrc) };
}
inline uint32_t DelaySinceLastRr::SsrcInfo::GetLastReceiverReport() const
{
return uint32_t{ ntohl(this->body->lrr) };
}
inline void DelaySinceLastRr::SsrcInfo::SetLastReceiverReport(uint32_t lrr)
{
this->body->lrr = uint32_t{ htonl(lrr) };
}
inline uint32_t DelaySinceLastRr::SsrcInfo::GetDelaySinceLastReceiverReport() const
{
return uint32_t{ ntohl(this->body->dlrr) };
}
inline void DelaySinceLastRr::SsrcInfo::SetDelaySinceLastReceiverReport(uint32_t dlrr)
{
this->body->dlrr = uint32_t{ htonl(dlrr) };
}
/* Inline DelaySinceLastRr instance methods. */
inline DelaySinceLastRr::DelaySinceLastRr(CommonHeader* header)
: ExtendedReportBlock(ExtendedReportBlock::Type::DLRR)
{
this->header = header;
}
inline DelaySinceLastRr::DelaySinceLastRr()
: ExtendedReportBlock(ExtendedReportBlock::Type::DLRR)
{
}
inline DelaySinceLastRr::~DelaySinceLastRr()
{
for (auto* ssrcInfo : this->ssrcInfos)
{ {
delete ssrcInfo; size_t size{ 4u }; // Common header.
}
}
inline void DelaySinceLastRr::AddSsrcInfo(SsrcInfo* ssrcInfo)
{
this->ssrcInfos.push_back(ssrcInfo);
}
inline DelaySinceLastRr::Iterator DelaySinceLastRr::Begin()
{
return this->ssrcInfos.begin();
}
inline DelaySinceLastRr::Iterator DelaySinceLastRr::End() for (auto* ssrcInfo : this->ssrcInfos)
{ {
return this->ssrcInfos.end(); size += ssrcInfo->GetSize();
} }
inline size_t DelaySinceLastRr::GetSize() const
{
size_t size{ 4 }; // Common header.
for (auto* ssrcInfo : this->ssrcInfos) return size;
{
size += ssrcInfo->GetSize();
} }
return size; private:
} std::vector<SsrcInfo*> ssrcInfos;
};
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -34,71 +34,54 @@ namespace RTC ...@@ -34,71 +34,54 @@ namespace RTC
static ReceiverReferenceTime* Parse(const uint8_t* data, size_t len); static ReceiverReferenceTime* Parse(const uint8_t* data, size_t len);
public: public:
// Parsed Report. Points to an external data.
explicit ReceiverReferenceTime(CommonHeader* header);
// Locally generated Report. Holds the data internally. // Locally generated Report. Holds the data internally.
ReceiverReferenceTime(); ReceiverReferenceTime() : ExtendedReportBlock(RTCP::ExtendedReportBlock::Type::RRT)
{
this->body = reinterpret_cast<Body*>(this->raw);
}
// Parsed Report. Points to an external data.
explicit ReceiverReferenceTime(CommonHeader* header)
: ExtendedReportBlock(ExtendedReportBlock::Type::RRT)
{
this->header = header;
this->body = reinterpret_cast<Body*>((header) + 1);
}
public: public:
uint32_t GetNtpSec() const; uint32_t GetNtpSec() const
void SetNtpSec(uint32_t ntpSec); {
uint32_t GetNtpFrac() const; return uint32_t{ ntohl(this->body->ntpSec) };
void SetNtpFrac(uint32_t ntpFrac); }
void SetNtpSec(uint32_t ntpSec)
{
this->body->ntpSec = uint32_t{ htonl(ntpSec) };
}
uint32_t GetNtpFrac() const
{
return uint32_t{ ntohl(this->body->ntpFrac) };
}
void SetNtpFrac(uint32_t ntpFrac)
{
this->body->ntpFrac = uint32_t{ htonl(ntpFrac) };
}
/* Pure virtual methods inherited from ExtendedReportBlock. */ /* Pure virtual methods inherited from ExtendedReportBlock. */
public: public:
virtual void Dump() const override; virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override; virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override; virtual size_t GetSize() const override
{
size_t size{ 4 }; // Common header.
size += sizeof(Body);
return size;
}
private: private:
Body* body{ nullptr }; Body* body{ nullptr };
uint8_t raw[sizeof(Body)] = { 0 }; uint8_t raw[sizeof(Body)] = { 0 };
}; };
/* Inline ReceiverReferenceTime instance methods. */
inline ReceiverReferenceTime::ReceiverReferenceTime()
: ExtendedReportBlock(RTCP::ExtendedReportBlock::Type::RRT)
{
this->body = reinterpret_cast<Body*>(this->raw);
}
inline ReceiverReferenceTime::ReceiverReferenceTime(CommonHeader* header)
: ExtendedReportBlock(ExtendedReportBlock::Type::RRT)
{
this->header = header;
this->body = reinterpret_cast<Body*>((header) + 1);
}
inline size_t ReceiverReferenceTime::GetSize() const
{
size_t size{ 4 }; // Common header.
size += sizeof(Body);
return size;
}
inline uint32_t ReceiverReferenceTime::GetNtpSec() const
{
return uint32_t{ ntohl(this->body->ntpSec) };
}
inline void ReceiverReferenceTime::SetNtpSec(uint32_t ntpSec)
{
this->body->ntpSec = uint32_t{ htonl(ntpSec) };
}
inline uint32_t ReceiverReferenceTime::GetNtpFrac() const
{
return uint32_t{ ntohl(this->body->ntpFrac) };
}
inline void ReceiverReferenceTime::SetNtpFrac(uint32_t ntpFrac)
{
this->body->ntpFrac = uint32_t{ htonl(ntpFrac) };
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -12,24 +12,44 @@ namespace RTC ...@@ -12,24 +12,44 @@ namespace RTC
class RateCalculator class RateCalculator
{ {
public: public:
static constexpr size_t DefaultWindowSize{ 1000 }; static constexpr size_t DefaultWindowSize{ 1000u };
static constexpr float DefaultBpsScale{ 8000.0f }; static constexpr float DefaultBpsScale{ 8000.0f };
public: public:
RateCalculator(size_t windowSize = DefaultWindowSize, float scale = DefaultBpsScale); RateCalculator(size_t windowSize = DefaultWindowSize, float scale = DefaultBpsScale)
: windowSize(windowSize), scale(scale)
{
Reset();
}
void Update(size_t size, uint64_t nowMs); void Update(size_t size, uint64_t nowMs);
uint32_t GetRate(uint64_t nowMs); uint32_t GetRate(uint64_t nowMs);
size_t GetBytes() const; size_t GetBytes() const
void Reset(); {
return this->bytes;
}
void Reset()
{
uint64_t nowMs = DepLibUV::GetTimeMs();
Reset(nowMs);
}
private: private:
void RemoveOldData(uint64_t nowMs); void RemoveOldData(uint64_t nowMs);
void Reset(uint64_t nowMs); void Reset(uint64_t nowMs)
{
this->buffer.reset(new BufferItem[this->windowSize]);
this->oldestTime = nowMs - this->windowSize;
this->oldestIndex = 0u;
this->totalCount = 0u;
this->lastRate = 0u;
this->lastTime = 0u;
}
private: private:
struct BufferItem struct BufferItem
{ {
size_t count{ 0 }; size_t count{ 0u };
}; };
private: private:
...@@ -40,85 +60,45 @@ namespace RTC ...@@ -40,85 +60,45 @@ namespace RTC
// Buffer to keep data. // Buffer to keep data.
std::unique_ptr<BufferItem[]> buffer; std::unique_ptr<BufferItem[]> buffer;
// Time (in milliseconds) for oldest item in the time window. // Time (in milliseconds) for oldest item in the time window.
uint64_t oldestTime{ 0 }; uint64_t oldestTime{ 0u };
// Index for the oldest item in the time window. // Index for the oldest item in the time window.
uint32_t oldestIndex{ 0 }; uint32_t oldestIndex{ 0u };
// Total count in the time window. // Total count in the time window.
size_t totalCount{ 0 }; size_t totalCount{ 0u };
// Total bytes transmitted. // Total bytes transmitted.
size_t bytes{ 0 }; size_t bytes{ 0u };
// Last value calculated by GetRate(). // Last value calculated by GetRate().
uint32_t lastRate{ 0 }; uint32_t lastRate{ 0u };
// Last time GetRate() was called. // Last time GetRate() was called.
uint64_t lastTime{ 0 }; uint64_t lastTime{ 0u };
}; };
/* Inline instance methods. */
inline RateCalculator::RateCalculator(size_t windowSize, float scale)
: windowSize(windowSize), scale(scale)
{
Reset();
}
inline size_t RateCalculator::GetBytes() const
{
return this->bytes;
}
inline void RateCalculator::Reset()
{
uint64_t nowMs = DepLibUV::GetTimeMs();
Reset(nowMs);
}
inline void RateCalculator::Reset(uint64_t nowMs)
{
this->buffer.reset(new BufferItem[this->windowSize]);
this->oldestTime = nowMs - this->windowSize;
this->oldestIndex = 0;
this->totalCount = 0;
this->lastRate = 0;
this->lastTime = 0;
}
class RtpDataCounter class RtpDataCounter
{ {
public: public:
explicit RtpDataCounter(size_t windowSize = 2500); explicit RtpDataCounter(size_t windowSize = 2500) : rate(windowSize)
{
}
public: public:
void Update(RTC::RtpPacket* packet); void Update(RTC::RtpPacket* packet);
uint32_t GetBitrate(uint64_t nowMs); uint32_t GetBitrate(uint64_t nowMs)
size_t GetPacketCount() const; {
size_t GetBytes() const; return this->rate.GetRate(nowMs);
}
size_t GetPacketCount() const
{
return this->packets;
}
size_t GetBytes() const
{
return this->rate.GetBytes();
}
private: private:
RateCalculator rate; RateCalculator rate;
size_t packets{ 0 }; size_t packets{ 0u };
}; };
/* Inline instance methods. */
inline RtpDataCounter::RtpDataCounter(size_t windowSize) : rate(windowSize)
{
}
inline uint32_t RtpDataCounter::GetBitrate(uint64_t nowMs)
{
return this->rate.GetRate(nowMs);
}
inline size_t RtpDataCounter::GetPacketCount() const
{
return this->packets;
}
inline size_t RtpDataCounter::GetBytes() const
{
return this->rate.GetBytes();
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -174,9 +174,9 @@ namespace RTC ...@@ -174,9 +174,9 @@ namespace RTC
public: public:
RtpCodecMimeType mimeType; RtpCodecMimeType mimeType;
uint8_t payloadType{ 0 }; uint8_t payloadType{ 0u };
uint32_t clockRate{ 0 }; uint32_t clockRate{ 0u };
uint8_t channels{ 1 }; uint8_t channels{ 1u };
RTC::Parameters parameters; RTC::Parameters parameters;
std::vector<RtcpFeedback> rtcpFeedback; std::vector<RtcpFeedback> rtcpFeedback;
}; };
...@@ -190,7 +190,7 @@ namespace RTC ...@@ -190,7 +190,7 @@ namespace RTC
void FillJson(json& jsonObject) const; void FillJson(json& jsonObject) const;
public: public:
uint32_t ssrc{ 0 }; uint32_t ssrc{ 0u };
}; };
class RtpEncodingParameters class RtpEncodingParameters
...@@ -202,18 +202,18 @@ namespace RTC ...@@ -202,18 +202,18 @@ namespace RTC
void FillJson(json& jsonObject) const; void FillJson(json& jsonObject) const;
public: public:
uint32_t ssrc{ 0 }; uint32_t ssrc{ 0u };
std::string rid; std::string rid;
uint8_t codecPayloadType{ 0 }; uint8_t codecPayloadType{ 0u };
bool hasCodecPayloadType{ false }; bool hasCodecPayloadType{ false };
RtpRtxParameters rtx; RtpRtxParameters rtx;
bool hasRtx{ false }; bool hasRtx{ false };
uint32_t maxBitrate{ 0 }; uint32_t maxBitrate{ 0u };
double maxFramerate{ 0 }; double maxFramerate{ 0 };
bool dtx{ false }; bool dtx{ false };
std::string scalabilityMode; std::string scalabilityMode;
uint8_t spatialLayers{ 1 }; uint8_t spatialLayers{ 1u };
uint8_t temporalLayers{ 1 }; uint8_t temporalLayers{ 1u };
bool ksvc{ false }; bool ksvc{ false };
}; };
...@@ -228,7 +228,7 @@ namespace RTC ...@@ -228,7 +228,7 @@ namespace RTC
public: public:
std::string uri; std::string uri;
RtpHeaderExtensionUri::Type type; RtpHeaderExtensionUri::Type type;
uint8_t id{ 0 }; uint8_t id{ 0u };
bool encrypt{ false }; bool encrypt{ false };
RTC::Parameters parameters; RTC::Parameters parameters;
}; };
...@@ -243,7 +243,7 @@ namespace RTC ...@@ -243,7 +243,7 @@ namespace RTC
public: public:
std::string cname; std::string cname;
uint32_t ssrc{ 0 }; uint32_t ssrc{ 0u };
bool reducedSize{ true }; bool reducedSize{ true };
}; };
......
...@@ -17,7 +17,10 @@ namespace RTC ...@@ -17,7 +17,10 @@ namespace RTC
public: public:
void Pause(); void Pause();
void Resume(); void Resume();
bool IsPaused() const; bool IsPaused() const
{
return this->paused;
}
virtual void AddProducer(RTC::Producer* producer) = 0; virtual void AddProducer(RTC::Producer* producer) = 0;
virtual void RemoveProducer(RTC::Producer* producer) = 0; virtual void RemoveProducer(RTC::Producer* producer) = 0;
virtual void ReceiveRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) = 0; virtual void ReceiveRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) = 0;
...@@ -36,11 +39,6 @@ namespace RTC ...@@ -36,11 +39,6 @@ namespace RTC
// Others. // Others.
bool paused{ false }; bool paused{ false };
}; };
inline bool RtpObserver::IsPaused() const
{
return this->paused;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -114,7 +114,23 @@ namespace RTC ...@@ -114,7 +114,23 @@ namespace RTC
}; };
public: public:
static bool IsRtp(const uint8_t* data, size_t len); static bool IsRtp(const uint8_t* data, size_t len)
{
// NOTE: RtcpPacket::IsRtcp() must always be called before this method.
auto header = const_cast<Header*>(reinterpret_cast<const Header*>(data));
// clang-format off
return (
(len >= sizeof(Header)) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 127 && data[0] < 192) &&
// RTP Version must be 2.
(header->version == 2)
);
// clang-format on
}
static RtpPacket* Parse(const uint8_t* data, size_t len); static RtpPacket* Parse(const uint8_t* data, size_t len);
private: private:
...@@ -130,545 +146,488 @@ namespace RTC ...@@ -130,545 +146,488 @@ namespace RTC
~RtpPacket(); ~RtpPacket();
void Dump() const; void Dump() const;
void FillJson(json& jsonObject) const; void FillJson(json& jsonObject) const;
const uint8_t* GetData() const;
size_t GetSize() const;
uint8_t GetPayloadType() const;
void SetPayloadType(uint8_t payloadType);
bool HasMarker() const;
void SetMarker(bool marker);
void SetPayloadPaddingFlag(bool flag);
uint16_t GetSequenceNumber() const;
void SetSequenceNumber(uint16_t seq);
uint32_t GetTimestamp() const;
void SetTimestamp(uint32_t timestamp);
uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc);
bool HasHeaderExtension() const;
// After calling this method, all the extension ids are reset to 0.
void SetExtensions(uint8_t type, const std::vector<GenericExtension>& extensions);
uint16_t GetHeaderExtensionId() const;
size_t GetHeaderExtensionLength() const;
uint8_t* GetHeaderExtensionValue() const;
bool HasOneByteExtensions() const;
bool HasTwoBytesExtensions() const;
void SetMidExtensionId(uint8_t id);
void SetRidExtensionId(uint8_t id);
void SetRepairedRidExtensionId(uint8_t id);
void SetAbsSendTimeExtensionId(uint8_t id);
void SetTransportWideCc01ExtensionId(uint8_t id);
void SetFrameMarking07ExtensionId(uint8_t id); // NOTE: Remove once RFC.
void SetFrameMarkingExtensionId(uint8_t id);
void SetSsrcAudioLevelExtensionId(uint8_t id);
void SetVideoOrientationExtensionId(uint8_t id);
bool ReadMid(std::string& mid) const;
bool UpdateMid(const std::string& mid);
bool ReadRid(std::string& rid) const;
bool ReadAbsSendTime(uint32_t& absSendtime) const;
bool UpdateAbsSendTime(uint64_t ms);
bool ReadTransportWideCc01(uint16_t& wideSeqNumber) const;
bool UpdateTransportWideCc01(uint16_t wideSeqNumber);
bool ReadFrameMarking(RtpPacket::FrameMarking** frameMarking, uint8_t& length) const;
bool ReadSsrcAudioLevel(uint8_t& volume, bool& voice) const;
bool ReadVideoOrientation(bool& camera, bool& flip, uint16_t& rotation) const;
bool HasExtension(uint8_t id) const;
uint8_t* GetExtension(uint8_t id, uint8_t& len) const;
bool SetExtensionLength(uint8_t id, uint8_t len);
uint8_t* GetPayload() const;
size_t GetPayloadLength() const;
void SetPayloadLength(size_t length);
uint8_t GetPayloadPadding() const;
uint8_t GetSpatialLayer() const;
uint8_t GetTemporalLayer() const;
bool IsKeyFrame() const;
RtpPacket* Clone(const uint8_t* buffer) const;
void RtxEncode(uint8_t payloadType, uint32_t ssrc, uint16_t seq);
bool RtxDecode(uint8_t payloadType, uint32_t ssrc);
void SetPayloadDescriptorHandler(RTC::Codecs::PayloadDescriptorHandler* payloadDescriptorHandler);
bool ProcessPayload(RTC::Codecs::EncodingContext* context);
void RestorePayload();
void ShiftPayload(size_t payloadOffset, size_t shift, bool expand = true);
private: const uint8_t* GetData() const
void ParseExtensions(); {
return (const uint8_t*)this->header;
}
private: size_t GetSize() const
// Passed by argument. {
Header* header{ nullptr }; return this->size;
uint8_t* csrcList{ nullptr }; }
HeaderExtension* headerExtension{ nullptr };
std::map<uint8_t, OneByteExtension*> mapOneByteExtensions;
std::map<uint8_t, TwoBytesExtension*> mapTwoBytesExtensions;
uint8_t midExtensionId{ 0u };
uint8_t ridExtensionId{ 0u };
uint8_t rridExtensionId{ 0u };
uint8_t absSendTimeExtensionId{ 0u };
uint8_t transportWideCc01ExtensionId{ 0u };
uint8_t frameMarking07ExtensionId{ 0u }; // NOTE: Remove once RFC.
uint8_t frameMarkingExtensionId{ 0u };
uint8_t ssrcAudioLevelExtensionId{ 0u };
uint8_t videoOrientationExtensionId{ 0u };
uint8_t* payload{ nullptr };
size_t payloadLength{ 0u };
uint8_t payloadPadding{ 0u };
size_t size{ 0u }; // Full size of the packet in bytes.
// Codecs
std::unique_ptr<Codecs::PayloadDescriptorHandler> payloadDescriptorHandler;
};
/* Inline static methods. */ uint8_t GetPayloadType() const
{
return this->header->payloadType;
}
inline bool RtpPacket::IsRtp(const uint8_t* data, size_t len) void SetPayloadType(uint8_t payloadType)
{ {
// NOTE: RtcpPacket::IsRtcp() must always be called before this method. this->header->payloadType = payloadType;
}
auto header = const_cast<Header*>(reinterpret_cast<const Header*>(data)); bool HasMarker() const
{
return this->header->marker;
}
// clang-format off void SetMarker(bool marker)
return ( {
(len >= sizeof(Header)) && this->header->marker = marker;
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes }
(data[0] > 127 && data[0] < 192) &&
// RTP Version must be 2.
(header->version == 2)
);
// clang-format on
}
/* Inline instance methods. */ void SetPayloadPaddingFlag(bool flag)
{
this->header->padding = flag;
}
inline const uint8_t* RtpPacket::GetData() const uint16_t GetSequenceNumber() const
{ {
return (const uint8_t*)this->header; return uint16_t{ ntohs(this->header->sequenceNumber) };
} }
inline size_t RtpPacket::GetSize() const void SetSequenceNumber(uint16_t seq)
{ {
return this->size; this->header->sequenceNumber = uint16_t{ htons(seq) };
} }
inline uint8_t RtpPacket::GetPayloadType() const uint32_t GetTimestamp() const
{ {
return this->header->payloadType; return uint32_t{ ntohl(this->header->timestamp) };
} }
inline void RtpPacket::SetPayloadType(uint8_t payloadType) void SetTimestamp(uint32_t timestamp)
{ {
this->header->payloadType = payloadType; this->header->timestamp = uint32_t{ htonl(timestamp) };
} }
inline bool RtpPacket::HasMarker() const uint32_t GetSsrc() const
{ {
return this->header->marker; return uint32_t{ ntohl(this->header->ssrc) };
} }
inline void RtpPacket::SetMarker(bool marker) void SetSsrc(uint32_t ssrc)
{ {
this->header->marker = marker; this->header->ssrc = uint32_t{ htonl(ssrc) };
} }
inline void RtpPacket::SetPayloadPaddingFlag(bool flag) bool HasHeaderExtension() const
{ {
this->header->padding = flag; return (this->headerExtension ? true : false);
} }
inline uint16_t RtpPacket::GetSequenceNumber() const // After calling this method, all the extension ids are reset to 0.
{ void SetExtensions(uint8_t type, const std::vector<GenericExtension>& extensions);
return uint16_t{ ntohs(this->header->sequenceNumber) };
}
inline void RtpPacket::SetSequenceNumber(uint16_t seq) uint16_t GetHeaderExtensionId() const
{ {
this->header->sequenceNumber = uint16_t{ htons(seq) }; if (!this->headerExtension)
} return 0u;
inline uint32_t RtpPacket::GetTimestamp() const return uint16_t{ ntohs(this->headerExtension->id) };
{ }
return uint32_t{ ntohl(this->header->timestamp) };
}
inline void RtpPacket::SetTimestamp(uint32_t timestamp) size_t GetHeaderExtensionLength() const
{ {
this->header->timestamp = uint32_t{ htonl(timestamp) }; if (!this->headerExtension)
} return 0u;
inline uint32_t RtpPacket::GetSsrc() const return static_cast<size_t>(ntohs(this->headerExtension->length) * 4);
{ }
return uint32_t{ ntohl(this->header->ssrc) };
}
inline void RtpPacket::SetSsrc(uint32_t ssrc) uint8_t* GetHeaderExtensionValue() const
{ {
this->header->ssrc = uint32_t{ htonl(ssrc) }; if (!this->headerExtension)
} return nullptr;
inline bool RtpPacket::HasHeaderExtension() const return this->headerExtension->value;
{ }
return (this->headerExtension ? true : false);
}
inline uint16_t RtpPacket::GetHeaderExtensionId() const bool HasOneByteExtensions() const
{ {
if (!this->headerExtension) return GetHeaderExtensionId() == 0xBEDE;
return 0u; }
return uint16_t{ ntohs(this->headerExtension->id) }; bool HasTwoBytesExtensions() const
} {
return (GetHeaderExtensionId() & 0b1111111111110000) == 0b0001000000000000;
}
inline size_t RtpPacket::GetHeaderExtensionLength() const void SetMidExtensionId(uint8_t id)
{ {
if (!this->headerExtension) this->midExtensionId = id;
return 0u; }
return static_cast<size_t>(ntohs(this->headerExtension->length) * 4); void SetRidExtensionId(uint8_t id)
} {
this->ridExtensionId = id;
}
inline uint8_t* RtpPacket::GetHeaderExtensionValue() const void SetRepairedRidExtensionId(uint8_t id)
{ {
if (!this->headerExtension) this->rridExtensionId = id;
return nullptr; }
return this->headerExtension->value; void SetAbsSendTimeExtensionId(uint8_t id)
} {
this->absSendTimeExtensionId = id;
}
inline bool RtpPacket::HasOneByteExtensions() const void SetTransportWideCc01ExtensionId(uint8_t id)
{ {
return GetHeaderExtensionId() == 0xBEDE; this->transportWideCc01ExtensionId = id;
} }
inline bool RtpPacket::HasTwoBytesExtensions() const // NOTE: Remove once RFC.
{ void SetFrameMarking07ExtensionId(uint8_t id)
return (GetHeaderExtensionId() & 0b1111111111110000) == 0b0001000000000000; {
} this->frameMarking07ExtensionId = id;
}
inline void RtpPacket::SetMidExtensionId(uint8_t id) void SetFrameMarkingExtensionId(uint8_t id)
{ {
this->midExtensionId = id; this->frameMarkingExtensionId = id;
} }
inline void RtpPacket::SetRidExtensionId(uint8_t id) void SetSsrcAudioLevelExtensionId(uint8_t id)
{ {
this->ridExtensionId = id; this->ssrcAudioLevelExtensionId = id;
} }
inline void RtpPacket::SetRepairedRidExtensionId(uint8_t id) void SetVideoOrientationExtensionId(uint8_t id)
{ {
this->rridExtensionId = id; this->videoOrientationExtensionId = id;
} }
inline void RtpPacket::SetAbsSendTimeExtensionId(uint8_t id) bool ReadMid(std::string& mid) const
{ {
this->absSendTimeExtensionId = id; uint8_t extenLen;
} uint8_t* extenValue = GetExtension(this->midExtensionId, extenLen);
inline void RtpPacket::SetTransportWideCc01ExtensionId(uint8_t id) if (!extenValue || extenLen == 0u)
{ return false;
this->transportWideCc01ExtensionId = id;
}
// NOTE: Remove once RFC. mid.assign(reinterpret_cast<const char*>(extenValue), static_cast<size_t>(extenLen));
inline void RtpPacket::SetFrameMarking07ExtensionId(uint8_t id)
{
this->frameMarking07ExtensionId = id;
}
inline void RtpPacket::SetFrameMarkingExtensionId(uint8_t id) return true;
{ }
this->frameMarkingExtensionId = id;
}
inline void RtpPacket::SetSsrcAudioLevelExtensionId(uint8_t id) bool UpdateMid(const std::string& mid);
{
this->ssrcAudioLevelExtensionId = id;
}
inline void RtpPacket::SetVideoOrientationExtensionId(uint8_t id) bool ReadRid(std::string& rid) const
{ {
this->videoOrientationExtensionId = id; // First try with the RID id then with the Repaired RID id.
} uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->ridExtensionId, extenLen);
inline bool RtpPacket::ReadMid(std::string& mid) const if (extenValue && extenLen > 0u)
{ {
uint8_t extenLen; rid.assign(reinterpret_cast<const char*>(extenValue), static_cast<size_t>(extenLen));
uint8_t* extenValue = GetExtension(this->midExtensionId, extenLen);
if (!extenValue || extenLen == 0u) return true;
return false; }
mid.assign(reinterpret_cast<const char*>(extenValue), static_cast<size_t>(extenLen)); extenValue = GetExtension(this->rridExtensionId, extenLen);
return true; if (extenValue && extenLen > 0u)
} {
rid.assign(reinterpret_cast<const char*>(extenValue), static_cast<size_t>(extenLen));
inline bool RtpPacket::ReadRid(std::string& rid) const return true;
{ }
// First try with the RID id then with the Repaired RID id.
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->ridExtensionId, extenLen);
if (extenValue && extenLen > 0u) return false;
}
bool ReadAbsSendTime(uint32_t& absSendtime) const
{ {
rid.assign(reinterpret_cast<const char*>(extenValue), static_cast<size_t>(extenLen)); uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->absSendTimeExtensionId, extenLen);
if (!extenValue || extenLen != 3u)
return false;
absSendtime = Utils::Byte::Get3Bytes(extenValue, 0);
return true; return true;
} }
extenValue = GetExtension(this->rridExtensionId, extenLen); bool UpdateAbsSendTime(uint64_t ms)
if (extenValue && extenLen > 0u)
{ {
rid.assign(reinterpret_cast<const char*>(extenValue), static_cast<size_t>(extenLen)); uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->absSendTimeExtensionId, extenLen);
if (!extenValue || extenLen != 3u)
return false;
auto absSendTime = Utils::Time::TimeMsToAbsSendTime(ms);
Utils::Byte::Set3Bytes(extenValue, 0, absSendTime);
return true; return true;
} }
return false; bool ReadTransportWideCc01(uint16_t& wideSeqNumber) const
} {
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->transportWideCc01ExtensionId, extenLen);
inline bool RtpPacket::ReadAbsSendTime(uint32_t& absSendtime) const if (!extenValue || extenLen != 2u)
{ return false;
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->absSendTimeExtensionId, extenLen);
if (!extenValue || extenLen != 3u) wideSeqNumber = Utils::Byte::Get2Bytes(extenValue, 0);
return false;
absSendtime = Utils::Byte::Get3Bytes(extenValue, 0); return true;
}
return true; bool UpdateTransportWideCc01(uint16_t wideSeqNumber)
} {
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->transportWideCc01ExtensionId, extenLen);
inline bool RtpPacket::UpdateAbsSendTime(uint64_t ms) if (!extenValue || extenLen != 2u)
{ return false;
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->absSendTimeExtensionId, extenLen);
if (!extenValue || extenLen != 3u) Utils::Byte::Set2Bytes(extenValue, 0, wideSeqNumber);
return false;
return true;
}
auto absSendTime = Utils::Time::TimeMsToAbsSendTime(ms); bool ReadFrameMarking(RtpPacket::FrameMarking** frameMarking, uint8_t& length) const
{
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->frameMarkingExtensionId, extenLen);
Utils::Byte::Set3Bytes(extenValue, 0, absSendTime); // NOTE: Remove this once framemarking draft becomes RFC.
if (!extenValue)
extenValue = GetExtension(this->frameMarking07ExtensionId, extenLen);
return true; if (!extenValue || extenLen > 3u)
} return false;
inline bool RtpPacket::ReadTransportWideCc01(uint16_t& wideSeqNumber) const *frameMarking = reinterpret_cast<RtpPacket::FrameMarking*>(extenValue);
{ length = extenLen;
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->transportWideCc01ExtensionId, extenLen);
if (!extenValue || extenLen != 2u) return true;
return false; }
wideSeqNumber = Utils::Byte::Get2Bytes(extenValue, 0); bool ReadSsrcAudioLevel(uint8_t& volume, bool& voice) const
{
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->ssrcAudioLevelExtensionId, extenLen);
return true; if (!extenValue || extenLen != 1u)
} return false;
inline bool RtpPacket::UpdateTransportWideCc01(uint16_t wideSeqNumber) volume = Utils::Byte::Get1Byte(extenValue, 0);
{ voice = (volume & (1 << 7)) ? true : false;
uint8_t extenLen; volume &= ~(1 << 7);
uint8_t* extenValue = GetExtension(this->transportWideCc01ExtensionId, extenLen);
if (!extenValue || extenLen != 2u) return true;
return false; }
Utils::Byte::Set2Bytes(extenValue, 0, wideSeqNumber); bool ReadVideoOrientation(bool& camera, bool& flip, uint16_t& rotation) const
{
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->videoOrientationExtensionId, extenLen);
return true; if (!extenValue || extenLen != 1u)
} return false;
inline bool RtpPacket::ReadFrameMarking(RtpPacket::FrameMarking** frameMarking, uint8_t& length) const uint8_t cvoByte = Utils::Byte::Get1Byte(extenValue, 0);
{ uint8_t cameraValue = ((cvoByte & 0b00001000) >> 3);
uint8_t extenLen; uint8_t flipValue = ((cvoByte & 0b00000100) >> 2);
uint8_t* extenValue = GetExtension(this->frameMarkingExtensionId, extenLen); uint8_t rotationValue = (cvoByte & 0b00000011);
camera = cameraValue ? true : false;
flip = flipValue ? true : false;
// Using counter clockwise values.
switch (rotationValue)
{
case 3:
rotation = 270;
break;
case 2:
rotation = 180;
break;
case 1:
rotation = 90;
break;
default:
rotation = 0;
}
// NOTE: Remove this once framemarking draft becomes RFC. return true;
if (!extenValue) }
extenValue = GetExtension(this->frameMarking07ExtensionId, extenLen);
if (!extenValue || extenLen > 3u) bool HasExtension(uint8_t id) const
return false; {
if (id == 0u)
{
return false;
}
else if (HasOneByteExtensions())
{
auto it = this->mapOneByteExtensions.find(id);
return it != this->mapOneByteExtensions.end();
}
else if (HasTwoBytesExtensions())
{
auto it = this->mapTwoBytesExtensions.find(id);
if (it == this->mapTwoBytesExtensions.end())
return false;
auto* extension = it->second;
// In Two-Byte extensions value length may be zero. If so, return false.
if (extension->len == 0u)
return false;
return true;
}
else
{
return false;
}
}
*frameMarking = reinterpret_cast<RtpPacket::FrameMarking*>(extenValue); uint8_t* GetExtension(uint8_t id, uint8_t& len) const
length = extenLen; {
len = 0u;
return true; if (id == 0u)
} {
return nullptr;
}
else if (HasOneByteExtensions())
{
auto it = this->mapOneByteExtensions.find(id);
inline bool RtpPacket::ReadSsrcAudioLevel(uint8_t& volume, bool& voice) const if (it == this->mapOneByteExtensions.end())
{ return nullptr;
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->ssrcAudioLevelExtensionId, extenLen);
if (!extenValue || extenLen != 1u) auto* extension = it->second;
return false;
volume = Utils::Byte::Get1Byte(extenValue, 0); // In One-Byte extensions value length 0 means 1.
voice = (volume & (1 << 7)) ? true : false; len = extension->len + 1;
volume &= ~(1 << 7);
return true; return extension->value;
} }
else if (HasTwoBytesExtensions())
{
auto it = this->mapTwoBytesExtensions.find(id);
inline bool RtpPacket::ReadVideoOrientation(bool& camera, bool& flip, uint16_t& rotation) const if (it == this->mapTwoBytesExtensions.end())
{ return nullptr;
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->videoOrientationExtensionId, extenLen);
if (!extenValue || extenLen != 1u) auto* extension = it->second;
return false;
uint8_t cvoByte = Utils::Byte::Get1Byte(extenValue, 0); len = extension->len;
uint8_t cameraValue = ((cvoByte & 0b00001000) >> 3);
uint8_t flipValue = ((cvoByte & 0b00000100) >> 2);
uint8_t rotationValue = (cvoByte & 0b00000011);
camera = cameraValue ? true : false; // In Two-Byte extensions value length may be zero. If so, return nullptr.
flip = flipValue ? true : false; if (extension->len == 0u)
return nullptr;
// Using counter clockwise values. return extension->value;
switch (rotationValue) }
{ else
case 3: {
rotation = 270; return nullptr;
break; }
case 2:
rotation = 180;
break;
case 1:
rotation = 90;
break;
default:
rotation = 0;
} }
return true; bool SetExtensionLength(uint8_t id, uint8_t len);
}
inline bool RtpPacket::HasExtension(uint8_t id) const uint8_t* GetPayload() const
{
if (id == 0u)
{ {
return false; return this->payloadLength != 0u ? this->payload : nullptr;
} }
else if (HasOneByteExtensions())
{
auto it = this->mapOneByteExtensions.find(id);
return it != this->mapOneByteExtensions.end(); size_t GetPayloadLength() const
}
else if (HasTwoBytesExtensions())
{ {
auto it = this->mapTwoBytesExtensions.find(id); return this->payloadLength;
if (it == this->mapTwoBytesExtensions.end())
return false;
auto* extension = it->second;
// In Two-Byte extensions value length may be zero. If so, return false.
if (extension->len == 0u)
return false;
return true;
} }
else
{
return false;
}
}
inline uint8_t* RtpPacket::GetExtension(uint8_t id, uint8_t& len) const void SetPayloadLength(size_t length);
{
len = 0u;
if (id == 0u) uint8_t GetPayloadPadding() const
{ {
return nullptr; return this->payloadPadding;
} }
else if (HasOneByteExtensions())
{
auto it = this->mapOneByteExtensions.find(id);
if (it == this->mapOneByteExtensions.end()) uint8_t GetSpatialLayer() const
return nullptr; {
if (!this->payloadDescriptorHandler)
return 0u;
auto* extension = it->second; return this->payloadDescriptorHandler->GetSpatialLayer();
}
// In One-Byte extensions value length 0 means 1. uint8_t GetTemporalLayer() const
len = extension->len + 1; {
if (!this->payloadDescriptorHandler)
return 0u;
return extension->value; return this->payloadDescriptorHandler->GetTemporalLayer();
} }
else if (HasTwoBytesExtensions())
bool IsKeyFrame() const
{ {
auto it = this->mapTwoBytesExtensions.find(id); if (!this->payloadDescriptorHandler)
return false;
if (it == this->mapTwoBytesExtensions.end()) return this->payloadDescriptorHandler->IsKeyFrame();
return nullptr; }
auto* extension = it->second; RtpPacket* Clone(const uint8_t* buffer) const;
len = extension->len; void RtxEncode(uint8_t payloadType, uint32_t ssrc, uint16_t seq);
// In Two-Byte extensions value length may be zero. If so, return nullptr. bool RtxDecode(uint8_t payloadType, uint32_t ssrc);
if (extension->len == 0u)
return nullptr;
return extension->value; void SetPayloadDescriptorHandler(RTC::Codecs::PayloadDescriptorHandler* payloadDescriptorHandler)
}
else
{ {
return nullptr; this->payloadDescriptorHandler.reset(payloadDescriptorHandler);
} }
}
inline uint8_t* RtpPacket::GetPayload() const
{
return this->payloadLength != 0u ? this->payload : nullptr;
}
inline size_t RtpPacket::GetPayloadLength() const
{
return this->payloadLength;
}
inline uint8_t RtpPacket::GetPayloadPadding() const
{
return this->payloadPadding;
}
inline uint8_t RtpPacket::GetSpatialLayer() const
{
if (!this->payloadDescriptorHandler)
return 0u;
return this->payloadDescriptorHandler->GetSpatialLayer();
}
inline uint8_t RtpPacket::GetTemporalLayer() const bool ProcessPayload(RTC::Codecs::EncodingContext* context);
{
if (!this->payloadDescriptorHandler)
return 0u;
return this->payloadDescriptorHandler->GetTemporalLayer(); void RestorePayload();
}
inline bool RtpPacket::IsKeyFrame() const void ShiftPayload(size_t payloadOffset, size_t shift, bool expand = true);
{
if (!this->payloadDescriptorHandler)
return false;
return this->payloadDescriptorHandler->IsKeyFrame(); private:
} void ParseExtensions();
inline void RtpPacket::SetPayloadDescriptorHandler( private:
RTC::Codecs::PayloadDescriptorHandler* payloadDescriptorHandler) // Passed by argument.
{ Header* header{ nullptr };
this->payloadDescriptorHandler.reset(payloadDescriptorHandler); uint8_t* csrcList{ nullptr };
} HeaderExtension* headerExtension{ nullptr };
std::map<uint8_t, OneByteExtension*> mapOneByteExtensions;
std::map<uint8_t, TwoBytesExtension*> mapTwoBytesExtensions;
uint8_t midExtensionId{ 0u };
uint8_t ridExtensionId{ 0u };
uint8_t rridExtensionId{ 0u };
uint8_t absSendTimeExtensionId{ 0u };
uint8_t transportWideCc01ExtensionId{ 0u };
uint8_t frameMarking07ExtensionId{ 0u }; // NOTE: Remove once RFC.
uint8_t frameMarkingExtensionId{ 0u };
uint8_t ssrcAudioLevelExtensionId{ 0u };
uint8_t videoOrientationExtensionId{ 0u };
uint8_t* payload{ nullptr };
size_t payloadLength{ 0u };
uint8_t payloadPadding{ 0u };
size_t size{ 0u }; // Full size of the packet in bytes.
// Codecs
std::unique_ptr<Codecs::PayloadDescriptorHandler> payloadDescriptorHandler;
};
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -57,18 +57,51 @@ namespace RTC ...@@ -57,18 +57,51 @@ namespace RTC
void FillJson(json& jsonObject) const; void FillJson(json& jsonObject) const;
virtual void FillJsonStats(json& jsonObject); virtual void FillJsonStats(json& jsonObject);
uint32_t GetSsrc() const; uint32_t GetSsrc() const
uint8_t GetPayloadType() const; {
const RTC::RtpCodecMimeType& GetMimeType() const; return this->params.ssrc;
uint32_t GetClockRate() const; }
const std::string& GetRid() const; uint8_t GetPayloadType() const
const std::string& GetCname() const; {
bool HasRtx() const; return this->params.payloadType;
}
const RTC::RtpCodecMimeType& GetMimeType() const
{
return this->params.mimeType;
}
uint32_t GetClockRate() const
{
return this->params.clockRate;
}
const std::string& GetRid() const
{
return this->params.rid;
}
const std::string& GetCname() const
{
return this->params.cname;
}
bool HasRtx() const
{
return this->rtxStream != nullptr;
}
virtual void SetRtx(uint8_t payloadType, uint32_t ssrc); virtual void SetRtx(uint8_t payloadType, uint32_t ssrc);
uint32_t GetRtxSsrc() const; uint32_t GetRtxSsrc() const
uint8_t GetRtxPayloadType() const; {
uint8_t GetSpatialLayers() const; return this->params.rtxSsrc;
uint8_t GetTemporalLayers() const; }
uint8_t GetRtxPayloadType() const
{
return this->params.rtxPayloadType;
}
uint8_t GetSpatialLayers() const
{
return this->params.spatialLayers;
}
uint8_t GetTemporalLayers() const
{
return this->params.temporalLayers;
}
virtual bool ReceivePacket(RTC::RtpPacket* packet); virtual bool ReceivePacket(RTC::RtpPacket* packet);
virtual void Pause() = 0; virtual void Pause() = 0;
virtual void Resume() = 0; virtual void Resume() = 0;
...@@ -77,22 +110,52 @@ namespace RTC ...@@ -77,22 +110,52 @@ namespace RTC
virtual uint32_t GetSpatialLayerBitrate(uint64_t nowMs, uint8_t spatialLayer) = 0; virtual uint32_t GetSpatialLayerBitrate(uint64_t nowMs, uint8_t spatialLayer) = 0;
virtual uint32_t GetLayerBitrate(uint64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer) = 0; virtual uint32_t GetLayerBitrate(uint64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer) = 0;
void ResetScore(uint8_t score, bool notify); void ResetScore(uint8_t score, bool notify);
uint8_t GetFractionLost() const; uint8_t GetFractionLost() const
float GetLossPercentage() const; {
float GetRtt() const; return this->fractionLost;
uint64_t GetMaxPacketMs() const; }
uint32_t GetMaxPacketTs() const; float GetLossPercentage() const
uint64_t GetSenderReportNtpMs() const; {
uint32_t GetSenderReportTs() const; return static_cast<float>(this->fractionLost) * 100 / 256;
uint8_t GetScore() const; }
uint64_t GetActiveMs() const; float GetRtt() const
{
return this->rtt;
}
uint64_t GetMaxPacketMs() const
{
return this->maxPacketMs;
}
uint32_t GetMaxPacketTs() const
{
return this->maxPacketTs;
}
uint64_t GetSenderReportNtpMs() const
{
return this->lastSenderReportNtpMs;
}
uint32_t GetSenderReportTs() const
{
return this->lastSenderReporTs;
}
uint8_t GetScore() const
{
return this->score;
}
uint64_t GetActiveMs() const
{
return DepLibUV::GetTimeMs() - this->activeSinceMs;
}
protected: protected:
bool UpdateSeq(RTC::RtpPacket* packet); bool UpdateSeq(RTC::RtpPacket* packet);
void UpdateScore(uint8_t score); void UpdateScore(uint8_t score);
void PacketRetransmitted(RTC::RtpPacket* packet); void PacketRetransmitted(RTC::RtpPacket* packet);
void PacketRepaired(RTC::RtpPacket* packet); void PacketRepaired(RTC::RtpPacket* packet);
uint32_t GetExpectedPackets() const; uint32_t GetExpectedPackets() const
{
return (this->cycles + this->maxSeq) - this->baseSeq + 1;
}
private: private:
void InitSeq(uint16_t seq); void InitSeq(uint16_t seq);
...@@ -103,25 +166,27 @@ namespace RTC ...@@ -103,25 +166,27 @@ namespace RTC
Params params; Params params;
// Others. // Others.
// https://tools.ietf.org/html/rfc3550#appendix-A.1 stuff. // https://tools.ietf.org/html/rfc3550#appendix-A.1 stuff.
uint16_t maxSeq{ 0 }; // Highest seq. number seen. uint16_t maxSeq{ 0u }; // Highest seq. number seen.
uint32_t cycles{ 0 }; // Shifted count of seq. number cycles. uint32_t cycles{ 0u }; // Shifted count of seq. number cycles.
uint32_t baseSeq{ 0 }; // Base seq number. uint32_t baseSeq{ 0u }; // Base seq number.
uint32_t badSeq{ 0 }; // Last 'bad' seq number + 1. uint32_t badSeq{ 0u }; // Last 'bad' seq number + 1.
uint32_t maxPacketTs{ 0 }; // Highest timestamp seen. uint32_t maxPacketTs{ 0u }; // Highest timestamp seen.
uint64_t maxPacketMs{ 0 }; // When the packet with highest timestammp was seen. uint64_t maxPacketMs{ 0u }; // When the packet with highest timestammp was seen.
uint32_t packetsLost{ 0 }; uint32_t packetsLost{ 0u };
uint8_t fractionLost{ 0 }; uint8_t fractionLost{ 0u };
size_t packetsDiscarded{ 0 }; size_t packetsDiscarded{ 0u };
size_t packetsRetransmitted{ 0 }; size_t packetsRetransmitted{ 0u };
size_t packetsRepaired{ 0 }; size_t packetsRepaired{ 0u };
size_t nackCount{ 0 }; size_t nackCount{ 0u };
size_t nackPacketCount{ 0 }; size_t nackPacketCount{ 0u };
size_t pliCount{ 0 }; size_t pliCount{ 0u };
size_t firCount{ 0 }; size_t firCount{ 0u };
size_t repairedPriorScore{ 0 }; // Packets repaired at last interval for score calculation. size_t repairedPriorScore{ 0u }; // Packets repaired at last interval for score calculation.
size_t retransmittedPriorScore{ 0 }; // Packets retransmitted at last interval for score calculation. size_t retransmittedPriorScore{
uint64_t lastSenderReportNtpMs{ 0 }; // NTP timestamp in last Sender Report (in ms). 0u
uint32_t lastSenderReporTs{ 0 }; // RTP timestamp in last Sender Report. }; // Packets retransmitted at last interval for score calculation.
uint64_t lastSenderReportNtpMs{ 0u }; // NTP timestamp in last Sender Report (in ms).
uint32_t lastSenderReporTs{ 0u }; // RTP timestamp in last Sender Report.
float rtt{ 0 }; float rtt{ 0 };
bool hasRtt{ false }; bool hasRtt{ false };
// Instance of RtxStream. // Instance of RtxStream.
...@@ -136,113 +201,6 @@ namespace RTC ...@@ -136,113 +201,6 @@ namespace RTC
// Last time since the stream is active. // Last time since the stream is active.
uint64_t activeSinceMs{ 0u }; uint64_t activeSinceMs{ 0u };
}; };
/* Inline instance methods. */
inline uint32_t RtpStream::GetSsrc() const
{
return this->params.ssrc;
}
inline uint8_t RtpStream::GetPayloadType() const
{
return this->params.payloadType;
}
inline const RTC::RtpCodecMimeType& RtpStream::GetMimeType() const
{
return this->params.mimeType;
}
inline uint32_t RtpStream::GetClockRate() const
{
return this->params.clockRate;
}
inline const std::string& RtpStream::GetRid() const
{
return this->params.rid;
}
inline const std::string& RtpStream::GetCname() const
{
return this->params.cname;
}
inline bool RtpStream::HasRtx() const
{
return this->rtxStream != nullptr;
}
inline uint32_t RtpStream::GetRtxSsrc() const
{
return this->params.rtxSsrc;
}
inline uint8_t RtpStream::GetRtxPayloadType() const
{
return this->params.rtxPayloadType;
}
inline uint8_t RtpStream::GetSpatialLayers() const
{
return this->params.spatialLayers;
}
inline uint8_t RtpStream::GetTemporalLayers() const
{
return this->params.temporalLayers;
}
inline uint8_t RtpStream::GetFractionLost() const
{
return this->fractionLost;
}
inline float RtpStream::GetLossPercentage() const
{
return static_cast<float>(this->fractionLost) * 100 / 256;
}
inline float RtpStream::GetRtt() const
{
return this->rtt;
}
inline uint64_t RtpStream::GetMaxPacketMs() const
{
return this->maxPacketMs;
}
inline uint32_t RtpStream::GetMaxPacketTs() const
{
return this->maxPacketTs;
}
inline uint64_t RtpStream::GetSenderReportNtpMs() const
{
return this->lastSenderReportNtpMs;
}
inline uint32_t RtpStream::GetSenderReportTs() const
{
return this->lastSenderReporTs;
}
inline uint8_t RtpStream::GetScore() const
{
return this->score;
}
inline uint64_t RtpStream::GetActiveMs() const
{
return DepLibUV::GetTimeMs() - this->activeSinceMs;
}
inline uint32_t RtpStream::GetExpectedPackets() const
{
return (this->cycles + this->maxSeq) - this->baseSeq + 1;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -56,10 +56,22 @@ namespace RTC ...@@ -56,10 +56,22 @@ namespace RTC
void RequestKeyFrame(); void RequestKeyFrame();
void Pause() override; void Pause() override;
void Resume() override; void Resume() override;
uint32_t GetBitrate(uint64_t nowMs) override; uint32_t GetBitrate(uint64_t nowMs) override
uint32_t GetBitrate(uint64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer) override; {
uint32_t GetSpatialLayerBitrate(uint64_t nowMs, uint8_t spatialLayer) override; return this->transmissionCounter.GetBitrate(nowMs);
uint32_t GetLayerBitrate(uint64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer) override; }
uint32_t GetBitrate(uint64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer) override
{
return this->transmissionCounter.GetBitrate(nowMs, spatialLayer, temporalLayer);
}
uint32_t GetSpatialLayerBitrate(uint64_t nowMs, uint8_t spatialLayer) override
{
return this->transmissionCounter.GetSpatialLayerBitrate(nowMs, spatialLayer);
}
uint32_t GetLayerBitrate(uint64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer) override
{
return this->transmissionCounter.GetLayerBitrate(nowMs, spatialLayer, temporalLayer);
}
private: private:
void CalculateJitter(uint32_t rtpTimestamp); void CalculateJitter(uint32_t rtpTimestamp);
...@@ -75,48 +87,25 @@ namespace RTC ...@@ -75,48 +87,25 @@ namespace RTC
void OnNackGeneratorKeyFrameRequired() override; void OnNackGeneratorKeyFrameRequired() override;
private: private:
uint32_t expectedPrior{ 0 }; // Packets expected at last interval. uint32_t expectedPrior{ 0u }; // Packets expected at last interval.
uint32_t expectedPriorScore{ 0 }; // Packets expected at last interval for score calculation. uint32_t expectedPriorScore{ 0u }; // Packets expected at last interval for score calculation.
uint32_t receivedPrior{ 0 }; // Packets received at last interval. uint32_t receivedPrior{ 0u }; // Packets received at last interval.
uint32_t receivedPriorScore{ 0 }; // Packets received at last interval for score calculation. uint32_t receivedPriorScore{ 0u }; // Packets received at last interval for score calculation.
uint32_t lastSrTimestamp{ 0 }; // The middle 32 bits out of 64 in the NTP uint32_t lastSrTimestamp{ 0u }; // The middle 32 bits out of 64 in the NTP
// timestamp received in the most recent // timestamp received in the most recent
// sender report. // sender report.
uint64_t lastSrReceived{ 0 }; // Wallclock time representing the most recent uint64_t lastSrReceived{ 0u }; // Wallclock time representing the most recent
// sender report arrival. // sender report arrival.
uint32_t transit{ 0 }; // Relative transit time for prev packet. uint32_t transit{ 0u }; // Relative transit time for prev packet.
uint32_t jitter{ 0 }; uint32_t jitter{ 0u };
uint8_t firSeqNumber{ 0 }; uint8_t firSeqNumber{ 0u };
uint32_t reportedPacketLost{ 0 }; uint32_t reportedPacketLost{ 0u };
std::unique_ptr<RTC::NackGenerator> nackGenerator; std::unique_ptr<RTC::NackGenerator> nackGenerator;
Timer* inactivityCheckPeriodicTimer{ nullptr }; Timer* inactivityCheckPeriodicTimer{ nullptr };
bool inactive{ false }; bool inactive{ false };
TransmissionCounter transmissionCounter; // Valid media + valid RTX. TransmissionCounter transmissionCounter; // Valid media + valid RTX.
RTC::RtpDataCounter mediaTransmissionCounter; // Just valid media. RTC::RtpDataCounter mediaTransmissionCounter; // Just valid media.
}; };
/* Inline instance methods */
inline uint32_t RtpStreamRecv::GetBitrate(uint64_t nowMs)
{
return this->transmissionCounter.GetBitrate(nowMs);
}
inline uint32_t RtpStreamRecv::GetBitrate(uint64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer)
{
return this->transmissionCounter.GetBitrate(nowMs, spatialLayer, temporalLayer);
}
inline uint32_t RtpStreamRecv::GetSpatialLayerBitrate(uint64_t nowMs, uint8_t spatialLayer)
{
return this->transmissionCounter.GetSpatialLayerBitrate(nowMs, spatialLayer);
}
inline uint32_t RtpStreamRecv::GetLayerBitrate(
uint64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer)
{
return this->transmissionCounter.GetLayerBitrate(nowMs, spatialLayer, temporalLayer);
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -47,7 +47,10 @@ namespace RTC ...@@ -47,7 +47,10 @@ namespace RTC
RTC::RTCP::SdesChunk* GetRtcpSdesChunk(); RTC::RTCP::SdesChunk* GetRtcpSdesChunk();
void Pause() override; void Pause() override;
void Resume() override; void Resume() override;
uint32_t GetBitrate(uint64_t nowMs) override; uint32_t GetBitrate(uint64_t nowMs) override
{
return this->transmissionCounter.GetBitrate(nowMs);
}
uint32_t GetBitrate(uint64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer) override; uint32_t GetBitrate(uint64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer) override;
uint32_t GetSpatialLayerBitrate(uint64_t nowMs, uint8_t spatialLayer) override; uint32_t GetSpatialLayerBitrate(uint64_t nowMs, uint8_t spatialLayer) override;
uint32_t GetLayerBitrate(uint64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer) override; uint32_t GetLayerBitrate(uint64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer) override;
...@@ -61,22 +64,15 @@ namespace RTC ...@@ -61,22 +64,15 @@ namespace RTC
void UpdateScore(RTC::RTCP::ReceiverReport* report); void UpdateScore(RTC::RTCP::ReceiverReport* report);
private: private:
uint32_t lostPriorScore{ 0 }; // Packets lost at last interval for score calculation. uint32_t lostPriorScore{ 0u }; // Packets lost at last interval for score calculation.
uint32_t sentPriorScore{ 0 }; // Packets sent at last interval for score calculation. uint32_t sentPriorScore{ 0u }; // Packets sent at last interval for score calculation.
std::vector<StorageItem*> buffer; std::vector<StorageItem*> buffer;
uint16_t bufferStartIdx{ 0 }; uint16_t bufferStartIdx{ 0u };
size_t bufferSize{ 0 }; size_t bufferSize{ 0u };
std::vector<StorageItem> storage; std::vector<StorageItem> storage;
uint16_t rtxSeq{ 0 }; uint16_t rtxSeq{ 0u };
RTC::RtpDataCounter transmissionCounter; RTC::RtpDataCounter transmissionCounter;
}; };
/* Inline instance methods */
inline uint32_t RtpStreamSend::GetBitrate(uint64_t nowMs)
{
return this->transmissionCounter.GetBitrate(nowMs);
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -36,21 +36,48 @@ namespace RTC ...@@ -36,21 +36,48 @@ namespace RTC
virtual ~RtxStream(); virtual ~RtxStream();
void FillJson(json& jsonObject) const; void FillJson(json& jsonObject) const;
uint32_t GetSsrc() const; uint32_t GetSsrc() const
uint8_t GetPayloadType() const; {
const RTC::RtpCodecMimeType& GetMimeType() const; return this->params.ssrc;
uint32_t GetClockRate() const; }
const std::string& GetRrid() const; uint8_t GetPayloadType() const
const std::string& GetCname() const; {
uint8_t GetFractionLost() const; return this->params.payloadType;
float GetLossPercentage() const; }
const RTC::RtpCodecMimeType& GetMimeType() const
{
return this->params.mimeType;
}
uint32_t GetClockRate() const
{
return this->params.clockRate;
}
const std::string& GetRrid() const
{
return this->params.rrid;
}
const std::string& GetCname() const
{
return this->params.cname;
}
uint8_t GetFractionLost() const
{
return this->fractionLost;
}
float GetLossPercentage() const
{
return static_cast<float>(this->fractionLost) * 100 / 256;
}
bool ReceivePacket(RTC::RtpPacket* packet); bool ReceivePacket(RTC::RtpPacket* packet);
RTC::RTCP::ReceiverReport* GetRtcpReceiverReport(); RTC::RTCP::ReceiverReport* GetRtcpReceiverReport();
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report); void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
protected: protected:
bool UpdateSeq(RTC::RtpPacket* packet); bool UpdateSeq(RTC::RtpPacket* packet);
uint32_t GetExpectedPackets() const; uint32_t GetExpectedPackets() const
{
return (this->cycles + this->maxSeq) - this->baseSeq + 1;
}
private: private:
void InitSeq(uint16_t seq); void InitSeq(uint16_t seq);
...@@ -60,74 +87,27 @@ namespace RTC ...@@ -60,74 +87,27 @@ namespace RTC
Params params; Params params;
// Others. // Others.
// https://tools.ietf.org/html/rfc3550#appendix-A.1 stuff. // https://tools.ietf.org/html/rfc3550#appendix-A.1 stuff.
uint16_t maxSeq{ 0 }; // Highest seq. number seen. uint16_t maxSeq{ 0u }; // Highest seq. number seen.
uint32_t cycles{ 0 }; // Shifted count of seq. number cycles. uint32_t cycles{ 0u }; // Shifted count of seq. number cycles.
uint32_t baseSeq{ 0 }; // Base seq number. uint32_t baseSeq{ 0u }; // Base seq number.
uint32_t badSeq{ 0 }; // Last 'bad' seq number + 1. uint32_t badSeq{ 0u }; // Last 'bad' seq number + 1.
uint32_t maxPacketTs{ 0 }; // Highest timestamp seen. uint32_t maxPacketTs{ 0u }; // Highest timestamp seen.
uint64_t maxPacketMs{ 0 }; // When the packet with highest timestammp was seen. uint64_t maxPacketMs{ 0u }; // When the packet with highest timestammp was seen.
uint32_t packetsLost{ 0 }; uint32_t packetsLost{ 0u };
uint8_t fractionLost{ 0 }; uint8_t fractionLost{ 0u };
size_t packetsDiscarded{ 0 }; size_t packetsDiscarded{ 0u };
size_t packetsCount{ 0 }; size_t packetsCount{ 0u };
private: private:
// Whether at least a RTP packet has been received. // Whether at least a RTP packet has been received.
bool started{ false }; bool started{ false };
// Fields for generating Receiver Reports. // Fields for generating Receiver Reports.
uint32_t expectedPrior{ 0 }; uint32_t expectedPrior{ 0u };
uint32_t receivedPrior{ 0 }; uint32_t receivedPrior{ 0u };
uint32_t lastSrTimestamp{ 0 }; uint32_t lastSrTimestamp{ 0u };
uint64_t lastSrReceived{ 0 }; uint64_t lastSrReceived{ 0u };
uint32_t reportedPacketLost{ 0 }; uint32_t reportedPacketLost{ 0u };
}; };
/* Inline instance methods. */
inline uint32_t RtxStream::GetSsrc() const
{
return this->params.ssrc;
}
inline uint8_t RtxStream::GetPayloadType() const
{
return this->params.payloadType;
}
inline const RTC::RtpCodecMimeType& RtxStream::GetMimeType() const
{
return this->params.mimeType;
}
inline uint32_t RtxStream::GetClockRate() const
{
return this->params.clockRate;
}
inline const std::string& RtxStream::GetRrid() const
{
return this->params.rrid;
}
inline const std::string& RtxStream::GetCname() const
{
return this->params.cname;
}
inline uint8_t RtxStream::GetFractionLost() const
{
return this->fractionLost;
}
inline float RtxStream::GetLossPercentage() const
{
return static_cast<float>(this->fractionLost) * 100 / 256;
}
inline uint32_t RtxStream::GetExpectedPackets() const
{
return (this->cycles + this->maxSeq) - this->baseSeq + 1;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -50,7 +50,17 @@ namespace RTC ...@@ -50,7 +50,17 @@ namespace RTC
}; };
public: public:
static bool IsSctp(const uint8_t* data, size_t len); static bool IsSctp(const uint8_t* data, size_t len)
{
// clang-format off
return (
(len >= 12) &&
// Must have Source Port Number and Destination Port Number set to 5000 (hack).
(Utils::Byte::Get2Bytes(data, 0) == 5000) &&
(Utils::Byte::Get2Bytes(data, 2) == 5000)
);
// clang-format on
}
public: public:
SctpAssociation( SctpAssociation(
...@@ -60,8 +70,14 @@ namespace RTC ...@@ -60,8 +70,14 @@ namespace RTC
public: public:
void FillJson(json& jsonObject) const; void FillJson(json& jsonObject) const;
void TransportConnected(); void TransportConnected();
size_t GetMaxSctpMessageSize() const; size_t GetMaxSctpMessageSize() const
SctpState GetState() const; {
return this->maxSctpMessageSize;
}
SctpState GetState() const
{
return this->state;
}
void ProcessSctpData(const uint8_t* data, size_t len); void ProcessSctpData(const uint8_t* data, size_t len);
void SendSctpMessage(RTC::DataConsumer* dataConsumer, uint32_t ppid, const uint8_t* msg, size_t len); void SendSctpMessage(RTC::DataConsumer* dataConsumer, uint32_t ppid, const uint8_t* msg, size_t len);
void HandleDataConsumer(RTC::DataConsumer* dataConsumer); void HandleDataConsumer(RTC::DataConsumer* dataConsumer);
...@@ -82,45 +98,19 @@ namespace RTC ...@@ -82,45 +98,19 @@ namespace RTC
private: private:
// Passed by argument. // Passed by argument.
Listener* listener{ nullptr }; Listener* listener{ nullptr };
uint16_t os{ 1024 }; uint16_t os{ 1024u };
uint16_t mis{ 1024 }; uint16_t mis{ 1024u };
size_t maxSctpMessageSize{ 262144 }; size_t maxSctpMessageSize{ 262144u };
bool isDataChannel{ false }; bool isDataChannel{ false };
// Allocated by this. // Allocated by this.
uint8_t* messageBuffer{ nullptr }; uint8_t* messageBuffer{ nullptr };
// Others. // Others.
SctpState state{ SctpState::NEW }; SctpState state{ SctpState::NEW };
struct socket* socket{ nullptr }; struct socket* socket{ nullptr };
uint16_t desiredOs{ 0 }; uint16_t desiredOs{ 0u };
size_t messageBufferLen{ 0 }; size_t messageBufferLen{ 0u };
uint16_t lastSsnReceived{ 0 }; // Valid for us since no SCTP I-DATA support. uint16_t lastSsnReceived{ 0u }; // Valid for us since no SCTP I-DATA support.
}; };
/* Inline static methods. */
inline bool SctpAssociation::IsSctp(const uint8_t* data, size_t len)
{
// clang-format off
return (
(len >= 12) &&
// Must have Source Port Number and Destination Port Number set to 5000 (hack).
(Utils::Byte::Get2Bytes(data, 0) == 5000) &&
(Utils::Byte::Get2Bytes(data, 2) == 5000)
);
// clang-format on
}
/* Inline instance methods. */
inline size_t SctpAssociation::GetMaxSctpMessageSize() const
{
return this->maxSctpMessageSize;
}
inline SctpAssociation::SctpState SctpAssociation::GetState() const
{
return this->state;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -39,11 +39,32 @@ namespace RTC ...@@ -39,11 +39,32 @@ namespace RTC
CummulativeResult() = default; CummulativeResult() = default;
public: public:
uint64_t GetStartedAtMs() const; uint64_t GetStartedAtMs() const
size_t GetNumPackets() const; {
size_t GetTotalSize() const; return this->firstPacketSentAtMs;
uint32_t GetSendBitrate() const; }
uint32_t GetReceiveBitrate() const; size_t GetNumPackets() const
{
return this->numPackets;
}
size_t GetTotalSize() const
{
return this->totalSize;
}
uint32_t GetSendBitrate() const
{
auto sendIntervalMs =
std::max<uint64_t>(this->lastPacketSentAtMs - this->firstPacketSentAtMs, 1u);
return static_cast<uint32_t>(this->totalSize / sendIntervalMs) * 8 * 1000;
}
uint32_t GetReceiveBitrate() const
{
auto recvIntervalMs =
std::max<uint64_t>(this->lastPacketReceivedAtMs - this->firstPacketReceivedAtMs, 1u);
return static_cast<uint32_t>(this->totalSize / recvIntervalMs) * 8 * 1000;
}
void AddPacket(size_t size, int64_t sentAtMs, int64_t receivedAtMs); void AddPacket(size_t size, int64_t sentAtMs, int64_t receivedAtMs);
void Reset(); void Reset();
...@@ -85,39 +106,6 @@ namespace RTC ...@@ -85,39 +106,6 @@ namespace RTC
RTC::RateCalculator sendTransmission; RTC::RateCalculator sendTransmission;
RTC::TrendCalculator sendTransmissionTrend; RTC::TrendCalculator sendTransmissionTrend;
}; };
/* Inline methods. */
inline uint64_t SenderBandwidthEstimator::CummulativeResult::GetStartedAtMs() const
{
return this->firstPacketSentAtMs;
}
inline size_t SenderBandwidthEstimator::CummulativeResult::GetNumPackets() const
{
return this->numPackets;
}
inline size_t SenderBandwidthEstimator::CummulativeResult::GetTotalSize() const
{
return this->totalSize;
}
inline uint32_t SenderBandwidthEstimator::CummulativeResult::GetSendBitrate() const
{
auto sendIntervalMs =
std::max<uint64_t>(this->lastPacketSentAtMs - this->firstPacketSentAtMs, 1u);
return static_cast<uint32_t>(this->totalSize / sendIntervalMs) * 8 * 1000;
}
inline uint32_t SenderBandwidthEstimator::CummulativeResult::GetReceiveBitrate() const
{
auto recvIntervalMs =
std::max<uint64_t>(this->lastPacketReceivedAtMs - this->firstPacketReceivedAtMs, 1u);
return static_cast<uint32_t>(this->totalSize / recvIntervalMs) * 8 * 1000;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -18,7 +18,16 @@ namespace RTC ...@@ -18,7 +18,16 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override; void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override; void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override; void HandleRequest(Channel::Request* request) override;
bool IsActive() const override; bool IsActive() const override
{
// clang-format off
return (
RTC::Consumer::IsActive() &&
this->producerRtpStream &&
this->producerRtpStream->GetScore() > 0u
);
// clang-format on
}
void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override; void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override; void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override; void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override;
...@@ -28,7 +37,10 @@ namespace RTC ...@@ -28,7 +37,10 @@ namespace RTC
void ApplyLayers() override; void ApplyLayers() override;
uint32_t GetDesiredBitrate() const override; uint32_t GetDesiredBitrate() const override;
void SendRtpPacket(RTC::RtpPacket* packet) override; void SendRtpPacket(RTC::RtpPacket* packet) override;
std::vector<RTC::RtpStreamSend*> GetRtpStreams() override; std::vector<RTC::RtpStreamSend*> GetRtpStreams() override
{
return this->rtpStreams;
}
void GetRtcp(RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t nowMs) override; void GetRtcp(RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t nowMs) override;
void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override; void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override;
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override; void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override;
...@@ -62,24 +74,6 @@ namespace RTC ...@@ -62,24 +74,6 @@ namespace RTC
RTC::SeqManager<uint16_t> rtpSeqManager; RTC::SeqManager<uint16_t> rtpSeqManager;
bool managingBitrate{ false }; bool managingBitrate{ false };
}; };
/* Inline methods. */
inline bool SimpleConsumer::IsActive() const
{
// clang-format off
return (
RTC::Consumer::IsActive() &&
this->producerRtpStream &&
this->producerRtpStream->GetScore() > 0u
);
// clang-format on
}
inline std::vector<RTC::RtpStreamSend*> SimpleConsumer::GetRtpStreams()
{
return this->rtpStreams;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -19,8 +19,31 @@ namespace RTC ...@@ -19,8 +19,31 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override; void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override; void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override; void HandleRequest(Channel::Request* request) override;
RTC::Consumer::Layers GetPreferredLayers() const override; RTC::Consumer::Layers GetPreferredLayers() const override
bool IsActive() const override; {
RTC::Consumer::Layers layers;
layers.spatial = this->preferredSpatialLayer;
layers.temporal = this->preferredTemporalLayer;
return layers;
}
bool IsActive() const override
{
// clang-format off
return (
RTC::Consumer::IsActive() &&
std::any_of(
this->producerRtpStreams.begin(),
this->producerRtpStreams.end(),
[](const RTC::RtpStream* rtpStream)
{
return (rtpStream != nullptr && rtpStream->GetScore() > 0u);
}
)
);
// clang-format on
}
void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override; void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override; void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override; void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override;
...@@ -31,7 +54,10 @@ namespace RTC ...@@ -31,7 +54,10 @@ namespace RTC
uint32_t GetDesiredBitrate() const override; uint32_t GetDesiredBitrate() const override;
void SendRtpPacket(RTC::RtpPacket* packet) override; void SendRtpPacket(RTC::RtpPacket* packet) override;
void GetRtcp(RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t nowMs) override; void GetRtcp(RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t nowMs) override;
std::vector<RTC::RtpStreamSend*> GetRtpStreams() override; std::vector<RTC::RtpStreamSend*> GetRtpStreams() override
{
return this->rtpStreams;
}
void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override; void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override;
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override; void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override;
void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType, uint32_t ssrc) override; void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType, uint32_t ssrc) override;
...@@ -85,40 +111,6 @@ namespace RTC ...@@ -85,40 +111,6 @@ namespace RTC
bool keyFrameForTsOffsetRequested{ false }; bool keyFrameForTsOffsetRequested{ false };
uint64_t lastBweDowngradeAtMs{ 0u }; // Last time we moved to lower spatial layer due to BWE. uint64_t lastBweDowngradeAtMs{ 0u }; // Last time we moved to lower spatial layer due to BWE.
}; };
/* Inline methods. */
inline RTC::Consumer::Layers SimulcastConsumer::GetPreferredLayers() const
{
RTC::Consumer::Layers layers;
layers.spatial = this->preferredSpatialLayer;
layers.temporal = this->preferredTemporalLayer;
return layers;
}
inline bool SimulcastConsumer::IsActive() const
{
// clang-format off
return (
RTC::Consumer::IsActive() &&
std::any_of(
this->producerRtpStreams.begin(),
this->producerRtpStreams.end(),
[](const RTC::RtpStream* rtpStream)
{
return (rtpStream != nullptr && rtpStream->GetScore() > 0u);
}
)
);
// clang-format on
}
inline std::vector<RTC::RtpStreamSend*> SimulcastConsumer::GetRtpStreams()
{
return this->rtpStreams;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -40,19 +40,15 @@ namespace RTC ...@@ -40,19 +40,15 @@ namespace RTC
bool DecryptSrtp(uint8_t* data, size_t* len); bool DecryptSrtp(uint8_t* data, size_t* len);
bool EncryptRtcp(const uint8_t** data, size_t* len); bool EncryptRtcp(const uint8_t** data, size_t* len);
bool DecryptSrtcp(uint8_t* data, size_t* len); bool DecryptSrtcp(uint8_t* data, size_t* len);
void RemoveStream(uint32_t ssrc); void RemoveStream(uint32_t ssrc)
{
srtp_remove_stream(this->session, uint32_t{ htonl(ssrc) });
}
private: private:
// Allocated by this. // Allocated by this.
srtp_t session{ nullptr }; srtp_t session{ nullptr };
}; };
/* Inline instance methods. */
inline void SrtpSession::RemoveStream(uint32_t ssrc)
{
srtp_remove_stream(this->session, uint32_t{ htonl(ssrc) });
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -53,7 +53,20 @@ namespace RTC ...@@ -53,7 +53,20 @@ namespace RTC
}; };
public: public:
static bool IsStun(const uint8_t* data, size_t len); static bool IsStun(const uint8_t* data, size_t len)
{
// clang-format off
return (
// STUN headers are 20 bytes.
(len >= 20) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] < 3) &&
// Magic cookie must match.
(data[4] == StunPacket::magicCookie[0]) && (data[5] == StunPacket::magicCookie[1]) &&
(data[6] == StunPacket::magicCookie[2]) && (data[7] == StunPacket::magicCookie[3])
);
// clang-format on
}
static StunPacket* Parse(const uint8_t* data, size_t len); static StunPacket* Parse(const uint8_t* data, size_t len);
private: private:
...@@ -65,27 +78,90 @@ namespace RTC ...@@ -65,27 +78,90 @@ namespace RTC
~StunPacket(); ~StunPacket();
void Dump() const; void Dump() const;
Class GetClass() const; Class GetClass() const
Method GetMethod() const; {
const uint8_t* GetData() const; return this->klass;
size_t GetSize() const; }
void SetUsername(const char* username, size_t len); Method GetMethod() const
void SetPriority(uint32_t priority); {
void SetIceControlling(uint64_t iceControlling); return this->method;
void SetIceControlled(uint64_t iceControlled); }
void SetUseCandidate(); const uint8_t* GetData() const
void SetXorMappedAddress(const struct sockaddr* xorMappedAddress); {
void SetErrorCode(uint16_t errorCode); return this->data;
void SetMessageIntegrity(const uint8_t* messageIntegrity); }
void SetFingerprint(); size_t GetSize() const
const std::string& GetUsername() const; {
uint32_t GetPriority() const; return this->size;
uint64_t GetIceControlling() const; }
uint64_t GetIceControlled() const; void SetUsername(const char* username, size_t len)
bool HasUseCandidate() const; {
uint16_t GetErrorCode() const; this->username.assign(username, len);
bool HasMessageIntegrity() const; }
bool HasFingerprint() const; void SetPriority(uint32_t priority)
{
this->priority = priority;
}
void SetIceControlling(uint64_t iceControlling)
{
this->iceControlling = iceControlling;
}
void SetIceControlled(uint64_t iceControlled)
{
this->iceControlled = iceControlled;
}
void SetUseCandidate()
{
this->hasUseCandidate = true;
}
void SetXorMappedAddress(const struct sockaddr* xorMappedAddress)
{
this->xorMappedAddress = xorMappedAddress;
}
void SetErrorCode(uint16_t errorCode)
{
this->errorCode = errorCode;
}
void SetMessageIntegrity(const uint8_t* messageIntegrity)
{
this->messageIntegrity = messageIntegrity;
}
void SetFingerprint()
{
this->hasFingerprint = true;
}
const std::string& GetUsername() const
{
return this->username;
}
uint32_t GetPriority() const
{
return this->priority;
}
uint64_t GetIceControlling() const
{
return this->iceControlling;
}
uint64_t GetIceControlled() const
{
return this->iceControlled;
}
bool HasUseCandidate() const
{
return this->hasUseCandidate;
}
uint16_t GetErrorCode() const
{
return this->errorCode;
}
bool HasMessageIntegrity() const
{
return (this->messageIntegrity ? true : false);
}
bool HasFingerprint() const
{
return this->hasFingerprint;
}
Authentication CheckAuthentication( Authentication CheckAuthentication(
const std::string& localUsername, const std::string& localPassword); const std::string& localUsername, const std::string& localPassword);
StunPacket* CreateSuccessResponse(); StunPacket* CreateSuccessResponse();
...@@ -99,143 +175,19 @@ namespace RTC ...@@ -99,143 +175,19 @@ namespace RTC
Method method; // 2 bytes. Method method; // 2 bytes.
const uint8_t* transactionId{ nullptr }; // 12 bytes. const uint8_t* transactionId{ nullptr }; // 12 bytes.
uint8_t* data{ nullptr }; // Pointer to binary data. uint8_t* data{ nullptr }; // Pointer to binary data.
size_t size{ 0 }; // The full message size (including header). size_t size{ 0u }; // The full message size (including header).
// STUN attributes. // STUN attributes.
std::string username; // Less than 513 bytes. std::string username; // Less than 513 bytes.
uint32_t priority{ 0 }; // 4 bytes unsigned integer. uint32_t priority{ 0u }; // 4 bytes unsigned integer.
uint64_t iceControlling{ 0 }; // 8 bytes unsigned integer. uint64_t iceControlling{ 0u }; // 8 bytes unsigned integer.
uint64_t iceControlled{ 0 }; // 8 bytes unsigned integer. uint64_t iceControlled{ 0u }; // 8 bytes unsigned integer.
bool hasUseCandidate{ false }; // 0 bytes. bool hasUseCandidate{ false }; // 0 bytes.
const uint8_t* messageIntegrity{ nullptr }; // 20 bytes. const uint8_t* messageIntegrity{ nullptr }; // 20 bytes.
bool hasFingerprint{ false }; // 4 bytes. bool hasFingerprint{ false }; // 4 bytes.
const struct sockaddr* xorMappedAddress{ nullptr }; // 8 or 20 bytes. const struct sockaddr* xorMappedAddress{ nullptr }; // 8 or 20 bytes.
uint16_t errorCode{ 0 }; // 4 bytes (no reason phrase). uint16_t errorCode{ 0u }; // 4 bytes (no reason phrase).
std::string password; std::string password;
}; };
/* Inline class methods. */
inline bool StunPacket::IsStun(const uint8_t* data, size_t len)
{
// clang-format off
return (
// STUN headers are 20 bytes.
(len >= 20) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] < 3) &&
// Magic cookie must match.
(data[4] == StunPacket::magicCookie[0]) && (data[5] == StunPacket::magicCookie[1]) &&
(data[6] == StunPacket::magicCookie[2]) && (data[7] == StunPacket::magicCookie[3])
);
// clang-format on
}
/* Inline instance methods. */
inline StunPacket::Class StunPacket::GetClass() const
{
return this->klass;
}
inline StunPacket::Method StunPacket::GetMethod() const
{
return this->method;
}
inline const uint8_t* StunPacket::GetData() const
{
return this->data;
}
inline size_t StunPacket::GetSize() const
{
return this->size;
}
inline void StunPacket::SetUsername(const char* username, size_t len)
{
this->username.assign(username, len);
}
inline void StunPacket::SetPriority(const uint32_t priority)
{
this->priority = priority;
}
inline void StunPacket::SetIceControlling(const uint64_t iceControlling)
{
this->iceControlling = iceControlling;
}
inline void StunPacket::SetIceControlled(const uint64_t iceControlled)
{
this->iceControlled = iceControlled;
}
inline void StunPacket::SetUseCandidate()
{
this->hasUseCandidate = true;
}
inline void StunPacket::SetXorMappedAddress(const struct sockaddr* xorMappedAddress)
{
this->xorMappedAddress = xorMappedAddress;
}
inline void StunPacket::SetErrorCode(uint16_t errorCode)
{
this->errorCode = errorCode;
}
inline void StunPacket::SetMessageIntegrity(const uint8_t* messageIntegrity)
{
this->messageIntegrity = messageIntegrity;
}
inline void StunPacket::SetFingerprint()
{
this->hasFingerprint = true;
}
inline const std::string& StunPacket::GetUsername() const
{
return this->username;
}
inline uint32_t StunPacket::GetPriority() const
{
return this->priority;
}
inline uint64_t StunPacket::GetIceControlling() const
{
return this->iceControlling;
}
inline uint64_t StunPacket::GetIceControlled() const
{
return this->iceControlled;
}
inline bool StunPacket::HasUseCandidate() const
{
return this->hasUseCandidate;
}
inline uint16_t StunPacket::GetErrorCode() const
{
return this->errorCode;
}
inline bool StunPacket::HasMessageIntegrity() const
{
return (this->messageIntegrity ? true : false);
}
inline bool StunPacket::HasFingerprint() const
{
return this->hasFingerprint;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -20,8 +20,25 @@ namespace RTC ...@@ -20,8 +20,25 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override; void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override; void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override; void HandleRequest(Channel::Request* request) override;
RTC::Consumer::Layers GetPreferredLayers() const override; RTC::Consumer::Layers GetPreferredLayers() const override
bool IsActive() const override; {
RTC::Consumer::Layers layers;
layers.spatial = this->preferredSpatialLayer;
layers.temporal = this->preferredTemporalLayer;
return layers;
}
bool IsActive() const override
{
// clang-format off
return (
RTC::Consumer::IsActive() &&
this->producerRtpStream &&
this->producerRtpStream->GetScore() > 0u
);
// clang-format on
}
void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override; void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override; void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override; void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override;
...@@ -32,7 +49,10 @@ namespace RTC ...@@ -32,7 +49,10 @@ namespace RTC
uint32_t GetDesiredBitrate() const override; uint32_t GetDesiredBitrate() const override;
void SendRtpPacket(RTC::RtpPacket* packet) override; void SendRtpPacket(RTC::RtpPacket* packet) override;
void GetRtcp(RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t nowMs) override; void GetRtcp(RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t nowMs) override;
std::vector<RTC::RtpStreamSend*> GetRtpStreams() override; std::vector<RTC::RtpStreamSend*> GetRtpStreams() override
{
return this->rtpStreams;
}
void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override; void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override;
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override; void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override;
void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType, uint32_t ssrc) override; void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType, uint32_t ssrc) override;
...@@ -73,34 +93,6 @@ namespace RTC ...@@ -73,34 +93,6 @@ namespace RTC
std::unique_ptr<RTC::Codecs::EncodingContext> encodingContext; std::unique_ptr<RTC::Codecs::EncodingContext> encodingContext;
uint64_t lastBweDowngradeAtMs{ 0u }; // Last time we moved to lower spatial layer due to BWE. uint64_t lastBweDowngradeAtMs{ 0u }; // Last time we moved to lower spatial layer due to BWE.
}; };
/* Inline methods. */
inline RTC::Consumer::Layers SvcConsumer::GetPreferredLayers() const
{
RTC::Consumer::Layers layers;
layers.spatial = this->preferredSpatialLayer;
layers.temporal = this->preferredTemporalLayer;
return layers;
}
inline bool SvcConsumer::IsActive() const
{
// clang-format off
return (
RTC::Consumer::IsActive() &&
this->producerRtpStream &&
this->producerRtpStream->GetScore() > 0u
);
// clang-format on
}
inline std::vector<RTC::RtpStreamSend*> SvcConsumer::GetRtpStreams()
{
return this->rtpStreams;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -31,7 +31,7 @@ namespace RTC ...@@ -31,7 +31,7 @@ namespace RTC
// Passed by argument. // Passed by argument.
Listener* listener{ nullptr }; Listener* listener{ nullptr };
// Others. // Others.
size_t frameStart{ 0 }; // Where the latest frame starts. size_t frameStart{ 0u }; // Where the latest frame starts.
}; };
} // namespace RTC } // namespace RTC
......
...@@ -124,8 +124,14 @@ namespace RTC ...@@ -124,8 +124,14 @@ namespace RTC
// Must be called from the subclass. // Must be called from the subclass.
void Connected(); void Connected();
void Disconnected(); void Disconnected();
void DataReceived(size_t len); void DataReceived(size_t len)
void DataSent(size_t len); {
this->recvTransmission.Update(len, DepLibUV::GetTimeMs());
}
void DataSent(size_t len)
{
this->sendTransmission.Update(len, DepLibUV::GetTimeMs());
}
void ReceiveRtpPacket(RTC::RtpPacket* packet); void ReceiveRtpPacket(RTC::RtpPacket* packet);
void ReceiveRtcpPacket(RTC::RTCP::Packet* packet); void ReceiveRtcpPacket(RTC::RTCP::Packet* packet);
void ReceiveSctpData(const uint8_t* data, size_t len); void ReceiveSctpData(const uint8_t* data, size_t len);
...@@ -269,18 +275,6 @@ namespace RTC ...@@ -269,18 +275,6 @@ namespace RTC
uint32_t maxIncomingBitrate{ 0u }; uint32_t maxIncomingBitrate{ 0u };
struct TraceEventTypes traceEventTypes; struct TraceEventTypes traceEventTypes;
}; };
/* Inline instance methods. */
inline void Transport::DataReceived(size_t len)
{
this->recvTransmission.Update(len, DepLibUV::GetTimeMs());
}
inline void Transport::DataSent(size_t len)
{
this->sendTransmission.Update(len, DepLibUV::GetTimeMs());
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -53,7 +53,10 @@ namespace RTC ...@@ -53,7 +53,10 @@ namespace RTC
virtual ~TransportCongestionControlClient(); virtual ~TransportCongestionControlClient();
public: public:
RTC::BweType GetBweType() const; RTC::BweType GetBweType() const
{
return this->bweType;
}
void TransportConnected(); void TransportConnected();
void TransportDisconnected(); void TransportDisconnected();
void InsertPacket(webrtc::RtpPacketSendInfo& packetInfo); void InsertPacket(webrtc::RtpPacketSendInfo& packetInfo);
...@@ -63,7 +66,10 @@ namespace RTC ...@@ -63,7 +66,10 @@ namespace RTC
void ReceiveRtcpReceiverReport(const webrtc::RTCPReportBlock& report, float rtt, uint64_t nowMs); void ReceiveRtcpReceiverReport(const webrtc::RTCPReportBlock& report, float rtt, uint64_t nowMs);
void ReceiveRtcpTransportFeedback(const RTC::RTCP::FeedbackRtpTransportPacket* feedback); void ReceiveRtcpTransportFeedback(const RTC::RTCP::FeedbackRtpTransportPacket* feedback);
void SetDesiredBitrate(uint32_t desiredBitrate, bool force); void SetDesiredBitrate(uint32_t desiredBitrate, bool force);
const Bitrates& GetBitrates() const; const Bitrates& GetBitrates() const
{
return this->bitrates;
}
uint32_t GetAvailableBitrate() const; uint32_t GetAvailableBitrate() const;
void RescheduleNextAvailableBitrateEvent(); void RescheduleNextAvailableBitrateEvent();
...@@ -102,18 +108,6 @@ namespace RTC ...@@ -102,18 +108,6 @@ namespace RTC
uint64_t lastAvailableBitrateEventAtMs{ 0u }; uint64_t lastAvailableBitrateEventAtMs{ 0u };
RTC::TrendCalculator desiredBitrateTrend; RTC::TrendCalculator desiredBitrateTrend;
}; };
/* Inline instance methods. */
inline RTC::BweType TransportCongestionControlClient::GetBweType() const
{
return this->bweType;
}
inline const RTC::TransportCongestionControlClient::Bitrates& TransportCongestionControlClient::GetBitrates() const
{
return this->bitrates;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -30,10 +30,23 @@ namespace RTC ...@@ -30,10 +30,23 @@ namespace RTC
virtual ~TransportCongestionControlServer(); virtual ~TransportCongestionControlServer();
public: public:
RTC::BweType GetBweType() const; RTC::BweType GetBweType() const
{
return this->bweType;
}
void TransportConnected(); void TransportConnected();
void TransportDisconnected(); void TransportDisconnected();
uint32_t GetAvailableBitrate() const; uint32_t GetAvailableBitrate() const
{
switch (this->bweType)
{
case RTC::BweType::REMB:
return this->rembServer->GetAvailableBitrate();
default:
return 0u;
}
}
void IncomingPacket(uint64_t nowMs, const RTC::RtpPacket* packet); void IncomingPacket(uint64_t nowMs, const RTC::RtpPacket* packet);
void SetMaxIncomingBitrate(uint32_t bitrate); void SetMaxIncomingBitrate(uint32_t bitrate);
...@@ -69,25 +82,6 @@ namespace RTC ...@@ -69,25 +82,6 @@ namespace RTC
uint64_t limitationRembSentAtMs{ 0u }; uint64_t limitationRembSentAtMs{ 0u };
uint8_t unlimitedRembCounter{ 0u }; uint8_t unlimitedRembCounter{ 0u };
}; };
/* Inline instance methods. */
inline RTC::BweType TransportCongestionControlServer::GetBweType() const
{
return this->bweType;
}
inline uint32_t TransportCongestionControlServer::GetAvailableBitrate() const
{
switch (this->bweType)
{
case RTC::BweType::REMB:
return this->rembServer->GetAvailableBitrate();
default:
return 0u;
}
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -25,131 +25,116 @@ namespace RTC ...@@ -25,131 +25,116 @@ namespace RTC
}; };
public: public:
TransportTuple(RTC::UdpSocket* udpSocket, const struct sockaddr* udpRemoteAddr); TransportTuple(RTC::UdpSocket* udpSocket, const struct sockaddr* udpRemoteAddr)
explicit TransportTuple(RTC::TcpConnection* tcpConnection); : udpSocket(udpSocket), udpRemoteAddr((struct sockaddr*)udpRemoteAddr), protocol(Protocol::UDP)
explicit TransportTuple(const TransportTuple* tuple); {
}
public:
void FillJson(json& jsonObject) const;
void Dump() const;
void StoreUdpRemoteAddress();
bool Compare(const TransportTuple* tuple) const;
void SetLocalAnnouncedIp(std::string& localAnnouncedIp);
void Send(const uint8_t* data, size_t len, RTC::TransportTuple::onSendCallback* cb = nullptr);
Protocol GetProtocol() const;
const struct sockaddr* GetLocalAddress() const;
const struct sockaddr* GetRemoteAddress() const;
size_t GetRecvBytes() const;
size_t GetSentBytes() const;
private:
// Passed by argument.
RTC::UdpSocket* udpSocket{ nullptr };
struct sockaddr* udpRemoteAddr{ nullptr };
RTC::TcpConnection* tcpConnection{ nullptr };
std::string localAnnouncedIp;
// Others.
struct sockaddr_storage udpRemoteAddrStorage;
Protocol protocol;
};
/* Inline methods. */
inline TransportTuple::TransportTuple(RTC::UdpSocket* udpSocket, const struct sockaddr* udpRemoteAddr) explicit TransportTuple(RTC::TcpConnection* tcpConnection)
: udpSocket(udpSocket), udpRemoteAddr((struct sockaddr*)udpRemoteAddr), protocol(Protocol::UDP) : tcpConnection(tcpConnection), protocol(Protocol::TCP)
{ {
} }
inline TransportTuple::TransportTuple(RTC::TcpConnection* tcpConnection) explicit TransportTuple(const TransportTuple* tuple)
: tcpConnection(tcpConnection), protocol(Protocol::TCP) : udpSocket(tuple->udpSocket), udpRemoteAddr(tuple->udpRemoteAddr),
{ tcpConnection(tuple->tcpConnection), localAnnouncedIp(tuple->localAnnouncedIp),
} protocol(tuple->protocol)
{
if (protocol == TransportTuple::Protocol::UDP)
StoreUdpRemoteAddress();
}
inline TransportTuple::TransportTuple(const TransportTuple* tuple) public:
: udpSocket(tuple->udpSocket), udpRemoteAddr(tuple->udpRemoteAddr), void FillJson(json& jsonObject) const;
tcpConnection(tuple->tcpConnection), localAnnouncedIp(tuple->localAnnouncedIp),
protocol(tuple->protocol)
{
if (protocol == TransportTuple::Protocol::UDP)
StoreUdpRemoteAddress();
}
inline void TransportTuple::StoreUdpRemoteAddress() void Dump() const;
{
// Clone the given address into our address storage and make the sockaddr
// pointer point to it.
this->udpRemoteAddrStorage = Utils::IP::CopyAddress(this->udpRemoteAddr);
this->udpRemoteAddr = (struct sockaddr*)&this->udpRemoteAddrStorage;
}
inline TransportTuple::Protocol TransportTuple::GetProtocol() const void StoreUdpRemoteAddress()
{ {
return this->protocol; // Clone the given address into our address storage and make the sockaddr
} // pointer point to it.
this->udpRemoteAddrStorage = Utils::IP::CopyAddress(this->udpRemoteAddr);
this->udpRemoteAddr = (struct sockaddr*)&this->udpRemoteAddrStorage;
}
inline bool TransportTuple::Compare(const TransportTuple* tuple) const bool Compare(const TransportTuple* tuple) const
{
if (this->protocol == Protocol::UDP && tuple->GetProtocol() == Protocol::UDP)
{ {
return ( if (this->protocol == Protocol::UDP && tuple->GetProtocol() == Protocol::UDP)
this->udpSocket == tuple->udpSocket && {
Utils::IP::CompareAddresses(this->udpRemoteAddr, tuple->GetRemoteAddress())); return (
this->udpSocket == tuple->udpSocket &&
Utils::IP::CompareAddresses(this->udpRemoteAddr, tuple->GetRemoteAddress()));
}
else if (this->protocol == Protocol::TCP && tuple->GetProtocol() == Protocol::TCP)
{
return (this->tcpConnection == tuple->tcpConnection);
}
else
{
return false;
}
} }
else if (this->protocol == Protocol::TCP && tuple->GetProtocol() == Protocol::TCP)
void SetLocalAnnouncedIp(std::string& localAnnouncedIp)
{ {
return (this->tcpConnection == tuple->tcpConnection); this->localAnnouncedIp = localAnnouncedIp;
} }
else
void Send(const uint8_t* data, size_t len, RTC::TransportTuple::onSendCallback* cb = nullptr)
{ {
return false; if (this->protocol == Protocol::UDP)
this->udpSocket->Send(data, len, this->udpRemoteAddr, cb);
else
this->tcpConnection->Send(data, len, cb);
} }
}
inline void TransportTuple::SetLocalAnnouncedIp(std::string& localAnnouncedIp) Protocol GetProtocol() const
{ {
this->localAnnouncedIp = localAnnouncedIp; return this->protocol;
} }
inline void TransportTuple::Send( const struct sockaddr* GetLocalAddress() const
const uint8_t* data, size_t len, RTC::TransportTuple::onSendCallback* cb) {
{ if (this->protocol == Protocol::UDP)
if (this->protocol == Protocol::UDP) return this->udpSocket->GetLocalAddress();
this->udpSocket->Send(data, len, this->udpRemoteAddr, cb); else
else return this->tcpConnection->GetLocalAddress();
this->tcpConnection->Send(data, len, cb); }
}
inline const struct sockaddr* TransportTuple::GetLocalAddress() const const struct sockaddr* GetRemoteAddress() const
{ {
if (this->protocol == Protocol::UDP) if (this->protocol == Protocol::UDP)
return this->udpSocket->GetLocalAddress(); return (const struct sockaddr*)this->udpRemoteAddr;
else else
return this->tcpConnection->GetLocalAddress(); return this->tcpConnection->GetPeerAddress();
} }
inline const struct sockaddr* TransportTuple::GetRemoteAddress() const size_t GetRecvBytes() const
{ {
if (this->protocol == Protocol::UDP) if (this->protocol == Protocol::UDP)
return (const struct sockaddr*)this->udpRemoteAddr; return this->udpSocket->GetRecvBytes();
else else
return this->tcpConnection->GetPeerAddress(); return this->tcpConnection->GetRecvBytes();
} }
inline size_t TransportTuple::GetRecvBytes() const size_t GetSentBytes() const
{ {
if (this->protocol == Protocol::UDP) if (this->protocol == Protocol::UDP)
return this->udpSocket->GetRecvBytes(); return this->udpSocket->GetSentBytes();
else else
return this->tcpConnection->GetRecvBytes(); return this->tcpConnection->GetSentBytes();
} }
inline size_t TransportTuple::GetSentBytes() const private:
{ // Passed by argument.
if (this->protocol == Protocol::UDP) RTC::UdpSocket* udpSocket{ nullptr };
return this->udpSocket->GetSentBytes(); struct sockaddr* udpRemoteAddr{ nullptr };
else RTC::TcpConnection* tcpConnection{ nullptr };
return this->tcpConnection->GetSentBytes(); std::string localAnnouncedIp;
} // Others.
struct sockaddr_storage udpRemoteAddrStorage;
Protocol protocol;
};
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -14,7 +14,10 @@ namespace RTC ...@@ -14,7 +14,10 @@ namespace RTC
TrendCalculator(float decreaseFactor = DecreaseFactor); TrendCalculator(float decreaseFactor = DecreaseFactor);
public: public:
uint32_t GetValue() const; uint32_t GetValue() const
{
return this->value;
}
void Update(uint32_t value, uint64_t nowMs); void Update(uint32_t value, uint64_t nowMs);
void ForceUpdate(uint32_t value, uint64_t nowMs); void ForceUpdate(uint32_t value, uint64_t nowMs);
...@@ -24,13 +27,6 @@ namespace RTC ...@@ -24,13 +27,6 @@ namespace RTC
uint32_t highestValue{ 0u }; uint32_t highestValue{ 0u };
uint64_t highestValueUpdatedAtMs{ 0u }; uint64_t highestValueUpdatedAtMs{ 0u };
}; };
/* Inline instance methods. */
inline uint32_t TrendCalculator::GetValue() const
{
return this->value;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -33,8 +33,8 @@ public: ...@@ -33,8 +33,8 @@ public:
{ {
LogLevel logLevel{ LogLevel::LOG_ERROR }; LogLevel logLevel{ LogLevel::LOG_ERROR };
struct LogTags logTags; struct LogTags logTags;
uint16_t rtcMinPort{ 10000 }; uint16_t rtcMinPort{ 10000u };
uint16_t rtcMaxPort{ 59999 }; uint16_t rtcMaxPort{ 59999u };
std::string dtlsCertificateFile; std::string dtlsCertificateFile;
std::string dtlsPrivateKeyFile; std::string dtlsPrivateKeyFile;
}; };
......
...@@ -22,75 +22,73 @@ namespace Utils ...@@ -22,75 +22,73 @@ namespace Utils
{ {
public: public:
static int GetFamily(const std::string& ip); static int GetFamily(const std::string& ip);
static void GetAddressInfo(const struct sockaddr* addr, int& family, std::string& ip, uint16_t& port);
static bool CompareAddresses(const struct sockaddr* addr1, const struct sockaddr* addr2);
static struct sockaddr_storage CopyAddress(const struct sockaddr* addr);
static void NormalizeIp(std::string& ip);
};
/* Inline static methods. */
inline bool IP::CompareAddresses(const struct sockaddr* addr1, const struct sockaddr* addr2)
{
// Compare family.
if (addr1->sa_family != addr2->sa_family || (addr1->sa_family != AF_INET && addr1->sa_family != AF_INET6))
{
return false;
}
// Compare port. static void GetAddressInfo(const struct sockaddr* addr, int& family, std::string& ip, uint16_t& port);
if (
reinterpret_cast<const struct sockaddr_in*>(addr1)->sin_port !=
reinterpret_cast<const struct sockaddr_in*>(addr2)->sin_port)
{
return false;
}
// Compare IP. static bool CompareAddresses(const struct sockaddr* addr1, const struct sockaddr* addr2)
switch (addr1->sa_family)
{ {
case AF_INET: // Compare family.
if (addr1->sa_family != addr2->sa_family || (addr1->sa_family != AF_INET && addr1->sa_family != AF_INET6))
{ {
return ( return false;
reinterpret_cast<const struct sockaddr_in*>(addr1)->sin_addr.s_addr ==
reinterpret_cast<const struct sockaddr_in*>(addr2)->sin_addr.s_addr);
} }
case AF_INET6: // Compare port.
if (
reinterpret_cast<const struct sockaddr_in*>(addr1)->sin_port !=
reinterpret_cast<const struct sockaddr_in*>(addr2)->sin_port)
{ {
return ( return false;
std::memcmp(
std::addressof(reinterpret_cast<const struct sockaddr_in6*>(addr1)->sin6_addr),
std::addressof(reinterpret_cast<const struct sockaddr_in6*>(addr2)->sin6_addr),
16) == 0
? true
: false);
} }
default: // Compare IP.
switch (addr1->sa_family)
{ {
return false; case AF_INET:
{
return (
reinterpret_cast<const struct sockaddr_in*>(addr1)->sin_addr.s_addr ==
reinterpret_cast<const struct sockaddr_in*>(addr2)->sin_addr.s_addr);
}
case AF_INET6:
{
return (
std::memcmp(
std::addressof(reinterpret_cast<const struct sockaddr_in6*>(addr1)->sin6_addr),
std::addressof(reinterpret_cast<const struct sockaddr_in6*>(addr2)->sin6_addr),
16) == 0
? true
: false);
}
default:
{
return false;
}
} }
} }
}
inline struct sockaddr_storage IP::CopyAddress(const struct sockaddr* addr)
{
struct sockaddr_storage copiedAddr;
switch (addr->sa_family) static struct sockaddr_storage CopyAddress(const struct sockaddr* addr)
{ {
case AF_INET: struct sockaddr_storage copiedAddr;
std::memcpy(std::addressof(copiedAddr), addr, sizeof(struct sockaddr_in));
break;
case AF_INET6: switch (addr->sa_family)
std::memcpy(std::addressof(copiedAddr), addr, sizeof(struct sockaddr_in6)); {
break; case AF_INET:
std::memcpy(std::addressof(copiedAddr), addr, sizeof(struct sockaddr_in));
break;
case AF_INET6:
std::memcpy(std::addressof(copiedAddr), addr, sizeof(struct sockaddr_in6));
break;
}
return copiedAddr;
} }
return copiedAddr; static void NormalizeIp(std::string& ip);
} };
class File class File
{ {
...@@ -105,201 +103,180 @@ namespace Utils ...@@ -105,201 +103,180 @@ namespace Utils
* Getters below get value in Host Byte Order. * Getters below get value in Host Byte Order.
* Setters below set value in Network Byte Order. * Setters below set value in Network Byte Order.
*/ */
static uint8_t Get1Byte(const uint8_t* data, size_t i); static uint8_t Get1Byte(const uint8_t* data, size_t i)
static uint16_t Get2Bytes(const uint8_t* data, size_t i); {
static uint32_t Get3Bytes(const uint8_t* data, size_t i); return data[i];
static uint32_t Get4Bytes(const uint8_t* data, size_t i); }
static uint64_t Get8Bytes(const uint8_t* data, size_t i);
static void Set1Byte(uint8_t* data, size_t i, uint8_t value);
static void Set2Bytes(uint8_t* data, size_t i, uint16_t value);
static void Set3Bytes(uint8_t* data, size_t i, uint32_t value);
static void Set4Bytes(uint8_t* data, size_t i, uint32_t value);
static void Set8Bytes(uint8_t* data, size_t i, uint64_t value);
static uint16_t PadTo4Bytes(uint16_t size);
static uint32_t PadTo4Bytes(uint32_t size);
};
/* Inline static methods. */ static uint16_t Get2Bytes(const uint8_t* data, size_t i)
{
return uint16_t{ data[i + 1] } | uint16_t{ data[i] } << 8;
}
inline uint8_t Byte::Get1Byte(const uint8_t* data, size_t i) static uint32_t Get3Bytes(const uint8_t* data, size_t i)
{ {
return data[i]; return uint32_t{ data[i + 2] } | uint32_t{ data[i + 1] } << 8 | uint32_t{ data[i] } << 16;
} }
inline uint16_t Byte::Get2Bytes(const uint8_t* data, size_t i) static uint32_t Get4Bytes(const uint8_t* data, size_t i)
{ {
return uint16_t{ data[i + 1] } | uint16_t{ data[i] } << 8; return uint32_t{ data[i + 3] } | uint32_t{ data[i + 2] } << 8 |
} uint32_t{ data[i + 1] } << 16 | uint32_t{ data[i] } << 24;
}
inline uint32_t Byte::Get3Bytes(const uint8_t* data, size_t i) static uint64_t Get8Bytes(const uint8_t* data, size_t i)
{ {
return uint32_t{ data[i + 2] } | uint32_t{ data[i + 1] } << 8 | uint32_t{ data[i] } << 16; return uint64_t{ Byte::Get4Bytes(data, i) } << 32 | Byte::Get4Bytes(data, i + 4);
} }
inline uint32_t Byte::Get4Bytes(const uint8_t* data, size_t i) static void Set1Byte(uint8_t* data, size_t i, uint8_t value)
{ {
return uint32_t{ data[i + 3] } | uint32_t{ data[i + 2] } << 8 | uint32_t{ data[i + 1] } << 16 | data[i] = value;
uint32_t{ data[i] } << 24; }
}
inline uint64_t Byte::Get8Bytes(const uint8_t* data, size_t i) static void Set2Bytes(uint8_t* data, size_t i, uint16_t value)
{ {
return uint64_t{ Byte::Get4Bytes(data, i) } << 32 | Byte::Get4Bytes(data, i + 4); data[i + 1] = static_cast<uint8_t>(value);
} data[i] = static_cast<uint8_t>(value >> 8);
}
inline void Byte::Set1Byte(uint8_t* data, size_t i, uint8_t value) static void Set3Bytes(uint8_t* data, size_t i, uint32_t value)
{ {
data[i] = value; data[i + 2] = static_cast<uint8_t>(value);
} data[i + 1] = static_cast<uint8_t>(value >> 8);
data[i] = static_cast<uint8_t>(value >> 16);
}
inline void Byte::Set2Bytes(uint8_t* data, size_t i, uint16_t value) static void Set4Bytes(uint8_t* data, size_t i, uint32_t value)
{ {
data[i + 1] = static_cast<uint8_t>(value); data[i + 3] = static_cast<uint8_t>(value);
data[i] = static_cast<uint8_t>(value >> 8); data[i + 2] = static_cast<uint8_t>(value >> 8);
} data[i + 1] = static_cast<uint8_t>(value >> 16);
data[i] = static_cast<uint8_t>(value >> 24);
}
inline void Byte::Set3Bytes(uint8_t* data, size_t i, uint32_t value) static void Set8Bytes(uint8_t* data, size_t i, uint64_t value)
{ {
data[i + 2] = static_cast<uint8_t>(value); data[i + 7] = static_cast<uint8_t>(value);
data[i + 1] = static_cast<uint8_t>(value >> 8); data[i + 6] = static_cast<uint8_t>(value >> 8);
data[i] = static_cast<uint8_t>(value >> 16); data[i + 5] = static_cast<uint8_t>(value >> 16);
} data[i + 4] = static_cast<uint8_t>(value >> 24);
data[i + 3] = static_cast<uint8_t>(value >> 32);
data[i + 2] = static_cast<uint8_t>(value >> 40);
data[i + 1] = static_cast<uint8_t>(value >> 48);
data[i] = static_cast<uint8_t>(value >> 56);
}
inline void Byte::Set4Bytes(uint8_t* data, size_t i, uint32_t value) static uint16_t PadTo4Bytes(uint16_t size)
{ {
data[i + 3] = static_cast<uint8_t>(value); // If size is not multiple of 32 bits then pad it.
data[i + 2] = static_cast<uint8_t>(value >> 8); if (size & 0x03)
data[i + 1] = static_cast<uint8_t>(value >> 16); return (size & 0xFFFC) + 4;
data[i] = static_cast<uint8_t>(value >> 24); else
} return size;
}
inline void Byte::Set8Bytes(uint8_t* data, size_t i, uint64_t value) static uint32_t PadTo4Bytes(uint32_t size)
{ {
data[i + 7] = static_cast<uint8_t>(value); // If size is not multiple of 32 bits then pad it.
data[i + 6] = static_cast<uint8_t>(value >> 8); if (size & 0x03)
data[i + 5] = static_cast<uint8_t>(value >> 16); return (size & 0xFFFFFFFC) + 4;
data[i + 4] = static_cast<uint8_t>(value >> 24); else
data[i + 3] = static_cast<uint8_t>(value >> 32); return size;
data[i + 2] = static_cast<uint8_t>(value >> 40); }
data[i + 1] = static_cast<uint8_t>(value >> 48); };
data[i] = static_cast<uint8_t>(value >> 56);
}
inline uint16_t Byte::PadTo4Bytes(uint16_t size)
{
// If size is not multiple of 32 bits then pad it.
if (size & 0x03)
return (size & 0xFFFC) + 4;
else
return size;
}
inline uint32_t Byte::PadTo4Bytes(uint32_t size)
{
// If size is not multiple of 32 bits then pad it.
if (size & 0x03)
return (size & 0xFFFFFFFC) + 4;
else
return size;
}
class Bits class Bits
{ {
public: public:
static size_t CountSetBits(const uint16_t mask); static size_t CountSetBits(const uint16_t mask)
{
return static_cast<size_t>(__builtin_popcount(mask));
}
}; };
/* Inline static methods. */
inline size_t Bits::CountSetBits(const uint16_t mask)
{
return static_cast<size_t>(__builtin_popcount(mask));
}
class Crypto class Crypto
{ {
public: public:
static void ClassInit(); static void ClassInit();
static void ClassDestroy(); static void ClassDestroy();
static uint32_t GetRandomUInt(uint32_t min, uint32_t max);
static const std::string GetRandomString(size_t len);
static uint32_t GetCRC32(const uint8_t* data, size_t size);
static const uint8_t* GetHmacShA1(const std::string& key, const uint8_t* data, size_t len);
private:
static uint32_t seed;
static HMAC_CTX* hmacSha1Ctx;
static uint8_t hmacSha1Buffer[];
static const uint32_t crc32Table[256];
};
/* Inline static methods. */ static uint32_t GetRandomUInt(uint32_t min, uint32_t max)
{
// NOTE: This is the original, but produces very small values.
// Crypto::seed = (214013 * Crypto::seed) + 2531011;
// return (((Crypto::seed>>16)&0x7FFF) % (max - min + 1)) + min;
inline uint32_t Crypto::GetRandomUInt(uint32_t min, uint32_t max) // This seems to produce better results.
{ Crypto::seed = uint32_t{ ((214013 * Crypto::seed) + 2531011) };
// NOTE: This is the original, but produces very small values.
// Crypto::seed = (214013 * Crypto::seed) + 2531011;
// return (((Crypto::seed>>16)&0x7FFF) % (max - min + 1)) + min;
// This seems to produce better results. // Special case.
Crypto::seed = uint32_t{ ((214013 * Crypto::seed) + 2531011) }; if (max == 4294967295)
--max;
// Special case. if (min > max)
if (max == 4294967295) min = max;
--max;
if (min > max) return (((Crypto::seed >> 4) & 0x7FFF7FFF) % (max - min + 1)) + min;
min = max; }
return (((Crypto::seed >> 4) & 0x7FFF7FFF) % (max - min + 1)) + min; static const std::string GetRandomString(size_t len)
} {
static char buffer[64];
static const char chars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b',
'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
inline const std::string Crypto::GetRandomString(size_t len) if (len > 64)
{ len = 64;
static char buffer[64];
static const char chars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b',
'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
if (len > 64) for (size_t i{ 0 }; i < len; ++i)
len = 64; {
buffer[i] = chars[GetRandomUInt(0, sizeof(chars) - 1)];
}
for (size_t i{ 0 }; i < len; ++i) return std::string(buffer, len);
{
buffer[i] = chars[GetRandomUInt(0, sizeof(chars) - 1)];
} }
return std::string(buffer, len); static uint32_t GetCRC32(const uint8_t* data, size_t size)
} {
uint32_t crc{ 0xFFFFFFFF };
const uint8_t* p = data;
inline uint32_t Crypto::GetCRC32(const uint8_t* data, size_t size) while (size--)
{ {
uint32_t crc{ 0xFFFFFFFF }; crc = Crypto::crc32Table[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
const uint8_t* p = data; }
while (size--) return crc ^ ~0U;
{
crc = Crypto::crc32Table[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
} }
return crc ^ ~0U; static const uint8_t* GetHmacShA1(const std::string& key, const uint8_t* data, size_t len);
}
private:
static uint32_t seed;
static HMAC_CTX* hmacSha1Ctx;
static uint8_t hmacSha1Buffer[];
static const uint32_t crc32Table[256];
};
class String class String
{ {
public: public:
static void ToLowerCase(std::string& str); static void ToLowerCase(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
}
static std::string Base64Encode(const uint8_t* data, size_t len); static std::string Base64Encode(const uint8_t* data, size_t len);
static std::string Base64Encode(const std::string& str); static std::string Base64Encode(const std::string& str);
static uint8_t* Base64Decode(const uint8_t* data, size_t len, size_t& outLen); static uint8_t* Base64Decode(const uint8_t* data, size_t len, size_t& outLen);
static uint8_t* Base64Decode(const std::string& str, size_t& outLen); static uint8_t* Base64Decode(const std::string& str, size_t& outLen);
}; };
inline void String::ToLowerCase(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
}
class Time class Time
{ {
// Seconds from Jan 1, 1900 to Jan 1, 1970. // Seconds from Jan 1, 1900 to Jan 1, 1970.
...@@ -314,74 +291,64 @@ namespace Utils ...@@ -314,74 +291,64 @@ namespace Utils
uint32_t fractions; uint32_t fractions;
}; };
static Time::Ntp TimeMs2Ntp(uint64_t ms); static Time::Ntp TimeMs2Ntp(uint64_t ms)
static uint64_t Ntp2TimeMs(Time::Ntp ntp); {
static bool IsNewerTimestamp(uint32_t timestamp, uint32_t prevTimestamp); Time::Ntp ntp; // NOLINT(cppcoreguidelines-pro-type-member-init)
static uint32_t LatestTimestamp(uint32_t timestamp1, uint32_t timestamp2);
static uint32_t TimeMsToAbsSendTime(uint64_t ms);
};
inline Time::Ntp Time::TimeMs2Ntp(uint64_t ms) ntp.seconds = ms / 1000;
{ ntp.fractions =
Time::Ntp ntp; // NOLINT(cppcoreguidelines-pro-type-member-init) static_cast<uint32_t>((static_cast<double>(ms % 1000) / 1000) * NtpFractionalUnit);
ntp.seconds = ms / 1000; return ntp;
ntp.fractions = }
static_cast<uint32_t>((static_cast<double>(ms % 1000) / 1000) * NtpFractionalUnit);
return ntp; static uint64_t Ntp2TimeMs(Time::Ntp ntp)
} {
// clang-format off
return (
static_cast<uint64_t>(ntp.seconds) * 1000 +
static_cast<uint64_t>(std::round((static_cast<double>(ntp.fractions) * 1000) / NtpFractionalUnit))
);
// clang-format on
}
inline uint64_t Time::Ntp2TimeMs(Time::Ntp ntp) static bool IsNewerTimestamp(uint32_t timestamp, uint32_t prevTimestamp)
{ {
// clang-format off // Distinguish between elements that are exactly 0x80000000 apart.
return ( // If t1>t2 and |t1-t2| = 0x80000000: IsNewer(t1,t2)=true,
static_cast<uint64_t>(ntp.seconds) * 1000 + // IsNewer(t2,t1)=false
static_cast<uint64_t>(std::round((static_cast<double>(ntp.fractions) * 1000) / NtpFractionalUnit)) // rather than having IsNewer(t1,t2) = IsNewer(t2,t1) = false.
); if (static_cast<uint32_t>(timestamp - prevTimestamp) == 0x80000000)
// clang-format on return timestamp > prevTimestamp;
}
return timestamp != prevTimestamp &&
inline bool Time::IsNewerTimestamp(uint32_t timestamp, uint32_t prevTimestamp) static_cast<uint32_t>(timestamp - prevTimestamp) < 0x80000000;
{ }
// Distinguish between elements that are exactly 0x80000000 apart.
// If t1>t2 and |t1-t2| = 0x80000000: IsNewer(t1,t2)=true,
// IsNewer(t2,t1)=false
// rather than having IsNewer(t1,t2) = IsNewer(t2,t1) = false.
if (static_cast<uint32_t>(timestamp - prevTimestamp) == 0x80000000)
return timestamp > prevTimestamp;
return timestamp != prevTimestamp &&
static_cast<uint32_t>(timestamp - prevTimestamp) < 0x80000000;
}
inline uint32_t Time::LatestTimestamp(uint32_t timestamp1, uint32_t timestamp2)
{
return IsNewerTimestamp(timestamp1, timestamp2) ? timestamp1 : timestamp2;
}
inline uint32_t Time::TimeMsToAbsSendTime(uint64_t ms) static uint32_t LatestTimestamp(uint32_t timestamp1, uint32_t timestamp2)
{ {
return static_cast<uint32_t>(((ms << 18) + 500) / 1000) & 0x00FFFFFF; return IsNewerTimestamp(timestamp1, timestamp2) ? timestamp1 : timestamp2;
} }
static uint32_t TimeMsToAbsSendTime(uint64_t ms)
{
return static_cast<uint32_t>(((ms << 18) + 500) / 1000) & 0x00FFFFFF;
}
};
class Json class Json
{ {
public: public:
static bool IsPositiveInteger(const json& value); static bool IsPositiveInteger(const json& value)
{
if (value.is_number_unsigned())
return true;
else if (value.is_number_integer())
return value.get<int64_t>() >= 0;
else
return false;
}
}; };
/* Inline static methods. */
inline bool Json::IsPositiveInteger(const json& value)
{
if (value.is_number_unsigned())
return true;
else if (value.is_number_integer())
return value.get<int64_t>() >= 0;
else
return false;
}
} // namespace Utils } // namespace Utils
#endif #endif
...@@ -57,8 +57,14 @@ public: ...@@ -57,8 +57,14 @@ public:
struct sockaddr_storage* localAddr, struct sockaddr_storage* localAddr,
const std::string& localIp, const std::string& localIp,
uint16_t localPort); uint16_t localPort);
bool IsClosed() const; bool IsClosed() const
uv_tcp_t* GetUvHandle() const; {
return this->closed;
}
uv_tcp_t* GetUvHandle() const
{
return this->uvHandle;
}
void Start(); void Start();
void Write(const uint8_t* data, size_t len, TcpConnection::onSendCallback* cb); void Write(const uint8_t* data, size_t len, TcpConnection::onSendCallback* cb);
void Write( void Write(
...@@ -68,15 +74,42 @@ public: ...@@ -68,15 +74,42 @@ public:
size_t len2, size_t len2,
TcpConnection::onSendCallback* cb); TcpConnection::onSendCallback* cb);
void ErrorReceiving(); void ErrorReceiving();
const struct sockaddr* GetLocalAddress() const; const struct sockaddr* GetLocalAddress() const
int GetLocalFamily() const; {
const std::string& GetLocalIp() const; return reinterpret_cast<const struct sockaddr*>(this->localAddr);
uint16_t GetLocalPort() const; }
const struct sockaddr* GetPeerAddress() const; int GetLocalFamily() const
const std::string& GetPeerIp() const; {
uint16_t GetPeerPort() const; return reinterpret_cast<const struct sockaddr*>(this->localAddr)->sa_family;
size_t GetRecvBytes() const; }
size_t GetSentBytes() const; const std::string& GetLocalIp() const
{
return this->localIp;
}
uint16_t GetLocalPort() const
{
return this->localPort;
}
const struct sockaddr* GetPeerAddress() const
{
return reinterpret_cast<const struct sockaddr*>(&this->peerAddr);
}
const std::string& GetPeerIp() const
{
return this->peerIp;
}
uint16_t GetPeerPort() const
{
return this->peerPort;
}
size_t GetRecvBytes() const
{
return this->recvBytes;
}
size_t GetSentBytes() const
{
return this->sentBytes;
}
private: private:
bool SetPeerAddress(); bool SetPeerAddress();
...@@ -93,16 +126,16 @@ protected: ...@@ -93,16 +126,16 @@ protected:
protected: protected:
// Passed by argument. // Passed by argument.
size_t bufferSize{ 0 }; size_t bufferSize{ 0u };
// Allocated by this. // Allocated by this.
uint8_t* buffer{ nullptr }; uint8_t* buffer{ nullptr };
// Others. // Others.
size_t bufferDataLen{ 0 }; size_t bufferDataLen{ 0u };
std::string localIp; std::string localIp;
uint16_t localPort{ 0 }; uint16_t localPort{ 0u };
struct sockaddr_storage peerAddr; struct sockaddr_storage peerAddr;
std::string peerIp; std::string peerIp;
uint16_t peerPort{ 0 }; uint16_t peerPort{ 0u };
private: private:
// Passed by argument. // Passed by argument.
...@@ -112,67 +145,10 @@ private: ...@@ -112,67 +145,10 @@ private:
// Others. // Others.
struct sockaddr_storage* localAddr{ nullptr }; struct sockaddr_storage* localAddr{ nullptr };
bool closed{ false }; bool closed{ false };
size_t recvBytes{ 0 }; size_t recvBytes{ 0u };
size_t sentBytes{ 0 }; size_t sentBytes{ 0u };
bool isClosedByPeer{ false }; bool isClosedByPeer{ false };
bool hasError{ false }; bool hasError{ false };
}; };
/* Inline methods. */
inline bool TcpConnection::IsClosed() const
{
return this->closed;
}
inline uv_tcp_t* TcpConnection::GetUvHandle() const
{
return this->uvHandle;
}
inline const struct sockaddr* TcpConnection::GetLocalAddress() const
{
return reinterpret_cast<const struct sockaddr*>(this->localAddr);
}
inline int TcpConnection::GetLocalFamily() const
{
return reinterpret_cast<const struct sockaddr*>(this->localAddr)->sa_family;
}
inline const std::string& TcpConnection::GetLocalIp() const
{
return this->localIp;
}
inline uint16_t TcpConnection::GetLocalPort() const
{
return this->localPort;
}
inline const struct sockaddr* TcpConnection::GetPeerAddress() const
{
return reinterpret_cast<const struct sockaddr*>(&this->peerAddr);
}
inline const std::string& TcpConnection::GetPeerIp() const
{
return this->peerIp;
}
inline uint16_t TcpConnection::GetPeerPort() const
{
return this->peerPort;
}
inline size_t TcpConnection::GetRecvBytes() const
{
return this->recvBytes;
}
inline size_t TcpConnection::GetSentBytes() const
{
return this->sentBytes;
}
#endif #endif
...@@ -19,11 +19,26 @@ public: ...@@ -19,11 +19,26 @@ public:
public: public:
void Close(); void Close();
virtual void Dump() const; virtual void Dump() const;
const struct sockaddr* GetLocalAddress() const; const struct sockaddr* GetLocalAddress() const
int GetLocalFamily() const; {
const std::string& GetLocalIp() const; return reinterpret_cast<const struct sockaddr*>(&this->localAddr);
uint16_t GetLocalPort() const; }
size_t GetNumConnections() const; int GetLocalFamily() const
{
return reinterpret_cast<const struct sockaddr*>(&this->localAddr)->sa_family;
}
const std::string& GetLocalIp() const
{
return this->localIp;
}
uint16_t GetLocalPort() const
{
return this->localPort;
}
size_t GetNumConnections() const
{
return this->connections.size();
}
protected: protected:
void AcceptTcpConnection(TcpConnection* connection); void AcceptTcpConnection(TcpConnection* connection);
...@@ -47,7 +62,7 @@ public: ...@@ -47,7 +62,7 @@ public:
protected: protected:
struct sockaddr_storage localAddr; struct sockaddr_storage localAddr;
std::string localIp; std::string localIp;
uint16_t localPort{ 0 }; uint16_t localPort{ 0u };
private: private:
// Allocated by this (may be passed by argument). // Allocated by this (may be passed by argument).
...@@ -57,31 +72,4 @@ private: ...@@ -57,31 +72,4 @@ private:
bool closed{ false }; bool closed{ false };
}; };
/* Inline methods. */
inline size_t TcpServer::GetNumConnections() const
{
return this->connections.size();
}
inline const struct sockaddr* TcpServer::GetLocalAddress() const
{
return reinterpret_cast<const struct sockaddr*>(&this->localAddr);
}
inline int TcpServer::GetLocalFamily() const
{
return reinterpret_cast<const struct sockaddr*>(&this->localAddr)->sa_family;
}
inline const std::string& TcpServer::GetLocalIp() const
{
return this->localIp;
}
inline uint16_t TcpServer::GetLocalPort() const
{
return this->localPort;
}
#endif #endif
...@@ -28,9 +28,18 @@ public: ...@@ -28,9 +28,18 @@ public:
void Stop(); void Stop();
void Reset(); void Reset();
void Restart(); void Restart();
uint64_t GetTimeout() const; uint64_t GetTimeout() const
uint64_t GetRepeat() const; {
bool IsActive() const; return this->timeout;
}
uint64_t GetRepeat() const
{
return this->repeat;
}
bool IsActive() const
{
return uv_is_active(reinterpret_cast<uv_handle_t*>(this->uvHandle)) != 0;
}
/* Callbacks fired by UV events. */ /* Callbacks fired by UV events. */
public: public:
...@@ -43,25 +52,8 @@ private: ...@@ -43,25 +52,8 @@ private:
uv_timer_t* uvHandle{ nullptr }; uv_timer_t* uvHandle{ nullptr };
// Others. // Others.
bool closed{ false }; bool closed{ false };
uint64_t timeout{ 0 }; uint64_t timeout{ 0u };
uint64_t repeat{ 0 }; uint64_t repeat{ 0u };
}; };
/* Inline methods. */
inline uint64_t Timer::GetTimeout() const
{
return this->timeout;
}
inline uint64_t Timer::GetRepeat() const
{
return this->repeat;
}
inline bool Timer::IsActive() const
{
return uv_is_active(reinterpret_cast<uv_handle_t*>(this->uvHandle)) != 0;
}
#endif #endif
...@@ -46,12 +46,30 @@ public: ...@@ -46,12 +46,30 @@ public:
void Close(); void Close();
virtual void Dump() const; virtual void Dump() const;
void Send(const uint8_t* data, size_t len, const struct sockaddr* addr, UdpSocket::onSendCallback* cb); void Send(const uint8_t* data, size_t len, const struct sockaddr* addr, UdpSocket::onSendCallback* cb);
const struct sockaddr* GetLocalAddress() const; const struct sockaddr* GetLocalAddress() const
int GetLocalFamily() const; {
const std::string& GetLocalIp() const; return reinterpret_cast<const struct sockaddr*>(&this->localAddr);
uint16_t GetLocalPort() const; }
size_t GetRecvBytes() const; int GetLocalFamily() const
size_t GetSentBytes() const; {
return reinterpret_cast<const struct sockaddr*>(&this->localAddr)->sa_family;
}
const std::string& GetLocalIp() const
{
return this->localIp;
}
uint16_t GetLocalPort() const
{
return this->localPort;
}
size_t GetRecvBytes() const
{
return this->recvBytes;
}
size_t GetSentBytes() const
{
return this->sentBytes;
}
private: private:
bool SetLocalAddress(); bool SetLocalAddress();
...@@ -70,47 +88,15 @@ protected: ...@@ -70,47 +88,15 @@ protected:
protected: protected:
struct sockaddr_storage localAddr; struct sockaddr_storage localAddr;
std::string localIp; std::string localIp;
uint16_t localPort{ 0 }; uint16_t localPort{ 0u };
private: private:
// Allocated by this (may be passed by argument). // Allocated by this (may be passed by argument).
uv_udp_t* uvHandle{ nullptr }; uv_udp_t* uvHandle{ nullptr };
// Others. // Others.
bool closed{ false }; bool closed{ false };
size_t recvBytes{ 0 }; size_t recvBytes{ 0u };
size_t sentBytes{ 0 }; size_t sentBytes{ 0u };
}; };
/* Inline methods. */
inline const struct sockaddr* UdpSocket::GetLocalAddress() const
{
return reinterpret_cast<const struct sockaddr*>(&this->localAddr);
}
inline int UdpSocket::GetLocalFamily() const
{
return reinterpret_cast<const struct sockaddr*>(&this->localAddr)->sa_family;
}
inline const std::string& UdpSocket::GetLocalIp() const
{
return this->localIp;
}
inline uint16_t UdpSocket::GetLocalPort() const
{
return this->localPort;
}
inline size_t UdpSocket::GetRecvBytes() const
{
return this->recvBytes;
}
inline size_t UdpSocket::GetSentBytes() const
{
return this->sentBytes;
}
#endif #endif
...@@ -42,9 +42,15 @@ public: ...@@ -42,9 +42,15 @@ public:
public: public:
void Close(); void Close();
bool IsClosed() const; bool IsClosed() const
{
return this->closed;
}
void Write(const uint8_t* data, size_t len); void Write(const uint8_t* data, size_t len);
void Write(const std::string& data); void Write(const std::string& data)
{
Write(reinterpret_cast<const uint8_t*>(data.c_str()), data.size());
}
/* Callbacks fired by UV events. */ /* Callbacks fired by UV events. */
public: public:
...@@ -67,24 +73,12 @@ private: ...@@ -67,24 +73,12 @@ private:
protected: protected:
// Passed by argument. // Passed by argument.
size_t bufferSize{ 0 }; size_t bufferSize{ 0u };
UnixStreamSocket::Role role; UnixStreamSocket::Role role;
// Allocated by this. // Allocated by this.
uint8_t* buffer{ nullptr }; uint8_t* buffer{ nullptr };
// Others. // Others.
size_t bufferDataLen{ 0 }; size_t bufferDataLen{ 0u };
}; };
/* Inline methods. */
inline bool UnixStreamSocket::IsClosed() const
{
return this->closed;
}
inline void UnixStreamSocket::Write(const std::string& data)
{
Write(reinterpret_cast<const uint8_t*>(data.c_str()), data.size());
}
#endif #endif
...@@ -79,7 +79,6 @@ ...@@ -79,7 +79,6 @@
'src/RTC/TrendCalculator.cpp', 'src/RTC/TrendCalculator.cpp',
'src/RTC/UdpSocket.cpp', 'src/RTC/UdpSocket.cpp',
'src/RTC/WebRtcTransport.cpp', 'src/RTC/WebRtcTransport.cpp',
'src/RTC/Codecs/Codecs.cpp',
'src/RTC/Codecs/H264.cpp', 'src/RTC/Codecs/H264.cpp',
'src/RTC/Codecs/VP8.cpp', 'src/RTC/Codecs/VP8.cpp',
'src/RTC/Codecs/VP9.cpp', 'src/RTC/Codecs/VP9.cpp',
...@@ -191,7 +190,7 @@ ...@@ -191,7 +190,7 @@
'include/RTC/TrendCalculator.hpp', 'include/RTC/TrendCalculator.hpp',
'include/RTC/UdpSocket.hpp', 'include/RTC/UdpSocket.hpp',
'include/RTC/WebRtcTransport.hpp', 'include/RTC/WebRtcTransport.hpp',
'include/RTC/Codecs/Codecs.hpp', 'include/RTC/Codecs/Tools.hpp',
'include/RTC/Codecs/PayloadDescriptorHandler.hpp', 'include/RTC/Codecs/PayloadDescriptorHandler.hpp',
'include/RTC/Codecs/H264.hpp', 'include/RTC/Codecs/H264.hpp',
'include/RTC/Codecs/VP8.hpp', 'include/RTC/Codecs/VP8.hpp',
......
#define MS_CLASS "RTC::Codecs"
// #define MS_LOG_DEV_LEVEL 3
#include "RTC/Codecs/Codecs.hpp"
#include "Logger.hpp"
#include "RTC/Codecs/VP8.hpp"
namespace RTC
{
namespace Codecs
{
void ProcessRtpPacket(RTC::RtpPacket* packet, const RTC::RtpCodecMimeType& mimeType)
{
MS_TRACE();
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
{
RTC::Codecs::VP8::ProcessRtpPacket(packet);
break;
}
case RTC::RtpCodecMimeType::Subtype::VP9:
{
RTC::Codecs::VP9::ProcessRtpPacket(packet);
break;
}
case RTC::RtpCodecMimeType::Subtype::H264:
{
RTC::Codecs::H264::ProcessRtpPacket(packet);
break;
}
default:;
}
}
default:;
}
}
} // namespace Codecs
} // namespace RTC
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "DepLibUV.hpp" #include "DepLibUV.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "RTC/Codecs/Codecs.hpp" #include "RTC/Codecs/Tools.hpp"
namespace RTC namespace RTC
{ {
...@@ -23,7 +23,7 @@ namespace RTC ...@@ -23,7 +23,7 @@ namespace RTC
auto& encoding = this->rtpParameters.encodings[0]; auto& encoding = this->rtpParameters.encodings[0];
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding); auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
this->keyFrameSupported = RTC::Codecs::CanBeKeyFrame(mediaCodec->mimeType); this->keyFrameSupported = RTC::Codecs::Tools::CanBeKeyFrame(mediaCodec->mimeType);
// Create RtpStreamSend instances. // Create RtpStreamSend instances.
CreateRtpStreams(); CreateRtpStreams();
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Channel/Notifier.hpp" #include "Channel/Notifier.hpp"
#include "RTC/Codecs/Codecs.hpp" #include "RTC/Codecs/Tools.hpp"
#include "RTC/RTCP/FeedbackPs.hpp" #include "RTC/RTCP/FeedbackPs.hpp"
#include "RTC/RTCP/FeedbackRtp.hpp" #include "RTC/RTCP/FeedbackRtp.hpp"
#include "RTC/RTCP/XrReceiverReferenceTime.hpp" #include "RTC/RTCP/XrReceiverReferenceTime.hpp"
...@@ -49,7 +49,7 @@ namespace RTC ...@@ -49,7 +49,7 @@ namespace RTC
auto& encoding = this->rtpParameters.encodings[0]; auto& encoding = this->rtpParameters.encodings[0];
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding); auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
if (!RTC::Codecs::IsValidTypeForCodec(this->type, mediaCodec->mimeType)) if (!RTC::Codecs::Tools::IsValidTypeForCodec(this->type, mediaCodec->mimeType))
{ {
MS_THROW_TYPE_ERROR( MS_THROW_TYPE_ERROR(
"%s codec not supported for %s", "%s codec not supported for %s",
......
...@@ -118,9 +118,32 @@ namespace RTC ...@@ -118,9 +118,32 @@ namespace RTC
void CompoundPacket::AddSenderReport(SenderReport* report) void CompoundPacket::AddSenderReport(SenderReport* report)
{ {
MS_TRACE();
MS_ASSERT(!HasSenderReport(), "a Sender Report is already present"); MS_ASSERT(!HasSenderReport(), "a Sender Report is already present");
this->senderReportPacket.AddReport(report); this->senderReportPacket.AddReport(report);
} }
void CompoundPacket::AddReceiverReport(ReceiverReport* report)
{
MS_TRACE();
this->receiverReportPacket.AddReport(report);
}
void CompoundPacket::AddSdesChunk(SdesChunk* chunk)
{
MS_TRACE();
this->sdesPacket.AddChunk(chunk);
}
void CompoundPacket::AddReceiverReferenceTime(ReceiverReferenceTime* report)
{
MS_TRACE();
this->xrPacket.AddReport(report);
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -184,6 +184,8 @@ namespace RTC ...@@ -184,6 +184,8 @@ namespace RTC
const std::string& Packet::Type2String(Type type) const std::string& Packet::Type2String(Type type)
{ {
MS_TRACE();
static const std::string Unknown("UNKNOWN"); static const std::string Unknown("UNKNOWN");
auto it = Packet::type2String.find(type); auto it = Packet::type2String.find(type);
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "RTC/RtpStreamRecv.hpp" #include "RTC/RtpStreamRecv.hpp"
#include "Logger.hpp" #include "Logger.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "RTC/Codecs/Codecs.hpp" #include "RTC/Codecs/Tools.hpp"
namespace RTC namespace RTC
{ {
...@@ -250,7 +250,7 @@ namespace RTC ...@@ -250,7 +250,7 @@ namespace RTC
// Process the packet at codec level. // Process the packet at codec level.
if (packet->GetPayloadType() == GetPayloadType()) if (packet->GetPayloadType() == GetPayloadType())
RTC::Codecs::ProcessRtpPacket(packet, GetMimeType()); RTC::Codecs::Tools::ProcessRtpPacket(packet, GetMimeType());
// Pass the packet to the NackGenerator. // Pass the packet to the NackGenerator.
if (this->params.useNack) if (this->params.useNack)
...@@ -370,7 +370,7 @@ namespace RTC ...@@ -370,7 +370,7 @@ namespace RTC
// Process the packet at codec level. // Process the packet at codec level.
if (packet->GetPayloadType() == GetPayloadType()) if (packet->GetPayloadType() == GetPayloadType())
RTC::Codecs::ProcessRtpPacket(packet, GetMimeType()); RTC::Codecs::Tools::ProcessRtpPacket(packet, GetMimeType());
// Mark the packet as retransmitted. // Mark the packet as retransmitted.
RTC::RtpStream::PacketRetransmitted(packet); RTC::RtpStream::PacketRetransmitted(packet);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "Logger.hpp" #include "Logger.hpp"
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Channel/Notifier.hpp" #include "Channel/Notifier.hpp"
#include "RTC/Codecs/Codecs.hpp" #include "RTC/Codecs/Tools.hpp"
namespace RTC namespace RTC
{ {
...@@ -24,7 +24,7 @@ namespace RTC ...@@ -24,7 +24,7 @@ namespace RTC
auto& encoding = this->rtpParameters.encodings[0]; auto& encoding = this->rtpParameters.encodings[0];
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding); auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
this->keyFrameSupported = RTC::Codecs::CanBeKeyFrame(mediaCodec->mimeType); this->keyFrameSupported = RTC::Codecs::Tools::CanBeKeyFrame(mediaCodec->mimeType);
// Create RtpStreamSend instance for sending a single stream to the remote. // Create RtpStreamSend instance for sending a single stream to the remote.
CreateRtpStream(); CreateRtpStream();
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Channel/Notifier.hpp" #include "Channel/Notifier.hpp"
#include "RTC/Codecs/Codecs.hpp" #include "RTC/Codecs/Tools.hpp"
namespace RTC namespace RTC
{ {
...@@ -102,7 +102,7 @@ namespace RTC ...@@ -102,7 +102,7 @@ namespace RTC
// Create the encoding context. // Create the encoding context.
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding); auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
if (!RTC::Codecs::IsValidTypeForCodec(this->type, mediaCodec->mimeType)) if (!RTC::Codecs::Tools::IsValidTypeForCodec(this->type, mediaCodec->mimeType))
{ {
MS_THROW_TYPE_ERROR( MS_THROW_TYPE_ERROR(
"%s codec not supported for simulcast", mediaCodec->mimeType.ToString().c_str()); "%s codec not supported for simulcast", mediaCodec->mimeType.ToString().c_str());
...@@ -113,7 +113,7 @@ namespace RTC ...@@ -113,7 +113,7 @@ namespace RTC
params.spatialLayers = encoding.spatialLayers; params.spatialLayers = encoding.spatialLayers;
params.temporalLayers = encoding.temporalLayers; params.temporalLayers = encoding.temporalLayers;
this->encodingContext.reset(RTC::Codecs::GetEncodingContext(mediaCodec->mimeType, params)); this->encodingContext.reset(RTC::Codecs::Tools::GetEncodingContext(mediaCodec->mimeType, params));
MS_ASSERT(this->encodingContext, "no encoding context for this codec"); MS_ASSERT(this->encodingContext, "no encoding context for this codec");
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Channel/Notifier.hpp" #include "Channel/Notifier.hpp"
#include "RTC/Codecs/Codecs.hpp" #include "RTC/Codecs/Tools.hpp"
namespace RTC namespace RTC
{ {
...@@ -84,7 +84,7 @@ namespace RTC ...@@ -84,7 +84,7 @@ namespace RTC
// Create the encoding context. // Create the encoding context.
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding); auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
if (!RTC::Codecs::IsValidTypeForCodec(this->type, mediaCodec->mimeType)) if (!RTC::Codecs::Tools::IsValidTypeForCodec(this->type, mediaCodec->mimeType))
{ {
MS_THROW_TYPE_ERROR("%s codec not supported for svc", mediaCodec->mimeType.ToString().c_str()); MS_THROW_TYPE_ERROR("%s codec not supported for svc", mediaCodec->mimeType.ToString().c_str());
} }
...@@ -95,7 +95,7 @@ namespace RTC ...@@ -95,7 +95,7 @@ namespace RTC
params.temporalLayers = encoding.temporalLayers; params.temporalLayers = encoding.temporalLayers;
params.ksvc = encoding.ksvc; params.ksvc = encoding.ksvc;
this->encodingContext.reset(RTC::Codecs::GetEncodingContext(mediaCodec->mimeType, params)); this->encodingContext.reset(RTC::Codecs::Tools::GetEncodingContext(mediaCodec->mimeType, params));
MS_ASSERT(this->encodingContext, "no encoding context for this codec"); MS_ASSERT(this->encodingContext, "no encoding context for this codec");
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论