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 @@
"directory": "PATH/out",
"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",
"directory": "PATH/out",
......@@ -534,4 +529,4 @@
"directory": "PATH/out",
"file": "PATH/src/main.cpp"
}
]
\ No newline at end of file
]
......@@ -29,13 +29,14 @@ namespace Channel
// Passed by argument.
Listener* listener{ nullptr };
// Others.
size_t msgStart{ 0 }; // Where the latest message starts.
size_t msgStart{ 0u }; // Where the latest message starts.
};
class ProducerSocket : public ::UnixStreamSocket
{
public:
ProducerSocket(int fd, size_t bufferSize);
/* Pure virtual methods inherited from ::UnixStreamSocket. */
public:
void UserOnUnixStreamRead() override
......
......@@ -9,24 +9,18 @@ class DepLibSRTP
public:
static void ClassInit();
static void ClassDestroy();
static bool IsError(srtp_err_status_t code);
static const char* GetErrorString(srtp_err_status_t code);
static bool IsError(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:
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
......@@ -11,35 +11,25 @@ public:
static void ClassDestroy();
static void PrintVersion();
static void RunLoop();
static uv_loop_t* GetLoop();
static uint64_t GetTimeMs();
static uint64_t GetTimeUs();
static uint64_t GetTimeNs();
static uv_loop_t* GetLoop()
{
return DepLibUV::loop;
}
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:
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
......@@ -8,27 +8,19 @@
class MediaSoupError : public std::runtime_error
{
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
{
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
#define MS_THROW_ERROR(desc, ...) \
do \
......
......@@ -15,8 +15,8 @@ namespace RTC
private:
struct DBovs
{
uint16_t totalSum{ 0 }; // Sum of dBvos (positive integer).
size_t count{ 0 }; // Number of dBvos entries in totalSum.
uint16_t totalSum{ 0u }; // Sum of dBvos (positive integer).
size_t count{ 0u }; // Number of dBvos entries in totalSum.
};
public:
......@@ -42,9 +42,9 @@ namespace RTC
private:
// Passed by argument.
uint16_t maxEntries{ 1 };
uint16_t maxEntries{ 1u };
int8_t threshold{ -80 };
uint16_t interval{ 1000 };
uint16_t interval{ 1000u };
// Allocated by this.
Timer* periodicTimer{ nullptr };
// 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
class EncodingContext : public RTC::Codecs::EncodingContext
{
public:
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params);
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
~EncodingContext() = default;
/* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */
public:
void SyncRequired() override;
void SyncRequired() override
{
}
};
public:
......@@ -63,50 +68,29 @@ namespace RTC
~PayloadDescriptorHandler() = default;
public:
void Dump() const override;
void Dump() const override
{
this->payloadDescriptor->Dump();
}
bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override;
void Restore(uint8_t* data) override;
uint8_t GetSpatialLayer() const override;
uint8_t GetTemporalLayer() const override;
bool IsKeyFrame() const override;
uint8_t GetSpatialLayer() const override
{
return 0u;
}
uint8_t GetTemporalLayer() const override
{
return this->payloadDescriptor->tid;
}
bool IsKeyFrame() const override
{
return this->payloadDescriptor->isKeyFrame;
}
private:
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 RTC
......
#ifndef MS_RTC_PAYLOAD_DESCRIPTOR_HANDLER_HPP
#define MS_RTC_PAYLOAD_DESCRIPTOR_HANDLER_HPP
#ifndef MS_RTC_CODECS_PAYLOAD_DESCRIPTOR_HANDLER_HPP
#define MS_RTC_CODECS_PAYLOAD_DESCRIPTOR_HANDLER_HPP
#include "common.hpp"
......@@ -27,21 +27,56 @@ namespace RTC
};
public:
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params);
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params) : params(params)
{
}
virtual ~EncodingContext() = default;
public:
uint8_t GetSpatialLayers() const;
uint8_t GetTemporalLayers() const;
bool IsKSvc() const;
int16_t GetTargetSpatialLayer() const;
int16_t GetTargetTemporalLayer() const;
int16_t GetCurrentSpatialLayer() const;
int16_t GetCurrentTemporalLayer() const;
void SetTargetSpatialLayer(int16_t spatialLayer);
void SetTargetTemporalLayer(int16_t temporalLayer);
void SetCurrentSpatialLayer(int16_t spatialLayer);
void SetCurrentTemporalLayer(int16_t temporalLayer);
uint8_t GetSpatialLayers() const
{
return this->params.spatialLayers;
}
uint8_t GetTemporalLayers() const
{
return this->params.temporalLayers;
}
bool IsKSvc() const
{
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;
private:
......@@ -52,68 +87,6 @@ namespace RTC
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
{
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
class EncodingContext : public RTC::Codecs::EncodingContext
{
public:
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params);
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
~EncodingContext() = default;
/* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */
public:
void SyncRequired() override;
void SyncRequired() override
{
this->syncRequired = true;
}
public:
RTC::SeqManager<uint16_t> pictureIdManager;
......@@ -103,51 +109,29 @@ namespace RTC
~PayloadDescriptorHandler() = default;
public:
void Dump() const override;
void Dump() const override
{
this->payloadDescriptor->Dump();
}
bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override;
void Restore(uint8_t* data) override;
uint8_t GetSpatialLayer() const override;
uint8_t GetTemporalLayer() const override;
bool IsKeyFrame() const override;
uint8_t GetSpatialLayer() 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:
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 RTC
......
......@@ -99,12 +99,18 @@ namespace RTC
class EncodingContext : public RTC::Codecs::EncodingContext
{
public:
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params);
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
~EncodingContext() = default;
/* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */
public:
void SyncRequired() override;
void SyncRequired() override
{
this->syncRequired = true;
}
public:
RTC::SeqManager<uint16_t> pictureIdManager;
......@@ -118,51 +124,29 @@ namespace RTC
~PayloadDescriptorHandler() = default;
public:
void Dump() const override;
void Dump() const override
{
this->payloadDescriptor->Dump();
}
bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override;
void Restore(uint8_t* data) override;
uint8_t GetSpatialLayer() const override;
uint8_t GetTemporalLayer() const override;
bool IsKeyFrame() const override;
uint8_t GetSpatialLayer() 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:
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 RTC
......
......@@ -67,18 +67,60 @@ namespace RTC
virtual void FillJsonStats(json& jsonArray) const = 0;
virtual void FillJsonScore(json& jsonObject) const = 0;
virtual void HandleRequest(Channel::Request* request);
RTC::Media::Kind GetKind() const;
const RTC::RtpParameters& GetRtpParameters() const;
const struct RTC::RtpHeaderExtensionIds& GetRtpHeaderExtensionIds() const;
RTC::RtpParameters::Type GetType() const;
virtual Layers GetPreferredLayers() const;
const std::vector<uint32_t>& GetMediaSsrcs() const;
const std::vector<uint32_t>& GetRtxSsrcs() const;
virtual bool IsActive() const;
RTC::Media::Kind GetKind() const
{
return this->kind;
}
const RTC::RtpParameters& GetRtpParameters() const
{
return this->rtpParameters;
}
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 TransportDisconnected();
bool IsPaused() const;
bool IsProducerPaused() const;
bool IsPaused() const
{
return this->paused;
}
bool IsProducerPaused() const
{
return this->producerPaused;
}
void ProducerPaused();
void ProducerResumed();
virtual void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) = 0;
......@@ -87,7 +129,10 @@ namespace RTC
RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) = 0;
virtual void ProducerRtcpSenderReport(RTC::RtpStream* rtpStream, bool first) = 0;
void ProducerClosed();
void SetExternallyManagedBitrate();
void SetExternallyManagedBitrate()
{
this->externallyManagedBitrate = true;
}
virtual uint8_t GetBitratePriority() const = 0;
virtual uint32_t IncreaseLayer(uint32_t bitrate, bool considerLoss) = 0;
virtual void ApplyLayers() = 0;
......@@ -146,75 +191,6 @@ namespace RTC
bool producerPaused{ 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
#endif
......@@ -32,8 +32,20 @@ namespace RTC
void FillJson(json& jsonObject) const;
void FillJsonStats(json& jsonArray) const;
void HandleRequest(Channel::Request* request);
const RTC::SctpStreamParameters& GetSctpStreamParameters() const;
bool IsActive() const;
const RTC::SctpStreamParameters& GetSctpStreamParameters() const
{
return this->sctpStreamParameters;
}
bool IsActive() const
{
// clang-format off
return (
this->transportConnected &&
this->sctpAssociationConnected &&
!this->dataProducerClosed
);
// clang-format on
}
void TransportConnected();
void TransportDisconnected();
void SctpAssociationConnected();
......@@ -48,7 +60,7 @@ namespace RTC
private:
// Passed by argument.
RTC::DataConsumer::Listener* listener{ nullptr };
size_t maxSctpMessageSize{ 0 };
size_t maxSctpMessageSize{ 0u };
// Others.
RTC::SctpStreamParameters sctpStreamParameters;
std::string label;
......@@ -56,27 +68,9 @@ namespace RTC
bool transportConnected{ false };
bool sctpAssociationConnected{ false };
bool dataProducerClosed{ false };
size_t messagesSent{ 0 };
size_t bytesSent{ 0 };
size_t messagesSent{ 0u };
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
#endif
......@@ -27,7 +27,10 @@ namespace RTC
void FillJson(json& jsonObject) const;
void FillJsonStats(json& jsonArray) const;
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);
public:
......@@ -41,16 +44,9 @@ namespace RTC
RTC::SctpStreamParameters sctpStreamParameters;
std::string label;
std::string protocol;
size_t messagesReceived{ 0 };
size_t bytesReceived{ 0 };
size_t messagesReceived{ 0u };
size_t bytesReceived{ 0u };
};
/* Inline methods. */
inline const RTC::SctpStreamParameters& DataProducer::GetSctpStreamParameters() const
{
return this->sctpStreamParameters;
}
} // namespace RTC
#endif
......@@ -94,10 +94,41 @@ namespace RTC
public:
static void ClassInit();
static void ClassDestroy();
static Role StringToRole(const std::string& role);
static FingerprintAlgorithm GetFingerprintAlgorithm(const std::string& fingerprint);
static std::string& GetFingerprintAlgorithmString(FingerprintAlgorithm fingerprint);
static bool IsDtls(const uint8_t* data, size_t len);
static Role StringToRole(const std::string& role)
{
auto it = DtlsTransport::string2Role.find(role);
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:
static void GenerateCertificateAndPrivateKey();
......@@ -123,15 +154,40 @@ namespace RTC
public:
void Dump() const;
void Run(Role localRole);
std::vector<Fingerprint>& GetLocalFingerprints() const;
std::vector<Fingerprint>& GetLocalFingerprints() const
{
return DtlsTransport::localFingerprints;
}
bool SetRemoteFingerprint(Fingerprint fingerprint);
void ProcessDtlsData(const uint8_t* data, size_t len);
DtlsState GetState() const;
Role GetLocalRole() const;
DtlsState GetState() const
{
return this->state;
}
Role GetLocalRole() const
{
return this->localRole;
}
void SendApplicationData(const uint8_t* data, size_t len);
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();
bool CheckStatus(int returnCode);
void SendPendingOutgoingDtlsData();
......@@ -165,84 +221,6 @@ namespace RTC
bool handshakeDoneNow{ false };
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
#endif
......@@ -33,50 +33,44 @@ namespace RTC
};
public:
IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority);
IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority, std::string& announcedIp);
IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority);
IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority, std::string& announcedIp);
IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority)
: foundation("udpcandidate"), priority(priority), ip(udpSocket->GetLocalIp()),
protocol(Protocol::UDP), port(udpSocket->GetLocalPort()), type(CandidateType::HOST)
{
}
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;
private:
// Others.
std::string foundation;
uint32_t priority{ 0 };
uint32_t priority{ 0u };
std::string ip;
Protocol protocol;
uint16_t port{ 0 };
uint16_t port{ 0u };
CandidateType type{ CandidateType::HOST };
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
#endif
......@@ -45,12 +45,32 @@ namespace RTC
public:
void ProcessStunPacket(RTC::StunPacket* packet, RTC::TransportTuple* tuple);
const std::string& GetUsernameFragment() const;
const std::string& GetPassword() const;
IceState GetState() const;
RTC::TransportTuple* GetSelectedTuple() const;
void SetUsernameFragment(const std::string& usernameFragment);
void SetPassword(const std::string& password);
const std::string& GetUsernameFragment() const
{
return this->usernameFragment;
}
const std::string& GetPassword() const
{
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;
void RemoveTuple(RTC::TransportTuple* tuple);
// This should be just called in 'connected' or completed' state
......@@ -85,40 +105,6 @@ namespace RTC
std::list<RTC::TransportTuple> tuples;
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
#endif
......@@ -19,10 +19,22 @@ namespace RTC
PendingKeyFrameInfo(Listener* listener, uint32_t ssrc);
~PendingKeyFrameInfo();
uint32_t GetSsrc() const;
void SetRetryOnTimeout(bool notify);
bool GetRetryOnTimeout() const;
void Restart();
uint32_t GetSsrc() const
{
return this->ssrc;
}
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. */
public:
......@@ -48,9 +60,18 @@ namespace RTC
KeyFrameRequestDelayer(Listener* listener, uint32_t ssrc, uint32_t delay);
~KeyFrameRequestDelayer();
uint32_t GetSsrc() const;
bool GetKeyFrameRequested() const;
void SetKeyFrameRequested(bool flag);
uint32_t GetSsrc() const
{
return this->ssrc;
}
bool GetKeyFrameRequested() const
{
return this->keyFrameRequested;
}
void SetKeyFrameRequested(bool flag)
{
this->keyFrameRequested = flag;
}
/* Pure virtual methods inherited from Timer::Listener. */
public:
......@@ -97,39 +118,4 @@ 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
......@@ -25,7 +25,9 @@ namespace RTC
struct NackInfo
{
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 sendAtSeq{ 0u };
......@@ -44,8 +46,14 @@ namespace RTC
~NackGenerator() override;
bool ReceivePacket(RTC::RtpPacket* packet, bool isRecovered);
size_t GetNackListLength() const;
void UpdateRtt(uint32_t rtt);
size_t GetNackListLength() const
{
return this->nackList.size();
}
void UpdateRtt(uint32_t rtt)
{
this->rtt = rtt;
}
void Reset();
private:
......@@ -71,23 +79,6 @@ namespace RTC
uint16_t lastSeq{ 0u }; // Seq number of last valid packet.
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
#endif
......@@ -28,7 +28,10 @@ namespace RTC
uint32_t GetDesiredBitrate() const override;
void SendRtpPacket(RTC::RtpPacket* packet) 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 ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override;
void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType, uint32_t ssrc) override;
......@@ -58,13 +61,6 @@ namespace RTC
std::unordered_map<RTC::RtpStreamSend*, bool> mapRtpStreamSyncRequired;
std::unordered_map<RTC::RtpStreamSend*, RTC::SeqManager<uint16_t>> mapRtpStreamRtpSeqManager;
};
// Inline methods.
inline std::vector<RTC::RtpStreamSend*> PipeConsumer::GetRtpStreams()
{
return this->rtpStreams;
}
} // namespace RTC
#endif
......@@ -21,10 +21,22 @@ namespace RTC
};
public:
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);
static void UnbindTcp(std::string& ip, uint16_t port);
static uv_udp_t* BindUdp(std::string& ip)
{
return reinterpret_cast<uv_udp_t*>(Bind(Transport::UDP, ip));
}
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);
private:
......@@ -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>> 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
#endif
......@@ -90,12 +90,30 @@ namespace RTC
void FillJson(json& jsonObject) const;
void FillJsonStats(json& jsonArray) const;
void HandleRequest(Channel::Request* request);
RTC::Media::Kind GetKind() const;
const RTC::RtpParameters& GetRtpParameters() const;
const struct RTC::RtpHeaderExtensionIds& GetRtpHeaderExtensionIds() const;
RTC::RtpParameters::Type GetType() const;
bool IsPaused() const;
std::map<RTC::RtpStreamRecv*, uint32_t>& GetRtpStreams();
RTC::Media::Kind GetKind() const
{
return this->kind;
}
const RTC::RtpParameters& GetRtpParameters() const
{
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);
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void ReceiveRtcpXrDelaySinceLastRr(RTC::RTCP::DelaySinceLastRr::SsrcInfo* ssrcInfo);
......@@ -150,45 +168,13 @@ namespace RTC
bool paused{ false };
RTC::RtpPacket* currentRtpPacket{ nullptr };
// Timestamp when last RTCP was sent.
uint64_t lastRtcpSentTime{ 0 };
uint16_t maxRtcpInterval{ 0 };
uint64_t lastRtcpSentTime{ 0u };
uint16_t maxRtcpInterval{ 0u };
// Video orientation.
bool videoOrientationDetected{ false };
struct VideoOrientation videoOrientation;
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
#endif
......@@ -19,84 +19,64 @@ namespace RTC
static ByePacket* Parse(const uint8_t* data, size_t len);
public:
ByePacket();
explicit ByePacket(CommonHeader* commonHeader);
ByePacket() : Packet(Type::BYE)
{
}
explicit ByePacket(CommonHeader* commonHeader) : Packet(commonHeader)
{
}
~ByePacket() override = default;
void AddSsrc(uint32_t ssrc);
void SetReason(const std::string& reason);
const std::string& GetReason() const;
Iterator Begin();
Iterator End();
void AddSsrc(uint32_t ssrc)
{
this->ssrcs.push_back(ssrc);
}
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. */
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<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_t GetCount() const override
{
size += 1u; // Length field.
size += this->reason.length();
return this->ssrcs.size();
}
size_t GetSize() const override
{
size_t size = sizeof(Packet::CommonHeader);
// http://stackoverflow.com/questions/11642210/computing-padding-required-for-n-byte-alignment
// 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;
}
size += ssrcs.size() * 4u;
inline const std::string& ByePacket::GetReason() const
{
return this->reason;
}
if (!this->reason.empty())
{
size += 1u; // Length field.
size += this->reason.length();
}
inline ByePacket::Iterator ByePacket::Begin()
{
return this->ssrcs.begin();
}
// http://stackoverflow.com/questions/11642210/computing-padding-required-for-n-byte-alignment
// Consider pading to 32 bits (4 bytes) boundary.
return (size + 3) & ~3;
}
inline ByePacket::Iterator ByePacket::End()
{
return this->ssrcs.end();
}
private:
std::vector<uint32_t> ssrcs;
std::string reason;
};
} // namespace RTCP
} // namespace RTC
......
......@@ -18,17 +18,38 @@ namespace RTC
CompoundPacket() = default;
public:
const uint8_t* GetData() const;
size_t GetSize() const;
size_t GetSenderReportCount() const;
size_t GetReceiverReportCount() const;
const uint8_t* GetData() const
{
return this->header;
}
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 AddSenderReport(SenderReport* report);
void AddReceiverReport(ReceiverReport* report);
void AddSdesChunk(SdesChunk* chunk);
void AddReceiverReferenceTime(ReceiverReferenceTime* report);
bool HasSenderReport();
bool HasReceiverReferenceTime();
bool HasSenderReport()
{
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);
private:
......@@ -39,56 +60,6 @@ namespace RTC
SdesPacket sdesPacket;
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 RTC
......
......@@ -29,18 +29,39 @@ namespace RTC
static std::map<typename T::MessageType, std::string> type2String;
public:
typename T::MessageType GetMessageType() const;
uint32_t GetSenderSsrc() const;
void SetSenderSsrc(uint32_t ssrc);
uint32_t GetMediaSsrc() const;
void SetMediaSsrc(uint32_t ssrc);
typename T::MessageType GetMessageType() const
{
return this->messageType;
}
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. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override;
size_t GetSize() const override;
size_t GetCount() const override
{
return static_cast<size_t>(GetMessageType());
}
size_t GetSize() const override
{
return sizeof(CommonHeader) + sizeof(Header);
}
protected:
explicit FeedbackPacket(CommonHeader* commonHeader);
......@@ -92,50 +113,6 @@ namespace RTC
using FeedbackPsPacket = FeedbackPacket<RTC::RTCP::FeedbackPs>;
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 RTC
......
......@@ -11,17 +11,39 @@ namespace RTC
{
public:
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:
bool IsCorrect() const;
bool IsCorrect() const
{
return this->isCorrect;
}
protected:
virtual ~FeedbackItem();
virtual ~FeedbackItem()
{
delete[] this->raw;
}
public:
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 GetSize() const = 0;
......@@ -29,40 +51,6 @@ namespace RTC
uint8_t* raw{ nullptr };
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 RTC
......
......@@ -20,77 +20,53 @@ namespace RTC
public:
// Parsed Report. Points to an external data.
explicit FeedbackPsItemsPacket(CommonHeader* commonHeader);
explicit FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0);
~FeedbackPsItemsPacket();
explicit FeedbackPsItemsPacket(CommonHeader* commonHeader) : FeedbackPsPacket(commonHeader)
{
}
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);
Iterator Begin();
Iterator End();
void AddItem(Item* item)
{
this->items.push_back(item);
}
Iterator Begin()
{
return this->items.begin();
}
Iterator End()
{
return this->items.end();
}
/* Pure virtual methods inherited from Packet. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) 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)
size_t GetSize() const override
{
delete item;
}
}
size_t size = FeedbackPsPacket::GetSize();
template<typename Item>
inline size_t FeedbackPsItemsPacket<Item>::GetSize() const
{
size_t size = FeedbackPsPacket::GetSize();
for (auto* item : this->items)
{
size += item->GetSize();
}
for (auto* item : this->items)
{
size += item->GetSize();
return size;
}
return size;
}
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();
}
private:
std::vector<Item*> items;
};
} // namespace RTCP
} // namespace RTC
......
......@@ -23,54 +23,43 @@ namespace RTC
public:
// Parsed Report. Points to an external data.
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(
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;
Application GetApplication() const;
Application GetApplication() const
{
return this->application;
}
/* Pure virtual methods inherited from Packet. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
size_t GetSize() const override
{
return FeedbackPsPacket::GetSize() + this->size;
}
private:
Application application{ Application::UNKNOWN };
uint8_t* data{ nullptr };
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 RTC
......
......@@ -38,19 +38,32 @@ namespace RTC
static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::FIR };
public:
explicit FeedbackPsFirItem(Header* header);
explicit FeedbackPsFirItem(FeedbackPsFirItem* item);
explicit FeedbackPsFirItem(Header* header) : header(header)
{
}
explicit FeedbackPsFirItem(FeedbackPsFirItem* item) : header(item->header)
{
}
FeedbackPsFirItem(uint32_t ssrc, uint8_t sequenceNumber);
~FeedbackPsFirItem() override = default;
uint32_t GetSsrc() const;
uint8_t GetSequenceNumber() const;
uint32_t GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
uint8_t GetSequenceNumber() const
{
return this->header->sequenceNumber;
}
/* Virtual methods inherited from FeedbackItem. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
size_t GetSize() const override
{
return sizeof(Header);
}
private:
Header* header{ nullptr };
......@@ -58,31 +71,6 @@ namespace RTC
// Fir packet declaration.
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 RTC
......
......@@ -29,18 +29,28 @@ namespace RTC
static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::PSLEI };
public:
explicit FeedbackPsLeiItem(Header* header);
explicit FeedbackPsLeiItem(FeedbackPsLeiItem* item);
explicit FeedbackPsLeiItem(Header* header) : header(header)
{
}
explicit FeedbackPsLeiItem(FeedbackPsLeiItem* item) : header(item->header)
{
}
explicit FeedbackPsLeiItem(uint32_t ssrc);
~FeedbackPsLeiItem() override = default;
uint32_t GetSsrc() const;
uint32_t GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
/* Virtual methods inherited from FeedbackItem. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
size_t GetSize() const override
{
return sizeof(Header);
}
private:
Header* header{ nullptr };
......@@ -48,26 +58,6 @@ namespace RTC
// Lei packet declaration.
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 RTC
......
......@@ -15,25 +15,18 @@ namespace RTC
public:
// Parsed Report. Points to an external data.
explicit FeedbackPsPliPacket(CommonHeader* commonHeader);
FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc);
explicit FeedbackPsPliPacket(CommonHeader* commonHeader) : FeedbackPsPacket(commonHeader)
{
}
FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackPsPacket(FeedbackPs::MessageType::PLI, senderSsrc, mediaSsrc)
{
}
~FeedbackPsPliPacket() override = default;
public:
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 RTC
......
......@@ -40,21 +40,42 @@ namespace RTC
public:
// 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() override = default;
bool IsCorrect();
void SetBitrate(uint64_t bitrate);
void SetSsrcs(const std::vector<uint32_t>& ssrcs);
uint64_t GetBitrate();
const std::vector<uint32_t>& GetSsrcs();
bool IsCorrect() const
{
return this->isCorrect;
}
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. */
public:
void Dump() const 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:
std::vector<uint32_t> ssrcs;
......@@ -62,43 +83,6 @@ namespace RTC
uint64_t bitrate{ 0 };
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 RTC
......
......@@ -40,20 +40,37 @@ namespace RTC
public:
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() override = default;
bool IsCorrect() const;
uint8_t GetPayloadType() const;
uint8_t* GetBitString() const;
size_t GetLength() const;
bool IsCorrect() const
{
return this->isCorrect;
}
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. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
size_t GetSize() const override
{
return sizeof(Header);
}
private:
Header* header{ nullptr };
......@@ -62,37 +79,6 @@ namespace RTC
// Rpsi packet declaration.
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 RTC
......
......@@ -34,18 +34,39 @@ namespace RTC
FeedbackPsSliItem(uint16_t first, uint16_t number, uint8_t pictureId);
~FeedbackPsSliItem() override = default;
uint16_t GetFirst() const;
void SetFirst(uint16_t first);
uint16_t GetNumber() const;
void SetNumber(uint16_t number);
uint8_t GetPictureId() const;
void SetPictureId(uint8_t pictureId);
uint16_t GetFirst() const
{
return this->first;
}
void SetFirst(uint16_t first)
{
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. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
size_t GetSize() const override
{
return sizeof(Header);
}
private:
Header* header{ nullptr };
......@@ -56,43 +77,6 @@ namespace RTC
// Sli packet declaration.
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 RTC
......
......@@ -37,20 +37,36 @@ namespace RTC
static const FeedbackPs::MessageType messageType;
public:
explicit FeedbackPsTstItem(Header* header);
explicit FeedbackPsTstItem(FeedbackPsTstItem* item);
explicit FeedbackPsTstItem(Header* header) : header(header)
{
}
explicit FeedbackPsTstItem(FeedbackPsTstItem* item) : header(item->header)
{
}
FeedbackPsTstItem(uint32_t ssrc, uint8_t sequenceNumber, uint8_t index);
~FeedbackPsTstItem() override = default;
uint32_t GetSsrc() const;
uint8_t GetSequenceNumber() const;
uint8_t GetIndex() const;
uint32_t GetSsrc() 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. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
size_t GetSize() const override
{
return sizeof(Header);
}
private:
Header* header{ nullptr };
......@@ -71,42 +87,6 @@ namespace RTC
// Tst packets declaration.
using FeedbackPsTstrPacket = FeedbackPsItemsPacket<FeedbackPsTstrItem>;
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 RTC
......
......@@ -40,23 +40,48 @@ namespace RTC
static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::FIR };
public:
explicit FeedbackPsVbcmItem(Header* header);
explicit FeedbackPsVbcmItem(FeedbackPsVbcmItem* item);
explicit FeedbackPsVbcmItem(Header* header) : header(header)
{
}
explicit FeedbackPsVbcmItem(FeedbackPsVbcmItem* item) : header(item->header)
{
}
FeedbackPsVbcmItem(
uint32_t ssrc, uint8_t sequenceNumber, uint8_t payloadType, uint16_t length, uint8_t* value);
~FeedbackPsVbcmItem() override = default;
uint32_t GetSsrc() const;
uint8_t GetSequenceNumber() const;
uint8_t GetPayloadType() const;
uint16_t GetLength() const;
uint8_t* GetValue() const;
uint32_t GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
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. */
public:
void Dump() const 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:
Header* header{ nullptr };
......@@ -64,49 +89,6 @@ namespace RTC
// Vbcm packet declaration.
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 RTC
......
......@@ -20,77 +20,53 @@ namespace RTC
public:
// Parsed Report. Points to an external data.
explicit FeedbackRtpItemsPacket(CommonHeader* commonHeader);
explicit FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0);
~FeedbackRtpItemsPacket();
explicit FeedbackRtpItemsPacket(CommonHeader* commonHeader) : FeedbackRtpPacket(commonHeader)
{
}
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);
Iterator Begin();
Iterator End();
void AddItem(Item* item)
{
this->items.push_back(item);
}
Iterator Begin()
{
return this->items.begin();
}
Iterator End()
{
return this->items.end();
}
/* Virtual methods inherited from FeedbackItem. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) 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)
size_t GetSize() const override
{
delete item;
}
}
size_t size = FeedbackRtpPacket::GetSize();
template<typename Item>
inline size_t FeedbackRtpItemsPacket<Item>::GetSize() const
{
size_t size = FeedbackRtpPacket::GetSize();
for (auto* item : this->items)
{
size += item->GetSize();
}
for (auto* item : this->items)
{
size += item->GetSize();
return size;
}
return size;
}
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();
}
private:
std::vector<Item*> items;
};
} // namespace RTCP
} // namespace RTC
......
......@@ -45,23 +45,51 @@ namespace RTC
static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::ECN };
public:
explicit FeedbackRtpEcnItem(Header* header);
explicit FeedbackRtpEcnItem(FeedbackRtpEcnItem* item);
explicit FeedbackRtpEcnItem(Header* header) : header(header)
{
}
explicit FeedbackRtpEcnItem(FeedbackRtpEcnItem* item) : header(item->header)
{
}
~FeedbackRtpEcnItem() override = default;
uint32_t GetSequenceNumber() const;
uint32_t GetEct0Counter() const;
uint32_t GetEct1Counter() const;
uint16_t GetEcnCeCounter() const;
uint16_t GetNotEctCounter() const;
uint16_t GetLostPackets() const;
uint16_t GetDuplicatedPackets() const;
uint32_t GetSequenceNumber() const
{
return uint32_t{ ntohl(this->header->sequenceNumber) };
}
uint32_t GetEct0Counter() 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. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
size_t GetSize() const override
{
return sizeof(Header);
}
private:
Header* header{ nullptr };
......@@ -69,56 +97,6 @@ namespace RTC
// Ecn packet declaration.
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 RTC
......
......@@ -31,20 +31,36 @@ namespace RTC
static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::NACK };
public:
explicit FeedbackRtpNackItem(Header* header);
explicit FeedbackRtpNackItem(FeedbackRtpNackItem* item);
explicit FeedbackRtpNackItem(Header* header) : header(header)
{
}
explicit FeedbackRtpNackItem(FeedbackRtpNackItem* item) : header(item->header)
{
}
FeedbackRtpNackItem(uint16_t packetId, uint16_t lostPacketBitmask);
~FeedbackRtpNackItem() override = default;
uint16_t GetPacketId() const;
uint16_t GetLostPacketBitmask() const;
size_t CountRequestedPackets() const;
uint16_t GetPacketId() 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. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
size_t GetSize() const override
{
return sizeof(Header);
}
private:
Header* header{ nullptr };
......@@ -52,37 +68,6 @@ namespace RTC
// Nack packet declaration.
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 RTC
......
......@@ -15,24 +15,17 @@ namespace RTC
public:
// Parsed Report. Points to an external data.
explicit FeedbackRtpSrReqPacket(CommonHeader* commonHeader);
FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc);
explicit FeedbackRtpSrReqPacket(CommonHeader* commonHeader) : FeedbackRtpPacket(commonHeader)
{
}
FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackRtpPacket(FeedbackRtp::MessageType::SR_REQ, senderSsrc, mediaSsrc)
{
}
~FeedbackRtpSrReqPacket() override = default;
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 RTC
......
......@@ -30,19 +30,32 @@ namespace RTC
static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::TLLEI };
public:
explicit FeedbackRtpTlleiItem(Header* header);
explicit FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item);
explicit FeedbackRtpTlleiItem(Header* header) : header(header)
{
}
explicit FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item) : header(item->header)
{
}
FeedbackRtpTlleiItem(uint16_t packetId, uint16_t lostPacketBitmask);
~FeedbackRtpTlleiItem() override = default;
uint16_t GetPacketId() const;
uint16_t GetLostPacketBitmask() const;
uint16_t GetPacketId() const
{
return uint16_t{ ntohs(this->header->packetId) };
}
uint16_t GetLostPacketBitmask() const
{
return uint16_t{ ntohs(this->header->lostPacketBitmask) };
}
/* Virtual methods inherited from FeedbackItem. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
size_t GetSize() const override
{
return sizeof(Header);
}
private:
Header* header{ nullptr };
......@@ -50,32 +63,6 @@ namespace RTC
// Tllei packet declaration.
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 RTC
......
......@@ -34,23 +34,44 @@ namespace RTC
static const FeedbackRtp::MessageType messageType;
public:
FeedbackRtpTmmbItem() = default;
explicit FeedbackRtpTmmbItem(const uint8_t* data);
explicit FeedbackRtpTmmbItem(const Header* header);
FeedbackRtpTmmbItem();
~FeedbackRtpTmmbItem() override = default;
uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc);
uint64_t GetBitrate() const;
void SetBitrate(uint64_t bitrate);
uint16_t GetOverhead() const;
void SetOverhead(uint16_t overhead);
uint32_t GetSsrc() const
{
return this->ssrc;
}
void SetSsrc(uint32_t ssrc)
{
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. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
size_t GetSize() const override
{
return sizeof(Header);
}
private:
uint32_t ssrc{ 0 };
......@@ -73,53 +94,6 @@ namespace RTC
// Tmmbn packets declaration.
using FeedbackRtpTmmbrPacket = FeedbackRtpItemsPacket<FeedbackRtpTmmbrItem>;
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 RTC
......
......@@ -105,15 +105,23 @@ namespace RTC
class RunLengthChunk : public Chunk
{
public:
RunLengthChunk(Status status, uint16_t count);
RunLengthChunk(Status status, uint16_t count) : status(status), count(count)
{
}
explicit RunLengthChunk(uint16_t buffer);
public:
bool AddDeltas(
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;
uint16_t GetCount() const override;
uint16_t GetCount() const override
{
return this->count;
}
uint16_t GetReceivedStatusCount() const override;
void FillResults(
std::vector<struct PacketResult>& packetResults,
......@@ -129,14 +137,19 @@ namespace RTC
class OneBitVectorChunk : public Chunk
{
public:
explicit OneBitVectorChunk(const std::vector<Status>& statuses);
explicit OneBitVectorChunk(const std::vector<Status>& statuses) : statuses(statuses)
{
}
OneBitVectorChunk(uint16_t buffer, uint16_t count);
public:
bool AddDeltas(
const uint8_t* data, size_t len, std::vector<int16_t>& deltas, size_t& offset) override;
void Dump() const override;
uint16_t GetCount() const override;
uint16_t GetCount() const override
{
return this->statuses.size();
}
uint16_t GetReceivedStatusCount() const override;
void FillResults(
std::vector<struct PacketResult>& packetResults,
......@@ -151,14 +164,19 @@ namespace RTC
class TwoBitVectorChunk : public Chunk
{
public:
explicit TwoBitVectorChunk(const std::vector<Status>& statuses);
explicit TwoBitVectorChunk(const std::vector<Status>& statuses) : statuses(statuses)
{
}
TwoBitVectorChunk(uint16_t buffer, uint16_t count);
public:
bool AddDeltas(
const uint8_t* data, size_t len, std::vector<int16_t>& deltas, size_t& offset) override;
void Dump() const override;
uint16_t GetCount() const override;
uint16_t GetCount() const override
{
return this->statuses.size();
}
uint16_t GetReceivedStatusCount() const override;
void FillResults(
std::vector<struct PacketResult>& packetResults,
......@@ -182,24 +200,63 @@ namespace RTC
static std::map<Status, std::string> status2String;
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();
public:
AddPacketResult AddPacket(uint16_t sequenceNumber, uint64_t timestamp, size_t maxRtcpPacketLen);
void Finish(); // Just for locally generated packets.
bool IsFull();
bool IsSerializable();
bool IsCorrect(); // Just for locally generated packets.
uint16_t GetBaseSequenceNumber() const;
uint16_t GetPacketStatusCount() const;
int32_t GetReferenceTime() const;
int64_t GetReferenceTimestamp() const; // Reference time in ms.
uint8_t GetFeedbackPacketCount() const;
void SetFeedbackPacketCount(uint8_t count);
uint16_t GetLatestSequenceNumber() const; // Just for locally generated packets.
uint64_t GetLatestTimestamp() const; // Just for locally generated packets.
bool 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;
}
bool IsSerializable() const
{
return this->deltas.size() > 0;
}
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;
uint8_t GetPacketFractionLost() const;
......@@ -207,7 +264,22 @@ namespace RTC
public:
void Dump() const 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:
void FillChunk(uint16_t previousSequenceNumber, uint16_t sequenceNumber, int16_t delta);
......@@ -230,125 +302,6 @@ namespace RTC
size_t size{ 0 };
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 RTC
......
......@@ -49,7 +49,24 @@ namespace RTC
};
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 const std::string& Type2String(Type type);
......@@ -57,86 +74,47 @@ namespace RTC
static std::map<Type, std::string> type2String;
public:
explicit Packet(Type type);
explicit Packet(CommonHeader* commonHeader);
virtual ~Packet();
explicit Packet(Type type) : type(type)
{
}
explicit Packet(CommonHeader* commonHeader)
{
this->type = RTCP::Type(commonHeader->packetType);
this->header = commonHeader;
}
virtual ~Packet() = default;
void SetNext(Packet* packet);
Packet* GetNext() const;
const uint8_t* GetData() const;
void SetNext(Packet* packet)
{
this->next = packet;
}
Packet* GetNext() const
{
return this->next;
}
const uint8_t* GetData() const
{
return reinterpret_cast<uint8_t*>(this->header);
}
public:
virtual void Dump() const = 0;
virtual size_t Serialize(uint8_t* buffer) = 0;
virtual Type GetType() const;
virtual size_t GetCount() const = 0;
virtual size_t GetSize() const = 0;
virtual Type GetType() const
{
return this->type;
}
virtual size_t GetCount() const
{
return 0u;
}
virtual size_t GetSize() const = 0;
private:
Type type;
Packet* next{ 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 RTC
......
......@@ -29,29 +29,97 @@ namespace RTC
static ReceiverReport* Parse(const uint8_t* data, size_t len);
public:
// Parsed Report. Points to an external data.
explicit ReceiverReport(Header* header);
explicit ReceiverReport(ReceiverReport* report);
// 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;
size_t Serialize(uint8_t* buffer);
size_t GetSize() const;
uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc);
uint8_t GetFractionLost() const;
void SetFractionLost(uint8_t fractionLost);
int32_t GetTotalLost() const;
void SetTotalLost(int32_t totalLost);
uint32_t GetLastSeq() const;
void SetLastSeq(uint32_t lastSeq);
uint32_t GetJitter() const;
void SetJitter(uint32_t jitter);
uint32_t GetLastSenderReport() const;
void SetLastSenderReport(uint32_t lsr);
uint32_t GetDelaySinceLastSenderReport() const;
void SetDelaySinceLastSenderReport(uint32_t dlsr);
size_t GetSize() const
{
return sizeof(Header);
}
uint32_t GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
void SetSsrc(uint32_t ssrc)
{
this->header->ssrc = uint32_t{ htonl(ssrc) };
}
uint8_t GetFractionLost() const
{
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:
Header* header{ nullptr };
......@@ -67,203 +135,74 @@ namespace RTC
static ReceiverReportPacket* Parse(const uint8_t* data, size_t len, size_t offset = 0);
public:
ReceiverReportPacket();
explicit ReceiverReportPacket(CommonHeader* commonHeader);
~ReceiverReportPacket() override;
ReceiverReportPacket() : Packet(Type::RR)
{
}
explicit ReceiverReportPacket(CommonHeader* commonHeader) : Packet(commonHeader)
{
}
~ReceiverReportPacket() override
{
for (auto* report : this->reports)
{
delete report;
}
}
uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc);
void AddReport(ReceiverReport* report);
Iterator Begin();
Iterator End();
uint32_t GetSsrc() const
{
return this->ssrc;
}
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. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
Type GetType() const override;
size_t GetCount() const override;
size_t GetSize() const override;
private:
// 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)
// 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.
Type GetType() const override
{
delete report;
return Type::RR;
}
}
// 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_t GetCount() const override
{
size += report->GetSize();
return this->reports.size();
}
size_t GetSize() const override
{
size_t size = sizeof(Packet::CommonHeader) + 4u /* this->ssrc */;
return size;
}
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);
}
for (auto* report : reports)
{
size += report->GetSize();
}
inline ReceiverReportPacket::Iterator ReceiverReportPacket::Begin()
{
return this->reports.begin();
}
return size;
}
inline ReceiverReportPacket::Iterator ReceiverReportPacket::End()
{
return this->reports.end();
}
private:
// SSRC of packet sender.
uint32_t ssrc{ 0u };
std::vector<ReceiverReport*> reports;
};
} // namespace RTCP
} // namespace RTC
......
......@@ -41,18 +41,34 @@ namespace RTC
static const std::string& Type2String(SdesItem::Type type);
public:
explicit SdesItem(Header* header);
explicit SdesItem(SdesItem* item);
explicit SdesItem(Header* header) : header(header)
{
}
explicit SdesItem(SdesItem* item) : header(item->header)
{
}
SdesItem(SdesItem::Type type, size_t len, const char* value);
~SdesItem() = default;
void Dump() const;
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;
uint8_t GetLength() const;
char* GetValue() const;
SdesItem::Type GetType() const
{
return this->header->type;
}
uint8_t GetLength() const
{
return this->header->length;
}
char* GetValue() const
{
return this->header->value;
}
private:
// Passed by argument.
......@@ -72,19 +88,63 @@ namespace RTC
static SdesChunk* Parse(const uint8_t* data, size_t len);
public:
explicit SdesChunk(uint32_t ssrc);
explicit SdesChunk(SdesChunk* chunk);
~SdesChunk();
explicit SdesChunk(uint32_t ssrc)
{
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 Serialize();
size_t Serialize(uint8_t* buffer);
size_t GetSize() const;
uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc);
void AddItem(SdesItem* item);
Iterator Begin();
Iterator End();
size_t GetSize() const
{
size_t size = 4u /*ssrc*/;
for (auto* item : this->items)
{
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:
uint32_t ssrc{ 0u };
......@@ -100,168 +160,56 @@ namespace RTC
static SdesPacket* Parse(const uint8_t* data, size_t len);
public:
SdesPacket();
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)
SdesPacket() : Packet(RTCP::Type::SDES)
{
this->AddItem(new SdesItem(*it));
}
}
inline SdesChunk::~SdesChunk()
{
for (auto* item : this->items)
explicit SdesPacket(CommonHeader* commonHeader) : Packet(commonHeader)
{
delete item;
}
}
inline size_t SdesChunk::GetSize() const
{
size_t size = 4u /*ssrc*/;
for (auto* item : this->items)
~SdesPacket() override
{
size += item->GetSize();
for (auto* chunk : this->chunks)
{
delete chunk;
}
}
// Consider pading to 32 bits (4 bytes) boundary.
// 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)
void AddChunk(SdesChunk* chunk)
{
delete chunk;
this->chunks.push_back(chunk);
}
}
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)
Iterator Begin()
{
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)
{
this->chunks.push_back(chunk);
}
for (auto* chunk : this->chunks)
{
size += chunk->GetSize();
}
inline SdesPacket::Iterator SdesPacket::Begin()
{
return this->chunks.begin();
}
return size;
}
inline SdesPacket::Iterator SdesPacket::End()
{
return this->chunks.end();
}
private:
std::vector<SdesChunk*> chunks;
};
} // namespace RTCP
} // namespace RTC
......
......@@ -27,27 +27,73 @@ namespace RTC
static SenderReport* Parse(const uint8_t* data, size_t len);
public:
// Parsed Report. Points to an external data.
explicit SenderReport(Header* header);
explicit SenderReport(SenderReport* report);
// 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;
size_t Serialize(uint8_t* buffer);
size_t GetSize() const;
uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc);
uint32_t GetNtpSec() const;
void SetNtpSec(uint32_t ntpSec);
uint32_t GetNtpFrac() const;
void SetNtpFrac(uint32_t ntpFrac);
uint32_t GetRtpTs() const;
void SetRtpTs(uint32_t rtpTs);
uint32_t GetPacketCount() const;
void SetPacketCount(uint32_t packetCount);
uint32_t GetOctetCount() const;
void SetOctetCount(uint32_t octetCount);
size_t GetSize() const
{
return sizeof(Header);
}
uint32_t GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
void SetSsrc(uint32_t ssrc)
{
this->header->ssrc = uint32_t{ htonl(ssrc) };
}
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:
Header* header{ nullptr };
......@@ -63,154 +109,56 @@ namespace RTC
static SenderReportPacket* Parse(const uint8_t* data, size_t len);
public:
SenderReportPacket();
explicit SenderReportPacket(CommonHeader* commonHeader);
~SenderReportPacket() override;
SenderReportPacket() : Packet(Type::SR)
{
}
explicit SenderReportPacket(CommonHeader* commonHeader) : Packet(commonHeader)
{
}
~SenderReportPacket() override
{
for (auto* report : this->reports)
{
delete report;
}
}
void AddReport(SenderReport* report);
Iterator Begin();
Iterator End();
void AddReport(SenderReport* report)
{
this->reports.push_back(report);
}
Iterator Begin()
{
return this->reports.begin();
}
Iterator End()
{
return this->reports.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<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)
size_t GetCount() const override
{
delete report;
return 0;
}
}
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_t GetSize() const override
{
size += report->GetSize();
}
return size;
}
size_t size = sizeof(Packet::CommonHeader);
inline void SenderReportPacket::AddReport(SenderReport* report)
{
this->reports.push_back(report);
}
for (auto* report : this->reports)
{
size += report->GetSize();
}
inline SenderReportPacket::Iterator SenderReportPacket::Begin()
{
return this->reports.begin();
}
return size;
}
inline SenderReportPacket::Iterator SenderReportPacket::End()
{
return this->reports.end();
}
private:
std::vector<SenderReport*> reports;
};
} // namespace RTCP
} // namespace RTC
......
......@@ -49,14 +49,22 @@ namespace RTC
static ExtendedReportBlock* Parse(const uint8_t* data, size_t len);
public:
ExtendedReportBlock(Type type);
ExtendedReportBlock(Type type) : type(type)
{
this->header = reinterpret_cast<CommonHeader*>(this->raw);
this->header->reserved = 0;
}
virtual ~ExtendedReportBlock() = default;
public:
virtual void Dump() const = 0;
virtual size_t Serialize(uint8_t* buffer) = 0;
virtual size_t GetSize() const = 0;
ExtendedReportBlock::Type GetType() const;
ExtendedReportBlock::Type GetType() const
{
return this->type;
}
protected:
Type type;
......@@ -75,102 +83,65 @@ namespace RTC
static ExtendedReportPacket* Parse(const uint8_t* data, size_t len);
public:
ExtendedReportPacket();
explicit ExtendedReportPacket(CommonHeader* commonHeader);
~ExtendedReportPacket() override;
ExtendedReportPacket() : Packet(Type::XR)
{
}
explicit ExtendedReportPacket(CommonHeader* commonHeader) : Packet(commonHeader)
{
}
~ExtendedReportPacket() override
{
for (auto* report : this->reports)
{
delete report;
}
}
void AddReport(ExtendedReportBlock* report);
uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc);
Iterator Begin();
Iterator End();
void AddReport(ExtendedReportBlock* report)
{
this->reports.push_back(report);
}
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. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) 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)
size_t GetCount() const override
{
delete report;
return 0;
}
}
inline ExtendedReportPacket::Iterator ExtendedReportPacket::Begin()
{
return this->reports.begin();
}
inline ExtendedReportPacket::Iterator ExtendedReportPacket::End()
{
return this->reports.end();
}
inline size_t ExtendedReportPacket::GetCount() const
{
return 0;
}
size_t GetSize() const override
{
size_t size = sizeof(Packet::CommonHeader) + 4u /*ssrc*/;
inline size_t ExtendedReportPacket::GetSize() const
{
size_t size = sizeof(Packet::CommonHeader) + 4u /*ssrc*/;
for (auto* report : this->reports)
{
size += report->GetSize();
}
for (auto* report : this->reports)
{
size += report->GetSize();
return size;
}
return size;
}
private:
uint32_t ssrc{ 0u };
std::vector<ExtendedReportBlock*> reports;
};
} // namespace RTCP
} // namespace RTC
......
......@@ -47,21 +47,46 @@ namespace RTC
};
public:
// Parsed Report. Points to an external data.
explicit SsrcInfo(Body* body);
// 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;
size_t Serialize(uint8_t* buffer);
size_t GetSize() const;
uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc);
uint32_t GetLastReceiverReport() const;
void SetLastReceiverReport(uint32_t lrr);
uint32_t GetDelaySinceLastReceiverReport() const;
void SetDelaySinceLastReceiverReport(uint32_t dlrr);
size_t GetSize() const
{
return sizeof(Body);
}
uint32_t GetSsrc() const
{
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:
Body* body{ nullptr };
......@@ -72,118 +97,55 @@ namespace RTC
using Iterator = std::vector<SsrcInfo*>::iterator;
public:
explicit DelaySinceLastRr(CommonHeader* header);
DelaySinceLastRr();
~DelaySinceLastRr();
DelaySinceLastRr() : ExtendedReportBlock(ExtendedReportBlock::Type::DLRR)
{
}
explicit DelaySinceLastRr(CommonHeader* header)
: ExtendedReportBlock(ExtendedReportBlock::Type::DLRR)
{
this->header = header;
}
~DelaySinceLastRr()
{
for (auto* ssrcInfo : this->ssrcInfos)
{
delete ssrcInfo;
}
}
public:
void AddSsrcInfo(SsrcInfo* ssrcInfo);
Iterator Begin();
Iterator End();
void AddSsrcInfo(SsrcInfo* ssrcInfo)
{
this->ssrcInfos.push_back(ssrcInfo);
}
Iterator Begin()
{
return this->ssrcInfos.begin();
}
Iterator End()
{
return this->ssrcInfos.end();
}
/* Pure virtual methods inherited from ExtendedReportBlock. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) 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)
virtual size_t GetSize() const override
{
delete ssrcInfo;
}
}
inline void DelaySinceLastRr::AddSsrcInfo(SsrcInfo* ssrcInfo)
{
this->ssrcInfos.push_back(ssrcInfo);
}
inline DelaySinceLastRr::Iterator DelaySinceLastRr::Begin()
{
return this->ssrcInfos.begin();
}
size_t size{ 4u }; // Common header.
inline DelaySinceLastRr::Iterator DelaySinceLastRr::End()
{
return this->ssrcInfos.end();
}
inline size_t DelaySinceLastRr::GetSize() const
{
size_t size{ 4 }; // Common header.
for (auto* ssrcInfo : this->ssrcInfos)
{
size += ssrcInfo->GetSize();
}
for (auto* ssrcInfo : this->ssrcInfos)
{
size += ssrcInfo->GetSize();
return size;
}
return size;
}
private:
std::vector<SsrcInfo*> ssrcInfos;
};
} // namespace RTCP
} // namespace RTC
......
......@@ -34,71 +34,54 @@ namespace RTC
static ReceiverReferenceTime* Parse(const uint8_t* data, size_t len);
public:
// Parsed Report. Points to an external data.
explicit ReceiverReferenceTime(CommonHeader* header);
// 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:
uint32_t GetNtpSec() const;
void SetNtpSec(uint32_t ntpSec);
uint32_t GetNtpFrac() const;
void SetNtpFrac(uint32_t ntpFrac);
uint32_t GetNtpSec() const
{
return uint32_t{ ntohl(this->body->ntpSec) };
}
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. */
public:
virtual void Dump() const 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:
Body* body{ nullptr };
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 RTC
......
......@@ -12,24 +12,44 @@ namespace RTC
class RateCalculator
{
public:
static constexpr size_t DefaultWindowSize{ 1000 };
static constexpr size_t DefaultWindowSize{ 1000u };
static constexpr float DefaultBpsScale{ 8000.0f };
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);
uint32_t GetRate(uint64_t nowMs);
size_t GetBytes() const;
void Reset();
size_t GetBytes() const
{
return this->bytes;
}
void Reset()
{
uint64_t nowMs = DepLibUV::GetTimeMs();
Reset(nowMs);
}
private:
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:
struct BufferItem
{
size_t count{ 0 };
size_t count{ 0u };
};
private:
......@@ -40,85 +60,45 @@ namespace RTC
// Buffer to keep data.
std::unique_ptr<BufferItem[]> buffer;
// 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.
uint32_t oldestIndex{ 0 };
uint32_t oldestIndex{ 0u };
// Total count in the time window.
size_t totalCount{ 0 };
size_t totalCount{ 0u };
// Total bytes transmitted.
size_t bytes{ 0 };
size_t bytes{ 0u };
// Last value calculated by GetRate().
uint32_t lastRate{ 0 };
uint32_t lastRate{ 0u };
// 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
{
public:
explicit RtpDataCounter(size_t windowSize = 2500);
explicit RtpDataCounter(size_t windowSize = 2500) : rate(windowSize)
{
}
public:
void Update(RTC::RtpPacket* packet);
uint32_t GetBitrate(uint64_t nowMs);
size_t GetPacketCount() const;
size_t GetBytes() const;
uint32_t GetBitrate(uint64_t nowMs)
{
return this->rate.GetRate(nowMs);
}
size_t GetPacketCount() const
{
return this->packets;
}
size_t GetBytes() const
{
return this->rate.GetBytes();
}
private:
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
#endif
......@@ -174,9 +174,9 @@ namespace RTC
public:
RtpCodecMimeType mimeType;
uint8_t payloadType{ 0 };
uint32_t clockRate{ 0 };
uint8_t channels{ 1 };
uint8_t payloadType{ 0u };
uint32_t clockRate{ 0u };
uint8_t channels{ 1u };
RTC::Parameters parameters;
std::vector<RtcpFeedback> rtcpFeedback;
};
......@@ -190,7 +190,7 @@ namespace RTC
void FillJson(json& jsonObject) const;
public:
uint32_t ssrc{ 0 };
uint32_t ssrc{ 0u };
};
class RtpEncodingParameters
......@@ -202,18 +202,18 @@ namespace RTC
void FillJson(json& jsonObject) const;
public:
uint32_t ssrc{ 0 };
uint32_t ssrc{ 0u };
std::string rid;
uint8_t codecPayloadType{ 0 };
uint8_t codecPayloadType{ 0u };
bool hasCodecPayloadType{ false };
RtpRtxParameters rtx;
bool hasRtx{ false };
uint32_t maxBitrate{ 0 };
uint32_t maxBitrate{ 0u };
double maxFramerate{ 0 };
bool dtx{ false };
std::string scalabilityMode;
uint8_t spatialLayers{ 1 };
uint8_t temporalLayers{ 1 };
uint8_t spatialLayers{ 1u };
uint8_t temporalLayers{ 1u };
bool ksvc{ false };
};
......@@ -228,7 +228,7 @@ namespace RTC
public:
std::string uri;
RtpHeaderExtensionUri::Type type;
uint8_t id{ 0 };
uint8_t id{ 0u };
bool encrypt{ false };
RTC::Parameters parameters;
};
......@@ -243,7 +243,7 @@ namespace RTC
public:
std::string cname;
uint32_t ssrc{ 0 };
uint32_t ssrc{ 0u };
bool reducedSize{ true };
};
......
......@@ -17,7 +17,10 @@ namespace RTC
public:
void Pause();
void Resume();
bool IsPaused() const;
bool IsPaused() const
{
return this->paused;
}
virtual void AddProducer(RTC::Producer* producer) = 0;
virtual void RemoveProducer(RTC::Producer* producer) = 0;
virtual void ReceiveRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) = 0;
......@@ -36,11 +39,6 @@ namespace RTC
// Others.
bool paused{ false };
};
inline bool RtpObserver::IsPaused() const
{
return this->paused;
}
} // namespace RTC
#endif
......@@ -114,7 +114,23 @@ namespace RTC
};
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);
private:
......@@ -130,545 +146,488 @@ namespace RTC
~RtpPacket();
void Dump() 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:
void ParseExtensions();
const uint8_t* GetData() const
{
return (const uint8_t*)this->header;
}
private:
// Passed by argument.
Header* header{ nullptr };
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;
};
size_t GetSize() const
{
return this->size;
}
/* Inline static methods. */
uint8_t GetPayloadType() const
{
return this->header->payloadType;
}
inline bool RtpPacket::IsRtp(const uint8_t* data, size_t len)
{
// NOTE: RtcpPacket::IsRtcp() must always be called before this method.
void SetPayloadType(uint8_t payloadType)
{
this->header->payloadType = payloadType;
}
auto header = const_cast<Header*>(reinterpret_cast<const Header*>(data));
bool HasMarker() const
{
return this->header->marker;
}
// 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
}
void SetMarker(bool marker)
{
this->header->marker = marker;
}
/* Inline instance methods. */
void SetPayloadPaddingFlag(bool flag)
{
this->header->padding = flag;
}
inline const uint8_t* RtpPacket::GetData() const
{
return (const uint8_t*)this->header;
}
uint16_t GetSequenceNumber() const
{
return uint16_t{ ntohs(this->header->sequenceNumber) };
}
inline size_t RtpPacket::GetSize() const
{
return this->size;
}
void SetSequenceNumber(uint16_t seq)
{
this->header->sequenceNumber = uint16_t{ htons(seq) };
}
inline uint8_t RtpPacket::GetPayloadType() const
{
return this->header->payloadType;
}
uint32_t GetTimestamp() const
{
return uint32_t{ ntohl(this->header->timestamp) };
}
inline void RtpPacket::SetPayloadType(uint8_t payloadType)
{
this->header->payloadType = payloadType;
}
void SetTimestamp(uint32_t timestamp)
{
this->header->timestamp = uint32_t{ htonl(timestamp) };
}
inline bool RtpPacket::HasMarker() const
{
return this->header->marker;
}
uint32_t GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
inline void RtpPacket::SetMarker(bool marker)
{
this->header->marker = marker;
}
void SetSsrc(uint32_t ssrc)
{
this->header->ssrc = uint32_t{ htonl(ssrc) };
}
inline void RtpPacket::SetPayloadPaddingFlag(bool flag)
{
this->header->padding = flag;
}
bool HasHeaderExtension() const
{
return (this->headerExtension ? true : false);
}
inline uint16_t RtpPacket::GetSequenceNumber() const
{
return uint16_t{ ntohs(this->header->sequenceNumber) };
}
// After calling this method, all the extension ids are reset to 0.
void SetExtensions(uint8_t type, const std::vector<GenericExtension>& extensions);
inline void RtpPacket::SetSequenceNumber(uint16_t seq)
{
this->header->sequenceNumber = uint16_t{ htons(seq) };
}
uint16_t GetHeaderExtensionId() const
{
if (!this->headerExtension)
return 0u;
inline uint32_t RtpPacket::GetTimestamp() const
{
return uint32_t{ ntohl(this->header->timestamp) };
}
return uint16_t{ ntohs(this->headerExtension->id) };
}
inline void RtpPacket::SetTimestamp(uint32_t timestamp)
{
this->header->timestamp = uint32_t{ htonl(timestamp) };
}
size_t GetHeaderExtensionLength() const
{
if (!this->headerExtension)
return 0u;
inline uint32_t RtpPacket::GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
return static_cast<size_t>(ntohs(this->headerExtension->length) * 4);
}
inline void RtpPacket::SetSsrc(uint32_t ssrc)
{
this->header->ssrc = uint32_t{ htonl(ssrc) };
}
uint8_t* GetHeaderExtensionValue() const
{
if (!this->headerExtension)
return nullptr;
inline bool RtpPacket::HasHeaderExtension() const
{
return (this->headerExtension ? true : false);
}
return this->headerExtension->value;
}
inline uint16_t RtpPacket::GetHeaderExtensionId() const
{
if (!this->headerExtension)
return 0u;
bool HasOneByteExtensions() const
{
return GetHeaderExtensionId() == 0xBEDE;
}
return uint16_t{ ntohs(this->headerExtension->id) };
}
bool HasTwoBytesExtensions() const
{
return (GetHeaderExtensionId() & 0b1111111111110000) == 0b0001000000000000;
}
inline size_t RtpPacket::GetHeaderExtensionLength() const
{
if (!this->headerExtension)
return 0u;
void SetMidExtensionId(uint8_t id)
{
this->midExtensionId = id;
}
return static_cast<size_t>(ntohs(this->headerExtension->length) * 4);
}
void SetRidExtensionId(uint8_t id)
{
this->ridExtensionId = id;
}
inline uint8_t* RtpPacket::GetHeaderExtensionValue() const
{
if (!this->headerExtension)
return nullptr;
void SetRepairedRidExtensionId(uint8_t id)
{
this->rridExtensionId = id;
}
return this->headerExtension->value;
}
void SetAbsSendTimeExtensionId(uint8_t id)
{
this->absSendTimeExtensionId = id;
}
inline bool RtpPacket::HasOneByteExtensions() const
{
return GetHeaderExtensionId() == 0xBEDE;
}
void SetTransportWideCc01ExtensionId(uint8_t id)
{
this->transportWideCc01ExtensionId = id;
}
inline bool RtpPacket::HasTwoBytesExtensions() const
{
return (GetHeaderExtensionId() & 0b1111111111110000) == 0b0001000000000000;
}
// NOTE: Remove once RFC.
void SetFrameMarking07ExtensionId(uint8_t id)
{
this->frameMarking07ExtensionId = id;
}
inline void RtpPacket::SetMidExtensionId(uint8_t id)
{
this->midExtensionId = id;
}
void SetFrameMarkingExtensionId(uint8_t id)
{
this->frameMarkingExtensionId = id;
}
inline void RtpPacket::SetRidExtensionId(uint8_t id)
{
this->ridExtensionId = id;
}
void SetSsrcAudioLevelExtensionId(uint8_t id)
{
this->ssrcAudioLevelExtensionId = id;
}
inline void RtpPacket::SetRepairedRidExtensionId(uint8_t id)
{
this->rridExtensionId = id;
}
void SetVideoOrientationExtensionId(uint8_t id)
{
this->videoOrientationExtensionId = id;
}
inline void RtpPacket::SetAbsSendTimeExtensionId(uint8_t id)
{
this->absSendTimeExtensionId = id;
}
bool ReadMid(std::string& mid) const
{
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->midExtensionId, extenLen);
inline void RtpPacket::SetTransportWideCc01ExtensionId(uint8_t id)
{
this->transportWideCc01ExtensionId = id;
}
if (!extenValue || extenLen == 0u)
return false;
// NOTE: Remove once RFC.
inline void RtpPacket::SetFrameMarking07ExtensionId(uint8_t id)
{
this->frameMarking07ExtensionId = id;
}
mid.assign(reinterpret_cast<const char*>(extenValue), static_cast<size_t>(extenLen));
inline void RtpPacket::SetFrameMarkingExtensionId(uint8_t id)
{
this->frameMarkingExtensionId = id;
}
return true;
}
inline void RtpPacket::SetSsrcAudioLevelExtensionId(uint8_t id)
{
this->ssrcAudioLevelExtensionId = id;
}
bool UpdateMid(const std::string& mid);
inline void RtpPacket::SetVideoOrientationExtensionId(uint8_t id)
{
this->videoOrientationExtensionId = id;
}
bool ReadRid(std::string& rid) const
{
// 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
{
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->midExtensionId, extenLen);
if (extenValue && extenLen > 0u)
{
rid.assign(reinterpret_cast<const char*>(extenValue), static_cast<size_t>(extenLen));
if (!extenValue || extenLen == 0u)
return false;
return true;
}
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
{
// First try with the RID id then with the Repaired RID id.
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->ridExtensionId, extenLen);
return true;
}
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;
}
extenValue = GetExtension(this->rridExtensionId, extenLen);
if (extenValue && extenLen > 0u)
bool UpdateAbsSendTime(uint64_t ms)
{
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 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
{
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->absSendTimeExtensionId, extenLen);
if (!extenValue || extenLen != 2u)
return false;
if (!extenValue || extenLen != 3u)
return false;
wideSeqNumber = Utils::Byte::Get2Bytes(extenValue, 0);
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)
{
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->absSendTimeExtensionId, extenLen);
if (!extenValue || extenLen != 2u)
return false;
if (!extenValue || extenLen != 3u)
return false;
Utils::Byte::Set2Bytes(extenValue, 0, wideSeqNumber);
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
{
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->transportWideCc01ExtensionId, extenLen);
*frameMarking = reinterpret_cast<RtpPacket::FrameMarking*>(extenValue);
length = extenLen;
if (!extenValue || extenLen != 2u)
return false;
return true;
}
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)
{
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->transportWideCc01ExtensionId, extenLen);
volume = Utils::Byte::Get1Byte(extenValue, 0);
voice = (volume & (1 << 7)) ? true : false;
volume &= ~(1 << 7);
if (!extenValue || extenLen != 2u)
return false;
return true;
}
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 extenLen;
uint8_t* extenValue = GetExtension(this->frameMarkingExtensionId, extenLen);
uint8_t cvoByte = Utils::Byte::Get1Byte(extenValue, 0);
uint8_t cameraValue = ((cvoByte & 0b00001000) >> 3);
uint8_t flipValue = ((cvoByte & 0b00000100) >> 2);
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.
if (!extenValue)
extenValue = GetExtension(this->frameMarking07ExtensionId, extenLen);
return true;
}
if (!extenValue || extenLen > 3u)
return false;
bool HasExtension(uint8_t id) const
{
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);
length = extenLen;
uint8_t* GetExtension(uint8_t id, uint8_t& len) const
{
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
{
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->ssrcAudioLevelExtensionId, extenLen);
if (it == this->mapOneByteExtensions.end())
return nullptr;
if (!extenValue || extenLen != 1u)
return false;
auto* extension = it->second;
volume = Utils::Byte::Get1Byte(extenValue, 0);
voice = (volume & (1 << 7)) ? true : false;
volume &= ~(1 << 7);
// In One-Byte extensions value length 0 means 1.
len = extension->len + 1;
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
{
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->videoOrientationExtensionId, extenLen);
if (it == this->mapTwoBytesExtensions.end())
return nullptr;
if (!extenValue || extenLen != 1u)
return false;
auto* extension = it->second;
uint8_t cvoByte = Utils::Byte::Get1Byte(extenValue, 0);
uint8_t cameraValue = ((cvoByte & 0b00001000) >> 3);
uint8_t flipValue = ((cvoByte & 0b00000100) >> 2);
uint8_t rotationValue = (cvoByte & 0b00000011);
len = extension->len;
camera = cameraValue ? true : false;
flip = flipValue ? true : false;
// In Two-Byte extensions value length may be zero. If so, return nullptr.
if (extension->len == 0u)
return nullptr;
// Using counter clockwise values.
switch (rotationValue)
{
case 3:
rotation = 270;
break;
case 2:
rotation = 180;
break;
case 1:
rotation = 90;
break;
default:
rotation = 0;
return extension->value;
}
else
{
return nullptr;
}
}
return true;
}
bool SetExtensionLength(uint8_t id, uint8_t len);
inline bool RtpPacket::HasExtension(uint8_t id) const
{
if (id == 0u)
uint8_t* GetPayload() const
{
return false;
return this->payloadLength != 0u ? this->payload : nullptr;
}
else if (HasOneByteExtensions())
{
auto it = this->mapOneByteExtensions.find(id);
return it != this->mapOneByteExtensions.end();
}
else if (HasTwoBytesExtensions())
size_t GetPayloadLength() const
{
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;
return this->payloadLength;
}
else
{
return false;
}
}
inline uint8_t* RtpPacket::GetExtension(uint8_t id, uint8_t& len) const
{
len = 0u;
void SetPayloadLength(size_t length);
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())
return nullptr;
uint8_t GetSpatialLayer() const
{
if (!this->payloadDescriptorHandler)
return 0u;
auto* extension = it->second;
return this->payloadDescriptorHandler->GetSpatialLayer();
}
// In One-Byte extensions value length 0 means 1.
len = extension->len + 1;
uint8_t GetTemporalLayer() const
{
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 nullptr;
return this->payloadDescriptorHandler->IsKeyFrame();
}
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.
if (extension->len == 0u)
return nullptr;
bool RtxDecode(uint8_t payloadType, uint32_t ssrc);
return extension->value;
}
else
void SetPayloadDescriptorHandler(RTC::Codecs::PayloadDescriptorHandler* payloadDescriptorHandler)
{
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
{
if (!this->payloadDescriptorHandler)
return 0u;
bool ProcessPayload(RTC::Codecs::EncodingContext* context);
return this->payloadDescriptorHandler->GetTemporalLayer();
}
void RestorePayload();
inline bool RtpPacket::IsKeyFrame() const
{
if (!this->payloadDescriptorHandler)
return false;
void ShiftPayload(size_t payloadOffset, size_t shift, bool expand = true);
return this->payloadDescriptorHandler->IsKeyFrame();
}
private:
void ParseExtensions();
inline void RtpPacket::SetPayloadDescriptorHandler(
RTC::Codecs::PayloadDescriptorHandler* payloadDescriptorHandler)
{
this->payloadDescriptorHandler.reset(payloadDescriptorHandler);
}
private:
// Passed by argument.
Header* header{ nullptr };
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
#endif
......@@ -57,18 +57,51 @@ namespace RTC
void FillJson(json& jsonObject) const;
virtual void FillJsonStats(json& jsonObject);
uint32_t GetSsrc() const;
uint8_t GetPayloadType() const;
const RTC::RtpCodecMimeType& GetMimeType() const;
uint32_t GetClockRate() const;
const std::string& GetRid() const;
const std::string& GetCname() const;
bool HasRtx() const;
uint32_t GetSsrc() const
{
return this->params.ssrc;
}
uint8_t GetPayloadType() 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);
uint32_t GetRtxSsrc() const;
uint8_t GetRtxPayloadType() const;
uint8_t GetSpatialLayers() const;
uint8_t GetTemporalLayers() const;
uint32_t GetRtxSsrc() const
{
return this->params.rtxSsrc;
}
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 void Pause() = 0;
virtual void Resume() = 0;
......@@ -77,22 +110,52 @@ namespace RTC
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;
void ResetScore(uint8_t score, bool notify);
uint8_t GetFractionLost() const;
float GetLossPercentage() const;
float GetRtt() const;
uint64_t GetMaxPacketMs() const;
uint32_t GetMaxPacketTs() const;
uint64_t GetSenderReportNtpMs() const;
uint32_t GetSenderReportTs() const;
uint8_t GetScore() const;
uint64_t GetActiveMs() const;
uint8_t GetFractionLost() const
{
return this->fractionLost;
}
float GetLossPercentage() const
{
return static_cast<float>(this->fractionLost) * 100 / 256;
}
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:
bool UpdateSeq(RTC::RtpPacket* packet);
void UpdateScore(uint8_t score);
void PacketRetransmitted(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:
void InitSeq(uint16_t seq);
......@@ -103,25 +166,27 @@ namespace RTC
Params params;
// Others.
// https://tools.ietf.org/html/rfc3550#appendix-A.1 stuff.
uint16_t maxSeq{ 0 }; // Highest seq. number seen.
uint32_t cycles{ 0 }; // Shifted count of seq. number cycles.
uint32_t baseSeq{ 0 }; // Base seq number.
uint32_t badSeq{ 0 }; // Last 'bad' seq number + 1.
uint32_t maxPacketTs{ 0 }; // Highest timestamp seen.
uint64_t maxPacketMs{ 0 }; // When the packet with highest timestammp was seen.
uint32_t packetsLost{ 0 };
uint8_t fractionLost{ 0 };
size_t packetsDiscarded{ 0 };
size_t packetsRetransmitted{ 0 };
size_t packetsRepaired{ 0 };
size_t nackCount{ 0 };
size_t nackPacketCount{ 0 };
size_t pliCount{ 0 };
size_t firCount{ 0 };
size_t repairedPriorScore{ 0 }; // Packets repaired at last interval for score calculation.
size_t retransmittedPriorScore{ 0 }; // Packets retransmitted at last interval for score calculation.
uint64_t lastSenderReportNtpMs{ 0 }; // NTP timestamp in last Sender Report (in ms).
uint32_t lastSenderReporTs{ 0 }; // RTP timestamp in last Sender Report.
uint16_t maxSeq{ 0u }; // Highest seq. number seen.
uint32_t cycles{ 0u }; // Shifted count of seq. number cycles.
uint32_t baseSeq{ 0u }; // Base seq number.
uint32_t badSeq{ 0u }; // Last 'bad' seq number + 1.
uint32_t maxPacketTs{ 0u }; // Highest timestamp seen.
uint64_t maxPacketMs{ 0u }; // When the packet with highest timestammp was seen.
uint32_t packetsLost{ 0u };
uint8_t fractionLost{ 0u };
size_t packetsDiscarded{ 0u };
size_t packetsRetransmitted{ 0u };
size_t packetsRepaired{ 0u };
size_t nackCount{ 0u };
size_t nackPacketCount{ 0u };
size_t pliCount{ 0u };
size_t firCount{ 0u };
size_t repairedPriorScore{ 0u }; // Packets repaired at last interval for score calculation.
size_t retransmittedPriorScore{
0u
}; // 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 };
bool hasRtt{ false };
// Instance of RtxStream.
......@@ -136,113 +201,6 @@ namespace RTC
// Last time since the stream is active.
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
#endif
......@@ -56,10 +56,22 @@ namespace RTC
void RequestKeyFrame();
void Pause() override;
void Resume() 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;
uint32_t GetLayerBitrate(uint64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer) 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
{
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:
void CalculateJitter(uint32_t rtpTimestamp);
......@@ -75,48 +87,25 @@ namespace RTC
void OnNackGeneratorKeyFrameRequired() override;
private:
uint32_t expectedPrior{ 0 }; // Packets expected at last interval.
uint32_t expectedPriorScore{ 0 }; // Packets expected at last interval for score calculation.
uint32_t receivedPrior{ 0 }; // Packets received at last interval.
uint32_t receivedPriorScore{ 0 }; // Packets received at last interval for score calculation.
uint32_t lastSrTimestamp{ 0 }; // The middle 32 bits out of 64 in the NTP
// timestamp received in the most recent
// sender report.
uint64_t lastSrReceived{ 0 }; // Wallclock time representing the most recent
// sender report arrival.
uint32_t transit{ 0 }; // Relative transit time for prev packet.
uint32_t jitter{ 0 };
uint8_t firSeqNumber{ 0 };
uint32_t reportedPacketLost{ 0 };
uint32_t expectedPrior{ 0u }; // Packets expected at last interval.
uint32_t expectedPriorScore{ 0u }; // Packets expected at last interval for score calculation.
uint32_t receivedPrior{ 0u }; // Packets received at last interval.
uint32_t receivedPriorScore{ 0u }; // Packets received at last interval for score calculation.
uint32_t lastSrTimestamp{ 0u }; // The middle 32 bits out of 64 in the NTP
// timestamp received in the most recent
// sender report.
uint64_t lastSrReceived{ 0u }; // Wallclock time representing the most recent
// sender report arrival.
uint32_t transit{ 0u }; // Relative transit time for prev packet.
uint32_t jitter{ 0u };
uint8_t firSeqNumber{ 0u };
uint32_t reportedPacketLost{ 0u };
std::unique_ptr<RTC::NackGenerator> nackGenerator;
Timer* inactivityCheckPeriodicTimer{ nullptr };
bool inactive{ false };
TransmissionCounter transmissionCounter; // Valid media + valid RTX.
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
#endif
......@@ -47,7 +47,10 @@ namespace RTC
RTC::RTCP::SdesChunk* GetRtcpSdesChunk();
void Pause() 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 GetSpatialLayerBitrate(uint64_t nowMs, uint8_t spatialLayer) override;
uint32_t GetLayerBitrate(uint64_t nowMs, uint8_t spatialLayer, uint8_t temporalLayer) override;
......@@ -61,22 +64,15 @@ namespace RTC
void UpdateScore(RTC::RTCP::ReceiverReport* report);
private:
uint32_t lostPriorScore{ 0 }; // Packets lost at last interval for score calculation.
uint32_t sentPriorScore{ 0 }; // Packets sent at last interval for score calculation.
uint32_t lostPriorScore{ 0u }; // Packets lost at last interval for score calculation.
uint32_t sentPriorScore{ 0u }; // Packets sent at last interval for score calculation.
std::vector<StorageItem*> buffer;
uint16_t bufferStartIdx{ 0 };
size_t bufferSize{ 0 };
uint16_t bufferStartIdx{ 0u };
size_t bufferSize{ 0u };
std::vector<StorageItem> storage;
uint16_t rtxSeq{ 0 };
uint16_t rtxSeq{ 0u };
RTC::RtpDataCounter transmissionCounter;
};
/* Inline instance methods */
inline uint32_t RtpStreamSend::GetBitrate(uint64_t nowMs)
{
return this->transmissionCounter.GetBitrate(nowMs);
}
} // namespace RTC
#endif
......@@ -36,21 +36,48 @@ namespace RTC
virtual ~RtxStream();
void FillJson(json& jsonObject) const;
uint32_t GetSsrc() const;
uint8_t GetPayloadType() const;
const RTC::RtpCodecMimeType& GetMimeType() const;
uint32_t GetClockRate() const;
const std::string& GetRrid() const;
const std::string& GetCname() const;
uint8_t GetFractionLost() const;
float GetLossPercentage() const;
uint32_t GetSsrc() const
{
return this->params.ssrc;
}
uint8_t GetPayloadType() 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& 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);
RTC::RTCP::ReceiverReport* GetRtcpReceiverReport();
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
protected:
bool UpdateSeq(RTC::RtpPacket* packet);
uint32_t GetExpectedPackets() const;
uint32_t GetExpectedPackets() const
{
return (this->cycles + this->maxSeq) - this->baseSeq + 1;
}
private:
void InitSeq(uint16_t seq);
......@@ -60,74 +87,27 @@ namespace RTC
Params params;
// Others.
// https://tools.ietf.org/html/rfc3550#appendix-A.1 stuff.
uint16_t maxSeq{ 0 }; // Highest seq. number seen.
uint32_t cycles{ 0 }; // Shifted count of seq. number cycles.
uint32_t baseSeq{ 0 }; // Base seq number.
uint32_t badSeq{ 0 }; // Last 'bad' seq number + 1.
uint32_t maxPacketTs{ 0 }; // Highest timestamp seen.
uint64_t maxPacketMs{ 0 }; // When the packet with highest timestammp was seen.
uint32_t packetsLost{ 0 };
uint8_t fractionLost{ 0 };
size_t packetsDiscarded{ 0 };
size_t packetsCount{ 0 };
uint16_t maxSeq{ 0u }; // Highest seq. number seen.
uint32_t cycles{ 0u }; // Shifted count of seq. number cycles.
uint32_t baseSeq{ 0u }; // Base seq number.
uint32_t badSeq{ 0u }; // Last 'bad' seq number + 1.
uint32_t maxPacketTs{ 0u }; // Highest timestamp seen.
uint64_t maxPacketMs{ 0u }; // When the packet with highest timestammp was seen.
uint32_t packetsLost{ 0u };
uint8_t fractionLost{ 0u };
size_t packetsDiscarded{ 0u };
size_t packetsCount{ 0u };
private:
// Whether at least a RTP packet has been received.
bool started{ false };
// Fields for generating Receiver Reports.
uint32_t expectedPrior{ 0 };
uint32_t receivedPrior{ 0 };
uint32_t lastSrTimestamp{ 0 };
uint64_t lastSrReceived{ 0 };
uint32_t reportedPacketLost{ 0 };
uint32_t expectedPrior{ 0u };
uint32_t receivedPrior{ 0u };
uint32_t lastSrTimestamp{ 0u };
uint64_t lastSrReceived{ 0u };
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
#endif
......@@ -50,7 +50,17 @@ namespace RTC
};
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:
SctpAssociation(
......@@ -60,8 +70,14 @@ namespace RTC
public:
void FillJson(json& jsonObject) const;
void TransportConnected();
size_t GetMaxSctpMessageSize() const;
SctpState GetState() const;
size_t GetMaxSctpMessageSize() const
{
return this->maxSctpMessageSize;
}
SctpState GetState() const
{
return this->state;
}
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 HandleDataConsumer(RTC::DataConsumer* dataConsumer);
......@@ -82,45 +98,19 @@ namespace RTC
private:
// Passed by argument.
Listener* listener{ nullptr };
uint16_t os{ 1024 };
uint16_t mis{ 1024 };
size_t maxSctpMessageSize{ 262144 };
uint16_t os{ 1024u };
uint16_t mis{ 1024u };
size_t maxSctpMessageSize{ 262144u };
bool isDataChannel{ false };
// Allocated by this.
uint8_t* messageBuffer{ nullptr };
// Others.
SctpState state{ SctpState::NEW };
struct socket* socket{ nullptr };
uint16_t desiredOs{ 0 };
size_t messageBufferLen{ 0 };
uint16_t lastSsnReceived{ 0 }; // Valid for us since no SCTP I-DATA support.
uint16_t desiredOs{ 0u };
size_t messageBufferLen{ 0u };
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
#endif
......@@ -39,11 +39,32 @@ namespace RTC
CummulativeResult() = default;
public:
uint64_t GetStartedAtMs() const;
size_t GetNumPackets() const;
size_t GetTotalSize() const;
uint32_t GetSendBitrate() const;
uint32_t GetReceiveBitrate() const;
uint64_t GetStartedAtMs() const
{
return this->firstPacketSentAtMs;
}
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 Reset();
......@@ -85,39 +106,6 @@ namespace RTC
RTC::RateCalculator sendTransmission;
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
#endif
......@@ -18,7 +18,16 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const 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 ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override;
......@@ -28,7 +37,10 @@ namespace RTC
void ApplyLayers() override;
uint32_t GetDesiredBitrate() const 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 NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override;
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override;
......@@ -62,24 +74,6 @@ namespace RTC
RTC::SeqManager<uint16_t> rtpSeqManager;
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
#endif
......@@ -19,8 +19,31 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override;
RTC::Consumer::Layers GetPreferredLayers() const override;
bool IsActive() const override;
RTC::Consumer::Layers GetPreferredLayers() 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 ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override;
......@@ -31,7 +54,10 @@ namespace RTC
uint32_t GetDesiredBitrate() const override;
void SendRtpPacket(RTC::RtpPacket* packet) 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 ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override;
void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType, uint32_t ssrc) override;
......@@ -85,40 +111,6 @@ namespace RTC
bool keyFrameForTsOffsetRequested{ false };
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
#endif
......@@ -40,19 +40,15 @@ namespace RTC
bool DecryptSrtp(uint8_t* data, size_t* len);
bool EncryptRtcp(const 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:
// Allocated by this.
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
#endif
......@@ -53,7 +53,20 @@ namespace RTC
};
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);
private:
......@@ -65,27 +78,90 @@ namespace RTC
~StunPacket();
void Dump() const;
Class GetClass() const;
Method GetMethod() const;
const uint8_t* GetData() const;
size_t GetSize() const;
void SetUsername(const char* username, size_t len);
void SetPriority(uint32_t priority);
void SetIceControlling(uint64_t iceControlling);
void SetIceControlled(uint64_t iceControlled);
void SetUseCandidate();
void SetXorMappedAddress(const struct sockaddr* xorMappedAddress);
void SetErrorCode(uint16_t errorCode);
void SetMessageIntegrity(const uint8_t* messageIntegrity);
void SetFingerprint();
const std::string& GetUsername() const;
uint32_t GetPriority() const;
uint64_t GetIceControlling() const;
uint64_t GetIceControlled() const;
bool HasUseCandidate() const;
uint16_t GetErrorCode() const;
bool HasMessageIntegrity() const;
bool HasFingerprint() const;
Class GetClass() const
{
return this->klass;
}
Method GetMethod() const
{
return this->method;
}
const uint8_t* GetData() const
{
return this->data;
}
size_t GetSize() const
{
return this->size;
}
void SetUsername(const char* username, size_t len)
{
this->username.assign(username, len);
}
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(
const std::string& localUsername, const std::string& localPassword);
StunPacket* CreateSuccessResponse();
......@@ -99,143 +175,19 @@ namespace RTC
Method method; // 2 bytes.
const uint8_t* transactionId{ nullptr }; // 12 bytes.
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.
std::string username; // Less than 513 bytes.
uint32_t priority{ 0 }; // 4 bytes unsigned integer.
uint64_t iceControlling{ 0 }; // 8 bytes unsigned integer.
uint64_t iceControlled{ 0 }; // 8 bytes unsigned integer.
uint32_t priority{ 0u }; // 4 bytes unsigned integer.
uint64_t iceControlling{ 0u }; // 8 bytes unsigned integer.
uint64_t iceControlled{ 0u }; // 8 bytes unsigned integer.
bool hasUseCandidate{ false }; // 0 bytes.
const uint8_t* messageIntegrity{ nullptr }; // 20 bytes.
bool hasFingerprint{ false }; // 4 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;
};
/* 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
#endif
......@@ -20,8 +20,25 @@ namespace RTC
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override;
RTC::Consumer::Layers GetPreferredLayers() const override;
bool IsActive() const override;
RTC::Consumer::Layers GetPreferredLayers() 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 ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override;
......@@ -32,7 +49,10 @@ namespace RTC
uint32_t GetDesiredBitrate() const override;
void SendRtpPacket(RTC::RtpPacket* packet) 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 ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override;
void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType, uint32_t ssrc) override;
......@@ -73,34 +93,6 @@ namespace RTC
std::unique_ptr<RTC::Codecs::EncodingContext> encodingContext;
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
#endif
......@@ -31,7 +31,7 @@ namespace RTC
// Passed by argument.
Listener* listener{ nullptr };
// Others.
size_t frameStart{ 0 }; // Where the latest frame starts.
size_t frameStart{ 0u }; // Where the latest frame starts.
};
} // namespace RTC
......
......@@ -124,8 +124,14 @@ namespace RTC
// Must be called from the subclass.
void Connected();
void Disconnected();
void DataReceived(size_t len);
void DataSent(size_t len);
void DataReceived(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 ReceiveRtcpPacket(RTC::RTCP::Packet* packet);
void ReceiveSctpData(const uint8_t* data, size_t len);
......@@ -269,18 +275,6 @@ namespace RTC
uint32_t maxIncomingBitrate{ 0u };
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
#endif
......@@ -53,7 +53,10 @@ namespace RTC
virtual ~TransportCongestionControlClient();
public:
RTC::BweType GetBweType() const;
RTC::BweType GetBweType() const
{
return this->bweType;
}
void TransportConnected();
void TransportDisconnected();
void InsertPacket(webrtc::RtpPacketSendInfo& packetInfo);
......@@ -63,7 +66,10 @@ namespace RTC
void ReceiveRtcpReceiverReport(const webrtc::RTCPReportBlock& report, float rtt, uint64_t nowMs);
void ReceiveRtcpTransportFeedback(const RTC::RTCP::FeedbackRtpTransportPacket* feedback);
void SetDesiredBitrate(uint32_t desiredBitrate, bool force);
const Bitrates& GetBitrates() const;
const Bitrates& GetBitrates() const
{
return this->bitrates;
}
uint32_t GetAvailableBitrate() const;
void RescheduleNextAvailableBitrateEvent();
......@@ -102,18 +108,6 @@ namespace RTC
uint64_t lastAvailableBitrateEventAtMs{ 0u };
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
#endif
......@@ -30,10 +30,23 @@ namespace RTC
virtual ~TransportCongestionControlServer();
public:
RTC::BweType GetBweType() const;
RTC::BweType GetBweType() const
{
return this->bweType;
}
void TransportConnected();
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 SetMaxIncomingBitrate(uint32_t bitrate);
......@@ -69,25 +82,6 @@ namespace RTC
uint64_t limitationRembSentAtMs{ 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
#endif
......@@ -25,131 +25,116 @@ namespace RTC
};
public:
TransportTuple(RTC::UdpSocket* udpSocket, const struct sockaddr* udpRemoteAddr);
explicit TransportTuple(RTC::TcpConnection* tcpConnection);
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. */
TransportTuple(RTC::UdpSocket* udpSocket, const struct sockaddr* udpRemoteAddr)
: udpSocket(udpSocket), udpRemoteAddr((struct sockaddr*)udpRemoteAddr), protocol(Protocol::UDP)
{
}
inline TransportTuple::TransportTuple(RTC::UdpSocket* udpSocket, const struct sockaddr* udpRemoteAddr)
: udpSocket(udpSocket), udpRemoteAddr((struct sockaddr*)udpRemoteAddr), protocol(Protocol::UDP)
{
}
explicit TransportTuple(RTC::TcpConnection* tcpConnection)
: tcpConnection(tcpConnection), protocol(Protocol::TCP)
{
}
inline TransportTuple::TransportTuple(RTC::TcpConnection* tcpConnection)
: tcpConnection(tcpConnection), protocol(Protocol::TCP)
{
}
explicit TransportTuple(const TransportTuple* tuple)
: 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)
: udpSocket(tuple->udpSocket), udpRemoteAddr(tuple->udpRemoteAddr),
tcpConnection(tuple->tcpConnection), localAnnouncedIp(tuple->localAnnouncedIp),
protocol(tuple->protocol)
{
if (protocol == TransportTuple::Protocol::UDP)
StoreUdpRemoteAddress();
}
public:
void FillJson(json& jsonObject) const;
inline void TransportTuple::StoreUdpRemoteAddress()
{
// 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;
}
void Dump() const;
inline TransportTuple::Protocol TransportTuple::GetProtocol() const
{
return this->protocol;
}
void StoreUdpRemoteAddress()
{
// 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
{
if (this->protocol == Protocol::UDP && tuple->GetProtocol() == Protocol::UDP)
bool Compare(const TransportTuple* tuple) const
{
return (
this->udpSocket == tuple->udpSocket &&
Utils::IP::CompareAddresses(this->udpRemoteAddr, tuple->GetRemoteAddress()));
if (this->protocol == Protocol::UDP && tuple->GetProtocol() == Protocol::UDP)
{
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)
{
this->localAnnouncedIp = localAnnouncedIp;
}
Protocol GetProtocol() const
{
return this->protocol;
}
inline void TransportTuple::Send(
const uint8_t* data, size_t len, RTC::TransportTuple::onSendCallback* cb)
{
if (this->protocol == Protocol::UDP)
this->udpSocket->Send(data, len, this->udpRemoteAddr, cb);
else
this->tcpConnection->Send(data, len, cb);
}
const struct sockaddr* GetLocalAddress() const
{
if (this->protocol == Protocol::UDP)
return this->udpSocket->GetLocalAddress();
else
return this->tcpConnection->GetLocalAddress();
}
inline const struct sockaddr* TransportTuple::GetLocalAddress() const
{
if (this->protocol == Protocol::UDP)
return this->udpSocket->GetLocalAddress();
else
return this->tcpConnection->GetLocalAddress();
}
const struct sockaddr* GetRemoteAddress() const
{
if (this->protocol == Protocol::UDP)
return (const struct sockaddr*)this->udpRemoteAddr;
else
return this->tcpConnection->GetPeerAddress();
}
inline const struct sockaddr* TransportTuple::GetRemoteAddress() const
{
if (this->protocol == Protocol::UDP)
return (const struct sockaddr*)this->udpRemoteAddr;
else
return this->tcpConnection->GetPeerAddress();
}
size_t GetRecvBytes() const
{
if (this->protocol == Protocol::UDP)
return this->udpSocket->GetRecvBytes();
else
return this->tcpConnection->GetRecvBytes();
}
inline size_t TransportTuple::GetRecvBytes() const
{
if (this->protocol == Protocol::UDP)
return this->udpSocket->GetRecvBytes();
else
return this->tcpConnection->GetRecvBytes();
}
size_t GetSentBytes() const
{
if (this->protocol == Protocol::UDP)
return this->udpSocket->GetSentBytes();
else
return this->tcpConnection->GetSentBytes();
}
inline size_t TransportTuple::GetSentBytes() const
{
if (this->protocol == Protocol::UDP)
return this->udpSocket->GetSentBytes();
else
return this->tcpConnection->GetSentBytes();
}
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;
};
} // namespace RTC
#endif
......@@ -14,7 +14,10 @@ namespace RTC
TrendCalculator(float decreaseFactor = DecreaseFactor);
public:
uint32_t GetValue() const;
uint32_t GetValue() const
{
return this->value;
}
void Update(uint32_t value, uint64_t nowMs);
void ForceUpdate(uint32_t value, uint64_t nowMs);
......@@ -24,13 +27,6 @@ namespace RTC
uint32_t highestValue{ 0u };
uint64_t highestValueUpdatedAtMs{ 0u };
};
/* Inline instance methods. */
inline uint32_t TrendCalculator::GetValue() const
{
return this->value;
}
} // namespace RTC
#endif
......@@ -33,8 +33,8 @@ public:
{
LogLevel logLevel{ LogLevel::LOG_ERROR };
struct LogTags logTags;
uint16_t rtcMinPort{ 10000 };
uint16_t rtcMaxPort{ 59999 };
uint16_t rtcMinPort{ 10000u };
uint16_t rtcMaxPort{ 59999u };
std::string dtlsCertificateFile;
std::string dtlsPrivateKeyFile;
};
......
......@@ -22,75 +22,73 @@ namespace Utils
{
public:
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.
if (
reinterpret_cast<const struct sockaddr_in*>(addr1)->sin_port !=
reinterpret_cast<const struct sockaddr_in*>(addr2)->sin_port)
{
return false;
}
static void GetAddressInfo(const struct sockaddr* addr, int& family, std::string& ip, uint16_t& port);
// Compare IP.
switch (addr1->sa_family)
static bool CompareAddresses(const struct sockaddr* addr1, const struct sockaddr* addr2)
{
case AF_INET:
// Compare family.
if (addr1->sa_family != addr2->sa_family || (addr1->sa_family != AF_INET && addr1->sa_family != AF_INET6))
{
return (
reinterpret_cast<const struct sockaddr_in*>(addr1)->sin_addr.s_addr ==
reinterpret_cast<const struct sockaddr_in*>(addr2)->sin_addr.s_addr);
return false;
}
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 (
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);
return 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:
std::memcpy(std::addressof(copiedAddr), addr, sizeof(struct sockaddr_in));
break;
struct sockaddr_storage copiedAddr;
case AF_INET6:
std::memcpy(std::addressof(copiedAddr), addr, sizeof(struct sockaddr_in6));
break;
switch (addr->sa_family)
{
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
{
......@@ -105,201 +103,180 @@ namespace Utils
* Getters below get value in Host Byte Order.
* Setters below set value in Network Byte Order.
*/
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);
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);
};
static uint8_t Get1Byte(const uint8_t* data, size_t i)
{
return data[i];
}
/* 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)
{
return data[i];
}
static uint32_t Get3Bytes(const uint8_t* data, size_t 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)
{
return uint16_t{ data[i + 1] } | uint16_t{ data[i] } << 8;
}
static uint32_t Get4Bytes(const uint8_t* data, size_t i)
{
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)
{
return uint32_t{ data[i + 2] } | uint32_t{ data[i + 1] } << 8 | uint32_t{ data[i] } << 16;
}
static uint64_t Get8Bytes(const uint8_t* data, size_t i)
{
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)
{
return uint32_t{ data[i + 3] } | uint32_t{ data[i + 2] } << 8 | uint32_t{ data[i + 1] } << 16 |
uint32_t{ data[i] } << 24;
}
static void Set1Byte(uint8_t* data, size_t i, uint8_t value)
{
data[i] = value;
}
inline uint64_t Byte::Get8Bytes(const uint8_t* data, size_t i)
{
return uint64_t{ Byte::Get4Bytes(data, i) } << 32 | Byte::Get4Bytes(data, i + 4);
}
static void Set2Bytes(uint8_t* data, size_t i, uint16_t value)
{
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)
{
data[i] = value;
}
static void Set3Bytes(uint8_t* data, size_t i, uint32_t 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)
{
data[i + 1] = static_cast<uint8_t>(value);
data[i] = static_cast<uint8_t>(value >> 8);
}
static void Set4Bytes(uint8_t* data, size_t i, uint32_t value)
{
data[i + 3] = static_cast<uint8_t>(value);
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)
{
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);
}
static void Set8Bytes(uint8_t* data, size_t i, uint64_t value)
{
data[i + 7] = static_cast<uint8_t>(value);
data[i + 6] = static_cast<uint8_t>(value >> 8);
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)
{
data[i + 3] = static_cast<uint8_t>(value);
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);
}
static uint16_t 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 void Byte::Set8Bytes(uint8_t* data, size_t i, uint64_t value)
{
data[i + 7] = static_cast<uint8_t>(value);
data[i + 6] = static_cast<uint8_t>(value >> 8);
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 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;
}
static uint32_t 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
{
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
{
public:
static void ClassInit();
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)
{
// 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.
Crypto::seed = uint32_t{ ((214013 * Crypto::seed) + 2531011) };
// This seems to produce better results.
Crypto::seed = uint32_t{ ((214013 * Crypto::seed) + 2531011) };
// Special case.
if (max == 4294967295)
--max;
// Special case.
if (max == 4294967295)
--max;
if (min > max)
min = max;
if (min > max)
min = max;
return (((Crypto::seed >> 4) & 0x7FFF7FFF) % (max - min + 1)) + min;
}
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)
{
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)
len = 64;
if (len > 64)
len = 64;
for (size_t i{ 0 }; i < len; ++i)
{
buffer[i] = chars[GetRandomUInt(0, sizeof(chars) - 1)];
}
for (size_t i{ 0 }; i < len; ++i)
{
buffer[i] = chars[GetRandomUInt(0, sizeof(chars) - 1)];
return std::string(buffer, len);
}
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)
{
uint32_t crc{ 0xFFFFFFFF };
const uint8_t* p = data;
while (size--)
{
crc = Crypto::crc32Table[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
}
while (size--)
{
crc = Crypto::crc32Table[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
return crc ^ ~0U;
}
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
{
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 std::string& str);
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);
};
inline void String::ToLowerCase(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
}
class Time
{
// Seconds from Jan 1, 1900 to Jan 1, 1970.
......@@ -314,74 +291,64 @@ namespace Utils
uint32_t fractions;
};
static Time::Ntp TimeMs2Ntp(uint64_t ms);
static uint64_t Ntp2TimeMs(Time::Ntp ntp);
static bool IsNewerTimestamp(uint32_t timestamp, uint32_t prevTimestamp);
static uint32_t LatestTimestamp(uint32_t timestamp1, uint32_t timestamp2);
static uint32_t TimeMsToAbsSendTime(uint64_t ms);
};
static Time::Ntp TimeMs2Ntp(uint64_t ms)
{
Time::Ntp ntp; // NOLINT(cppcoreguidelines-pro-type-member-init)
inline Time::Ntp Time::TimeMs2Ntp(uint64_t ms)
{
Time::Ntp ntp; // NOLINT(cppcoreguidelines-pro-type-member-init)
ntp.seconds = ms / 1000;
ntp.fractions =
static_cast<uint32_t>((static_cast<double>(ms % 1000) / 1000) * NtpFractionalUnit);
ntp.seconds = ms / 1000;
ntp.fractions =
static_cast<uint32_t>((static_cast<double>(ms % 1000) / 1000) * NtpFractionalUnit);
return ntp;
}
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)
{
// 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 bool Time::IsNewerTimestamp(uint32_t timestamp, uint32_t prevTimestamp)
{
// 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;
}
static bool IsNewerTimestamp(uint32_t timestamp, uint32_t prevTimestamp)
{
// 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::TimeMsToAbsSendTime(uint64_t ms)
{
return static_cast<uint32_t>(((ms << 18) + 500) / 1000) & 0x00FFFFFF;
}
static uint32_t LatestTimestamp(uint32_t timestamp1, uint32_t timestamp2)
{
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
{
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
#endif
......@@ -57,8 +57,14 @@ public:
struct sockaddr_storage* localAddr,
const std::string& localIp,
uint16_t localPort);
bool IsClosed() const;
uv_tcp_t* GetUvHandle() const;
bool IsClosed() const
{
return this->closed;
}
uv_tcp_t* GetUvHandle() const
{
return this->uvHandle;
}
void Start();
void Write(const uint8_t* data, size_t len, TcpConnection::onSendCallback* cb);
void Write(
......@@ -68,15 +74,42 @@ public:
size_t len2,
TcpConnection::onSendCallback* cb);
void ErrorReceiving();
const struct sockaddr* GetLocalAddress() const;
int GetLocalFamily() const;
const std::string& GetLocalIp() const;
uint16_t GetLocalPort() const;
const struct sockaddr* GetPeerAddress() const;
const std::string& GetPeerIp() const;
uint16_t GetPeerPort() const;
size_t GetRecvBytes() const;
size_t GetSentBytes() const;
const struct sockaddr* GetLocalAddress() const
{
return reinterpret_cast<const struct sockaddr*>(this->localAddr);
}
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;
}
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:
bool SetPeerAddress();
......@@ -93,16 +126,16 @@ protected:
protected:
// Passed by argument.
size_t bufferSize{ 0 };
size_t bufferSize{ 0u };
// Allocated by this.
uint8_t* buffer{ nullptr };
// Others.
size_t bufferDataLen{ 0 };
size_t bufferDataLen{ 0u };
std::string localIp;
uint16_t localPort{ 0 };
uint16_t localPort{ 0u };
struct sockaddr_storage peerAddr;
std::string peerIp;
uint16_t peerPort{ 0 };
uint16_t peerPort{ 0u };
private:
// Passed by argument.
......@@ -112,67 +145,10 @@ private:
// Others.
struct sockaddr_storage* localAddr{ nullptr };
bool closed{ false };
size_t recvBytes{ 0 };
size_t sentBytes{ 0 };
size_t recvBytes{ 0u };
size_t sentBytes{ 0u };
bool isClosedByPeer{ 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
......@@ -19,11 +19,26 @@ public:
public:
void Close();
virtual void Dump() const;
const struct sockaddr* GetLocalAddress() const;
int GetLocalFamily() const;
const std::string& GetLocalIp() const;
uint16_t GetLocalPort() const;
size_t GetNumConnections() const;
const struct sockaddr* GetLocalAddress() const
{
return reinterpret_cast<const struct sockaddr*>(&this->localAddr);
}
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:
void AcceptTcpConnection(TcpConnection* connection);
......@@ -47,7 +62,7 @@ public:
protected:
struct sockaddr_storage localAddr;
std::string localIp;
uint16_t localPort{ 0 };
uint16_t localPort{ 0u };
private:
// Allocated by this (may be passed by argument).
......@@ -57,31 +72,4 @@ private:
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
......@@ -28,9 +28,18 @@ public:
void Stop();
void Reset();
void Restart();
uint64_t GetTimeout() const;
uint64_t GetRepeat() const;
bool IsActive() const;
uint64_t GetTimeout() 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. */
public:
......@@ -43,25 +52,8 @@ private:
uv_timer_t* uvHandle{ nullptr };
// Others.
bool closed{ false };
uint64_t timeout{ 0 };
uint64_t repeat{ 0 };
uint64_t timeout{ 0u };
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
......@@ -46,12 +46,30 @@ public:
void Close();
virtual void Dump() const;
void Send(const uint8_t* data, size_t len, const struct sockaddr* addr, UdpSocket::onSendCallback* cb);
const struct sockaddr* GetLocalAddress() const;
int GetLocalFamily() const;
const std::string& GetLocalIp() const;
uint16_t GetLocalPort() const;
size_t GetRecvBytes() const;
size_t GetSentBytes() const;
const struct sockaddr* GetLocalAddress() const
{
return reinterpret_cast<const struct sockaddr*>(&this->localAddr);
}
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 GetRecvBytes() const
{
return this->recvBytes;
}
size_t GetSentBytes() const
{
return this->sentBytes;
}
private:
bool SetLocalAddress();
......@@ -70,47 +88,15 @@ protected:
protected:
struct sockaddr_storage localAddr;
std::string localIp;
uint16_t localPort{ 0 };
uint16_t localPort{ 0u };
private:
// Allocated by this (may be passed by argument).
uv_udp_t* uvHandle{ nullptr };
// Others.
bool closed{ false };
size_t recvBytes{ 0 };
size_t sentBytes{ 0 };
size_t recvBytes{ 0u };
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
......@@ -42,9 +42,15 @@ public:
public:
void Close();
bool IsClosed() const;
bool IsClosed() const
{
return this->closed;
}
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. */
public:
......@@ -67,24 +73,12 @@ private:
protected:
// Passed by argument.
size_t bufferSize{ 0 };
size_t bufferSize{ 0u };
UnixStreamSocket::Role role;
// Allocated by this.
uint8_t* buffer{ nullptr };
// 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
......@@ -79,7 +79,6 @@
'src/RTC/TrendCalculator.cpp',
'src/RTC/UdpSocket.cpp',
'src/RTC/WebRtcTransport.cpp',
'src/RTC/Codecs/Codecs.cpp',
'src/RTC/Codecs/H264.cpp',
'src/RTC/Codecs/VP8.cpp',
'src/RTC/Codecs/VP9.cpp',
......@@ -191,7 +190,7 @@
'include/RTC/TrendCalculator.hpp',
'include/RTC/UdpSocket.hpp',
'include/RTC/WebRtcTransport.hpp',
'include/RTC/Codecs/Codecs.hpp',
'include/RTC/Codecs/Tools.hpp',
'include/RTC/Codecs/PayloadDescriptorHandler.hpp',
'include/RTC/Codecs/H264.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 @@
#include "DepLibUV.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "RTC/Codecs/Codecs.hpp"
#include "RTC/Codecs/Tools.hpp"
namespace RTC
{
......@@ -23,7 +23,7 @@ namespace RTC
auto& encoding = this->rtpParameters.encodings[0];
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
this->keyFrameSupported = RTC::Codecs::CanBeKeyFrame(mediaCodec->mimeType);
this->keyFrameSupported = RTC::Codecs::Tools::CanBeKeyFrame(mediaCodec->mimeType);
// Create RtpStreamSend instances.
CreateRtpStreams();
......
......@@ -7,7 +7,7 @@
#include "MediaSoupErrors.hpp"
#include "Utils.hpp"
#include "Channel/Notifier.hpp"
#include "RTC/Codecs/Codecs.hpp"
#include "RTC/Codecs/Tools.hpp"
#include "RTC/RTCP/FeedbackPs.hpp"
#include "RTC/RTCP/FeedbackRtp.hpp"
#include "RTC/RTCP/XrReceiverReferenceTime.hpp"
......@@ -49,7 +49,7 @@ namespace RTC
auto& encoding = this->rtpParameters.encodings[0];
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 %s",
......
......@@ -118,9 +118,32 @@ namespace RTC
void CompoundPacket::AddSenderReport(SenderReport* report)
{
MS_TRACE();
MS_ASSERT(!HasSenderReport(), "a Sender Report is already present");
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 RTC
......@@ -184,6 +184,8 @@ namespace RTC
const std::string& Packet::Type2String(Type type)
{
MS_TRACE();
static const std::string Unknown("UNKNOWN");
auto it = Packet::type2String.find(type);
......
......@@ -4,7 +4,7 @@
#include "RTC/RtpStreamRecv.hpp"
#include "Logger.hpp"
#include "Utils.hpp"
#include "RTC/Codecs/Codecs.hpp"
#include "RTC/Codecs/Tools.hpp"
namespace RTC
{
......@@ -250,7 +250,7 @@ namespace RTC
// Process the packet at codec level.
if (packet->GetPayloadType() == GetPayloadType())
RTC::Codecs::ProcessRtpPacket(packet, GetMimeType());
RTC::Codecs::Tools::ProcessRtpPacket(packet, GetMimeType());
// Pass the packet to the NackGenerator.
if (this->params.useNack)
......@@ -370,7 +370,7 @@ namespace RTC
// Process the packet at codec level.
if (packet->GetPayloadType() == GetPayloadType())
RTC::Codecs::ProcessRtpPacket(packet, GetMimeType());
RTC::Codecs::Tools::ProcessRtpPacket(packet, GetMimeType());
// Mark the packet as retransmitted.
RTC::RtpStream::PacketRetransmitted(packet);
......
......@@ -6,7 +6,7 @@
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "Channel/Notifier.hpp"
#include "RTC/Codecs/Codecs.hpp"
#include "RTC/Codecs/Tools.hpp"
namespace RTC
{
......@@ -24,7 +24,7 @@ namespace RTC
auto& encoding = this->rtpParameters.encodings[0];
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.
CreateRtpStream();
......
......@@ -7,7 +7,7 @@
#include "MediaSoupErrors.hpp"
#include "Utils.hpp"
#include "Channel/Notifier.hpp"
#include "RTC/Codecs/Codecs.hpp"
#include "RTC/Codecs/Tools.hpp"
namespace RTC
{
......@@ -102,7 +102,7 @@ namespace RTC
// Create the encoding context.
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 simulcast", mediaCodec->mimeType.ToString().c_str());
......@@ -113,7 +113,7 @@ namespace RTC
params.spatialLayers = encoding.spatialLayers;
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");
......
......@@ -7,7 +7,7 @@
#include "MediaSoupErrors.hpp"
#include "Utils.hpp"
#include "Channel/Notifier.hpp"
#include "RTC/Codecs/Codecs.hpp"
#include "RTC/Codecs/Tools.hpp"
namespace RTC
{
......@@ -84,7 +84,7 @@ namespace RTC
// Create the encoding context.
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());
}
......@@ -95,7 +95,7 @@ namespace RTC
params.temporalLayers = encoding.temporalLayers;
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");
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论