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