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

C++: Remove inline methods (#371)

Instead, directly define the method in the method declaration within the class declaration.
上级 1ad97057
...@@ -314,11 +314,6 @@ ...@@ -314,11 +314,6 @@
"directory": "PATH/out", "directory": "PATH/out",
"file": "PATH/src/RTC/WebRtcTransport.cpp" "file": "PATH/src/RTC/WebRtcTransport.cpp"
}, },
{
"command": "c++ -c -DMS_LITTLE_ENDIAN -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -IPATH/include -IPATH/deps/json/single_include/nlohmann -IPATH/deps/netstring/netstring-c -IPATH/deps/libuv/include -IPATH/deps/openssl/openssl/include -IPATH/deps/libsrtp/srtp/include -IPATH/deps/usrsctp/usrsctp/usrsctplib -IPATH/deps/libwebrtc -IPATH/deps/libwebrtc/libwebrtc -IPATH/deps/libwebrtc/deps/abseil-cpp/abseil-cpp -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -m64 -g -Wno-unknown-warning-option -fPIC -o PATH/out/Release/obj.target/mediasoup-worker/src/RTC/Codecs/Codecs.o PATH/src/RTC/Codecs/Codecs.cpp",
"directory": "PATH/out",
"file": "PATH/src/RTC/Codecs/Codecs.cpp"
},
{ {
"command": "c++ -c -DMS_LITTLE_ENDIAN -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -IPATH/include -IPATH/deps/json/single_include/nlohmann -IPATH/deps/netstring/netstring-c -IPATH/deps/libuv/include -IPATH/deps/openssl/openssl/include -IPATH/deps/libsrtp/srtp/include -IPATH/deps/usrsctp/usrsctp/usrsctplib -IPATH/deps/libwebrtc -IPATH/deps/libwebrtc/libwebrtc -IPATH/deps/libwebrtc/deps/abseil-cpp/abseil-cpp -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -m64 -g -Wno-unknown-warning-option -fPIC -o PATH/out/Release/obj.target/mediasoup-worker/src/RTC/Codecs/H264.o PATH/src/RTC/Codecs/H264.cpp", "command": "c++ -c -DMS_LITTLE_ENDIAN -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -IPATH/include -IPATH/deps/json/single_include/nlohmann -IPATH/deps/netstring/netstring-c -IPATH/deps/libuv/include -IPATH/deps/openssl/openssl/include -IPATH/deps/libsrtp/srtp/include -IPATH/deps/usrsctp/usrsctp/usrsctplib -IPATH/deps/libwebrtc -IPATH/deps/libwebrtc/libwebrtc -IPATH/deps/libwebrtc/deps/abseil-cpp/abseil-cpp -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -m64 -g -Wno-unknown-warning-option -fPIC -o PATH/out/Release/obj.target/mediasoup-worker/src/RTC/Codecs/H264.o PATH/src/RTC/Codecs/H264.cpp",
"directory": "PATH/out", "directory": "PATH/out",
......
...@@ -29,13 +29,14 @@ namespace Channel ...@@ -29,13 +29,14 @@ namespace Channel
// Passed by argument. // Passed by argument.
Listener* listener{ nullptr }; Listener* listener{ nullptr };
// Others. // Others.
size_t msgStart{ 0 }; // Where the latest message starts. size_t msgStart{ 0u }; // Where the latest message starts.
}; };
class ProducerSocket : public ::UnixStreamSocket class ProducerSocket : public ::UnixStreamSocket
{ {
public: public:
ProducerSocket(int fd, size_t bufferSize); ProducerSocket(int fd, size_t bufferSize);
/* Pure virtual methods inherited from ::UnixStreamSocket. */ /* Pure virtual methods inherited from ::UnixStreamSocket. */
public: public:
void UserOnUnixStreamRead() override void UserOnUnixStreamRead() override
......
...@@ -9,24 +9,18 @@ class DepLibSRTP ...@@ -9,24 +9,18 @@ class DepLibSRTP
public: public:
static void ClassInit(); static void ClassInit();
static void ClassDestroy(); static void ClassDestroy();
static bool IsError(srtp_err_status_t code); static bool IsError(srtp_err_status_t code)
static const char* GetErrorString(srtp_err_status_t code); {
return (code != srtp_err_status_ok);
}
static const char* GetErrorString(srtp_err_status_t code)
{
// This throws out_of_range if the given index is not in the vector.
return DepLibSRTP::errors.at(code);
}
private: private:
static std::vector<const char*> errors; static std::vector<const char*> errors;
}; };
/* Inline static methods. */
inline bool DepLibSRTP::IsError(srtp_err_status_t code)
{
return (code != srtp_err_status_ok);
}
inline const char* DepLibSRTP::GetErrorString(srtp_err_status_t code)
{
// This throws out_of_range if the given index is not in the vector.
return DepLibSRTP::errors.at(code);
}
#endif #endif
...@@ -11,35 +11,25 @@ public: ...@@ -11,35 +11,25 @@ public:
static void ClassDestroy(); static void ClassDestroy();
static void PrintVersion(); static void PrintVersion();
static void RunLoop(); static void RunLoop();
static uv_loop_t* GetLoop(); static uv_loop_t* GetLoop()
static uint64_t GetTimeMs(); {
static uint64_t GetTimeUs();
static uint64_t GetTimeNs();
private:
static uv_loop_t* loop;
};
/* Inline static methods. */
inline uv_loop_t* DepLibUV::GetLoop()
{
return DepLibUV::loop; return DepLibUV::loop;
} }
static uint64_t GetTimeMs()
inline uint64_t DepLibUV::GetTimeMs() {
{
return static_cast<uint64_t>(uv_hrtime() / 1000000u); return static_cast<uint64_t>(uv_hrtime() / 1000000u);
} }
static uint64_t GetTimeUs()
inline uint64_t DepLibUV::GetTimeUs() {
{
return static_cast<uint64_t>(uv_hrtime() / 1000u); return static_cast<uint64_t>(uv_hrtime() / 1000u);
} }
static uint64_t GetTimeNs()
inline uint64_t DepLibUV::GetTimeNs() {
{
return uv_hrtime(); return uv_hrtime();
} }
private:
static uv_loop_t* loop;
};
#endif #endif
...@@ -8,27 +8,19 @@ ...@@ -8,27 +8,19 @@
class MediaSoupError : public std::runtime_error class MediaSoupError : public std::runtime_error
{ {
public: public:
explicit MediaSoupError(const char* description); explicit MediaSoupError(const char* description) : std::runtime_error(description)
{
}
}; };
/* Inline methods. */
inline MediaSoupError::MediaSoupError(const char* description) : std::runtime_error(description)
{
}
class MediaSoupTypeError : public MediaSoupError class MediaSoupTypeError : public MediaSoupError
{ {
public: public:
explicit MediaSoupTypeError(const char* description); explicit MediaSoupTypeError(const char* description) : MediaSoupError(description)
{
}
}; };
/* Inline methods. */
inline MediaSoupTypeError::MediaSoupTypeError(const char* description) : MediaSoupError(description)
{
}
// clang-format off // clang-format off
#define MS_THROW_ERROR(desc, ...) \ #define MS_THROW_ERROR(desc, ...) \
do \ do \
......
...@@ -15,8 +15,8 @@ namespace RTC ...@@ -15,8 +15,8 @@ namespace RTC
private: private:
struct DBovs struct DBovs
{ {
uint16_t totalSum{ 0 }; // Sum of dBvos (positive integer). uint16_t totalSum{ 0u }; // Sum of dBvos (positive integer).
size_t count{ 0 }; // Number of dBvos entries in totalSum. size_t count{ 0u }; // Number of dBvos entries in totalSum.
}; };
public: public:
...@@ -42,9 +42,9 @@ namespace RTC ...@@ -42,9 +42,9 @@ namespace RTC
private: private:
// Passed by argument. // Passed by argument.
uint16_t maxEntries{ 1 }; uint16_t maxEntries{ 1u };
int8_t threshold{ -80 }; int8_t threshold{ -80 };
uint16_t interval{ 1000 }; uint16_t interval{ 1000u };
// Allocated by this. // Allocated by this.
Timer* periodicTimer{ nullptr }; Timer* periodicTimer{ nullptr };
// Others. // Others.
......
#ifndef MS_RTC_CODECS_HPP
#define MS_RTC_CODECS_HPP
#include "common.hpp"
#include "RTC/Codecs/H264.hpp"
#include "RTC/Codecs/PayloadDescriptorHandler.hpp"
#include "RTC/Codecs/VP8.hpp"
#include "RTC/Codecs/VP9.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
namespace RTC
{
namespace Codecs
{
bool CanBeKeyFrame(const RTC::RtpCodecMimeType& mimeType);
void ProcessRtpPacket(RTC::RtpPacket* packet, const RTC::RtpCodecMimeType& mimeType);
bool IsValidTypeForCodec(RTC::RtpParameters::Type type, const RTC::RtpCodecMimeType& mimeType);
EncodingContext* GetEncodingContext(
const RTC::RtpCodecMimeType& mimeType, uint8_t spatialLayers, uint8_t temporalLayers);
/* Inline namespace methods. */
inline bool CanBeKeyFrame(const RTC::RtpCodecMimeType& mimeType)
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
case RTC::RtpCodecMimeType::Subtype::VP9:
case RTC::RtpCodecMimeType::Subtype::H264:
return true;
default:
return false;
}
}
default:
{
return false;
}
}
}
inline bool IsValidTypeForCodec(RTC::RtpParameters::Type type, const RTC::RtpCodecMimeType& mimeType)
{
switch (type)
{
case RTC::RtpParameters::Type::NONE:
{
return false;
}
case RTC::RtpParameters::Type::SIMPLE:
{
return true;
}
case RTC::RtpParameters::Type::SIMULCAST:
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
case RTC::RtpCodecMimeType::Subtype::H264:
return true;
default:
return false;
}
}
default:
{
return false;
}
}
}
case RTC::RtpParameters::Type::SVC:
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP9:
return true;
default:
return false;
}
}
default:
{
return false;
}
}
}
case RTC::RtpParameters::Type::PIPE:
{
return true;
}
default:
{
return false;
}
}
}
inline EncodingContext* GetEncodingContext(
const RTC::RtpCodecMimeType& mimeType, RTC::Codecs::EncodingContext::Params& params)
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
return new RTC::Codecs::VP8::EncodingContext(params);
case RTC::RtpCodecMimeType::Subtype::VP9:
return new RTC::Codecs::VP9::EncodingContext(params);
case RTC::RtpCodecMimeType::Subtype::H264:
return new RTC::Codecs::H264::EncodingContext(params);
default:
return nullptr;
}
}
default:
{
return nullptr;
}
}
}
} // namespace Codecs
} // namespace RTC
#endif
...@@ -47,12 +47,17 @@ namespace RTC ...@@ -47,12 +47,17 @@ namespace RTC
class EncodingContext : public RTC::Codecs::EncodingContext class EncodingContext : public RTC::Codecs::EncodingContext
{ {
public: public:
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params); explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
~EncodingContext() = default; ~EncodingContext() = default;
/* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */ /* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */
public: public:
void SyncRequired() override; void SyncRequired() override
{
}
}; };
public: public:
...@@ -63,50 +68,29 @@ namespace RTC ...@@ -63,50 +68,29 @@ namespace RTC
~PayloadDescriptorHandler() = default; ~PayloadDescriptorHandler() = default;
public: public:
void Dump() const override; void Dump() const override
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;
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(); this->payloadDescriptor->Dump();
} }
bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override;
inline uint8_t H264::PayloadDescriptorHandler::GetSpatialLayer() const void Restore(uint8_t* data) override;
uint8_t GetSpatialLayer() const override
{ {
return 0u; return 0u;
} }
uint8_t GetTemporalLayer() const override
inline uint8_t H264::PayloadDescriptorHandler::GetTemporalLayer() const
{ {
return this->payloadDescriptor->tid; return this->payloadDescriptor->tid;
} }
bool IsKeyFrame() const override
inline bool H264::PayloadDescriptorHandler::IsKeyFrame() const
{ {
return this->payloadDescriptor->isKeyFrame; return this->payloadDescriptor->isKeyFrame;
} }
private:
std::unique_ptr<PayloadDescriptor> payloadDescriptor;
};
};
} // namespace Codecs } // namespace Codecs
} // namespace RTC } // namespace RTC
......
#ifndef MS_RTC_PAYLOAD_DESCRIPTOR_HANDLER_HPP #ifndef MS_RTC_CODECS_PAYLOAD_DESCRIPTOR_HANDLER_HPP
#define MS_RTC_PAYLOAD_DESCRIPTOR_HANDLER_HPP #define MS_RTC_CODECS_PAYLOAD_DESCRIPTOR_HANDLER_HPP
#include "common.hpp" #include "common.hpp"
...@@ -27,92 +27,65 @@ namespace RTC ...@@ -27,92 +27,65 @@ namespace RTC
}; };
public: 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);
virtual void SyncRequired() = 0;
private:
Params params;
int16_t targetSpatialLayer{ -1 };
int16_t targetTemporalLayer{ -1 };
int16_t currentSpatialLayer{ -1 };
int16_t currentTemporalLayer{ -1 };
};
/* Inline instance methods. */
inline EncodingContext::EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: params(params)
{ {
} }
virtual ~EncodingContext() = default;
inline uint8_t EncodingContext::GetSpatialLayers() const public:
uint8_t GetSpatialLayers() const
{ {
return this->params.spatialLayers; return this->params.spatialLayers;
} }
uint8_t GetTemporalLayers() const
inline uint8_t EncodingContext::GetTemporalLayers() const
{ {
return this->params.temporalLayers; return this->params.temporalLayers;
} }
bool IsKSvc() const
inline bool EncodingContext::IsKSvc() const
{ {
return this->params.ksvc; return this->params.ksvc;
} }
int16_t GetTargetSpatialLayer() const
inline int16_t EncodingContext::GetTargetSpatialLayer() const
{ {
return this->targetSpatialLayer; return this->targetSpatialLayer;
} }
int16_t GetTargetTemporalLayer() const
inline int16_t EncodingContext::GetTargetTemporalLayer() const
{ {
return this->targetTemporalLayer; return this->targetTemporalLayer;
} }
int16_t GetCurrentSpatialLayer() const
inline int16_t EncodingContext::GetCurrentSpatialLayer() const
{ {
return this->currentSpatialLayer; return this->currentSpatialLayer;
} }
int16_t GetCurrentTemporalLayer() const
inline int16_t EncodingContext::GetCurrentTemporalLayer() const
{ {
return this->currentTemporalLayer; return this->currentTemporalLayer;
} }
void SetTargetSpatialLayer(int16_t spatialLayer)
inline void EncodingContext::SetTargetSpatialLayer(int16_t spatialLayer)
{ {
this->targetSpatialLayer = spatialLayer; this->targetSpatialLayer = spatialLayer;
} }
void SetTargetTemporalLayer(int16_t temporalLayer)
inline void EncodingContext::SetTargetTemporalLayer(int16_t temporalLayer)
{ {
this->targetTemporalLayer = temporalLayer; this->targetTemporalLayer = temporalLayer;
} }
void SetCurrentSpatialLayer(int16_t spatialLayer)
inline void EncodingContext::SetCurrentSpatialLayer(int16_t spatialLayer)
{ {
this->currentSpatialLayer = spatialLayer; this->currentSpatialLayer = spatialLayer;
} }
void SetCurrentTemporalLayer(int16_t temporalLayer)
inline void EncodingContext::SetCurrentTemporalLayer(int16_t temporalLayer)
{ {
this->currentTemporalLayer = temporalLayer; this->currentTemporalLayer = temporalLayer;
} }
virtual void SyncRequired() = 0;
private:
Params params;
int16_t targetSpatialLayer{ -1 };
int16_t targetTemporalLayer{ -1 };
int16_t currentSpatialLayer{ -1 };
int16_t currentTemporalLayer{ -1 };
};
class PayloadDescriptorHandler class PayloadDescriptorHandler
{ {
......
#ifndef MS_RTC_CODECS_TOOLS_HPP
#define MS_RTC_CODECS_TOOLS_HPP
#include "common.hpp"
#include "RTC/Codecs/H264.hpp"
#include "RTC/Codecs/PayloadDescriptorHandler.hpp"
#include "RTC/Codecs/VP8.hpp"
#include "RTC/Codecs/VP9.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
namespace RTC
{
namespace Codecs
{
class Tools
{
public:
static bool CanBeKeyFrame(const RTC::RtpCodecMimeType& mimeType)
{
MS_TRACE();
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
case RTC::RtpCodecMimeType::Subtype::VP9:
case RTC::RtpCodecMimeType::Subtype::H264:
return true;
default:
return false;
}
}
default:
{
return false;
}
}
}
static void ProcessRtpPacket(RTC::RtpPacket* packet, const RTC::RtpCodecMimeType& mimeType)
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
{
RTC::Codecs::VP8::ProcessRtpPacket(packet);
break;
}
case RTC::RtpCodecMimeType::Subtype::VP9:
{
RTC::Codecs::VP9::ProcessRtpPacket(packet);
break;
}
case RTC::RtpCodecMimeType::Subtype::H264:
{
RTC::Codecs::H264::ProcessRtpPacket(packet);
break;
}
default:;
}
}
default:;
}
}
static bool IsValidTypeForCodec(RTC::RtpParameters::Type type, const RTC::RtpCodecMimeType& mimeType)
{
switch (type)
{
case RTC::RtpParameters::Type::NONE:
{
return false;
}
case RTC::RtpParameters::Type::SIMPLE:
{
return true;
}
case RTC::RtpParameters::Type::SIMULCAST:
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
case RTC::RtpCodecMimeType::Subtype::H264:
return true;
default:
return false;
}
}
default:
{
return false;
}
}
}
case RTC::RtpParameters::Type::SVC:
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP9:
return true;
default:
return false;
}
}
default:
{
return false;
}
}
}
case RTC::RtpParameters::Type::PIPE:
{
return true;
}
default:
{
return false;
}
}
}
static EncodingContext* GetEncodingContext(
const RTC::RtpCodecMimeType& mimeType, RTC::Codecs::EncodingContext::Params& params)
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
return new RTC::Codecs::VP8::EncodingContext(params);
case RTC::RtpCodecMimeType::Subtype::VP9:
return new RTC::Codecs::VP9::EncodingContext(params);
case RTC::RtpCodecMimeType::Subtype::H264:
return new RTC::Codecs::H264::EncodingContext(params);
default:
return nullptr;
}
}
default:
{
return nullptr;
}
}
}
};
} // namespace Codecs
} // namespace RTC
#endif
...@@ -82,12 +82,18 @@ namespace RTC ...@@ -82,12 +82,18 @@ namespace RTC
class EncodingContext : public RTC::Codecs::EncodingContext class EncodingContext : public RTC::Codecs::EncodingContext
{ {
public: public:
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params); explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
~EncodingContext() = default; ~EncodingContext() = default;
/* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */ /* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */
public: public:
void SyncRequired() override; void SyncRequired() override
{
this->syncRequired = true;
}
public: public:
RTC::SeqManager<uint16_t> pictureIdManager; RTC::SeqManager<uint16_t> pictureIdManager;
...@@ -103,51 +109,29 @@ namespace RTC ...@@ -103,51 +109,29 @@ namespace RTC
~PayloadDescriptorHandler() = default; ~PayloadDescriptorHandler() = default;
public: public:
void Dump() const override; void Dump() const override
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;
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(); this->payloadDescriptor->Dump();
} }
bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override;
inline uint8_t VP8::PayloadDescriptorHandler::GetSpatialLayer() const void Restore(uint8_t* data) override;
uint8_t GetSpatialLayer() const override
{ {
return 0u; return 0u;
} }
uint8_t GetTemporalLayer() const override
inline uint8_t VP8::PayloadDescriptorHandler::GetTemporalLayer() const
{ {
return this->payloadDescriptor->hasTlIndex ? this->payloadDescriptor->tlIndex : 0u; return this->payloadDescriptor->hasTlIndex ? this->payloadDescriptor->tlIndex : 0u;
} }
bool IsKeyFrame() const override
inline bool VP8::PayloadDescriptorHandler::IsKeyFrame() const
{ {
return this->payloadDescriptor->isKeyFrame; return this->payloadDescriptor->isKeyFrame;
} }
private:
std::unique_ptr<PayloadDescriptor> payloadDescriptor;
};
};
} // namespace Codecs } // namespace Codecs
} // namespace RTC } // namespace RTC
......
...@@ -99,12 +99,18 @@ namespace RTC ...@@ -99,12 +99,18 @@ namespace RTC
class EncodingContext : public RTC::Codecs::EncodingContext class EncodingContext : public RTC::Codecs::EncodingContext
{ {
public: public:
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params); explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
~EncodingContext() = default; ~EncodingContext() = default;
/* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */ /* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */
public: public:
void SyncRequired() override; void SyncRequired() override
{
this->syncRequired = true;
}
public: public:
RTC::SeqManager<uint16_t> pictureIdManager; RTC::SeqManager<uint16_t> pictureIdManager;
...@@ -118,51 +124,29 @@ namespace RTC ...@@ -118,51 +124,29 @@ namespace RTC
~PayloadDescriptorHandler() = default; ~PayloadDescriptorHandler() = default;
public: public:
void Dump() const override; void Dump() const override
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;
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(); this->payloadDescriptor->Dump();
} }
bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override;
inline uint8_t VP9::PayloadDescriptorHandler::GetSpatialLayer() const void Restore(uint8_t* data) override;
uint8_t GetSpatialLayer() const override
{ {
return this->payloadDescriptor->hasSlIndex ? this->payloadDescriptor->slIndex : 0u; return this->payloadDescriptor->hasSlIndex ? this->payloadDescriptor->slIndex : 0u;
} }
uint8_t GetTemporalLayer() const override
inline uint8_t VP9::PayloadDescriptorHandler::GetTemporalLayer() const
{ {
return this->payloadDescriptor->hasTlIndex ? this->payloadDescriptor->tlIndex : 0u; return this->payloadDescriptor->hasTlIndex ? this->payloadDescriptor->tlIndex : 0u;
} }
bool IsKeyFrame() const override
inline bool VP9::PayloadDescriptorHandler::IsKeyFrame() const
{ {
return this->payloadDescriptor->isKeyFrame; return this->payloadDescriptor->isKeyFrame;
} }
private:
std::unique_ptr<PayloadDescriptor> payloadDescriptor;
};
};
} // namespace Codecs } // namespace Codecs
} // namespace RTC } // namespace RTC
......
...@@ -67,18 +67,60 @@ namespace RTC ...@@ -67,18 +67,60 @@ namespace RTC
virtual void FillJsonStats(json& jsonArray) const = 0; virtual void FillJsonStats(json& jsonArray) const = 0;
virtual void FillJsonScore(json& jsonObject) const = 0; virtual void FillJsonScore(json& jsonObject) const = 0;
virtual void HandleRequest(Channel::Request* request); virtual void HandleRequest(Channel::Request* request);
RTC::Media::Kind GetKind() const; RTC::Media::Kind GetKind() const
const RTC::RtpParameters& GetRtpParameters() const; {
const struct RTC::RtpHeaderExtensionIds& GetRtpHeaderExtensionIds() const; return this->kind;
RTC::RtpParameters::Type GetType() const; }
virtual Layers GetPreferredLayers() const; const RTC::RtpParameters& GetRtpParameters() const
const std::vector<uint32_t>& GetMediaSsrcs() const; {
const std::vector<uint32_t>& GetRtxSsrcs() const; return this->rtpParameters;
virtual bool IsActive() const; }
const struct RTC::RtpHeaderExtensionIds& GetRtpHeaderExtensionIds() const
{
return this->rtpHeaderExtensionIds;
}
RTC::RtpParameters::Type GetType() const
{
return this->type;
}
virtual Layers GetPreferredLayers() const
{
// By default return 1:1.
Consumer::Layers layers;
return layers;
}
const std::vector<uint32_t>& GetMediaSsrcs() const
{
return this->mediaSsrcs;
}
const std::vector<uint32_t>& GetRtxSsrcs() const
{
return this->rtxSsrcs;
}
virtual bool IsActive() const
{
// The parent Consumer just checks whether Consumer and Producer are
// not paused and the transport connected.
// clang-format off
return (
this->transportConnected &&
!this->paused &&
!this->producerPaused &&
!this->producerClosed
);
// clang-format on
}
void TransportConnected(); void TransportConnected();
void TransportDisconnected(); void TransportDisconnected();
bool IsPaused() const; bool IsPaused() const
bool IsProducerPaused() const; {
return this->paused;
}
bool IsProducerPaused() const
{
return this->producerPaused;
}
void ProducerPaused(); void ProducerPaused();
void ProducerResumed(); void ProducerResumed();
virtual void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) = 0; virtual void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) = 0;
...@@ -87,7 +129,10 @@ namespace RTC ...@@ -87,7 +129,10 @@ namespace RTC
RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) = 0; RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) = 0;
virtual void ProducerRtcpSenderReport(RTC::RtpStream* rtpStream, bool first) = 0; virtual void ProducerRtcpSenderReport(RTC::RtpStream* rtpStream, bool first) = 0;
void ProducerClosed(); void ProducerClosed();
void SetExternallyManagedBitrate(); void SetExternallyManagedBitrate()
{
this->externallyManagedBitrate = true;
}
virtual uint8_t GetBitratePriority() const = 0; virtual uint8_t GetBitratePriority() const = 0;
virtual uint32_t IncreaseLayer(uint32_t bitrate, bool considerLoss) = 0; virtual uint32_t IncreaseLayer(uint32_t bitrate, bool considerLoss) = 0;
virtual void ApplyLayers() = 0; virtual void ApplyLayers() = 0;
...@@ -146,75 +191,6 @@ namespace RTC ...@@ -146,75 +191,6 @@ namespace RTC
bool producerPaused{ false }; bool producerPaused{ false };
bool producerClosed{ false }; bool producerClosed{ false };
}; };
/* Inline methods. */
inline RTC::Media::Kind Consumer::GetKind() const
{
return this->kind;
}
inline const RTC::RtpParameters& Consumer::GetRtpParameters() const
{
return this->rtpParameters;
}
inline const struct RTC::RtpHeaderExtensionIds& Consumer::GetRtpHeaderExtensionIds() const
{
return this->rtpHeaderExtensionIds;
}
inline RTC::RtpParameters::Type Consumer::GetType() const
{
return this->type;
}
inline Consumer::Layers Consumer::GetPreferredLayers() const
{
// By default return 1:1.
Consumer::Layers layers;
return layers;
}
inline const std::vector<uint32_t>& Consumer::GetMediaSsrcs() const
{
return this->mediaSsrcs;
}
inline const std::vector<uint32_t>& Consumer::GetRtxSsrcs() const
{
return this->rtxSsrcs;
}
inline bool Consumer::IsActive() const
{
// The parent Consumer just checks whether Consumer and Producer are
// not paused and the transport connected.
// clang-format off
return (
this->transportConnected &&
!this->paused &&
!this->producerPaused &&
!this->producerClosed
);
// clang-format on
}
inline bool Consumer::IsPaused() const
{
return this->paused;
}
inline bool Consumer::IsProducerPaused() const
{
return this->producerPaused;
}
inline void Consumer::SetExternallyManagedBitrate()
{
this->externallyManagedBitrate = true;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -32,8 +32,20 @@ namespace RTC ...@@ -32,8 +32,20 @@ namespace RTC
void FillJson(json& jsonObject) const; void FillJson(json& jsonObject) const;
void FillJsonStats(json& jsonArray) const; void FillJsonStats(json& jsonArray) const;
void HandleRequest(Channel::Request* request); void HandleRequest(Channel::Request* request);
const RTC::SctpStreamParameters& GetSctpStreamParameters() const; const RTC::SctpStreamParameters& GetSctpStreamParameters() const
bool IsActive() const; {
return this->sctpStreamParameters;
}
bool IsActive() const
{
// clang-format off
return (
this->transportConnected &&
this->sctpAssociationConnected &&
!this->dataProducerClosed
);
// clang-format on
}
void TransportConnected(); void TransportConnected();
void TransportDisconnected(); void TransportDisconnected();
void SctpAssociationConnected(); void SctpAssociationConnected();
...@@ -48,7 +60,7 @@ namespace RTC ...@@ -48,7 +60,7 @@ namespace RTC
private: private:
// Passed by argument. // Passed by argument.
RTC::DataConsumer::Listener* listener{ nullptr }; RTC::DataConsumer::Listener* listener{ nullptr };
size_t maxSctpMessageSize{ 0 }; size_t maxSctpMessageSize{ 0u };
// Others. // Others.
RTC::SctpStreamParameters sctpStreamParameters; RTC::SctpStreamParameters sctpStreamParameters;
std::string label; std::string label;
...@@ -56,27 +68,9 @@ namespace RTC ...@@ -56,27 +68,9 @@ namespace RTC
bool transportConnected{ false }; bool transportConnected{ false };
bool sctpAssociationConnected{ false }; bool sctpAssociationConnected{ false };
bool dataProducerClosed{ false }; bool dataProducerClosed{ false };
size_t messagesSent{ 0 }; size_t messagesSent{ 0u };
size_t bytesSent{ 0 }; size_t bytesSent{ 0u };
}; };
/* Inline methods. */
inline const RTC::SctpStreamParameters& DataConsumer::GetSctpStreamParameters() const
{
return this->sctpStreamParameters;
}
inline bool DataConsumer::IsActive() const
{
// clang-format off
return (
this->transportConnected &&
this->sctpAssociationConnected &&
!this->dataProducerClosed
);
// clang-format on
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -27,7 +27,10 @@ namespace RTC ...@@ -27,7 +27,10 @@ namespace RTC
void FillJson(json& jsonObject) const; void FillJson(json& jsonObject) const;
void FillJsonStats(json& jsonArray) const; void FillJsonStats(json& jsonArray) const;
void HandleRequest(Channel::Request* request); void HandleRequest(Channel::Request* request);
const RTC::SctpStreamParameters& GetSctpStreamParameters() const; const RTC::SctpStreamParameters& GetSctpStreamParameters() const
{
return this->sctpStreamParameters;
}
void ReceiveSctpMessage(uint32_t ppid, const uint8_t* msg, size_t len); void ReceiveSctpMessage(uint32_t ppid, const uint8_t* msg, size_t len);
public: public:
...@@ -41,16 +44,9 @@ namespace RTC ...@@ -41,16 +44,9 @@ namespace RTC
RTC::SctpStreamParameters sctpStreamParameters; RTC::SctpStreamParameters sctpStreamParameters;
std::string label; std::string label;
std::string protocol; std::string protocol;
size_t messagesReceived{ 0 }; size_t messagesReceived{ 0u };
size_t bytesReceived{ 0 }; size_t bytesReceived{ 0u };
}; };
/* Inline methods. */
inline const RTC::SctpStreamParameters& DataProducer::GetSctpStreamParameters() const
{
return this->sctpStreamParameters;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -94,10 +94,41 @@ namespace RTC ...@@ -94,10 +94,41 @@ namespace RTC
public: public:
static void ClassInit(); static void ClassInit();
static void ClassDestroy(); static void ClassDestroy();
static Role StringToRole(const std::string& role); static Role StringToRole(const std::string& role)
static FingerprintAlgorithm GetFingerprintAlgorithm(const std::string& fingerprint); {
static std::string& GetFingerprintAlgorithmString(FingerprintAlgorithm fingerprint); auto it = DtlsTransport::string2Role.find(role);
static bool IsDtls(const uint8_t* data, size_t len);
if (it != DtlsTransport::string2Role.end())
return it->second;
else
return DtlsTransport::Role::NONE;
}
static FingerprintAlgorithm GetFingerprintAlgorithm(const std::string& fingerprint)
{
auto it = DtlsTransport::string2FingerprintAlgorithm.find(fingerprint);
if (it != DtlsTransport::string2FingerprintAlgorithm.end())
return it->second;
else
return DtlsTransport::FingerprintAlgorithm::NONE;
}
static std::string& GetFingerprintAlgorithmString(FingerprintAlgorithm fingerprint)
{
auto it = DtlsTransport::fingerprintAlgorithm2String.find(fingerprint);
return it->second;
}
static bool IsDtls(const uint8_t* data, size_t len)
{
// clang-format off
return (
// Minimum DTLS record length is 13 bytes.
(len >= 13) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 19 && data[0] < 64)
);
// clang-format on
}
private: private:
static void GenerateCertificateAndPrivateKey(); static void GenerateCertificateAndPrivateKey();
...@@ -123,15 +154,40 @@ namespace RTC ...@@ -123,15 +154,40 @@ namespace RTC
public: public:
void Dump() const; void Dump() const;
void Run(Role localRole); void Run(Role localRole);
std::vector<Fingerprint>& GetLocalFingerprints() const; std::vector<Fingerprint>& GetLocalFingerprints() const
{
return DtlsTransport::localFingerprints;
}
bool SetRemoteFingerprint(Fingerprint fingerprint); bool SetRemoteFingerprint(Fingerprint fingerprint);
void ProcessDtlsData(const uint8_t* data, size_t len); void ProcessDtlsData(const uint8_t* data, size_t len);
DtlsState GetState() const; DtlsState GetState() const
Role GetLocalRole() const; {
return this->state;
}
Role GetLocalRole() const
{
return this->localRole;
}
void SendApplicationData(const uint8_t* data, size_t len); void SendApplicationData(const uint8_t* data, size_t len);
private: private:
bool IsRunning() const; bool IsRunning() const
{
switch (this->state)
{
case DtlsState::NEW:
return false;
case DtlsState::CONNECTING:
case DtlsState::CONNECTED:
return true;
case DtlsState::FAILED:
case DtlsState::CLOSED:
return false;
}
// Make GCC 4.9 happy.
return false;
}
void Reset(); void Reset();
bool CheckStatus(int returnCode); bool CheckStatus(int returnCode);
void SendPendingOutgoingDtlsData(); void SendPendingOutgoingDtlsData();
...@@ -165,84 +221,6 @@ namespace RTC ...@@ -165,84 +221,6 @@ namespace RTC
bool handshakeDoneNow{ false }; bool handshakeDoneNow{ false };
std::string remoteCert; std::string remoteCert;
}; };
/* Inline static methods. */
inline DtlsTransport::Role DtlsTransport::StringToRole(const std::string& role)
{
auto it = DtlsTransport::string2Role.find(role);
if (it != DtlsTransport::string2Role.end())
return it->second;
else
return DtlsTransport::Role::NONE;
}
inline DtlsTransport::FingerprintAlgorithm DtlsTransport::GetFingerprintAlgorithm(
const std::string& fingerprint)
{
auto it = DtlsTransport::string2FingerprintAlgorithm.find(fingerprint);
if (it != DtlsTransport::string2FingerprintAlgorithm.end())
return it->second;
else
return DtlsTransport::FingerprintAlgorithm::NONE;
}
inline std::string& DtlsTransport::GetFingerprintAlgorithmString(
DtlsTransport::FingerprintAlgorithm fingerprint)
{
auto it = DtlsTransport::fingerprintAlgorithm2String.find(fingerprint);
return it->second;
}
inline bool DtlsTransport::IsDtls(const uint8_t* data, size_t len)
{
// clang-format off
return (
// Minimum DTLS record length is 13 bytes.
(len >= 13) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 19 && data[0] < 64)
);
// clang-format on
}
/* Inline instance methods. */
inline std::vector<DtlsTransport::Fingerprint>& DtlsTransport::GetLocalFingerprints() const
{
return DtlsTransport::localFingerprints;
}
inline DtlsTransport::DtlsState DtlsTransport::GetState() const
{
return this->state;
}
inline DtlsTransport::Role DtlsTransport::GetLocalRole() const
{
return this->localRole;
}
inline bool DtlsTransport::IsRunning() const
{
switch (this->state)
{
case DtlsState::NEW:
return false;
case DtlsState::CONNECTING:
case DtlsState::CONNECTED:
return true;
case DtlsState::FAILED:
case DtlsState::CLOSED:
return false;
}
// Make GCC 4.9 happy.
return false;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -33,50 +33,44 @@ namespace RTC ...@@ -33,50 +33,44 @@ namespace RTC
}; };
public: public:
IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority); IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority)
IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority, std::string& announcedIp);
IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority);
IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority, std::string& announcedIp);
void FillJson(json& jsonObject) const;
private:
// Others.
std::string foundation;
uint32_t priority{ 0 };
std::string ip;
Protocol protocol;
uint16_t port{ 0 };
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()), : foundation("udpcandidate"), priority(priority), ip(udpSocket->GetLocalIp()),
protocol(Protocol::UDP), port(udpSocket->GetLocalPort()), type(CandidateType::HOST) protocol(Protocol::UDP), port(udpSocket->GetLocalPort()), type(CandidateType::HOST)
{ {
} }
inline IceCandidate::IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority, std::string& announcedIp) IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority, std::string& announcedIp)
: foundation("udpcandidate"), priority(priority), ip(announcedIp), protocol(Protocol::UDP), : foundation("udpcandidate"), priority(priority), ip(announcedIp), protocol(Protocol::UDP),
port(udpSocket->GetLocalPort()), type(CandidateType::HOST) port(udpSocket->GetLocalPort()), type(CandidateType::HOST)
{ {
} }
inline IceCandidate::IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority) IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority)
: foundation("tcpcandidate"), priority(priority), ip(tcpServer->GetLocalIp()), : foundation("tcpcandidate"), priority(priority), ip(tcpServer->GetLocalIp()),
protocol(Protocol::TCP), port(tcpServer->GetLocalPort()), type(CandidateType::HOST), protocol(Protocol::TCP), port(tcpServer->GetLocalPort()), type(CandidateType::HOST),
tcpType(TcpCandidateType::PASSIVE) tcpType(TcpCandidateType::PASSIVE)
{ {
} }
inline IceCandidate::IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority, std::string& announcedIp) IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority, std::string& announcedIp)
: foundation("tcpcandidate"), priority(priority), ip(announcedIp), protocol(Protocol::TCP), : foundation("tcpcandidate"), priority(priority), ip(announcedIp), protocol(Protocol::TCP),
port(tcpServer->GetLocalPort()), type(CandidateType::HOST), tcpType(TcpCandidateType::PASSIVE) port(tcpServer->GetLocalPort()), type(CandidateType::HOST),
tcpType(TcpCandidateType::PASSIVE)
{ {
} }
void FillJson(json& jsonObject) const;
private:
// Others.
std::string foundation;
uint32_t priority{ 0u };
std::string ip;
Protocol protocol;
uint16_t port{ 0u };
CandidateType type{ CandidateType::HOST };
TcpCandidateType tcpType{ TcpCandidateType::PASSIVE };
};
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -45,12 +45,32 @@ namespace RTC ...@@ -45,12 +45,32 @@ namespace RTC
public: public:
void ProcessStunPacket(RTC::StunPacket* packet, RTC::TransportTuple* tuple); void ProcessStunPacket(RTC::StunPacket* packet, RTC::TransportTuple* tuple);
const std::string& GetUsernameFragment() const; const std::string& GetUsernameFragment() const
const std::string& GetPassword() const; {
IceState GetState() const; return this->usernameFragment;
RTC::TransportTuple* GetSelectedTuple() const; }
void SetUsernameFragment(const std::string& usernameFragment); const std::string& GetPassword() const
void SetPassword(const std::string& password); {
return this->password;
}
IceState GetState() const
{
return this->state;
}
RTC::TransportTuple* GetSelectedTuple() const
{
return this->selectedTuple;
}
void SetUsernameFragment(const std::string& usernameFragment)
{
this->oldUsernameFragment = this->usernameFragment;
this->usernameFragment = usernameFragment;
}
void SetPassword(const std::string& password)
{
this->oldPassword = this->password;
this->password = password;
}
bool IsValidTuple(const RTC::TransportTuple* tuple) const; bool IsValidTuple(const RTC::TransportTuple* tuple) const;
void RemoveTuple(RTC::TransportTuple* tuple); void RemoveTuple(RTC::TransportTuple* tuple);
// This should be just called in 'connected' or completed' state // This should be just called in 'connected' or completed' state
...@@ -85,40 +105,6 @@ namespace RTC ...@@ -85,40 +105,6 @@ namespace RTC
std::list<RTC::TransportTuple> tuples; std::list<RTC::TransportTuple> tuples;
RTC::TransportTuple* selectedTuple{ nullptr }; RTC::TransportTuple* selectedTuple{ nullptr };
}; };
/* Inline instance methods. */
inline const std::string& IceServer::GetUsernameFragment() const
{
return this->usernameFragment;
}
inline const std::string& IceServer::GetPassword() const
{
return this->password;
}
inline IceServer::IceState IceServer::GetState() const
{
return this->state;
}
inline RTC::TransportTuple* IceServer::GetSelectedTuple() const
{
return this->selectedTuple;
}
inline void IceServer::SetUsernameFragment(const std::string& usernameFragment)
{
this->oldUsernameFragment = this->usernameFragment;
this->usernameFragment = usernameFragment;
}
inline void IceServer::SetPassword(const std::string& password)
{
this->oldPassword = this->password;
this->password = password;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -19,10 +19,22 @@ namespace RTC ...@@ -19,10 +19,22 @@ namespace RTC
PendingKeyFrameInfo(Listener* listener, uint32_t ssrc); PendingKeyFrameInfo(Listener* listener, uint32_t ssrc);
~PendingKeyFrameInfo(); ~PendingKeyFrameInfo();
uint32_t GetSsrc() const; uint32_t GetSsrc() const
void SetRetryOnTimeout(bool notify); {
bool GetRetryOnTimeout() const; return this->ssrc;
void Restart(); }
void SetRetryOnTimeout(bool notify)
{
this->retryOnTimeout = notify;
}
bool GetRetryOnTimeout() const
{
return this->retryOnTimeout;
}
void Restart()
{
return this->timer->Restart();
}
/* Pure virtual methods inherited from Timer::Listener. */ /* Pure virtual methods inherited from Timer::Listener. */
public: public:
...@@ -48,9 +60,18 @@ namespace RTC ...@@ -48,9 +60,18 @@ namespace RTC
KeyFrameRequestDelayer(Listener* listener, uint32_t ssrc, uint32_t delay); KeyFrameRequestDelayer(Listener* listener, uint32_t ssrc, uint32_t delay);
~KeyFrameRequestDelayer(); ~KeyFrameRequestDelayer();
uint32_t GetSsrc() const; uint32_t GetSsrc() const
bool GetKeyFrameRequested() const; {
void SetKeyFrameRequested(bool flag); return this->ssrc;
}
bool GetKeyFrameRequested() const
{
return this->keyFrameRequested;
}
void SetKeyFrameRequested(bool flag)
{
this->keyFrameRequested = flag;
}
/* Pure virtual methods inherited from Timer::Listener. */ /* Pure virtual methods inherited from Timer::Listener. */
public: public:
...@@ -97,39 +118,4 @@ namespace RTC ...@@ -97,39 +118,4 @@ namespace RTC
}; };
} // namespace RTC } // namespace RTC
inline uint32_t RTC::PendingKeyFrameInfo::GetSsrc() const
{
return this->ssrc;
}
inline void RTC::PendingKeyFrameInfo::SetRetryOnTimeout(bool notify)
{
this->retryOnTimeout = notify;
}
inline bool RTC::PendingKeyFrameInfo::GetRetryOnTimeout() const
{
return this->retryOnTimeout;
}
inline void RTC::PendingKeyFrameInfo::Restart()
{
return this->timer->Restart();
}
inline uint32_t RTC::KeyFrameRequestDelayer::GetSsrc() const
{
return this->ssrc;
}
inline bool RTC::KeyFrameRequestDelayer::GetKeyFrameRequested() const
{
return this->keyFrameRequested;
}
inline void RTC::KeyFrameRequestDelayer::SetKeyFrameRequested(bool flag)
{
this->keyFrameRequested = flag;
}
#endif #endif
...@@ -25,7 +25,9 @@ namespace RTC ...@@ -25,7 +25,9 @@ namespace RTC
struct NackInfo struct NackInfo
{ {
NackInfo() = default; NackInfo() = default;
explicit NackInfo(uint16_t seq, uint16_t sendAtSeq); explicit NackInfo(uint16_t seq, uint16_t sendAtSeq) : seq(seq), sendAtSeq(sendAtSeq)
{
}
uint16_t seq{ 0u }; uint16_t seq{ 0u };
uint16_t sendAtSeq{ 0u }; uint16_t sendAtSeq{ 0u };
...@@ -44,8 +46,14 @@ namespace RTC ...@@ -44,8 +46,14 @@ namespace RTC
~NackGenerator() override; ~NackGenerator() override;
bool ReceivePacket(RTC::RtpPacket* packet, bool isRecovered); bool ReceivePacket(RTC::RtpPacket* packet, bool isRecovered);
size_t GetNackListLength() const; size_t GetNackListLength() const
void UpdateRtt(uint32_t rtt); {
return this->nackList.size();
}
void UpdateRtt(uint32_t rtt)
{
this->rtt = rtt;
}
void Reset(); void Reset();
private: private:
...@@ -71,23 +79,6 @@ namespace RTC ...@@ -71,23 +79,6 @@ namespace RTC
uint16_t lastSeq{ 0u }; // Seq number of last valid packet. uint16_t lastSeq{ 0u }; // Seq number of last valid packet.
uint32_t rtt{ 0u }; // Round trip time (ms). uint32_t rtt{ 0u }; // Round trip time (ms).
}; };
// Inline instance methods.
inline void NackGenerator::UpdateRtt(uint32_t rtt)
{
this->rtt = rtt;
}
inline NackGenerator::NackInfo::NackInfo(uint16_t seq, uint16_t sendAtSeq)
: seq(seq), sendAtSeq(sendAtSeq)
{
}
inline size_t NackGenerator::GetNackListLength() const
{
return this->nackList.size();
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -28,7 +28,10 @@ namespace RTC ...@@ -28,7 +28,10 @@ namespace RTC
uint32_t GetDesiredBitrate() const override; uint32_t GetDesiredBitrate() const override;
void SendRtpPacket(RTC::RtpPacket* packet) override; void SendRtpPacket(RTC::RtpPacket* packet) override;
void GetRtcp(RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t nowMs) override; void GetRtcp(RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t nowMs) override;
std::vector<RTC::RtpStreamSend*> GetRtpStreams() override; std::vector<RTC::RtpStreamSend*> GetRtpStreams() override
{
return this->rtpStreams;
}
void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override; void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override;
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override; void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override;
void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType, uint32_t ssrc) override; void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType, uint32_t ssrc) override;
...@@ -58,13 +61,6 @@ namespace RTC ...@@ -58,13 +61,6 @@ namespace RTC
std::unordered_map<RTC::RtpStreamSend*, bool> mapRtpStreamSyncRequired; std::unordered_map<RTC::RtpStreamSend*, bool> mapRtpStreamSyncRequired;
std::unordered_map<RTC::RtpStreamSend*, RTC::SeqManager<uint16_t>> mapRtpStreamRtpSeqManager; std::unordered_map<RTC::RtpStreamSend*, RTC::SeqManager<uint16_t>> mapRtpStreamRtpSeqManager;
}; };
// Inline methods.
inline std::vector<RTC::RtpStreamSend*> PipeConsumer::GetRtpStreams()
{
return this->rtpStreams;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -21,43 +21,33 @@ namespace RTC ...@@ -21,43 +21,33 @@ namespace RTC
}; };
public: public:
static uv_udp_t* BindUdp(std::string& ip); static uv_udp_t* BindUdp(std::string& ip)
static uv_tcp_t* BindTcp(std::string& ip);
static void UnbindUdp(std::string& ip, uint16_t port);
static void UnbindTcp(std::string& ip, uint16_t port);
static void FillJson(json& jsonObject);
private:
static uv_handle_t* Bind(Transport transport, std::string& ip);
static void Unbind(Transport transport, std::string& ip, uint16_t port);
static std::vector<bool>& GetPorts(Transport transport, const std::string& ip);
private:
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)); return reinterpret_cast<uv_udp_t*>(Bind(Transport::UDP, ip));
} }
static uv_tcp_t* BindTcp(std::string& ip)
inline uv_tcp_t* PortManager::BindTcp(std::string& ip)
{ {
return reinterpret_cast<uv_tcp_t*>(Bind(Transport::TCP, ip)); return reinterpret_cast<uv_tcp_t*>(Bind(Transport::TCP, ip));
} }
static void UnbindUdp(std::string& ip, uint16_t port)
inline void PortManager::UnbindUdp(std::string& ip, uint16_t port)
{ {
return Unbind(Transport::UDP, ip, port); return Unbind(Transport::UDP, ip, port);
} }
static void UnbindTcp(std::string& ip, uint16_t port)
inline void PortManager::UnbindTcp(std::string& ip, uint16_t port)
{ {
return Unbind(Transport::TCP, ip, port); return Unbind(Transport::TCP, ip, port);
} }
static void FillJson(json& jsonObject);
private:
static uv_handle_t* Bind(Transport transport, std::string& ip);
static void Unbind(Transport transport, std::string& ip, uint16_t port);
static std::vector<bool>& GetPorts(Transport transport, const std::string& ip);
private:
static std::unordered_map<std::string, std::vector<bool>> mapUdpIpPorts;
static std::unordered_map<std::string, std::vector<bool>> mapTcpIpPorts;
};
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -90,12 +90,30 @@ namespace RTC ...@@ -90,12 +90,30 @@ namespace RTC
void FillJson(json& jsonObject) const; void FillJson(json& jsonObject) const;
void FillJsonStats(json& jsonArray) const; void FillJsonStats(json& jsonArray) const;
void HandleRequest(Channel::Request* request); void HandleRequest(Channel::Request* request);
RTC::Media::Kind GetKind() const; RTC::Media::Kind GetKind() const
const RTC::RtpParameters& GetRtpParameters() const; {
const struct RTC::RtpHeaderExtensionIds& GetRtpHeaderExtensionIds() const; return this->kind;
RTC::RtpParameters::Type GetType() const; }
bool IsPaused() const; const RTC::RtpParameters& GetRtpParameters() const
std::map<RTC::RtpStreamRecv*, uint32_t>& GetRtpStreams(); {
return this->rtpParameters;
}
const struct RTC::RtpHeaderExtensionIds& GetRtpHeaderExtensionIds() const
{
return this->rtpHeaderExtensionIds;
}
RTC::RtpParameters::Type GetType() const
{
return this->type;
}
bool IsPaused() const
{
return this->paused;
}
std::map<RTC::RtpStreamRecv*, uint32_t>& GetRtpStreams()
{
return this->mapRtpStreamMappedSsrc;
}
ReceiveRtpPacketResult ReceiveRtpPacket(RTC::RtpPacket* packet); ReceiveRtpPacketResult ReceiveRtpPacket(RTC::RtpPacket* packet);
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report); void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void ReceiveRtcpXrDelaySinceLastRr(RTC::RTCP::DelaySinceLastRr::SsrcInfo* ssrcInfo); void ReceiveRtcpXrDelaySinceLastRr(RTC::RTCP::DelaySinceLastRr::SsrcInfo* ssrcInfo);
...@@ -150,45 +168,13 @@ namespace RTC ...@@ -150,45 +168,13 @@ namespace RTC
bool paused{ false }; bool paused{ false };
RTC::RtpPacket* currentRtpPacket{ nullptr }; RTC::RtpPacket* currentRtpPacket{ nullptr };
// Timestamp when last RTCP was sent. // Timestamp when last RTCP was sent.
uint64_t lastRtcpSentTime{ 0 }; uint64_t lastRtcpSentTime{ 0u };
uint16_t maxRtcpInterval{ 0 }; uint16_t maxRtcpInterval{ 0u };
// Video orientation. // Video orientation.
bool videoOrientationDetected{ false }; bool videoOrientationDetected{ false };
struct VideoOrientation videoOrientation; struct VideoOrientation videoOrientation;
struct TraceEventTypes traceEventTypes; struct TraceEventTypes traceEventTypes;
}; };
/* Inline methods. */
inline RTC::Media::Kind Producer::GetKind() const
{
return this->kind;
}
inline const RTC::RtpParameters& Producer::GetRtpParameters() const
{
return this->rtpParameters;
}
inline const struct RTC::RtpHeaderExtensionIds& Producer::GetRtpHeaderExtensionIds() const
{
return this->rtpHeaderExtensionIds;
}
inline RTC::RtpParameters::Type Producer::GetType() const
{
return this->type;
}
inline bool Producer::IsPaused() const
{
return this->paused;
}
inline std::map<RTC::RtpStreamRecv*, uint32_t>& Producer::GetRtpStreams()
{
return this->mapRtpStreamMappedSsrc;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -19,44 +19,44 @@ namespace RTC ...@@ -19,44 +19,44 @@ namespace RTC
static ByePacket* Parse(const uint8_t* data, size_t len); static ByePacket* Parse(const uint8_t* data, size_t len);
public: public:
ByePacket(); ByePacket() : Packet(Type::BYE)
explicit ByePacket(CommonHeader* commonHeader); {
}
explicit ByePacket(CommonHeader* commonHeader) : Packet(commonHeader)
{
}
~ByePacket() override = default; ~ByePacket() override = default;
void AddSsrc(uint32_t ssrc); void AddSsrc(uint32_t ssrc)
void SetReason(const std::string& reason);
const std::string& GetReason() const;
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<uint32_t> ssrcs;
std::string reason;
};
/* Inline instance methods. */
inline ByePacket::ByePacket() : Packet(Type::BYE)
{ {
this->ssrcs.push_back(ssrc);
} }
void SetReason(const std::string& reason)
inline ByePacket::ByePacket(CommonHeader* commonHeader) : Packet(commonHeader) {
this->reason = reason;
}
const std::string& GetReason() const
{ {
return this->reason;
}
Iterator Begin()
{
return this->ssrcs.begin();
}
Iterator End()
{
return this->ssrcs.end();
} }
inline size_t ByePacket::GetCount() const /* 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->ssrcs.size(); return this->ssrcs.size();
} }
size_t GetSize() const override
inline size_t ByePacket::GetSize() const
{ {
size_t size = sizeof(Packet::CommonHeader); size_t size = sizeof(Packet::CommonHeader);
...@@ -73,30 +73,10 @@ namespace RTC ...@@ -73,30 +73,10 @@ namespace RTC
return (size + 3) & ~3; return (size + 3) & ~3;
} }
inline void ByePacket::AddSsrc(uint32_t ssrc) private:
{ std::vector<uint32_t> ssrcs;
this->ssrcs.push_back(ssrc); std::string reason;
} };
inline void ByePacket::SetReason(const std::string& reason)
{
this->reason = reason;
}
inline const std::string& ByePacket::GetReason() const
{
return this->reason;
}
inline ByePacket::Iterator ByePacket::Begin()
{
return this->ssrcs.begin();
}
inline ByePacket::Iterator ByePacket::End()
{
return this->ssrcs.end();
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -18,77 +18,48 @@ namespace RTC ...@@ -18,77 +18,48 @@ namespace RTC
CompoundPacket() = default; CompoundPacket() = default;
public: public:
const uint8_t* GetData() const; const uint8_t* GetData() const
size_t GetSize() const;
size_t GetSenderReportCount() const;
size_t GetReceiverReportCount() const;
void Dump();
void AddSenderReport(SenderReport* report);
void AddReceiverReport(ReceiverReport* report);
void AddSdesChunk(SdesChunk* chunk);
void AddReceiverReferenceTime(ReceiverReferenceTime* report);
bool HasSenderReport();
bool HasReceiverReferenceTime();
void Serialize(uint8_t* data);
private:
uint8_t* header{ nullptr };
size_t size{ 0 };
SenderReportPacket senderReportPacket;
ReceiverReportPacket receiverReportPacket;
SdesPacket sdesPacket;
ExtendedReportPacket xrPacket;
};
/* Inline methods. */
inline const uint8_t* CompoundPacket::GetData() const
{ {
return this->header; return this->header;
} }
size_t GetSize() const
inline size_t CompoundPacket::GetSize() const
{ {
return this->size; return this->size;
} }
size_t GetSenderReportCount() const
inline size_t CompoundPacket::GetSenderReportCount() const
{ {
return this->senderReportPacket.GetCount(); return this->senderReportPacket.GetCount();
} }
size_t GetReceiverReportCount() const
inline size_t CompoundPacket::GetReceiverReportCount() const
{ {
return this->receiverReportPacket.GetCount(); return this->receiverReportPacket.GetCount();
} }
void Dump();
inline void CompoundPacket::AddReceiverReport(ReceiverReport* report) void AddSenderReport(SenderReport* report);
{ void AddReceiverReport(ReceiverReport* report);
this->receiverReportPacket.AddReport(report); void AddSdesChunk(SdesChunk* chunk);
} void AddReceiverReferenceTime(ReceiverReferenceTime* report);
bool HasSenderReport()
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(); return this->senderReportPacket.Begin() != this->senderReportPacket.End();
} }
bool HasReceiverReferenceTime()
inline bool CompoundPacket::HasReceiverReferenceTime()
{ {
return std::any_of( return std::any_of(
this->xrPacket.Begin(), this->xrPacket.End(), [](const ExtendedReportBlock* report) { this->xrPacket.Begin(), this->xrPacket.End(), [](const ExtendedReportBlock* report) {
return report->GetType() == ExtendedReportBlock::Type::RRT; return report->GetType() == ExtendedReportBlock::Type::RRT;
}); });
} }
void Serialize(uint8_t* data);
private:
uint8_t* header{ nullptr };
size_t size{ 0 };
SenderReportPacket senderReportPacket;
ReceiverReportPacket receiverReportPacket;
SdesPacket sdesPacket;
ExtendedReportPacket xrPacket;
};
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -29,18 +29,39 @@ namespace RTC ...@@ -29,18 +29,39 @@ namespace RTC
static std::map<typename T::MessageType, std::string> type2String; static std::map<typename T::MessageType, std::string> type2String;
public: public:
typename T::MessageType GetMessageType() const; typename T::MessageType GetMessageType() const
uint32_t GetSenderSsrc() const; {
void SetSenderSsrc(uint32_t ssrc); return this->messageType;
uint32_t GetMediaSsrc() const; }
void SetMediaSsrc(uint32_t ssrc); uint32_t GetSenderSsrc() const
{
return uint32_t{ ntohl(this->header->senderSsrc) };
}
void SetSenderSsrc(uint32_t ssrc)
{
this->header->senderSsrc = uint32_t{ htonl(ssrc) };
}
uint32_t GetMediaSsrc() const
{
return uint32_t{ ntohl(this->header->mediaSsrc) };
}
void SetMediaSsrc(uint32_t ssrc)
{
this->header->mediaSsrc = uint32_t{ htonl(ssrc) };
}
/* Pure virtual methods inherited from Packet. */ /* Pure virtual methods inherited from Packet. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override; size_t GetCount() const override
size_t GetSize() const override; {
return static_cast<size_t>(GetMessageType());
}
size_t GetSize() const override
{
return sizeof(CommonHeader) + sizeof(Header);
}
protected: protected:
explicit FeedbackPacket(CommonHeader* commonHeader); explicit FeedbackPacket(CommonHeader* commonHeader);
...@@ -92,50 +113,6 @@ namespace RTC ...@@ -92,50 +113,6 @@ namespace RTC
using FeedbackPsPacket = FeedbackPacket<RTC::RTCP::FeedbackPs>; using FeedbackPsPacket = FeedbackPacket<RTC::RTCP::FeedbackPs>;
using FeedbackRtpPacket = FeedbackPacket<RTC::RTCP::FeedbackRtp>; using FeedbackRtpPacket = FeedbackPacket<RTC::RTCP::FeedbackRtp>;
/* Inline instance methods. */
template<typename T>
inline typename T::MessageType FeedbackPacket<T>::GetMessageType() const
{
return this->messageType;
}
template<typename T>
inline size_t FeedbackPacket<T>::GetCount() const
{
return static_cast<size_t>(this->GetMessageType());
}
template<typename T>
inline size_t FeedbackPacket<T>::GetSize() const
{
return sizeof(CommonHeader) + sizeof(Header);
}
template<typename T>
inline uint32_t FeedbackPacket<T>::GetSenderSsrc() const
{
return uint32_t{ ntohl(this->header->senderSsrc) };
}
template<typename T>
inline void FeedbackPacket<T>::SetSenderSsrc(uint32_t ssrc)
{
this->header->senderSsrc = uint32_t{ htonl(ssrc) };
}
template<typename T>
inline uint32_t FeedbackPacket<T>::GetMediaSsrc() const
{
return uint32_t{ ntohl(this->header->mediaSsrc) };
}
template<typename T>
inline void FeedbackPacket<T>::SetMediaSsrc(uint32_t ssrc)
{
this->header->mediaSsrc = uint32_t{ htonl(ssrc) };
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -11,28 +11,7 @@ namespace RTC ...@@ -11,28 +11,7 @@ namespace RTC
{ {
public: public:
template<typename Item> template<typename Item>
static Item* Parse(const uint8_t* data, size_t len); static Item* Parse(const uint8_t* data, size_t len)
public:
bool IsCorrect() const;
protected:
virtual ~FeedbackItem();
public:
virtual void Dump() const = 0;
virtual void Serialize();
virtual size_t Serialize(uint8_t* buffer) = 0;
virtual size_t GetSize() const = 0;
protected:
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. // data size must be >= header.
if (sizeof(typename Item::Header) > len) if (sizeof(typename Item::Header) > len)
...@@ -44,25 +23,34 @@ namespace RTC ...@@ -44,25 +23,34 @@ namespace RTC
return new Item(header); return new Item(header);
} }
/* Inline instance methods */ public:
bool IsCorrect() const
{
return this->isCorrect;
}
inline FeedbackItem::~FeedbackItem() protected:
virtual ~FeedbackItem()
{ {
delete[] this->raw; delete[] this->raw;
} }
inline void FeedbackItem::Serialize() public:
virtual void Dump() const = 0;
virtual void Serialize()
{ {
delete[] this->raw; delete[] this->raw;
this->raw = new uint8_t[this->GetSize()]; this->raw = new uint8_t[this->GetSize()];
this->Serialize(this->raw); this->Serialize(this->raw);
} }
virtual size_t Serialize(uint8_t* buffer) = 0;
virtual size_t GetSize() const = 0;
inline bool FeedbackItem::IsCorrect() const protected:
{ uint8_t* raw{ nullptr };
return this->isCorrect; bool isCorrect{ true };
} };
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -20,40 +20,14 @@ namespace RTC ...@@ -20,40 +20,14 @@ namespace RTC
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackPsItemsPacket(CommonHeader* commonHeader); explicit FeedbackPsItemsPacket(CommonHeader* commonHeader) : FeedbackPsPacket(commonHeader)
explicit FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0);
~FeedbackPsItemsPacket();
void AddItem(Item* item);
Iterator Begin();
Iterator 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)
{ {
} }
explicit FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0)
template<typename Item>
inline FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackPsPacket(Item::messageType, senderSsrc, mediaSsrc) : FeedbackPsPacket(Item::messageType, senderSsrc, mediaSsrc)
{ {
} }
~FeedbackPsItemsPacket()
template<typename Item>
FeedbackPsItemsPacket<Item>::~FeedbackPsItemsPacket()
{ {
for (auto* item : this->items) for (auto* item : this->items)
{ {
...@@ -61,36 +35,38 @@ namespace RTC ...@@ -61,36 +35,38 @@ namespace RTC
} }
} }
template<typename Item> void AddItem(Item* item)
inline size_t FeedbackPsItemsPacket<Item>::GetSize() const
{ {
size_t size = FeedbackPsPacket::GetSize(); this->items.push_back(item);
}
for (auto* item : this->items) Iterator Begin()
{ {
size += item->GetSize(); return this->items.begin();
} }
Iterator End()
return size; {
return this->items.end();
} }
template<typename Item> /* Pure virtual methods inherited from Packet. */
inline void FeedbackPsItemsPacket<Item>::AddItem(Item* item) public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override
{ {
this->items.push_back(item); size_t size = FeedbackPsPacket::GetSize();
}
template<typename Item> for (auto* item : this->items)
inline typename FeedbackPsItemsPacket<Item>::Iterator FeedbackPsItemsPacket<Item>::Begin()
{ {
return this->items.begin(); size += item->GetSize();
} }
template<typename Item> return size;
inline typename FeedbackPsItemsPacket<Item>::Iterator FeedbackPsItemsPacket<Item>::End()
{
return this->items.end();
} }
private:
std::vector<Item*> items;
};
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -23,28 +23,7 @@ namespace RTC ...@@ -23,28 +23,7 @@ namespace RTC
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackPsAfbPacket( explicit FeedbackPsAfbPacket(
CommonHeader* commonHeader, Application application = Application::UNKNOWN); CommonHeader* commonHeader, Application application = Application::UNKNOWN)
FeedbackPsAfbPacket(
uint32_t senderSsrc, uint32_t mediaSsrc, Application application = Application::UNKNOWN);
~FeedbackPsAfbPacket() override = default;
Application GetApplication() const;
/* Pure virtual methods inherited from Packet. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
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) : FeedbackPsPacket(commonHeader)
{ {
this->size = ((static_cast<size_t>(ntohs(commonHeader->length)) + 1) * 4) - this->size = ((static_cast<size_t>(ntohs(commonHeader->length)) + 1) * 4) -
...@@ -54,23 +33,33 @@ namespace RTC ...@@ -54,23 +33,33 @@ namespace RTC
this->application = application; this->application = application;
} }
FeedbackPsAfbPacket(
inline FeedbackPsAfbPacket::FeedbackPsAfbPacket( uint32_t senderSsrc, uint32_t mediaSsrc, Application application = Application::UNKNOWN)
uint32_t senderSsrc, uint32_t mediaSsrc, Application application)
: FeedbackPsPacket(FeedbackPs::MessageType::AFB, senderSsrc, mediaSsrc) : FeedbackPsPacket(FeedbackPs::MessageType::AFB, senderSsrc, mediaSsrc)
{ {
this->application = application; this->application = application;
} }
~FeedbackPsAfbPacket() override = default;
inline FeedbackPsAfbPacket::Application FeedbackPsAfbPacket::GetApplication() const Application GetApplication() const
{ {
return this->application; return this->application;
} }
inline size_t FeedbackPsAfbPacket::GetSize() const /* Pure virtual methods inherited from Packet. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override
{ {
return FeedbackPsPacket::GetSize() + this->size; return FeedbackPsPacket::GetSize() + this->size;
} }
private:
Application application{ Application::UNKNOWN };
uint8_t* data{ nullptr };
size_t size{ 0 };
};
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -38,19 +38,32 @@ namespace RTC ...@@ -38,19 +38,32 @@ namespace RTC
static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::FIR }; static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::FIR };
public: public:
explicit FeedbackPsFirItem(Header* header); explicit FeedbackPsFirItem(Header* header) : header(header)
explicit FeedbackPsFirItem(FeedbackPsFirItem* item); {
}
explicit FeedbackPsFirItem(FeedbackPsFirItem* item) : header(item->header)
{
}
FeedbackPsFirItem(uint32_t ssrc, uint8_t sequenceNumber); FeedbackPsFirItem(uint32_t ssrc, uint8_t sequenceNumber);
~FeedbackPsFirItem() override = default; ~FeedbackPsFirItem() override = default;
uint32_t GetSsrc() const; uint32_t GetSsrc() const
uint8_t GetSequenceNumber() const; {
return uint32_t{ ntohl(this->header->ssrc) };
}
uint8_t GetSequenceNumber() const
{
return this->header->sequenceNumber;
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return sizeof(Header);
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -58,31 +71,6 @@ namespace RTC ...@@ -58,31 +71,6 @@ namespace RTC
// Fir packet declaration. // Fir packet declaration.
using FeedbackPsFirPacket = FeedbackPsItemsPacket<FeedbackPsFirItem>; using FeedbackPsFirPacket = FeedbackPsItemsPacket<FeedbackPsFirItem>;
/* Inline instance methods. */
inline FeedbackPsFirItem::FeedbackPsFirItem(Header* header) : header(header)
{
}
inline FeedbackPsFirItem::FeedbackPsFirItem(FeedbackPsFirItem* item) : header(item->header)
{
}
inline size_t FeedbackPsFirItem::GetSize() const
{
return sizeof(Header);
}
inline uint32_t FeedbackPsFirItem::GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
inline uint8_t FeedbackPsFirItem::GetSequenceNumber() const
{
return this->header->sequenceNumber;
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -29,18 +29,28 @@ namespace RTC ...@@ -29,18 +29,28 @@ namespace RTC
static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::PSLEI }; static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::PSLEI };
public: public:
explicit FeedbackPsLeiItem(Header* header); explicit FeedbackPsLeiItem(Header* header) : header(header)
explicit FeedbackPsLeiItem(FeedbackPsLeiItem* item); {
}
explicit FeedbackPsLeiItem(FeedbackPsLeiItem* item) : header(item->header)
{
}
explicit FeedbackPsLeiItem(uint32_t ssrc); explicit FeedbackPsLeiItem(uint32_t ssrc);
~FeedbackPsLeiItem() override = default; ~FeedbackPsLeiItem() override = default;
uint32_t GetSsrc() const; uint32_t GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return sizeof(Header);
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -48,26 +58,6 @@ namespace RTC ...@@ -48,26 +58,6 @@ namespace RTC
// Lei packet declaration. // Lei packet declaration.
using FeedbackPsLeiPacket = FeedbackPsItemsPacket<FeedbackPsLeiItem>; using FeedbackPsLeiPacket = FeedbackPsItemsPacket<FeedbackPsLeiItem>;
/* Inline instance methods. */
inline FeedbackPsLeiItem::FeedbackPsLeiItem(Header* header) : header(header)
{
}
inline FeedbackPsLeiItem::FeedbackPsLeiItem(FeedbackPsLeiItem* item) : header(item->header)
{
}
inline size_t FeedbackPsLeiItem::GetSize() const
{
return sizeof(Header);
}
inline uint32_t FeedbackPsLeiItem::GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -15,25 +15,18 @@ namespace RTC ...@@ -15,25 +15,18 @@ namespace RTC
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackPsPliPacket(CommonHeader* commonHeader); explicit FeedbackPsPliPacket(CommonHeader* commonHeader) : FeedbackPsPacket(commonHeader)
FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc);
~FeedbackPsPliPacket() override = default;
public:
void Dump() const override;
};
/* Inline instance methods. */
inline FeedbackPsPliPacket::FeedbackPsPliPacket(CommonHeader* commonHeader)
: FeedbackPsPacket(commonHeader)
{ {
} }
FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
inline FeedbackPsPliPacket::FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackPsPacket(FeedbackPs::MessageType::PLI, senderSsrc, mediaSsrc) : FeedbackPsPacket(FeedbackPs::MessageType::PLI, senderSsrc, mediaSsrc)
{ {
} }
~FeedbackPsPliPacket() override = default;
public:
void Dump() const override;
};
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -40,65 +40,49 @@ namespace RTC ...@@ -40,65 +40,49 @@ namespace RTC
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
FeedbackPsRembPacket(uint32_t senderSsrc, uint32_t mediaSsrc); FeedbackPsRembPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
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();
/* 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<uint32_t> ssrcs;
// Bitrate represented in bps.
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) : FeedbackPsAfbPacket(senderSsrc, mediaSsrc, FeedbackPsAfbPacket::Application::REMB)
{ {
} }
FeedbackPsRembPacket(CommonHeader* commonHeader, size_t availableLen);
~FeedbackPsRembPacket() override = default;
inline bool FeedbackPsRembPacket::IsCorrect() bool IsCorrect() const
{ {
return this->isCorrect; return this->isCorrect;
} }
void SetBitrate(uint64_t bitrate)
inline void FeedbackPsRembPacket::SetBitrate(uint64_t bitrate)
{ {
this->bitrate = bitrate; this->bitrate = bitrate;
} }
void SetSsrcs(const std::vector<uint32_t>& ssrcs)
inline void FeedbackPsRembPacket::SetSsrcs(const std::vector<uint32_t>& ssrcs)
{ {
this->ssrcs = ssrcs; this->ssrcs = ssrcs;
} }
uint64_t GetBitrate()
inline uint64_t FeedbackPsRembPacket::GetBitrate()
{ {
return this->bitrate; return this->bitrate;
} }
const std::vector<uint32_t>& GetSsrcs()
inline const std::vector<uint32_t>& FeedbackPsRembPacket::GetSsrcs()
{ {
return this->ssrcs; return this->ssrcs;
} }
inline size_t FeedbackPsRembPacket::GetSize() const /* Pure virtual methods inherited from Packet. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override
{ {
return FeedbackPsPacket::GetSize() + 8 + (4u * this->ssrcs.size()); return FeedbackPsPacket::GetSize() + 8 + (4u * this->ssrcs.size());
} }
private:
std::vector<uint32_t> ssrcs;
// Bitrate represented in bps.
uint64_t bitrate{ 0 };
bool isCorrect{ true };
};
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -40,59 +40,45 @@ namespace RTC ...@@ -40,59 +40,45 @@ namespace RTC
public: public:
explicit FeedbackPsRpsiItem(Header* header); explicit FeedbackPsRpsiItem(Header* header);
explicit FeedbackPsRpsiItem(FeedbackPsRpsiItem* item); explicit FeedbackPsRpsiItem(FeedbackPsRpsiItem* item) : header(item->header)
FeedbackPsRpsiItem(uint8_t payloadType, uint8_t* bitString, size_t length);
~FeedbackPsRpsiItem() override = default;
bool IsCorrect() const;
uint8_t GetPayloadType() const;
uint8_t* GetBitString() const;
size_t GetLength() const;
/* Virtual methods inherited from FeedbackItem. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
Header* header{ nullptr };
size_t length{ 0 };
};
// Rpsi packet declaration.
using FeedbackPsRpsiPacket = FeedbackPsItemsPacket<FeedbackPsRpsiItem>;
/* Inline instance methods. */
inline FeedbackPsRpsiItem::FeedbackPsRpsiItem(FeedbackPsRpsiItem* item) : header(item->header)
{ {
} }
FeedbackPsRpsiItem(uint8_t payloadType, uint8_t* bitString, size_t length);
~FeedbackPsRpsiItem() override = default;
inline size_t FeedbackPsRpsiItem::GetSize() const bool IsCorrect() const
{ {
return sizeof(Header); return this->isCorrect;
} }
uint8_t GetPayloadType() const
inline uint8_t FeedbackPsRpsiItem::GetPayloadType() const
{ {
return this->header->payloadType; return this->header->payloadType;
} }
uint8_t* GetBitString() const
inline uint8_t* FeedbackPsRpsiItem::GetBitString() const
{ {
return this->header->bitString; return this->header->bitString;
} }
size_t GetLength() const
inline size_t FeedbackPsRpsiItem::GetLength() const
{ {
return this->length; return this->length;
} }
inline bool FeedbackPsRpsiItem::IsCorrect() const /* Virtual methods inherited from FeedbackItem. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override
{ {
return this->isCorrect; return sizeof(Header);
} }
private:
Header* header{ nullptr };
size_t length{ 0 };
};
// Rpsi packet declaration.
using FeedbackPsRpsiPacket = FeedbackPsItemsPacket<FeedbackPsRpsiItem>;
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -34,65 +34,49 @@ namespace RTC ...@@ -34,65 +34,49 @@ namespace RTC
FeedbackPsSliItem(uint16_t first, uint16_t number, uint8_t pictureId); FeedbackPsSliItem(uint16_t first, uint16_t number, uint8_t pictureId);
~FeedbackPsSliItem() override = default; ~FeedbackPsSliItem() override = default;
uint16_t GetFirst() const; uint16_t GetFirst() const
void SetFirst(uint16_t first);
uint16_t GetNumber() const;
void SetNumber(uint16_t number);
uint8_t GetPictureId() const;
void SetPictureId(uint8_t pictureId);
/* Virtual methods inherited from FeedbackItem. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
Header* header{ nullptr };
uint16_t first{ 0 };
uint16_t number{ 0 };
uint8_t pictureId{ 0 };
};
// 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; return this->first;
} }
void SetFirst(uint16_t first)
inline void FeedbackPsSliItem::SetFirst(uint16_t first)
{ {
this->first = first; this->first = first;
} }
uint16_t GetNumber() const
inline uint16_t FeedbackPsSliItem::GetNumber() const
{ {
return this->number; return this->number;
} }
void SetNumber(uint16_t number)
inline void FeedbackPsSliItem::SetNumber(uint16_t number)
{ {
this->number = number; this->number = number;
} }
uint8_t GetPictureId() const
inline uint8_t FeedbackPsSliItem::GetPictureId() const
{ {
return this->pictureId; return this->pictureId;
} }
void SetPictureId(uint8_t pictureId)
inline void FeedbackPsSliItem::SetPictureId(uint8_t pictureId)
{ {
this->pictureId = 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
{
return sizeof(Header);
}
private:
Header* header{ nullptr };
uint16_t first{ 0 };
uint16_t number{ 0 };
uint8_t pictureId{ 0 };
};
// Sli packet declaration.
using FeedbackPsSliPacket = FeedbackPsItemsPacket<FeedbackPsSliItem>;
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -37,20 +37,36 @@ namespace RTC ...@@ -37,20 +37,36 @@ namespace RTC
static const FeedbackPs::MessageType messageType; static const FeedbackPs::MessageType messageType;
public: public:
explicit FeedbackPsTstItem(Header* header); explicit FeedbackPsTstItem(Header* header) : header(header)
explicit FeedbackPsTstItem(FeedbackPsTstItem* item); {
}
explicit FeedbackPsTstItem(FeedbackPsTstItem* item) : header(item->header)
{
}
FeedbackPsTstItem(uint32_t ssrc, uint8_t sequenceNumber, uint8_t index); FeedbackPsTstItem(uint32_t ssrc, uint8_t sequenceNumber, uint8_t index);
~FeedbackPsTstItem() override = default; ~FeedbackPsTstItem() override = default;
uint32_t GetSsrc() const; uint32_t GetSsrc() const
uint8_t GetSequenceNumber() const; {
uint8_t GetIndex() const; return uint32_t{ ntohl(this->header->ssrc) };
}
uint8_t GetSequenceNumber() const
{
return static_cast<uint8_t>(this->header->sequenceNumber);
}
uint8_t GetIndex() const
{
return static_cast<uint8_t>(this->header->index);
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return sizeof(Header);
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -71,42 +87,6 @@ namespace RTC ...@@ -71,42 +87,6 @@ namespace RTC
// Tst packets declaration. // Tst packets declaration.
using FeedbackPsTstrPacket = FeedbackPsItemsPacket<FeedbackPsTstrItem>; using FeedbackPsTstrPacket = FeedbackPsItemsPacket<FeedbackPsTstrItem>;
using FeedbackPsTstnPacket = FeedbackPsItemsPacket<FeedbackPsTstnItem>; using FeedbackPsTstnPacket = FeedbackPsItemsPacket<FeedbackPsTstnItem>;
/* Inline instance methods. */
template<typename T>
inline FeedbackPsTstItem<T>::FeedbackPsTstItem(Header* header) : header(header)
{
}
template<typename T>
inline FeedbackPsTstItem<T>::FeedbackPsTstItem(FeedbackPsTstItem* item) : header(item->header)
{
}
template<typename T>
inline size_t FeedbackPsTstItem<T>::GetSize() const
{
return sizeof(Header);
}
template<typename T>
inline uint32_t FeedbackPsTstItem<T>::GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
template<typename T>
inline uint8_t FeedbackPsTstItem<T>::GetSequenceNumber() const
{
return static_cast<uint8_t>(this->header->sequenceNumber);
}
template<typename T>
inline uint8_t FeedbackPsTstItem<T>::GetIndex() const
{
return static_cast<uint8_t>(this->header->index);
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -40,73 +40,55 @@ namespace RTC ...@@ -40,73 +40,55 @@ namespace RTC
static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::FIR }; static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::FIR };
public: public:
explicit FeedbackPsVbcmItem(Header* header); explicit FeedbackPsVbcmItem(Header* header) : header(header)
explicit FeedbackPsVbcmItem(FeedbackPsVbcmItem* item);
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;
/* Virtual methods inherited from FeedbackItem. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
Header* header{ nullptr };
};
// Vbcm packet declaration.
using FeedbackPsVbcmPacket = FeedbackPsItemsPacket<FeedbackPsVbcmItem>;
/* Inline instance methods. */
inline FeedbackPsVbcmItem::FeedbackPsVbcmItem(Header* header) : header(header)
{ {
} }
explicit FeedbackPsVbcmItem(FeedbackPsVbcmItem* item) : header(item->header)
inline FeedbackPsVbcmItem::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;
inline size_t FeedbackPsVbcmItem::GetSize() const uint32_t GetSsrc() 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) }; return uint32_t{ ntohl(this->header->ssrc) };
} }
uint8_t GetSequenceNumber() const
inline uint8_t FeedbackPsVbcmItem::GetSequenceNumber() const
{ {
return uint8_t{ this->header->sequenceNumber }; return uint8_t{ this->header->sequenceNumber };
} }
uint8_t GetPayloadType() const
inline uint8_t FeedbackPsVbcmItem::GetPayloadType() const
{ {
return uint8_t{ this->header->payloadType }; return uint8_t{ this->header->payloadType };
} }
uint16_t GetLength() const
inline uint16_t FeedbackPsVbcmItem::GetLength() const
{ {
return uint16_t{ ntohs(this->header->length) }; return uint16_t{ ntohs(this->header->length) };
} }
uint8_t* GetValue() const
inline uint8_t* FeedbackPsVbcmItem::GetValue() const
{ {
return this->header->value; 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 size = 8 + static_cast<size_t>(GetLength());
// Consider pading to 32 bits (4 bytes) boundary.
return (size + 3) & ~3;
}
private:
Header* header{ nullptr };
};
// Vbcm packet declaration.
using FeedbackPsVbcmPacket = FeedbackPsItemsPacket<FeedbackPsVbcmItem>;
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -20,40 +20,14 @@ namespace RTC ...@@ -20,40 +20,14 @@ namespace RTC
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackRtpItemsPacket(CommonHeader* commonHeader); explicit FeedbackRtpItemsPacket(CommonHeader* commonHeader) : FeedbackRtpPacket(commonHeader)
explicit FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0);
~FeedbackRtpItemsPacket();
void AddItem(Item* item);
Iterator Begin();
Iterator 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)
{ {
} }
explicit FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0)
template<typename Item>
inline FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackRtpPacket(Item::messageType, senderSsrc, mediaSsrc) : FeedbackRtpPacket(Item::messageType, senderSsrc, mediaSsrc)
{ {
} }
~FeedbackRtpItemsPacket()
template<typename Item>
FeedbackRtpItemsPacket<Item>::~FeedbackRtpItemsPacket()
{ {
for (auto* item : this->items) for (auto* item : this->items)
{ {
...@@ -61,36 +35,38 @@ namespace RTC ...@@ -61,36 +35,38 @@ namespace RTC
} }
} }
template<typename Item> void AddItem(Item* item)
inline size_t FeedbackRtpItemsPacket<Item>::GetSize() const
{ {
size_t size = FeedbackRtpPacket::GetSize(); this->items.push_back(item);
}
for (auto* item : this->items) Iterator Begin()
{ {
size += item->GetSize(); return this->items.begin();
} }
Iterator End()
return size; {
return this->items.end();
} }
template<typename Item> /* Virtual methods inherited from FeedbackItem. */
inline void FeedbackRtpItemsPacket<Item>::AddItem(Item* item) public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override
{ {
this->items.push_back(item); size_t size = FeedbackRtpPacket::GetSize();
}
template<typename Item> for (auto* item : this->items)
inline typename FeedbackRtpItemsPacket<Item>::Iterator FeedbackRtpItemsPacket<Item>::Begin()
{ {
return this->items.begin(); size += item->GetSize();
} }
template<typename Item> return size;
inline typename FeedbackRtpItemsPacket<Item>::Iterator FeedbackRtpItemsPacket<Item>::End()
{
return this->items.end();
} }
private:
std::vector<Item*> items;
};
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -45,80 +45,58 @@ namespace RTC ...@@ -45,80 +45,58 @@ namespace RTC
static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::ECN }; static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::ECN };
public: public:
explicit FeedbackRtpEcnItem(Header* header); explicit FeedbackRtpEcnItem(Header* header) : header(header)
explicit FeedbackRtpEcnItem(FeedbackRtpEcnItem* item);
~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;
/* Virtual methods inherited from FeedbackItem. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
Header* header{ nullptr };
};
// Ecn packet declaration.
using FeedbackRtpEcnPacket = FeedbackRtpItemsPacket<FeedbackRtpEcnItem>;
/* Inline instance methods. */
inline FeedbackRtpEcnItem::FeedbackRtpEcnItem(Header* header) : header(header)
{ {
} }
explicit FeedbackRtpEcnItem(FeedbackRtpEcnItem* item) : header(item->header)
inline FeedbackRtpEcnItem::FeedbackRtpEcnItem(FeedbackRtpEcnItem* item) : header(item->header)
{ {
} }
~FeedbackRtpEcnItem() override = default;
inline size_t FeedbackRtpEcnItem::GetSize() const uint32_t GetSequenceNumber() const
{
return sizeof(Header);
}
inline uint32_t FeedbackRtpEcnItem::GetSequenceNumber() const
{ {
return uint32_t{ ntohl(this->header->sequenceNumber) }; return uint32_t{ ntohl(this->header->sequenceNumber) };
} }
uint32_t GetEct0Counter() const
inline uint32_t FeedbackRtpEcnItem::GetEct0Counter() const
{ {
return uint32_t{ ntohl(this->header->ect0Counter) }; return uint32_t{ ntohl(this->header->ect0Counter) };
} }
uint32_t GetEct1Counter() const
inline uint32_t FeedbackRtpEcnItem::GetEct1Counter() const
{ {
return uint32_t{ ntohl(this->header->ect1Counter) }; return uint32_t{ ntohl(this->header->ect1Counter) };
} }
uint16_t GetEcnCeCounter() const
inline uint16_t FeedbackRtpEcnItem::GetEcnCeCounter() const
{ {
return uint16_t{ ntohs(this->header->ecnCeCounter) }; return uint16_t{ ntohs(this->header->ecnCeCounter) };
} }
uint16_t GetNotEctCounter() const
inline uint16_t FeedbackRtpEcnItem::GetNotEctCounter() const
{ {
return uint16_t{ ntohs(this->header->notEctCounter) }; return uint16_t{ ntohs(this->header->notEctCounter) };
} }
uint16_t GetLostPackets() const
inline uint16_t FeedbackRtpEcnItem::GetLostPackets() const
{ {
return uint16_t{ ntohs(this->header->lostPackets) }; return uint16_t{ ntohs(this->header->lostPackets) };
} }
uint16_t GetDuplicatedPackets() const
inline uint16_t FeedbackRtpEcnItem::GetDuplicatedPackets() const
{ {
return uint16_t{ ntohs(this->header->duplicatedPackets) }; 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
{
return sizeof(Header);
}
private:
Header* header{ nullptr };
};
// Ecn packet declaration.
using FeedbackRtpEcnPacket = FeedbackRtpItemsPacket<FeedbackRtpEcnItem>;
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -31,20 +31,36 @@ namespace RTC ...@@ -31,20 +31,36 @@ namespace RTC
static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::NACK }; static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::NACK };
public: public:
explicit FeedbackRtpNackItem(Header* header); explicit FeedbackRtpNackItem(Header* header) : header(header)
explicit FeedbackRtpNackItem(FeedbackRtpNackItem* item); {
}
explicit FeedbackRtpNackItem(FeedbackRtpNackItem* item) : header(item->header)
{
}
FeedbackRtpNackItem(uint16_t packetId, uint16_t lostPacketBitmask); FeedbackRtpNackItem(uint16_t packetId, uint16_t lostPacketBitmask);
~FeedbackRtpNackItem() override = default; ~FeedbackRtpNackItem() override = default;
uint16_t GetPacketId() const; uint16_t GetPacketId() const
uint16_t GetLostPacketBitmask() const; {
size_t CountRequestedPackets() const; return uint16_t{ ntohs(this->header->packetId) };
}
uint16_t GetLostPacketBitmask() const
{
return uint16_t{ ntohs(this->header->lostPacketBitmask) };
}
size_t CountRequestedPackets() const
{
return Utils::Bits::CountSetBits(this->header->lostPacketBitmask) + 1;
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return sizeof(Header);
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -52,37 +68,6 @@ namespace RTC ...@@ -52,37 +68,6 @@ namespace RTC
// Nack packet declaration. // Nack packet declaration.
using FeedbackRtpNackPacket = FeedbackRtpItemsPacket<FeedbackRtpNackItem>; using FeedbackRtpNackPacket = FeedbackRtpItemsPacket<FeedbackRtpNackItem>;
/* Inline instance methods. */
inline FeedbackRtpNackItem::FeedbackRtpNackItem(Header* header) : header(header)
{
}
inline FeedbackRtpNackItem::FeedbackRtpNackItem(FeedbackRtpNackItem* item)
: header(item->header)
{
}
inline size_t FeedbackRtpNackItem::GetSize() const
{
return sizeof(Header);
}
inline uint16_t FeedbackRtpNackItem::GetPacketId() const
{
return uint16_t{ ntohs(this->header->packetId) };
}
inline uint16_t FeedbackRtpNackItem::GetLostPacketBitmask() const
{
return uint16_t{ ntohs(this->header->lostPacketBitmask) };
}
inline size_t FeedbackRtpNackItem::CountRequestedPackets() const
{
return Utils::Bits::CountSetBits(this->header->lostPacketBitmask) + 1;
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -15,24 +15,17 @@ namespace RTC ...@@ -15,24 +15,17 @@ namespace RTC
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackRtpSrReqPacket(CommonHeader* commonHeader); explicit FeedbackRtpSrReqPacket(CommonHeader* commonHeader) : FeedbackRtpPacket(commonHeader)
FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc);
~FeedbackRtpSrReqPacket() override = default;
void Dump() const override;
};
/* Inline instance methods. */
inline FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(CommonHeader* commonHeader)
: FeedbackRtpPacket(commonHeader)
{ {
} }
FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
inline FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackRtpPacket(FeedbackRtp::MessageType::SR_REQ, senderSsrc, mediaSsrc) : FeedbackRtpPacket(FeedbackRtp::MessageType::SR_REQ, senderSsrc, mediaSsrc)
{ {
} }
~FeedbackRtpSrReqPacket() override = default;
void Dump() const override;
};
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -30,19 +30,32 @@ namespace RTC ...@@ -30,19 +30,32 @@ namespace RTC
static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::TLLEI }; static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::TLLEI };
public: public:
explicit FeedbackRtpTlleiItem(Header* header); explicit FeedbackRtpTlleiItem(Header* header) : header(header)
explicit FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item); {
}
explicit FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item) : header(item->header)
{
}
FeedbackRtpTlleiItem(uint16_t packetId, uint16_t lostPacketBitmask); FeedbackRtpTlleiItem(uint16_t packetId, uint16_t lostPacketBitmask);
~FeedbackRtpTlleiItem() override = default; ~FeedbackRtpTlleiItem() override = default;
uint16_t GetPacketId() const; uint16_t GetPacketId() const
uint16_t GetLostPacketBitmask() const; {
return uint16_t{ ntohs(this->header->packetId) };
}
uint16_t GetLostPacketBitmask() const
{
return uint16_t{ ntohs(this->header->lostPacketBitmask) };
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return sizeof(Header);
}
private: private:
Header* header{ nullptr }; Header* header{ nullptr };
...@@ -50,32 +63,6 @@ namespace RTC ...@@ -50,32 +63,6 @@ namespace RTC
// Tllei packet declaration. // Tllei packet declaration.
using FeedbackRtpTlleiPacket = FeedbackRtpItemsPacket<FeedbackRtpTlleiItem>; using FeedbackRtpTlleiPacket = FeedbackRtpItemsPacket<FeedbackRtpTlleiItem>;
/* Inline instance methods. */
inline FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(Header* header) : header(header)
{
}
inline FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item)
: header(item->header)
{
}
inline size_t FeedbackRtpTlleiItem::GetSize() const
{
return sizeof(Header);
}
inline uint16_t FeedbackRtpTlleiItem::GetPacketId() const
{
return uint16_t{ ntohs(this->header->packetId) };
}
inline uint16_t FeedbackRtpTlleiItem::GetLostPacketBitmask() const
{
return uint16_t{ ntohs(this->header->lostPacketBitmask) };
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -34,23 +34,44 @@ namespace RTC ...@@ -34,23 +34,44 @@ namespace RTC
static const FeedbackRtp::MessageType messageType; static const FeedbackRtp::MessageType messageType;
public: public:
FeedbackRtpTmmbItem() = default;
explicit FeedbackRtpTmmbItem(const uint8_t* data); explicit FeedbackRtpTmmbItem(const uint8_t* data);
explicit FeedbackRtpTmmbItem(const Header* header); explicit FeedbackRtpTmmbItem(const Header* header);
FeedbackRtpTmmbItem();
~FeedbackRtpTmmbItem() override = default; ~FeedbackRtpTmmbItem() override = default;
uint32_t GetSsrc() const; uint32_t GetSsrc() const
void SetSsrc(uint32_t ssrc); {
uint64_t GetBitrate() const; return this->ssrc;
void SetBitrate(uint64_t bitrate); }
uint16_t GetOverhead() const; void SetSsrc(uint32_t ssrc)
void SetOverhead(uint16_t overhead); {
this->ssrc = ssrc;
}
uint64_t GetBitrate() const
{
return this->bitrate;
}
void SetBitrate(uint64_t bitrate)
{
this->bitrate = bitrate;
}
uint16_t GetOverhead() const
{
return this->overhead;
}
void SetOverhead(uint16_t overhead)
{
this->overhead = overhead;
}
/* Virtual methods inherited from FeedbackItem. */ /* Virtual methods inherited from FeedbackItem. */
public: public:
void Dump() const override; void Dump() const override;
size_t Serialize(uint8_t* buffer) override; size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override; size_t GetSize() const override
{
return sizeof(Header);
}
private: private:
uint32_t ssrc{ 0 }; uint32_t ssrc{ 0 };
...@@ -73,53 +94,6 @@ namespace RTC ...@@ -73,53 +94,6 @@ namespace RTC
// Tmmbn packets declaration. // Tmmbn packets declaration.
using FeedbackRtpTmmbrPacket = FeedbackRtpItemsPacket<FeedbackRtpTmmbrItem>; using FeedbackRtpTmmbrPacket = FeedbackRtpItemsPacket<FeedbackRtpTmmbrItem>;
using FeedbackRtpTmmbnPacket = FeedbackRtpItemsPacket<FeedbackRtpTmmbnItem>; using FeedbackRtpTmmbnPacket = FeedbackRtpItemsPacket<FeedbackRtpTmmbnItem>;
/* Inline instance methods. */
template<typename T>
inline FeedbackRtpTmmbItem<T>::FeedbackRtpTmmbItem() = default;
template<typename T>
inline size_t FeedbackRtpTmmbItem<T>::GetSize() const
{
return sizeof(Header);
}
template<typename T>
inline uint32_t FeedbackRtpTmmbItem<T>::GetSsrc() const
{
return this->ssrc;
}
template<typename T>
inline void FeedbackRtpTmmbItem<T>::SetSsrc(uint32_t ssrc)
{
this->ssrc = ssrc;
}
template<typename T>
inline uint64_t FeedbackRtpTmmbItem<T>::GetBitrate() const
{
return this->bitrate;
}
template<typename T>
inline void FeedbackRtpTmmbItem<T>::SetBitrate(uint64_t bitrate)
{
this->bitrate = bitrate;
}
template<typename T>
inline uint16_t FeedbackRtpTmmbItem<T>::GetOverhead() const
{
return this->overhead;
}
template<typename T>
inline void FeedbackRtpTmmbItem<T>::SetOverhead(uint16_t overhead)
{
this->overhead = overhead;
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -105,15 +105,23 @@ namespace RTC ...@@ -105,15 +105,23 @@ namespace RTC
class RunLengthChunk : public Chunk class RunLengthChunk : public Chunk
{ {
public: public:
RunLengthChunk(Status status, uint16_t count); RunLengthChunk(Status status, uint16_t count) : status(status), count(count)
{
}
explicit RunLengthChunk(uint16_t buffer); explicit RunLengthChunk(uint16_t buffer);
public: public:
bool AddDeltas( bool AddDeltas(
const uint8_t* data, size_t len, std::vector<int16_t>& deltas, size_t& offset) override; const uint8_t* data, size_t len, std::vector<int16_t>& deltas, size_t& offset) override;
Status GetStatus() const; Status GetStatus() const
{
return this->status;
}
void Dump() const override; void Dump() const override;
uint16_t GetCount() const override; uint16_t GetCount() const override
{
return this->count;
}
uint16_t GetReceivedStatusCount() const override; uint16_t GetReceivedStatusCount() const override;
void FillResults( void FillResults(
std::vector<struct PacketResult>& packetResults, std::vector<struct PacketResult>& packetResults,
...@@ -129,14 +137,19 @@ namespace RTC ...@@ -129,14 +137,19 @@ namespace RTC
class OneBitVectorChunk : public Chunk class OneBitVectorChunk : public Chunk
{ {
public: public:
explicit OneBitVectorChunk(const std::vector<Status>& statuses); explicit OneBitVectorChunk(const std::vector<Status>& statuses) : statuses(statuses)
{
}
OneBitVectorChunk(uint16_t buffer, uint16_t count); OneBitVectorChunk(uint16_t buffer, uint16_t count);
public: public:
bool AddDeltas( bool AddDeltas(
const uint8_t* data, size_t len, std::vector<int16_t>& deltas, size_t& offset) override; const uint8_t* data, size_t len, std::vector<int16_t>& deltas, size_t& offset) override;
void Dump() const override; void Dump() const override;
uint16_t GetCount() const override; uint16_t GetCount() const override
{
return this->statuses.size();
}
uint16_t GetReceivedStatusCount() const override; uint16_t GetReceivedStatusCount() const override;
void FillResults( void FillResults(
std::vector<struct PacketResult>& packetResults, std::vector<struct PacketResult>& packetResults,
...@@ -151,14 +164,19 @@ namespace RTC ...@@ -151,14 +164,19 @@ namespace RTC
class TwoBitVectorChunk : public Chunk class TwoBitVectorChunk : public Chunk
{ {
public: public:
explicit TwoBitVectorChunk(const std::vector<Status>& statuses); explicit TwoBitVectorChunk(const std::vector<Status>& statuses) : statuses(statuses)
{
}
TwoBitVectorChunk(uint16_t buffer, uint16_t count); TwoBitVectorChunk(uint16_t buffer, uint16_t count);
public: public:
bool AddDeltas( bool AddDeltas(
const uint8_t* data, size_t len, std::vector<int16_t>& deltas, size_t& offset) override; const uint8_t* data, size_t len, std::vector<int16_t>& deltas, size_t& offset) override;
void Dump() const override; void Dump() const override;
uint16_t GetCount() const override; uint16_t GetCount() const override
{
return this->statuses.size();
}
uint16_t GetReceivedStatusCount() const override; uint16_t GetReceivedStatusCount() const override;
void FillResults( void FillResults(
std::vector<struct PacketResult>& packetResults, std::vector<struct PacketResult>& packetResults,
...@@ -182,121 +200,71 @@ namespace RTC ...@@ -182,121 +200,71 @@ namespace RTC
static std::map<Status, std::string> status2String; static std::map<Status, std::string> status2String;
public: public:
FeedbackRtpTransportPacket(uint32_t senderSsrc, uint32_t mediaSsrc); FeedbackRtpTransportPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackRtpPacket(RTC::RTCP::FeedbackRtp::MessageType::TCC, senderSsrc, mediaSsrc)
{
}
FeedbackRtpTransportPacket(CommonHeader* commonHeader, size_t availableLen); FeedbackRtpTransportPacket(CommonHeader* commonHeader, size_t availableLen);
~FeedbackRtpTransportPacket(); ~FeedbackRtpTransportPacket();
public: public:
AddPacketResult AddPacket(uint16_t sequenceNumber, uint64_t timestamp, size_t maxRtcpPacketLen); AddPacketResult AddPacket(uint16_t sequenceNumber, uint64_t timestamp, size_t maxRtcpPacketLen);
void Finish(); // Just for locally generated packets. void Finish(); // Just for locally generated packets.
bool IsFull(); bool IsFull()
bool IsSerializable();
bool IsCorrect(); // Just for locally generated packets.
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.
std::vector<struct PacketResult> GetPacketResults() const;
uint8_t GetPacketFractionLost() const;
/* Pure virtual methods inherited from Packet. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
void FillChunk(uint16_t previousSequenceNumber, uint16_t sequenceNumber, int16_t delta);
void CreateRunLengthChunk(Status status, uint16_t count);
void CreateOneBitVectorChunk(std::vector<Status>& statuses);
void CreateTwoBitVectorChunk(std::vector<Status>& statuses);
void AddPendingChunks();
private:
uint16_t baseSequenceNumber{ 0u };
int32_t referenceTime{ 0 };
uint16_t latestSequenceNumber{ 0u }; // Just for locally generated packets.
uint64_t latestTimestamp{ 0u }; // Just for locally generated packets.
uint16_t packetStatusCount{ 0u };
uint8_t feedbackPacketCount{ 0u };
std::vector<Chunk*> chunks;
std::vector<int16_t> deltas;
Context context; // Just for locally generated packets.
size_t deltasAndChunksSize{ 0u };
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 // NOTE: Since AddPendingChunks() is called at the end, we cannot track
// the exact ongoing value of packetStatusCount. Hence, let's reserve 7 // the exact ongoing value of packetStatusCount. Hence, let's reserve 7
// packets just in case. // packets just in case.
return this->packetStatusCount >= FeedbackRtpTransportPacket::maxPacketStatusCount - 7; return this->packetStatusCount >= FeedbackRtpTransportPacket::maxPacketStatusCount - 7;
} }
bool IsSerializable() const
inline bool FeedbackRtpTransportPacket::IsSerializable()
{ {
return this->deltas.size() > 0; return this->deltas.size() > 0;
} }
bool IsCorrect() const // Just for locally generated packets.
inline bool FeedbackRtpTransportPacket::IsCorrect()
{ {
return this->isCorrect; return this->isCorrect;
} }
uint16_t GetBaseSequenceNumber() const
inline uint16_t FeedbackRtpTransportPacket::GetBaseSequenceNumber() const
{ {
return this->baseSequenceNumber; return this->baseSequenceNumber;
} }
uint16_t GetPacketStatusCount() const
inline uint16_t FeedbackRtpTransportPacket::GetPacketStatusCount() const
{ {
return this->packetStatusCount; return this->packetStatusCount;
} }
int32_t GetReferenceTime() const
inline int32_t FeedbackRtpTransportPacket::GetReferenceTime() const
{ {
return this->referenceTime; return this->referenceTime;
} }
int64_t GetReferenceTimestamp() const // Reference time in ms.
inline int64_t FeedbackRtpTransportPacket::GetReferenceTimestamp() const
{ {
return static_cast<int64_t>(this->referenceTime) * 64; return static_cast<int64_t>(this->referenceTime) * 64;
} }
uint8_t GetFeedbackPacketCount() const
inline uint8_t FeedbackRtpTransportPacket::GetFeedbackPacketCount() const
{ {
return this->feedbackPacketCount; return this->feedbackPacketCount;
} }
void SetFeedbackPacketCount(uint8_t count)
inline void FeedbackRtpTransportPacket::SetFeedbackPacketCount(uint8_t count)
{ {
this->feedbackPacketCount = count; this->feedbackPacketCount = count;
} }
uint16_t GetLatestSequenceNumber() const // Just for locally generated packets.
inline uint16_t FeedbackRtpTransportPacket::GetLatestSequenceNumber() const
{ {
return this->latestSequenceNumber; return this->latestSequenceNumber;
} }
uint64_t GetLatestTimestamp() const // Just for locally generated packets.
inline uint64_t FeedbackRtpTransportPacket::GetLatestTimestamp() const
{ {
return this->latestTimestamp; return this->latestTimestamp;
} }
std::vector<struct PacketResult> GetPacketResults() const;
uint8_t GetPacketFractionLost() const;
inline size_t FeedbackRtpTransportPacket::GetSize() const /* Pure virtual methods inherited from Packet. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override
{ {
if (this->size) if (this->size)
return this->size; return this->size;
...@@ -313,42 +281,27 @@ namespace RTC ...@@ -313,42 +281,27 @@ namespace RTC
return size; return size;
} }
inline FeedbackRtpTransportPacket::RunLengthChunk::RunLengthChunk(Status status, uint16_t count) private:
: status(status), count(count) void FillChunk(uint16_t previousSequenceNumber, uint16_t sequenceNumber, int16_t delta);
{ void CreateRunLengthChunk(Status status, uint16_t count);
} void CreateOneBitVectorChunk(std::vector<Status>& statuses);
void CreateTwoBitVectorChunk(std::vector<Status>& statuses);
inline uint16_t FeedbackRtpTransportPacket::RunLengthChunk::GetCount() const void AddPendingChunks();
{
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 private:
{ uint16_t baseSequenceNumber{ 0u };
return this->statuses.size(); int32_t referenceTime{ 0 };
} uint16_t latestSequenceNumber{ 0u }; // Just for locally generated packets.
uint64_t latestTimestamp{ 0u }; // Just for locally generated packets.
uint16_t packetStatusCount{ 0u };
uint8_t feedbackPacketCount{ 0u };
std::vector<Chunk*> chunks;
std::vector<int16_t> deltas;
Context context; // Just for locally generated packets.
size_t deltasAndChunksSize{ 0u };
size_t size{ 0 };
bool isCorrect{ true };
};
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -49,38 +49,7 @@ namespace RTC ...@@ -49,38 +49,7 @@ namespace RTC
}; };
public: public:
static bool IsRtcp(const uint8_t* data, size_t len); static bool IsRtcp(const uint8_t* data, size_t len)
static Packet* Parse(const uint8_t* data, size_t len);
static const std::string& Type2String(Type type);
private:
static std::map<Type, std::string> type2String;
public:
explicit Packet(Type type);
explicit Packet(CommonHeader* commonHeader);
virtual ~Packet();
void SetNext(Packet* packet);
Packet* GetNext() const;
const uint8_t* GetData() const;
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;
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)); auto header = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data));
...@@ -98,45 +67,54 @@ namespace RTC ...@@ -98,45 +67,54 @@ namespace RTC
); );
// clang-format on // clang-format on
} }
static Packet* Parse(const uint8_t* data, size_t len);
static const std::string& Type2String(Type type);
/* Inline instance methods. */ private:
static std::map<Type, std::string> type2String;
inline Packet::Packet(Type type) : type(type) public:
explicit Packet(Type type) : type(type)
{ {
} }
explicit Packet(CommonHeader* commonHeader)
inline Packet::Packet(CommonHeader* commonHeader)
{ {
this->type = RTCP::Type(commonHeader->packetType); this->type = RTCP::Type(commonHeader->packetType);
this->header = commonHeader; this->header = commonHeader;
} }
virtual ~Packet() = default;
inline Packet::~Packet() = default; void SetNext(Packet* packet)
{
inline Packet* Packet::GetNext() const this->next = packet;
}
Packet* GetNext() const
{ {
return this->next; return this->next;
} }
const uint8_t* GetData() const
inline void Packet::SetNext(Packet* packet)
{ {
this->next = packet; return reinterpret_cast<uint8_t*>(this->header);
} }
inline Type Packet::GetType() const public:
virtual void Dump() const = 0;
virtual size_t Serialize(uint8_t* buffer) = 0;
virtual Type GetType() const
{ {
return this->type; return this->type;
} }
virtual size_t GetCount() const
inline size_t Packet::GetCount() const
{ {
return 0; return 0u;
} }
virtual size_t GetSize() const = 0;
inline const uint8_t* Packet::GetData() const private:
{ Type type;
return reinterpret_cast<uint8_t*>(this->header); Packet* next{ nullptr };
} CommonHeader* header{ nullptr };
};
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -29,109 +29,42 @@ namespace RTC ...@@ -29,109 +29,42 @@ namespace RTC
static ReceiverReport* Parse(const uint8_t* data, size_t len); static ReceiverReport* Parse(const uint8_t* data, size_t len);
public: public:
// Parsed Report. Points to an external data.
explicit ReceiverReport(Header* header);
explicit ReceiverReport(ReceiverReport* report);
// Locally generated Report. Holds the data internally. // Locally generated Report. Holds the data internally.
ReceiverReport(); ReceiverReport()
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);
private:
Header* header{ nullptr };
uint8_t raw[sizeof(Header)]{ 0u };
};
class ReceiverReportPacket : public Packet
{
public:
using Iterator = std::vector<ReceiverReport*>::iterator;
public:
static ReceiverReportPacket* Parse(const uint8_t* data, size_t len, size_t offset = 0);
public:
ReceiverReportPacket();
explicit ReceiverReportPacket(CommonHeader* commonHeader);
~ReceiverReportPacket() override;
uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc);
void AddReport(ReceiverReport* report);
Iterator Begin();
Iterator 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); this->header = reinterpret_cast<Header*>(this->raw);
} }
// Parsed Report. Points to an external data.
inline ReceiverReport::ReceiverReport(Header* header) : header(header) explicit ReceiverReport(Header* header) : header(header)
{ {
} }
explicit ReceiverReport(ReceiverReport* report) : header(report->header)
inline ReceiverReport::ReceiverReport(ReceiverReport* report) : header(report->header)
{ {
} }
inline size_t ReceiverReport::GetSize() const void Dump() const;
size_t Serialize(uint8_t* buffer);
size_t GetSize() const
{ {
return sizeof(Header); return sizeof(Header);
} }
uint32_t GetSsrc() const
inline uint32_t ReceiverReport::GetSsrc() const
{ {
return uint32_t{ ntohl(this->header->ssrc) }; return uint32_t{ ntohl(this->header->ssrc) };
} }
void SetSsrc(uint32_t ssrc)
inline void ReceiverReport::SetSsrc(uint32_t ssrc)
{ {
this->header->ssrc = uint32_t{ htonl(ssrc) }; this->header->ssrc = uint32_t{ htonl(ssrc) };
} }
uint8_t GetFractionLost() const
inline uint8_t ReceiverReport::GetFractionLost() const
{ {
return uint8_t{ Utils::Byte::Get1Byte((uint8_t*)this->header, 4) }; return uint8_t{ Utils::Byte::Get1Byte((uint8_t*)this->header, 4) };
} }
void SetFractionLost(uint8_t fractionLost)
inline void ReceiverReport::SetFractionLost(uint8_t fractionLost)
{ {
Utils::Byte::Set1Byte((uint8_t*)this->header, 4, fractionLost); Utils::Byte::Set1Byte((uint8_t*)this->header, 4, fractionLost);
} }
int32_t GetTotalLost() const
inline int32_t ReceiverReport::GetTotalLost() const
{ {
auto value = uint32_t{ Utils::Byte::Get3Bytes((uint8_t*)this->header, 5) }; auto value = uint32_t{ Utils::Byte::Get3Bytes((uint8_t*)this->header, 5) };
...@@ -145,8 +78,7 @@ namespace RTC ...@@ -145,8 +78,7 @@ namespace RTC
return -value; return -value;
} }
void SetTotalLost(int32_t totalLost)
inline void ReceiverReport::SetTotalLost(int32_t totalLost)
{ {
// Get the limit value for possitive and negative totalLost. // Get the limit value for possitive and negative totalLost.
int32_t clamp = (totalLost >= 0) ? totalLost > 0x07FFFFF ? 0x07FFFFF : totalLost int32_t clamp = (totalLost >= 0) ? totalLost > 0x07FFFFF ? 0x07FFFFF : totalLost
...@@ -156,57 +88,60 @@ namespace RTC ...@@ -156,57 +88,60 @@ namespace RTC
Utils::Byte::Set3Bytes(reinterpret_cast<uint8_t*>(this->header), 5, value); Utils::Byte::Set3Bytes(reinterpret_cast<uint8_t*>(this->header), 5, value);
} }
uint32_t GetLastSeq() const
inline uint32_t ReceiverReport::GetLastSeq() const
{ {
return uint32_t{ ntohl(this->header->lastSeq) }; return uint32_t{ ntohl(this->header->lastSeq) };
} }
void SetLastSeq(uint32_t lastSeq)
inline void ReceiverReport::SetLastSeq(uint32_t lastSeq)
{ {
this->header->lastSeq = uint32_t{ htonl(lastSeq) }; this->header->lastSeq = uint32_t{ htonl(lastSeq) };
} }
uint32_t GetJitter() const
inline uint32_t ReceiverReport::GetJitter() const
{ {
return uint32_t{ ntohl(this->header->jitter) }; return uint32_t{ ntohl(this->header->jitter) };
} }
void SetJitter(uint32_t jitter)
inline void ReceiverReport::SetJitter(uint32_t jitter)
{ {
this->header->jitter = uint32_t{ htonl(jitter) }; this->header->jitter = uint32_t{ htonl(jitter) };
} }
uint32_t GetLastSenderReport() const
inline uint32_t ReceiverReport::GetLastSenderReport() const
{ {
return uint32_t{ ntohl(this->header->lsr) }; return uint32_t{ ntohl(this->header->lsr) };
} }
void SetLastSenderReport(uint32_t lsr)
inline void ReceiverReport::SetLastSenderReport(uint32_t lsr)
{ {
this->header->lsr = uint32_t{ htonl(lsr) }; this->header->lsr = uint32_t{ htonl(lsr) };
} }
uint32_t GetDelaySinceLastSenderReport() const
inline uint32_t ReceiverReport::GetDelaySinceLastSenderReport() const
{ {
return uint32_t{ ntohl(this->header->dlsr) }; return uint32_t{ ntohl(this->header->dlsr) };
} }
void SetDelaySinceLastSenderReport(uint32_t dlsr)
inline void ReceiverReport::SetDelaySinceLastSenderReport(uint32_t dlsr)
{ {
this->header->dlsr = uint32_t{ htonl(dlsr) }; this->header->dlsr = uint32_t{ htonl(dlsr) };
} }
inline ReceiverReportPacket::ReceiverReportPacket() : Packet(Type::RR) private:
Header* header{ nullptr };
uint8_t raw[sizeof(Header)]{ 0u };
};
class ReceiverReportPacket : public Packet
{ {
} public:
using Iterator = std::vector<ReceiverReport*>::iterator;
inline ReceiverReportPacket::ReceiverReportPacket(CommonHeader* commonHeader) public:
: Packet(commonHeader) static ReceiverReportPacket* Parse(const uint8_t* data, size_t len, size_t offset = 0);
public:
ReceiverReportPacket() : Packet(Type::RR)
{ {
} }
explicit ReceiverReportPacket(CommonHeader* commonHeader) : Packet(commonHeader)
inline ReceiverReportPacket::~ReceiverReportPacket() {
}
~ReceiverReportPacket() override
{ {
for (auto* report : this->reports) for (auto* report : this->reports)
{ {
...@@ -214,21 +149,44 @@ namespace RTC ...@@ -214,21 +149,44 @@ namespace RTC
} }
} }
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;
// NOTE: We need to force this since when we parse a SenderReportPacket that // NOTE: We need to force this since when we parse a SenderReportPacket that
// contains receive report blocks we also generate a second ReceiverReportPacket // contains receive report blocks we also generate a second ReceiverReportPacket
// from same data and len, so parent Packet::GetType() would return // from same data and len, so parent Packet::GetType() would return
// this->type which would be SR instead of RR. // this->type which would be SR instead of RR.
inline Type ReceiverReportPacket::GetType() const Type GetType() const override
{ {
return Type::RR; return Type::RR;
} }
size_t GetCount() const override
inline size_t ReceiverReportPacket::GetCount() const
{ {
return this->reports.size(); return this->reports.size();
} }
size_t GetSize() const override
inline size_t ReceiverReportPacket::GetSize() const
{ {
size_t size = sizeof(Packet::CommonHeader) + 4u /* this->ssrc */; size_t size = sizeof(Packet::CommonHeader) + 4u /* this->ssrc */;
...@@ -240,30 +198,11 @@ namespace RTC ...@@ -240,30 +198,11 @@ namespace RTC
return size; return size;
} }
inline uint32_t ReceiverReportPacket::GetSsrc() const private:
{ // SSRC of packet sender.
return this->ssrc; uint32_t ssrc{ 0u };
} std::vector<ReceiverReport*> reports;
};
inline void ReceiverReportPacket::SetSsrc(uint32_t ssrc)
{
this->ssrc = ssrc;
}
inline void ReceiverReportPacket::AddReport(ReceiverReport* report)
{
this->reports.push_back(report);
}
inline ReceiverReportPacket::Iterator ReceiverReportPacket::Begin()
{
return this->reports.begin();
}
inline ReceiverReportPacket::Iterator ReceiverReportPacket::End()
{
return this->reports.end();
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -41,18 +41,34 @@ namespace RTC ...@@ -41,18 +41,34 @@ namespace RTC
static const std::string& Type2String(SdesItem::Type type); static const std::string& Type2String(SdesItem::Type type);
public: public:
explicit SdesItem(Header* header); explicit SdesItem(Header* header) : header(header)
explicit SdesItem(SdesItem* item); {
}
explicit SdesItem(SdesItem* item) : header(item->header)
{
}
SdesItem(SdesItem::Type type, size_t len, const char* value); SdesItem(SdesItem::Type type, size_t len, const char* value);
~SdesItem() = default; ~SdesItem() = default;
void Dump() const; void Dump() const;
size_t Serialize(uint8_t* buffer); size_t Serialize(uint8_t* buffer);
size_t GetSize() const; size_t GetSize() const
{
return 2 + size_t{ this->header->length };
}
SdesItem::Type GetType() const; SdesItem::Type GetType() const
uint8_t GetLength() const; {
char* GetValue() const; return this->header->type;
}
uint8_t GetLength() const
{
return this->header->length;
}
char* GetValue() const
{
return this->header->value;
}
private: private:
// Passed by argument. // Passed by argument.
...@@ -72,91 +88,11 @@ namespace RTC ...@@ -72,91 +88,11 @@ namespace RTC
static SdesChunk* Parse(const uint8_t* data, size_t len); static SdesChunk* Parse(const uint8_t* data, size_t len);
public: public:
explicit SdesChunk(uint32_t ssrc); explicit SdesChunk(uint32_t ssrc)
explicit SdesChunk(SdesChunk* chunk);
~SdesChunk();
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();
private:
uint32_t ssrc{ 0u };
std::vector<SdesItem*> items;
};
class SdesPacket : public Packet
{
public:
using Iterator = std::vector<SdesChunk*>::iterator;
public:
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; this->ssrc = ssrc;
} }
explicit SdesChunk(SdesChunk* chunk)
inline SdesChunk::SdesChunk(SdesChunk* chunk)
{ {
this->ssrc = chunk->ssrc; this->ssrc = chunk->ssrc;
...@@ -165,8 +101,7 @@ namespace RTC ...@@ -165,8 +101,7 @@ namespace RTC
this->AddItem(new SdesItem(*it)); this->AddItem(new SdesItem(*it));
} }
} }
~SdesChunk()
inline SdesChunk::~SdesChunk()
{ {
for (auto* item : this->items) for (auto* item : this->items)
{ {
...@@ -174,7 +109,10 @@ namespace RTC ...@@ -174,7 +109,10 @@ namespace RTC
} }
} }
inline size_t SdesChunk::GetSize() const void Dump() const;
void Serialize();
size_t Serialize(uint8_t* buffer);
size_t GetSize() const
{ {
size_t size = 4u /*ssrc*/; size_t size = 4u /*ssrc*/;
...@@ -187,43 +125,48 @@ namespace RTC ...@@ -187,43 +125,48 @@ namespace RTC
// http://stackoverflow.com/questions/11642210/computing-padding-required-for-n-byte-alignment // http://stackoverflow.com/questions/11642210/computing-padding-required-for-n-byte-alignment
return (size + 3) & ~3; return (size + 3) & ~3;
} }
uint32_t GetSsrc() const
inline uint32_t SdesChunk::GetSsrc() const
{ {
return this->ssrc; return this->ssrc;
} }
void SetSsrc(uint32_t ssrc)
inline void SdesChunk::SetSsrc(uint32_t ssrc)
{ {
this->ssrc = htonl(ssrc); this->ssrc = htonl(ssrc);
} }
void AddItem(SdesItem* item)
inline void SdesChunk::AddItem(SdesItem* item)
{ {
this->items.push_back(item); this->items.push_back(item);
} }
Iterator Begin()
inline SdesChunk::Iterator SdesChunk::Begin()
{ {
return this->items.begin(); return this->items.begin();
} }
Iterator End()
inline SdesChunk::Iterator SdesChunk::End()
{ {
return this->items.end(); return this->items.end();
} }
/* Inline instance methods. */ private:
uint32_t ssrc{ 0u };
std::vector<SdesItem*> items;
};
inline SdesPacket::SdesPacket() : Packet(RTCP::Type::SDES) class SdesPacket : public Packet
{ {
} public:
using Iterator = std::vector<SdesChunk*>::iterator;
inline SdesPacket::SdesPacket(CommonHeader* commonHeader) : Packet(commonHeader) public:
static SdesPacket* Parse(const uint8_t* data, size_t len);
public:
SdesPacket() : Packet(RTCP::Type::SDES)
{ {
} }
explicit SdesPacket(CommonHeader* commonHeader) : Packet(commonHeader)
inline SdesPacket::~SdesPacket() {
}
~SdesPacket() override
{ {
for (auto* chunk : this->chunks) for (auto* chunk : this->chunks)
{ {
...@@ -231,12 +174,28 @@ namespace RTC ...@@ -231,12 +174,28 @@ namespace RTC
} }
} }
inline size_t SdesPacket::GetCount() const void AddChunk(SdesChunk* chunk)
{ {
return this->chunks.size(); this->chunks.push_back(chunk);
}
Iterator Begin()
{
return this->chunks.begin();
}
Iterator End()
{
return this->chunks.end();
} }
inline size_t SdesPacket::GetSize() const /* 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); size_t size = sizeof(Packet::CommonHeader);
...@@ -248,20 +207,9 @@ namespace RTC ...@@ -248,20 +207,9 @@ namespace RTC
return size; return size;
} }
inline void SdesPacket::AddChunk(SdesChunk* chunk) private:
{ std::vector<SdesChunk*> chunks;
this->chunks.push_back(chunk); };
}
inline SdesPacket::Iterator SdesPacket::Begin()
{
return this->chunks.begin();
}
inline SdesPacket::Iterator SdesPacket::End()
{
return this->chunks.end();
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -27,152 +27,95 @@ namespace RTC ...@@ -27,152 +27,95 @@ namespace RTC
static SenderReport* Parse(const uint8_t* data, size_t len); static SenderReport* Parse(const uint8_t* data, size_t len);
public: public:
// Parsed Report. Points to an external data.
explicit SenderReport(Header* header);
explicit SenderReport(SenderReport* report);
// Locally generated Report. Holds the data internally. // Locally generated Report. Holds the data internally.
SenderReport(); SenderReport()
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);
private:
Header* header{ nullptr };
uint8_t raw[sizeof(Header)]{ 0 };
};
class SenderReportPacket : public Packet
{
public:
using Iterator = std::vector<SenderReport*>::iterator;
public:
static SenderReportPacket* Parse(const uint8_t* data, size_t len);
public:
SenderReportPacket();
explicit SenderReportPacket(CommonHeader* commonHeader);
~SenderReportPacket() override;
void AddReport(SenderReport* report);
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<SenderReport*> reports;
};
/* Inline instance methods. */
inline SenderReport::SenderReport()
{ {
this->header = reinterpret_cast<Header*>(this->raw); this->header = reinterpret_cast<Header*>(this->raw);
} }
// Parsed Report. Points to an external data.
inline SenderReport::SenderReport(Header* header) : header(header) explicit SenderReport(Header* header) : header(header)
{ {
} }
explicit SenderReport(SenderReport* report) : header(report->header)
inline SenderReport::SenderReport(SenderReport* report) : header(report->header)
{ {
} }
inline size_t SenderReport::GetSize() const void Dump() const;
size_t Serialize(uint8_t* buffer);
size_t GetSize() const
{ {
return sizeof(Header); return sizeof(Header);
} }
uint32_t GetSsrc() const
inline uint32_t SenderReport::GetSsrc() const
{ {
return uint32_t{ ntohl(this->header->ssrc) }; return uint32_t{ ntohl(this->header->ssrc) };
} }
void SetSsrc(uint32_t ssrc)
inline void SenderReport::SetSsrc(uint32_t ssrc)
{ {
this->header->ssrc = uint32_t{ htonl(ssrc) }; this->header->ssrc = uint32_t{ htonl(ssrc) };
} }
uint32_t GetNtpSec() const
inline uint32_t SenderReport::GetNtpSec() const
{ {
return uint32_t{ ntohl(this->header->ntpSec) }; return uint32_t{ ntohl(this->header->ntpSec) };
} }
void SetNtpSec(uint32_t ntpSec)
inline void SenderReport::SetNtpSec(uint32_t ntpSec)
{ {
this->header->ntpSec = uint32_t{ htonl(ntpSec) }; this->header->ntpSec = uint32_t{ htonl(ntpSec) };
} }
uint32_t GetNtpFrac() const
inline uint32_t SenderReport::GetNtpFrac() const
{ {
return uint32_t{ ntohl(this->header->ntpFrac) }; return uint32_t{ ntohl(this->header->ntpFrac) };
} }
void SetNtpFrac(uint32_t ntpFrac)
inline void SenderReport::SetNtpFrac(uint32_t ntpFrac)
{ {
this->header->ntpFrac = uint32_t{ htonl(ntpFrac) }; this->header->ntpFrac = uint32_t{ htonl(ntpFrac) };
} }
uint32_t GetRtpTs() const
inline uint32_t SenderReport::GetRtpTs() const
{ {
return uint32_t{ ntohl(this->header->rtpTs) }; return uint32_t{ ntohl(this->header->rtpTs) };
} }
void SetRtpTs(uint32_t rtpTs)
inline void SenderReport::SetRtpTs(uint32_t rtpTs)
{ {
this->header->rtpTs = uint32_t{ htonl(rtpTs) }; this->header->rtpTs = uint32_t{ htonl(rtpTs) };
} }
uint32_t GetPacketCount() const
inline uint32_t SenderReport::GetPacketCount() const
{ {
return uint32_t{ ntohl(this->header->packetCount) }; return uint32_t{ ntohl(this->header->packetCount) };
} }
void SetPacketCount(uint32_t packetCount)
inline void SenderReport::SetPacketCount(uint32_t packetCount)
{ {
this->header->packetCount = uint32_t{ htonl(packetCount) }; this->header->packetCount = uint32_t{ htonl(packetCount) };
} }
uint32_t GetOctetCount() const
inline uint32_t SenderReport::GetOctetCount() const
{ {
return uint32_t{ ntohl(this->header->octetCount) }; return uint32_t{ ntohl(this->header->octetCount) };
} }
void SetOctetCount(uint32_t octetCount)
inline void SenderReport::SetOctetCount(uint32_t octetCount)
{ {
this->header->octetCount = uint32_t{ htonl(octetCount) }; this->header->octetCount = uint32_t{ htonl(octetCount) };
} }
/* Inline instance methods. */ private:
Header* header{ nullptr };
uint8_t raw[sizeof(Header)]{ 0 };
};
inline SenderReportPacket::SenderReportPacket() : Packet(Type::SR) class SenderReportPacket : public Packet
{ {
} public:
using Iterator = std::vector<SenderReport*>::iterator;
inline SenderReportPacket::SenderReportPacket(CommonHeader* commonHeader) : Packet(commonHeader) public:
static SenderReportPacket* Parse(const uint8_t* data, size_t len);
public:
SenderReportPacket() : Packet(Type::SR)
{ {
} }
explicit SenderReportPacket(CommonHeader* commonHeader) : Packet(commonHeader)
inline SenderReportPacket::~SenderReportPacket() {
}
~SenderReportPacket() override
{ {
for (auto* report : this->reports) for (auto* report : this->reports)
{ {
...@@ -180,12 +123,28 @@ namespace RTC ...@@ -180,12 +123,28 @@ namespace RTC
} }
} }
inline size_t SenderReportPacket::GetCount() const void AddReport(SenderReport* report)
{ {
return 0; this->reports.push_back(report);
}
Iterator Begin()
{
return this->reports.begin();
}
Iterator End()
{
return this->reports.end();
} }
inline size_t SenderReportPacket::GetSize() const /* Pure virtual methods inherited from Packet. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override
{
return 0;
}
size_t GetSize() const override
{ {
size_t size = sizeof(Packet::CommonHeader); size_t size = sizeof(Packet::CommonHeader);
...@@ -197,20 +156,9 @@ namespace RTC ...@@ -197,20 +156,9 @@ namespace RTC
return size; return size;
} }
inline void SenderReportPacket::AddReport(SenderReport* report) private:
{ std::vector<SenderReport*> reports;
this->reports.push_back(report); };
}
inline SenderReportPacket::Iterator SenderReportPacket::Begin()
{
return this->reports.begin();
}
inline SenderReportPacket::Iterator SenderReportPacket::End()
{
return this->reports.end();
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -49,14 +49,22 @@ namespace RTC ...@@ -49,14 +49,22 @@ namespace RTC
static ExtendedReportBlock* Parse(const uint8_t* data, size_t len); static ExtendedReportBlock* Parse(const uint8_t* data, size_t len);
public: public:
ExtendedReportBlock(Type type); ExtendedReportBlock(Type type) : type(type)
{
this->header = reinterpret_cast<CommonHeader*>(this->raw);
this->header->reserved = 0;
}
virtual ~ExtendedReportBlock() = default; virtual ~ExtendedReportBlock() = default;
public: public:
virtual void Dump() const = 0; virtual void Dump() const = 0;
virtual size_t Serialize(uint8_t* buffer) = 0; virtual size_t Serialize(uint8_t* buffer) = 0;
virtual size_t GetSize() const = 0; virtual size_t GetSize() const = 0;
ExtendedReportBlock::Type GetType() const; ExtendedReportBlock::Type GetType() const
{
return this->type;
}
protected: protected:
Type type; Type type;
...@@ -75,92 +83,50 @@ namespace RTC ...@@ -75,92 +83,50 @@ namespace RTC
static ExtendedReportPacket* Parse(const uint8_t* data, size_t len); static ExtendedReportPacket* Parse(const uint8_t* data, size_t len);
public: public:
ExtendedReportPacket(); ExtendedReportPacket() : Packet(Type::XR)
explicit ExtendedReportPacket(CommonHeader* commonHeader);
~ExtendedReportPacket() override;
void AddReport(ExtendedReportBlock* report);
uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc);
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:
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;
} }
explicit ExtendedReportPacket(CommonHeader* commonHeader) : Packet(commonHeader)
inline ExtendedReportBlock::Type ExtendedReportBlock::GetType() const
{ {
return this->type;
} }
~ExtendedReportPacket() override
inline void ExtendedReportPacket::AddReport(ExtendedReportBlock* report)
{ {
this->reports.push_back(report); for (auto* report : this->reports)
}
inline uint32_t ExtendedReportPacket::GetSsrc() const
{ {
return this->ssrc; delete report;
} }
inline void ExtendedReportPacket::SetSsrc(uint32_t ssrc)
{
this->ssrc = ssrc;
} }
/* Inline ExtendedReportPacket instance methods. */ void AddReport(ExtendedReportBlock* report)
inline ExtendedReportPacket::ExtendedReportPacket() : Packet(Type::XR)
{ {
this->reports.push_back(report);
} }
uint32_t GetSsrc() const
inline ExtendedReportPacket::ExtendedReportPacket(CommonHeader* commonHeader)
: Packet(commonHeader)
{ {
return this->ssrc;
} }
void SetSsrc(uint32_t ssrc)
inline ExtendedReportPacket::~ExtendedReportPacket()
{ {
for (auto* report : this->reports) this->ssrc = ssrc;
{
delete report;
}
} }
Iterator Begin()
inline ExtendedReportPacket::Iterator ExtendedReportPacket::Begin()
{ {
return this->reports.begin(); return this->reports.begin();
} }
Iterator End()
inline ExtendedReportPacket::Iterator ExtendedReportPacket::End()
{ {
return this->reports.end(); return this->reports.end();
} }
inline size_t ExtendedReportPacket::GetCount() const /* Pure virtual methods inherited from Packet. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override
{ {
return 0; return 0;
} }
size_t GetSize() const override
inline size_t ExtendedReportPacket::GetSize() const
{ {
size_t size = sizeof(Packet::CommonHeader) + 4u /*ssrc*/; size_t size = sizeof(Packet::CommonHeader) + 4u /*ssrc*/;
...@@ -171,6 +137,11 @@ namespace RTC ...@@ -171,6 +137,11 @@ namespace RTC
return size; return size;
} }
private:
uint32_t ssrc{ 0u };
std::vector<ExtendedReportBlock*> reports;
};
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -47,110 +47,65 @@ namespace RTC ...@@ -47,110 +47,65 @@ namespace RTC
}; };
public: public:
// Parsed Report. Points to an external data.
explicit SsrcInfo(Body* body);
// Locally generated Report. Holds the data internally. // Locally generated Report. Holds the data internally.
SsrcInfo(); SsrcInfo()
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);
private:
Body* body{ nullptr };
uint8_t raw[sizeof(Body)] = { 0 };
};
public:
using Iterator = std::vector<SsrcInfo*>::iterator;
public:
explicit DelaySinceLastRr(CommonHeader* header);
DelaySinceLastRr();
~DelaySinceLastRr();
public:
void AddSsrcInfo(SsrcInfo* ssrcInfo);
Iterator Begin();
Iterator 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); this->body = reinterpret_cast<Body*>(this->raw);
} }
// Parsed Report. Points to an external data.
inline DelaySinceLastRr::SsrcInfo::SsrcInfo(Body* body) : body(body) explicit SsrcInfo(Body* body) : body(body)
{ {
} }
inline size_t DelaySinceLastRr::SsrcInfo::GetSize() const void Dump() const;
size_t Serialize(uint8_t* buffer);
size_t GetSize() const
{ {
return sizeof(Body); return sizeof(Body);
} }
uint32_t GetSsrc() const
inline uint32_t DelaySinceLastRr::SsrcInfo::GetSsrc() const
{ {
return uint32_t{ ntohl(this->body->ssrc) }; return uint32_t{ ntohl(this->body->ssrc) };
} }
void SetSsrc(uint32_t ssrc)
inline void DelaySinceLastRr::SsrcInfo::SetSsrc(uint32_t ssrc)
{ {
this->body->ssrc = uint32_t{ htonl(ssrc) }; this->body->ssrc = uint32_t{ htonl(ssrc) };
} }
uint32_t GetLastReceiverReport() const
inline uint32_t DelaySinceLastRr::SsrcInfo::GetLastReceiverReport() const
{ {
return uint32_t{ ntohl(this->body->lrr) }; return uint32_t{ ntohl(this->body->lrr) };
} }
void SetLastReceiverReport(uint32_t lrr)
inline void DelaySinceLastRr::SsrcInfo::SetLastReceiverReport(uint32_t lrr)
{ {
this->body->lrr = uint32_t{ htonl(lrr) }; this->body->lrr = uint32_t{ htonl(lrr) };
} }
uint32_t GetDelaySinceLastReceiverReport() const
inline uint32_t DelaySinceLastRr::SsrcInfo::GetDelaySinceLastReceiverReport() const
{ {
return uint32_t{ ntohl(this->body->dlrr) }; return uint32_t{ ntohl(this->body->dlrr) };
} }
void SetDelaySinceLastReceiverReport(uint32_t dlrr)
inline void DelaySinceLastRr::SsrcInfo::SetDelaySinceLastReceiverReport(uint32_t dlrr)
{ {
this->body->dlrr = uint32_t{ htonl(dlrr) }; this->body->dlrr = uint32_t{ htonl(dlrr) };
} }
/* Inline DelaySinceLastRr instance methods. */ private:
Body* body{ nullptr };
uint8_t raw[sizeof(Body)] = { 0 };
};
public:
using Iterator = std::vector<SsrcInfo*>::iterator;
inline DelaySinceLastRr::DelaySinceLastRr(CommonHeader* header) public:
: ExtendedReportBlock(ExtendedReportBlock::Type::DLRR) DelaySinceLastRr() : ExtendedReportBlock(ExtendedReportBlock::Type::DLRR)
{ {
this->header = header;
} }
explicit DelaySinceLastRr(CommonHeader* header)
inline DelaySinceLastRr::DelaySinceLastRr()
: ExtendedReportBlock(ExtendedReportBlock::Type::DLRR) : ExtendedReportBlock(ExtendedReportBlock::Type::DLRR)
{ {
this->header = header;
} }
~DelaySinceLastRr()
inline DelaySinceLastRr::~DelaySinceLastRr()
{ {
for (auto* ssrcInfo : this->ssrcInfos) for (auto* ssrcInfo : this->ssrcInfos)
{ {
...@@ -158,24 +113,27 @@ namespace RTC ...@@ -158,24 +113,27 @@ namespace RTC
} }
} }
inline void DelaySinceLastRr::AddSsrcInfo(SsrcInfo* ssrcInfo) public:
void AddSsrcInfo(SsrcInfo* ssrcInfo)
{ {
this->ssrcInfos.push_back(ssrcInfo); this->ssrcInfos.push_back(ssrcInfo);
} }
Iterator Begin()
inline DelaySinceLastRr::Iterator DelaySinceLastRr::Begin()
{ {
return this->ssrcInfos.begin(); return this->ssrcInfos.begin();
} }
Iterator End()
inline DelaySinceLastRr::Iterator DelaySinceLastRr::End()
{ {
return this->ssrcInfos.end(); return this->ssrcInfos.end();
} }
inline size_t DelaySinceLastRr::GetSize() const /* 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
{ {
size_t size{ 4 }; // Common header. size_t size{ 4u }; // Common header.
for (auto* ssrcInfo : this->ssrcInfos) for (auto* ssrcInfo : this->ssrcInfos)
{ {
...@@ -184,6 +142,10 @@ namespace RTC ...@@ -184,6 +142,10 @@ namespace RTC
return size; return size;
} }
private:
std::vector<SsrcInfo*> ssrcInfos;
};
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -34,71 +34,54 @@ namespace RTC ...@@ -34,71 +34,54 @@ namespace RTC
static ReceiverReferenceTime* Parse(const uint8_t* data, size_t len); static ReceiverReferenceTime* Parse(const uint8_t* data, size_t len);
public: public:
// Parsed Report. Points to an external data.
explicit ReceiverReferenceTime(CommonHeader* header);
// Locally generated Report. Holds the data internally. // Locally generated Report. Holds the data internally.
ReceiverReferenceTime(); ReceiverReferenceTime() : ExtendedReportBlock(RTCP::ExtendedReportBlock::Type::RRT)
public:
uint32_t GetNtpSec() const;
void SetNtpSec(uint32_t ntpSec);
uint32_t GetNtpFrac() const;
void SetNtpFrac(uint32_t 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;
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); this->body = reinterpret_cast<Body*>(this->raw);
} }
// Parsed Report. Points to an external data.
inline ReceiverReferenceTime::ReceiverReferenceTime(CommonHeader* header) explicit ReceiverReferenceTime(CommonHeader* header)
: ExtendedReportBlock(ExtendedReportBlock::Type::RRT) : ExtendedReportBlock(ExtendedReportBlock::Type::RRT)
{ {
this->header = header; this->header = header;
this->body = reinterpret_cast<Body*>((header) + 1); this->body = reinterpret_cast<Body*>((header) + 1);
} }
inline size_t ReceiverReferenceTime::GetSize() const public:
{ uint32_t GetNtpSec() 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) }; return uint32_t{ ntohl(this->body->ntpSec) };
} }
void SetNtpSec(uint32_t ntpSec)
inline void ReceiverReferenceTime::SetNtpSec(uint32_t ntpSec)
{ {
this->body->ntpSec = uint32_t{ htonl(ntpSec) }; this->body->ntpSec = uint32_t{ htonl(ntpSec) };
} }
uint32_t GetNtpFrac() const
inline uint32_t ReceiverReferenceTime::GetNtpFrac() const
{ {
return uint32_t{ ntohl(this->body->ntpFrac) }; return uint32_t{ ntohl(this->body->ntpFrac) };
} }
void SetNtpFrac(uint32_t ntpFrac)
inline void ReceiverReferenceTime::SetNtpFrac(uint32_t ntpFrac)
{ {
this->body->ntpFrac = uint32_t{ htonl(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
{
size_t size{ 4 }; // Common header.
size += sizeof(Body);
return size;
}
private:
Body* body{ nullptr };
uint8_t raw[sizeof(Body)] = { 0 };
};
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
...@@ -17,7 +17,10 @@ namespace RTC ...@@ -17,7 +17,10 @@ namespace RTC
public: public:
void Pause(); void Pause();
void Resume(); void Resume();
bool IsPaused() const; bool IsPaused() const
{
return this->paused;
}
virtual void AddProducer(RTC::Producer* producer) = 0; virtual void AddProducer(RTC::Producer* producer) = 0;
virtual void RemoveProducer(RTC::Producer* producer) = 0; virtual void RemoveProducer(RTC::Producer* producer) = 0;
virtual void ReceiveRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) = 0; virtual void ReceiveRtpPacket(RTC::Producer* producer, RTC::RtpPacket* packet) = 0;
...@@ -36,11 +39,6 @@ namespace RTC ...@@ -36,11 +39,6 @@ namespace RTC
// Others. // Others.
bool paused{ false }; bool paused{ false };
}; };
inline bool RtpObserver::IsPaused() const
{
return this->paused;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -31,7 +31,7 @@ namespace RTC ...@@ -31,7 +31,7 @@ namespace RTC
// Passed by argument. // Passed by argument.
Listener* listener{ nullptr }; Listener* listener{ nullptr };
// Others. // Others.
size_t frameStart{ 0 }; // Where the latest frame starts. size_t frameStart{ 0u }; // Where the latest frame starts.
}; };
} // namespace RTC } // namespace RTC
......
差异被折叠。
差异被折叠。
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论