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