提交 b4429478 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: José Luis Millán

Clang format (fixes #74) (#98)

* More C++ syntax work

* Fix test-rtcp

* More camelCase

* Working on C++ style.

* More C++ styling

* More work in C++ styling

* More work on C++ styling

* C++ style: remove #defines

* doc/RoomOverview.md: some fixes

* More C++ styling: camelCase RTCP

* More C++ styling: camelCase RemoteBitrateEstimator

* C++ styling

* C++ styling

* clang-format proposal

clang-format can be disabled for certain code by using
clang-format [off|on] comments

May be usefull for static class maps for example.

* .clang-format: minimal change

* .clang-format: improve IncludeCategories

* clang-format: improve IncludeCategories

* Logger.hpp: ignore clang-format

* clang-format: mostly done

* Add clang-format off in map initializations

* Remove comment

* "gulp lint" includes C++ linter

* Habemus clang-format
上级 14752064
## Peer.cpp
uint8_t Peer::rtcpBuffer[MS_RTCP_BUFFER_SIZE];
this->timer->Start(uint64_t(RTC::RTCP::MAX_VIDEO_INTERVAL_MS / 2));
if (packet->GetSize() > MS_RTCP_BUFFER_SIZE)
uint64_t interval = RTC::RTCP::MAX_VIDEO_INTERVAL_MS;
if (interval > RTC::RTCP::MAX_VIDEO_INTERVAL_MS)
## RtpReceiver.cpp
uint8_t RtpReceiver::rtcpBuffer[MS_RTCP_BUFFER_SIZE];
if (packet.GetSize() > MS_RTCP_BUFFER_SIZE)
packet.Serialize(RtpReceiver::rtcpBuffer);
##RtpSender.cpp
this->maxRtcpInterval = RTC::RTCP::MAX_AUDIO_INTERVAL_MS;
...@@ -63,26 +63,12 @@ These codecs have the same fields as the peer's capabilities codecs above, with ...@@ -63,26 +63,12 @@ These codecs have the same fields as the peer's capabilities codecs above, with
* `kind` is ignored. * `kind` is ignored.
* `payloadType` MUST match the same value as the one set by the room (otherwise it will fail). * `payloadType` MUST match the same value as the one set by the room (otherwise it will fail).
If `receive()` is called ith a codec that is not supported by the room or not present in the peer's given capabilities, it fails. If `receive()` is called with a codec that is not supported by the room or not present in the peer's given capabilities, it fails.
Unsupported RTCP feedback mechanisms and RTP header extensions not supported by mediasoup or by the peer itself are removed. Unsupported RTCP feedback mechanisms and RTP header extensions not supported by mediasoup or by the peer itself are removed.
Effective RTP parameters are returned to the `receive()` promise. Effective RTP parameters are returned to the `receive()` promise.
After that, C++ `RtpReceiver::FillRtpParameters()` is called. This method does nothing right now.
*TODO:* C++ `RtpReceiver::FillRtpParameters()` should:
* Set a random `muxId` and map the original value.
* If any SSRC value is not given, set a random one and be ready to match the unknown incoming SSRC value to it.
* If not given, set the `rtcp` field.
* Should map the `id` of the supported ones to a static value.
* *NOTE:* This is important so we can deal with PlanB in which all the RTP streams are sent over a single `m=` section.
*TODO:* The whole mapping system could be implemented by maintaing two `RtpParameters` objects within each `RtpReceiver`: the original one and the maped one (although that wouldn't be efficient when it comes to mangle each RTP packet so it may be better to handle an internal value mapping...).
After that, C++ `Peer::onRtpReceiverParametersDone()` is called, which just calls to C++ `Room::onPeerRtpReceiverParameters()`.
`Room::onPeerRtpReceiverParameters()` creates `RtpSenders` associated to this `RtpReceiver` (for every other `Peer` with its capabilities already set) by calling `Peer::AddRtpSender()` on them. `Room::onPeerRtpReceiverParameters()` creates `RtpSenders` associated to this `RtpReceiver` (for every other `Peer` with its capabilities already set) by calling `Peer::AddRtpSender()` on them.
`Peer::AddRtpSender()` takes the associated `RtpParameters` of the `RtpReceiver` as parameter and call `RtpSender::Send(parameters)`. `Peer::AddRtpSender()` takes the associated `RtpParameters` of the `RtpReceiver` as parameter and call `RtpSender::Send(parameters)`.
......
...@@ -92,9 +92,7 @@ gulp.task('rtpcapabilities', () => ...@@ -92,9 +92,7 @@ gulp.task('rtpcapabilities', () =>
.pipe(touch()); .pipe(touch());
}); });
// TODO: Uncomment when C++ syntax and clang-format stuff is done. gulp.task('lint', gulp.series('lint:node', 'lint:worker'));
// gulp.task('lint', gulp.series('lint:node', 'lint:worker'));
gulp.task('lint', gulp.series('lint:node'));
gulp.task('test', gulp.series('test:node', 'test:worker')); gulp.task('test', gulp.series('test:node', 'test:worker'));
......
Language: Cpp
AccessModifierOffset: -2 AccessModifierOffset: -2
AlignConsecutiveAssignments: false AlignAfterOpenBracket: AlwaysBreak
AlignEscapedNewlinesLeft: true AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true AlignOperands: true
AlignTrailingComments: true AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Custom BreakBeforeBraces: Custom
BraceWrapping: BraceWrapping:
AfterClass: true AfterClass: true
...@@ -23,32 +29,47 @@ BraceWrapping: ...@@ -23,32 +29,47 @@ BraceWrapping:
BeforeCatch: true BeforeCatch: true
BeforeElse: true BeforeElse: true
IndentBraces: false IndentBraces: false
BinPackArguments: true
BreakBeforeBinaryOperators: None BreakBeforeBinaryOperators: None
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true BreakConstructorInitializersBeforeComma: true
BreakStringLiterals: true BreakStringLiterals: true
ColumnLimit: 150 ColumnLimit: 100
ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 1 ConstructorInitializerIndentWidth: 4
DerivePointerAlignment: true ContinuationIndentWidth: 4
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: true
IncludeCategories:
- Regex: '"common.hpp"'
Priority: 1
- Regex: '^"(Channel|RTC|handles)/'
Priority: 3
- Regex: '"*"'
Priority: 2
- Regex: '^<(uv|openssl|srtp|json|netstring)(.|/)'
Priority: 4
- Regex: '<*>'
Priority: 5
IncludeIsMainRegex: '$'
IndentCaseLabels: true IndentCaseLabels: true
IndentWidth: 2 IndentWidth: 2
IndentWrappedFunctionNames: true IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MaxEmptyLinesToKeep: 1 MaxEmptyLinesToKeep: 1
NamespaceIndentation: All NamespaceIndentation: All
PenaltyBreakBeforeFirstCallParameter: 100 PenaltyBreakBeforeFirstCallParameter: 5
PenaltyBreakComment: 100 PenaltyBreakComment: 100
PenaltyBreakFirstLessLess: 100 PenaltyBreakFirstLessLess: 200
PenaltyBreakString: 100 PenaltyBreakString: 20
PenaltyExcessCharacter: 100 PenaltyExcessCharacter: 10
PenaltyReturnTypeOnItsOwnLine: 100 PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Left PointerAlignment: Left
ReflowComments: false ReflowComments: true
SortIncludes: false SortIncludes: true
SpaceAfterCStyleCast: true SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements SpaceBeforeParens: ControlStatements
...@@ -56,6 +77,7 @@ SpaceInEmptyParentheses: false ...@@ -56,6 +77,7 @@ SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1 SpacesBeforeTrailingComments: 1
SpacesInAngles: false SpacesInAngles: false
SpacesInCStyleCastParentheses: false SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpacesInParentheses: false SpacesInParentheses: false
SpacesInSquareBrackets: false SpacesInSquareBrackets: false
Standard: Cpp11 Standard: Cpp11
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
#include "common.hpp" #include "common.hpp"
#include "Channel/UnixStreamSocket.hpp" #include "Channel/UnixStreamSocket.hpp"
#include <string>
#include <json/json.h> #include <json/json.h>
#include <string>
namespace Channel namespace Channel
{ {
...@@ -15,7 +15,12 @@ namespace Channel ...@@ -15,7 +15,12 @@ namespace Channel
void Emit(uint32_t targetId, std::string event); void Emit(uint32_t targetId, std::string event);
void Emit(uint32_t targetId, std::string event, Json::Value& data); void Emit(uint32_t targetId, std::string event, Json::Value& data);
void EmitWithBinary(uint32_t targetId, std::string event, Json::Value& data, const uint8_t* binary_data, size_t binary_len); void EmitWithBinary(
uint32_t targetId,
std::string event,
Json::Value& data,
const uint8_t* binaryData,
size_t binaryLen);
public: public:
// Passed by argument. // Passed by argument.
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
#define MS_CHANNEL_REQUEST_HPP #define MS_CHANNEL_REQUEST_HPP
#include "common.hpp" #include "common.hpp"
#include <json/json.h>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <json/json.h>
namespace Channel namespace Channel
{ {
...@@ -50,7 +50,7 @@ namespace Channel ...@@ -50,7 +50,7 @@ namespace Channel
virtual ~Request(); virtual ~Request();
void Accept(); void Accept();
void Accept(Json::Value &data); void Accept(Json::Value& data);
void Reject(std::string& reason); void Reject(std::string& reason);
void Reject(const char* reason = nullptr); void Reject(const char* reason = nullptr);
......
...@@ -2,14 +2,13 @@ ...@@ -2,14 +2,13 @@
#define MS_CHANNEL_UNIX_STREAM_SOCKET_HPP #define MS_CHANNEL_UNIX_STREAM_SOCKET_HPP
#include "common.hpp" #include "common.hpp"
#include "handles/UnixStreamSocket.hpp"
#include "Channel/Request.hpp" #include "Channel/Request.hpp"
#include "handles/UnixStreamSocket.hpp"
#include <json/json.h> #include <json/json.h>
namespace Channel namespace Channel
{ {
class UnixStreamSocket : class UnixStreamSocket : public ::UnixStreamSocket
public ::UnixStreamSocket
{ {
public: public:
class Listener class Listener
...@@ -19,9 +18,6 @@ namespace Channel ...@@ -19,9 +18,6 @@ namespace Channel
virtual void onChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* channel) = 0; virtual void onChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* channel) = 0;
}; };
private:
static uint8_t writeBuffer[];
public: public:
explicit UnixStreamSocket(int fd); explicit UnixStreamSocket(int fd);
...@@ -30,23 +26,23 @@ namespace Channel ...@@ -30,23 +26,23 @@ namespace Channel
public: public:
void SetListener(Listener* listener); void SetListener(Listener* listener);
void Send(Json::Value &json); void Send(Json::Value& json);
void SendLog(char* ns_payload, size_t ns_payload_len); void SendLog(char* nsPayload, size_t nsPayloadLen);
void SendBinary(const uint8_t* ns_payload, size_t ns_payload_len); void SendBinary(const uint8_t* nsPayload, size_t nsPayloadLen);
/* Pure virtual methods inherited from ::UnixStreamSocket. */ /* Pure virtual methods inherited from ::UnixStreamSocket. */
public: public:
virtual void userOnUnixStreamRead() override; virtual void userOnUnixStreamRead() override;
virtual void userOnUnixStreamSocketClosed(bool is_closed_by_peer) override; virtual void userOnUnixStreamSocketClosed(bool isClosedByPeer) override;
private: private:
// Passed by argument. // Passed by argument.
Listener* listener = nullptr; Listener* listener = nullptr;
// Others. // Others.
Json::CharReader* jsonReader = nullptr; Json::CharReader* jsonReader = nullptr;
Json::StreamWriter* jsonWriter = nullptr; Json::StreamWriter* jsonWriter = nullptr;
size_t msgStart = 0; // Where the latest message starts. size_t msgStart = 0; // Where the latest message starts.
bool closed = false; bool closed = false;
}; };
} }
......
#ifndef MS_DEP_LIBSRTP_HPP #ifndef MS_DEP_LIBSRTP_HPP
#define MS_DEP_LIBSRTP_HPP #define MS_DEP_LIBSRTP_HPP
#include <vector>
#include <srtp.h> #include <srtp.h>
#include <vector>
class DepLibSRTP class DepLibSRTP
{ {
...@@ -18,14 +18,12 @@ private: ...@@ -18,14 +18,12 @@ private:
/* Inline static methods. */ /* Inline static methods. */
inline inline bool DepLibSRTP::IsError(srtp_err_status_t code)
bool DepLibSRTP::IsError(srtp_err_status_t code)
{ {
return (code != srtp_err_status_ok); return (code != srtp_err_status_ok);
} }
inline inline const char* DepLibSRTP::GetErrorString(srtp_err_status_t code)
const char* DepLibSRTP::GetErrorString(srtp_err_status_t code)
{ {
// This throws out_of_range if the given index is not in the vector. // This throws out_of_range if the given index is not in the vector.
return DepLibSRTP::errors.at(code); return DepLibSRTP::errors.at(code);
......
#ifndef MS_DEP_LIBUV_HPP #ifndef MS_DEP_LIBUV_HPP
#define MS_DEP_LIBUV_HPP #define MS_DEP_LIBUV_HPP
#include "common.hpp" #include "common.hpp"
#include <uv.h> #include <uv.h>
...@@ -20,14 +20,12 @@ private: ...@@ -20,14 +20,12 @@ private:
/* Inline static methods. */ /* Inline static methods. */
inline inline uv_loop_t* DepLibUV::GetLoop()
uv_loop_t* DepLibUV::GetLoop()
{ {
return DepLibUV::loop; return DepLibUV::loop;
} }
inline inline uint64_t DepLibUV::GetTime()
uint64_t DepLibUV::GetTime()
{ {
return uv_now(DepLibUV::loop); return uv_now(DepLibUV::loop);
} }
......
#ifndef MS_DEP_OPENSSL_HPP #ifndef MS_DEP_OPENSSL_HPP
#define MS_DEP_OPENSSL_HPP #define MS_DEP_OPENSSL_HPP
#include "common.hpp" #include "common.hpp"
#include <openssl/ssl.h>
#include <openssl/crypto.h> #include <openssl/crypto.h>
#include <openssl/ssl.h>
#include <uv.h> #include <uv.h>
/* OpenSSL doc: struct CRYPTO_dynlock_value has to be defined by the application. */ /* OpenSSL doc: struct CRYPTO_dynlock_value has to be defined by the application. */
...@@ -20,7 +20,7 @@ public: ...@@ -20,7 +20,7 @@ public:
private: private:
static void SetThreadId(CRYPTO_THREADID* id); static void SetThreadId(CRYPTO_THREADID* id);
static void LockingFunction(int mode, int n, const char *file, int line); static void LockingFunction(int mode, int n, const char* file, int line);
static CRYPTO_dynlock_value* DynCreateFunction(const char* file, int line); static CRYPTO_dynlock_value* DynCreateFunction(const char* file, int line);
static void DynLockFunction(int mode, CRYPTO_dynlock_value* v, const char* file, int line); static void DynLockFunction(int mode, CRYPTO_dynlock_value* v, const char* file, int line);
static void DynDestroyFunction(CRYPTO_dynlock_value* v, const char* file, int line); static void DynDestroyFunction(CRYPTO_dynlock_value* v, const char* file, int line);
......
#ifndef MS_LOG_LEVEL_HPP #ifndef MS_LOG_LEVEL_HPP
#define MS_LOG_LEVEL_HPP #define MS_LOG_LEVEL_HPP
#include "common.hpp" #include "common.hpp"
......
...@@ -64,17 +64,18 @@ ...@@ -64,17 +64,18 @@
*/ */
#ifndef MS_LOGGER_HPP #ifndef MS_LOGGER_HPP
#define MS_LOGGER_HPP #define MS_LOGGER_HPP
#include "LogLevel.hpp" #include "LogLevel.hpp"
#include "Settings.hpp" #include "Settings.hpp"
#include "Channel/UnixStreamSocket.hpp" #include "Channel/UnixStreamSocket.hpp"
#include <string> #include <cstdio> // std::snprintf(), std::fprintf(), stdout, stderr
#include <cstdio> // std::snprintf(), std::fprintf(), stdout, stderr
#include <cstring>
#include <cstdlib> // std::abort() #include <cstdlib> // std::abort()
#include <cstring>
#include <string>
// clang-format off
#define MS_LOGGER_BUFFER_SIZE 10000
#define _MS_TAG_ENABLED(tag) Settings::configuration.logTags.tag #define _MS_TAG_ENABLED(tag) Settings::configuration.logTags.tag
#define _MS_TAG_ENABLED_2(tag1, tag2) (Settings::configuration.logTags.tag1 || Settings::configuration.logTags.tag2) #define _MS_TAG_ENABLED_2(tag1, tag2) (Settings::configuration.logTags.tag1 || Settings::configuration.logTags.tag2)
#ifdef MS_LOG_DEV #ifdef MS_LOG_DEV
...@@ -113,6 +114,7 @@ public: ...@@ -113,6 +114,7 @@ public:
public: public:
static std::string id; static std::string id;
static Channel::UnixStreamSocket* channel; static Channel::UnixStreamSocket* channel;
static const size_t bufferSize = 10000;
static char buffer[]; static char buffer[];
}; };
...@@ -137,8 +139,8 @@ public: ...@@ -137,8 +139,8 @@ public:
{ \ { \
if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel) \ if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel) \
{ \ { \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D(trace) " _MS_LOG_STR, _MS_LOG_ARG); \ int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "D(trace) " _MS_LOG_STR, _MS_LOG_ARG); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \ } \
} \ } \
while (0) while (0)
...@@ -169,8 +171,8 @@ public: ...@@ -169,8 +171,8 @@ public:
{ \ { \
if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel && (_MS_TAG_ENABLED(tag) || _MS_LOG_DEV_ENABLED)) \ if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel && (_MS_TAG_ENABLED(tag) || _MS_LOG_DEV_ENABLED)) \
{ \ { \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \ } \
} \ } \
while (0) while (0)
...@@ -191,8 +193,8 @@ public: ...@@ -191,8 +193,8 @@ public:
{ \ { \
if (LogLevel::LOG_WARN <= Settings::configuration.logLevel && (_MS_TAG_ENABLED(tag) || _MS_LOG_DEV_ENABLED)) \ if (LogLevel::LOG_WARN <= Settings::configuration.logLevel && (_MS_TAG_ENABLED(tag) || _MS_LOG_DEV_ENABLED)) \
{ \ { \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \ } \
} \ } \
while (0) while (0)
...@@ -213,8 +215,8 @@ public: ...@@ -213,8 +215,8 @@ public:
{ \ { \
if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel && (_MS_TAG_ENABLED_2(tag1, tag2) || _MS_LOG_DEV_ENABLED)) \ if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel && (_MS_TAG_ENABLED_2(tag1, tag2) || _MS_LOG_DEV_ENABLED)) \
{ \ { \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \ } \
} \ } \
while (0) while (0)
...@@ -235,8 +237,8 @@ public: ...@@ -235,8 +237,8 @@ public:
{ \ { \
if (LogLevel::LOG_WARN <= Settings::configuration.logLevel && (_MS_TAG_ENABLED_2(tag1, tag2) || _MS_LOG_DEV_ENABLED)) \ if (LogLevel::LOG_WARN <= Settings::configuration.logLevel && (_MS_TAG_ENABLED_2(tag1, tag2) || _MS_LOG_DEV_ENABLED)) \
{ \ { \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \ } \
} \ } \
while (0) while (0)
...@@ -258,8 +260,8 @@ public: ...@@ -258,8 +260,8 @@ public:
{ \ { \
if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel) \ if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel) \
{ \ { \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \ } \
} \ } \
while (0) while (0)
...@@ -280,8 +282,8 @@ public: ...@@ -280,8 +282,8 @@ public:
{ \ { \
if (LogLevel::LOG_WARN <= Settings::configuration.logLevel) \ if (LogLevel::LOG_WARN <= Settings::configuration.logLevel) \
{ \ { \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \ } \
} \ } \
while (0) while (0)
...@@ -306,8 +308,8 @@ public: ...@@ -306,8 +308,8 @@ public:
#define MS_DUMP(desc, ...) \ #define MS_DUMP(desc, ...) \
do \ do \
{ \ { \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \ } \
while (0) while (0)
...@@ -322,8 +324,8 @@ public: ...@@ -322,8 +324,8 @@ public:
#define MS_ERROR(desc, ...) \ #define MS_ERROR(desc, ...) \
do \ do \
{ \ { \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "E" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "E" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \ } \
while (0) while (0)
...@@ -371,4 +373,6 @@ public: ...@@ -371,4 +373,6 @@ public:
#define MS_ERROR MS_ERROR_STD #define MS_ERROR MS_ERROR_STD
#endif #endif
// clang-format on
#endif #endif
#ifndef MS_LOOP_HPP #ifndef MS_LOOP_HPP
#define MS_LOOP_HPP #define MS_LOOP_HPP
#include "common.hpp" #include "common.hpp"
#include "handles/SignalsHandler.hpp"
#include "Channel/UnixStreamSocket.hpp"
#include "Channel/Request.hpp"
#include "Channel/Notifier.hpp" #include "Channel/Notifier.hpp"
#include "Channel/Request.hpp"
#include "Channel/UnixStreamSocket.hpp"
#include "RTC/Room.hpp" #include "RTC/Room.hpp"
#include "handles/SignalsHandler.hpp"
#include <unordered_map> #include <unordered_map>
class Loop : class Loop : public SignalsHandler::Listener,
public SignalsHandler::Listener, public Channel::UnixStreamSocket::Listener,
public Channel::UnixStreamSocket::Listener, public RTC::Room::Listener
public RTC::Room::Listener
{ {
public: public:
explicit Loop(Channel::UnixStreamSocket* channel); explicit Loop(Channel::UnixStreamSocket* channel);
...@@ -22,16 +21,16 @@ private: ...@@ -22,16 +21,16 @@ private:
void Close(); void Close();
RTC::Room* GetRoomFromRequest(Channel::Request* request, uint32_t* roomId = nullptr); RTC::Room* GetRoomFromRequest(Channel::Request* request, uint32_t* roomId = nullptr);
/* Methods inherited from SignalsHandler::Listener. */ /* Methods inherited from SignalsHandler::Listener. */
public: public:
virtual void onSignal(SignalsHandler* signalsHandler, int signum) override; virtual void onSignal(SignalsHandler* signalsHandler, int signum) override;
/* Methods inherited from Channel::lUnixStreamSocket::Listener. */ /* Methods inherited from Channel::lUnixStreamSocket::Listener. */
public: public:
virtual void onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request* request) override; virtual void onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request* request) override;
virtual void onChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* channel) override; virtual void onChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* channel) override;
/* Methods inherited from RTC::Room::Listener. */ /* Methods inherited from RTC::Room::Listener. */
public: public:
virtual void onRoomClosed(RTC::Room* room) override; virtual void onRoomClosed(RTC::Room* room) override;
...@@ -39,7 +38,7 @@ private: ...@@ -39,7 +38,7 @@ private:
// Passed by argument. // Passed by argument.
Channel::UnixStreamSocket* channel = nullptr; Channel::UnixStreamSocket* channel = nullptr;
// Allocated by this. // Allocated by this.
Channel::Notifier* notifier = nullptr; Channel::Notifier* notifier = nullptr;
SignalsHandler* signalsHandler = nullptr; SignalsHandler* signalsHandler = nullptr;
// Others. // Others.
bool closed = false; bool closed = false;
......
...@@ -2,12 +2,10 @@ ...@@ -2,12 +2,10 @@
#define MS_MEDIASOUP_ERROR_HPP #define MS_MEDIASOUP_ERROR_HPP
#include "Logger.hpp" #include "Logger.hpp"
#include <cstdio> // std::snprintf()
#include <stdexcept> #include <stdexcept>
#include <string>
#include <cstdio> // std::snprintf
class MediaSoupError : class MediaSoupError : public std::runtime_error
public std::runtime_error
{ {
public: public:
explicit MediaSoupError(const char* description); explicit MediaSoupError(const char* description);
...@@ -15,29 +13,27 @@ public: ...@@ -15,29 +13,27 @@ public:
/* Inline methods. */ /* Inline methods. */
inline inline MediaSoupError::MediaSoupError(const char* description)
MediaSoupError::MediaSoupError(const char* description) : : std::runtime_error(description)
std::runtime_error(description) {
{} }
#define MS_THROW_ERROR(desc, ...) \ #define MS_THROW_ERROR(desc, ...) \
do \ do \
{ \ { \
MS_ERROR("throwing MediaSoupError | " desc, ##__VA_ARGS__); \ MS_ERROR("throwing MediaSoupError | " desc, ##__VA_ARGS__); \
static char buffer[2000]; \ static char buffer[2000]; \
std::snprintf(buffer, 2000, desc, ##__VA_ARGS__); \ std::snprintf(buffer, 2000, desc, ##__VA_ARGS__); \
throw MediaSoupError(buffer); \ throw MediaSoupError(buffer); \
} \ } while (0)
while (0)
#define MS_THROW_ERROR_STD(desc, ...) \ #define MS_THROW_ERROR_STD(desc, ...) \
do \ do \
{ \ { \
MS_ERROR_STD("throwing MediaSoupError | " desc, ##__VA_ARGS__); \ MS_ERROR_STD("throwing MediaSoupError | " desc, ##__VA_ARGS__); \
static char buffer[2000]; \ static char buffer[2000]; \
std::snprintf(buffer, 2000, desc, ##__VA_ARGS__); \ std::snprintf(buffer, 2000, desc, ##__VA_ARGS__); \
throw MediaSoupError(buffer); \ throw MediaSoupError(buffer); \
} \ } while (0)
while (0)
#endif #endif
...@@ -4,19 +4,17 @@ ...@@ -4,19 +4,17 @@
#include "common.hpp" #include "common.hpp"
#include "RTC/SrtpSession.hpp" #include "RTC/SrtpSession.hpp"
#include "handles/Timer.hpp" #include "handles/Timer.hpp"
#include <string> #include <json/json.h>
#include <map>
#include <vector>
#include <openssl/ssl.h>
#include <openssl/bio.h> #include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/bio.h> #include <map>
#include <json/json.h> #include <string>
#include <vector>
namespace RTC namespace RTC
{ {
class DtlsTransport : class DtlsTransport : public Timer::Listener
public Timer::Listener
{ {
public: public:
enum class DtlsState enum class DtlsState
...@@ -52,7 +50,7 @@ namespace RTC ...@@ -52,7 +50,7 @@ namespace RTC
struct Fingerprint struct Fingerprint
{ {
FingerprintAlgorithm algorithm; FingerprintAlgorithm algorithm;
std::string value; std::string value;
}; };
private: private:
...@@ -69,24 +67,33 @@ namespace RTC ...@@ -69,24 +67,33 @@ namespace RTC
// DTLS is in the process of negotiating a secure connection. Incoming // DTLS is in the process of negotiating a secure connection. Incoming
// media can flow through. // media can flow through.
// NOTE: The caller MUST NOT call any method during this callback. // NOTE: The caller MUST NOT call any method during this callback.
virtual void onDtlsConnecting(const DtlsTransport* dtlsTransport) = 0; virtual void onDtlsConnecting(const RTC::DtlsTransport* dtlsTransport) = 0;
// DTLS has completed negotiation of a secure connection (including DTLS-SRTP // DTLS has completed negotiation of a secure connection (including DTLS-SRTP
// and remote fingerprint verification). Outgoing media can now flow through. // and remote fingerprint verification). Outgoing media can now flow through.
// NOTE: The caller MUST NOT call any method during this callback. // NOTE: The caller MUST NOT call any method during this callback.
virtual void onDtlsConnected(const DtlsTransport* dtlsTransport, RTC::SrtpSession::Profile srtp_profile, uint8_t* srtp_local_key, size_t srtp_local_key_len, uint8_t* srtp_remote_key, size_t srtp_remote_key_len, std::string& remoteCert) = 0; virtual void onDtlsConnected(
const RTC::DtlsTransport* dtlsTransport,
RTC::SrtpSession::Profile srtpProfile,
uint8_t* srtpLocalKey,
size_t srtpLocalKeyLen,
uint8_t* srtpRemoteKey,
size_t srtpRemoteKeyLen,
std::string& remoteCert) = 0;
// The DTLS connection has been closed as the result of an error (such as a // The DTLS connection has been closed as the result of an error (such as a
// DTLS alert or a failure to validate the remote fingerprint). // DTLS alert or a failure to validate the remote fingerprint).
// NOTE: The caller MUST NOT call Destroy() during this callback. // NOTE: The caller MUST NOT call Destroy() during this callback.
virtual void onDtlsFailed(const DtlsTransport* dtlsTransport) = 0; virtual void onDtlsFailed(const RTC::DtlsTransport* dtlsTransport) = 0;
// The DTLS connection has been closed due to receipt of a close_notify alert. // The DTLS connection has been closed due to receipt of a close_notify alert.
// NOTE: The caller MUST NOT call Destroy() during this callback. // NOTE: The caller MUST NOT call Destroy() during this callback.
virtual void onDtlsClosed(const DtlsTransport* dtlsTransport) = 0; virtual void onDtlsClosed(const RTC::DtlsTransport* dtlsTransport) = 0;
// Need to send DTLS data to the peer. // Need to send DTLS data to the peer.
// NOTE: The caller MUST NOT call Destroy() during this callback. // NOTE: The caller MUST NOT call Destroy() during this callback.
virtual void onOutgoingDtlsData(const DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0; virtual void onOutgoingDtlsData(
const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0;
// DTLS application data received. // DTLS application data received.
// NOTE: The caller MUST NOT call Destroy() during this callback. // NOTE: The caller MUST NOT call Destroy() during this callback.
virtual void onDtlsApplicationData(const DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0; virtual void onDtlsApplicationData(
const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0;
}; };
public: public:
...@@ -137,14 +144,14 @@ namespace RTC ...@@ -137,14 +144,14 @@ namespace RTC
bool SetTimeout(); bool SetTimeout();
void ProcessHandshake(); void ProcessHandshake();
bool CheckRemoteFingerprint(); bool CheckRemoteFingerprint();
void ExtractSrtpKeys(RTC::SrtpSession::Profile srtp_profile); void ExtractSrtpKeys(RTC::SrtpSession::Profile srtpProfile);
RTC::SrtpSession::Profile GetNegotiatedSrtpProfile(); RTC::SrtpSession::Profile GetNegotiatedSrtpProfile();
/* Callbacks fired by OpenSSL events. */ /* Callbacks fired by OpenSSL events. */
public: public:
void onSSLInfo(int where, int ret); void onSSLInfo(int where, int ret);
/* Pure virtual methods inherited from Timer::Listener. */ /* Pure virtual methods inherited from Timer::Listener. */
public: public:
virtual void onTimer(Timer* timer) override; virtual void onTimer(Timer* timer) override;
...@@ -152,29 +159,27 @@ namespace RTC ...@@ -152,29 +159,27 @@ namespace RTC
// Passed by argument. // Passed by argument.
Listener* listener = nullptr; Listener* listener = nullptr;
// Allocated by this. // Allocated by this.
SSL* ssl = nullptr; SSL* ssl = nullptr;
BIO* sslBioFromNetwork = nullptr; // The BIO from which ssl reads. BIO* sslBioFromNetwork = nullptr; // The BIO from which ssl reads.
BIO* sslBioToNetwork = nullptr; // The BIO in which ssl writes. BIO* sslBioToNetwork = nullptr; // The BIO in which ssl writes.
Timer* timer = nullptr; Timer* timer = nullptr;
// Others. // Others.
DtlsState state = DtlsState::NEW; DtlsState state = DtlsState::NEW;
Role localRole = Role::NONE; Role localRole = Role::NONE;
Fingerprint remoteFingerprint = { FingerprintAlgorithm::NONE, "" }; Fingerprint remoteFingerprint = {FingerprintAlgorithm::NONE, ""};
bool handshakeDone = false; bool handshakeDone = false;
bool handshakeDoneNow = false; bool handshakeDoneNow = false;
std::string remoteCert; std::string remoteCert;
}; };
/* Inline static methods. */ /* Inline static methods. */
inline inline Json::Value& DtlsTransport::GetLocalFingerprints()
Json::Value& DtlsTransport::GetLocalFingerprints()
{ {
return DtlsTransport::localFingerprints; return DtlsTransport::localFingerprints;
} }
inline inline DtlsTransport::Role DtlsTransport::StringToRole(std::string role)
DtlsTransport::Role DtlsTransport::StringToRole(std::string role)
{ {
auto it = DtlsTransport::string2Role.find(role); auto it = DtlsTransport::string2Role.find(role);
...@@ -184,8 +189,7 @@ namespace RTC ...@@ -184,8 +189,7 @@ namespace RTC
return DtlsTransport::Role::NONE; return DtlsTransport::Role::NONE;
} }
inline inline DtlsTransport::FingerprintAlgorithm DtlsTransport::GetFingerprintAlgorithm(std::string fingerprint)
DtlsTransport::FingerprintAlgorithm DtlsTransport::GetFingerprintAlgorithm(std::string fingerprint)
{ {
auto it = DtlsTransport::string2FingerprintAlgorithm.find(fingerprint); auto it = DtlsTransport::string2FingerprintAlgorithm.find(fingerprint);
...@@ -195,33 +199,28 @@ namespace RTC ...@@ -195,33 +199,28 @@ namespace RTC
return DtlsTransport::FingerprintAlgorithm::NONE; return DtlsTransport::FingerprintAlgorithm::NONE;
} }
inline inline bool DtlsTransport::IsDtls(const uint8_t* data, size_t len)
bool DtlsTransport::IsDtls(const uint8_t* data, size_t len)
{ {
return ( return (
// Minimum DTLS record length is 13 bytes. // Minimum DTLS record length is 13 bytes.
(len >= 13) && (len >= 13) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 19 && data[0] < 64) (data[0] > 19 && data[0] < 64));
);
} }
/* Inline instance methods. */ /* Inline instance methods. */
inline inline DtlsTransport::DtlsState DtlsTransport::GetState() const
DtlsTransport::DtlsState DtlsTransport::GetState() const
{ {
return this->state; return this->state;
} }
inline inline DtlsTransport::Role DtlsTransport::GetLocalRole() const
DtlsTransport::Role DtlsTransport::GetLocalRole() const
{ {
return this->localRole; return this->localRole;
} }
inline inline bool DtlsTransport::IsRunning() const
bool DtlsTransport::IsRunning() const
{ {
switch (this->state) switch (this->state)
{ {
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
#define MS_RTC_ICE_CANDIDATE_HPP #define MS_RTC_ICE_CANDIDATE_HPP
#include "common.hpp" #include "common.hpp"
#include "RTC/UdpSocket.hpp"
#include "RTC/TcpServer.hpp" #include "RTC/TcpServer.hpp"
#include <string> #include "RTC/UdpSocket.hpp"
#include <json/json.h> #include <json/json.h>
#include <string>
namespace RTC namespace RTC
{ {
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
#include "common.hpp" #include "common.hpp"
#include "RTC/StunMessage.hpp" #include "RTC/StunMessage.hpp"
#include "RTC/TransportTuple.hpp" #include "RTC/TransportTuple.hpp"
#include <string>
#include <list> #include <list>
#include <string>
namespace RTC namespace RTC
{ {
...@@ -24,18 +24,19 @@ namespace RTC ...@@ -24,18 +24,19 @@ namespace RTC
class Listener class Listener
{ {
public: public:
virtual ~Listener() {}; virtual ~Listener(){};
public: public:
/** /**
* These callbacks are guaranteed to be called before ProcessStunMessage() * These callbacks are guaranteed to be called before ProcessStunMessage()
* returns, so the given pointers are still usable. * returns, so the given pointers are still usable.
*/ */
virtual void onOutgoingStunMessage(const IceServer* iceServer, const RTC::StunMessage* msg, RTC::TransportTuple* tuple) = 0; virtual void onOutgoingStunMessage(
virtual void onIceSelectedTuple(const IceServer* iceServer, RTC::TransportTuple* tuple) = 0; const RTC::IceServer* iceServer, const RTC::StunMessage* msg, RTC::TransportTuple* tuple) = 0;
virtual void onIceConnected(const IceServer* iceServer) = 0; virtual void onIceSelectedTuple(const RTC::IceServer* iceServer, RTC::TransportTuple* tuple) = 0;
virtual void onIceCompleted(const IceServer* iceServer) = 0; virtual void onIceConnected(const RTC::IceServer* iceServer) = 0;
virtual void onIceDisconnected(const IceServer* iceServer) = 0; virtual void onIceCompleted(const RTC::IceServer* iceServer) = 0;
virtual void onIceDisconnected(const RTC::IceServer* iceServer) = 0;
}; };
public: public:
...@@ -81,20 +82,17 @@ namespace RTC ...@@ -81,20 +82,17 @@ namespace RTC
/* Inline instance methods. */ /* Inline instance methods. */
inline inline const std::string& IceServer::GetUsernameFragment() const
const std::string& IceServer::GetUsernameFragment() const
{ {
return this->usernameFragment; return this->usernameFragment;
} }
inline inline const std::string& IceServer::GetPassword() const
const std::string& IceServer::GetPassword() const
{ {
return this->password; return this->password;
} }
inline inline IceServer::IceState IceServer::GetState() const
IceServer::IceState IceServer::GetState() const
{ {
return this->state; return this->state;
} }
......
...@@ -9,27 +9,26 @@ ...@@ -9,27 +9,26 @@
namespace RTC namespace RTC
{ {
class NackGenerator : class NackGenerator : public Timer::Listener
public Timer::Listener
{ {
public: public:
class Listener class Listener
{ {
public: public:
virtual void onNackRequired(const std::vector<uint16_t>& seqNumbers) = 0; virtual void onNackRequired(const std::vector<uint16_t>& seqNumbers) = 0;
virtual void onFullFrameRequired() = 0; virtual void onFullFrameRequired() = 0;
}; };
private: private:
struct NackInfo struct NackInfo
{ {
NackInfo() {}; NackInfo(){};
explicit NackInfo(uint32_t seq32, uint32_t sendAtSeqNum); explicit NackInfo(uint32_t seq32, uint32_t sendAtSeqNum);
uint32_t seq32 = 0; uint32_t seq32 = 0;
uint32_t sendAtSeqNum = 0; uint32_t sendAtSeqNum = 0;
uint64_t sentAtTime = 0; uint64_t sentAtTime = 0;
uint8_t retries = 0; uint8_t retries = 0;
}; };
enum class NackFilter enum class NackFilter
...@@ -49,7 +48,7 @@ namespace RTC ...@@ -49,7 +48,7 @@ namespace RTC
std::vector<uint16_t> GetNackBatch(NackFilter filter); std::vector<uint16_t> GetNackBatch(NackFilter filter);
void MayRunTimer() const; void MayRunTimer() const;
/* Pure virtual methods inherited from Timer::Listener. */ /* Pure virtual methods inherited from Timer::Listener. */
public: public:
virtual void onTimer(Timer* timer) override; virtual void onTimer(Timer* timer) override;
...@@ -60,18 +59,18 @@ namespace RTC ...@@ -60,18 +59,18 @@ namespace RTC
Timer* timer = nullptr; Timer* timer = nullptr;
// Others. // Others.
std::map<uint32_t, NackInfo> nackList; std::map<uint32_t, NackInfo> nackList;
bool started = false; bool started = false;
uint32_t lastSeq32 = 0; // Extended seq number of last valid packet. uint32_t lastSeq32 = 0; // Extended seq number of last valid packet.
uint32_t rtt = 0; // Round trip time (ms). uint32_t rtt = 0; // Round trip time (ms).
}; };
// Inline instance methods. // Inline instance methods.
inline inline NackGenerator::NackInfo::NackInfo(uint32_t seq32, uint32_t sendAtSeqNum)
NackGenerator::NackInfo::NackInfo(uint32_t seq32, uint32_t sendAtSeqNum) : : seq32(seq32)
seq32(seq32), , sendAtSeqNum(sendAtSeqNum)
sendAtSeqNum(sendAtSeqNum) {
{} }
} }
#endif #endif
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
#define MS_RTC_PARAMETERS_HPP #define MS_RTC_PARAMETERS_HPP
#include "common.hpp" #include "common.hpp"
#include <json/json.h>
#include <string> #include <string>
#include <vector>
#include <unordered_map> #include <unordered_map>
#include <json/json.h> #include <vector>
namespace RTC namespace RTC
{ {
...@@ -25,44 +25,49 @@ namespace RTC ...@@ -25,44 +25,49 @@ namespace RTC
}; };
public: public:
Value() {}; Value(){};
explicit Value(bool booleanValue) : explicit Value(bool booleanValue)
type(Type::BOOLEAN), : type(Type::BOOLEAN)
booleanValue(booleanValue) , booleanValue(booleanValue)
{} {
}
explicit Value(int32_t integerValue) : explicit Value(int32_t integerValue)
type(Type::INTEGER), : type(Type::INTEGER)
integerValue(integerValue) , integerValue(integerValue)
{} {
}
explicit Value(double doubleValue) : explicit Value(double doubleValue)
type(Type::DOUBLE), : type(Type::DOUBLE)
doubleValue(doubleValue) , doubleValue(doubleValue)
{} {
}
explicit Value(std::string& stringValue) : explicit Value(std::string& stringValue)
type(Type::STRING), : type(Type::STRING)
stringValue(stringValue) , stringValue(stringValue)
{} {
}
explicit Value(std::vector<int32_t>& arrayOfIntegers) : explicit Value(std::vector<int32_t>& arrayOfIntegers)
type(Type::ARRAY_OF_INTEGERS), : type(Type::ARRAY_OF_INTEGERS)
arrayOfIntegers(arrayOfIntegers) , arrayOfIntegers(arrayOfIntegers)
{} {
}
public: public:
Type type; Type type;
bool booleanValue = false; bool booleanValue = false;
int32_t integerValue = 0; int32_t integerValue = 0;
double doubleValue = 0.0; double doubleValue = 0.0;
std::string stringValue; std::string stringValue;
std::vector<int32_t> arrayOfIntegers; std::vector<int32_t> arrayOfIntegers;
}; };
public: public:
Parameters() {}; Parameters(){};
Json::Value toJson() const; Json::Value toJson() const;
void Set(Json::Value& data); void Set(Json::Value& data);
...@@ -92,8 +97,7 @@ namespace RTC ...@@ -92,8 +97,7 @@ namespace RTC
/* Inline methods. */ /* Inline methods. */
inline inline bool Parameters::HasBoolean(std::string& key)
bool Parameters::HasBoolean(std::string& key)
{ {
if (this->mapKeyValues.find(key) == this->mapKeyValues.end()) if (this->mapKeyValues.find(key) == this->mapKeyValues.end())
return false; return false;
...@@ -101,8 +105,7 @@ namespace RTC ...@@ -101,8 +105,7 @@ namespace RTC
return this->mapKeyValues[key].type == Value::Type::BOOLEAN; return this->mapKeyValues[key].type == Value::Type::BOOLEAN;
} }
inline inline bool Parameters::HasInteger(std::string& key)
bool Parameters::HasInteger(std::string& key)
{ {
if (this->mapKeyValues.find(key) == this->mapKeyValues.end()) if (this->mapKeyValues.find(key) == this->mapKeyValues.end())
return false; return false;
...@@ -110,8 +113,7 @@ namespace RTC ...@@ -110,8 +113,7 @@ namespace RTC
return this->mapKeyValues[key].type == Value::Type::INTEGER; return this->mapKeyValues[key].type == Value::Type::INTEGER;
} }
inline inline bool Parameters::HasDouble(std::string& key)
bool Parameters::HasDouble(std::string& key)
{ {
if (this->mapKeyValues.find(key) == this->mapKeyValues.end()) if (this->mapKeyValues.find(key) == this->mapKeyValues.end())
return false; return false;
...@@ -119,8 +121,7 @@ namespace RTC ...@@ -119,8 +121,7 @@ namespace RTC
return this->mapKeyValues[key].type == Value::Type::DOUBLE; return this->mapKeyValues[key].type == Value::Type::DOUBLE;
} }
inline inline bool Parameters::HasString(std::string& key)
bool Parameters::HasString(std::string& key)
{ {
if (this->mapKeyValues.find(key) == this->mapKeyValues.end()) if (this->mapKeyValues.find(key) == this->mapKeyValues.end())
return false; return false;
...@@ -128,8 +129,7 @@ namespace RTC ...@@ -128,8 +129,7 @@ namespace RTC
return this->mapKeyValues[key].type == Value::Type::STRING; return this->mapKeyValues[key].type == Value::Type::STRING;
} }
inline inline bool Parameters::HasArrayOfIntegers(std::string& key)
bool Parameters::HasArrayOfIntegers(std::string& key)
{ {
if (this->mapKeyValues.find(key) == this->mapKeyValues.end()) if (this->mapKeyValues.find(key) == this->mapKeyValues.end())
return false; return false;
...@@ -137,8 +137,7 @@ namespace RTC ...@@ -137,8 +137,7 @@ namespace RTC
return this->mapKeyValues[key].type == Value::Type::ARRAY_OF_INTEGERS; return this->mapKeyValues[key].type == Value::Type::ARRAY_OF_INTEGERS;
} }
inline inline bool Parameters::IncludesInteger(std::string& key, int32_t integer)
bool Parameters::IncludesInteger(std::string& key, int32_t integer)
{ {
if (this->mapKeyValues.find(key) == this->mapKeyValues.end()) if (this->mapKeyValues.find(key) == this->mapKeyValues.end())
return false; return false;
...@@ -148,32 +147,27 @@ namespace RTC ...@@ -148,32 +147,27 @@ namespace RTC
return std::find(array.begin(), array.end(), integer) != array.end(); return std::find(array.begin(), array.end(), integer) != array.end();
} }
inline inline void Parameters::SetBoolean(std::string& key, bool booleanValue)
void Parameters::SetBoolean(std::string& key, bool booleanValue)
{ {
this->mapKeyValues[key] = Value(booleanValue); this->mapKeyValues[key] = Value(booleanValue);
} }
inline inline void Parameters::SetInteger(std::string& key, int32_t integerValue)
void Parameters::SetInteger(std::string& key, int32_t integerValue)
{ {
this->mapKeyValues[key] = Value(integerValue); this->mapKeyValues[key] = Value(integerValue);
} }
inline inline void Parameters::SetDouble(std::string& key, double doubleValue)
void Parameters::SetDouble(std::string& key, double doubleValue)
{ {
this->mapKeyValues[key] = Value(doubleValue); this->mapKeyValues[key] = Value(doubleValue);
} }
inline inline void Parameters::SetString(std::string& key, std::string& stringValue)
void Parameters::SetString(std::string& key, std::string& stringValue)
{ {
this->mapKeyValues[key] = Value(stringValue); this->mapKeyValues[key] = Value(stringValue);
} }
inline inline void Parameters::SetArrayOfIntegers(std::string& key, std::vector<int32_t>& arrayOfIntegers)
void Parameters::SetArrayOfIntegers(std::string& key, std::vector<int32_t>& arrayOfIntegers)
{ {
this->mapKeyValues[key] = Value(arrayOfIntegers); this->mapKeyValues[key] = Value(arrayOfIntegers);
} }
......
...@@ -2,50 +2,52 @@ ...@@ -2,50 +2,52 @@
#define MS_RTC_PEER_HPP #define MS_RTC_PEER_HPP
#include "common.hpp" #include "common.hpp"
#include "RTC/Transport.hpp" #include "Channel/Notifier.hpp"
#include "RTC/RtpReceiver.hpp" #include "Channel/Request.hpp"
#include "RTC/RtpSender.hpp" #include "RTC/RTCP/Feedback.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/RTCP/ReceiverReport.hpp" #include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/SenderReport.hpp" #include "RTC/RTCP/SenderReport.hpp"
#include "RTC/RTCP/Feedback.hpp" #include "RTC/RtpDictionaries.hpp"
#include "Channel/Request.hpp" #include "RTC/RtpPacket.hpp"
#include "Channel/Notifier.hpp" #include "RTC/RtpReceiver.hpp"
#include "RTC/RtpSender.hpp"
#include "RTC/Transport.hpp"
#include "handles/Timer.hpp" #include "handles/Timer.hpp"
#include <json/json.h>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <json/json.h>
namespace RTC namespace RTC
{ {
class Peer : class Peer : public RTC::Transport::Listener,
public RTC::Transport::Listener, public RTC::RtpReceiver::Listener,
public RTC::RtpReceiver::Listener, public RTC::RtpSender::Listener,
public RTC::RtpSender::Listener, public Timer::Listener
public Timer::Listener
{ {
public: public:
class Listener class Listener
{ {
public: public:
virtual void onPeerClosed(const RTC::Peer* peer) = 0; virtual void onPeerClosed(const RTC::Peer* peer) = 0;
virtual void onPeerCapabilities(RTC::Peer* peer, RTC::RtpCapabilities* capabilities) = 0; virtual void onPeerCapabilities(RTC::Peer* peer, RTC::RtpCapabilities* capabilities) = 0;
virtual void onPeerRtpReceiverParameters(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver) = 0; virtual void onPeerRtpReceiverParameters(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver) = 0;
virtual void onPeerRtpReceiverClosed(const RTC::Peer* peer, const RTC::RtpReceiver* rtpReceiver) = 0; virtual void onPeerRtpReceiverClosed(
const RTC::Peer* peer, const RTC::RtpReceiver* rtpReceiver) = 0;
virtual void onPeerRtpSenderClosed(const RTC::Peer* peer, RTC::RtpSender* rtpSender) = 0; virtual void onPeerRtpSenderClosed(const RTC::Peer* peer, RTC::RtpSender* rtpSender) = 0;
virtual void onPeerRtpPacket(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) = 0; virtual void onPeerRtpPacket(
virtual void onPeerRtcpReceiverReport(const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::ReceiverReport* report) = 0; const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) = 0;
virtual void onPeerRtcpFeedback(const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackPsPacket* packet) = 0; virtual void onPeerRtcpReceiverReport(
virtual void onPeerRtcpFeedback(const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackRtpPacket* packet) = 0; const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::ReceiverReport* report) = 0;
virtual void onPeerRtcpSenderReport(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RTCP::SenderReport* report) = 0; virtual void onPeerRtcpFeedback(
const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackPsPacket* packet) = 0;
virtual void onPeerRtcpFeedback(
const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackRtpPacket* packet) = 0;
virtual void onPeerRtcpSenderReport(
const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RTCP::SenderReport* report) = 0;
virtual void onFullFrameRequired(RTC::Peer* peer, RTC::RtpSender* rtpSender) = 0; virtual void onFullFrameRequired(RTC::Peer* peer, RTC::RtpSender* rtpSender) = 0;
}; };
private:
static uint8_t rtcpBuffer[];
public: public:
Peer(Listener* listener, Channel::Notifier* notifier, uint32_t peerId, std::string& peerName); Peer(Listener* listener, Channel::Notifier* notifier, uint32_t peerId, std::string& peerName);
...@@ -62,37 +64,41 @@ namespace RTC ...@@ -62,37 +64,41 @@ namespace RTC
const std::unordered_map<uint32_t, RTC::Transport*>& GetTransports() const; const std::unordered_map<uint32_t, RTC::Transport*>& GetTransports() const;
/** /**
* Add a new RtpSender to the Peer. * Add a new RtpSender to the Peer.
* @param rtpSender Instance of RtpSender. * @param rtpSender - Instance of RtpSender.
* @param peerName Name of the receiver Peer. * @param peerName - Name of the receiver Peer.
*/ */
void AddRtpSender(RTC::RtpSender* rtpSender, const std::string& peerName, RTC::RtpParameters* rtpParameters); void AddRtpSender(
RTC::RtpSender* rtpSender, const std::string& peerName, RTC::RtpParameters* rtpParameters);
RTC::RtpSender* GetRtpSender(uint32_t ssrc) const; RTC::RtpSender* GetRtpSender(uint32_t ssrc) const;
void SendRtcp(uint64_t now); void SendRtcp(uint64_t now);
private: private:
RTC::Transport* GetTransportFromRequest(Channel::Request* request, uint32_t* transportId = nullptr) const; RTC::Transport* GetTransportFromRequest(
RTC::RtpReceiver* GetRtpReceiverFromRequest(Channel::Request* request, uint32_t* rtpReceiverId = nullptr) const; Channel::Request* request, uint32_t* transportId = nullptr) const;
RTC::RtpSender* GetRtpSenderFromRequest(Channel::Request* request, uint32_t* rtpSenderId = nullptr) const; RTC::RtpReceiver* GetRtpReceiverFromRequest(
Channel::Request* request, uint32_t* rtpReceiverId = nullptr) const;
/* Pure virtual methods inherited from RTC::Transport::Listener. */ RTC::RtpSender* GetRtpSenderFromRequest(
Channel::Request* request, uint32_t* rtpSenderId = nullptr) const;
/* Pure virtual methods inherited from RTC::Transport::Listener. */
public: public:
virtual void onTransportConnected(RTC::Transport* transport) override; virtual void onTransportConnected(RTC::Transport* transport) override;
virtual void onTransportClosed(RTC::Transport* transport) override; virtual void onTransportClosed(RTC::Transport* transport) override;
virtual void onTransportRtcpPacket(RTC::Transport* transport, RTC::RTCP::Packet* packet) override; virtual void onTransportRtcpPacket(RTC::Transport* transport, RTC::RTCP::Packet* packet) override;
virtual void onTransportFullFrameRequired(RTC::Transport* transport) override; virtual void onTransportFullFrameRequired(RTC::Transport* transport) override;
/* Pure virtual methods inherited from RTC::RtpReceiver::Listener. */ /* Pure virtual methods inherited from RTC::RtpReceiver::Listener. */
public: public:
virtual void onRtpReceiverParameters(RTC::RtpReceiver* rtpReceiver) override; virtual void onRtpReceiverParameters(RTC::RtpReceiver* rtpReceiver) override;
virtual void onRtpReceiverParametersDone(RTC::RtpReceiver* rtpReceiver) override; virtual void onRtpReceiverParametersDone(RTC::RtpReceiver* rtpReceiver) override;
virtual void onRtpPacket(RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) override; virtual void onRtpPacket(RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) override;
virtual void onRtpReceiverClosed(const RTC::RtpReceiver* rtpReceiver) override; virtual void onRtpReceiverClosed(const RTC::RtpReceiver* rtpReceiver) override;
/* Pure virtual methods inherited from RTC::RtpSender::Listener. */ /* Pure virtual methods inherited from RTC::RtpSender::Listener. */
public: public:
virtual void onRtpSenderClosed(RTC::RtpSender* rtpSender) override; virtual void onRtpSenderClosed(RTC::RtpSender* rtpSender) override;
/* Pure virtual methods inherited from Timer::Listener. */ /* Pure virtual methods inherited from Timer::Listener. */
public: public:
virtual void onTimer(Timer* timer) override; virtual void onTimer(Timer* timer) override;
...@@ -103,10 +109,10 @@ namespace RTC ...@@ -103,10 +109,10 @@ namespace RTC
private: private:
// Passed by argument. // Passed by argument.
Listener* listener = nullptr; Listener* listener = nullptr;
Channel::Notifier* notifier = nullptr; Channel::Notifier* notifier = nullptr;
// Others. // Others.
Timer* timer = nullptr; Timer* timer = nullptr;
bool hasCapabilities = false; bool hasCapabilities = false;
RTC::RtpCapabilities capabilities; RTC::RtpCapabilities capabilities;
std::unordered_map<uint32_t, RTC::Transport*> transports; std::unordered_map<uint32_t, RTC::Transport*> transports;
...@@ -116,14 +122,12 @@ namespace RTC ...@@ -116,14 +122,12 @@ namespace RTC
/* Inline methods. */ /* Inline methods. */
inline inline bool Peer::HasCapabilities() const
bool Peer::HasCapabilities() const
{ {
return this->hasCapabilities; return this->hasCapabilities;
} }
inline inline std::vector<RTC::RtpReceiver*> Peer::GetRtpReceivers() const
std::vector<RTC::RtpReceiver*> Peer::GetRtpReceivers() const
{ {
std::vector<RTC::RtpReceiver*> rtpReceivers; std::vector<RTC::RtpReceiver*> rtpReceivers;
...@@ -135,8 +139,7 @@ namespace RTC ...@@ -135,8 +139,7 @@ namespace RTC
return rtpReceivers; return rtpReceivers;
} }
inline inline std::vector<RTC::RtpSender*> Peer::GetRtpSenders() const
std::vector<RTC::RtpSender*> Peer::GetRtpSenders() const
{ {
std::vector<RTC::RtpSender*> rtpSenders; std::vector<RTC::RtpSender*> rtpSenders;
...@@ -148,8 +151,7 @@ namespace RTC ...@@ -148,8 +151,7 @@ namespace RTC
return rtpSenders; return rtpSenders;
} }
inline inline const std::unordered_map<uint32_t, RTC::Transport*>& Peer::GetTransports() const
const std::unordered_map<uint32_t, RTC::Transport*>& Peer::GetTransports() const
{ {
return this->transports; return this->transports;
} }
......
...@@ -3,102 +3,97 @@ ...@@ -3,102 +3,97 @@
#include "common.hpp" #include "common.hpp"
#include "RTC/RTCP/Packet.hpp" #include "RTC/RTCP/Packet.hpp"
#include <vector>
#include <string> #include <string>
#include <vector>
namespace RTC { namespace RTCP namespace RTC
{ {
class ByePacket namespace RTCP
: public Packet
{
public:
typedef std::vector<uint32_t>::iterator Iterator;
public:
static ByePacket* Parse(const uint8_t* data, size_t len);
public:
ByePacket();
virtual ~ByePacket() {};
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:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetCount() const override;
virtual size_t GetSize() const override;
private:
std::vector<uint32_t> ssrcs;
std::string reason;
};
/* Inline instance methods. */
inline
ByePacket::ByePacket()
: Packet(Type::BYE)
{}
inline
size_t ByePacket::GetCount() const
{ {
return this->ssrcs.size(); class ByePacket : public Packet
} {
public:
inline typedef std::vector<uint32_t>::iterator Iterator;
size_t ByePacket::GetSize() const
{ public:
size_t size = sizeof(Packet::CommonHeader); static ByePacket* Parse(const uint8_t* data, size_t len);
size += ssrcs.size() * sizeof(uint32_t); public:
ByePacket();
virtual ~ByePacket(){};
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:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetCount() const override;
virtual size_t GetSize() const override;
private:
std::vector<uint32_t> ssrcs;
std::string reason;
};
/* Inline instance methods. */
inline ByePacket::ByePacket()
: Packet(Type::BYE)
{
}
if (!this->reason.empty()) inline size_t ByePacket::GetCount() const
{ {
size += sizeof(uint8_t); // Length field. return this->ssrcs.size();
size += this->reason.length();
} }
// http://stackoverflow.com/questions/11642210/computing-padding-required-for-n-byte-alignment inline size_t ByePacket::GetSize() const
// Consider pading to 32 bits (4 bytes) boundary. {
return (size + 3) & ~3; size_t size = sizeof(Packet::CommonHeader);
}
inline size += ssrcs.size() * sizeof(uint32_t);
void ByePacket::AddSsrc(uint32_t ssrc)
{
this->ssrcs.push_back(ssrc);
}
inline if (!this->reason.empty())
void ByePacket::SetReason(const std::string& reason) {
{ size += sizeof(uint8_t); // Length field.
this->reason = reason; size += this->reason.length();
} }
inline // http://stackoverflow.com/questions/11642210/computing-padding-required-for-n-byte-alignment
const std::string& ByePacket::GetReason() const // Consider pading to 32 bits (4 bytes) boundary.
{ return (size + 3) & ~3;
return this->reason; }
}
inline inline void ByePacket::AddSsrc(uint32_t ssrc)
ByePacket::Iterator ByePacket::Begin() {
{ this->ssrcs.push_back(ssrc);
return this->ssrcs.begin(); }
}
inline inline void ByePacket::SetReason(const std::string& reason)
ByePacket::Iterator ByePacket::End() {
{ this->reason = reason;
return this->ssrcs.end(); }
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();
}
} }
}} }
#endif #endif
...@@ -2,71 +2,68 @@ ...@@ -2,71 +2,68 @@
#define MS_RTC_RTCP_COMPOUND_PACKET_HPP #define MS_RTC_RTCP_COMPOUND_PACKET_HPP
#include "common.hpp" #include "common.hpp"
#include "RTC/RTCP/SenderReport.hpp"
#include "RTC/RTCP/ReceiverReport.hpp" #include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/Sdes.hpp" #include "RTC/RTCP/Sdes.hpp"
#include "RTC/RTCP/SenderReport.hpp"
#include <vector> #include <vector>
namespace RTC { namespace RTCP namespace RTC
{ {
class CompoundPacket namespace RTCP
{ {
public: class CompoundPacket
const uint8_t* GetData() const; {
size_t GetSize() const; public:
size_t GetSenderReportCount() const; const uint8_t* GetData() const;
size_t GetReceiverReportCount() const; size_t GetSize() const;
void Dump() const; size_t GetSenderReportCount() const;
void AddSenderReport(SenderReport* report); size_t GetReceiverReportCount() const;
void AddReceiverReport(ReceiverReport* report); void Dump() const;
void AddSdesChunk(SdesChunk* chunk); void AddSenderReport(SenderReport* report);
void Serialize(uint8_t* buffer); void AddReceiverReport(ReceiverReport* report);
void AddSdesChunk(SdesChunk* chunk);
void Serialize(uint8_t* buffer);
private: private:
uint8_t* header = nullptr; uint8_t* header = nullptr;
size_t size = 0; size_t size = 0;
SenderReportPacket senderReportPacket; SenderReportPacket senderReportPacket;
ReceiverReportPacket receiverReportPacket; ReceiverReportPacket receiverReportPacket;
SdesPacket sdesPacket; SdesPacket sdesPacket;
}; };
/* Inline methods. */ /* Inline methods. */
inline inline const uint8_t* CompoundPacket::GetData() const
const uint8_t* CompoundPacket::GetData() const {
{ return this->header;
return this->header; }
}
inline inline size_t CompoundPacket::GetSize() const
size_t CompoundPacket::GetSize() const {
{ return this->size;
return this->size; }
}
inline inline size_t CompoundPacket::GetSenderReportCount() const
size_t CompoundPacket::GetSenderReportCount() const {
{ return this->senderReportPacket.GetCount();
return this->senderReportPacket.GetCount(); }
}
inline inline size_t CompoundPacket::GetReceiverReportCount() const
size_t CompoundPacket::GetReceiverReportCount() const {
{ return this->receiverReportPacket.GetCount();
return this->receiverReportPacket.GetCount(); }
}
inline inline void CompoundPacket::AddReceiverReport(ReceiverReport* report)
void CompoundPacket::AddReceiverReport(ReceiverReport* report) {
{ this->receiverReportPacket.AddReport(report);
this->receiverReportPacket.AddReport(report); }
}
inline inline void CompoundPacket::AddSdesChunk(SdesChunk* chunk)
void CompoundPacket::AddSdesChunk(SdesChunk* chunk) {
{ this->sdesPacket.AddChunk(chunk);
this->sdesPacket.AddChunk(chunk); }
} }
}} }
#endif #endif
...@@ -2,137 +2,140 @@ ...@@ -2,137 +2,140 @@
#define MS_RTC_RTCP_FEEDBACK_HPP #define MS_RTC_RTCP_FEEDBACK_HPP
#include "common.hpp" #include "common.hpp"
#include "RTC/RTCP/Packet.hpp"
#include "RTC/RTCP/FeedbackItem.hpp" #include "RTC/RTCP/FeedbackItem.hpp"
#include "RTC/RTCP/Packet.hpp"
namespace RTC { namespace RTCP namespace RTC
{ {
template <typename T> class FeedbackPacket namespace RTCP
: public Packet
{ {
public: template<typename T>
/* Struct for RTP Feedback message. */ class FeedbackPacket : public Packet
struct Header
{ {
uint32_t s_ssrc; public:
uint32_t m_ssrc; /* Struct for RTP Feedback message. */
struct Header
{
uint32_t senderSsrc;
uint32_t mediaSsrc;
};
public:
static RTCP::Type RtcpType;
static FeedbackPacket<T>* Parse(const uint8_t* data, size_t len);
static const std::string& MessageType2String(typename T::MessageType type);
private:
static std::map<typename T::MessageType, std::string> type2String;
public:
typename T::MessageType GetMessageType() const;
uint32_t GetSenderSsrc() const;
void SetSenderSsrc(uint32_t ssrc);
uint32_t GetMediaSsrc() const;
void SetMediaSsrc(uint32_t ssrc);
/* Pure virtual methods inherited from Packet. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetCount() const override;
virtual size_t GetSize() const override;
protected:
explicit FeedbackPacket(CommonHeader* commonHeader);
FeedbackPacket(typename T::MessageType type, uint32_t senderSsrc, uint32_t mediaSsrc);
virtual ~FeedbackPacket();
private:
Header* header = nullptr;
uint8_t* raw = nullptr;
typename T::MessageType messageType;
}; };
public: class FeedbackPs
static RTCP::Type RtcpType;
static FeedbackPacket<T>* Parse(const uint8_t* data, size_t len);
static const std::string& MessageType2String(typename T::MessageType type);
private:
static std::map<typename T::MessageType, std::string> type2String;
public:
typename T::MessageType GetMessageType() const;
uint32_t GetSenderSsrc() const;
void SetSenderSsrc(uint32_t ssrc);
uint32_t GetMediaSsrc() const;
void SetMediaSsrc(uint32_t ssrc);
/* Pure virtual methods inherited from Packet. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetCount() const override;
virtual size_t GetSize() const override;
protected:
explicit FeedbackPacket(CommonHeader* commonHeader);
FeedbackPacket(typename T::MessageType type, uint32_t sender_ssrc, uint32_t media_ssrc);
virtual ~FeedbackPacket();
private:
Header* header = nullptr;
uint8_t* raw = nullptr;
typename T::MessageType messageType;
};
class FeedbackPs
{
public:
enum class MessageType : uint8_t
{ {
PLI = 1, public:
SLI = 2, enum class MessageType : uint8_t
RPSI = 3, {
FIR = 4, PLI = 1,
TSTR = 5, SLI = 2,
TSTN = 6, RPSI = 3,
VBCM = 7, FIR = 4,
PSLEI = 8, TSTR = 5,
ROI = 9, TSTN = 6,
AFB = 15, VBCM = 7,
EXT = 31 PSLEI = 8,
ROI = 9,
AFB = 15,
EXT = 31
};
}; };
};
class FeedbackRtp class FeedbackRtp
{
public:
enum class MessageType : uint8_t
{ {
NACK = 1, public:
TMMBR = 3, enum class MessageType : uint8_t
TMMBN = 4, {
SR_REQ = 5, NACK = 1,
RAMS = 6, TMMBR = 3,
TLLEI = 7, TMMBN = 4,
ECN = 8, SR_REQ = 5,
PS = 9, RAMS = 6,
EXT = 31 TLLEI = 7,
ECN = 8,
PS = 9,
EXT = 31
};
}; };
};
typedef FeedbackPacket<FeedbackPs> FeedbackPsPacket; typedef FeedbackPacket<FeedbackPs> FeedbackPsPacket;
typedef FeedbackPacket<FeedbackRtp> FeedbackRtpPacket; typedef FeedbackPacket<FeedbackRtp> FeedbackRtpPacket;
/* Inline instance methods. */ /* Inline instance methods. */
template <typename T> template<typename T>
typename T::MessageType FeedbackPacket<T>::GetMessageType() const typename T::MessageType FeedbackPacket<T>::GetMessageType() const
{ {
return this->messageType; return this->messageType;
} }
template <typename T> template<typename T>
size_t FeedbackPacket<T>::GetCount() const size_t FeedbackPacket<T>::GetCount() const
{ {
return (size_t)this->GetMessageType(); return (size_t)this->GetMessageType();
} }
template <typename T> template<typename T>
size_t FeedbackPacket<T>::GetSize() const size_t FeedbackPacket<T>::GetSize() const
{ {
return sizeof(CommonHeader) + sizeof(Header); return sizeof(CommonHeader) + sizeof(Header);
} }
template <typename T> template<typename T>
uint32_t FeedbackPacket<T>::GetSenderSsrc() const uint32_t FeedbackPacket<T>::GetSenderSsrc() const
{ {
return (uint32_t)ntohl(this->header->s_ssrc); return (uint32_t)ntohl(this->header->senderSsrc);
} }
template <typename T> template<typename T>
void FeedbackPacket<T>::SetSenderSsrc(uint32_t ssrc) void FeedbackPacket<T>::SetSenderSsrc(uint32_t ssrc)
{ {
this->header->s_ssrc = (uint32_t)htonl(ssrc); this->header->senderSsrc = (uint32_t)htonl(ssrc);
} }
template <typename T> template<typename T>
uint32_t FeedbackPacket<T>::GetMediaSsrc() const uint32_t FeedbackPacket<T>::GetMediaSsrc() const
{ {
return (uint32_t)ntohl(this->header->m_ssrc); return (uint32_t)ntohl(this->header->mediaSsrc);
} }
template <typename T> template<typename T>
void FeedbackPacket<T>::SetMediaSsrc(uint32_t ssrc) void FeedbackPacket<T>::SetMediaSsrc(uint32_t ssrc)
{ {
this->header->m_ssrc = (uint32_t)htonl(ssrc); this->header->mediaSsrc = (uint32_t)htonl(ssrc);
}
} }
}} }
#endif #endif
...@@ -3,51 +3,51 @@ ...@@ -3,51 +3,51 @@
#include "common.hpp" #include "common.hpp"
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackItem namespace RTCP
{ {
public: class FeedbackItem
bool IsCorrect() const; {
public:
protected: bool IsCorrect() const;
virtual ~FeedbackItem();
protected:
public: virtual ~FeedbackItem();
virtual void Dump() const = 0;
virtual void Serialize(); public:
virtual size_t Serialize(uint8_t* buffer) = 0; virtual void Dump() const = 0;
virtual size_t GetSize() const = 0; virtual void Serialize();
virtual size_t Serialize(uint8_t* buffer) = 0;
protected: virtual size_t GetSize() const = 0;
uint8_t* raw = nullptr;
bool isCorrect = true; protected:
}; uint8_t* raw = nullptr;
bool isCorrect = true;
/* Inline instance methods */ };
inline /* Inline instance methods */
FeedbackItem::~FeedbackItem()
{ inline FeedbackItem::~FeedbackItem()
if (this->raw) {
delete this->raw; if (this->raw)
} delete this->raw;
}
inline
void FeedbackItem::Serialize() inline void FeedbackItem::Serialize()
{ {
if (this->raw) if (this->raw)
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);
} }
inline inline bool FeedbackItem::IsCorrect() const
bool FeedbackItem::IsCorrect() const {
{ return this->isCorrect;
return this->isCorrect; }
} }
}} }
#endif #endif
...@@ -5,79 +5,84 @@ ...@@ -5,79 +5,84 @@
#include "RTC/RTCP/Feedback.hpp" #include "RTC/RTCP/Feedback.hpp"
#include <vector> #include <vector>
namespace RTC { namespace RTCP namespace RTC
{ {
template<typename Item> class FeedbackPsItemsPacket namespace RTCP
: public FeedbackPsPacket
{ {
public: template<typename Item>
typedef typename std::vector<Item*>::iterator Iterator; class FeedbackPsItemsPacket : public FeedbackPsPacket
{
public: public:
static FeedbackPsItemsPacket<Item>* Parse(const uint8_t* data, size_t len); typedef typename std::vector<Item*>::iterator Iterator;
public: public:
// Parsed Report. Points to an external data. static FeedbackPsItemsPacket<Item>* Parse(const uint8_t* data, size_t len);
explicit FeedbackPsItemsPacket(CommonHeader* commonHeader);
explicit FeedbackPsItemsPacket(uint32_t sender_ssrc, uint32_t media_ssrc = 0); public:
virtual ~FeedbackPsItemsPacket() {}; // Parsed Report. Points to an external data.
explicit FeedbackPsItemsPacket(CommonHeader* commonHeader);
void AddItem(Item* item); explicit FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0);
Iterator Begin(); virtual ~FeedbackPsItemsPacket(){};
Iterator End();
void AddItem(Item* item);
/* Pure virtual methods inherited from Packet. */ Iterator Begin();
public: Iterator End();
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override; /* Pure virtual methods inherited from Packet. */
virtual size_t GetSize() const override; public:
virtual void Dump() const override;
private: virtual size_t Serialize(uint8_t* buffer) override;
std::vector<Item*> items; virtual size_t GetSize() const override;
};
private:
/* Inline instance methods. */ std::vector<Item*> items;
};
template<typename Item>
FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(CommonHeader* commonHeader):
FeedbackPsPacket(commonHeader)
{}
template<typename Item>
FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(uint32_t sender_ssrc, uint32_t media_ssrc):
FeedbackPsPacket(Item::MessageType, sender_ssrc, media_ssrc)
{}
template<typename Item>
size_t FeedbackPsItemsPacket<Item>::GetSize() const
{
size_t size = FeedbackPsPacket::GetSize();
for (auto item : this->items) /* Inline instance methods. */
template<typename Item>
FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(CommonHeader* commonHeader)
: FeedbackPsPacket(commonHeader)
{ {
size += item->GetSize();
} }
return size; template<typename Item>
} FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackPsPacket(Item::MessageType, senderSsrc, mediaSsrc)
{
}
template<typename Item> template<typename Item>
void FeedbackPsItemsPacket<Item>::AddItem(Item* item) size_t FeedbackPsItemsPacket<Item>::GetSize() const
{ {
this->items.push_back(item); size_t size = FeedbackPsPacket::GetSize();
}
template<typename Item> for (auto item : this->items)
typename FeedbackPsItemsPacket<Item>::Iterator FeedbackPsItemsPacket<Item>::Begin() {
{ size += item->GetSize();
return this->items.begin(); }
}
template<typename Item> return size;
typename FeedbackPsItemsPacket<Item>::Iterator FeedbackPsItemsPacket<Item>::End() }
{
return this->items.end(); template<typename Item>
void FeedbackPsItemsPacket<Item>::AddItem(Item* item)
{
this->items.push_back(item);
}
template<typename Item>
typename FeedbackPsItemsPacket<Item>::Iterator FeedbackPsItemsPacket<Item>::Begin()
{
return this->items.begin();
}
template<typename Item>
typename FeedbackPsItemsPacket<Item>::Iterator FeedbackPsItemsPacket<Item>::End()
{
return this->items.end();
}
} }
}} }
#endif #endif
...@@ -4,70 +4,68 @@ ...@@ -4,70 +4,68 @@
#include "common.hpp" #include "common.hpp"
#include "RTC/RTCP/Feedback.hpp" #include "RTC/RTCP/Feedback.hpp"
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackPsAfbPacket namespace RTCP
: public FeedbackPsPacket
{ {
public: class FeedbackPsAfbPacket : public FeedbackPsPacket
typedef enum Application : uint8_t
{ {
UNKNOWN = 0, public:
REMB = 1 typedef enum Application : uint8_t { UNKNOWN = 0, REMB = 1 } Application;
} Application;
public: public:
static FeedbackPsAfbPacket* Parse(const uint8_t* data, size_t len); static FeedbackPsAfbPacket* Parse(const uint8_t* data, size_t len);
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackPsAfbPacket(CommonHeader* commonHeader, Application application = UNKNOWN); explicit FeedbackPsAfbPacket(CommonHeader* commonHeader, Application application = UNKNOWN);
FeedbackPsAfbPacket(uint32_t sender_ssrc, uint32_t media_ssrc, Application application = UNKNOWN); FeedbackPsAfbPacket(uint32_t senderSsrc, uint32_t mediaSsrc, Application application = UNKNOWN);
virtual ~FeedbackPsAfbPacket() {}; virtual ~FeedbackPsAfbPacket(){};
Application GetApplication() const; Application GetApplication() const;
/* Pure virtual methods inherited from Packet. */ /* Pure virtual methods inherited from Packet. */
public: public:
virtual void Dump() const override; virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override; virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override; virtual size_t GetSize() const override;
private: private:
Application application = UNKNOWN; Application application = UNKNOWN;
uint8_t* data = nullptr; uint8_t* data = nullptr;
size_t size = 0; size_t size = 0;
}; };
/* Inline instance methods. */ /* Inline instance methods. */
inline inline FeedbackPsAfbPacket::FeedbackPsAfbPacket(CommonHeader* commonHeader, Application application)
FeedbackPsAfbPacket::FeedbackPsAfbPacket(CommonHeader* commonHeader, Application application): : FeedbackPsPacket(commonHeader)
FeedbackPsPacket(commonHeader) {
{ this->size = ((ntohs(commonHeader->length) + 1) * 4) -
this->size = ((ntohs(commonHeader->length) + 1) * 4) - (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header)); (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header));
this->data = (uint8_t*)commonHeader + sizeof(CommonHeader) + sizeof(FeedbackPacket::Header);
this->application = application;
}
inline this->data = (uint8_t*)commonHeader + sizeof(CommonHeader) + sizeof(FeedbackPacket::Header);
FeedbackPsAfbPacket::FeedbackPsAfbPacket(uint32_t sender_ssrc, uint32_t media_ssrc, Application application):
FeedbackPsPacket(FeedbackPs::MessageType::AFB, sender_ssrc, media_ssrc)
{
this->application = application;
}
inline this->application = application;
FeedbackPsAfbPacket::Application FeedbackPsAfbPacket::GetApplication() const }
{
return this->application;
}
inline inline FeedbackPsAfbPacket::FeedbackPsAfbPacket(
size_t FeedbackPsAfbPacket::GetSize() const uint32_t senderSsrc, uint32_t mediaSsrc, Application application)
{ : FeedbackPsPacket(FeedbackPs::MessageType::AFB, senderSsrc, mediaSsrc)
return FeedbackPsPacket::GetSize() + this->size; {
this->application = application;
}
inline FeedbackPsAfbPacket::Application FeedbackPsAfbPacket::GetApplication() const
{
return this->application;
}
inline size_t FeedbackPsAfbPacket::GetSize() const
{
return FeedbackPsPacket::GetSize() + this->size;
}
} }
}} }
#endif #endif
...@@ -16,76 +16,75 @@ ...@@ -16,76 +16,75 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackPsFirItem namespace RTCP
: public FeedbackItem
{ {
private: class FeedbackPsFirItem : public FeedbackItem
struct Header
{ {
uint32_t ssrc; private:
uint8_t sequence_number; struct Header
uint32_t reserved:24; {
uint32_t ssrc;
uint8_t sequenceNumber;
uint32_t reserved : 24;
};
public:
static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::FIR;
public:
static FeedbackPsFirItem* Parse(const uint8_t* data, size_t len);
public:
explicit FeedbackPsFirItem(Header* header);
explicit FeedbackPsFirItem(FeedbackPsFirItem* item);
FeedbackPsFirItem(uint32_t ssrc, uint8_t sequenceNumber);
virtual ~FeedbackPsFirItem(){};
uint32_t GetSsrc() const;
uint8_t GetSequenceNumber() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
}; };
public: // Fir packet declaration.
static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::FIR; typedef FeedbackPsItemsPacket<FeedbackPsFirItem> FeedbackPsFirPacket;
public: /* Inline instance methods. */
static FeedbackPsFirItem* Parse(const uint8_t* data, size_t len);
public: inline FeedbackPsFirItem::FeedbackPsFirItem(Header* header)
explicit FeedbackPsFirItem(Header* header); : header(header)
explicit FeedbackPsFirItem(FeedbackPsFirItem* item); {
FeedbackPsFirItem(uint32_t ssrc, uint8_t sequence_number); }
virtual ~FeedbackPsFirItem() {};
uint32_t GetSsrc() const;
uint8_t GetSequenceNumber() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
};
// Fir packet declaration.
typedef FeedbackPsItemsPacket<FeedbackPsFirItem> FeedbackPsFirPacket;
/* Inline instance methods. */
inline
FeedbackPsFirItem::FeedbackPsFirItem(Header* header):
header(header)
{}
inline inline FeedbackPsFirItem::FeedbackPsFirItem(FeedbackPsFirItem* item)
FeedbackPsFirItem::FeedbackPsFirItem(FeedbackPsFirItem* item) : : header(item->header)
header(item->header) {
{} }
inline inline size_t FeedbackPsFirItem::GetSize() const
size_t FeedbackPsFirItem::GetSize() const {
{ return sizeof(Header);
return sizeof(Header); }
}
inline inline uint32_t FeedbackPsFirItem::GetSsrc() const
uint32_t FeedbackPsFirItem::GetSsrc() const {
{ return (uint32_t)ntohl(this->header->ssrc);
return (uint32_t)ntohl(this->header->ssrc); }
}
inline inline uint8_t FeedbackPsFirItem::GetSequenceNumber() const
uint8_t FeedbackPsFirItem::GetSequenceNumber() const {
{ return (uint8_t)this->header->sequenceNumber;
return (uint8_t)this->header->sequence_number; }
} }
}} }
#endif #endif
...@@ -13,67 +13,67 @@ ...@@ -13,67 +13,67 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackPsLeiItem namespace RTCP
: public FeedbackItem
{ {
private: class FeedbackPsLeiItem : public FeedbackItem
struct Header
{ {
uint32_t ssrc; private:
struct Header
{
uint32_t ssrc;
};
public:
static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::PSLEI;
public:
static FeedbackPsLeiItem* Parse(const uint8_t* data, size_t len);
public:
explicit FeedbackPsLeiItem(Header* header);
explicit FeedbackPsLeiItem(FeedbackPsLeiItem* item);
explicit FeedbackPsLeiItem(uint32_t ssrc);
virtual ~FeedbackPsLeiItem(){};
uint32_t GetSsrc() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
}; };
public: // Lei packet declaration.
static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::PSLEI; typedef FeedbackPsItemsPacket<FeedbackPsLeiItem> FeedbackPsLeiPacket;
public: /* Inline instance methods. */
static FeedbackPsLeiItem* Parse(const uint8_t* data, size_t len);
public: inline FeedbackPsLeiItem::FeedbackPsLeiItem(Header* header)
explicit FeedbackPsLeiItem(Header* header); : header(header)
explicit FeedbackPsLeiItem(FeedbackPsLeiItem* item); {
explicit FeedbackPsLeiItem(uint32_t ssrc); }
virtual ~FeedbackPsLeiItem() {};
uint32_t GetSsrc() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
};
// Lei packet declaration.
typedef FeedbackPsItemsPacket<FeedbackPsLeiItem> FeedbackPsLeiPacket;
/* Inline instance methods. */
inline
FeedbackPsLeiItem::FeedbackPsLeiItem(Header* header):
header(header)
{}
inline inline FeedbackPsLeiItem::FeedbackPsLeiItem(FeedbackPsLeiItem* item)
FeedbackPsLeiItem::FeedbackPsLeiItem(FeedbackPsLeiItem* item): : header(item->header)
header(item->header) {
{} }
inline inline size_t FeedbackPsLeiItem::GetSize() const
size_t FeedbackPsLeiItem::GetSize() const {
{ return sizeof(Header);
return sizeof(Header); }
}
inline inline uint32_t FeedbackPsLeiItem::GetSsrc() const
uint32_t FeedbackPsLeiItem::GetSsrc() const {
{ return (uint32_t)ntohl(this->header->ssrc);
return (uint32_t)ntohl(this->header->ssrc); }
} }
}} }
#endif #endif
...@@ -4,35 +4,37 @@ ...@@ -4,35 +4,37 @@
#include "common.hpp" #include "common.hpp"
#include "RTC/RTCP/Feedback.hpp" #include "RTC/RTCP/Feedback.hpp"
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackPsPliPacket namespace RTCP
: public FeedbackPsPacket
{ {
public: class FeedbackPsPliPacket : public FeedbackPsPacket
static FeedbackPsPliPacket* Parse(const uint8_t* data, size_t len); {
public:
public: static FeedbackPsPliPacket* Parse(const uint8_t* data, size_t len);
// Parsed Report. Points to an external data.
explicit FeedbackPsPliPacket(CommonHeader* commonHeader); public:
FeedbackPsPliPacket(uint32_t sender_ssrc, uint32_t media_ssrc); // Parsed Report. Points to an external data.
virtual ~FeedbackPsPliPacket() {}; explicit FeedbackPsPliPacket(CommonHeader* commonHeader);
FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc);
public: virtual ~FeedbackPsPliPacket(){};
virtual void Dump() const override;
}; public:
virtual void Dump() const override;
/* Inline instance methods. */ };
inline /* Inline instance methods. */
FeedbackPsPliPacket::FeedbackPsPliPacket(CommonHeader* commonHeader):
FeedbackPsPacket(commonHeader) inline FeedbackPsPliPacket::FeedbackPsPliPacket(CommonHeader* commonHeader)
{} : FeedbackPsPacket(commonHeader)
{
inline }
FeedbackPsPliPacket::FeedbackPsPliPacket(uint32_t sender_ssrc, uint32_t media_ssrc):
FeedbackPsPacket(FeedbackPs::MessageType::PLI, sender_ssrc, media_ssrc) inline FeedbackPsPliPacket::FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
{} : FeedbackPsPacket(FeedbackPs::MessageType::PLI, senderSsrc, mediaSsrc)
}} {
}
}
}
#endif #endif
...@@ -25,85 +25,81 @@ ...@@ -25,85 +25,81 @@
| ... | | ... |
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackPsRembPacket namespace RTCP
: public FeedbackPsAfbPacket
{ {
public: class FeedbackPsRembPacket : public FeedbackPsAfbPacket
// 'R' 'E' 'M' 'B'. {
static uint32_t UniqueIdentifier; public:
// 'R' 'E' 'M' 'B'.
public: static uint32_t UniqueIdentifier;
static FeedbackPsRembPacket* Parse(const uint8_t* data, size_t len);
public:
public: static FeedbackPsRembPacket* Parse(const uint8_t* data, size_t len);
// Parsed Report. Points to an external data.
explicit FeedbackPsRembPacket(CommonHeader* commonHeader); public:
FeedbackPsRembPacket(uint32_t sender_ssrc, uint32_t media_ssrc); // Parsed Report. Points to an external data.
virtual ~FeedbackPsRembPacket() {}; explicit FeedbackPsRembPacket(CommonHeader* commonHeader);
FeedbackPsRembPacket(uint32_t senderSsrc, uint32_t mediaSsrc);
bool IsCorrect(); virtual ~FeedbackPsRembPacket(){};
void SetBitrate(uint64_t bitrate);
void SetSsrcs(const std::vector<uint32_t>& ssrcs); bool IsCorrect();
uint64_t GetBitrate(); void SetBitrate(uint64_t bitrate);
const std::vector<uint32_t>& GetSsrcs(); void SetSsrcs(const std::vector<uint32_t>& ssrcs);
uint64_t GetBitrate();
/* Pure virtual methods inherited from Packet. */ const std::vector<uint32_t>& GetSsrcs();
public:
virtual void Dump() const override; /* Pure virtual methods inherited from Packet. */
virtual size_t Serialize(uint8_t* buffer) override; public:
virtual size_t GetSize() const override; virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
private: virtual size_t GetSize() const override;
std::vector<uint32_t> ssrcs;
// Bitrate represented in bps. private:
uint64_t bitrate = 0; std::vector<uint32_t> ssrcs;
bool isCorrect = true; // Bitrate represented in bps.
}; uint64_t bitrate = 0;
bool isCorrect = true;
/* Inline instance methods. */ };
inline /* Inline instance methods. */
FeedbackPsRembPacket::FeedbackPsRembPacket(uint32_t sender_ssrc, uint32_t media_ssrc):
FeedbackPsAfbPacket(sender_ssrc, media_ssrc, FeedbackPsAfbPacket::Application::REMB) inline FeedbackPsRembPacket::FeedbackPsRembPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
{} : FeedbackPsAfbPacket(senderSsrc, mediaSsrc, FeedbackPsAfbPacket::Application::REMB)
{
inline }
bool FeedbackPsRembPacket::IsCorrect()
{ inline bool FeedbackPsRembPacket::IsCorrect()
return this->isCorrect; {
} return this->isCorrect;
}
inline
void FeedbackPsRembPacket::SetBitrate(uint64_t bitrate) inline void FeedbackPsRembPacket::SetBitrate(uint64_t bitrate)
{ {
this->bitrate = bitrate; this->bitrate = bitrate;
} }
inline inline void FeedbackPsRembPacket::SetSsrcs(const std::vector<uint32_t>& ssrcs)
void FeedbackPsRembPacket::SetSsrcs(const std::vector<uint32_t>& ssrcs) {
{ this->ssrcs = ssrcs;
this->ssrcs = ssrcs; }
}
inline uint64_t FeedbackPsRembPacket::GetBitrate()
inline {
uint64_t FeedbackPsRembPacket::GetBitrate() return this->bitrate;
{ }
return this->bitrate;
} inline const std::vector<uint32_t>& FeedbackPsRembPacket::GetSsrcs()
{
inline return this->ssrcs;
const std::vector<uint32_t>& FeedbackPsRembPacket::GetSsrcs() }
{
return this->ssrcs; inline size_t FeedbackPsRembPacket::GetSize() const
} {
return FeedbackPsPacket::GetSize() + 8 + (sizeof(uint32_t) * this->ssrcs.size());
inline }
size_t FeedbackPsRembPacket::GetSize() const
{
return FeedbackPsPacket::GetSize() + 8 + (sizeof(uint32_t) * this->ssrcs.size());
} }
}} }
#endif #endif
...@@ -17,90 +17,87 @@ ...@@ -17,90 +17,87 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackPsRpsiItem namespace RTCP
: public FeedbackItem
{ {
const static size_t MaxBitStringSize = 6; class FeedbackPsRpsiItem : public FeedbackItem
const static size_t BitStringOffset = 2;
private:
struct Header
{ {
uint8_t padding_bits; const static size_t MaxBitStringSize = 6;
uint8_t zero:1; const static size_t BitStringOffset = 2;
uint8_t payload_type:7;
uint8_t bit_string[MaxBitStringSize]; private:
struct Header
{
uint8_t paddingBits;
uint8_t zero : 1;
uint8_t payloadType : 7;
uint8_t bitString[MaxBitStringSize];
};
public:
static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::RPSI;
public:
static FeedbackPsRpsiItem* Parse(const uint8_t* data, size_t len);
public:
explicit FeedbackPsRpsiItem(Header* header);
explicit FeedbackPsRpsiItem(FeedbackPsRpsiItem* item);
FeedbackPsRpsiItem(uint8_t payloadType, uint8_t* bitString, size_t length);
virtual ~FeedbackPsRpsiItem(){};
bool IsCorrect() const;
uint8_t GetPayloadType() const;
uint8_t* GetBitString() const;
size_t GetLength() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
size_t length = 0;
}; };
public: // Rpsi packet declaration.
static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::RPSI; typedef FeedbackPsItemsPacket<FeedbackPsRpsiItem> FeedbackPsRpsiPacket;
public:
static FeedbackPsRpsiItem* Parse(const uint8_t* data, size_t len);
public:
explicit FeedbackPsRpsiItem(Header* header);
explicit FeedbackPsRpsiItem(FeedbackPsRpsiItem* item);
FeedbackPsRpsiItem(uint8_t payload_type, uint8_t* bit_string, size_t length);
virtual ~FeedbackPsRpsiItem() {};
bool IsCorrect() const;
uint8_t GetPayloadType() const;
uint8_t* GetBitString() const;
size_t GetLength() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
size_t length = 0;
};
// Rpsi packet declaration. /* Inline instance methods. */
typedef FeedbackPsItemsPacket<FeedbackPsRpsiItem> FeedbackPsRpsiPacket;
/* Inline instance methods. */ inline FeedbackPsRpsiItem::FeedbackPsRpsiItem(FeedbackPsRpsiItem* item)
: header(item->header)
inline {
FeedbackPsRpsiItem::FeedbackPsRpsiItem(FeedbackPsRpsiItem* item) : }
header(item->header)
{}
inline inline size_t FeedbackPsRpsiItem::GetSize() const
size_t FeedbackPsRpsiItem::GetSize() const {
{ return sizeof(Header);
return sizeof(Header); }
}
inline inline uint8_t FeedbackPsRpsiItem::GetPayloadType() const
uint8_t FeedbackPsRpsiItem::GetPayloadType() const {
{ return this->header->payloadType;
return this->header->payload_type; }
}
inline inline uint8_t* FeedbackPsRpsiItem::GetBitString() const
uint8_t* FeedbackPsRpsiItem::GetBitString() const {
{ return this->header->bitString;
return this->header->bit_string; }
}
inline inline size_t FeedbackPsRpsiItem::GetLength() const
size_t FeedbackPsRpsiItem::GetLength() const {
{ return this->length;
return this->length; }
}
inline inline bool FeedbackPsRpsiItem::IsCorrect() const
bool FeedbackPsRpsiItem::IsCorrect() const {
{ return this->isCorrect;
return this->isCorrect; }
} }
}} }
#endif #endif
...@@ -13,95 +13,90 @@ ...@@ -13,95 +13,90 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackPsSliItem namespace RTCP
: public FeedbackItem
{ {
private: class FeedbackPsSliItem : public FeedbackItem
struct Header
{ {
uint32_t compact; private:
struct Header
{
uint32_t compact;
};
public:
static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::SLI;
public:
static FeedbackPsSliItem* Parse(const uint8_t* data, size_t len);
public:
explicit FeedbackPsSliItem(Header* header);
explicit FeedbackPsSliItem(FeedbackPsSliItem* item);
FeedbackPsSliItem(uint16_t first, uint16_t number, uint8_t pictureId);
virtual ~FeedbackPsSliItem(){};
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:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
uint16_t first;
uint16_t number;
uint8_t pictureId;
}; };
public: // Sli packet declaration.
static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::SLI; typedef FeedbackPsItemsPacket<FeedbackPsSliItem> FeedbackPsSliPacket;
public:
static FeedbackPsSliItem* Parse(const uint8_t* data, size_t len);
public:
explicit FeedbackPsSliItem(Header* header);
explicit FeedbackPsSliItem(FeedbackPsSliItem* item);
FeedbackPsSliItem(uint16_t first, uint16_t number, uint8_t pictureId);
virtual ~FeedbackPsSliItem() {};
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:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
uint16_t first;
uint16_t number;
uint8_t pictureId;
};
// Sli packet declaration.
typedef FeedbackPsItemsPacket<FeedbackPsSliItem> FeedbackPsSliPacket;
/* Inline instance methods. */
inline
size_t FeedbackPsSliItem::GetSize() const
{
return sizeof(Header);
}
inline /* Inline instance methods. */
uint16_t FeedbackPsSliItem::GetFirst() const
{
return this->first;
}
inline inline size_t FeedbackPsSliItem::GetSize() const
void FeedbackPsSliItem::SetFirst(uint16_t first) {
{ return sizeof(Header);
this->first = first; }
}
inline inline uint16_t FeedbackPsSliItem::GetFirst() const
uint16_t FeedbackPsSliItem::GetNumber() const {
{ return this->first;
return this->number; }
}
inline inline void FeedbackPsSliItem::SetFirst(uint16_t first)
void FeedbackPsSliItem::SetNumber(uint16_t number) {
{ this->first = first;
this->number = number; }
}
inline inline uint16_t FeedbackPsSliItem::GetNumber() const
uint8_t FeedbackPsSliItem::GetPictureId() const {
{ return this->number;
return this->pictureId; }
}
inline inline void FeedbackPsSliItem::SetNumber(uint16_t number)
void FeedbackPsSliItem::SetPictureId(uint8_t pictureId) {
{ this->number = number;
this->pictureId = pictureId; }
inline uint8_t FeedbackPsSliItem::GetPictureId() const
{
return this->pictureId;
}
inline void FeedbackPsSliItem::SetPictureId(uint8_t pictureId)
{
this->pictureId = pictureId;
}
} }
}} }
#endif #endif
...@@ -17,92 +17,101 @@ ...@@ -17,92 +17,101 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
template<typename T> class FeedbackPsTstItem namespace RTCP
: public FeedbackItem
{ {
private: template<typename T>
struct Header class FeedbackPsTstItem : public FeedbackItem
{ {
uint32_t ssrc; private:
uint32_t sequence_number:8; struct Header
uint32_t reserved:19; {
uint32_t index:5; uint32_t ssrc;
uint32_t sequenceNumber : 8;
uint32_t reserved : 19;
uint32_t index : 5;
};
public:
static const FeedbackPs::MessageType MessageType;
public:
static FeedbackPsTstItem* Parse(const uint8_t* data, size_t len);
public:
explicit FeedbackPsTstItem(Header* header);
explicit FeedbackPsTstItem(FeedbackPsTstItem* item);
FeedbackPsTstItem(uint32_t ssrc, uint8_t sequenceNumber, uint8_t index);
virtual ~FeedbackPsTstItem(){};
uint32_t GetSsrc() const;
uint8_t GetSequenceNumber() const;
uint8_t GetIndex() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
}; };
public: class Tstr
static const FeedbackPs::MessageType MessageType; {
};
public: class Tstn
static FeedbackPsTstItem* Parse(const uint8_t* data, size_t len); {
};
public:
explicit FeedbackPsTstItem(Header* header);
explicit FeedbackPsTstItem(FeedbackPsTstItem* item);
FeedbackPsTstItem(uint32_t ssrc, uint8_t sequenceNumber, uint8_t index);
virtual ~FeedbackPsTstItem() {};
uint32_t GetSsrc() const;
uint8_t GetSequenceNumber() const;
uint8_t GetIndex() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
};
class Tstr {};
class Tstn {};
// Tst classes declaration. // Tst classes declaration.
typedef FeedbackPsTstItem<Tstr> FeedbackPsTstrItem; typedef FeedbackPsTstItem<Tstr> FeedbackPsTstrItem;
typedef FeedbackPsTstItem<Tstn> FeedbackPsTstnItem; typedef FeedbackPsTstItem<Tstn> FeedbackPsTstnItem;
// Tst packets declaration. // Tst packets declaration.
typedef FeedbackPsItemsPacket<FeedbackPsTstrItem> FeedbackPsTstrPacket; typedef FeedbackPsItemsPacket<FeedbackPsTstrItem> FeedbackPsTstrPacket;
typedef FeedbackPsItemsPacket<FeedbackPsTstnItem> FeedbackPsTstnPacket; typedef FeedbackPsItemsPacket<FeedbackPsTstnItem> FeedbackPsTstnPacket;
/* Inline instance methods. */ /* Inline instance methods. */
template <typename T> template<typename T>
FeedbackPsTstItem<T>::FeedbackPsTstItem(Header* header): FeedbackPsTstItem<T>::FeedbackPsTstItem(Header* header)
header(header) : header(header)
{} {
}
template <typename T> template<typename T>
FeedbackPsTstItem<T>::FeedbackPsTstItem(FeedbackPsTstItem* item) : FeedbackPsTstItem<T>::FeedbackPsTstItem(FeedbackPsTstItem* item)
header(item->header) : header(item->header)
{} {
}
template <typename T> template<typename T>
size_t FeedbackPsTstItem<T>::GetSize() const size_t FeedbackPsTstItem<T>::GetSize() const
{ {
return sizeof(Header); return sizeof(Header);
} }
template <typename T> template<typename T>
uint32_t FeedbackPsTstItem<T>::GetSsrc() const uint32_t FeedbackPsTstItem<T>::GetSsrc() const
{ {
return (uint32_t)ntohl(this->header->ssrc); return (uint32_t)ntohl(this->header->ssrc);
} }
template <typename T> template<typename T>
uint8_t FeedbackPsTstItem<T>::GetSequenceNumber() const uint8_t FeedbackPsTstItem<T>::GetSequenceNumber() const
{ {
return (uint8_t)this->header->sequence_number; return (uint8_t)this->header->sequenceNumber;
} }
template <typename T> template<typename T>
uint8_t FeedbackPsTstItem<T>::GetIndex() const uint8_t FeedbackPsTstItem<T>::GetIndex() const
{ {
return (uint8_t)this->header->index; return (uint8_t)this->header->index;
}
} }
}} }
#endif #endif
...@@ -19,103 +19,100 @@ ...@@ -19,103 +19,100 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackPsVbcmItem namespace RTCP
: public FeedbackItem
{ {
private: class FeedbackPsVbcmItem : public FeedbackItem
struct Header
{ {
uint32_t ssrc; private:
uint8_t sequence_number; struct Header
uint8_t zero:1; {
uint8_t payload_type:7; uint32_t ssrc;
uint16_t length; uint8_t sequenceNumber;
uint8_t value[]; uint8_t zero : 1;
uint8_t payloadType : 7;
uint16_t length;
uint8_t value[];
};
public:
static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::FIR;
public:
static FeedbackPsVbcmItem* Parse(const uint8_t* data, size_t len);
public:
explicit FeedbackPsVbcmItem(Header* header);
explicit FeedbackPsVbcmItem(FeedbackPsVbcmItem* item);
FeedbackPsVbcmItem(
uint32_t ssrc, uint8_t sequenceNumber, uint8_t payloadType, uint16_t length, uint8_t* value);
virtual ~FeedbackPsVbcmItem(){};
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:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
}; };
public: // Vbcm packet declaration
static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::FIR; typedef FeedbackPsItemsPacket<FeedbackPsVbcmItem> FeedbackPsVbcmPacket;
public: /* Inline instance methods. */
static FeedbackPsVbcmItem* Parse(const uint8_t* data, size_t len);
public: inline FeedbackPsVbcmItem::FeedbackPsVbcmItem(Header* header)
explicit FeedbackPsVbcmItem(Header* header); : header(header)
explicit FeedbackPsVbcmItem(FeedbackPsVbcmItem* item); {
FeedbackPsVbcmItem(uint32_t ssrc, uint8_t sequence_number, uint8_t payload_type, uint16_t length, uint8_t* value); }
virtual ~FeedbackPsVbcmItem() {};
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:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
};
// Vbcm packet declaration
typedef FeedbackPsItemsPacket<FeedbackPsVbcmItem> FeedbackPsVbcmPacket;
/* Inline instance methods. */
inline
FeedbackPsVbcmItem::FeedbackPsVbcmItem(Header* header):
header(header)
{}
inline inline FeedbackPsVbcmItem::FeedbackPsVbcmItem(FeedbackPsVbcmItem* item)
FeedbackPsVbcmItem::FeedbackPsVbcmItem(FeedbackPsVbcmItem* item): : header(item->header)
header(item->header) {
{} }
inline inline size_t FeedbackPsVbcmItem::GetSize() const
size_t FeedbackPsVbcmItem::GetSize() const {
{ size_t size = 8 + size_t(this->header->length);
size_t size = 8 + size_t(this->header->length);
// Consider pading to 32 bits (4 bytes) boundary. // Consider pading to 32 bits (4 bytes) boundary.
return (size + 3) & ~3; return (size + 3) & ~3;
} }
inline inline uint32_t FeedbackPsVbcmItem::GetSsrc() const
uint32_t FeedbackPsVbcmItem::GetSsrc() const {
{ return (uint32_t)ntohl(this->header->ssrc);
return (uint32_t)ntohl(this->header->ssrc); }
}
inline inline uint8_t FeedbackPsVbcmItem::GetSequenceNumber() const
uint8_t FeedbackPsVbcmItem::GetSequenceNumber() const {
{ return (uint8_t)this->header->sequenceNumber;
return (uint8_t)this->header->sequence_number; }
}
inline inline uint8_t FeedbackPsVbcmItem::GetPayloadType() const
uint8_t FeedbackPsVbcmItem::GetPayloadType() const {
{ return (uint8_t)this->header->payloadType;
return (uint8_t)this->header->payload_type; }
}
inline inline uint16_t FeedbackPsVbcmItem::GetLength() const
uint16_t FeedbackPsVbcmItem::GetLength() const {
{ return (uint16_t)ntohs(this->header->length);
return (uint16_t)ntohs(this->header->length); }
}
inline inline uint8_t* FeedbackPsVbcmItem::GetValue() const
uint8_t* FeedbackPsVbcmItem::GetValue() const {
{ return this->header->value;
return this->header->value; }
} }
}} }
#endif #endif
...@@ -5,79 +5,84 @@ ...@@ -5,79 +5,84 @@
#include "RTC/RTCP/Feedback.hpp" #include "RTC/RTCP/Feedback.hpp"
#include <vector> #include <vector>
namespace RTC { namespace RTCP namespace RTC
{ {
template<typename Item> class FeedbackRtpItemsPacket namespace RTCP
: public FeedbackRtpPacket
{ {
public: template<typename Item>
typedef typename std::vector<Item*>::iterator Iterator; class FeedbackRtpItemsPacket : public FeedbackRtpPacket
{
public: public:
static FeedbackRtpItemsPacket<Item>* Parse(const uint8_t* data, size_t len); typedef typename std::vector<Item*>::iterator Iterator;
public: public:
// Parsed Report. Points to an external data. static FeedbackRtpItemsPacket<Item>* Parse(const uint8_t* data, size_t len);
explicit FeedbackRtpItemsPacket(CommonHeader* commonHeader);
explicit FeedbackRtpItemsPacket(uint32_t sender_ssrc, uint32_t media_ssrc = 0); public:
virtual ~FeedbackRtpItemsPacket() {}; // Parsed Report. Points to an external data.
explicit FeedbackRtpItemsPacket(CommonHeader* commonHeader);
void AddItem(Item* item); explicit FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0);
Iterator Begin(); virtual ~FeedbackRtpItemsPacket(){};
Iterator End();
void AddItem(Item* item);
/* Virtual methods inherited from FeedbackItem. */ Iterator Begin();
public: Iterator End();
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override; /* Virtual methods inherited from FeedbackItem. */
virtual size_t GetSize() const override; public:
virtual void Dump() const override;
private: virtual size_t Serialize(uint8_t* buffer) override;
std::vector<Item*> items; virtual size_t GetSize() const override;
};
private:
/* Inline instance methods. */ std::vector<Item*> items;
};
template<typename Item>
FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(CommonHeader* commonHeader):
FeedbackRtpPacket(commonHeader)
{}
template<typename Item>
FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(uint32_t sender_ssrc, uint32_t media_ssrc):
FeedbackRtpPacket(Item::MessageType, sender_ssrc, media_ssrc)
{}
template<typename Item>
size_t FeedbackRtpItemsPacket<Item>::GetSize() const
{
size_t size = FeedbackRtpPacket::GetSize();
for (auto item : this->items) /* Inline instance methods. */
template<typename Item>
FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(CommonHeader* commonHeader)
: FeedbackRtpPacket(commonHeader)
{ {
size += item->GetSize();
} }
return size; template<typename Item>
} FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackRtpPacket(Item::MessageType, senderSsrc, mediaSsrc)
{
}
template<typename Item> template<typename Item>
void FeedbackRtpItemsPacket<Item>::AddItem(Item* item) size_t FeedbackRtpItemsPacket<Item>::GetSize() const
{ {
this->items.push_back(item); size_t size = FeedbackRtpPacket::GetSize();
}
template<typename Item> for (auto item : this->items)
typename FeedbackRtpItemsPacket<Item>::Iterator FeedbackRtpItemsPacket<Item>::Begin() {
{ size += item->GetSize();
return this->items.begin(); }
}
template<typename Item> return size;
typename FeedbackRtpItemsPacket<Item>::Iterator FeedbackRtpItemsPacket<Item>::End() }
{
return this->items.end(); template<typename Item>
void FeedbackRtpItemsPacket<Item>::AddItem(Item* item)
{
this->items.push_back(item);
}
template<typename Item>
typename FeedbackRtpItemsPacket<Item>::Iterator FeedbackRtpItemsPacket<Item>::Begin()
{
return this->items.begin();
}
template<typename Item>
typename FeedbackRtpItemsPacket<Item>::Iterator FeedbackRtpItemsPacket<Item>::End()
{
return this->items.end();
}
} }
}} }
#endif #endif
...@@ -24,114 +24,108 @@ ...@@ -24,114 +24,108 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackRtpEcnItem namespace RTCP
: public FeedbackItem
{ {
private: class FeedbackRtpEcnItem : public FeedbackItem
struct Header
{ {
uint32_t sequence_number; private:
uint32_t ect0_counter; struct Header
uint32_t ect1_counter; {
uint16_t ecn_ce_counter; uint32_t sequenceNumber;
uint16_t not_ect_counter; uint32_t ect0Counter;
uint16_t lost_packets; uint32_t ect1Counter;
uint16_t duplicated_packets; uint16_t ecnCeCounter;
uint16_t notEctCounter;
uint16_t lostPackets;
uint16_t duplicatedPackets;
};
public:
static const FeedbackRtp::MessageType MessageType = FeedbackRtp::MessageType::ECN;
public:
static FeedbackRtpEcnItem* Parse(const uint8_t* data, size_t len);
public:
explicit FeedbackRtpEcnItem(Header* header);
explicit FeedbackRtpEcnItem(FeedbackRtpEcnItem* item);
virtual ~FeedbackRtpEcnItem(){};
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:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
}; };
public: // Ecn packet declaration.
static const FeedbackRtp::MessageType MessageType = FeedbackRtp::MessageType::ECN; typedef FeedbackRtpItemsPacket<FeedbackRtpEcnItem> FeedbackRtpEcnPacket;
public: /* Inline instance methods. */
static FeedbackRtpEcnItem* Parse(const uint8_t* data, size_t len);
public: inline FeedbackRtpEcnItem::FeedbackRtpEcnItem(Header* header)
explicit FeedbackRtpEcnItem(Header* header); : header(header)
explicit FeedbackRtpEcnItem(FeedbackRtpEcnItem* item); {
virtual ~FeedbackRtpEcnItem() {}; }
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:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
};
// Ecn packet declaration.
typedef FeedbackRtpItemsPacket<FeedbackRtpEcnItem> FeedbackRtpEcnPacket;
/* Inline instance methods. */
inline
FeedbackRtpEcnItem::FeedbackRtpEcnItem(Header* header):
header(header)
{}
inline inline FeedbackRtpEcnItem::FeedbackRtpEcnItem(FeedbackRtpEcnItem* item)
FeedbackRtpEcnItem::FeedbackRtpEcnItem(FeedbackRtpEcnItem* item): : header(item->header)
header(item->header) {
{} }
inline inline size_t FeedbackRtpEcnItem::GetSize() const
size_t FeedbackRtpEcnItem::GetSize() const {
{ return sizeof(Header);
return sizeof(Header); }
}
inline inline uint32_t FeedbackRtpEcnItem::GetSequenceNumber() const
uint32_t FeedbackRtpEcnItem::GetSequenceNumber() const {
{ return ntohl(this->header->sequenceNumber);
return ntohl(this->header->sequence_number); }
}
inline inline uint32_t FeedbackRtpEcnItem::GetEct0Counter() const
uint32_t FeedbackRtpEcnItem::GetEct0Counter() const {
{ return ntohl(this->header->ect0Counter);
return ntohl(this->header->ect0_counter); }
}
inline inline uint32_t FeedbackRtpEcnItem::GetEct1Counter() const
uint32_t FeedbackRtpEcnItem::GetEct1Counter() const {
{ return ntohl(this->header->ect1Counter);
return ntohl(this->header->ect1_counter); }
}
inline inline uint16_t FeedbackRtpEcnItem::GetEcnCeCounter() const
uint16_t FeedbackRtpEcnItem::GetEcnCeCounter() const {
{ return ntohs(this->header->ecnCeCounter);
return ntohs(this->header->ecn_ce_counter); }
}
inline inline uint16_t FeedbackRtpEcnItem::GetNotEctCounter() const
uint16_t FeedbackRtpEcnItem::GetNotEctCounter() const {
{ return ntohs(this->header->notEctCounter);
return ntohs(this->header->not_ect_counter); }
}
inline inline uint16_t FeedbackRtpEcnItem::GetLostPackets() const
uint16_t FeedbackRtpEcnItem::GetLostPackets() const {
{ return ntohs(this->header->lostPackets);
return ntohs(this->header->lost_packets); }
}
inline inline uint16_t FeedbackRtpEcnItem::GetDuplicatedPackets() const
uint16_t FeedbackRtpEcnItem::GetDuplicatedPackets() const {
{ return ntohs(this->header->duplicatedPackets);
return ntohs(this->header->duplicated_packets); }
} }
}} }
#endif #endif
...@@ -13,75 +13,74 @@ ...@@ -13,75 +13,74 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackRtpNackItem namespace RTCP
: public FeedbackItem
{ {
public: class FeedbackRtpNackItem : public FeedbackItem
struct Header
{ {
uint16_t packet_id; public:
uint16_t lost_packet_bitmask; struct Header
{
uint16_t packetId;
uint16_t lostPacketBitmask;
};
public:
static const FeedbackRtp::MessageType MessageType = FeedbackRtp::MessageType::NACK;
public:
static FeedbackRtpNackItem* Parse(const uint8_t* data, size_t len);
public:
explicit FeedbackRtpNackItem(Header* header);
explicit FeedbackRtpNackItem(FeedbackRtpNackItem* item);
FeedbackRtpNackItem(uint16_t packetId, uint16_t lostPacketBitmask);
virtual ~FeedbackRtpNackItem(){};
uint16_t GetPacketId() const;
uint16_t GetLostPacketBitmask() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
}; };
public: // Nack packet declaration.
static const FeedbackRtp::MessageType MessageType = FeedbackRtp::MessageType::NACK; typedef FeedbackRtpItemsPacket<FeedbackRtpNackItem> FeedbackRtpNackPacket;
public: /* Inline instance methods. */
static FeedbackRtpNackItem* Parse(const uint8_t* data, size_t len);
public: inline FeedbackRtpNackItem::FeedbackRtpNackItem(Header* header)
explicit FeedbackRtpNackItem(Header* header); : header(header)
explicit FeedbackRtpNackItem(FeedbackRtpNackItem* item); {
FeedbackRtpNackItem(uint16_t packetId, uint16_t lostPacketBitmask); }
virtual ~FeedbackRtpNackItem() {};
uint16_t GetPacketId() const;
uint16_t GetLostPacketBitmask() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
};
// Nack packet declaration.
typedef FeedbackRtpItemsPacket<FeedbackRtpNackItem> FeedbackRtpNackPacket;
/* Inline instance methods. */
inline
FeedbackRtpNackItem::FeedbackRtpNackItem(Header* header):
header(header)
{}
inline inline FeedbackRtpNackItem::FeedbackRtpNackItem(FeedbackRtpNackItem* item)
FeedbackRtpNackItem::FeedbackRtpNackItem(FeedbackRtpNackItem* item): : header(item->header)
header(item->header) {
{} }
inline inline size_t FeedbackRtpNackItem::GetSize() const
size_t FeedbackRtpNackItem::GetSize() const {
{ return sizeof(Header);
return sizeof(Header); }
}
inline inline uint16_t FeedbackRtpNackItem::GetPacketId() const
uint16_t FeedbackRtpNackItem::GetPacketId() const {
{ return (uint16_t)ntohs(this->header->packetId);
return (uint16_t)ntohs(this->header->packet_id); }
}
inline inline uint16_t FeedbackRtpNackItem::GetLostPacketBitmask() const
uint16_t FeedbackRtpNackItem::GetLostPacketBitmask() const {
{ return (uint16_t)ntohs(this->header->lostPacketBitmask);
return (uint16_t)ntohs(this->header->lost_packet_bitmask); }
} }
}} }
#endif #endif
...@@ -4,34 +4,36 @@ ...@@ -4,34 +4,36 @@
#include "common.hpp" #include "common.hpp"
#include "RTC/RTCP/Feedback.hpp" #include "RTC/RTCP/Feedback.hpp"
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackRtpSrReqPacket namespace RTCP
: public FeedbackRtpPacket
{ {
public: class FeedbackRtpSrReqPacket : public FeedbackRtpPacket
static FeedbackRtpSrReqPacket* Parse(const uint8_t* data, size_t len); {
public:
public: static FeedbackRtpSrReqPacket* Parse(const uint8_t* data, size_t len);
// Parsed Report. Points to an external data.
explicit FeedbackRtpSrReqPacket(CommonHeader* commonHeader); public:
FeedbackRtpSrReqPacket(uint32_t sender_ssrc, uint32_t media_ssrc); // Parsed Report. Points to an external data.
virtual ~FeedbackRtpSrReqPacket() {}; explicit FeedbackRtpSrReqPacket(CommonHeader* commonHeader);
FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc);
virtual void Dump() const override; virtual ~FeedbackRtpSrReqPacket(){};
};
virtual void Dump() const override;
/* Inline instance methods. */ };
inline /* Inline instance methods. */
FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(CommonHeader* commonHeader):
FeedbackRtpPacket(commonHeader) inline FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(CommonHeader* commonHeader)
{} : FeedbackRtpPacket(commonHeader)
{
inline }
FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(uint32_t sender_ssrc, uint32_t media_ssrc):
FeedbackRtpPacket(FeedbackRtp::MessageType::SR_REQ, sender_ssrc, media_ssrc) inline FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
{} : FeedbackRtpPacket(FeedbackRtp::MessageType::SR_REQ, senderSsrc, mediaSsrc)
}} {
}
}
}
#endif #endif
...@@ -13,75 +13,74 @@ ...@@ -13,75 +13,74 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackRtpTlleiItem namespace RTCP
: public FeedbackItem
{ {
private: class FeedbackRtpTlleiItem : public FeedbackItem
struct Header
{ {
uint16_t packet_id; private:
uint16_t lost_packet_bitmask; struct Header
{
uint16_t packetId;
uint16_t lostPacketBitmask;
};
public:
static const FeedbackRtp::MessageType MessageType = FeedbackRtp::MessageType::TLLEI;
public:
static FeedbackRtpTlleiItem* Parse(const uint8_t* data, size_t len);
public:
explicit FeedbackRtpTlleiItem(Header* header);
explicit FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item);
FeedbackRtpTlleiItem(uint16_t packetId, uint16_t lostPacketBitmask);
virtual ~FeedbackRtpTlleiItem(){};
uint16_t GetPacketId() const;
uint16_t GetLostPacketBitmask() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
}; };
public: // Nack packet declaration.
static const FeedbackRtp::MessageType MessageType = FeedbackRtp::MessageType::TLLEI; typedef FeedbackRtpItemsPacket<FeedbackRtpTlleiItem> FeedbackRtpTlleiPacket;
public: /* Inline instance methods. */
static FeedbackRtpTlleiItem* Parse(const uint8_t* data, size_t len);
public: inline FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(Header* header)
explicit FeedbackRtpTlleiItem(Header* header); : header(header)
explicit FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item); {
FeedbackRtpTlleiItem(uint16_t packetId, uint16_t lostPacketBitmask); }
virtual ~FeedbackRtpTlleiItem() {};
uint16_t GetPacketId() const;
uint16_t GetLostPacketBitmask() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Header* header = nullptr;
};
// Nack packet declaration.
typedef FeedbackRtpItemsPacket<FeedbackRtpTlleiItem> FeedbackRtpTlleiPacket;
/* Inline instance methods. */
inline
FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(Header* header):
header(header)
{}
inline inline FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item)
FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item): : header(item->header)
header(item->header) {
{} }
inline inline size_t FeedbackRtpTlleiItem::GetSize() const
size_t FeedbackRtpTlleiItem::GetSize() const {
{ return sizeof(Header);
return sizeof(Header); }
}
inline inline uint16_t FeedbackRtpTlleiItem::GetPacketId() const
uint16_t FeedbackRtpTlleiItem::GetPacketId() const {
{ return (uint16_t)ntohs(this->header->packetId);
return (uint16_t)ntohs(this->header->packet_id); }
}
inline inline uint16_t FeedbackRtpTlleiItem::GetLostPacketBitmask() const
uint16_t FeedbackRtpTlleiItem::GetLostPacketBitmask() const {
{ return (uint16_t)ntohs(this->header->lostPacketBitmask);
return (uint16_t)ntohs(this->header->lost_packet_bitmask); }
} }
}} }
#endif #endif
...@@ -16,102 +16,110 @@ ...@@ -16,102 +16,110 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
template<typename T> class FeedbackRtpTmmbItem namespace RTCP
: public FeedbackItem
{ {
private: template<typename T>
static constexpr size_t HeaderSize = 8; class FeedbackRtpTmmbItem : public FeedbackItem
{
public: private:
static const FeedbackRtp::MessageType MessageType; static constexpr size_t HeaderSize = 8;
public: public:
static FeedbackRtpTmmbItem* Parse(const uint8_t* data, size_t len); static const FeedbackRtp::MessageType MessageType;
public: public:
explicit FeedbackRtpTmmbItem(const uint8_t* data); static FeedbackRtpTmmbItem* Parse(const uint8_t* data, size_t len);
FeedbackRtpTmmbItem();
public:
uint32_t GetSsrc() const; explicit FeedbackRtpTmmbItem(const uint8_t* data);
void SetSsrc(uint32_t ssrc); FeedbackRtpTmmbItem();
uint64_t GetBitrate() const;
void SetBitrate(uint64_t bitrate); uint32_t GetSsrc() const;
uint16_t GetOverhead() const; void SetSsrc(uint32_t ssrc);
void SetOverhead(uint16_t overhead); uint64_t GetBitrate() const;
void SetBitrate(uint64_t bitrate);
/* Virtual methods inherited from FeedbackItem. */ uint16_t GetOverhead() const;
public: void SetOverhead(uint16_t overhead);
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override; /* Virtual methods inherited from FeedbackItem. */
virtual size_t GetSize() const override; public:
virtual void Dump() const override;
private: virtual size_t Serialize(uint8_t* buffer) override;
uint32_t ssrc = 0; virtual size_t GetSize() const override;
uint64_t bitrate = 0;
uint16_t overhead = 0; private:
}; uint32_t ssrc = 0;
uint64_t bitrate = 0;
// Tmmb types declaration. uint16_t overhead = 0;
class FeedbackRtpTmmbr {}; };
class FeedbackRtpTmmbn {};
// Tmmb types declaration.
// Tmmbn classes declaration. class FeedbackRtpTmmbr
typedef FeedbackRtpTmmbItem<FeedbackRtpTmmbr> FeedbackRtpTmmbrItem; {
typedef FeedbackRtpTmmbItem<FeedbackRtpTmmbn> FeedbackRtpTmmbnItem; };
class FeedbackRtpTmmbn
// Tmmbn packets declaration. {
typedef FeedbackRtpItemsPacket<FeedbackRtpTmmbrItem> FeedbackRtpTmmbrPacket; };
typedef FeedbackRtpItemsPacket<FeedbackRtpTmmbnItem> FeedbackRtpTmmbnPacket;
// Tmmbn classes declaration.
/* Inline instance methods. */ typedef FeedbackRtpTmmbItem<FeedbackRtpTmmbr> FeedbackRtpTmmbrItem;
typedef FeedbackRtpTmmbItem<FeedbackRtpTmmbn> FeedbackRtpTmmbnItem;
template <typename T>
FeedbackRtpTmmbItem<T>::FeedbackRtpTmmbItem() // Tmmbn packets declaration.
{} typedef FeedbackRtpItemsPacket<FeedbackRtpTmmbrItem> FeedbackRtpTmmbrPacket;
typedef FeedbackRtpItemsPacket<FeedbackRtpTmmbnItem> FeedbackRtpTmmbnPacket;
template <typename T>
size_t FeedbackRtpTmmbItem<T>::GetSize() const /* Inline instance methods. */
{
return HeaderSize; template<typename T>
} FeedbackRtpTmmbItem<T>::FeedbackRtpTmmbItem()
{
template <typename T> }
uint32_t FeedbackRtpTmmbItem<T>::GetSsrc() const
{ template<typename T>
return this->ssrc; size_t FeedbackRtpTmmbItem<T>::GetSize() const
} {
return HeaderSize;
template <typename T> }
void FeedbackRtpTmmbItem<T>::SetSsrc(uint32_t ssrc)
{ template<typename T>
this->ssrc = ssrc; uint32_t FeedbackRtpTmmbItem<T>::GetSsrc() const
} {
return this->ssrc;
template <typename T> }
uint64_t FeedbackRtpTmmbItem<T>::GetBitrate() const
{ template<typename T>
return this->bitrate; void FeedbackRtpTmmbItem<T>::SetSsrc(uint32_t ssrc)
} {
this->ssrc = ssrc;
template <typename T> }
void FeedbackRtpTmmbItem<T>::SetBitrate(uint64_t bitrate)
{ template<typename T>
this->bitrate = bitrate; uint64_t FeedbackRtpTmmbItem<T>::GetBitrate() const
} {
return this->bitrate;
template <typename T> }
uint16_t FeedbackRtpTmmbItem<T>::GetOverhead() const
{ template<typename T>
return this->overhead; void FeedbackRtpTmmbItem<T>::SetBitrate(uint64_t bitrate)
} {
this->bitrate = bitrate;
template <typename T> }
void FeedbackRtpTmmbItem<T>::SetOverhead(uint16_t overhead)
{ template<typename T>
this->overhead = overhead; uint16_t FeedbackRtpTmmbItem<T>::GetOverhead() const
{
return this->overhead;
}
template<typename T>
void FeedbackRtpTmmbItem<T>::SetOverhead(uint16_t overhead)
{
this->overhead = overhead;
}
} }
}} }
#endif #endif
...@@ -5,137 +5,135 @@ ...@@ -5,137 +5,135 @@
#include <map> #include <map>
#include <string> #include <string>
#define MS_RTCP_BUFFER_SIZE 65536 namespace RTC
namespace RTC { namespace RTCP
{ {
// Maximum interval for regular RTCP mode. namespace RTCP
constexpr uint16_t MAX_VIDEO_INTERVAL_MS = 1000;
constexpr uint16_t MAX_AUDIO_INTERVAL_MS = 5000;
enum class Type : uint8_t
{
FIR = 192,
NACK = 193,
SR = 200,
RR = 201,
SDES = 202,
BYE = 203,
APP = 204,
RTPFB = 205,
PSFB = 206
};
class Packet
{ {
public: // Internal buffer for RTCP serialization.
/* Struct for RTCP common header. */ constexpr size_t bufferSize = 65536;
struct CommonHeader extern uint8_t buffer[bufferSize];
{
#if defined(MS_LITTLE_ENDIAN)
uint8_t count:5;
uint8_t padding:1;
uint8_t version:2;
#elif defined(MS_BIG_ENDIAN)
uint8_t version:2;
uint8_t padding:1;
uint8_t count:5;
#endif
uint8_t packet_type:8;
uint16_t length:16;
};
public:
static bool IsRtcp(const uint8_t* data, size_t len);
static Packet* Parse(const uint8_t* data, size_t len);
private:
static const std::string& Type2String(Type type);
private:
static std::map<Type, std::string> type2String;
public:
explicit Packet(Type type);
virtual ~Packet();
void SetNext(Packet* packet); // Maximum interval for regular RTCP mode.
Packet* GetNext() const; constexpr uint16_t maxVideoIntervalMs = 1000;
Type GetType() const; constexpr uint16_t maxAudioIntervalMs = 5000;
const uint8_t* GetData() const;
public: enum class Type : uint8_t
virtual void Dump() const = 0; {
virtual size_t Serialize(uint8_t* buffer) = 0; FIR = 192,
virtual size_t GetCount() const = 0; NACK = 193,
virtual size_t GetSize() const = 0; SR = 200,
RR = 201,
private: SDES = 202,
Type type; BYE = 203,
Packet* next = nullptr; APP = 204,
CommonHeader* header = nullptr; RTPFB = 205,
}; PSFB = 206
};
/* Inline static methods. */
inline class Packet
bool Packet::IsRtcp(const uint8_t* data, size_t len) {
{ public:
CommonHeader* header = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data)); /* Struct for RTCP common header. */
struct CommonHeader
return ( {
(len >= sizeof(CommonHeader)) && #if defined(MS_LITTLE_ENDIAN)
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes uint8_t count : 5;
(data[0] > 127 && data[0] < 192) && uint8_t padding : 1;
// RTP Version must be 2. uint8_t version : 2;
(header->version == 2) && #elif defined(MS_BIG_ENDIAN)
// RTCP packet types defined by IANA: uint8_t version : 2;
// http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4 uint8_t padding : 1;
// RFC 5761 (RTCP-mux) states this range for secure RTCP/RTP detection. uint8_t count : 5;
(header->packet_type >= 192 && header->packet_type <= 223) #endif
); uint8_t packetType : 8;
} uint16_t length : 16;
};
public:
static bool IsRtcp(const uint8_t* data, size_t len);
static Packet* Parse(const uint8_t* data, size_t len);
private:
static const std::string& Type2String(Type type);
private:
static std::map<Type, std::string> type2String;
public:
explicit Packet(Type type);
virtual ~Packet();
void SetNext(Packet* packet);
Packet* GetNext() const;
Type GetType() const;
const uint8_t* GetData() const;
public:
virtual void Dump() const = 0;
virtual size_t Serialize(uint8_t* buffer) = 0;
virtual size_t GetCount() const = 0;
virtual size_t GetSize() const = 0;
private:
Type type;
Packet* next = nullptr;
CommonHeader* header = nullptr;
};
/* Inline instance methods. */ /* Inline static methods. */
inline inline bool Packet::IsRtcp(const uint8_t* data, size_t len)
Packet::Packet(Type type) {
:type(type) CommonHeader* header = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data));
{}
return (
(len >= sizeof(CommonHeader)) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 127 && data[0] < 192) &&
// RTP Version must be 2.
(header->version == 2) &&
// RTCP packet types defined by IANA:
// http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4
// RFC 5761 (RTCP-mux) states this range for secure RTCP/RTP detection.
(header->packetType >= 192 && header->packetType <= 223));
}
/* Inline instance methods. */
inline Packet::Packet(Type type)
: type(type)
{
}
inline inline Packet::~Packet()
Packet::~Packet() {
{} }
inline inline Packet* Packet::GetNext() const
Packet* Packet::GetNext() const {
{ return this->next;
return this->next; }
}
inline inline void Packet::SetNext(Packet* packet)
void Packet::SetNext(Packet* packet) {
{ this->next = packet;
this->next = packet; }
}
inline inline Type Packet::GetType() const
Type Packet::GetType() const {
{ return this->type;
return this->type; }
}
inline inline size_t Packet::GetCount() const
size_t Packet::GetCount() const {
{ return 0;
return 0; }
}
inline inline const uint8_t* Packet::GetData() const
const uint8_t* Packet::GetData() const {
{ return (uint8_t*)this->header;
return (uint8_t*)this->header; }
} }
}} }
#endif #endif
...@@ -11,15 +11,15 @@ ...@@ -11,15 +11,15 @@
#define MS_RTC_REMOTE_BITRATE_ESTIMATOR_OVERUSE_DETECTOR_HPP #define MS_RTC_REMOTE_BITRATE_ESTIMATOR_OVERUSE_DETECTOR_HPP
#include "common.hpp" #include "common.hpp"
#include "RTC/RemoteBitrateEstimator/RateControlRegion.hpp"
#include "RTC/RemoteBitrateEstimator/BandwidthUsage.hpp" #include "RTC/RemoteBitrateEstimator/BandwidthUsage.hpp"
#include "RTC/RemoteBitrateEstimator/RateControlRegion.hpp"
#include <list> #include <list>
namespace RTC namespace RTC
{ {
class OveruseDetector class OveruseDetector
{ {
private: private:
static constexpr double kOverUsingTimeThreshold = 10; static constexpr double kOverUsingTimeThreshold = 10;
public: public:
...@@ -39,19 +39,18 @@ namespace RTC ...@@ -39,19 +39,18 @@ namespace RTC
void UpdateThreshold(double modifiedOffset, int64_t nowMs); void UpdateThreshold(double modifiedOffset, int64_t nowMs);
private: private:
double kUp = 0.0087; double kUp = 0.0087;
double kDown = 0.039; double kDown = 0.039;
double overusingTimeThreshold = kOverUsingTimeThreshold; double overusingTimeThreshold = kOverUsingTimeThreshold;
double threshold = 12.5; double threshold = 12.5;
int64_t lastUpdateMs = -1; int64_t lastUpdateMs = -1;
double prevOffset = 0.0; double prevOffset = 0.0;
double timeOverUsing = -1; double timeOverUsing = -1;
int overuseCounter = 0; int overuseCounter = 0;
BandwidthUsage hypothesis = kBwNormal; BandwidthUsage hypothesis = kBwNormal;
}; };
inline inline BandwidthUsage OveruseDetector::State() const
BandwidthUsage OveruseDetector::State() const
{ {
return this->hypothesis; return this->hypothesis;
} }
......
...@@ -14,17 +14,18 @@ namespace RTC ...@@ -14,17 +14,18 @@ namespace RTC
BandwidthUsage bwState; BandwidthUsage bwState;
uint32_t incomingBitrate = 0; uint32_t incomingBitrate = 0;
double noiseVar = 0; double noiseVar = 0;
}; };
/* Inline methods. */ /* Inline methods. */
inline inline RateControlInput::RateControlInput(
RateControlInput::RateControlInput(BandwidthUsage bwState, const uint32_t incomingBitrate, double noiseVar) : BandwidthUsage bwState, const uint32_t incomingBitrate, double noiseVar)
bwState(bwState), : bwState(bwState)
incomingBitrate(incomingBitrate), , incomingBitrate(incomingBitrate)
noiseVar(noiseVar) , noiseVar(noiseVar)
{} {
}
} }
#endif #endif
...@@ -50,8 +50,7 @@ namespace RTC ...@@ -50,8 +50,7 @@ namespace RTC
/* Inline instance methods. */ /* Inline instance methods. */
inline inline void SrtpSession::RemoveStream(uint32_t ssrc)
void SrtpSession::RemoveStream(uint32_t ssrc)
{ {
srtp_remove_stream(this->session, htonl(ssrc)); srtp_remove_stream(this->session, htonl(ssrc));
} }
......
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论