提交 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,14 +26,14 @@ namespace Channel ...@@ -30,14 +26,14 @@ 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.
......
#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);
......
...@@ -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);
} }
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
#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);
......
...@@ -69,12 +69,13 @@ ...@@ -69,12 +69,13 @@
#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
...@@ -2,15 +2,14 @@ ...@@ -2,15 +2,14 @@
#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
{ {
...@@ -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;
......
...@@ -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,10 +13,10 @@ public: ...@@ -15,10 +13,10 @@ 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 \
...@@ -27,8 +25,7 @@ MediaSoupError::MediaSoupError(const char* description) : ...@@ -27,8 +25,7 @@ MediaSoupError::MediaSoupError(const char* description) :
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 \
...@@ -37,7 +34,6 @@ MediaSoupError::MediaSoupError(const char* description) : ...@@ -37,7 +34,6 @@ MediaSoupError::MediaSoupError(const char* description) :
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
...@@ -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,7 +144,7 @@ namespace RTC ...@@ -137,7 +144,7 @@ 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. */
...@@ -159,7 +166,7 @@ namespace RTC ...@@ -159,7 +166,7 @@ namespace RTC
// 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;
...@@ -167,14 +174,12 @@ namespace RTC ...@@ -167,14 +174,12 @@ namespace RTC
/* 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,8 +9,7 @@ ...@@ -9,8 +9,7 @@
namespace RTC namespace RTC
{ {
class NackGenerator : class NackGenerator : public Timer::Listener
public Timer::Listener
{ {
public: public:
class Listener class Listener
...@@ -23,7 +22,7 @@ namespace RTC ...@@ -23,7 +22,7 @@ namespace RTC
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;
...@@ -67,11 +66,11 @@ namespace RTC ...@@ -67,11 +66,11 @@ namespace RTC
// 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,32 +25,37 @@ namespace RTC ...@@ -25,32 +25,37 @@ 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;
...@@ -62,7 +67,7 @@ namespace RTC ...@@ -62,7 +67,7 @@ namespace RTC
}; };
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,26 +2,25 @@ ...@@ -2,26 +2,25 @@
#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
...@@ -33,19 +32,22 @@ namespace RTC ...@@ -33,19 +32,22 @@ namespace RTC
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,17 +64,21 @@ namespace RTC ...@@ -62,17 +64,21 @@ 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;
RTC::RtpSender* GetRtpSenderFromRequest(
Channel::Request* request, uint32_t* rtpSenderId = nullptr) const;
/* Pure virtual methods inherited from RTC::Transport::Listener. */ /* Pure virtual methods inherited from RTC::Transport::Listener. */
public: public:
...@@ -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,13 +3,14 @@ ...@@ -3,13 +3,14 @@
#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 {
class ByePacket : public Packet
{ {
public: public:
typedef std::vector<uint32_t>::iterator Iterator; typedef std::vector<uint32_t>::iterator Iterator;
...@@ -19,7 +20,7 @@ namespace RTC { namespace RTCP ...@@ -19,7 +20,7 @@ namespace RTC { namespace RTCP
public: public:
ByePacket(); ByePacket();
virtual ~ByePacket() {}; virtual ~ByePacket(){};
void AddSsrc(uint32_t ssrc); void AddSsrc(uint32_t ssrc);
void SetReason(const std::string& reason); void SetReason(const std::string& reason);
...@@ -41,19 +42,17 @@ namespace RTC { namespace RTCP ...@@ -41,19 +42,17 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
inline inline ByePacket::ByePacket()
ByePacket::ByePacket()
: Packet(Type::BYE) : Packet(Type::BYE)
{} {
}
inline inline size_t ByePacket::GetCount() const
size_t ByePacket::GetCount() const
{ {
return this->ssrcs.size(); return this->ssrcs.size();
} }
inline inline size_t ByePacket::GetSize() const
size_t ByePacket::GetSize() const
{ {
size_t size = sizeof(Packet::CommonHeader); size_t size = sizeof(Packet::CommonHeader);
...@@ -70,35 +69,31 @@ namespace RTC { namespace RTCP ...@@ -70,35 +69,31 @@ namespace RTC { namespace RTCP
return (size + 3) & ~3; return (size + 3) & ~3;
} }
inline inline void ByePacket::AddSsrc(uint32_t ssrc)
void ByePacket::AddSsrc(uint32_t ssrc)
{ {
this->ssrcs.push_back(ssrc); this->ssrcs.push_back(ssrc);
} }
inline inline void ByePacket::SetReason(const std::string& reason)
void ByePacket::SetReason(const std::string& reason)
{ {
this->reason = reason; this->reason = reason;
} }
inline inline const std::string& ByePacket::GetReason() const
const std::string& ByePacket::GetReason() const
{ {
return this->reason; return this->reason;
} }
inline inline ByePacket::Iterator ByePacket::Begin()
ByePacket::Iterator ByePacket::Begin()
{ {
return this->ssrcs.begin(); return this->ssrcs.begin();
} }
inline inline ByePacket::Iterator ByePacket::End()
ByePacket::Iterator ByePacket::End()
{ {
return this->ssrcs.end(); return this->ssrcs.end();
} }
}} }
}
#endif #endif
...@@ -2,13 +2,15 @@ ...@@ -2,13 +2,15 @@
#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
{ {
namespace RTCP
{
class CompoundPacket class CompoundPacket
{ {
public: public:
...@@ -32,41 +34,36 @@ namespace RTC { namespace RTCP ...@@ -32,41 +34,36 @@ namespace RTC { namespace RTCP
/* 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,20 +2,22 @@ ...@@ -2,20 +2,22 @@
#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 {
template<typename T>
class FeedbackPacket : public Packet
{ {
public: public:
/* Struct for RTP Feedback message. */ /* Struct for RTP Feedback message. */
struct Header struct Header
{ {
uint32_t s_ssrc; uint32_t senderSsrc;
uint32_t m_ssrc; uint32_t mediaSsrc;
}; };
public: public:
...@@ -42,7 +44,7 @@ namespace RTC { namespace RTCP ...@@ -42,7 +44,7 @@ namespace RTC { namespace RTCP
protected: protected:
explicit FeedbackPacket(CommonHeader* commonHeader); explicit FeedbackPacket(CommonHeader* commonHeader);
FeedbackPacket(typename T::MessageType type, uint32_t sender_ssrc, uint32_t media_ssrc); FeedbackPacket(typename T::MessageType type, uint32_t senderSsrc, uint32_t mediaSsrc);
virtual ~FeedbackPacket(); virtual ~FeedbackPacket();
private: private:
...@@ -92,47 +94,48 @@ namespace RTC { namespace RTCP ...@@ -92,47 +94,48 @@ namespace RTC { namespace RTCP
/* 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,8 +3,10 @@ ...@@ -3,8 +3,10 @@
#include "common.hpp" #include "common.hpp"
namespace RTC { namespace RTCP namespace RTC
{ {
namespace RTCP
{
class FeedbackItem class FeedbackItem
{ {
public: public:
...@@ -26,15 +28,13 @@ namespace RTC { namespace RTCP ...@@ -26,15 +28,13 @@ namespace RTC { namespace RTCP
/* Inline instance methods */ /* Inline instance methods */
inline inline FeedbackItem::~FeedbackItem()
FeedbackItem::~FeedbackItem()
{ {
if (this->raw) if (this->raw)
delete this->raw; delete this->raw;
} }
inline inline void FeedbackItem::Serialize()
void FeedbackItem::Serialize()
{ {
if (this->raw) if (this->raw)
delete this->raw; delete this->raw;
...@@ -43,11 +43,11 @@ namespace RTC { namespace RTCP ...@@ -43,11 +43,11 @@ namespace RTC { namespace RTCP
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,10 +5,12 @@ ...@@ -5,10 +5,12 @@
#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 {
template<typename Item>
class FeedbackPsItemsPacket : public FeedbackPsPacket
{ {
public: public:
typedef typename std::vector<Item*>::iterator Iterator; typedef typename std::vector<Item*>::iterator Iterator;
...@@ -19,8 +21,8 @@ namespace RTC { namespace RTCP ...@@ -19,8 +21,8 @@ namespace RTC { namespace RTCP
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackPsItemsPacket(CommonHeader* commonHeader); explicit FeedbackPsItemsPacket(CommonHeader* commonHeader);
explicit FeedbackPsItemsPacket(uint32_t sender_ssrc, uint32_t media_ssrc = 0); explicit FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0);
virtual ~FeedbackPsItemsPacket() {}; virtual ~FeedbackPsItemsPacket(){};
void AddItem(Item* item); void AddItem(Item* item);
Iterator Begin(); Iterator Begin();
...@@ -39,14 +41,16 @@ namespace RTC { namespace RTCP ...@@ -39,14 +41,16 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
template<typename Item> template<typename Item>
FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(CommonHeader* commonHeader): FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(CommonHeader* commonHeader)
FeedbackPsPacket(commonHeader) : FeedbackPsPacket(commonHeader)
{} {
}
template<typename Item> template<typename Item>
FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(uint32_t sender_ssrc, uint32_t media_ssrc): FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
FeedbackPsPacket(Item::MessageType, sender_ssrc, media_ssrc) : FeedbackPsPacket(Item::MessageType, senderSsrc, mediaSsrc)
{} {
}
template<typename Item> template<typename Item>
size_t FeedbackPsItemsPacket<Item>::GetSize() const size_t FeedbackPsItemsPacket<Item>::GetSize() const
...@@ -78,6 +82,7 @@ namespace RTC { namespace RTCP ...@@ -78,6 +82,7 @@ namespace RTC { namespace RTCP
{ {
return this->items.end(); return this->items.end();
} }
}} }
}
#endif #endif
...@@ -4,17 +4,14 @@ ...@@ -4,17 +4,14 @@
#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);
...@@ -22,8 +19,8 @@ namespace RTC { namespace RTCP ...@@ -22,8 +19,8 @@ namespace RTC { namespace RTCP
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;
...@@ -41,33 +38,34 @@ namespace RTC { namespace RTCP ...@@ -41,33 +38,34 @@ namespace RTC { namespace RTCP
/* 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) - (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header)); this->size = ((ntohs(commonHeader->length) + 1) * 4) -
(sizeof(CommonHeader) + sizeof(FeedbackPacket::Header));
this->data = (uint8_t*)commonHeader + sizeof(CommonHeader) + sizeof(FeedbackPacket::Header); this->data = (uint8_t*)commonHeader + sizeof(CommonHeader) + sizeof(FeedbackPacket::Header);
this->application = application; this->application = application;
} }
inline inline FeedbackPsAfbPacket::FeedbackPsAfbPacket(
FeedbackPsAfbPacket::FeedbackPsAfbPacket(uint32_t sender_ssrc, uint32_t media_ssrc, Application application): uint32_t senderSsrc, uint32_t mediaSsrc, Application application)
FeedbackPsPacket(FeedbackPs::MessageType::AFB, sender_ssrc, media_ssrc) : FeedbackPsPacket(FeedbackPs::MessageType::AFB, senderSsrc, mediaSsrc)
{ {
this->application = application; this->application = application;
} }
inline inline FeedbackPsAfbPacket::Application FeedbackPsAfbPacket::GetApplication() const
FeedbackPsAfbPacket::Application FeedbackPsAfbPacket::GetApplication() const
{ {
return this->application; return this->application;
} }
inline inline size_t FeedbackPsAfbPacket::GetSize() const
size_t FeedbackPsAfbPacket::GetSize() const
{ {
return FeedbackPsPacket::GetSize() + this->size; return FeedbackPsPacket::GetSize() + this->size;
} }
}} }
}
#endif #endif
...@@ -16,17 +16,18 @@ ...@@ -16,17 +16,18 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackPsFirItem namespace RTCP
: public FeedbackItem {
class FeedbackPsFirItem : public FeedbackItem
{ {
private: private:
struct Header struct Header
{ {
uint32_t ssrc; uint32_t ssrc;
uint8_t sequence_number; uint8_t sequenceNumber;
uint32_t reserved:24; uint32_t reserved : 24;
}; };
public: public:
...@@ -38,8 +39,8 @@ namespace RTC { namespace RTCP ...@@ -38,8 +39,8 @@ namespace RTC { namespace RTCP
public: public:
explicit FeedbackPsFirItem(Header* header); explicit FeedbackPsFirItem(Header* header);
explicit FeedbackPsFirItem(FeedbackPsFirItem* item); explicit FeedbackPsFirItem(FeedbackPsFirItem* item);
FeedbackPsFirItem(uint32_t ssrc, uint8_t sequence_number); FeedbackPsFirItem(uint32_t ssrc, uint8_t sequenceNumber);
virtual ~FeedbackPsFirItem() {}; virtual ~FeedbackPsFirItem(){};
uint32_t GetSsrc() const; uint32_t GetSsrc() const;
uint8_t GetSequenceNumber() const; uint8_t GetSequenceNumber() const;
...@@ -59,33 +60,31 @@ namespace RTC { namespace RTCP ...@@ -59,33 +60,31 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
inline inline FeedbackPsFirItem::FeedbackPsFirItem(Header* header)
FeedbackPsFirItem::FeedbackPsFirItem(Header* header): : 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->sequence_number; return (uint8_t)this->header->sequenceNumber;
}
} }
}} }
#endif #endif
...@@ -13,10 +13,11 @@ ...@@ -13,10 +13,11 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackPsLeiItem namespace RTCP
: public FeedbackItem {
class FeedbackPsLeiItem : public FeedbackItem
{ {
private: private:
struct Header struct Header
...@@ -34,7 +35,7 @@ namespace RTC { namespace RTCP ...@@ -34,7 +35,7 @@ namespace RTC { namespace RTCP
explicit FeedbackPsLeiItem(Header* header); explicit FeedbackPsLeiItem(Header* header);
explicit FeedbackPsLeiItem(FeedbackPsLeiItem* item); explicit FeedbackPsLeiItem(FeedbackPsLeiItem* item);
explicit FeedbackPsLeiItem(uint32_t ssrc); explicit FeedbackPsLeiItem(uint32_t ssrc);
virtual ~FeedbackPsLeiItem() {}; virtual ~FeedbackPsLeiItem(){};
uint32_t GetSsrc() const; uint32_t GetSsrc() const;
...@@ -53,27 +54,26 @@ namespace RTC { namespace RTCP ...@@ -53,27 +54,26 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
inline inline FeedbackPsLeiItem::FeedbackPsLeiItem(Header* header)
FeedbackPsLeiItem::FeedbackPsLeiItem(Header* header): : 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,10 +4,11 @@ ...@@ -4,10 +4,11 @@
#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 {
class FeedbackPsPliPacket : public FeedbackPsPacket
{ {
public: public:
static FeedbackPsPliPacket* Parse(const uint8_t* data, size_t len); static FeedbackPsPliPacket* Parse(const uint8_t* data, size_t len);
...@@ -15,8 +16,8 @@ namespace RTC { namespace RTCP ...@@ -15,8 +16,8 @@ namespace RTC { namespace RTCP
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackPsPliPacket(CommonHeader* commonHeader); explicit FeedbackPsPliPacket(CommonHeader* commonHeader);
FeedbackPsPliPacket(uint32_t sender_ssrc, uint32_t media_ssrc); FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc);
virtual ~FeedbackPsPliPacket() {}; virtual ~FeedbackPsPliPacket(){};
public: public:
virtual void Dump() const override; virtual void Dump() const override;
...@@ -24,15 +25,16 @@ namespace RTC { namespace RTCP ...@@ -24,15 +25,16 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
inline inline FeedbackPsPliPacket::FeedbackPsPliPacket(CommonHeader* commonHeader)
FeedbackPsPliPacket::FeedbackPsPliPacket(CommonHeader* commonHeader): : FeedbackPsPacket(commonHeader)
FeedbackPsPacket(commonHeader) {
{} }
inline inline FeedbackPsPliPacket::FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
FeedbackPsPliPacket::FeedbackPsPliPacket(uint32_t sender_ssrc, uint32_t media_ssrc): : FeedbackPsPacket(FeedbackPs::MessageType::PLI, senderSsrc, mediaSsrc)
FeedbackPsPacket(FeedbackPs::MessageType::PLI, sender_ssrc, media_ssrc) {
{} }
}} }
}
#endif #endif
...@@ -25,10 +25,11 @@ ...@@ -25,10 +25,11 @@
| ... | | ... |
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackPsRembPacket namespace RTCP
: public FeedbackPsAfbPacket {
class FeedbackPsRembPacket : public FeedbackPsAfbPacket
{ {
public: public:
// 'R' 'E' 'M' 'B'. // 'R' 'E' 'M' 'B'.
...@@ -40,8 +41,8 @@ namespace RTC { namespace RTCP ...@@ -40,8 +41,8 @@ namespace RTC { namespace RTCP
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackPsRembPacket(CommonHeader* commonHeader); explicit FeedbackPsRembPacket(CommonHeader* commonHeader);
FeedbackPsRembPacket(uint32_t sender_ssrc, uint32_t media_ssrc); FeedbackPsRembPacket(uint32_t senderSsrc, uint32_t mediaSsrc);
virtual ~FeedbackPsRembPacket() {}; virtual ~FeedbackPsRembPacket(){};
bool IsCorrect(); bool IsCorrect();
void SetBitrate(uint64_t bitrate); void SetBitrate(uint64_t bitrate);
...@@ -64,46 +65,41 @@ namespace RTC { namespace RTCP ...@@ -64,46 +65,41 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
inline inline FeedbackPsRembPacket::FeedbackPsRembPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
FeedbackPsRembPacket::FeedbackPsRembPacket(uint32_t sender_ssrc, uint32_t media_ssrc): : FeedbackPsAfbPacket(senderSsrc, mediaSsrc, FeedbackPsAfbPacket::Application::REMB)
FeedbackPsAfbPacket(sender_ssrc, media_ssrc, FeedbackPsAfbPacket::Application::REMB) {
{} }
inline inline bool FeedbackPsRembPacket::IsCorrect()
bool FeedbackPsRembPacket::IsCorrect()
{ {
return this->isCorrect; return this->isCorrect;
} }
inline inline void FeedbackPsRembPacket::SetBitrate(uint64_t bitrate)
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 inline uint64_t FeedbackPsRembPacket::GetBitrate()
uint64_t FeedbackPsRembPacket::GetBitrate()
{ {
return this->bitrate; return this->bitrate;
} }
inline inline const std::vector<uint32_t>& FeedbackPsRembPacket::GetSsrcs()
const std::vector<uint32_t>& FeedbackPsRembPacket::GetSsrcs()
{ {
return this->ssrcs; return this->ssrcs;
} }
inline inline size_t FeedbackPsRembPacket::GetSize() const
size_t FeedbackPsRembPacket::GetSize() const
{ {
return FeedbackPsPacket::GetSize() + 8 + (sizeof(uint32_t) * this->ssrcs.size()); return FeedbackPsPacket::GetSize() + 8 + (sizeof(uint32_t) * this->ssrcs.size());
} }
}} }
}
#endif #endif
...@@ -17,10 +17,11 @@ ...@@ -17,10 +17,11 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackPsRpsiItem namespace RTCP
: public FeedbackItem {
class FeedbackPsRpsiItem : public FeedbackItem
{ {
const static size_t MaxBitStringSize = 6; const static size_t MaxBitStringSize = 6;
const static size_t BitStringOffset = 2; const static size_t BitStringOffset = 2;
...@@ -28,10 +29,10 @@ namespace RTC { namespace RTCP ...@@ -28,10 +29,10 @@ namespace RTC { namespace RTCP
private: private:
struct Header struct Header
{ {
uint8_t padding_bits; uint8_t paddingBits;
uint8_t zero:1; uint8_t zero : 1;
uint8_t payload_type:7; uint8_t payloadType : 7;
uint8_t bit_string[MaxBitStringSize]; uint8_t bitString[MaxBitStringSize];
}; };
public: public:
...@@ -43,8 +44,8 @@ namespace RTC { namespace RTCP ...@@ -43,8 +44,8 @@ namespace RTC { namespace RTCP
public: public:
explicit FeedbackPsRpsiItem(Header* header); explicit FeedbackPsRpsiItem(Header* header);
explicit FeedbackPsRpsiItem(FeedbackPsRpsiItem* item); explicit FeedbackPsRpsiItem(FeedbackPsRpsiItem* item);
FeedbackPsRpsiItem(uint8_t payload_type, uint8_t* bit_string, size_t length); FeedbackPsRpsiItem(uint8_t payloadType, uint8_t* bitString, size_t length);
virtual ~FeedbackPsRpsiItem() {}; virtual ~FeedbackPsRpsiItem(){};
bool IsCorrect() const; bool IsCorrect() const;
uint8_t GetPayloadType() const; uint8_t GetPayloadType() const;
...@@ -67,40 +68,36 @@ namespace RTC { namespace RTCP ...@@ -67,40 +68,36 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
inline inline FeedbackPsRpsiItem::FeedbackPsRpsiItem(FeedbackPsRpsiItem* item)
FeedbackPsRpsiItem::FeedbackPsRpsiItem(FeedbackPsRpsiItem* item) : : header(item->header)
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->payload_type; return this->header->payloadType;
} }
inline inline uint8_t* FeedbackPsRpsiItem::GetBitString() const
uint8_t* FeedbackPsRpsiItem::GetBitString() const
{ {
return this->header->bit_string; return this->header->bitString;
} }
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,10 +13,11 @@ ...@@ -13,10 +13,11 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackPsSliItem namespace RTCP
: public FeedbackItem {
class FeedbackPsSliItem : public FeedbackItem
{ {
private: private:
struct Header struct Header
...@@ -34,7 +35,7 @@ namespace RTC { namespace RTCP ...@@ -34,7 +35,7 @@ namespace RTC { namespace RTCP
explicit FeedbackPsSliItem(Header* header); explicit FeedbackPsSliItem(Header* header);
explicit FeedbackPsSliItem(FeedbackPsSliItem* item); explicit FeedbackPsSliItem(FeedbackPsSliItem* item);
FeedbackPsSliItem(uint16_t first, uint16_t number, uint8_t pictureId); FeedbackPsSliItem(uint16_t first, uint16_t number, uint8_t pictureId);
virtual ~FeedbackPsSliItem() {}; virtual ~FeedbackPsSliItem(){};
uint16_t GetFirst() const; uint16_t GetFirst() const;
void SetFirst(uint16_t first); void SetFirst(uint16_t first);
...@@ -61,47 +62,41 @@ namespace RTC { namespace RTCP ...@@ -61,47 +62,41 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
inline inline size_t FeedbackPsSliItem::GetSize() const
size_t FeedbackPsSliItem::GetSize() const
{ {
return sizeof(Header); return sizeof(Header);
} }
inline inline uint16_t FeedbackPsSliItem::GetFirst() const
uint16_t FeedbackPsSliItem::GetFirst() const
{ {
return this->first; return this->first;
} }
inline inline void FeedbackPsSliItem::SetFirst(uint16_t first)
void FeedbackPsSliItem::SetFirst(uint16_t first)
{ {
this->first = first; this->first = first;
} }
inline inline uint16_t FeedbackPsSliItem::GetNumber() const
uint16_t FeedbackPsSliItem::GetNumber() const
{ {
return this->number; return this->number;
} }
inline inline void FeedbackPsSliItem::SetNumber(uint16_t number)
void FeedbackPsSliItem::SetNumber(uint16_t number)
{ {
this->number = number; this->number = number;
} }
inline inline uint8_t FeedbackPsSliItem::GetPictureId() const
uint8_t FeedbackPsSliItem::GetPictureId() const
{ {
return this->pictureId; return this->pictureId;
} }
inline inline void FeedbackPsSliItem::SetPictureId(uint8_t pictureId)
void FeedbackPsSliItem::SetPictureId(uint8_t pictureId)
{ {
this->pictureId = pictureId; this->pictureId = pictureId;
} }
}} }
}
#endif #endif
...@@ -17,18 +17,20 @@ ...@@ -17,18 +17,20 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
template<typename T> class FeedbackPsTstItem namespace RTCP
: public FeedbackItem {
template<typename T>
class FeedbackPsTstItem : public FeedbackItem
{ {
private: private:
struct Header struct Header
{ {
uint32_t ssrc; uint32_t ssrc;
uint32_t sequence_number:8; uint32_t sequenceNumber : 8;
uint32_t reserved:19; uint32_t reserved : 19;
uint32_t index:5; uint32_t index : 5;
}; };
public: public:
...@@ -41,7 +43,7 @@ namespace RTC { namespace RTCP ...@@ -41,7 +43,7 @@ namespace RTC { namespace RTCP
explicit FeedbackPsTstItem(Header* header); explicit FeedbackPsTstItem(Header* header);
explicit FeedbackPsTstItem(FeedbackPsTstItem* item); explicit FeedbackPsTstItem(FeedbackPsTstItem* item);
FeedbackPsTstItem(uint32_t ssrc, uint8_t sequenceNumber, uint8_t index); FeedbackPsTstItem(uint32_t ssrc, uint8_t sequenceNumber, uint8_t index);
virtual ~FeedbackPsTstItem() {}; virtual ~FeedbackPsTstItem(){};
uint32_t GetSsrc() const; uint32_t GetSsrc() const;
uint8_t GetSequenceNumber() const; uint8_t GetSequenceNumber() const;
...@@ -57,8 +59,12 @@ namespace RTC { namespace RTCP ...@@ -57,8 +59,12 @@ namespace RTC { namespace RTCP
Header* header = nullptr; Header* header = nullptr;
}; };
class Tstr {}; class Tstr
class Tstn {}; {
};
class Tstn
{
};
// Tst classes declaration. // Tst classes declaration.
typedef FeedbackPsTstItem<Tstr> FeedbackPsTstrItem; typedef FeedbackPsTstItem<Tstr> FeedbackPsTstrItem;
...@@ -70,39 +76,42 @@ namespace RTC { namespace RTCP ...@@ -70,39 +76,42 @@ namespace RTC { namespace RTCP
/* 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,18 +19,19 @@ ...@@ -19,18 +19,19 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackPsVbcmItem namespace RTCP
: public FeedbackItem {
class FeedbackPsVbcmItem : public FeedbackItem
{ {
private: private:
struct Header struct Header
{ {
uint32_t ssrc; uint32_t ssrc;
uint8_t sequence_number; uint8_t sequenceNumber;
uint8_t zero:1; uint8_t zero : 1;
uint8_t payload_type:7; uint8_t payloadType : 7;
uint16_t length; uint16_t length;
uint8_t value[]; uint8_t value[];
}; };
...@@ -44,8 +45,9 @@ namespace RTC { namespace RTCP ...@@ -44,8 +45,9 @@ namespace RTC { namespace RTCP
public: public:
explicit FeedbackPsVbcmItem(Header* header); explicit FeedbackPsVbcmItem(Header* header);
explicit FeedbackPsVbcmItem(FeedbackPsVbcmItem* item); explicit FeedbackPsVbcmItem(FeedbackPsVbcmItem* item);
FeedbackPsVbcmItem(uint32_t ssrc, uint8_t sequence_number, uint8_t payload_type, uint16_t length, uint8_t* value); FeedbackPsVbcmItem(
virtual ~FeedbackPsVbcmItem() {}; uint32_t ssrc, uint8_t sequenceNumber, uint8_t payloadType, uint16_t length, uint8_t* value);
virtual ~FeedbackPsVbcmItem(){};
uint32_t GetSsrc() const; uint32_t GetSsrc() const;
uint8_t GetSequenceNumber() const; uint8_t GetSequenceNumber() const;
...@@ -68,18 +70,17 @@ namespace RTC { namespace RTCP ...@@ -68,18 +70,17 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
inline inline FeedbackPsVbcmItem::FeedbackPsVbcmItem(Header* header)
FeedbackPsVbcmItem::FeedbackPsVbcmItem(Header* header): : 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);
...@@ -87,35 +88,31 @@ namespace RTC { namespace RTCP ...@@ -87,35 +88,31 @@ namespace RTC { namespace RTCP
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->sequence_number; return (uint8_t)this->header->sequenceNumber;
} }
inline inline uint8_t FeedbackPsVbcmItem::GetPayloadType() const
uint8_t FeedbackPsVbcmItem::GetPayloadType() const
{ {
return (uint8_t)this->header->payload_type; return (uint8_t)this->header->payloadType;
} }
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,10 +5,12 @@ ...@@ -5,10 +5,12 @@
#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 {
template<typename Item>
class FeedbackRtpItemsPacket : public FeedbackRtpPacket
{ {
public: public:
typedef typename std::vector<Item*>::iterator Iterator; typedef typename std::vector<Item*>::iterator Iterator;
...@@ -19,8 +21,8 @@ namespace RTC { namespace RTCP ...@@ -19,8 +21,8 @@ namespace RTC { namespace RTCP
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackRtpItemsPacket(CommonHeader* commonHeader); explicit FeedbackRtpItemsPacket(CommonHeader* commonHeader);
explicit FeedbackRtpItemsPacket(uint32_t sender_ssrc, uint32_t media_ssrc = 0); explicit FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0);
virtual ~FeedbackRtpItemsPacket() {}; virtual ~FeedbackRtpItemsPacket(){};
void AddItem(Item* item); void AddItem(Item* item);
Iterator Begin(); Iterator Begin();
...@@ -39,14 +41,16 @@ namespace RTC { namespace RTCP ...@@ -39,14 +41,16 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
template<typename Item> template<typename Item>
FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(CommonHeader* commonHeader): FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(CommonHeader* commonHeader)
FeedbackRtpPacket(commonHeader) : FeedbackRtpPacket(commonHeader)
{} {
}
template<typename Item> template<typename Item>
FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(uint32_t sender_ssrc, uint32_t media_ssrc): FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
FeedbackRtpPacket(Item::MessageType, sender_ssrc, media_ssrc) : FeedbackRtpPacket(Item::MessageType, senderSsrc, mediaSsrc)
{} {
}
template<typename Item> template<typename Item>
size_t FeedbackRtpItemsPacket<Item>::GetSize() const size_t FeedbackRtpItemsPacket<Item>::GetSize() const
...@@ -78,6 +82,7 @@ namespace RTC { namespace RTCP ...@@ -78,6 +82,7 @@ namespace RTC { namespace RTCP
{ {
return this->items.end(); return this->items.end();
} }
}} }
}
#endif #endif
...@@ -24,21 +24,22 @@ ...@@ -24,21 +24,22 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackRtpEcnItem namespace RTCP
: public FeedbackItem {
class FeedbackRtpEcnItem : public FeedbackItem
{ {
private: private:
struct Header struct Header
{ {
uint32_t sequence_number; uint32_t sequenceNumber;
uint32_t ect0_counter; uint32_t ect0Counter;
uint32_t ect1_counter; uint32_t ect1Counter;
uint16_t ecn_ce_counter; uint16_t ecnCeCounter;
uint16_t not_ect_counter; uint16_t notEctCounter;
uint16_t lost_packets; uint16_t lostPackets;
uint16_t duplicated_packets; uint16_t duplicatedPackets;
}; };
public: public:
...@@ -50,7 +51,7 @@ namespace RTC { namespace RTCP ...@@ -50,7 +51,7 @@ namespace RTC { namespace RTCP
public: public:
explicit FeedbackRtpEcnItem(Header* header); explicit FeedbackRtpEcnItem(Header* header);
explicit FeedbackRtpEcnItem(FeedbackRtpEcnItem* item); explicit FeedbackRtpEcnItem(FeedbackRtpEcnItem* item);
virtual ~FeedbackRtpEcnItem() {}; virtual ~FeedbackRtpEcnItem(){};
uint32_t GetSequenceNumber() const; uint32_t GetSequenceNumber() const;
uint32_t GetEct0Counter() const; uint32_t GetEct0Counter() const;
...@@ -75,63 +76,56 @@ namespace RTC { namespace RTCP ...@@ -75,63 +76,56 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
inline inline FeedbackRtpEcnItem::FeedbackRtpEcnItem(Header* header)
FeedbackRtpEcnItem::FeedbackRtpEcnItem(Header* header): : 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->sequence_number); return ntohl(this->header->sequenceNumber);
} }
inline inline uint32_t FeedbackRtpEcnItem::GetEct0Counter() const
uint32_t FeedbackRtpEcnItem::GetEct0Counter() const
{ {
return ntohl(this->header->ect0_counter); return ntohl(this->header->ect0Counter);
} }
inline inline uint32_t FeedbackRtpEcnItem::GetEct1Counter() const
uint32_t FeedbackRtpEcnItem::GetEct1Counter() const
{ {
return ntohl(this->header->ect1_counter); return ntohl(this->header->ect1Counter);
} }
inline inline uint16_t FeedbackRtpEcnItem::GetEcnCeCounter() const
uint16_t FeedbackRtpEcnItem::GetEcnCeCounter() const
{ {
return ntohs(this->header->ecn_ce_counter); return ntohs(this->header->ecnCeCounter);
} }
inline inline uint16_t FeedbackRtpEcnItem::GetNotEctCounter() const
uint16_t FeedbackRtpEcnItem::GetNotEctCounter() const
{ {
return ntohs(this->header->not_ect_counter); return ntohs(this->header->notEctCounter);
} }
inline inline uint16_t FeedbackRtpEcnItem::GetLostPackets() const
uint16_t FeedbackRtpEcnItem::GetLostPackets() const
{ {
return ntohs(this->header->lost_packets); return ntohs(this->header->lostPackets);
} }
inline inline uint16_t FeedbackRtpEcnItem::GetDuplicatedPackets() const
uint16_t FeedbackRtpEcnItem::GetDuplicatedPackets() const
{ {
return ntohs(this->header->duplicated_packets); return ntohs(this->header->duplicatedPackets);
}
} }
}} }
#endif #endif
...@@ -13,16 +13,17 @@ ...@@ -13,16 +13,17 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackRtpNackItem namespace RTCP
: public FeedbackItem {
class FeedbackRtpNackItem : public FeedbackItem
{ {
public: public:
struct Header struct Header
{ {
uint16_t packet_id; uint16_t packetId;
uint16_t lost_packet_bitmask; uint16_t lostPacketBitmask;
}; };
public: public:
...@@ -35,7 +36,7 @@ namespace RTC { namespace RTCP ...@@ -35,7 +36,7 @@ namespace RTC { namespace RTCP
explicit FeedbackRtpNackItem(Header* header); explicit FeedbackRtpNackItem(Header* header);
explicit FeedbackRtpNackItem(FeedbackRtpNackItem* item); explicit FeedbackRtpNackItem(FeedbackRtpNackItem* item);
FeedbackRtpNackItem(uint16_t packetId, uint16_t lostPacketBitmask); FeedbackRtpNackItem(uint16_t packetId, uint16_t lostPacketBitmask);
virtual ~FeedbackRtpNackItem() {}; virtual ~FeedbackRtpNackItem(){};
uint16_t GetPacketId() const; uint16_t GetPacketId() const;
uint16_t GetLostPacketBitmask() const; uint16_t GetLostPacketBitmask() const;
...@@ -55,33 +56,31 @@ namespace RTC { namespace RTCP ...@@ -55,33 +56,31 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
inline inline FeedbackRtpNackItem::FeedbackRtpNackItem(Header* header)
FeedbackRtpNackItem::FeedbackRtpNackItem(Header* header): : 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->packet_id); return (uint16_t)ntohs(this->header->packetId);
} }
inline inline uint16_t FeedbackRtpNackItem::GetLostPacketBitmask() const
uint16_t FeedbackRtpNackItem::GetLostPacketBitmask() const
{ {
return (uint16_t)ntohs(this->header->lost_packet_bitmask); return (uint16_t)ntohs(this->header->lostPacketBitmask);
}
} }
}} }
#endif #endif
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
#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 {
class FeedbackRtpSrReqPacket : public FeedbackRtpPacket
{ {
public: public:
static FeedbackRtpSrReqPacket* Parse(const uint8_t* data, size_t len); static FeedbackRtpSrReqPacket* Parse(const uint8_t* data, size_t len);
...@@ -15,23 +16,24 @@ namespace RTC { namespace RTCP ...@@ -15,23 +16,24 @@ namespace RTC { namespace RTCP
public: public:
// Parsed Report. Points to an external data. // Parsed Report. Points to an external data.
explicit FeedbackRtpSrReqPacket(CommonHeader* commonHeader); explicit FeedbackRtpSrReqPacket(CommonHeader* commonHeader);
FeedbackRtpSrReqPacket(uint32_t sender_ssrc, uint32_t media_ssrc); FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc);
virtual ~FeedbackRtpSrReqPacket() {}; virtual ~FeedbackRtpSrReqPacket(){};
virtual void Dump() const override; virtual void Dump() const override;
}; };
/* Inline instance methods. */ /* Inline instance methods. */
inline inline FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(CommonHeader* commonHeader)
FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(CommonHeader* commonHeader): : FeedbackRtpPacket(commonHeader)
FeedbackRtpPacket(commonHeader) {
{} }
inline inline FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
FeedbackRtpSrReqPacket::FeedbackRtpSrReqPacket(uint32_t sender_ssrc, uint32_t media_ssrc): : FeedbackRtpPacket(FeedbackRtp::MessageType::SR_REQ, senderSsrc, mediaSsrc)
FeedbackRtpPacket(FeedbackRtp::MessageType::SR_REQ, sender_ssrc, media_ssrc) {
{} }
}} }
}
#endif #endif
...@@ -13,16 +13,17 @@ ...@@ -13,16 +13,17 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
class FeedbackRtpTlleiItem namespace RTCP
: public FeedbackItem {
class FeedbackRtpTlleiItem : public FeedbackItem
{ {
private: private:
struct Header struct Header
{ {
uint16_t packet_id; uint16_t packetId;
uint16_t lost_packet_bitmask; uint16_t lostPacketBitmask;
}; };
public: public:
...@@ -35,7 +36,7 @@ namespace RTC { namespace RTCP ...@@ -35,7 +36,7 @@ namespace RTC { namespace RTCP
explicit FeedbackRtpTlleiItem(Header* header); explicit FeedbackRtpTlleiItem(Header* header);
explicit FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item); explicit FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item);
FeedbackRtpTlleiItem(uint16_t packetId, uint16_t lostPacketBitmask); FeedbackRtpTlleiItem(uint16_t packetId, uint16_t lostPacketBitmask);
virtual ~FeedbackRtpTlleiItem() {}; virtual ~FeedbackRtpTlleiItem(){};
uint16_t GetPacketId() const; uint16_t GetPacketId() const;
uint16_t GetLostPacketBitmask() const; uint16_t GetLostPacketBitmask() const;
...@@ -55,33 +56,31 @@ namespace RTC { namespace RTCP ...@@ -55,33 +56,31 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
inline inline FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(Header* header)
FeedbackRtpTlleiItem::FeedbackRtpTlleiItem(Header* header): : 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->packet_id); return (uint16_t)ntohs(this->header->packetId);
} }
inline inline uint16_t FeedbackRtpTlleiItem::GetLostPacketBitmask() const
uint16_t FeedbackRtpTlleiItem::GetLostPacketBitmask() const
{ {
return (uint16_t)ntohs(this->header->lost_packet_bitmask); return (uint16_t)ntohs(this->header->lostPacketBitmask);
}
} }
}} }
#endif #endif
...@@ -16,10 +16,12 @@ ...@@ -16,10 +16,12 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
namespace RTC { namespace RTCP namespace RTC
{ {
template<typename T> class FeedbackRtpTmmbItem namespace RTCP
: public FeedbackItem {
template<typename T>
class FeedbackRtpTmmbItem : public FeedbackItem
{ {
private: private:
static constexpr size_t HeaderSize = 8; static constexpr size_t HeaderSize = 8;
...@@ -54,8 +56,12 @@ namespace RTC { namespace RTCP ...@@ -54,8 +56,12 @@ namespace RTC { namespace RTCP
}; };
// Tmmb types declaration. // Tmmb types declaration.
class FeedbackRtpTmmbr {}; class FeedbackRtpTmmbr
class FeedbackRtpTmmbn {}; {
};
class FeedbackRtpTmmbn
{
};
// Tmmbn classes declaration. // Tmmbn classes declaration.
typedef FeedbackRtpTmmbItem<FeedbackRtpTmmbr> FeedbackRtpTmmbrItem; typedef FeedbackRtpTmmbItem<FeedbackRtpTmmbr> FeedbackRtpTmmbrItem;
...@@ -67,51 +73,53 @@ namespace RTC { namespace RTCP ...@@ -67,51 +73,53 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
template <typename T> template<typename T>
FeedbackRtpTmmbItem<T>::FeedbackRtpTmmbItem() FeedbackRtpTmmbItem<T>::FeedbackRtpTmmbItem()
{} {
}
template <typename T> template<typename T>
size_t FeedbackRtpTmmbItem<T>::GetSize() const size_t FeedbackRtpTmmbItem<T>::GetSize() const
{ {
return HeaderSize; return HeaderSize;
} }
template <typename T> template<typename T>
uint32_t FeedbackRtpTmmbItem<T>::GetSsrc() const uint32_t FeedbackRtpTmmbItem<T>::GetSsrc() const
{ {
return this->ssrc; return this->ssrc;
} }
template <typename T> template<typename T>
void FeedbackRtpTmmbItem<T>::SetSsrc(uint32_t ssrc) void FeedbackRtpTmmbItem<T>::SetSsrc(uint32_t ssrc)
{ {
this->ssrc = ssrc; this->ssrc = ssrc;
} }
template <typename T> template<typename T>
uint64_t FeedbackRtpTmmbItem<T>::GetBitrate() const uint64_t FeedbackRtpTmmbItem<T>::GetBitrate() const
{ {
return this->bitrate; return this->bitrate;
} }
template <typename T> template<typename T>
void FeedbackRtpTmmbItem<T>::SetBitrate(uint64_t bitrate) void FeedbackRtpTmmbItem<T>::SetBitrate(uint64_t bitrate)
{ {
this->bitrate = bitrate; this->bitrate = bitrate;
} }
template <typename T> template<typename T>
uint16_t FeedbackRtpTmmbItem<T>::GetOverhead() const uint16_t FeedbackRtpTmmbItem<T>::GetOverhead() const
{ {
return this->overhead; return this->overhead;
} }
template <typename T> template<typename T>
void FeedbackRtpTmmbItem<T>::SetOverhead(uint16_t overhead) void FeedbackRtpTmmbItem<T>::SetOverhead(uint16_t overhead)
{ {
this->overhead = overhead; this->overhead = overhead;
} }
}} }
}
#endif #endif
...@@ -5,13 +5,17 @@ ...@@ -5,13 +5,17 @@
#include <map> #include <map>
#include <string> #include <string>
#define MS_RTCP_BUFFER_SIZE 65536 namespace RTC
namespace RTC { namespace RTCP
{ {
namespace RTCP
{
// Internal buffer for RTCP serialization.
constexpr size_t bufferSize = 65536;
extern uint8_t buffer[bufferSize];
// Maximum interval for regular RTCP mode. // Maximum interval for regular RTCP mode.
constexpr uint16_t MAX_VIDEO_INTERVAL_MS = 1000; constexpr uint16_t maxVideoIntervalMs = 1000;
constexpr uint16_t MAX_AUDIO_INTERVAL_MS = 5000; constexpr uint16_t maxAudioIntervalMs = 5000;
enum class Type : uint8_t enum class Type : uint8_t
{ {
...@@ -32,17 +36,17 @@ namespace RTC { namespace RTCP ...@@ -32,17 +36,17 @@ namespace RTC { namespace RTCP
/* Struct for RTCP common header. */ /* Struct for RTCP common header. */
struct CommonHeader struct CommonHeader
{ {
#if defined(MS_LITTLE_ENDIAN) #if defined(MS_LITTLE_ENDIAN)
uint8_t count:5; uint8_t count : 5;
uint8_t padding:1; uint8_t padding : 1;
uint8_t version:2; uint8_t version : 2;
#elif defined(MS_BIG_ENDIAN) #elif defined(MS_BIG_ENDIAN)
uint8_t version:2; uint8_t version : 2;
uint8_t padding:1; uint8_t padding : 1;
uint8_t count:5; uint8_t count : 5;
#endif #endif
uint8_t packet_type:8; uint8_t packetType : 8;
uint16_t length:16; uint16_t length : 16;
}; };
public: public:
...@@ -78,8 +82,7 @@ namespace RTC { namespace RTCP ...@@ -78,8 +82,7 @@ namespace RTC { namespace RTCP
/* Inline static methods. */ /* Inline static methods. */
inline inline bool Packet::IsRtcp(const uint8_t* data, size_t len)
bool Packet::IsRtcp(const uint8_t* data, size_t len)
{ {
CommonHeader* header = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data)); CommonHeader* header = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data));
...@@ -92,50 +95,45 @@ namespace RTC { namespace RTCP ...@@ -92,50 +95,45 @@ namespace RTC { namespace RTCP
// RTCP packet types defined by IANA: // RTCP packet types defined by IANA:
// http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4 // 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. // RFC 5761 (RTCP-mux) states this range for secure RTCP/RTP detection.
(header->packet_type >= 192 && header->packet_type <= 223) (header->packetType >= 192 && header->packetType <= 223));
);
} }
/* Inline instance methods. */ /* Inline instance methods. */
inline inline Packet::Packet(Type type)
Packet::Packet(Type type) : 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
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
#define MS_RTC_RTCP_RECEIVER_REPORT_HPP #define MS_RTC_RTCP_RECEIVER_REPORT_HPP
#include "common.hpp" #include "common.hpp"
#include "RTC/RTCP/Packet.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "RTC/RTCP/Packet.hpp"
#include <vector> #include <vector>
namespace RTC { namespace RTCP namespace RTC
{ {
namespace RTCP
{
class ReceiverReport class ReceiverReport
{ {
public: public:
...@@ -15,9 +17,9 @@ namespace RTC { namespace RTCP ...@@ -15,9 +17,9 @@ namespace RTC { namespace RTCP
struct Header struct Header
{ {
uint32_t ssrc; uint32_t ssrc;
uint32_t fraction_lost:8; uint32_t fractionLost : 8;
uint32_t total_lost:24; uint32_t totalLost : 24;
uint32_t last_seq; uint32_t lastSeq;
uint32_t jitter; uint32_t jitter;
uint32_t lsr; uint32_t lsr;
uint32_t dlsr; uint32_t dlsr;
...@@ -40,11 +42,11 @@ namespace RTC { namespace RTCP ...@@ -40,11 +42,11 @@ namespace RTC { namespace RTCP
uint32_t GetSsrc() const; uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc); void SetSsrc(uint32_t ssrc);
uint8_t GetFractionLost() const; uint8_t GetFractionLost() const;
void SetFractionLost(uint8_t fraction_lost); void SetFractionLost(uint8_t fractionLost);
int32_t GetTotalLost() const; int32_t GetTotalLost() const;
void SetTotalLost(int32_t total_lost); void SetTotalLost(int32_t totalLost);
uint32_t GetLastSeq() const; uint32_t GetLastSeq() const;
void SetLastSeq(uint32_t last_seq); void SetLastSeq(uint32_t lastSeq);
uint32_t GetJitter() const; uint32_t GetJitter() const;
void SetJitter(uint32_t jitter); void SetJitter(uint32_t jitter);
uint32_t GetLastSenderReport() const; uint32_t GetLastSenderReport() const;
...@@ -57,14 +59,13 @@ namespace RTC { namespace RTCP ...@@ -57,14 +59,13 @@ namespace RTC { namespace RTCP
uint8_t raw[sizeof(Header)] = {0}; uint8_t raw[sizeof(Header)] = {0};
}; };
class ReceiverReportPacket class ReceiverReportPacket : public Packet
: public Packet
{ {
public: public:
typedef std::vector<ReceiverReport*>::iterator Iterator; typedef std::vector<ReceiverReport*>::iterator Iterator;
public: public:
static ReceiverReportPacket* Parse(const uint8_t* data, size_t len, size_t offset=0); static ReceiverReportPacket* Parse(const uint8_t* data, size_t len, size_t offset = 0);
public: public:
ReceiverReportPacket(); ReceiverReportPacket();
...@@ -91,54 +92,47 @@ namespace RTC { namespace RTCP ...@@ -91,54 +92,47 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
inline inline ReceiverReport::ReceiverReport()
ReceiverReport::ReceiverReport()
{ {
this->header = reinterpret_cast<Header*>(this->raw); this->header = reinterpret_cast<Header*>(this->raw);
} }
inline inline ReceiverReport::ReceiverReport(Header* header)
ReceiverReport::ReceiverReport(Header* header) : : header(header)
header(header) {
{} }
inline inline ReceiverReport::ReceiverReport(ReceiverReport* report)
ReceiverReport::ReceiverReport(ReceiverReport* report) : : header(report->header)
header(report->header) {
{} }
inline inline size_t ReceiverReport::GetSize() const
size_t ReceiverReport::GetSize() const
{ {
return sizeof(Header); return sizeof(Header);
} }
inline inline uint32_t ReceiverReport::GetSsrc() const
uint32_t ReceiverReport::GetSsrc() const
{ {
return (uint32_t)ntohl(this->header->ssrc); return (uint32_t)ntohl(this->header->ssrc);
} }
inline inline void ReceiverReport::SetSsrc(uint32_t ssrc)
void ReceiverReport::SetSsrc(uint32_t ssrc)
{ {
this->header->ssrc = (uint32_t)htonl(ssrc); this->header->ssrc = (uint32_t)htonl(ssrc);
} }
inline inline uint8_t ReceiverReport::GetFractionLost() const
uint8_t ReceiverReport::GetFractionLost() const
{ {
return (uint8_t)Utils::Byte::Get1Byte((uint8_t*)this->header, 4); return (uint8_t)Utils::Byte::Get1Byte((uint8_t*)this->header, 4);
} }
inline inline void ReceiverReport::SetFractionLost(uint8_t fractionLost)
void ReceiverReport::SetFractionLost(uint8_t fraction_lost)
{ {
Utils::Byte::Set1Byte((uint8_t*)this->header, 4, fraction_lost); Utils::Byte::Set1Byte((uint8_t*)this->header, 4, fractionLost);
} }
inline inline int32_t ReceiverReport::GetTotalLost() const
int32_t ReceiverReport::GetTotalLost() const
{ {
uint32_t value = (uint32_t)Utils::Byte::Get3Bytes((uint8_t*)this->header, 5); uint32_t value = (uint32_t)Utils::Byte::Get3Bytes((uint8_t*)this->header, 5);
...@@ -153,75 +147,63 @@ namespace RTC { namespace RTCP ...@@ -153,75 +147,63 @@ namespace RTC { namespace RTCP
return -value; return -value;
} }
inline inline void ReceiverReport::SetTotalLost(int32_t totalLost)
void ReceiverReport::SetTotalLost(int32_t total_lost)
{ {
// Get the limit value for possitive and negative total_lost. // Get the limit value for possitive and negative totalLost.
int32_t clamp = (total_lost >= 0) ? int32_t clamp = (totalLost >= 0) ? totalLost > 0x07FFFFF ? 0x07FFFFF : totalLost
total_lost > 0x07FFFFF? 0x07FFFFF : total_lost : : -totalLost > 0x0800000 ? 0x0800000 : -totalLost;
-total_lost > 0x0800000? 0x0800000 : -total_lost;
uint32_t value = (total_lost >= 0) ? uint32_t value = (totalLost >= 0) ? (clamp & 0x07FFFFF) : (clamp | 0x0800000);
(clamp & 0x07FFFFF) : (clamp | 0x0800000);
Utils::Byte::Set3Bytes((uint8_t*)this->header, 5, value); Utils::Byte::Set3Bytes((uint8_t*)this->header, 5, value);
} }
inline inline uint32_t ReceiverReport::GetLastSeq() const
uint32_t ReceiverReport::GetLastSeq() const
{ {
return (uint32_t)ntohl(this->header->last_seq); return (uint32_t)ntohl(this->header->lastSeq);
} }
inline inline void ReceiverReport::SetLastSeq(uint32_t lastSeq)
void ReceiverReport::SetLastSeq(uint32_t last_seq)
{ {
this->header->last_seq = (uint32_t)htonl(last_seq); this->header->lastSeq = (uint32_t)htonl(lastSeq);
} }
inline inline uint32_t ReceiverReport::GetJitter() const
uint32_t ReceiverReport::GetJitter() const
{ {
return (uint32_t)ntohl(this->header->jitter); return (uint32_t)ntohl(this->header->jitter);
} }
inline inline void ReceiverReport::SetJitter(uint32_t jitter)
void ReceiverReport::SetJitter(uint32_t jitter)
{ {
this->header->jitter = (uint32_t)htonl(jitter); this->header->jitter = (uint32_t)htonl(jitter);
} }
inline inline uint32_t ReceiverReport::GetLastSenderReport() const
uint32_t ReceiverReport::GetLastSenderReport() const
{ {
return (uint32_t)ntohl(this->header->lsr); return (uint32_t)ntohl(this->header->lsr);
} }
inline inline void ReceiverReport::SetLastSenderReport(uint32_t lsr)
void ReceiverReport::SetLastSenderReport(uint32_t lsr)
{ {
this->header->lsr = (uint32_t)htonl(lsr); this->header->lsr = (uint32_t)htonl(lsr);
} }
inline inline uint32_t ReceiverReport::GetDelaySinceLastSenderReport() const
uint32_t ReceiverReport::GetDelaySinceLastSenderReport() const
{ {
return (uint32_t)ntohl(this->header->dlsr); return (uint32_t)ntohl(this->header->dlsr);
} }
inline inline void ReceiverReport::SetDelaySinceLastSenderReport(uint32_t dlsr)
void ReceiverReport::SetDelaySinceLastSenderReport(uint32_t dlsr)
{ {
this->header->dlsr = (uint32_t)htonl(dlsr); this->header->dlsr = (uint32_t)htonl(dlsr);
} }
inline inline ReceiverReportPacket::ReceiverReportPacket()
ReceiverReportPacket::ReceiverReportPacket()
: Packet(Type::RR) : Packet(Type::RR)
{} {
}
inline inline ReceiverReportPacket::~ReceiverReportPacket()
ReceiverReportPacket::~ReceiverReportPacket()
{ {
for (auto report : this->reports) for (auto report : this->reports)
{ {
...@@ -229,14 +211,12 @@ namespace RTC { namespace RTCP ...@@ -229,14 +211,12 @@ namespace RTC { namespace RTCP
} }
} }
inline inline size_t ReceiverReportPacket::GetCount() const
size_t ReceiverReportPacket::GetCount() const
{ {
return this->reports.size(); return this->reports.size();
} }
inline inline size_t ReceiverReportPacket::GetSize() const
size_t ReceiverReportPacket::GetSize() const
{ {
size_t size = sizeof(Packet::CommonHeader) + sizeof(this->ssrc); size_t size = sizeof(Packet::CommonHeader) + sizeof(this->ssrc);
...@@ -248,35 +228,31 @@ namespace RTC { namespace RTCP ...@@ -248,35 +228,31 @@ namespace RTC { namespace RTCP
return size; return size;
} }
inline inline uint32_t ReceiverReportPacket::GetSsrc() const
uint32_t ReceiverReportPacket::GetSsrc() const
{ {
return (uint32_t)ntohl(this->ssrc); return (uint32_t)ntohl(this->ssrc);
} }
inline inline void ReceiverReportPacket::SetSsrc(uint32_t ssrc)
void ReceiverReportPacket::SetSsrc(uint32_t ssrc)
{ {
this->ssrc = (uint32_t)htonl(ssrc); this->ssrc = (uint32_t)htonl(ssrc);
} }
inline inline void ReceiverReportPacket::AddReport(ReceiverReport* report)
void ReceiverReportPacket::AddReport(ReceiverReport* report)
{ {
this->reports.push_back(report); this->reports.push_back(report);
} }
inline inline ReceiverReportPacket::Iterator ReceiverReportPacket::Begin()
ReceiverReportPacket::Iterator ReceiverReportPacket::Begin()
{ {
return this->reports.begin(); return this->reports.begin();
} }
inline inline ReceiverReportPacket::Iterator ReceiverReportPacket::End()
ReceiverReportPacket::Iterator ReceiverReportPacket::End()
{ {
return this->reports.end(); return this->reports.end();
} }
}} }
}
#endif #endif
...@@ -3,12 +3,14 @@ ...@@ -3,12 +3,14 @@
#include "common.hpp" #include "common.hpp"
#include "RTC/RTCP/Packet.hpp" #include "RTC/RTCP/Packet.hpp"
#include <vector>
#include <map> #include <map>
#include <string> #include <string>
#include <vector>
namespace RTC { namespace RTCP namespace RTC
{ {
namespace RTCP
{
/* SDES Item. */ /* SDES Item. */
class SdesItem class SdesItem
{ {
...@@ -89,8 +91,7 @@ namespace RTC { namespace RTCP ...@@ -89,8 +91,7 @@ namespace RTC { namespace RTCP
std::vector<SdesItem*> items; std::vector<SdesItem*> items;
}; };
class SdesPacket class SdesPacket : public Packet
: public Packet
{ {
public: public:
typedef std::vector<SdesChunk*>::iterator Iterator; typedef std::vector<SdesChunk*>::iterator Iterator;
...@@ -119,55 +120,48 @@ namespace RTC { namespace RTCP ...@@ -119,55 +120,48 @@ namespace RTC { namespace RTCP
/* SDES Item inline instance methods */ /* SDES Item inline instance methods */
inline inline SdesItem::SdesItem(Header* header)
SdesItem::SdesItem(Header* header) : : header(header)
header(header) {
{} }
inline inline SdesItem::SdesItem(SdesItem* item)
SdesItem::SdesItem(SdesItem* item) : : header(item->header)
header(item->header) {
{} }
inline inline SdesItem::~SdesItem()
SdesItem::~SdesItem()
{ {
} }
inline inline size_t SdesItem::GetSize() const
size_t SdesItem::GetSize() const
{ {
return 2 + size_t(this->header->length); return 2 + size_t(this->header->length);
} }
inline inline SdesItem::Type SdesItem::GetType() const
SdesItem::Type SdesItem::GetType() const
{ {
return this->header->type; return this->header->type;
} }
inline inline uint8_t SdesItem::GetLength() const
uint8_t SdesItem::GetLength() const
{ {
return this->header->length; return this->header->length;
} }
inline inline char* SdesItem::GetValue() const
char* SdesItem::GetValue() const
{ {
return this->header->value; return this->header->value;
} }
/* Inline instance methods. */ /* Inline instance methods. */
inline inline SdesChunk::SdesChunk(uint32_t ssrc)
SdesChunk::SdesChunk(uint32_t ssrc)
{ {
this->ssrc = htonl(ssrc); this->ssrc = htonl(ssrc);
} }
inline inline SdesChunk::SdesChunk(SdesChunk* chunk)
SdesChunk::SdesChunk(SdesChunk* chunk)
{ {
this->ssrc = chunk->ssrc; this->ssrc = chunk->ssrc;
...@@ -177,8 +171,7 @@ namespace RTC { namespace RTCP ...@@ -177,8 +171,7 @@ namespace RTC { namespace RTCP
} }
} }
inline inline SdesChunk::~SdesChunk()
SdesChunk::~SdesChunk()
{ {
for (auto item : this->items) for (auto item : this->items)
{ {
...@@ -186,8 +179,7 @@ namespace RTC { namespace RTCP ...@@ -186,8 +179,7 @@ namespace RTC { namespace RTCP
} }
} }
inline inline size_t SdesChunk::GetSize() const
size_t SdesChunk::GetSize() const
{ {
size_t size = sizeof(this->ssrc); size_t size = sizeof(this->ssrc);
...@@ -201,45 +193,39 @@ namespace RTC { namespace RTCP ...@@ -201,45 +193,39 @@ namespace RTC { namespace RTCP
return (size + 3) & ~3; return (size + 3) & ~3;
} }
inline inline uint32_t SdesChunk::GetSsrc() const
uint32_t SdesChunk::GetSsrc() const
{ {
return (uint32_t)ntohl(this->ssrc); return (uint32_t)ntohl(this->ssrc);
} }
inline inline void SdesChunk::SetSsrc(uint32_t ssrc)
void SdesChunk::SetSsrc(uint32_t ssrc)
{ {
this->ssrc = (uint32_t)htonl(ssrc); this->ssrc = (uint32_t)htonl(ssrc);
} }
inline inline void SdesChunk::AddItem(SdesItem* item)
void SdesChunk::AddItem(SdesItem* item)
{ {
this->items.push_back(item); this->items.push_back(item);
} }
inline inline SdesChunk::Iterator SdesChunk::Begin()
SdesChunk::Iterator SdesChunk::Begin()
{ {
return this->items.begin(); return this->items.begin();
} }
inline inline SdesChunk::Iterator SdesChunk::End()
SdesChunk::Iterator SdesChunk::End()
{ {
return this->items.end(); return this->items.end();
} }
/* Inline instance methods. */ /* Inline instance methods. */
inline inline SdesPacket::SdesPacket()
SdesPacket::SdesPacket()
: Packet(RTCP::Type::SDES) : Packet(RTCP::Type::SDES)
{} {
}
inline inline SdesPacket::~SdesPacket()
SdesPacket::~SdesPacket()
{ {
for (auto chunk : this->chunks) for (auto chunk : this->chunks)
{ {
...@@ -247,14 +233,12 @@ namespace RTC { namespace RTCP ...@@ -247,14 +233,12 @@ namespace RTC { namespace RTCP
} }
} }
inline inline size_t SdesPacket::GetCount() const
size_t SdesPacket::GetCount() const
{ {
return this->chunks.size(); return this->chunks.size();
} }
inline inline size_t SdesPacket::GetSize() const
size_t SdesPacket::GetSize() const
{ {
size_t size = sizeof(Packet::CommonHeader); size_t size = sizeof(Packet::CommonHeader);
...@@ -266,23 +250,21 @@ namespace RTC { namespace RTCP ...@@ -266,23 +250,21 @@ namespace RTC { namespace RTCP
return size; return size;
} }
inline inline void SdesPacket::AddChunk(SdesChunk* chunk)
void SdesPacket::AddChunk(SdesChunk* chunk)
{ {
this->chunks.push_back(chunk); this->chunks.push_back(chunk);
} }
inline inline SdesPacket::Iterator SdesPacket::Begin()
SdesPacket::Iterator SdesPacket::Begin()
{ {
return this->chunks.begin(); return this->chunks.begin();
} }
inline inline SdesPacket::Iterator SdesPacket::End()
SdesPacket::Iterator SdesPacket::End()
{ {
return this->chunks.end(); return this->chunks.end();
} }
}} }
}
#endif #endif
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
#include "RTC/RTCP/Packet.hpp" #include "RTC/RTCP/Packet.hpp"
#include <vector> #include <vector>
namespace RTC { namespace RTCP namespace RTC
{ {
namespace RTCP
{
class SenderReport class SenderReport
{ {
public: public:
...@@ -14,11 +16,11 @@ namespace RTC { namespace RTCP ...@@ -14,11 +16,11 @@ namespace RTC { namespace RTCP
struct Header struct Header
{ {
uint32_t ssrc; uint32_t ssrc;
uint32_t ntp_sec; uint32_t ntpSec;
uint32_t ntp_frac; uint32_t ntpFrac;
uint32_t rtp_ts; uint32_t rtpTs;
uint32_t packet_count; uint32_t packetCount;
uint32_t octet_count; uint32_t octetCount;
}; };
public: public:
...@@ -38,23 +40,22 @@ namespace RTC { namespace RTCP ...@@ -38,23 +40,22 @@ namespace RTC { namespace RTCP
uint32_t GetSsrc() const; uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc); void SetSsrc(uint32_t ssrc);
uint32_t GetNtpSec() const; uint32_t GetNtpSec() const;
void SetNtpSec(uint32_t ntp_sec); void SetNtpSec(uint32_t ntpSec);
uint32_t GetNtpFrac() const; uint32_t GetNtpFrac() const;
void SetNtpFrac(uint32_t ntp_frac); void SetNtpFrac(uint32_t ntpFrac);
uint32_t GetRtpTs() const; uint32_t GetRtpTs() const;
void SetRtpTs(uint32_t rtp_ts); void SetRtpTs(uint32_t rtpTs);
uint32_t GetPacketCount() const; uint32_t GetPacketCount() const;
void SetPacketCount(uint32_t packet_count); void SetPacketCount(uint32_t packetCount);
uint32_t GetOctetCount() const; uint32_t GetOctetCount() const;
void SetOctetCount(uint32_t octet_count); void SetOctetCount(uint32_t octetCount);
private: private:
Header* header = nullptr; Header* header = nullptr;
uint8_t raw[sizeof(Header)] = {0}; uint8_t raw[sizeof(Header)] = {0};
}; };
class SenderReportPacket class SenderReportPacket : public Packet
: public Packet
{ {
public: public:
typedef std::vector<SenderReport*>::iterator Iterator; typedef std::vector<SenderReport*>::iterator Iterator;
...@@ -83,110 +84,97 @@ namespace RTC { namespace RTCP ...@@ -83,110 +84,97 @@ namespace RTC { namespace RTCP
/* Inline instance methods. */ /* Inline instance methods. */
inline inline SenderReport::SenderReport()
SenderReport::SenderReport()
{ {
this->header = reinterpret_cast<Header*>(this->raw); this->header = reinterpret_cast<Header*>(this->raw);
} }
inline inline SenderReport::SenderReport(Header* header)
SenderReport::SenderReport(Header* header) : : header(header)
header(header) {
{} }
inline inline SenderReport::SenderReport(SenderReport* report)
SenderReport::SenderReport(SenderReport* report) : : header(report->header)
header(report->header) {
{} }
inline inline size_t SenderReport::GetSize() const
size_t SenderReport::GetSize() const
{ {
return sizeof(Header); return sizeof(Header);
} }
inline inline uint32_t SenderReport::GetSsrc() const
uint32_t SenderReport::GetSsrc() const
{ {
return (uint32_t)ntohl(this->header->ssrc); return (uint32_t)ntohl(this->header->ssrc);
} }
inline inline void SenderReport::SetSsrc(uint32_t ssrc)
void SenderReport::SetSsrc(uint32_t ssrc)
{ {
this->header->ssrc = (uint32_t)htonl(ssrc); this->header->ssrc = (uint32_t)htonl(ssrc);
} }
inline inline uint32_t SenderReport::GetNtpSec() const
uint32_t SenderReport::GetNtpSec() const
{ {
return (uint32_t)ntohl(this->header->ntp_sec); return (uint32_t)ntohl(this->header->ntpSec);
} }
inline inline void SenderReport::SetNtpSec(uint32_t ntpSec)
void SenderReport::SetNtpSec(uint32_t ntp_sec)
{ {
this->header->ntp_sec = (uint32_t)htonl(ntp_sec); this->header->ntpSec = (uint32_t)htonl(ntpSec);
} }
inline inline uint32_t SenderReport::GetNtpFrac() const
uint32_t SenderReport::GetNtpFrac() const
{ {
return (uint32_t)ntohl(this->header->ntp_frac); return (uint32_t)ntohl(this->header->ntpFrac);
} }
inline inline void SenderReport::SetNtpFrac(uint32_t ntpFrac)
void SenderReport::SetNtpFrac(uint32_t ntp_frac)
{ {
this->header->ntp_frac = (uint32_t)htonl(ntp_frac); this->header->ntpFrac = (uint32_t)htonl(ntpFrac);
} }
inline inline uint32_t SenderReport::GetRtpTs() const
uint32_t SenderReport::GetRtpTs() const
{ {
return (uint32_t)ntohl(this->header->rtp_ts); return (uint32_t)ntohl(this->header->rtpTs);
} }
inline inline void SenderReport::SetRtpTs(uint32_t rtpTs)
void SenderReport::SetRtpTs(uint32_t rtp_ts)
{ {
this->header->rtp_ts = (uint32_t)htonl(rtp_ts); this->header->rtpTs = (uint32_t)htonl(rtpTs);
} }
inline inline
uint32_t SenderReport::GetPacketCount() const uint32_t
SenderReport::GetPacketCount() const
{ {
return (uint32_t)ntohl(this->header->packet_count); return (uint32_t)ntohl(this->header->packetCount);
} }
inline inline void SenderReport::SetPacketCount(uint32_t packetCount)
void SenderReport::SetPacketCount(uint32_t packet_count)
{ {
this->header->packet_count = (uint32_t)htonl(packet_count); this->header->packetCount = (uint32_t)htonl(packetCount);
} }
inline inline uint32_t SenderReport::GetOctetCount() const
uint32_t SenderReport::GetOctetCount() const
{ {
return (uint32_t)ntohl(this->header->octet_count); return (uint32_t)ntohl(this->header->octetCount);
} }
inline inline void SenderReport::SetOctetCount(uint32_t octetCount)
void SenderReport::SetOctetCount(uint32_t octet_count)
{ {
this->header->octet_count = (uint32_t)htonl(octet_count); this->header->octetCount = (uint32_t)htonl(octetCount);
} }
/* Inline instance methods. */ /* Inline instance methods. */
inline inline SenderReportPacket::SenderReportPacket()
SenderReportPacket::SenderReportPacket()
: Packet(Type::SR) : Packet(Type::SR)
{} {
}
inline inline SenderReportPacket::~SenderReportPacket()
SenderReportPacket::~SenderReportPacket()
{ {
for (auto report : this->reports) for (auto report : this->reports)
{ {
...@@ -194,14 +182,12 @@ namespace RTC { namespace RTCP ...@@ -194,14 +182,12 @@ namespace RTC { namespace RTCP
} }
} }
inline inline size_t SenderReportPacket::GetCount() const
size_t SenderReportPacket::GetCount() const
{ {
return this->reports.size(); return this->reports.size();
} }
inline inline size_t SenderReportPacket::GetSize() const
size_t SenderReportPacket::GetSize() const
{ {
size_t size = sizeof(Packet::CommonHeader); size_t size = sizeof(Packet::CommonHeader);
...@@ -213,23 +199,21 @@ namespace RTC { namespace RTCP ...@@ -213,23 +199,21 @@ namespace RTC { namespace RTCP
return size; return size;
} }
inline inline void SenderReportPacket::AddReport(SenderReport* report)
void SenderReportPacket::AddReport(SenderReport* report)
{ {
this->reports.push_back(report); this->reports.push_back(report);
} }
inline inline SenderReportPacket::Iterator SenderReportPacket::Begin()
SenderReportPacket::Iterator SenderReportPacket::Begin()
{ {
return this->reports.begin(); return this->reports.begin();
} }
inline inline SenderReportPacket::Iterator SenderReportPacket::End()
SenderReportPacket::Iterator SenderReportPacket::End()
{ {
return this->reports.end(); return this->reports.end();
} }
}} }
}
#endif #endif
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
#define MS_RTC_REMOTE_BITRATE_ESTIMATOR_AIMD_RATE_CONTROL_HPP #define MS_RTC_REMOTE_BITRATE_ESTIMATOR_AIMD_RATE_CONTROL_HPP
#include "common.hpp" #include "common.hpp"
#include "RTC/RemoteBitrateEstimator/RateControlRegion.hpp"
#include "RTC/RemoteBitrateEstimator/RateControlInput.hpp"
#include "RTC/RemoteBitrateEstimator/OveruseDetector.hpp" #include "RTC/RemoteBitrateEstimator/OveruseDetector.hpp"
#include "RTC/RemoteBitrateEstimator/RateControlInput.hpp"
#include "RTC/RemoteBitrateEstimator/RateControlRegion.hpp"
// A rate control implementation based on additive increases of // A rate control implementation based on additive increases of
// bitrate when no over-use is detected and multiplicative decreases when // bitrate when no over-use is detected and multiplicative decreases when
...@@ -107,52 +107,46 @@ namespace RTC ...@@ -107,52 +107,46 @@ namespace RTC
/* Inline methods. */ /* Inline methods. */
inline inline AimdRateControl::AimdRateControl()
AimdRateControl::AimdRateControl() : : currentInput(kBwNormal, 0, 1.0)
currentInput(kBwNormal, 0, 1.0) {
{} }
inline inline void AimdRateControl::SetStartBitrate(int startBitrateBps)
void AimdRateControl::SetStartBitrate(int startBitrateBps)
{ {
this->currentBitrateBps = startBitrateBps; this->currentBitrateBps = startBitrateBps;
this->bitrateIsInitialized = true; this->bitrateIsInitialized = true;
} }
inline inline void AimdRateControl::SetMinBitrate(int minBitrateBps)
void AimdRateControl::SetMinBitrate(int minBitrateBps)
{ {
this->minConfiguredBitrateBps = minBitrateBps; this->minConfiguredBitrateBps = minBitrateBps;
this->currentBitrateBps = std::max<int>(minBitrateBps, this->currentBitrateBps); this->currentBitrateBps = std::max<int>(minBitrateBps, this->currentBitrateBps);
} }
inline inline bool AimdRateControl::ValidEstimate() const
bool AimdRateControl::ValidEstimate() const
{ {
return this->bitrateIsInitialized; return this->bitrateIsInitialized;
} }
inline inline uint32_t AimdRateControl::LatestEstimate() const
uint32_t AimdRateControl::LatestEstimate() const
{ {
return this->currentBitrateBps; return this->currentBitrateBps;
} }
inline inline uint32_t AimdRateControl::UpdateBandwidthEstimate(int64_t nowMs)
uint32_t AimdRateControl::UpdateBandwidthEstimate(int64_t nowMs)
{ {
this->currentBitrateBps = ChangeBitrate(this->currentBitrateBps, this->currentInput.incomingBitrate, nowMs); this->currentBitrateBps =
ChangeBitrate(this->currentBitrateBps, this->currentInput.incomingBitrate, nowMs);
return this->currentBitrateBps; return this->currentBitrateBps;
} }
inline inline void AimdRateControl::SetRtt(int64_t rtt)
void AimdRateControl::SetRtt(int64_t rtt)
{ {
this->rtt = rtt; this->rtt = rtt;
} }
inline inline void AimdRateControl::SetEstimate(int bitrateBps, int64_t nowMs)
void AimdRateControl::SetEstimate(int bitrateBps, int64_t nowMs)
{ {
this->updated = true; this->updated = true;
this->bitrateIsInitialized = true; this->bitrateIsInitialized = true;
...@@ -160,26 +154,22 @@ namespace RTC ...@@ -160,26 +154,22 @@ namespace RTC
this->timeLastBitrateChange = nowMs; this->timeLastBitrateChange = nowMs;
} }
inline inline int AimdRateControl::GetLastBitrateDecreaseBps() const
int AimdRateControl::GetLastBitrateDecreaseBps() const
{ {
return this->lastDecrease; return this->lastDecrease;
} }
inline inline uint32_t AimdRateControl::AdditiveRateIncrease(int64_t nowMs, int64_t lastMs) const
uint32_t AimdRateControl::AdditiveRateIncrease(int64_t nowMs, int64_t lastMs) const
{ {
return static_cast<uint32_t>((nowMs - lastMs) * GetNearMaxIncreaseRateBps() / 1000); return static_cast<uint32_t>((nowMs - lastMs) * GetNearMaxIncreaseRateBps() / 1000);
} }
inline inline void AimdRateControl::ChangeRegion(RateControlRegion region)
void AimdRateControl::ChangeRegion(RateControlRegion region)
{ {
this->rateControlRegion = region; this->rateControlRegion = region;
} }
inline inline void AimdRateControl::ChangeState(RateControlState newState)
void AimdRateControl::ChangeState(RateControlState newState)
{ {
this->rateControlState = newState; this->rateControlState = newState;
} }
......
...@@ -27,19 +27,26 @@ namespace RTC ...@@ -27,19 +27,26 @@ namespace RTC
static constexpr int64_t kArrivalTimeOffsetThresholdMs = 3000; static constexpr int64_t kArrivalTimeOffsetThresholdMs = 3000;
// A timestamp group is defined as all packets with a timestamp which are at // A timestamp group is defined as all packets with a timestamp which are at
// most timestamp_group_length_ticks older than the first timestamp in that // most timestampGroupLengthTicks older than the first timestamp in that
// group. // group.
InterArrival(uint32_t timestamp_group_length_ticks, double timestamp_to_ms_coeff, bool enable_burst_grouping); InterArrival(uint32_t timestampGroupLengthTicks, double timestampToMsCoeff, bool enableBurstGrouping);
// This function returns true if a delta was computed, or false if the current // This function returns true if a delta was computed, or false if the current
// group is still incomplete or if only one group has been completed. // group is still incomplete or if only one group has been completed.
// |timestamp| is the timestamp. // |timestamp| is the timestamp.
// |arrival_time_ms| is the local time at which the packet arrived. // |arrivalTimeMs| is the local time at which the packet arrived.
// |packet_size| is the size of the packet. // |packetSize| is the size of the packet.
// |timestamp_delta| (output) is the computed timestamp delta. // |timestampDelta| (output) is the computed timestamp delta.
// |arrival_time_delta_ms| (output) is the computed arrival-time delta. // |arrivalTimeDeltaMs| (output) is the computed arrival-time delta.
// |packet_size_delta| (output) is the computed size delta. // |packetSizeDelta| (output) is the computed size delta.
bool ComputeDeltas(uint32_t timestamp, int64_t arrival_time_ms, int64_t system_time_ms, size_t packet_size, uint32_t* timestamp_delta, int64_t* arrival_time_delta_ms, int* packet_size_delta); bool ComputeDeltas(
uint32_t timestamp,
int64_t arrivalTimeMs,
int64_t systemTimeMs,
size_t packetSize,
uint32_t* timestampDelta,
int64_t* arrivalTimeDeltaMs,
int* packetSizeDelta);
private: private:
struct TimestampGroup struct TimestampGroup
...@@ -48,18 +55,18 @@ namespace RTC ...@@ -48,18 +55,18 @@ namespace RTC
bool IsFirstPacket() const; bool IsFirstPacket() const;
size_t size = 0; size_t size = 0;
uint32_t first_timestamp = 0; uint32_t firstTimestamp = 0;
uint32_t timestamp = 0; uint32_t timestamp = 0;
int64_t complete_time_ms = 0; int64_t completeTimeMs = 0;
int64_t last_system_time_ms = 0; int64_t lastSystemTimeMs = 0;
}; };
// Returns true if the packet with timestamp |timestamp| arrived in order. // Returns true if the packet with timestamp |timestamp| arrived in order.
bool PacketInOrder(uint32_t timestamp); bool PacketInOrder(uint32_t timestamp);
// Returns true if the last packet was the end of the current batch and the // Returns true if the last packet was the end of the current batch and the
// packet with |timestamp| is the first of a new batch. // packet with |timestamp| is the first of a new batch.
bool NewTimestampGroup(int64_t arrival_time_ms, uint32_t timestamp) const; bool NewTimestampGroup(int64_t arrivalTimeMs, uint32_t timestamp) const;
bool BelongsToBurst(int64_t arrival_time_ms, uint32_t timestamp) const; bool BelongsToBurst(int64_t arrivalTimeMs, uint32_t timestamp) const;
void Reset(); void Reset();
const uint32_t kTimestampGroupLengthTicks; const uint32_t kTimestampGroupLengthTicks;
...@@ -72,29 +79,29 @@ namespace RTC ...@@ -72,29 +79,29 @@ namespace RTC
/* Inline methods. */ /* Inline methods. */
inline inline InterArrival::TimestampGroup::TimestampGroup()
InterArrival::TimestampGroup::TimestampGroup() : : size(0)
size(0), , firstTimestamp(0)
first_timestamp(0), , timestamp(0)
timestamp(0), , completeTimeMs(-1)
complete_time_ms(-1) {
{} }
inline inline bool InterArrival::TimestampGroup::IsFirstPacket() const
bool InterArrival::TimestampGroup::IsFirstPacket() const
{ {
return complete_time_ms == -1; return completeTimeMs == -1;
} }
inline inline InterArrival::InterArrival(
InterArrival::InterArrival(uint32_t timestamp_group_length_ticks, double timestamp_to_ms_coeff, bool enable_burst_grouping) : uint32_t timestampGroupLengthTicks, double timestampToMsCoeff, bool enableBurstGrouping)
kTimestampGroupLengthTicks(timestamp_group_length_ticks), : kTimestampGroupLengthTicks(timestampGroupLengthTicks)
currentTimestampGroup(), , currentTimestampGroup()
prevTimestampGroup(), , prevTimestampGroup()
timestampToMsCoeff(timestamp_to_ms_coeff), , timestampToMsCoeff(timestampToMsCoeff)
burstGrouping(enable_burst_grouping), , burstGrouping(enableBurstGrouping)
numConsecutiveReorderedPackets(0) , numConsecutiveReorderedPackets(0)
{} {
}
} }
#endif #endif
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
#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
...@@ -50,8 +50,7 @@ namespace RTC ...@@ -50,8 +50,7 @@ namespace RTC
BandwidthUsage hypothesis = kBwNormal; BandwidthUsage hypothesis = kBwNormal;
}; };
inline inline BandwidthUsage OveruseDetector::State() const
BandwidthUsage OveruseDetector::State() const
{ {
return this->hypothesis; return this->hypothesis;
} }
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
#include "common.hpp" #include "common.hpp"
#include "RTC/RemoteBitrateEstimator/BandwidthUsage.hpp" #include "RTC/RemoteBitrateEstimator/BandwidthUsage.hpp"
#include <deque>
#include <cstring> // std::memcpy() #include <cstring> // std::memcpy()
#include <deque>
namespace RTC namespace RTC
{ {
...@@ -42,9 +42,10 @@ namespace RTC ...@@ -42,9 +42,10 @@ namespace RTC
// Update the estimator with a new sample. The deltas should represent deltas // Update the estimator with a new sample. The deltas should represent deltas
// between timestamp groups as defined by the InterArrival class. // between timestamp groups as defined by the InterArrival class.
// |current_hypothesis| should be the hypothesis of the over-use detector at // |currentHypothesis| should be the hypothesis of the over-use detector at
// this time. // this time.
void Update(int64_t tDelta, double tsDelta, int sizeDelta, BandwidthUsage currentHypothesis, int64_t nowMs); void Update(
int64_t tDelta, double tsDelta, int sizeDelta, BandwidthUsage currentHypothesis, int64_t nowMs);
// Returns the estimated noise/jitter variance in ms^2. // Returns the estimated noise/jitter variance in ms^2.
double GetVarNoise() const; double GetVarNoise() const;
// Returns the estimated inter-arrival time delta offset in ms. // Returns the estimated inter-arrival time delta offset in ms.
...@@ -73,14 +74,13 @@ namespace RTC ...@@ -73,14 +74,13 @@ namespace RTC
/* Inline methods. */ /* Inline methods. */
inline inline OverUseDetectorOptions::OverUseDetectorOptions()
OverUseDetectorOptions::OverUseDetectorOptions() : : initialSlope(8.0 / 512.0)
initialSlope(8.0 / 512.0), , initialOffset(0)
initialOffset(0), , initialE()
initialE(), , initialProcessNoise()
initialProcessNoise(), , initialAvgNoise(0.0)
initialAvgNoise(0.0), , initialVarNoise(50)
initialVarNoise(50)
{ {
initialE[0][0] = 100; initialE[0][0] = 100;
initialE[1][1] = 1e-1; initialE[1][1] = 1e-1;
...@@ -89,43 +89,38 @@ namespace RTC ...@@ -89,43 +89,38 @@ namespace RTC
initialProcessNoise[1] = 1e-3; initialProcessNoise[1] = 1e-3;
} }
inline inline OveruseEstimator::OveruseEstimator(const OverUseDetectorOptions& options)
OveruseEstimator::OveruseEstimator(const OverUseDetectorOptions& options) : : options(options)
options(options), , numOfDeltas(0)
numOfDeltas(0), , slope(this->options.initialSlope)
slope(this->options.initialSlope), , offset(this->options.initialOffset)
offset(this->options.initialOffset), , prevOffset(this->options.initialOffset)
prevOffset(this->options.initialOffset), , E()
E(), , processNoise()
processNoise(), , avgNoise(this->options.initialAvgNoise)
avgNoise(this->options.initialAvgNoise), , varNoise(this->options.initialVarNoise)
varNoise(this->options.initialVarNoise), , tsDeltaHist()
tsDeltaHist()
{ {
std::memcpy(this->E, this->options.initialE, sizeof(this->E)); std::memcpy(this->E, this->options.initialE, sizeof(this->E));
std::memcpy(this->processNoise, this->options.initialProcessNoise, sizeof(this->processNoise)); std::memcpy(this->processNoise, this->options.initialProcessNoise, sizeof(this->processNoise));
} }
inline inline OveruseEstimator::~OveruseEstimator()
OveruseEstimator::~OveruseEstimator()
{ {
this->tsDeltaHist.clear(); this->tsDeltaHist.clear();
} }
inline inline double OveruseEstimator::GetVarNoise() const
double OveruseEstimator::GetVarNoise() const
{ {
return this->varNoise; return this->varNoise;
} }
inline inline double OveruseEstimator::GetOffset() const
double OveruseEstimator::GetOffset() const
{ {
return this->offset; return this->offset;
} }
inline inline unsigned int OveruseEstimator::GetNumOfDeltas() const
unsigned int OveruseEstimator::GetNumOfDeltas() const
{ {
return this->numOfDeltas; return this->numOfDeltas;
} }
......
...@@ -19,12 +19,13 @@ namespace RTC ...@@ -19,12 +19,13 @@ namespace RTC
/* 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
...@@ -30,7 +30,7 @@ namespace RTC ...@@ -30,7 +30,7 @@ namespace RTC
public: public:
virtual ~CallStatsObserver() = default; virtual ~CallStatsObserver() = default;
virtual void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) = 0; virtual void OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs) = 0;
}; };
class RemoteBitrateEstimator : public CallStatsObserver class RemoteBitrateEstimator : public CallStatsObserver
...@@ -53,18 +53,22 @@ namespace RTC ...@@ -53,18 +53,22 @@ namespace RTC
// Called for each incoming packet. Updates the incoming payload bitrate // Called for each incoming packet. Updates the incoming payload bitrate
// estimate and the over-use detector. If an over-use is detected the // estimate and the over-use detector. If an over-use is detected the
// remote bitrate estimate will be updated. Note that |payload_size| is the // remote bitrate estimate will be updated. Note that |payloadSize| is the
// packet size excluding headers. // packet size excluding headers.
// Note that |arrival_time_ms| can be of an arbitrary time base. // Note that |arrivalTimeMs| can be of an arbitrary time base.
virtual void IncomingPacket(int64_t arrival_time_ms, size_t payload_size, const RtpPacket& packet, const uint32_t absSendTime) = 0; virtual void IncomingPacket(
int64_t arrivalTimeMs,
size_t payloadSize,
const RtpPacket& packet,
const uint32_t absSendTime) = 0;
// Removes all data for |ssrc|. // Removes all data for |ssrc|.
virtual void RemoveStream(uint32_t ssrc) = 0; virtual void RemoveStream(uint32_t ssrc) = 0;
// Returns true if a valid estimate exists and sets |bitrate_bps| to the // Returns true if a valid estimate exists and sets |bitrateBps| to the
// estimated payload bitrate in bits per second. |ssrcs| is the list of ssrcs // estimated payload bitrate in bits per second. |ssrcs| is the list of ssrcs
// currently being received and of which the bitrate estimate is based upon. // currently being received and of which the bitrate estimate is based upon.
virtual bool LatestEstimate(std::vector<uint32_t>* ssrcs, uint32_t* bitrate_bps) const = 0; virtual bool LatestEstimate(std::vector<uint32_t>* ssrcs, uint32_t* bitrateBps) const = 0;
virtual void SetMinBitrate(int min_bitrate_bps) = 0; virtual void SetMinBitrate(int minBitrateBps) = 0;
// (jmillan) borrowed from webrtc/modules/include/module.h. // (jmillan) borrowed from webrtc/modules/include/module.h.
// //
// Returns the number of milliseconds until the module wants a worker // Returns the number of milliseconds until the module wants a worker
......
...@@ -12,18 +12,18 @@ ...@@ -12,18 +12,18 @@
#define MS_RTC_REMOTE_BITRATE_ESTIMATOR_ABS_SEND_TIME_HPP #define MS_RTC_REMOTE_BITRATE_ESTIMATOR_ABS_SEND_TIME_HPP
#include "common.hpp" #include "common.hpp"
#include "Logger.hpp"
#include "RTC/RemoteBitrateEstimator/AimdRateControl.hpp" #include "RTC/RemoteBitrateEstimator/AimdRateControl.hpp"
#include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp"
#include "RTC/RemoteBitrateEstimator/InterArrival.hpp" #include "RTC/RemoteBitrateEstimator/InterArrival.hpp"
#include "RTC/RemoteBitrateEstimator/OveruseDetector.hpp" #include "RTC/RemoteBitrateEstimator/OveruseDetector.hpp"
#include "RTC/RemoteBitrateEstimator/OveruseEstimator.hpp" #include "RTC/RemoteBitrateEstimator/OveruseEstimator.hpp"
#include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp"
#include "RTC/RtpDataCounter.hpp" #include "RTC/RtpDataCounter.hpp"
#include "Logger.hpp" #include <cassert>
#include <list> #include <list>
#include <map> #include <map>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <cassert>
namespace RTC namespace RTC
{ {
...@@ -59,7 +59,11 @@ namespace RTC ...@@ -59,7 +59,11 @@ namespace RTC
explicit RemoteBitrateEstimatorAbsSendTime(Listener* observer); explicit RemoteBitrateEstimatorAbsSendTime(Listener* observer);
virtual ~RemoteBitrateEstimatorAbsSendTime() = default; virtual ~RemoteBitrateEstimatorAbsSendTime() = default;
void IncomingPacket(int64_t arrivalTimeMs, size_t payloadSize, const RtpPacket& packet, const uint32_t absSendTime) override; void IncomingPacket(
int64_t arrivalTimeMs,
size_t payloadSize,
const RtpPacket& packet,
const uint32_t absSendTime) override;
// This class relies on Process() being called periodically (at least once // This class relies on Process() being called periodically (at least once
// every other second) for streams to be timed out properly. // every other second) for streams to be timed out properly.
void Process() override; void Process() override;
...@@ -79,7 +83,8 @@ namespace RTC ...@@ -79,7 +83,8 @@ namespace RTC
}; };
private: private:
void IncomingPacketInfo(int64_t arrivalTimeMs, uint32_t sendTime_24bits, size_t payloadSize, uint32_t ssrc); void IncomingPacketInfo(
int64_t arrivalTimeMs, uint32_t sendTime_24bits, size_t payloadSize, uint32_t ssrc);
void ComputeClusters(std::list<Cluster>* clusters) const; void ComputeClusters(std::list<Cluster>* clusters) const;
std::list<Cluster>::const_iterator FindBestProbe(const std::list<Cluster>& clusters) const; std::list<Cluster>::const_iterator FindBestProbe(const std::list<Cluster>& clusters) const;
...@@ -108,64 +113,58 @@ namespace RTC ...@@ -108,64 +113,58 @@ namespace RTC
/* Inline Methods. */ /* Inline Methods. */
inline inline Probe::Probe(int64_t sendTimeMs, int64_t recvTimeMs, size_t payloadSize)
Probe::Probe(int64_t sendTimeMs, int64_t recvTimeMs, size_t payloadSize) : : sendTimeMs(sendTimeMs)
sendTimeMs(sendTimeMs), , recvTimeMs(recvTimeMs)
recvTimeMs(recvTimeMs), , payloadSize(payloadSize)
payloadSize(payloadSize) {
{} }
inline inline int Cluster::GetSendBitrateBps() const
int Cluster::GetSendBitrateBps() const
{ {
assert(sendMeanMs > 0.0f); assert(sendMeanMs > 0.0f);
return meanSize * 8 * 1000 / sendMeanMs; return meanSize * 8 * 1000 / sendMeanMs;
} }
inline inline int Cluster::GetRecvBitrateBps() const
int Cluster::GetRecvBitrateBps() const
{ {
assert(recvMeanMs > 0.0f); assert(recvMeanMs > 0.0f);
return meanSize * 8 * 1000 / recvMeanMs; return meanSize * 8 * 1000 / recvMeanMs;
} }
inline inline RemoteBitrateEstimatorAbsSendTime::RemoteBitrateEstimatorAbsSendTime(Listener* observer)
RemoteBitrateEstimatorAbsSendTime::RemoteBitrateEstimatorAbsSendTime(Listener* observer) : : observer(observer)
observer(observer), , interArrival()
interArrival(), , estimator()
estimator(), , detector()
detector(), , incomingBitrate()
incomingBitrate() {
{} }
inline inline void RemoteBitrateEstimatorAbsSendTime::Process()
void RemoteBitrateEstimatorAbsSendTime::Process() {
{} }
inline inline int64_t RemoteBitrateEstimatorAbsSendTime::TimeUntilNextProcess()
int64_t RemoteBitrateEstimatorAbsSendTime::TimeUntilNextProcess()
{ {
const int64_t kDisabledModuleTime = 1000; const int64_t kDisabledModuleTime = 1000;
return kDisabledModuleTime; return kDisabledModuleTime;
} }
inline inline void RemoteBitrateEstimatorAbsSendTime::OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs)
void RemoteBitrateEstimatorAbsSendTime::OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs)
{ {
(void)maxRttMs; (void)maxRttMs;
this->remoteRate.SetRtt(avgRttMs); this->remoteRate.SetRtt(avgRttMs);
} }
inline inline void RemoteBitrateEstimatorAbsSendTime::RemoveStream(uint32_t ssrc)
void RemoteBitrateEstimatorAbsSendTime::RemoveStream(uint32_t ssrc)
{ {
this->ssrcs.erase(ssrc); this->ssrcs.erase(ssrc);
} }
inline inline void RemoteBitrateEstimatorAbsSendTime::SetMinBitrate(int minBitrateBps)
void RemoteBitrateEstimatorAbsSendTime::SetMinBitrate(int minBitrateBps)
{ {
this->remoteRate.SetMinBitrate(minBitrateBps); this->remoteRate.SetMinBitrate(minBitrateBps);
} }
......
...@@ -13,19 +13,18 @@ ...@@ -13,19 +13,18 @@
#include "common.hpp" #include "common.hpp"
#include "RTC/RemoteBitrateEstimator/AimdRateControl.hpp" #include "RTC/RemoteBitrateEstimator/AimdRateControl.hpp"
#include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp"
#include "RTC/RemoteBitrateEstimator/OveruseEstimator.hpp"
#include "RTC/RemoteBitrateEstimator/InterArrival.hpp" #include "RTC/RemoteBitrateEstimator/InterArrival.hpp"
#include "RTC/RemoteBitrateEstimator/OveruseEstimator.hpp"
#include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimator.hpp"
#include "RTC/RtpDataCounter.hpp" #include "RTC/RtpDataCounter.hpp"
#include <cassert>
#include <map> #include <map>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <cassert>
namespace RTC namespace RTC
{ {
class RemoteBitrateEstimatorSingleStream : class RemoteBitrateEstimatorSingleStream : public RemoteBitrateEstimator
public RemoteBitrateEstimator
{ {
private: private:
static constexpr double kTimestampToMs = 1.0 / 90.0; static constexpr double kTimestampToMs = 1.0 / 90.0;
...@@ -34,7 +33,11 @@ namespace RTC ...@@ -34,7 +33,11 @@ namespace RTC
explicit RemoteBitrateEstimatorSingleStream(Listener* observer); explicit RemoteBitrateEstimatorSingleStream(Listener* observer);
virtual ~RemoteBitrateEstimatorSingleStream(); virtual ~RemoteBitrateEstimatorSingleStream();
void IncomingPacket(int64_t arrivalTimeMs, size_t payloadSize, const RtpPacket& packet, const uint32_t transmissionTimeOffset) override; void IncomingPacket(
int64_t arrivalTimeMs,
size_t payloadSize,
const RtpPacket& packet,
const uint32_t transmissionTimeOffset) override;
void Process() override; void Process() override;
int64_t TimeUntilNextProcess() override; int64_t TimeUntilNextProcess() override;
void OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs) override; void OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs) override;
...@@ -49,7 +52,8 @@ namespace RTC ...@@ -49,7 +52,8 @@ namespace RTC
{ {
kTimestampGroupLengthMs = 5 kTimestampGroupLengthMs = 5
}; };
explicit Detector(int64_t lastPacketTimeMs, const OverUseDetectorOptions& options, bool enableBurstGrouping); explicit Detector(
int64_t lastPacketTimeMs, const OverUseDetectorOptions& options, bool enableBurstGrouping);
int64_t lastPacketTimeMs; int64_t lastPacketTimeMs;
InterArrival interArrival; InterArrival interArrival;
...@@ -82,24 +86,25 @@ namespace RTC ...@@ -82,24 +86,25 @@ namespace RTC
/* Inline Methods. */ /* Inline Methods. */
inline inline RemoteBitrateEstimatorSingleStream::Detector::Detector(
RemoteBitrateEstimatorSingleStream::Detector::Detector(int64_t lastPacketTimeMs, const OverUseDetectorOptions& options, bool enableBurstGrouping) : int64_t lastPacketTimeMs, const OverUseDetectorOptions& options, bool enableBurstGrouping)
lastPacketTimeMs(lastPacketTimeMs), : lastPacketTimeMs(lastPacketTimeMs)
interArrival(90 * kTimestampGroupLengthMs, kTimestampToMs, enableBurstGrouping), , interArrival(90 * kTimestampGroupLengthMs, kTimestampToMs, enableBurstGrouping)
estimator(options), , estimator(options)
detector() , detector()
{} {
}
inline
RemoteBitrateEstimatorSingleStream::RemoteBitrateEstimatorSingleStream(Listener* observer) : inline RemoteBitrateEstimatorSingleStream::RemoteBitrateEstimatorSingleStream(Listener* observer)
incomingBitrate(), : incomingBitrate()
remoteRate(new AimdRateControl()), observer(observer), processIntervalMs(kProcessIntervalMs) , remoteRate(new AimdRateControl())
, observer(observer)
, processIntervalMs(kProcessIntervalMs)
{ {
// assert(this->observer); // assert(this->observer);
} }
inline inline RemoteBitrateEstimatorSingleStream::~RemoteBitrateEstimatorSingleStream()
RemoteBitrateEstimatorSingleStream::~RemoteBitrateEstimatorSingleStream()
{ {
while (!this->overuseDetectors.empty()) while (!this->overuseDetectors.empty())
{ {
...@@ -109,22 +114,19 @@ namespace RTC ...@@ -109,22 +114,19 @@ namespace RTC
} }
} }
inline inline void RemoteBitrateEstimatorSingleStream::Process()
void RemoteBitrateEstimatorSingleStream::Process()
{ {
UpdateEstimate(DepLibUV::GetTime()); UpdateEstimate(DepLibUV::GetTime());
this->lastProcessTime = DepLibUV::GetTime(); this->lastProcessTime = DepLibUV::GetTime();
} }
inline inline void RemoteBitrateEstimatorSingleStream::OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs)
void RemoteBitrateEstimatorSingleStream::OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs)
{ {
(void)maxRttMs; (void)maxRttMs;
GetRemoteRate()->SetRtt(avgRttMs); GetRemoteRate()->SetRtt(avgRttMs);
} }
inline inline void RemoteBitrateEstimatorSingleStream::RemoveStream(unsigned int ssrc)
void RemoteBitrateEstimatorSingleStream::RemoveStream(unsigned int ssrc)
{ {
SsrcOveruseEstimatorMap::iterator it = this->overuseDetectors.find(ssrc); SsrcOveruseEstimatorMap::iterator it = this->overuseDetectors.find(ssrc);
if (it != this->overuseDetectors.end()) if (it != this->overuseDetectors.end())
...@@ -134,16 +136,14 @@ namespace RTC ...@@ -134,16 +136,14 @@ namespace RTC
} }
} }
inline inline AimdRateControl* RemoteBitrateEstimatorSingleStream::GetRemoteRate()
AimdRateControl* RemoteBitrateEstimatorSingleStream::GetRemoteRate()
{ {
if (!this->remoteRate) if (!this->remoteRate)
this->remoteRate.reset(new AimdRateControl()); this->remoteRate.reset(new AimdRateControl());
return this->remoteRate.get(); return this->remoteRate.get();
} }
inline inline void RemoteBitrateEstimatorSingleStream::SetMinBitrate(int minBitrateBps)
void RemoteBitrateEstimatorSingleStream::SetMinBitrate(int minBitrateBps)
{ {
this->remoteRate->SetMinBitrate(minBitrateBps); this->remoteRate->SetMinBitrate(minBitrateBps);
} }
......
...@@ -2,26 +2,25 @@ ...@@ -2,26 +2,25 @@
#define MS_RTC_ROOM_HPP #define MS_RTC_ROOM_HPP
#include "common.hpp" #include "common.hpp"
#include "RTC/RtpDictionaries.hpp" #include "Channel/Notifier.hpp"
#include "Channel/Request.hpp"
#include "RTC/Peer.hpp" #include "RTC/Peer.hpp"
#include "RTC/RtpReceiver.hpp"
#include "RTC/RtpSender.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/SenderReport.hpp"
#include "RTC/RTCP/Feedback.hpp" #include "RTC/RTCP/Feedback.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/Sdes.hpp" #include "RTC/RTCP/Sdes.hpp"
#include "Channel/Request.hpp" #include "RTC/RTCP/SenderReport.hpp"
#include "Channel/Notifier.hpp" #include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/RtpReceiver.hpp"
#include "RTC/RtpSender.hpp"
#include <json/json.h>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include <json/json.h>
namespace RTC namespace RTC
{ {
class Room : class Room : public RTC::Peer::Listener
public RTC::Peer::Listener
{ {
public: public:
class Listener class Listener
...@@ -58,13 +57,19 @@ namespace RTC ...@@ -58,13 +57,19 @@ namespace RTC
virtual void onPeerClosed(const RTC::Peer* peer) override; virtual void onPeerClosed(const RTC::Peer* peer) override;
virtual void onPeerCapabilities(RTC::Peer* peer, RTC::RtpCapabilities* capabilities) override; virtual void onPeerCapabilities(RTC::Peer* peer, RTC::RtpCapabilities* capabilities) override;
virtual void onPeerRtpReceiverParameters(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver) override; virtual void onPeerRtpReceiverParameters(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver) override;
virtual void onPeerRtpReceiverClosed(const RTC::Peer* peer, const RTC::RtpReceiver* rtpReceiver) override; virtual void onPeerRtpReceiverClosed(
const RTC::Peer* peer, const RTC::RtpReceiver* rtpReceiver) override;
virtual void onPeerRtpSenderClosed(const RTC::Peer* peer, RTC::RtpSender* rtpSender) override; virtual void onPeerRtpSenderClosed(const RTC::Peer* peer, RTC::RtpSender* rtpSender) override;
virtual void onPeerRtpPacket(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) override; virtual void onPeerRtpPacket(
virtual void onPeerRtcpReceiverReport(const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::ReceiverReport* report) override; const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) override;
virtual void onPeerRtcpFeedback(const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackPsPacket* packet) override; virtual void onPeerRtcpReceiverReport(
virtual void onPeerRtcpFeedback(const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackRtpPacket* packet) override; const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::ReceiverReport* report) override;
virtual void onPeerRtcpSenderReport(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RTCP::SenderReport* report) override; virtual void onPeerRtcpFeedback(
const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackPsPacket* packet) override;
virtual void onPeerRtcpFeedback(
const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackRtpPacket* packet) override;
virtual void onPeerRtcpSenderReport(
const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RTCP::SenderReport* report) override;
virtual void onFullFrameRequired(RTC::Peer* peer, RTC::RtpSender* rtpSender) override; virtual void onFullFrameRequired(RTC::Peer* peer, RTC::RtpSender* rtpSender) override;
public: public:
...@@ -84,8 +89,7 @@ namespace RTC ...@@ -84,8 +89,7 @@ namespace RTC
/* Inline static methods. */ /* Inline static methods. */
inline inline const RTC::RtpCapabilities& Room::GetCapabilities() const
const RTC::RtpCapabilities& Room::GetCapabilities() const
{ {
return this->capabilities; return this->capabilities;
} }
......
...@@ -12,12 +12,12 @@ namespace RTC ...@@ -12,12 +12,12 @@ namespace RTC
class RateCalculator class RateCalculator
{ {
public: public:
static constexpr float kBpsScale = 8000.0f; static constexpr float BpsScale = 8000.0f;
static constexpr float kbpsScale = 1000.0f; static constexpr float BpsScale2 = 1000.0f;
static constexpr size_t defaultWindowSize = 1000; static constexpr size_t DefaultWindowSize = 1000;
public: public:
explicit RateCalculator(size_t windowSize = defaultWindowSize, float scale = kBpsScale); explicit RateCalculator(size_t windowSize = DefaultWindowSize, float scale = BpsScale);
void Update(size_t count, uint64_t now); void Update(size_t count, uint64_t now);
uint32_t GetRate(uint64_t now); uint32_t GetRate(uint64_t now);
void Reset(); void Reset();
...@@ -42,9 +42,9 @@ namespace RTC ...@@ -42,9 +42,9 @@ namespace RTC
// Total count in the time window. // Total count in the time window.
size_t totalCount = 0; size_t totalCount = 0;
// Window Size (in milliseconds). // Window Size (in milliseconds).
size_t windowSize = defaultWindowSize; size_t windowSize = DefaultWindowSize;
// Scale in which the rate is represented. // Scale in which the rate is represented.
const float scale = kBpsScale; const float scale = BpsScale;
}; };
class RtpDataCounter class RtpDataCounter
...@@ -63,24 +63,21 @@ namespace RTC ...@@ -63,24 +63,21 @@ namespace RTC
/* Inline instance methods. */ /* Inline instance methods. */
inline inline RateCalculator::RateCalculator(size_t windowSize, float scale)
RateCalculator::RateCalculator(size_t windowSize, float scale) : : windowSize(windowSize)
windowSize(windowSize), , scale(scale)
scale(scale)
{ {
uint64_t now = DepLibUV::GetTime(); uint64_t now = DepLibUV::GetTime();
this->Reset(now); this->Reset(now);
} }
inline inline void RateCalculator::Reset()
void RateCalculator::Reset()
{ {
this->Reset(this->oldestTime); this->Reset(this->oldestTime);
} }
inline inline void RateCalculator::Reset(uint64_t now)
void RateCalculator::Reset(uint64_t now)
{ {
this->buffer.reset(new BufferItem[windowSize]); this->buffer.reset(new BufferItem[windowSize]);
this->totalCount = 0; this->totalCount = 0;
...@@ -88,20 +85,17 @@ namespace RTC ...@@ -88,20 +85,17 @@ namespace RTC
this->oldestTime = now - this->windowSize; this->oldestTime = now - this->windowSize;
} }
inline inline uint32_t RtpDataCounter::GetRate(uint64_t now)
uint32_t RtpDataCounter::GetRate(uint64_t now)
{ {
return this->rate.GetRate(now); return this->rate.GetRate(now);
} }
inline inline size_t RtpDataCounter::GetPacketCount() const
size_t RtpDataCounter::GetPacketCount() const
{ {
return this->packets; return this->packets;
} }
inline inline size_t RtpDataCounter::GetBytes() const
size_t RtpDataCounter::GetBytes() const
{ {
return this->bytes; return this->bytes;
} }
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
#include "common.hpp" #include "common.hpp"
#include "RTC/Parameters.hpp" #include "RTC/Parameters.hpp"
#include <json/json.h>
#include <map>
#include <string> #include <string>
#include <vector>
#include <unordered_map> #include <unordered_map>
#include <map> #include <vector>
#include <json/json.h>
namespace RTC namespace RTC
{ {
...@@ -82,7 +82,7 @@ namespace RTC ...@@ -82,7 +82,7 @@ namespace RTC
static std::map<Subtype, std::string> subtype2String; static std::map<Subtype, std::string> subtype2String;
public: public:
RtpCodecMime() {}; RtpCodecMime(){};
bool operator==(const RtpCodecMime& other) const bool operator==(const RtpCodecMime& other) const
{ {
...@@ -157,7 +157,7 @@ namespace RTC ...@@ -157,7 +157,7 @@ namespace RTC
class RtpCodecParameters class RtpCodecParameters
{ {
public: public:
RtpCodecParameters() {}; RtpCodecParameters(){};
RtpCodecParameters(Json::Value& data, RTC::Scope scope); RtpCodecParameters(Json::Value& data, RTC::Scope scope);
Json::Value toJson() const; Json::Value toJson() const;
...@@ -201,7 +201,7 @@ namespace RTC ...@@ -201,7 +201,7 @@ namespace RTC
class RtpCapabilities class RtpCapabilities
{ {
public: public:
RtpCapabilities() {}; RtpCapabilities(){};
RtpCapabilities(Json::Value& data, RTC::Scope scope); RtpCapabilities(Json::Value& data, RTC::Scope scope);
Json::Value toJson() const; Json::Value toJson() const;
...@@ -220,7 +220,7 @@ namespace RTC ...@@ -220,7 +220,7 @@ namespace RTC
class RtpFecParameters class RtpFecParameters
{ {
public: public:
RtpFecParameters() {}; RtpFecParameters(){};
explicit RtpFecParameters(Json::Value& data); explicit RtpFecParameters(Json::Value& data);
Json::Value toJson() const; Json::Value toJson() const;
...@@ -233,7 +233,7 @@ namespace RTC ...@@ -233,7 +233,7 @@ namespace RTC
class RtpRtxParameters class RtpRtxParameters
{ {
public: public:
RtpRtxParameters() {}; RtpRtxParameters(){};
explicit RtpRtxParameters(Json::Value& data); explicit RtpRtxParameters(Json::Value& data);
Json::Value toJson() const; Json::Value toJson() const;
...@@ -245,7 +245,7 @@ namespace RTC ...@@ -245,7 +245,7 @@ namespace RTC
class RtpEncodingParameters class RtpEncodingParameters
{ {
public: public:
RtpEncodingParameters() {}; RtpEncodingParameters(){};
explicit RtpEncodingParameters(Json::Value& data); explicit RtpEncodingParameters(Json::Value& data);
Json::Value toJson() const; Json::Value toJson() const;
...@@ -284,7 +284,7 @@ namespace RTC ...@@ -284,7 +284,7 @@ namespace RTC
class RtcpParameters class RtcpParameters
{ {
public: public:
RtcpParameters() {}; RtcpParameters(){};
explicit RtcpParameters(Json::Value& data); explicit RtcpParameters(Json::Value& data);
Json::Value toJson() const; Json::Value toJson() const;
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
#define MS_RTC_LISTENER_HPP #define MS_RTC_LISTENER_HPP
#include "common.hpp" #include "common.hpp"
#include "RTC/RtpReceiver.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "RTC/RtpReceiver.hpp"
#include <string> #include <string>
#include <vector>
#include <unordered_map> #include <unordered_map>
#include <vector>
namespace RTC namespace RTC
{ {
...@@ -23,7 +23,11 @@ namespace RTC ...@@ -23,7 +23,11 @@ namespace RTC
RTC::RtpReceiver* GetRtpReceiver(uint32_t ssrc); RTC::RtpReceiver* GetRtpReceiver(uint32_t ssrc);
private: private:
void RollbackRtpReceiver(RTC::RtpReceiver* rtpReceiver, std::vector<uint32_t>& previousSsrcs, std::string& previousMuxId, std::vector<uint8_t>& previousPayloadTypes); void RollbackRtpReceiver(
RTC::RtpReceiver* rtpReceiver,
std::vector<uint32_t>& previousSsrcs,
std::string& previousMuxId,
std::vector<uint8_t>& previousPayloadTypes);
public: public:
// Table of SSRC / RtpReceiver pairs. // Table of SSRC / RtpReceiver pairs.
...@@ -36,8 +40,7 @@ namespace RTC ...@@ -36,8 +40,7 @@ namespace RTC
/* Inline instance methods. */ /* Inline instance methods. */
inline inline bool RtpListener::HasSsrc(uint32_t ssrc, const RTC::RtpReceiver* rtpReceiver) const
bool RtpListener::HasSsrc(uint32_t ssrc, const RTC::RtpReceiver* rtpReceiver) const
{ {
auto it = this->ssrcTable.find(ssrc); auto it = this->ssrcTable.find(ssrc);
...@@ -51,8 +54,7 @@ namespace RTC ...@@ -51,8 +54,7 @@ namespace RTC
} }
} }
inline inline bool RtpListener::HasMuxId(std::string& muxId, const RTC::RtpReceiver* rtpReceiver) const
bool RtpListener::HasMuxId(std::string& muxId, const RTC::RtpReceiver* rtpReceiver) const
{ {
auto it = this->muxIdTable.find(muxId); auto it = this->muxIdTable.find(muxId);
...@@ -66,8 +68,7 @@ namespace RTC ...@@ -66,8 +68,7 @@ namespace RTC
} }
} }
inline inline bool RtpListener::HasPayloadType(uint8_t payloadType, const RTC::RtpReceiver* rtpReceiver) const
bool RtpListener::HasPayloadType(uint8_t payloadType, const RTC::RtpReceiver* rtpReceiver) const
{ {
auto it = this->ptTable.find(payloadType); auto it = this->ptTable.find(payloadType);
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
#define MS_RTC_RTP_PACKET_HPP #define MS_RTC_RTP_PACKET_HPP
#include "common.hpp" #include "common.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "RTC/RtpDictionaries.hpp"
#include <map> #include <map>
namespace RTC namespace RTC
...@@ -14,21 +14,21 @@ namespace RTC ...@@ -14,21 +14,21 @@ namespace RTC
/* Struct for RTP header. */ /* Struct for RTP header. */
struct Header struct Header
{ {
#if defined(MS_LITTLE_ENDIAN) #if defined(MS_LITTLE_ENDIAN)
uint8_t csrcCount:4; uint8_t csrcCount : 4;
uint8_t extension:1; uint8_t extension : 1;
uint8_t padding:1; uint8_t padding : 1;
uint8_t version:2; uint8_t version : 2;
uint8_t payloadType:7; uint8_t payloadType : 7;
uint8_t marker:1; uint8_t marker : 1;
#elif defined(MS_BIG_ENDIAN) #elif defined(MS_BIG_ENDIAN)
uint8_t version:2; uint8_t version : 2;
uint8_t padding:1; uint8_t padding : 1;
uint8_t extension:1; uint8_t extension : 1;
uint8_t csrcCount:4; uint8_t csrcCount : 4;
uint8_t marker:1; uint8_t marker : 1;
uint8_t payloadType:7; uint8_t payloadType : 7;
#endif #endif
uint16_t sequenceNumber; uint16_t sequenceNumber;
uint32_t timestamp; uint32_t timestamp;
uint32_t ssrc; uint32_t ssrc;
...@@ -47,13 +47,13 @@ namespace RTC ...@@ -47,13 +47,13 @@ namespace RTC
/* Struct for One-Byte extension. */ /* Struct for One-Byte extension. */
struct OneByteExtension struct OneByteExtension
{ {
#if defined(MS_LITTLE_ENDIAN) #if defined(MS_LITTLE_ENDIAN)
uint8_t len:4; uint8_t len : 4;
uint8_t id:4; uint8_t id : 4;
#elif defined(MS_BIG_ENDIAN) #elif defined(MS_BIG_ENDIAN)
uint8_t id:4; uint8_t id : 4;
uint8_t len:4; uint8_t len : 4;
#endif #endif
uint8_t value[1]; uint8_t value[1];
}; };
...@@ -61,13 +61,13 @@ namespace RTC ...@@ -61,13 +61,13 @@ namespace RTC
/* Struct for Two-Bytes extension. */ /* Struct for Two-Bytes extension. */
struct TwoBytesExtension struct TwoBytesExtension
{ {
#if defined(MS_LITTLE_ENDIAN) #if defined(MS_LITTLE_ENDIAN)
uint8_t len:8; uint8_t len : 8;
uint8_t id:8; uint8_t id : 8;
#elif defined(MS_BIG_ENDIAN) #elif defined(MS_BIG_ENDIAN)
uint8_t id:8; uint8_t id : 8;
uint8_t len:8; uint8_t len : 8;
#endif #endif
uint8_t value[1]; uint8_t value[1];
}; };
...@@ -76,7 +76,13 @@ namespace RTC ...@@ -76,7 +76,13 @@ namespace RTC
static RtpPacket* Parse(const uint8_t* data, size_t len); static RtpPacket* Parse(const uint8_t* data, size_t len);
public: public:
RtpPacket(Header* header, ExtensionHeader* extensionHeader, const uint8_t* payload, size_t payloadLen, uint8_t payloadPadding, size_t size); RtpPacket(
Header* header,
ExtensionHeader* extensionHeader,
const uint8_t* payload,
size_t payloadLen,
uint8_t payloadPadding,
size_t size);
~RtpPacket(); ~RtpPacket();
void Dump() const; void Dump() const;
...@@ -129,8 +135,7 @@ namespace RTC ...@@ -129,8 +135,7 @@ namespace RTC
/* Inline static methods. */ /* Inline static methods. */
inline inline bool RtpPacket::IsRtp(const uint8_t* data, size_t len)
bool RtpPacket::IsRtp(const uint8_t* data, size_t len)
{ {
// NOTE: RtcpPacket::IsRtcp() must always be called before this method. // NOTE: RtcpPacket::IsRtcp() must always be called before this method.
...@@ -141,104 +146,87 @@ namespace RTC ...@@ -141,104 +146,87 @@ namespace RTC
// 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] > 127 && data[0] < 192) && (data[0] > 127 && data[0] < 192) &&
// RTP Version must be 2. // RTP Version must be 2.
(header->version == 2) (header->version == 2));
);
} }
/* Inline instance methods. */ /* Inline instance methods. */
inline inline const uint8_t* RtpPacket::GetData() const
const uint8_t* RtpPacket::GetData() const
{ {
return (const uint8_t*)this->header; return (const uint8_t*)this->header;
} }
inline inline size_t RtpPacket::GetSize() const
size_t RtpPacket::GetSize() const
{ {
return this->size; return this->size;
} }
inline inline uint8_t RtpPacket::GetPayloadType() const
uint8_t RtpPacket::GetPayloadType() const
{ {
return this->header->payloadType; return this->header->payloadType;
} }
inline inline void RtpPacket::SetPayloadType(uint8_t payloadType)
void RtpPacket::SetPayloadType(uint8_t payloadType)
{ {
this->header->payloadType = payloadType; this->header->payloadType = payloadType;
} }
inline inline bool RtpPacket::HasMarker() const
bool RtpPacket::HasMarker() const
{ {
return this->header->marker; return this->header->marker;
} }
inline inline void RtpPacket::SetMarker(bool marker)
void RtpPacket::SetMarker(bool marker)
{ {
this->header->marker = marker; this->header->marker = marker;
} }
inline inline uint16_t RtpPacket::GetSequenceNumber() const
uint16_t RtpPacket::GetSequenceNumber() const
{ {
return (uint16_t)ntohs(this->header->sequenceNumber); return (uint16_t)ntohs(this->header->sequenceNumber);
} }
inline inline void RtpPacket::SetSequenceNumber(uint16_t seq)
void RtpPacket::SetSequenceNumber(uint16_t seq)
{ {
this->header->sequenceNumber = (uint16_t)htons(seq); this->header->sequenceNumber = (uint16_t)htons(seq);
} }
inline inline uint32_t RtpPacket::GetExtendedSequenceNumber() const
uint32_t RtpPacket::GetExtendedSequenceNumber() const
{ {
return this->seq32; return this->seq32;
} }
inline inline void RtpPacket::SetExtendedSequenceNumber(uint32_t seq32)
void RtpPacket::SetExtendedSequenceNumber(uint32_t seq32)
{ {
this->seq32 = seq32; this->seq32 = seq32;
} }
inline inline uint32_t RtpPacket::GetTimestamp() const
uint32_t RtpPacket::GetTimestamp() const
{ {
return (uint32_t)ntohl(this->header->timestamp); return (uint32_t)ntohl(this->header->timestamp);
} }
inline inline void RtpPacket::SetTimestamp(uint32_t timestamp)
void RtpPacket::SetTimestamp(uint32_t timestamp)
{ {
this->header->timestamp = (uint32_t)htonl(timestamp); this->header->timestamp = (uint32_t)htonl(timestamp);
} }
inline inline uint32_t RtpPacket::GetSsrc() const
uint32_t RtpPacket::GetSsrc() const
{ {
return (uint32_t)ntohl(this->header->ssrc); return (uint32_t)ntohl(this->header->ssrc);
} }
inline inline void RtpPacket::SetSsrc(uint32_t ssrc)
void RtpPacket::SetSsrc(uint32_t ssrc)
{ {
this->header->ssrc = (uint32_t)htonl(ssrc); this->header->ssrc = (uint32_t)htonl(ssrc);
} }
inline inline bool RtpPacket::HasExtensionHeader() const
bool RtpPacket::HasExtensionHeader() const
{ {
return (this->extensionHeader ? true : false); return (this->extensionHeader ? true : false);
} }
inline inline uint16_t RtpPacket::GetExtensionHeaderId() const
uint16_t RtpPacket::GetExtensionHeaderId() const
{ {
if (!this->extensionHeader) if (!this->extensionHeader)
return 0; return 0;
...@@ -246,8 +234,7 @@ namespace RTC ...@@ -246,8 +234,7 @@ namespace RTC
return uint16_t(ntohs(this->extensionHeader->id)); return uint16_t(ntohs(this->extensionHeader->id));
} }
inline inline size_t RtpPacket::GetExtensionHeaderLength() const
size_t RtpPacket::GetExtensionHeaderLength() const
{ {
if (!this->extensionHeader) if (!this->extensionHeader)
return 0; return 0;
...@@ -255,8 +242,7 @@ namespace RTC ...@@ -255,8 +242,7 @@ namespace RTC
return size_t(ntohs(this->extensionHeader->length) * 4); return size_t(ntohs(this->extensionHeader->length) * 4);
} }
inline inline uint8_t* RtpPacket::GetExtensionHeaderValue() const
uint8_t* RtpPacket::GetExtensionHeaderValue() const
{ {
if (!this->extensionHeader) if (!this->extensionHeader)
return nullptr; return nullptr;
...@@ -264,26 +250,22 @@ namespace RTC ...@@ -264,26 +250,22 @@ namespace RTC
return this->extensionHeader->value; return this->extensionHeader->value;
} }
inline inline bool RtpPacket::HasOneByteExtensions() const
bool RtpPacket::HasOneByteExtensions() const
{ {
return GetExtensionHeaderId() == 0xBEDE; return GetExtensionHeaderId() == 0xBEDE;
} }
inline inline bool RtpPacket::HasTwoBytesExtensions() const
bool RtpPacket::HasTwoBytesExtensions() const
{ {
return (GetExtensionHeaderId() & 0b1111111111110000) == 0b0001000000000000; return (GetExtensionHeaderId() & 0b1111111111110000) == 0b0001000000000000;
} }
inline inline void RtpPacket::AddExtensionMapping(RtpHeaderExtensionUri::Type uri, uint8_t id)
void RtpPacket::AddExtensionMapping(RtpHeaderExtensionUri::Type uri, uint8_t id)
{ {
this->extensionMap[uri] = id; this->extensionMap[uri] = id;
} }
inline inline uint8_t* RtpPacket::GetExtension(RtpHeaderExtensionUri::Type uri, uint8_t* len) const
uint8_t* RtpPacket::GetExtension(RtpHeaderExtensionUri::Type uri, uint8_t* len) const
{ {
*len = 0; *len = 0;
...@@ -316,8 +298,7 @@ namespace RTC ...@@ -316,8 +298,7 @@ namespace RTC
} }
} }
inline inline bool RtpPacket::ReadAudioLevel(uint8_t* volume, bool* voice) const
bool RtpPacket::ReadAudioLevel(uint8_t* volume, bool* voice) const
{ {
uint8_t extenLen; uint8_t extenLen;
uint8_t* extenValue; uint8_t* extenValue;
...@@ -334,8 +315,7 @@ namespace RTC ...@@ -334,8 +315,7 @@ namespace RTC
return true; return true;
} }
inline inline bool RtpPacket::ReadAbsSendTime(uint32_t* time) const
bool RtpPacket::ReadAbsSendTime(uint32_t* time) const
{ {
uint8_t extenLen; uint8_t extenLen;
uint8_t* extenValue; uint8_t* extenValue;
...@@ -350,14 +330,12 @@ namespace RTC ...@@ -350,14 +330,12 @@ namespace RTC
return true; return true;
} }
inline inline uint8_t* RtpPacket::GetPayload() const
uint8_t* RtpPacket::GetPayload() const
{ {
return this->payload; return this->payload;
} }
inline inline size_t RtpPacket::GetPayloadLength() const
size_t RtpPacket::GetPayloadLength() const
{ {
return this->payloadLength; return this->payloadLength;
} }
......
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
#define MS_RTC_RTP_RECEIVER_HPP #define MS_RTC_RTP_RECEIVER_HPP
#include "common.hpp" #include "common.hpp"
#include "Channel/Notifier.hpp"
#include "Channel/Request.hpp"
#include "RTC/RTCP/CompoundPacket.hpp"
#include "RTC/RTCP/Feedback.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RtpDictionaries.hpp" #include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "RTC/RtpStreamRecv.hpp" #include "RTC/RtpStreamRecv.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/Feedback.hpp"
#include "RTC/RTCP/CompoundPacket.hpp"
#include "Channel/Request.hpp"
#include "Channel/Notifier.hpp"
#include <string>
#include <map>
#include <json/json.h> #include <json/json.h>
#include <map>
#include <string>
namespace RTC namespace RTC
{ {
...@@ -20,8 +20,7 @@ namespace RTC ...@@ -20,8 +20,7 @@ namespace RTC
// the corresponding header files. // the corresponding header files.
class Transport; class Transport;
class RtpReceiver : class RtpReceiver : public RtpStreamRecv::Listener
public RtpStreamRecv::Listener
{ {
public: public:
/** /**
...@@ -30,17 +29,15 @@ namespace RTC ...@@ -30,17 +29,15 @@ namespace RTC
class Listener class Listener
{ {
public: public:
virtual void onRtpReceiverParameters(RtpReceiver* rtpReceiver) = 0; virtual void onRtpReceiverParameters(RTC::RtpReceiver* rtpReceiver) = 0;
virtual void onRtpReceiverParametersDone(RTC::RtpReceiver* rtpReceiver) = 0; virtual void onRtpReceiverParametersDone(RTC::RtpReceiver* rtpReceiver) = 0;
virtual void onRtpPacket(RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) = 0; virtual void onRtpPacket(RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) = 0;
virtual void onRtpReceiverClosed(const RtpReceiver* rtpReceiver) = 0; virtual void onRtpReceiverClosed(const RTC::RtpReceiver* rtpReceiver) = 0;
}; };
private:
static uint8_t rtcpBuffer[];
public: public:
RtpReceiver(Listener* listener, Channel::Notifier* notifier, uint32_t rtpReceiverId, RTC::Media::Kind kind); RtpReceiver(
Listener* listener, Channel::Notifier* notifier, uint32_t rtpReceiverId, RTC::Media::Kind kind);
private: private:
virtual ~RtpReceiver(); virtual ~RtpReceiver();
...@@ -55,7 +52,7 @@ namespace RTC ...@@ -55,7 +52,7 @@ namespace RTC
RTC::RtpParameters* GetParameters() const; RTC::RtpParameters* GetParameters() const;
void ReceiveRtpPacket(RTC::RtpPacket* packet); void ReceiveRtpPacket(RTC::RtpPacket* packet);
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report); void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void GetRtcp(RTC::RTCP::CompoundPacket *packet, uint64_t now); void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
void ReceiveRtcpFeedback(RTC::RTCP::FeedbackPsPacket* packet) const; void ReceiveRtcpFeedback(RTC::RTCP::FeedbackPsPacket* packet) const;
void ReceiveRtcpFeedback(RTC::RTCP::FeedbackRtpPacket* packet) const; void ReceiveRtcpFeedback(RTC::RTCP::FeedbackRtpPacket* packet) const;
void RequestFullFrame() const; void RequestFullFrame() const;
...@@ -66,7 +63,8 @@ namespace RTC ...@@ -66,7 +63,8 @@ namespace RTC
/* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */ /* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */
public: public:
virtual void onNackRequired(RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) override; virtual void onNackRequired(
RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) override;
virtual void onPliRequired(RTC::RtpStreamRecv* rtpStream) override; virtual void onPliRequired(RTC::RtpStreamRecv* rtpStream) override;
public: public:
...@@ -92,36 +90,30 @@ namespace RTC ...@@ -92,36 +90,30 @@ namespace RTC
/* Inline methods. */ /* Inline methods. */
inline inline void RtpReceiver::SetTransport(RTC::Transport* transport)
void RtpReceiver::SetTransport(RTC::Transport* transport)
{ {
this->transport = transport; this->transport = transport;
} }
inline inline RTC::Transport* RtpReceiver::GetTransport() const
RTC::Transport* RtpReceiver::GetTransport() const
{ {
return this->transport; return this->transport;
} }
inline inline void RtpReceiver::RemoveTransport(RTC::Transport* transport)
void RtpReceiver::RemoveTransport(RTC::Transport* transport)
{ {
if (this->transport == transport) if (this->transport == transport)
this->transport = nullptr; this->transport = nullptr;
} }
inline inline RTC::RtpParameters* RtpReceiver::GetParameters() const
RTC::RtpParameters* RtpReceiver::GetParameters() const
{ {
return this->rtpParameters; return this->rtpParameters;
} }
inline inline void RtpReceiver::ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report)
void RtpReceiver::ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report)
{ {
auto it = this->rtpStreams.find(report->GetSsrc()); auto it = this->rtpStreams.find(report->GetSsrc());
if (it != this->rtpStreams.end()) if (it != this->rtpStreams.end())
{ {
auto rtpStream = it->second; auto rtpStream = it->second;
......
...@@ -2,19 +2,19 @@ ...@@ -2,19 +2,19 @@
#define MS_RTC_RTP_SENDER_HPP #define MS_RTC_RTP_SENDER_HPP
#include "common.hpp" #include "common.hpp"
#include "RTC/Transport.hpp" #include "Channel/Notifier.hpp"
#include "RTC/RtpStreamSend.hpp" #include "Channel/Request.hpp"
#include "RTC/RTCP/CompoundPacket.hpp"
#include "RTC/RTCP/FeedbackRtpNack.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/Sdes.hpp"
#include "RTC/RtpDataCounter.hpp"
#include "RTC/RtpDictionaries.hpp" #include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "RTC/RtpDataCounter.hpp" #include "RTC/RtpStreamSend.hpp"
#include "RTC/RTCP/Sdes.hpp" #include "RTC/Transport.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/FeedbackRtpNack.hpp"
#include "RTC/RTCP/CompoundPacket.hpp"
#include "Channel/Request.hpp"
#include "Channel/Notifier.hpp"
#include <unordered_set>
#include <json/json.h> #include <json/json.h>
#include <unordered_set>
namespace RTC namespace RTC
{ {
...@@ -31,7 +31,8 @@ namespace RTC ...@@ -31,7 +31,8 @@ namespace RTC
}; };
public: public:
RtpSender(Listener* listener, Channel::Notifier* notifier, uint32_t rtpSenderId, RTC::Media::Kind kind); RtpSender(
Listener* listener, Channel::Notifier* notifier, uint32_t rtpSenderId, RTC::Media::Kind kind);
private: private:
virtual ~RtpSender(); virtual ~RtpSender();
...@@ -48,7 +49,7 @@ namespace RTC ...@@ -48,7 +49,7 @@ namespace RTC
RTC::RtpParameters* GetParameters() const; RTC::RtpParameters* GetParameters() const;
bool GetActive() const; bool GetActive() const;
void SendRtpPacket(RTC::RtpPacket* packet); void SendRtpPacket(RTC::RtpPacket* packet);
void GetRtcp(RTC::RTCP::CompoundPacket *packet, uint64_t now); void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket); void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket);
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report); void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
uint32_t GetTransmissionRate(uint64_t now); uint32_t GetTransmissionRate(uint64_t now);
...@@ -89,8 +90,7 @@ namespace RTC ...@@ -89,8 +90,7 @@ namespace RTC
/* Inline methods. */ /* Inline methods. */
inline inline void RtpSender::SetTransport(RTC::Transport* transport)
void RtpSender::SetTransport(RTC::Transport* transport)
{ {
bool wasActive = this->GetActive(); bool wasActive = this->GetActive();
...@@ -100,14 +100,12 @@ namespace RTC ...@@ -100,14 +100,12 @@ namespace RTC
EmitActiveChange(); EmitActiveChange();
} }
inline inline RTC::Transport* RtpSender::GetTransport() const
RTC::Transport* RtpSender::GetTransport() const
{ {
return this->transport; return this->transport;
} }
inline inline void RtpSender::RemoveTransport(RTC::Transport* transport)
void RtpSender::RemoveTransport(RTC::Transport* transport)
{ {
bool wasActive = this->GetActive(); bool wasActive = this->GetActive();
...@@ -118,20 +116,17 @@ namespace RTC ...@@ -118,20 +116,17 @@ namespace RTC
EmitActiveChange(); EmitActiveChange();
} }
inline inline RTC::RtpParameters* RtpSender::GetParameters() const
RTC::RtpParameters* RtpSender::GetParameters() const
{ {
return this->rtpParameters; return this->rtpParameters;
} }
inline inline bool RtpSender::GetActive() const
bool RtpSender::GetActive() const
{ {
return (this->available && this->transport && !this->disabled); return (this->available && this->transport && !this->disabled);
} }
inline inline uint32_t RtpSender::GetTransmissionRate(uint64_t now)
uint32_t RtpSender::GetTransmissionRate(uint64_t now)
{ {
return this->transmittedCounter.GetRate(now); return this->transmittedCounter.GetRate(now);
} }
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
#define MS_RTC_RTP_STREAM_HPP #define MS_RTC_RTP_STREAM_HPP
#include "common.hpp" #include "common.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/RtpDictionaries.hpp" #include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
#include <json/json.h> #include <json/json.h>
namespace RTC namespace RTC
...@@ -60,8 +60,7 @@ namespace RTC ...@@ -60,8 +60,7 @@ namespace RTC
/* Inline instance methods. */ /* Inline instance methods. */
inline inline uint32_t RtpStream::GetSsrc()
uint32_t RtpStream::GetSsrc()
{ {
return this->params.ssrc; return this->params.ssrc;
} }
......
#ifndef MS_RTC_RTP_STREAM_RECV_HPP #ifndef MS_RTC_RTP_STREAM_RECV_HPP
#define MS_RTC_RTP_STREAM_RECV_HPP #define MS_RTC_RTP_STREAM_RECV_HPP
#include "RTC/RtpStream.hpp" #include "RTC/NackGenerator.hpp"
#include "RTC/RTCP/ReceiverReport.hpp" #include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/SenderReport.hpp" #include "RTC/RTCP/SenderReport.hpp"
#include "RTC/NackGenerator.hpp" #include "RTC/RtpStream.hpp"
namespace RTC namespace RTC
{ {
class RtpStreamRecv : class RtpStreamRecv : public RtpStream, public RTC::NackGenerator::Listener
public RtpStream,
public RTC::NackGenerator::Listener
{ {
public: public:
class Listener class Listener
{ {
public: public:
virtual void onNackRequired(RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) = 0; virtual void onNackRequired(
RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) = 0;
virtual void onPliRequired(RTC::RtpStreamRecv* rtpStream) = 0; virtual void onPliRequired(RTC::RtpStreamRecv* rtpStream) = 0;
}; };
...@@ -46,8 +45,10 @@ namespace RTC ...@@ -46,8 +45,10 @@ namespace RTC
// Passed by argument. // Passed by argument.
Listener* listener = nullptr; Listener* listener = nullptr;
// Others. // Others.
uint32_t lastSrTimestamp = 0; // The middle 32 bits out of 64 in the NTP timestamp received in the most recent sender report. uint32_t lastSrTimestamp = 0; // The middle 32 bits out of 64 in the NTP timestamp received in
uint64_t lastSrReceived = 0; // Wallclock time representing the most recent sender report arrival. // the most recent sender report.
uint64_t lastSrReceived =
0; // Wallclock time representing the most recent sender report arrival.
uint32_t transit = 0; // Relative trans time for prev pkt. uint32_t transit = 0; // Relative trans time for prev pkt.
uint32_t jitter = 0; // Estimated jitter. uint32_t jitter = 0; // Estimated jitter.
std::unique_ptr<RTC::NackGenerator> nackGenerator; std::unique_ptr<RTC::NackGenerator> nackGenerator;
......
#ifndef MS_RTC_RTP_STREAM_SEND_HPP #ifndef MS_RTC_RTP_STREAM_SEND_HPP
#define MS_RTC_RTP_STREAM_SEND_HPP #define MS_RTC_RTP_STREAM_SEND_HPP
#include "RTC/RtpStream.hpp"
#include "RTC/RTCP/SenderReport.hpp"
#include "RTC/RTCP/ReceiverReport.hpp" #include "RTC/RTCP/ReceiverReport.hpp"
#include <vector> #include "RTC/RTCP/SenderReport.hpp"
#include "RTC/RtpStream.hpp"
#include <list> #include <list>
#include <vector>
namespace RTC namespace RTC
{ {
class RtpStreamSend : class RtpStreamSend : public RtpStream
public RtpStream
{ {
private: private:
struct StorageItem struct StorageItem
...@@ -33,7 +32,8 @@ namespace RTC ...@@ -33,7 +32,8 @@ namespace RTC
virtual Json::Value toJson() const override; virtual Json::Value toJson() const override;
bool ReceivePacket(RTC::RtpPacket* packet) override; bool ReceivePacket(RTC::RtpPacket* packet) override;
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report); void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
void RequestRtpRetransmission(uint16_t seq, uint16_t bitmask, std::vector<RTC::RtpPacket*>& container); void RequestRtpRetransmission(
uint16_t seq, uint16_t bitmask, std::vector<RTC::RtpPacket*>& container);
RTC::RTCP::SenderReport* GetRtcpSenderReport(uint64_t now); RTC::RTCP::SenderReport* GetRtcpSenderReport(uint64_t now);
uint32_t GetRtt() const; uint32_t GetRtt() const;
...@@ -57,8 +57,7 @@ namespace RTC ...@@ -57,8 +57,7 @@ namespace RTC
uint32_t rtt = 0; // Round trip time. uint32_t rtt = 0; // Round trip time.
}; };
inline inline uint32_t RtpStreamSend::GetRtt() const
uint32_t RtpStreamSend::GetRtt() const
{ {
return this->rtt; return this->rtt;
} }
......
...@@ -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 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论