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

Apply clang-tidy (#107)

* C++ tidy: terminate namespaces with a closing comment
* C++ tidy: do not use C-style cast to convert between unrelated types
* C++ tidy: do not convert integer literal to bool, use bool literal instead
* C++ tidy: do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead
* C++ tidy: more camelCase
* clang-tidy config file
* C++ tidy: readability-identifier-naming
* C++ tidy: modernize-use-default
* C++ tidy: modernize-use-auto
* C++ tidy: performance-*
* C++ tidy: misc-unused-parameters
* C++ tidy: modernize-use-auto
* C++ tidy: modernize-loop-convert
* C++ tidy: modernize-use-bool-literals
* C++ tidy: modernize-use-emplace
* C++ tidy: modernize-use-nullptr
* C++ tidy: modernize-deprecated-headers
* C++ tidy: modernize-pass-by-value
* C++ tidy: cppcoreguidelines-pro-type-static-cast-downcast
* C++ tidy: readability-inconsistent-declaration-parameter-name
* C++ tidy: readability-container-size-empty
* C++ tidy: modernize-use-default
* C++ tidy: modernize-use-override
* C++ tidy: modernize-loop-convert
* C++ tidy: modernize-use-auto
* C++ tidy: modernize-pass-by-value
* C++ tidy: performance-for-range-copy
* C++ tidy: readability-avoid-const-params-in-decls
* C++ tidy: modernize-use-using
* C++ tidy: remove unnecesary 'typedef'
* C++ tidy: misc-definitions-in-headers
* C++ tidy: Gulp task
* C++ tidy: Add compile_commands.json file
* C++ tidy: Update .clang-tidy
* C++ tidy: Add run-clang-tidy.py
* Rename compile_commands.json to compile_commands_template.json
* clang-tidy: fix path in gulpfile.js
* C++ tidy: Use clang-tools-prebuilt npm
* Rename kXxxx Google constants to CamelCase
* Put consistent names in worker/scripts/*
* C++ tidy: Update .clang-tidy
* C++ tidy: rename 'k_' and 'v_' by JsonString
* C++: replace ugly enum with static constexpr
* Rename "gulp tidy:worker" to "gulp tidy"
* Include "gulp lint" in .travis.yml
* BUILDING: document "gulp tidy"
* Add 'readability-identifier-naming' check to .clang-format
* C++ tidy: readability-identifier-naming
* Apply format rules defined in .clang-format file
* Add '-header-filter' option to clang-tidy
* C++ tidy: readability-delete-null-pointer
* C++ tidy: readability-else-after-return
* Remove IP.cpp from compile commands database
* C++ tidy: readability-else-implicit-bool-cast
* C++ tidy: readability-*
* Enable all readabiliy checks
* C++ tidy: modernize-use-auto
* C++ tidy: modernize-*
* Add '-header-filter' option to clang-tidy
* Override IP.cpp with the version produced by Ragel.
* C++ tidy: misc-string-compare
* Travis-CI: Add `gulp tidy`
* clang-tidy: make clang-analyzer-core.uninitialized.Assign happy
* clang-tidy: `gulp tidy` just works on OSX (for now).
* Activate all the checks with some explicit exceptions
* Move clang-tools-prebuilt to optionalDependencies.
* Improve BUILDING.md.
* Exclude 'cert-*' and 'clang-analyzer-optin.osx.*' checks
* Use clang-tools-prebuilt 0.1.4 and add `gulp tidy` to Travis.
* C++ tidy: google-readability-casting
* Update deps so `gulp tidy` works on Node 4.
* clang-tidy: ignore some OpenSSL stuff
* Use static_cast everywhere.
* clang-tidy: make misc-incorrect-roundings rule (and some others) happy
* clang-tidy: really get rid of misc-incorrect-roundings
* clang-tidy: apply cppcoreguidelines-pro-type-cstyle-cast check
* C++ tidy: cppcoreguidelines-pro-type-member-init
* clang-tidy: enable cppcoreguidelines-pro-type-member-init (use {} for member/variable initialization)
* Use brace initialization to convert arithmetic types
* clang-format: initialize with { foo }
* worker .cpp files: Use { foo } initializers
* clang-tidy: use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto]
上级 1b467b58
/node_modules/
# clang-tidy stuff
/worker/compile_commands.json
# gyp generated stuff
/worker/out/
/worker/**/*.xcodeproj/
......
......@@ -69,6 +69,8 @@ before_script:
- npm install -g gulp-cli
script:
- gulp lint
- gulp tidy
- gulp test
notifications:
......
......@@ -66,29 +66,43 @@ $ npm install -g gulp-cli
The default task runs the `gulp:lint` and `gulp:test` tasks.
### `gulp rtpcapabilities`
Reads **mediasoup** [supported RTP capabilities](https://github.com/versatica/mediasoup/blob/master/lib/supportedRtpCapabilities.js) and inserts them into the worker C++ code. After that, `make Release` and/or `make Debug` must be called.
### `gulp lint`
Runs both the `lint:node` and `lint:worker` gulp tasks.
### `gulp lint:node`
Validates the Node.js JavaScript code/syntax.
### `gulp lint:worker`
Validates the worker C++ code/syntax against the `worker/.clang-format` rules.
Validates the worker C++ code/syntax using [clang-format](https://clang.llvm.org/docs/ClangFormat.html) following `worker/.clang-format` rules.
### `gulp lint`
### `gulp format`
Runs both the `lint:node` and `lint:worker` gulp tasks.
Runs the `format:worker` gulp task.
### `gulp format:worker`
Rewrites all the worker source files and include files in order to satisfy the rules at `worker/.clang-format`.
Rewrites worker source and include files using [clang-format](https://clang.llvm.org/docs/ClangFormat.html).
### `gulp format`
### `gulp tidy`
Runs the `format:worker` gulp task.
Runs the `tidy:worker` gulp task.
### `gulp rtpcapabilities`
### `gulp tidy:worker`
Reads **mediasoup** [supported RTP capabilities](https://github.com/versatica/mediasoup/blob/master/lib/supportedRtpCapabilities.js) and inserts them into the worker C++ code. After that, `make Release` and/or `make Debug` must be called.
Performs C++ code check using [clang-tidy](http://clang.llvm.org/extra/clang-tidy/) following following `worker/.clang-tidy` rules.
*NOTE:* It just works on Linux and OSX.
### `gulp test`
Runs both the `test:node` and `test:worker` gulp tasks.
### `gulp test:node`
......@@ -109,7 +123,3 @@ In order to run the worker test units with the mediasoup worker in `Debug` mode
```bash
$ MEDIASOUP_BUILDTYPE=Debug gulp test:worker
```
### `gulp test`
Runs both the `test:node` and `test:worker` gulp tasks.
......@@ -3,11 +3,13 @@
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const replace = require('gulp-replace');
const rename = require('gulp-rename');
const touch = require('gulp-touch-cmd');
const shell = require('gulp-shell');
const clangFormat = require('gulp-clang-format');
const os = require('os');
let nodeFiles =
const nodeFiles =
[
'.eslintrc.js',
'gulpfile.js',
......@@ -28,9 +30,25 @@ const nodeTests =
'test/test-Transport.js',
'test/test-RtpReceiver.js',
'test/test-extra.js'
// NOTE: Disable this test until adapted.
// 'test/test-scene-1.js'
];
const workerCompilationDatabaseTemplate = 'worker/compile_commands_template.json';
const workerHeaderFilterRegex =
'(common.hpp|DepLibSRTP.hpp|DepLibUV.hpp|DepOpenSSL.hpp|LogLevel.hpp|Logger.hpp' +
'|Loop.hpp|MediaSoupError.hpp|Settings.hpp|Utils.hpp' +
'|handles/*.hpp|Channel/*.hpp|RTC/**/*.hpp)';
const numCpus = os.cpus().length;
gulp.task('rtpcapabilities', () =>
{
let supportedRtpCapabilities = require('./lib/supportedRtpCapabilities');
return gulp.src('worker/src/RTC/Room.cpp')
// Let's generate valid syntax as expected by clang-format rules.
.pipe(replace(/(const std::string supportedRtpCapabilities =).*\r?\n.*/,
`$1\n\t\t\t R"(${JSON.stringify(supportedRtpCapabilities)})";`))
.pipe(gulp.dest('worker/src/RTC/'))
.pipe(touch());
});
gulp.task('lint:node', () =>
{
......@@ -63,6 +81,35 @@ gulp.task('format:worker', () =>
.pipe(gulp.dest('.'));
});
gulp.task('tidy:worker:prepare', () =>
{
return gulp.src(workerCompilationDatabaseTemplate)
.pipe(replace(/PATH/gm, __dirname))
.pipe(rename('compile_commands.json'))
.pipe(gulp.dest('worker'))
.pipe(touch());
});
gulp.task('tidy:worker:run', shell.task(
[
'cd worker && ' +
'./scripts/clang-tidy.py ' +
'-clang-tidy-binary=../node_modules/.bin/clang-tidy ' +
'-clang-apply-replacements-binary=../node_modules/.bin/clang-apply-replacements ' +
`-header-filter='${workerHeaderFilterRegex}' ` +
'-p=. ' +
`-j=${numCpus} ` +
`-checks=${process.env.MEDIASOUP_TIDY_CHECKS || ''} ` +
'-quiet ' +
`${process.env.MEDIASOUP_TIDY_FIX === '1' ? '-fix -format' : ''}`
],
{
verbose : true
}
));
gulp.task('tidy:worker', gulp.series('tidy:worker:prepare', 'tidy:worker:run'));
gulp.task('test:node', shell.task(
[
'if type make &> /dev/null; then make; fi',
......@@ -86,22 +133,12 @@ gulp.task('test:worker', shell.task(
}
));
gulp.task('rtpcapabilities', () =>
{
let supportedRtpCapabilities = require('./lib/supportedRtpCapabilities');
return gulp.src('worker/src/RTC/Room.cpp')
// Let's generate valid syntax as expected by clang-format rules.
.pipe(replace(/(const std::string supportedRtpCapabilities =).*\r?\n.*/,
`$1\n\t\t\t R"(${JSON.stringify(supportedRtpCapabilities)})";`))
.pipe(gulp.dest('worker/src/RTC/'))
.pipe(touch());
});
gulp.task('lint', gulp.series('lint:node', 'lint:worker'));
gulp.task('format', gulp.series('format:worker'));
gulp.task('tidy', gulp.series('tidy:worker'));
gulp.task('test', gulp.series('test:node', 'test:worker'));
gulp.task('default', gulp.series('lint', 'test'));
......@@ -39,14 +39,18 @@
"sdp-transform": "^2.3.0"
},
"devDependencies": {
"gulp": "git://github.com/gulpjs/gulp.git#4.0",
"gulp": "gulpjs/gulp.git#4.0",
"gulp-clang-format": "^1.0.23",
"gulp-eslint": "^3.0.1",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
"gulp-shell": "^0.6.3",
"gulp-touch-cmd": "0.0.1",
"tap": "^10.3.2"
},
"optionalDependencies": {
"clang-tools-prebuilt": "^0.1.4"
},
"scripts": {
"test": "gulp test",
"postinstall": "make Release"
......
......@@ -21,7 +21,7 @@ function initTest(t)
})
.then(() =>
{
return { peer: peer };
return { peer };
});
}
......
......@@ -26,7 +26,7 @@ function initTest(t)
})
.then((transport) =>
{
return { peer: peer, transport: transport };
return { peer, transport };
});
}
......
......@@ -20,7 +20,7 @@ function initTest(t)
})
.then((transport) =>
{
return { peer: peer, transport: transport };
return { peer, transport };
});
}
......@@ -200,3 +200,50 @@ tap.test('transport.close() must succeed', { timeout: 2000 }, (t) =>
.catch((error) => t.fail(`peer.createTransport() failed: ${error}`));
});
});
tap.test('create transport in a server with rtcAnnouncedIPv4', { timeout: 2000 }, (t) =>
{
let server = mediasoup.Server(
{
rtcIPv4 : true,
rtcIPv6 : false,
rtcAnnouncedIPv4 : 'test.foo.com'
});
let peer;
t.tearDown(() => server.close());
return server.createRoom(roomOptions)
.then((room) =>
{
peer = room.Peer('alice');
})
.then(() =>
{
return peer.createTransport({ tcp: false });
})
.then((transport) =>
{
let candidates = transport.iceLocalCandidates;
let candidate = candidates[0];
t.equal(candidates.length, 1, 'transport has 1 ICE local candidate');
t.equal(candidate.protocol, 'udp', 'candidate.protocol must be udp');
t.equal(candidate.family, 'ipv4', 'candidate.family must be ipv4');
t.equal(candidate.ip, 'test.foo.com', 'candidate.ip must be test.foo.com');
})
.then(() =>
{
return peer.createTransport({ udp: false });
})
.then((transport) =>
{
let candidates = transport.iceLocalCandidates;
let candidate = candidates[0];
t.equal(candidates.length, 1, 'transport has 1 ICE local candidate');
t.equal(candidate.protocol, 'tcp', 'candidate.protocol must be tcp');
t.equal(candidate.family, 'ipv4', 'candidate.family must be ipv4');
t.equal(candidate.ip, 'test.foo.com', 'candidate.ip must be test.foo.com');
});
});
......@@ -33,11 +33,13 @@ BreakBeforeBinaryOperators: None
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakStringLiterals: true
BreakStringLiterals: false
ColumnLimit: 100
CommentPragmas: 'NOLINT'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: true
......
差异被折叠。
差异被折叠。
......@@ -13,19 +13,19 @@ namespace Channel
public:
explicit Notifier(Channel::UnixStreamSocket* channel);
void Emit(uint32_t targetId, std::string event);
void Emit(uint32_t targetId, std::string event, Json::Value& data);
void Emit(uint32_t targetId, const std::string& event);
void Emit(uint32_t targetId, const std::string& event, Json::Value& data);
void EmitWithBinary(
uint32_t targetId,
std::string event,
const std::string& event,
Json::Value& data,
const uint8_t* binaryData,
size_t binaryLen);
public:
// Passed by argument.
Channel::UnixStreamSocket* channel = nullptr;
Channel::UnixStreamSocket* channel{ nullptr };
};
}
} // namespace Channel
#endif
......@@ -17,31 +17,31 @@ namespace Channel
public:
enum class MethodId
{
worker_dump = 1,
worker_updateSettings,
worker_createRoom,
room_close,
room_dump,
room_createPeer,
peer_close,
peer_dump,
peer_setCapabilities,
peer_createTransport,
peer_createRtpReceiver,
transport_close,
transport_dump,
transport_setRemoteDtlsParameters,
transport_setMaxBitrate,
transport_changeUfragPwd,
rtpReceiver_close,
rtpReceiver_dump,
rtpReceiver_receive,
rtpReceiver_setTransport,
rtpReceiver_setRtpRawEvent,
rtpReceiver_setRtpObjectEvent,
rtpSender_dump,
rtpSender_setTransport,
rtpSender_disable
WORKER_DUMP = 1,
WORKER_UPDATE_SETTINGS,
WORKER_CREATE_ROOM,
ROOM_CLOSE,
ROOM_DUMP,
ROOM_CREATE_PEER,
PEER_CLOSE,
PEER_DUMP,
PEER_SET_CAPABILITIES,
PEER_CREATE_TRANSPORT,
PEER_CREATE_RTP_RECEIVER,
TRANSPORT_CLOSE,
TRANSPORT_DUMP,
TRANSPORT_SET_REMOTE_DTLS_PARAMETERS,
TRANSPORT_SET_MAX_BITRATE,
TRANSPORT_CHANGE_UFRAG_PWD,
RTP_RECEIVER_CLOSE,
RTP_RECEIVER_DUMP,
RTP_RECEIVER_RECEIVE,
RTP_RECEIVER_SET_TRANSPORT,
RTP_RECEIVER_SET_RTP_RAW_EVENT,
RTP_RECEIVER_SET_RTP_OBJECT_EVENT,
RTP_SENDER_DUMP,
RTP_SENDER_SET_TRANSPORT,
RTP_SENDER_DISABLE
};
private:
......@@ -58,15 +58,15 @@ namespace Channel
public:
// Passed by argument.
Channel::UnixStreamSocket* channel = nullptr;
uint32_t id;
Channel::UnixStreamSocket* channel{ nullptr };
uint32_t id{ 0 };
std::string method;
MethodId methodId;
Json::Value internal;
Json::Value data;
// Others.
bool replied = false;
bool replied{ false };
};
}
} // namespace Channel
#endif
......@@ -14,36 +14,36 @@ namespace Channel
class Listener
{
public:
virtual void onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request* request) = 0;
virtual void onChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* channel) = 0;
virtual void OnChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request* request) = 0;
virtual void OnChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* channel) = 0;
};
public:
explicit UnixStreamSocket(int fd);
private:
virtual ~UnixStreamSocket();
~UnixStreamSocket() override;
public:
void SetListener(Listener* listener);
void Send(Json::Value& json);
void Send(Json::Value& msg);
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 isClosedByPeer) override;
void UserOnUnixStreamRead() override;
void UserOnUnixStreamSocketClosed(bool isClosedByPeer) override;
private:
// Passed by argument.
Listener* listener = nullptr;
Listener* listener{ nullptr };
// Others.
Json::CharReader* jsonReader = nullptr;
Json::StreamWriter* jsonWriter = nullptr;
size_t msgStart = 0; // Where the latest message starts.
bool closed = false;
Json::CharReader* jsonReader{ nullptr };
Json::StreamWriter* jsonWriter{ nullptr };
size_t msgStart{ 0 }; // Where the latest message starts.
bool closed{ false };
};
}
} // namespace Channel
#endif
......@@ -7,7 +7,7 @@
#include <uv.h>
/* OpenSSL doc: struct CRYPTO_dynlock_value has to be defined by the application. */
struct CRYPTO_dynlock_value
struct CRYPTO_dynlock_value // NOLINT
{
uv_mutex_t mutex;
};
......
......@@ -66,6 +66,7 @@
#ifndef MS_LOGGER_HPP
#define MS_LOGGER_HPP
#include "common.hpp"
#include "LogLevel.hpp"
#include "Settings.hpp"
#include "Channel/UnixStreamSocket.hpp"
......@@ -114,7 +115,7 @@ public:
public:
static std::string id;
static Channel::UnixStreamSocket* channel;
static const size_t bufferSize = 10000;
static const size_t bufferSize {10000};
static char buffer[];
};
......@@ -143,7 +144,7 @@ public:
Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \
} \
while (0)
while (false)
#define MS_TRACE_STD() \
do \
......@@ -154,7 +155,7 @@ public:
std::fflush(stdout); \
} \
} \
while (0)
while (false)
#else
#define MS_TRACE() ;
#define MS_TRACE_STD() ;
......@@ -175,7 +176,7 @@ public:
Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \
} \
while (0)
while (false)
#define MS_DEBUG_TAG_STD(tag, desc, ...) \
do \
......@@ -186,7 +187,7 @@ public:
std::fflush(stdout); \
} \
} \
while (0)
while (false)
#define MS_WARN_TAG(tag, desc, ...) \
do \
......@@ -197,7 +198,7 @@ public:
Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \
} \
while (0)
while (false)
#define MS_WARN_TAG_STD(tag, desc, ...) \
do \
......@@ -208,7 +209,7 @@ public:
std::fflush(stderr); \
} \
} \
while (0)
while (false)
#define MS_DEBUG_2TAGS(tag1, tag2, desc, ...) \
do \
......@@ -219,7 +220,7 @@ public:
Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \
} \
while (0)
while (false)
#define MS_DEBUG_2TAGS_STD(tag1, tag2, desc, ...) \
do \
......@@ -230,7 +231,7 @@ public:
std::fflush(stdout); \
} \
} \
while (0)
while (false)
#define MS_WARN_2TAGS(tag1, tag2, desc, ...) \
do \
......@@ -241,7 +242,7 @@ public:
Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \
} \
while (0)
while (false)
#define MS_WARN_2TAGS_STD(tag1, tag2, desc, ...) \
do \
......@@ -252,7 +253,7 @@ public:
std::fflush(stderr); \
} \
} \
while (0)
while (false)
#ifdef MS_LOG_DEV
#define MS_DEBUG_DEV(desc, ...) \
......@@ -264,7 +265,7 @@ public:
Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \
} \
while (0)
while (false)
#define MS_DEBUG_DEV_STD(desc, ...) \
do \
......@@ -275,7 +276,7 @@ public:
std::fflush(stdout); \
} \
} \
while (0)
while (false)
#define MS_WARN_DEV(desc, ...) \
do \
......@@ -286,7 +287,7 @@ public:
Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \
} \
while (0)
while (false)
#define MS_WARN_DEV_STD(desc, ...) \
do \
......@@ -297,7 +298,7 @@ public:
std::fflush(stderr); \
} \
} \
while (0)
while (false)
#else
#define MS_DEBUG_DEV(desc, ...) ;
#define MS_DEBUG_DEV_STD(desc, ...) ;
......@@ -311,7 +312,7 @@ public:
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)
while (false)
#define MS_DUMP_STD(desc, ...) \
do \
......@@ -319,7 +320,7 @@ public:
std::fprintf(stdout, _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG, ##__VA_ARGS__); \
std::fflush(stdout); \
} \
while (0)
while (false)
#define MS_ERROR(desc, ...) \
do \
......@@ -327,7 +328,7 @@ public:
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)
while (false)
#define MS_ERROR_STD(desc, ...) \
do \
......@@ -335,7 +336,7 @@ public:
std::fprintf(stderr, _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG, ##__VA_ARGS__); \
std::fflush(stderr); \
} \
while (0)
while (false)
#define MS_ABORT(desc, ...) \
do \
......@@ -344,7 +345,7 @@ public:
std::fflush(stderr); \
std::abort(); \
} \
while (0)
while (false)
#define MS_ASSERT(condition, desc, ...) \
if (!(condition)) \
......
......@@ -15,7 +15,7 @@ class Loop : public SignalsHandler::Listener,
{
public:
explicit Loop(Channel::UnixStreamSocket* channel);
virtual ~Loop();
~Loop() override;
private:
void Close();
......@@ -23,25 +23,25 @@ private:
/* Methods inherited from SignalsHandler::Listener. */
public:
virtual void onSignal(SignalsHandler* signalsHandler, int signum) override;
void OnSignal(SignalsHandler* signalsHandler, int signum) override;
/* Methods inherited from Channel::lUnixStreamSocket::Listener. */
public:
virtual void onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request* request) override;
virtual void onChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* channel) override;
void OnChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request* request) override;
void OnChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* channel) override;
/* Methods inherited from RTC::Room::Listener. */
public:
virtual void onRoomClosed(RTC::Room* room) override;
void OnRoomClosed(RTC::Room* room) override;
private:
// Passed by argument.
Channel::UnixStreamSocket* channel = nullptr;
Channel::UnixStreamSocket* channel{ nullptr };
// Allocated by this.
Channel::Notifier* notifier = nullptr;
SignalsHandler* signalsHandler = nullptr;
Channel::Notifier* notifier{ nullptr };
SignalsHandler* signalsHandler{ nullptr };
// Others.
bool closed = false;
bool closed{ false };
std::unordered_map<uint32_t, RTC::Room*> rooms;
};
......
......@@ -24,7 +24,7 @@ inline MediaSoupError::MediaSoupError(const char* description) : std::runtime_er
static char buffer[2000]; \
std::snprintf(buffer, 2000, desc, ##__VA_ARGS__); \
throw MediaSoupError(buffer); \
} while (0)
} while (false)
#define MS_THROW_ERROR_STD(desc, ...) \
do \
......@@ -33,6 +33,6 @@ inline MediaSoupError::MediaSoupError(const char* description) : std::runtime_er
static char buffer[2000]; \
std::snprintf(buffer, 2000, desc, ##__VA_ARGS__); \
throw MediaSoupError(buffer); \
} while (0)
} while (false)
#endif
......@@ -67,11 +67,11 @@ 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 RTC::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(
virtual void OnDtlsConnected(
const RTC::DtlsTransport* dtlsTransport,
RTC::SrtpSession::Profile srtpProfile,
uint8_t* srtpLocalKey,
......@@ -82,17 +82,17 @@ namespace RTC
// 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 RTC::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 RTC::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(
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(
virtual void OnDtlsApplicationData(
const RTC::DtlsTransport* dtlsTransport, const uint8_t* data, size_t len) = 0;
};
......@@ -100,14 +100,14 @@ namespace RTC
static void ClassInit();
static void ClassDestroy();
static Json::Value& GetLocalFingerprints();
static Role StringToRole(std::string role);
static FingerprintAlgorithm GetFingerprintAlgorithm(std::string fingerprint);
static Role StringToRole(const std::string& role);
static FingerprintAlgorithm GetFingerprintAlgorithm(const std::string& fingerprint);
static bool IsDtls(const uint8_t* data, size_t len);
private:
static void GenerateCertificateAndPrivateKey();
static void ReadCertificateAndPrivateKeyFromFiles();
static void CreateSSL_CTX();
static void CreateSslCtx();
static void GenerateFingerprints();
private:
......@@ -124,7 +124,7 @@ namespace RTC
explicit DtlsTransport(Listener* listener);
private:
virtual ~DtlsTransport();
~DtlsTransport() override;
public:
void Destroy();
......@@ -139,7 +139,7 @@ namespace RTC
private:
bool IsRunning() const;
void Reset();
bool CheckStatus(int return_code);
bool CheckStatus(int returnCode);
void SendPendingOutgoingDtlsData();
bool SetTimeout();
void ProcessHandshake();
......@@ -149,26 +149,26 @@ namespace RTC
/* Callbacks fired by OpenSSL events. */
public:
void onSSLInfo(int where, int ret);
void OnSslInfo(int where, int ret);
/* Pure virtual methods inherited from Timer::Listener. */
public:
virtual void onTimer(Timer* timer) override;
void OnTimer(Timer* timer) override;
private:
// Passed by argument.
Listener* listener = nullptr;
Listener* listener{ nullptr };
// Allocated by this.
SSL* ssl = nullptr;
BIO* sslBioFromNetwork = nullptr; // The BIO from which ssl reads.
BIO* sslBioToNetwork = nullptr; // The BIO in which ssl writes.
Timer* timer = nullptr;
SSL* ssl{ nullptr };
BIO* sslBioFromNetwork{ nullptr }; // The BIO from which ssl reads.
BIO* sslBioToNetwork{ nullptr }; // The BIO in which ssl writes.
Timer* timer{ nullptr };
// Others.
DtlsState state = DtlsState::NEW;
Role localRole = Role::NONE;
Fingerprint remoteFingerprint = {FingerprintAlgorithm::NONE, ""};
bool handshakeDone = false;
bool handshakeDoneNow = false;
DtlsState state{ DtlsState::NEW };
Role localRole{ Role::NONE };
Fingerprint remoteFingerprint{ FingerprintAlgorithm::NONE, "" };
bool handshakeDone{ false };
bool handshakeDoneNow{ false };
std::string remoteCert;
};
......@@ -179,7 +179,7 @@ namespace RTC
return DtlsTransport::localFingerprints;
}
inline DtlsTransport::Role DtlsTransport::StringToRole(std::string role)
inline DtlsTransport::Role DtlsTransport::StringToRole(const std::string& role)
{
auto it = DtlsTransport::string2Role.find(role);
......@@ -189,7 +189,8 @@ namespace RTC
return DtlsTransport::Role::NONE;
}
inline DtlsTransport::FingerprintAlgorithm DtlsTransport::GetFingerprintAlgorithm(std::string fingerprint)
inline DtlsTransport::FingerprintAlgorithm DtlsTransport::GetFingerprintAlgorithm(
const std::string& fingerprint)
{
auto it = DtlsTransport::string2FingerprintAlgorithm.find(fingerprint);
......@@ -237,6 +238,6 @@ namespace RTC
// Make GCC 4.9 happy.
return false;
}
}
} // namespace RTC
#endif
......@@ -34,19 +34,19 @@ namespace RTC
IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority);
IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority);
Json::Value toJson() const;
Json::Value ToJson() const;
private:
// Others.
std::string foundation;
uint32_t priority;
int family = 0;
uint32_t priority{ 0 };
int family{ 0 };
std::string ip;
Protocol protocol;
uint16_t port;
uint16_t port{ 0 };
CandidateType type;
TcpCandidateType tcpType = TcpCandidateType::PASSIVE;
TcpCandidateType tcpType{ TcpCandidateType::PASSIVE };
};
}
} // namespace RTC
#endif
......@@ -24,23 +24,23 @@ namespace RTC
class Listener
{
public:
virtual ~Listener(){};
virtual ~Listener() = default;
public:
/**
* These callbacks are guaranteed to be called before ProcessStunMessage()
* returns, so the given pointers are still usable.
*/
virtual void onOutgoingStunMessage(
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;
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:
IceServer(Listener* listener, const std::string& usernameFragment, const std::string& password);
IceServer(Listener* listener, std::string usernameFragment, std::string password);
void Destroy();
void ProcessStunMessage(RTC::StunMessage* msg, RTC::TransportTuple* tuple);
......@@ -73,13 +73,13 @@ namespace RTC
private:
// Passed by argument.
Listener* listener = nullptr;
Listener* listener{ nullptr };
// Others.
std::string usernameFragment;
std::string password;
IceState state = IceState::NEW;
IceState state{ IceState::NEW };
std::list<RTC::TransportTuple> tuples;
RTC::TransportTuple* selectedTuple = nullptr;
RTC::TransportTuple* selectedTuple{ nullptr };
};
/* Inline instance methods. */
......@@ -108,6 +108,6 @@ namespace RTC
{
return this->state;
}
}
} // namespace RTC
#endif
......@@ -15,8 +15,8 @@ namespace RTC
class Listener
{
public:
virtual void onNackRequired(const std::vector<uint16_t>& seqNumbers) = 0;
virtual void onFullFrameRequired() = 0;
virtual void OnNackRequired(const std::vector<uint16_t>& seqNumbers) = 0;
virtual void OnFullFrameRequired() = 0;
};
private:
......@@ -25,10 +25,10 @@ namespace RTC
NackInfo(){};
explicit NackInfo(uint32_t seq32, uint32_t sendAtSeqNum);
uint32_t seq32 = 0;
uint32_t sendAtSeqNum = 0;
uint64_t sentAtTime = 0;
uint8_t retries = 0;
uint32_t seq32{ 0 };
uint32_t sendAtSeqNum{ 0 };
uint64_t sentAtTime{ 0 };
uint8_t retries{ 0 };
};
enum class NackFilter
......@@ -39,7 +39,7 @@ namespace RTC
public:
explicit NackGenerator(Listener* listener);
virtual ~NackGenerator();
~NackGenerator() override;
void ReceivePacket(RTC::RtpPacket* packet);
......@@ -50,18 +50,18 @@ namespace RTC
/* Pure virtual methods inherited from Timer::Listener. */
public:
virtual void onTimer(Timer* timer) override;
void OnTimer(Timer* timer) override;
private:
// Passed by argument.
Listener* listener = nullptr;
Listener* listener{ nullptr };
// Allocated by this.
Timer* timer = nullptr;
Timer* timer{ nullptr };
// Others.
std::map<uint32_t, NackInfo> nackList;
bool started = false;
uint32_t lastSeq32 = 0; // Extended seq number of last valid packet.
uint32_t rtt = 0; // Round trip time (ms).
bool started{ false };
uint32_t lastSeq32{ 0 }; // Extended seq number of last valid packet.
uint32_t rtt{ 0 }; // Round trip time (ms).
};
// Inline instance methods.
......@@ -70,6 +70,6 @@ namespace RTC
: seq32(seq32), sendAtSeqNum(sendAtSeqNum)
{
}
}
} // namespace RTC
#endif
......@@ -50,9 +50,9 @@ namespace RTC
public:
Type type;
bool booleanValue = false;
int32_t integerValue = 0;
double doubleValue = 0.0;
bool booleanValue{ false };
int32_t integerValue{ 0 };
double doubleValue{ 0.0 };
std::string stringValue;
std::vector<int32_t> arrayOfIntegers;
};
......@@ -60,7 +60,7 @@ namespace RTC
public:
Parameters(){};
Json::Value toJson() const;
Json::Value ToJson() const;
void Set(Json::Value& data);
bool HasBoolean(std::string& key);
......@@ -162,6 +162,6 @@ namespace RTC
{
this->mapKeyValues[key] = Value(arrayOfIntegers);
}
}
} // namespace RTC
#endif
......@@ -29,34 +29,34 @@ namespace RTC
class Listener
{
public:
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(
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 onPeerRtpSenderClosed(const RTC::Peer* peer, RTC::RtpSender* rtpSender) = 0;
virtual void onPeerRtpPacket(
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(
virtual void OnPeerRtcpReceiverReport(
const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::ReceiverReport* report) = 0;
virtual void onPeerRtcpFeedback(
virtual void OnPeerRtcpFeedback(
const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackPsPacket* packet) = 0;
virtual void onPeerRtcpFeedback(
virtual void OnPeerRtcpFeedback(
const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackRtpPacket* packet) = 0;
virtual void onPeerRtcpSenderReport(
virtual void OnPeerRtcpSenderReport(
const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RTCP::SenderReport* report) = 0;
virtual void onFullFrameRequired(RTC::Peer* peer, RTC::RtpSender* rtpSender) = 0;
virtual void OnFullFrameRequired(RTC::Peer* peer, RTC::RtpSender* rtpSender) = 0;
};
public:
Peer(Listener* listener, Channel::Notifier* notifier, uint32_t peerId, std::string& peerName);
private:
virtual ~Peer();
~Peer() override;
public:
void Destroy();
Json::Value toJson() const;
Json::Value ToJson() const;
void HandleRequest(Channel::Request* request);
bool HasCapabilities() const;
std::vector<RTC::RtpReceiver*> GetRtpReceivers() const;
......@@ -82,38 +82,38 @@ namespace RTC
/* Pure virtual methods inherited from RTC::Transport::Listener. */
public:
virtual void onTransportConnected(RTC::Transport* transport) override;
virtual void onTransportClosed(RTC::Transport* transport) override;
virtual void onTransportRtcpPacket(RTC::Transport* transport, RTC::RTCP::Packet* packet) override;
virtual void onTransportFullFrameRequired(RTC::Transport* transport) override;
void OnTransportConnected(RTC::Transport* transport) override;
void OnTransportClosed(RTC::Transport* transport) override;
void OnTransportRtcpPacket(RTC::Transport* transport, RTC::RTCP::Packet* packet) override;
void OnTransportFullFrameRequired(RTC::Transport* transport) override;
/* Pure virtual methods inherited from RTC::RtpReceiver::Listener. */
public:
virtual void onRtpReceiverParameters(RTC::RtpReceiver* rtpReceiver) override;
virtual void onRtpReceiverParametersDone(RTC::RtpReceiver* rtpReceiver) override;
virtual void onRtpPacket(RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) override;
virtual void onRtpReceiverClosed(const RTC::RtpReceiver* rtpReceiver) override;
void OnRtpReceiverParameters(RTC::RtpReceiver* rtpReceiver) override;
void OnRtpReceiverParametersDone(RTC::RtpReceiver* rtpReceiver) override;
void OnRtpPacket(RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) override;
void OnRtpReceiverClosed(const RTC::RtpReceiver* rtpReceiver) override;
/* Pure virtual methods inherited from RTC::RtpSender::Listener. */
public:
virtual void onRtpSenderClosed(RTC::RtpSender* rtpSender) override;
void OnRtpSenderClosed(RTC::RtpSender* rtpSender) override;
/* Pure virtual methods inherited from Timer::Listener. */
public:
virtual void onTimer(Timer* timer) override;
void OnTimer(Timer* timer) override;
public:
// Passed by argument.
uint32_t peerId;
uint32_t peerId{ 0 };
std::string peerName;
private:
// Passed by argument.
Listener* listener = nullptr;
Channel::Notifier* notifier = nullptr;
Listener* listener{ nullptr };
Channel::Notifier* notifier{ nullptr };
// Others.
Timer* timer = nullptr;
bool hasCapabilities = false;
Timer* timer{ nullptr };
bool hasCapabilities{ false };
RTC::RtpCapabilities capabilities;
std::unordered_map<uint32_t, RTC::Transport*> transports;
std::unordered_map<uint32_t, RTC::RtpReceiver*> rtpReceivers;
......@@ -131,9 +131,9 @@ namespace RTC
{
std::vector<RTC::RtpReceiver*> rtpReceivers;
for (auto it = this->rtpReceivers.begin(); it != this->rtpReceivers.end(); ++it)
for (const auto& rtpReceiver : this->rtpReceivers)
{
rtpReceivers.push_back(it->second);
rtpReceivers.push_back(rtpReceiver.second);
}
return rtpReceivers;
......@@ -143,9 +143,9 @@ namespace RTC
{
std::vector<RTC::RtpSender*> rtpSenders;
for (auto it = this->rtpSenders.begin(); it != this->rtpSenders.end(); ++it)
for (const auto& rtpSender : this->rtpSenders)
{
rtpSenders.push_back(it->second);
rtpSenders.push_back(rtpSender.second);
}
return rtpSenders;
......@@ -155,6 +155,6 @@ namespace RTC
{
return this->transports;
}
}
} // namespace RTC
#endif
......@@ -13,14 +13,14 @@ namespace RTC
class ByePacket : public Packet
{
public:
typedef std::vector<uint32_t>::iterator Iterator;
using Iterator = std::vector<uint32_t>::iterator;
public:
static ByePacket* Parse(const uint8_t* data, size_t len);
public:
ByePacket();
virtual ~ByePacket(){};
~ByePacket() override = default;
void AddSsrc(uint32_t ssrc);
void SetReason(const std::string& reason);
......@@ -30,10 +30,10 @@ namespace RTC
/* Pure virtual methods inherited from Packet. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetCount() const override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override;
size_t GetSize() const override;
private:
std::vector<uint32_t> ssrcs;
......@@ -92,7 +92,7 @@ namespace RTC
{
return this->ssrcs.end();
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -22,11 +22,11 @@ namespace RTC
void AddSenderReport(SenderReport* report);
void AddReceiverReport(ReceiverReport* report);
void AddSdesChunk(SdesChunk* chunk);
void Serialize(uint8_t* buffer);
void Serialize(uint8_t* data);
private:
uint8_t* header = nullptr;
size_t size = 0;
uint8_t* header{ nullptr };
size_t size{ 0 };
SenderReportPacket senderReportPacket;
ReceiverReportPacket receiverReportPacket;
SdesPacket sdesPacket;
......@@ -63,7 +63,7 @@ namespace RTC
{
this->sdesPacket.AddChunk(chunk);
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -9,7 +9,7 @@ namespace RTC
{
namespace RTCP
{
template<typename T>
template<typename t>
class FeedbackPacket : public Packet
{
public:
......@@ -21,15 +21,15 @@ namespace RTC
};
public:
static RTCP::Type RtcpType;
static FeedbackPacket<T>* Parse(const uint8_t* data, size_t len);
static const std::string& MessageType2String(typename T::MessageType type);
static RTCP::Type rtcpType;
static FeedbackPacket<t>* Parse(const uint8_t* data, size_t len);
static const std::string& MessageType2String(typename t::MessageType type);
private:
static std::map<typename T::MessageType, std::string> type2String;
static std::map<typename t::MessageType, std::string> type2String;
public:
typename T::MessageType GetMessageType() const;
typename t::MessageType GetMessageType() const;
uint32_t GetSenderSsrc() const;
void SetSenderSsrc(uint32_t ssrc);
uint32_t GetMediaSsrc() const;
......@@ -37,20 +37,20 @@ namespace RTC
/* Pure virtual methods inherited from Packet. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetCount() const override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override;
size_t GetSize() const override;
protected:
explicit FeedbackPacket(CommonHeader* commonHeader);
FeedbackPacket(typename T::MessageType type, uint32_t senderSsrc, uint32_t mediaSsrc);
virtual ~FeedbackPacket();
FeedbackPacket(typename t::MessageType messageType, uint32_t senderSsrc, uint32_t mediaSsrc);
~FeedbackPacket() override;
private:
Header* header = nullptr;
uint8_t* raw = nullptr;
typename T::MessageType messageType;
Header* header{ nullptr };
uint8_t* raw{ nullptr };
typename t::MessageType messageType;
};
class FeedbackPs
......@@ -89,53 +89,53 @@ namespace RTC
};
};
typedef FeedbackPacket<FeedbackPs> FeedbackPsPacket;
typedef FeedbackPacket<FeedbackRtp> FeedbackRtpPacket;
using FeedbackPsPacket = FeedbackPacket<RTC::RTCP::FeedbackPs>;
using FeedbackRtpPacket = FeedbackPacket<RTC::RTCP::FeedbackRtp>;
/* Inline instance methods. */
template<typename T>
typename T::MessageType FeedbackPacket<T>::GetMessageType() const
inline typename T::MessageType FeedbackPacket<T>::GetMessageType() const
{
return this->messageType;
}
template<typename T>
size_t FeedbackPacket<T>::GetCount() const
inline size_t FeedbackPacket<T>::GetCount() const
{
return (size_t)this->GetMessageType();
return static_cast<size_t>(this->GetMessageType());
}
template<typename T>
size_t FeedbackPacket<T>::GetSize() const
inline size_t FeedbackPacket<T>::GetSize() const
{
return sizeof(CommonHeader) + sizeof(Header);
}
template<typename T>
uint32_t FeedbackPacket<T>::GetSenderSsrc() const
inline uint32_t FeedbackPacket<T>::GetSenderSsrc() const
{
return (uint32_t)ntohl(this->header->senderSsrc);
return uint32_t{ ntohl(this->header->senderSsrc) };
}
template<typename T>
void FeedbackPacket<T>::SetSenderSsrc(uint32_t ssrc)
inline void FeedbackPacket<T>::SetSenderSsrc(uint32_t ssrc)
{
this->header->senderSsrc = (uint32_t)htonl(ssrc);
this->header->senderSsrc = uint32_t{ htonl(ssrc) };
}
template<typename T>
uint32_t FeedbackPacket<T>::GetMediaSsrc() const
inline uint32_t FeedbackPacket<T>::GetMediaSsrc() const
{
return (uint32_t)ntohl(this->header->mediaSsrc);
return uint32_t{ ntohl(this->header->mediaSsrc) };
}
template<typename T>
void FeedbackPacket<T>::SetMediaSsrc(uint32_t ssrc)
inline void FeedbackPacket<T>::SetMediaSsrc(uint32_t ssrc)
{
this->header->mediaSsrc = (uint32_t)htonl(ssrc);
this->header->mediaSsrc = uint32_t{ htonl(ssrc) };
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -22,8 +22,8 @@ namespace RTC
virtual size_t GetSize() const = 0;
protected:
uint8_t* raw = nullptr;
bool isCorrect = true;
uint8_t* raw{ nullptr };
bool isCorrect{ true };
};
/* Inline instance methods */
......@@ -47,7 +47,7 @@ namespace RTC
{
return this->isCorrect;
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -13,7 +13,7 @@ namespace RTC
class FeedbackPsItemsPacket : public FeedbackPsPacket
{
public:
typedef typename std::vector<Item*>::iterator Iterator;
using Iterator = typename std::vector<Item*>::iterator;
public:
static FeedbackPsItemsPacket<Item>* Parse(const uint8_t* data, size_t len);
......@@ -22,7 +22,7 @@ namespace RTC
// Parsed Report. Points to an external data.
explicit FeedbackPsItemsPacket(CommonHeader* commonHeader);
explicit FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0);
virtual ~FeedbackPsItemsPacket(){};
~FeedbackPsItemsPacket() override = default;
void AddItem(Item* item);
Iterator Begin();
......@@ -30,9 +30,9 @@ namespace RTC
/* Pure virtual methods inherited from Packet. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
std::vector<Item*> items;
......@@ -41,19 +41,19 @@ namespace RTC
/* Inline instance methods. */
template<typename Item>
FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(CommonHeader* commonHeader)
inline FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(CommonHeader* commonHeader)
: FeedbackPsPacket(commonHeader)
{
}
template<typename Item>
FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackPsPacket(Item::MessageType, senderSsrc, mediaSsrc)
inline FeedbackPsItemsPacket<Item>::FeedbackPsItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackPsPacket(Item::messageType, senderSsrc, mediaSsrc)
{
}
template<typename Item>
size_t FeedbackPsItemsPacket<Item>::GetSize() const
inline size_t FeedbackPsItemsPacket<Item>::GetSize() const
{
size_t size = FeedbackPsPacket::GetSize();
......@@ -66,23 +66,23 @@ namespace RTC
}
template<typename Item>
void FeedbackPsItemsPacket<Item>::AddItem(Item* item)
inline void FeedbackPsItemsPacket<Item>::AddItem(Item* item)
{
this->items.push_back(item);
}
template<typename Item>
typename FeedbackPsItemsPacket<Item>::Iterator FeedbackPsItemsPacket<Item>::Begin()
inline typename FeedbackPsItemsPacket<Item>::Iterator FeedbackPsItemsPacket<Item>::Begin()
{
return this->items.begin();
}
template<typename Item>
typename FeedbackPsItemsPacket<Item>::Iterator FeedbackPsItemsPacket<Item>::End()
inline typename FeedbackPsItemsPacket<Item>::Iterator FeedbackPsItemsPacket<Item>::End()
{
return this->items.end();
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -11,29 +11,35 @@ namespace RTC
class FeedbackPsAfbPacket : public FeedbackPsPacket
{
public:
typedef enum Application : uint8_t { UNKNOWN = 0, REMB = 1 } Application;
enum class Application : uint8_t
{
UNKNOWN = 0,
REMB = 1
};
public:
static FeedbackPsAfbPacket* Parse(const uint8_t* data, size_t len);
public:
// Parsed Report. Points to an external data.
explicit FeedbackPsAfbPacket(CommonHeader* commonHeader, Application application = UNKNOWN);
FeedbackPsAfbPacket(uint32_t senderSsrc, uint32_t mediaSsrc, Application application = UNKNOWN);
virtual ~FeedbackPsAfbPacket(){};
explicit FeedbackPsAfbPacket(
CommonHeader* commonHeader, Application application = Application::UNKNOWN);
FeedbackPsAfbPacket(
uint32_t senderSsrc, uint32_t mediaSsrc, Application application = Application::UNKNOWN);
~FeedbackPsAfbPacket() override = default;
Application GetApplication() const;
/* Pure virtual methods inherited from Packet. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
Application application = UNKNOWN;
uint8_t* data = nullptr;
size_t size = 0;
Application application{ Application::UNKNOWN };
uint8_t* data{ nullptr };
size_t size{ 0 };
};
/* Inline instance methods. */
......@@ -41,7 +47,7 @@ namespace RTC
inline FeedbackPsAfbPacket::FeedbackPsAfbPacket(CommonHeader* commonHeader, Application application)
: FeedbackPsPacket(commonHeader)
{
this->size = ((ntohs(commonHeader->length) + 1) * 4) -
this->size = ((static_cast<size_t>(ntohs(commonHeader->length)) + 1) * 4) -
(sizeof(CommonHeader) + sizeof(FeedbackPacket::Header));
this->data = (uint8_t*)commonHeader + sizeof(CommonHeader) + sizeof(FeedbackPacket::Header);
......@@ -65,7 +71,7 @@ namespace RTC
{
return FeedbackPsPacket::GetSize() + this->size;
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -31,7 +31,7 @@ namespace RTC
};
public:
static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::FIR;
static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::FIR };
public:
static FeedbackPsFirItem* Parse(const uint8_t* data, size_t len);
......@@ -40,23 +40,23 @@ namespace RTC
explicit FeedbackPsFirItem(Header* header);
explicit FeedbackPsFirItem(FeedbackPsFirItem* item);
FeedbackPsFirItem(uint32_t ssrc, uint8_t sequenceNumber);
virtual ~FeedbackPsFirItem(){};
~FeedbackPsFirItem() override = default;
uint32_t GetSsrc() const;
uint8_t GetSequenceNumber() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
Header* header = nullptr;
Header* header{ nullptr };
};
// Fir packet declaration.
typedef FeedbackPsItemsPacket<FeedbackPsFirItem> FeedbackPsFirPacket;
using FeedbackPsFirPacket = FeedbackPsItemsPacket<FeedbackPsFirItem>;
/* Inline instance methods. */
......@@ -75,14 +75,14 @@ namespace RTC
inline uint32_t FeedbackPsFirItem::GetSsrc() const
{
return (uint32_t)ntohl(this->header->ssrc);
return uint32_t{ ntohl(this->header->ssrc) };
}
inline uint8_t FeedbackPsFirItem::GetSequenceNumber() const
{
return (uint8_t)this->header->sequenceNumber;
return this->header->sequenceNumber;
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -26,7 +26,7 @@ namespace RTC
};
public:
static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::PSLEI;
static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::PSLEI };
public:
static FeedbackPsLeiItem* Parse(const uint8_t* data, size_t len);
......@@ -35,22 +35,22 @@ namespace RTC
explicit FeedbackPsLeiItem(Header* header);
explicit FeedbackPsLeiItem(FeedbackPsLeiItem* item);
explicit FeedbackPsLeiItem(uint32_t ssrc);
virtual ~FeedbackPsLeiItem(){};
~FeedbackPsLeiItem() override = default;
uint32_t GetSsrc() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
Header* header = nullptr;
Header* header{ nullptr };
};
// Lei packet declaration.
typedef FeedbackPsItemsPacket<FeedbackPsLeiItem> FeedbackPsLeiPacket;
using FeedbackPsLeiPacket = FeedbackPsItemsPacket<FeedbackPsLeiItem>;
/* Inline instance methods. */
......@@ -69,9 +69,9 @@ namespace RTC
inline uint32_t FeedbackPsLeiItem::GetSsrc() const
{
return (uint32_t)ntohl(this->header->ssrc);
return uint32_t{ ntohl(this->header->ssrc) };
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -17,10 +17,10 @@ namespace RTC
// Parsed Report. Points to an external data.
explicit FeedbackPsPliPacket(CommonHeader* commonHeader);
FeedbackPsPliPacket(uint32_t senderSsrc, uint32_t mediaSsrc);
virtual ~FeedbackPsPliPacket(){};
~FeedbackPsPliPacket() override = default;
public:
virtual void Dump() const override;
void Dump() const override;
};
/* Inline instance methods. */
......@@ -34,7 +34,7 @@ namespace RTC
: FeedbackPsPacket(FeedbackPs::MessageType::PLI, senderSsrc, mediaSsrc)
{
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -33,7 +33,7 @@ namespace RTC
{
public:
// 'R' 'E' 'M' 'B'.
static uint32_t UniqueIdentifier;
static uint32_t uniqueIdentifier;
public:
static FeedbackPsRembPacket* Parse(const uint8_t* data, size_t len);
......@@ -42,7 +42,7 @@ namespace RTC
// Parsed Report. Points to an external data.
explicit FeedbackPsRembPacket(CommonHeader* commonHeader);
FeedbackPsRembPacket(uint32_t senderSsrc, uint32_t mediaSsrc);
virtual ~FeedbackPsRembPacket(){};
~FeedbackPsRembPacket() override = default;
bool IsCorrect();
void SetBitrate(uint64_t bitrate);
......@@ -52,15 +52,15 @@ namespace RTC
/* Pure virtual methods inherited from Packet. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
std::vector<uint32_t> ssrcs;
// Bitrate represented in bps.
uint64_t bitrate = 0;
bool isCorrect = true;
uint64_t bitrate{ 0 };
bool isCorrect{ true };
};
/* Inline instance methods. */
......@@ -99,7 +99,7 @@ namespace RTC
{
return FeedbackPsPacket::GetSize() + 8 + (sizeof(uint32_t) * this->ssrcs.size());
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -23,8 +23,8 @@ namespace RTC
{
class FeedbackPsRpsiItem : public FeedbackItem
{
const static size_t MaxBitStringSize = 6;
const static size_t BitStringOffset = 2;
const static size_t maxBitStringSize{ 6 };
const static size_t bitStringOffset{ 2 };
private:
struct Header
......@@ -32,11 +32,11 @@ namespace RTC
uint8_t paddingBits;
uint8_t zero : 1;
uint8_t payloadType : 7;
uint8_t bitString[MaxBitStringSize];
uint8_t bitString[maxBitStringSize];
};
public:
static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::RPSI;
static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::RPSI };
public:
static FeedbackPsRpsiItem* Parse(const uint8_t* data, size_t len);
......@@ -45,7 +45,7 @@ namespace RTC
explicit FeedbackPsRpsiItem(Header* header);
explicit FeedbackPsRpsiItem(FeedbackPsRpsiItem* item);
FeedbackPsRpsiItem(uint8_t payloadType, uint8_t* bitString, size_t length);
virtual ~FeedbackPsRpsiItem(){};
~FeedbackPsRpsiItem() override = default;
bool IsCorrect() const;
uint8_t GetPayloadType() const;
......@@ -54,17 +54,17 @@ namespace RTC
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
Header* header = nullptr;
size_t length = 0;
Header* header{ nullptr };
size_t length{ 0 };
};
// Rpsi packet declaration.
typedef FeedbackPsItemsPacket<FeedbackPsRpsiItem> FeedbackPsRpsiPacket;
using FeedbackPsRpsiPacket = FeedbackPsItemsPacket<FeedbackPsRpsiItem>;
/* Inline instance methods. */
......@@ -96,7 +96,7 @@ namespace RTC
{
return this->isCorrect;
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -26,7 +26,7 @@ namespace RTC
};
public:
static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::SLI;
static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::SLI };
public:
static FeedbackPsSliItem* Parse(const uint8_t* data, size_t len);
......@@ -35,7 +35,7 @@ namespace RTC
explicit FeedbackPsSliItem(Header* header);
explicit FeedbackPsSliItem(FeedbackPsSliItem* item);
FeedbackPsSliItem(uint16_t first, uint16_t number, uint8_t pictureId);
virtual ~FeedbackPsSliItem(){};
~FeedbackPsSliItem() override = default;
uint16_t GetFirst() const;
void SetFirst(uint16_t first);
......@@ -46,19 +46,19 @@ namespace RTC
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
Header* header = nullptr;
uint16_t first;
uint16_t number;
uint8_t pictureId;
Header* header{ nullptr };
uint16_t first{ 0 };
uint16_t number{ 0 };
uint8_t pictureId{ 0 };
};
// Sli packet declaration.
typedef FeedbackPsItemsPacket<FeedbackPsSliItem> FeedbackPsSliPacket;
using FeedbackPsSliPacket = FeedbackPsItemsPacket<FeedbackPsSliItem>;
/* Inline instance methods. */
......@@ -96,7 +96,7 @@ namespace RTC
{
this->pictureId = pictureId;
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -21,7 +21,7 @@ namespace RTC
{
namespace RTCP
{
template<typename T>
template<typename t>
class FeedbackPsTstItem : public FeedbackItem
{
private:
......@@ -34,7 +34,7 @@ namespace RTC
};
public:
static const FeedbackPs::MessageType MessageType;
static const FeedbackPs::MessageType messageType;
public:
static FeedbackPsTstItem* Parse(const uint8_t* data, size_t len);
......@@ -43,7 +43,7 @@ namespace RTC
explicit FeedbackPsTstItem(Header* header);
explicit FeedbackPsTstItem(FeedbackPsTstItem* item);
FeedbackPsTstItem(uint32_t ssrc, uint8_t sequenceNumber, uint8_t index);
virtual ~FeedbackPsTstItem(){};
~FeedbackPsTstItem() override = default;
uint32_t GetSsrc() const;
uint8_t GetSequenceNumber() const;
......@@ -51,12 +51,12 @@ namespace RTC
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
Header* header = nullptr;
Header* header{ nullptr };
};
class Tstr
......@@ -67,49 +67,49 @@ namespace RTC
};
// Tst classes declaration.
typedef FeedbackPsTstItem<Tstr> FeedbackPsTstrItem;
typedef FeedbackPsTstItem<Tstn> FeedbackPsTstnItem;
using FeedbackPsTstrItem = FeedbackPsTstItem<Tstr>;
using FeedbackPsTstnItem = FeedbackPsTstItem<Tstn>;
// Tst packets declaration.
typedef FeedbackPsItemsPacket<FeedbackPsTstrItem> FeedbackPsTstrPacket;
typedef FeedbackPsItemsPacket<FeedbackPsTstnItem> FeedbackPsTstnPacket;
using FeedbackPsTstrPacket = FeedbackPsItemsPacket<FeedbackPsTstrItem>;
using FeedbackPsTstnPacket = FeedbackPsItemsPacket<FeedbackPsTstnItem>;
/* Inline instance methods. */
template<typename T>
FeedbackPsTstItem<T>::FeedbackPsTstItem(Header* header) : header(header)
inline FeedbackPsTstItem<T>::FeedbackPsTstItem(Header* header) : header(header)
{
}
template<typename T>
FeedbackPsTstItem<T>::FeedbackPsTstItem(FeedbackPsTstItem* item) : header(item->header)
inline FeedbackPsTstItem<T>::FeedbackPsTstItem(FeedbackPsTstItem* item) : header(item->header)
{
}
template<typename T>
size_t FeedbackPsTstItem<T>::GetSize() const
inline size_t FeedbackPsTstItem<T>::GetSize() const
{
return sizeof(Header);
}
template<typename T>
uint32_t FeedbackPsTstItem<T>::GetSsrc() const
inline uint32_t FeedbackPsTstItem<T>::GetSsrc() const
{
return (uint32_t)ntohl(this->header->ssrc);
return uint32_t{ ntohl(this->header->ssrc) };
}
template<typename T>
uint8_t FeedbackPsTstItem<T>::GetSequenceNumber() const
inline uint8_t FeedbackPsTstItem<T>::GetSequenceNumber() const
{
return (uint8_t)this->header->sequenceNumber;
return static_cast<uint8_t>(this->header->sequenceNumber);
}
template<typename T>
uint8_t FeedbackPsTstItem<T>::GetIndex() const
inline uint8_t FeedbackPsTstItem<T>::GetIndex() const
{
return (uint8_t)this->header->index;
return static_cast<uint8_t>(this->header->index);
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -37,7 +37,7 @@ namespace RTC
};
public:
static const FeedbackPs::MessageType MessageType = FeedbackPs::MessageType::FIR;
static const FeedbackPs::MessageType messageType{ FeedbackPs::MessageType::FIR };
public:
static FeedbackPsVbcmItem* Parse(const uint8_t* data, size_t len);
......@@ -47,7 +47,7 @@ namespace RTC
explicit FeedbackPsVbcmItem(FeedbackPsVbcmItem* item);
FeedbackPsVbcmItem(
uint32_t ssrc, uint8_t sequenceNumber, uint8_t payloadType, uint16_t length, uint8_t* value);
virtual ~FeedbackPsVbcmItem(){};
~FeedbackPsVbcmItem() override = default;
uint32_t GetSsrc() const;
uint8_t GetSequenceNumber() const;
......@@ -57,16 +57,16 @@ namespace RTC
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
Header* header = nullptr;
Header* header{ nullptr };
};
// Vbcm packet declaration
typedef FeedbackPsItemsPacket<FeedbackPsVbcmItem> FeedbackPsVbcmPacket;
using FeedbackPsVbcmPacket = FeedbackPsItemsPacket<FeedbackPsVbcmItem>;
/* Inline instance methods. */
......@@ -80,7 +80,7 @@ namespace RTC
inline size_t FeedbackPsVbcmItem::GetSize() const
{
size_t size = 8 + size_t(this->header->length);
size_t size = 8 + static_cast<size_t>(this->header->length);
// Consider pading to 32 bits (4 bytes) boundary.
return (size + 3) & ~3;
......@@ -88,29 +88,29 @@ namespace RTC
inline uint32_t FeedbackPsVbcmItem::GetSsrc() const
{
return (uint32_t)ntohl(this->header->ssrc);
return uint32_t{ ntohl(this->header->ssrc) };
}
inline uint8_t FeedbackPsVbcmItem::GetSequenceNumber() const
{
return (uint8_t)this->header->sequenceNumber;
return uint8_t{ this->header->sequenceNumber };
}
inline uint8_t FeedbackPsVbcmItem::GetPayloadType() const
{
return (uint8_t)this->header->payloadType;
return uint8_t{ this->header->payloadType };
}
inline uint16_t FeedbackPsVbcmItem::GetLength() const
{
return (uint16_t)ntohs(this->header->length);
return uint16_t{ ntohs(this->header->length) };
}
inline uint8_t* FeedbackPsVbcmItem::GetValue() const
{
return this->header->value;
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -13,7 +13,7 @@ namespace RTC
class FeedbackRtpItemsPacket : public FeedbackRtpPacket
{
public:
typedef typename std::vector<Item*>::iterator Iterator;
using Iterator = typename std::vector<Item*>::iterator;
public:
static FeedbackRtpItemsPacket<Item>* Parse(const uint8_t* data, size_t len);
......@@ -22,7 +22,7 @@ namespace RTC
// Parsed Report. Points to an external data.
explicit FeedbackRtpItemsPacket(CommonHeader* commonHeader);
explicit FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc = 0);
virtual ~FeedbackRtpItemsPacket(){};
~FeedbackRtpItemsPacket() override = default;
void AddItem(Item* item);
Iterator Begin();
......@@ -30,9 +30,9 @@ namespace RTC
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
std::vector<Item*> items;
......@@ -41,19 +41,19 @@ namespace RTC
/* Inline instance methods. */
template<typename Item>
FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(CommonHeader* commonHeader)
inline FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(CommonHeader* commonHeader)
: FeedbackRtpPacket(commonHeader)
{
}
template<typename Item>
FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackRtpPacket(Item::MessageType, senderSsrc, mediaSsrc)
inline FeedbackRtpItemsPacket<Item>::FeedbackRtpItemsPacket(uint32_t senderSsrc, uint32_t mediaSsrc)
: FeedbackRtpPacket(Item::messageType, senderSsrc, mediaSsrc)
{
}
template<typename Item>
size_t FeedbackRtpItemsPacket<Item>::GetSize() const
inline size_t FeedbackRtpItemsPacket<Item>::GetSize() const
{
size_t size = FeedbackRtpPacket::GetSize();
......@@ -66,23 +66,23 @@ namespace RTC
}
template<typename Item>
void FeedbackRtpItemsPacket<Item>::AddItem(Item* item)
inline void FeedbackRtpItemsPacket<Item>::AddItem(Item* item)
{
this->items.push_back(item);
}
template<typename Item>
typename FeedbackRtpItemsPacket<Item>::Iterator FeedbackRtpItemsPacket<Item>::Begin()
inline typename FeedbackRtpItemsPacket<Item>::Iterator FeedbackRtpItemsPacket<Item>::Begin()
{
return this->items.begin();
}
template<typename Item>
typename FeedbackRtpItemsPacket<Item>::Iterator FeedbackRtpItemsPacket<Item>::End()
inline typename FeedbackRtpItemsPacket<Item>::Iterator FeedbackRtpItemsPacket<Item>::End()
{
return this->items.end();
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -43,7 +43,7 @@ namespace RTC
};
public:
static const FeedbackRtp::MessageType MessageType = FeedbackRtp::MessageType::ECN;
static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::ECN };
public:
static FeedbackRtpEcnItem* Parse(const uint8_t* data, size_t len);
......@@ -51,7 +51,7 @@ namespace RTC
public:
explicit FeedbackRtpEcnItem(Header* header);
explicit FeedbackRtpEcnItem(FeedbackRtpEcnItem* item);
virtual ~FeedbackRtpEcnItem(){};
~FeedbackRtpEcnItem() override = default;
uint32_t GetSequenceNumber() const;
uint32_t GetEct0Counter() const;
......@@ -63,16 +63,16 @@ namespace RTC
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
Header* header = nullptr;
Header* header{ nullptr };
};
// Ecn packet declaration.
typedef FeedbackRtpItemsPacket<FeedbackRtpEcnItem> FeedbackRtpEcnPacket;
using FeedbackRtpEcnPacket = FeedbackRtpItemsPacket<FeedbackRtpEcnItem>;
/* Inline instance methods. */
......@@ -91,39 +91,39 @@ namespace RTC
inline uint32_t FeedbackRtpEcnItem::GetSequenceNumber() const
{
return ntohl(this->header->sequenceNumber);
return uint32_t{ ntohl(this->header->sequenceNumber) };
}
inline uint32_t FeedbackRtpEcnItem::GetEct0Counter() const
{
return ntohl(this->header->ect0Counter);
return uint32_t{ ntohl(this->header->ect0Counter) };
}
inline uint32_t FeedbackRtpEcnItem::GetEct1Counter() const
{
return ntohl(this->header->ect1Counter);
return uint32_t{ ntohl(this->header->ect1Counter) };
}
inline uint16_t FeedbackRtpEcnItem::GetEcnCeCounter() const
{
return ntohs(this->header->ecnCeCounter);
return uint16_t{ ntohs(this->header->ecnCeCounter) };
}
inline uint16_t FeedbackRtpEcnItem::GetNotEctCounter() const
{
return ntohs(this->header->notEctCounter);
return uint16_t{ ntohs(this->header->notEctCounter) };
}
inline uint16_t FeedbackRtpEcnItem::GetLostPackets() const
{
return ntohs(this->header->lostPackets);
return uint16_t{ ntohs(this->header->lostPackets) };
}
inline uint16_t FeedbackRtpEcnItem::GetDuplicatedPackets() const
{
return ntohs(this->header->duplicatedPackets);
return uint16_t{ ntohs(this->header->duplicatedPackets) };
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -27,7 +27,7 @@ namespace RTC
};
public:
static const FeedbackRtp::MessageType MessageType = FeedbackRtp::MessageType::NACK;
static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::NACK };
public:
static FeedbackRtpNackItem* Parse(const uint8_t* data, size_t len);
......@@ -36,23 +36,23 @@ namespace RTC
explicit FeedbackRtpNackItem(Header* header);
explicit FeedbackRtpNackItem(FeedbackRtpNackItem* item);
FeedbackRtpNackItem(uint16_t packetId, uint16_t lostPacketBitmask);
virtual ~FeedbackRtpNackItem(){};
~FeedbackRtpNackItem() override = default;
uint16_t GetPacketId() const;
uint16_t GetLostPacketBitmask() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
Header* header = nullptr;
Header* header{ nullptr };
};
// Nack packet declaration.
typedef FeedbackRtpItemsPacket<FeedbackRtpNackItem> FeedbackRtpNackPacket;
using FeedbackRtpNackPacket = FeedbackRtpItemsPacket<FeedbackRtpNackItem>;
/* Inline instance methods. */
......@@ -72,14 +72,14 @@ namespace RTC
inline uint16_t FeedbackRtpNackItem::GetPacketId() const
{
return (uint16_t)ntohs(this->header->packetId);
return uint16_t{ ntohs(this->header->packetId) };
}
inline uint16_t FeedbackRtpNackItem::GetLostPacketBitmask() const
{
return (uint16_t)ntohs(this->header->lostPacketBitmask);
return uint16_t{ ntohs(this->header->lostPacketBitmask) };
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -17,9 +17,9 @@ namespace RTC
// Parsed Report. Points to an external data.
explicit FeedbackRtpSrReqPacket(CommonHeader* commonHeader);
FeedbackRtpSrReqPacket(uint32_t senderSsrc, uint32_t mediaSsrc);
virtual ~FeedbackRtpSrReqPacket(){};
~FeedbackRtpSrReqPacket() override = default;
virtual void Dump() const override;
void Dump() const override;
};
/* Inline instance methods. */
......@@ -33,7 +33,7 @@ namespace RTC
: FeedbackRtpPacket(FeedbackRtp::MessageType::SR_REQ, senderSsrc, mediaSsrc)
{
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -27,7 +27,7 @@ namespace RTC
};
public:
static const FeedbackRtp::MessageType MessageType = FeedbackRtp::MessageType::TLLEI;
static const FeedbackRtp::MessageType messageType{ FeedbackRtp::MessageType::TLLEI };
public:
static FeedbackRtpTlleiItem* Parse(const uint8_t* data, size_t len);
......@@ -36,23 +36,23 @@ namespace RTC
explicit FeedbackRtpTlleiItem(Header* header);
explicit FeedbackRtpTlleiItem(FeedbackRtpTlleiItem* item);
FeedbackRtpTlleiItem(uint16_t packetId, uint16_t lostPacketBitmask);
virtual ~FeedbackRtpTlleiItem(){};
~FeedbackRtpTlleiItem() override = default;
uint16_t GetPacketId() const;
uint16_t GetLostPacketBitmask() const;
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
Header* header = nullptr;
Header* header{ nullptr };
};
// Nack packet declaration.
typedef FeedbackRtpItemsPacket<FeedbackRtpTlleiItem> FeedbackRtpTlleiPacket;
// Tllei packet declaration.
using FeedbackRtpTlleiPacket = FeedbackRtpItemsPacket<FeedbackRtpTlleiItem>;
/* Inline instance methods. */
......@@ -72,14 +72,14 @@ namespace RTC
inline uint16_t FeedbackRtpTlleiItem::GetPacketId() const
{
return (uint16_t)ntohs(this->header->packetId);
return uint16_t{ ntohs(this->header->packetId) };
}
inline uint16_t FeedbackRtpTlleiItem::GetLostPacketBitmask() const
{
return (uint16_t)ntohs(this->header->lostPacketBitmask);
return uint16_t{ ntohs(this->header->lostPacketBitmask) };
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -20,14 +20,14 @@ namespace RTC
{
namespace RTCP
{
template<typename T>
template<typename t>
class FeedbackRtpTmmbItem : public FeedbackItem
{
private:
static constexpr size_t HeaderSize = 8;
static constexpr size_t HeaderSize{ 8 };
public:
static const FeedbackRtp::MessageType MessageType;
static const FeedbackRtp::MessageType messageType;
public:
static FeedbackRtpTmmbItem* Parse(const uint8_t* data, size_t len);
......@@ -35,7 +35,7 @@ namespace RTC
public:
explicit FeedbackRtpTmmbItem(const uint8_t* data);
FeedbackRtpTmmbItem();
virtual ~FeedbackRtpTmmbItem() = default;
~FeedbackRtpTmmbItem() override = default;
uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc);
......@@ -46,14 +46,14 @@ namespace RTC
/* Virtual methods inherited from FeedbackItem. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetSize() const override;
private:
uint32_t ssrc = 0;
uint64_t bitrate = 0;
uint16_t overhead = 0;
uint32_t ssrc{ 0 };
uint64_t bitrate{ 0 };
uint16_t overhead{ 0 };
};
// Tmmb types declaration.
......@@ -65,62 +65,60 @@ namespace RTC
};
// Tmmbn classes declaration.
typedef FeedbackRtpTmmbItem<FeedbackRtpTmmbr> FeedbackRtpTmmbrItem;
typedef FeedbackRtpTmmbItem<FeedbackRtpTmmbn> FeedbackRtpTmmbnItem;
using FeedbackRtpTmmbrItem = FeedbackRtpTmmbItem<FeedbackRtpTmmbr>;
using FeedbackRtpTmmbnItem = FeedbackRtpTmmbItem<FeedbackRtpTmmbn>;
// Tmmbn packets declaration.
typedef FeedbackRtpItemsPacket<FeedbackRtpTmmbrItem> FeedbackRtpTmmbrPacket;
typedef FeedbackRtpItemsPacket<FeedbackRtpTmmbnItem> FeedbackRtpTmmbnPacket;
using FeedbackRtpTmmbrPacket = FeedbackRtpItemsPacket<FeedbackRtpTmmbrItem>;
using FeedbackRtpTmmbnPacket = FeedbackRtpItemsPacket<FeedbackRtpTmmbnItem>;
/* Inline instance methods. */
template<typename T>
FeedbackRtpTmmbItem<T>::FeedbackRtpTmmbItem()
{
}
inline FeedbackRtpTmmbItem<T>::FeedbackRtpTmmbItem() = default;
template<typename T>
size_t FeedbackRtpTmmbItem<T>::GetSize() const
inline size_t FeedbackRtpTmmbItem<T>::GetSize() const
{
return HeaderSize;
}
template<typename T>
uint32_t FeedbackRtpTmmbItem<T>::GetSsrc() const
inline uint32_t FeedbackRtpTmmbItem<T>::GetSsrc() const
{
return this->ssrc;
}
template<typename T>
void FeedbackRtpTmmbItem<T>::SetSsrc(uint32_t ssrc)
inline void FeedbackRtpTmmbItem<T>::SetSsrc(uint32_t ssrc)
{
this->ssrc = ssrc;
}
template<typename T>
uint64_t FeedbackRtpTmmbItem<T>::GetBitrate() const
inline uint64_t FeedbackRtpTmmbItem<T>::GetBitrate() const
{
return this->bitrate;
}
template<typename T>
void FeedbackRtpTmmbItem<T>::SetBitrate(uint64_t bitrate)
inline void FeedbackRtpTmmbItem<T>::SetBitrate(uint64_t bitrate)
{
this->bitrate = bitrate;
}
template<typename T>
uint16_t FeedbackRtpTmmbItem<T>::GetOverhead() const
inline uint16_t FeedbackRtpTmmbItem<T>::GetOverhead() const
{
return this->overhead;
}
template<typename T>
void FeedbackRtpTmmbItem<T>::SetOverhead(uint16_t overhead)
inline void FeedbackRtpTmmbItem<T>::SetOverhead(uint16_t overhead)
{
this->overhead = overhead;
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -10,12 +10,12 @@ namespace RTC
namespace RTCP
{
// Internal buffer for RTCP serialization.
constexpr size_t bufferSize = 65536;
extern uint8_t buffer[bufferSize];
constexpr size_t BufferSize{ 65536 };
extern uint8_t Buffer[BufferSize];
// Maximum interval for regular RTCP mode.
constexpr uint16_t maxVideoIntervalMs = 1000;
constexpr uint16_t maxAudioIntervalMs = 5000;
constexpr uint16_t MaxVideoIntervalMs{ 1000 };
constexpr uint16_t MaxAudioIntervalMs{ 5000 };
enum class Type : uint8_t
{
......@@ -76,15 +76,15 @@ namespace RTC
private:
Type type;
Packet* next = nullptr;
CommonHeader* header = nullptr;
Packet* next{ nullptr };
CommonHeader* header{ nullptr };
};
/* Inline static methods. */
inline bool Packet::IsRtcp(const uint8_t* data, size_t len)
{
CommonHeader* header = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data));
auto header = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data));
return (
(len >= sizeof(CommonHeader)) &&
......@@ -104,9 +104,7 @@ namespace RTC
{
}
inline Packet::~Packet()
{
}
inline Packet::~Packet() = default;
inline Packet* Packet::GetNext() const
{
......@@ -130,9 +128,9 @@ namespace RTC
inline const uint8_t* Packet::GetData() const
{
return (uint8_t*)this->header;
return reinterpret_cast<uint8_t*>(this->header);
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -55,21 +55,21 @@ namespace RTC
void SetDelaySinceLastSenderReport(uint32_t dlsr);
private:
Header* header = nullptr;
uint8_t raw[sizeof(Header)] = {0};
Header* header{ nullptr };
uint8_t raw[sizeof(Header)]{ 0 };
};
class ReceiverReportPacket : public Packet
{
public:
typedef std::vector<ReceiverReport*>::iterator Iterator;
using Iterator = std::vector<ReceiverReport*>::iterator;
public:
static ReceiverReportPacket* Parse(const uint8_t* data, size_t len, size_t offset = 0);
public:
ReceiverReportPacket();
virtual ~ReceiverReportPacket();
~ReceiverReportPacket() override;
uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc);
......@@ -79,14 +79,14 @@ namespace RTC
/* Pure virtual methods inherited from Packet. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetCount() const override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override;
size_t GetSize() const override;
private:
// SSRC of packet sender.
uint32_t ssrc = 0;
uint32_t ssrc{ 0 };
std::vector<ReceiverReport*> reports;
};
......@@ -112,17 +112,17 @@ namespace RTC
inline uint32_t ReceiverReport::GetSsrc() const
{
return (uint32_t)ntohl(this->header->ssrc);
return uint32_t{ ntohl(this->header->ssrc) };
}
inline void ReceiverReport::SetSsrc(uint32_t ssrc)
{
this->header->ssrc = (uint32_t)htonl(ssrc);
this->header->ssrc = uint32_t{ htonl(ssrc) };
}
inline uint8_t ReceiverReport::GetFractionLost() const
{
return (uint8_t)Utils::Byte::Get1Byte((uint8_t*)this->header, 4);
return uint8_t{ Utils::Byte::Get1Byte((uint8_t*)this->header, 4) };
}
inline void ReceiverReport::SetFractionLost(uint8_t fractionLost)
......@@ -132,7 +132,7 @@ namespace RTC
inline int32_t ReceiverReport::GetTotalLost() const
{
uint32_t value = (uint32_t)Utils::Byte::Get3Bytes((uint8_t*)this->header, 5);
auto value = uint32_t{ Utils::Byte::Get3Bytes((uint8_t*)this->header, 5) };
// Possitive value.
if (((value >> 23) & 1) == 0)
......@@ -153,47 +153,47 @@ namespace RTC
uint32_t value = (totalLost >= 0) ? (clamp & 0x07FFFFF) : (clamp | 0x0800000);
Utils::Byte::Set3Bytes((uint8_t*)this->header, 5, value);
Utils::Byte::Set3Bytes(reinterpret_cast<uint8_t*>(this->header), 5, value);
}
inline uint32_t ReceiverReport::GetLastSeq() const
{
return (uint32_t)ntohl(this->header->lastSeq);
return uint32_t{ ntohl(this->header->lastSeq) };
}
inline void ReceiverReport::SetLastSeq(uint32_t lastSeq)
{
this->header->lastSeq = (uint32_t)htonl(lastSeq);
this->header->lastSeq = uint32_t{ htonl(lastSeq) };
}
inline uint32_t ReceiverReport::GetJitter() const
{
return (uint32_t)ntohl(this->header->jitter);
return uint32_t{ ntohl(this->header->jitter) };
}
inline void ReceiverReport::SetJitter(uint32_t jitter)
{
this->header->jitter = (uint32_t)htonl(jitter);
this->header->jitter = uint32_t{ htonl(jitter) };
}
inline uint32_t ReceiverReport::GetLastSenderReport() const
{
return (uint32_t)ntohl(this->header->lsr);
return uint32_t{ ntohl(this->header->lsr) };
}
inline void ReceiverReport::SetLastSenderReport(uint32_t lsr)
{
this->header->lsr = (uint32_t)htonl(lsr);
this->header->lsr = uint32_t{ htonl(lsr) };
}
inline uint32_t ReceiverReport::GetDelaySinceLastSenderReport() const
{
return (uint32_t)ntohl(this->header->dlsr);
return uint32_t{ ntohl(this->header->dlsr) };
}
inline void ReceiverReport::SetDelaySinceLastSenderReport(uint32_t dlsr)
{
this->header->dlsr = (uint32_t)htonl(dlsr);
this->header->dlsr = uint32_t{ htonl(dlsr) };
}
inline ReceiverReportPacket::ReceiverReportPacket() : Packet(Type::RR)
......@@ -227,12 +227,12 @@ namespace RTC
inline uint32_t ReceiverReportPacket::GetSsrc() const
{
return (uint32_t)ntohl(this->ssrc);
return uint32_t{ ntohl(this->ssrc) };
}
inline void ReceiverReportPacket::SetSsrc(uint32_t ssrc)
{
this->ssrc = (uint32_t)htonl(ssrc);
this->ssrc = uint32_t{ htonl(ssrc) };
}
inline void ReceiverReportPacket::AddReport(ReceiverReport* report)
......@@ -249,7 +249,7 @@ namespace RTC
{
return this->reports.end();
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -44,7 +44,7 @@ namespace RTC
explicit SdesItem(Header* header);
explicit SdesItem(SdesItem* item);
SdesItem(SdesItem::Type type, size_t len, const char* value);
~SdesItem();
~SdesItem() = default;
void Dump() const;
size_t Serialize(uint8_t* buffer);
......@@ -56,7 +56,7 @@ namespace RTC
private:
// Passed by argument.
Header* header = nullptr;
Header* header{ nullptr };
std::unique_ptr<uint8_t> raw;
private:
......@@ -66,13 +66,13 @@ namespace RTC
class SdesChunk
{
public:
typedef std::vector<SdesItem*>::iterator Iterator;
using Iterator = std::vector<SdesItem*>::iterator;
public:
static SdesChunk* Parse(const uint8_t* data, size_t len);
public:
explicit SdesChunk(const uint32_t ssrc);
explicit SdesChunk(uint32_t ssrc);
explicit SdesChunk(SdesChunk* chunk);
~SdesChunk();
......@@ -87,21 +87,21 @@ namespace RTC
Iterator End();
private:
uint32_t ssrc;
uint32_t ssrc{ 0 };
std::vector<SdesItem*> items;
};
class SdesPacket : public Packet
{
public:
typedef std::vector<SdesChunk*>::iterator Iterator;
using Iterator = std::vector<SdesChunk*>::iterator;
public:
static SdesPacket* Parse(const uint8_t* data, size_t len);
public:
SdesPacket();
virtual ~SdesPacket();
~SdesPacket() override;
void AddChunk(SdesChunk* chunk);
Iterator Begin();
......@@ -109,10 +109,10 @@ namespace RTC
/* Pure virtual methods inherited from Packet. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetCount() const override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override;
size_t GetSize() const override;
private:
std::vector<SdesChunk*> chunks;
......@@ -128,13 +128,9 @@ namespace RTC
{
}
inline SdesItem::~SdesItem()
{
}
inline size_t SdesItem::GetSize() const
{
return 2 + size_t(this->header->length);
return 2 + size_t{ this->header->length };
}
inline SdesItem::Type SdesItem::GetType() const
......@@ -156,14 +152,14 @@ namespace RTC
inline SdesChunk::SdesChunk(uint32_t ssrc)
{
this->ssrc = htonl(ssrc);
this->ssrc = uint32_t{ htonl(ssrc) };
}
inline SdesChunk::SdesChunk(SdesChunk* chunk)
{
this->ssrc = chunk->ssrc;
for (Iterator it = chunk->Begin(); it != chunk->End(); ++it)
for (auto it = chunk->Begin(); it != chunk->End(); ++it)
{
this->AddItem(new SdesItem(*it));
}
......@@ -193,12 +189,12 @@ namespace RTC
inline uint32_t SdesChunk::GetSsrc() const
{
return (uint32_t)ntohl(this->ssrc);
return uint32_t{ ntohl(this->ssrc) };
}
inline void SdesChunk::SetSsrc(uint32_t ssrc)
{
this->ssrc = (uint32_t)htonl(ssrc);
this->ssrc = uint32_t{ htonl(ssrc) };
}
inline void SdesChunk::AddItem(SdesItem* item)
......@@ -261,7 +257,7 @@ namespace RTC
{
return this->chunks.end();
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -51,21 +51,21 @@ namespace RTC
void SetOctetCount(uint32_t octetCount);
private:
Header* header = nullptr;
uint8_t raw[sizeof(Header)] = {0};
Header* header{ nullptr };
uint8_t raw[sizeof(Header)]{ 0 };
};
class SenderReportPacket : public Packet
{
public:
typedef std::vector<SenderReport*>::iterator Iterator;
using Iterator = std::vector<SenderReport*>::iterator;
public:
static SenderReportPacket* Parse(const uint8_t* data, size_t len);
public:
SenderReportPacket();
virtual ~SenderReportPacket();
~SenderReportPacket() override;
void AddReport(SenderReport* report);
Iterator Begin();
......@@ -73,10 +73,10 @@ namespace RTC
/* Pure virtual methods inherited from Packet. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetCount() const override;
virtual size_t GetSize() const override;
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override;
size_t GetSize() const override;
private:
std::vector<SenderReport*> reports;
......@@ -104,65 +104,62 @@ namespace RTC
inline uint32_t SenderReport::GetSsrc() const
{
return (uint32_t)ntohl(this->header->ssrc);
return uint32_t{ ntohl(this->header->ssrc) };
}
inline void SenderReport::SetSsrc(uint32_t ssrc)
{
this->header->ssrc = (uint32_t)htonl(ssrc);
this->header->ssrc = uint32_t{ htonl(ssrc) };
}
inline uint32_t SenderReport::GetNtpSec() const
{
return (uint32_t)ntohl(this->header->ntpSec);
return uint32_t{ ntohl(this->header->ntpSec) };
}
inline void SenderReport::SetNtpSec(uint32_t ntpSec)
{
this->header->ntpSec = (uint32_t)htonl(ntpSec);
this->header->ntpSec = uint32_t{ htonl(ntpSec) };
}
inline uint32_t SenderReport::GetNtpFrac() const
{
return (uint32_t)ntohl(this->header->ntpFrac);
return uint32_t{ ntohl(this->header->ntpFrac) };
}
inline void SenderReport::SetNtpFrac(uint32_t ntpFrac)
{
this->header->ntpFrac = (uint32_t)htonl(ntpFrac);
this->header->ntpFrac = uint32_t{ htonl(ntpFrac) };
}
inline uint32_t SenderReport::GetRtpTs() const
{
return (uint32_t)ntohl(this->header->rtpTs);
return uint32_t{ ntohl(this->header->rtpTs) };
}
inline void SenderReport::SetRtpTs(uint32_t rtpTs)
{
this->header->rtpTs = (uint32_t)htonl(rtpTs);
this->header->rtpTs = uint32_t{ htonl(rtpTs) };
}
inline
uint32_t
SenderReport::GetPacketCount() const
inline uint32_t SenderReport::GetPacketCount() const
{
return (uint32_t)ntohl(this->header->packetCount);
return uint32_t{ ntohl(this->header->packetCount) };
}
inline void SenderReport::SetPacketCount(uint32_t packetCount)
{
this->header->packetCount = (uint32_t)htonl(packetCount);
this->header->packetCount = uint32_t{ htonl(packetCount) };
}
inline uint32_t SenderReport::GetOctetCount() const
{
return (uint32_t)ntohl(this->header->octetCount);
return uint32_t{ ntohl(this->header->octetCount) };
}
inline void SenderReport::SetOctetCount(uint32_t octetCount)
{
this->header->octetCount = (uint32_t)htonl(octetCount);
this->header->octetCount = uint32_t{ htonl(octetCount) };
}
/* Inline instance methods. */
......@@ -210,7 +207,7 @@ namespace RTC
{
return this->reports.end();
}
}
}
} // namespace RTCP
} // namespace RTC
#endif
......@@ -27,16 +27,16 @@ namespace RTC
class AimdRateControl
{
private:
static constexpr int64_t kDefaultRttMs = 200;
static constexpr int64_t DefaultRttMs{ 200 };
// (jmillan) replacement from 'congestion_controller::GetMinBitrateBps()'.
static constexpr int kMinBitrateBps = 10000;
static constexpr int MinBitrateBps{ 10000 };
private:
enum RateControlState
{
kRcHold,
kRcIncrease,
kRcDecrease
RC_HOLD,
RC_INCREASE,
RC_DECREASE
};
public:
......@@ -74,7 +74,7 @@ namespace RTC
// in the "decrease" state the bitrate will be decreased to slightly below the
// incoming bitrate. When in the "hold" state the bitrate will be kept
// constant to allow built up queues to drain.
uint32_t ChangeBitrate(uint32_t currentBitrate, uint32_t incomingBitrate, int64_t nowMs);
uint32_t ChangeBitrate(uint32_t newBitrateBps, uint32_t incomingBitrateBps, int64_t nowMs);
// Clamps newBitrateBps to within the configured min bitrate and a linear
// function of the incoming bitrate, so that the new bitrate can't grow too
// large compared to the bitrate actually being received by the other end.
......@@ -82,32 +82,32 @@ namespace RTC
uint32_t MultiplicativeRateIncrease(int64_t nowMs, int64_t lastMs, uint32_t currentBitrateBps) const;
uint32_t AdditiveRateIncrease(int64_t nowMs, int64_t lastMs) const;
void UpdateChangePeriod(int64_t nowMs);
void UpdateMaxBitRateEstimate(float incomingBitRateKbps);
void UpdateMaxBitRateEstimate(float incomingBitrateKbps);
void ChangeState(const RateControlInput& input, int64_t nowMs);
void ChangeState(RateControlState newState);
void ChangeRegion(RateControlRegion region);
private:
uint32_t minConfiguredBitrateBps = kMinBitrateBps;
uint32_t maxConfiguredBitrateBps = 30000000;
uint32_t currentBitrateBps = this->maxConfiguredBitrateBps;
float avgMaxBitrateKbps = -1.0f;
float varMaxBitrateKbps = 0.4f;
RateControlState rateControlState = kRcHold;
RateControlRegion rateControlRegion = kRcMaxUnknown;
int64_t timeLastBitrateChange = -1;
uint32_t minConfiguredBitrateBps{ MinBitrateBps };
uint32_t maxConfiguredBitrateBps{ 30000000 };
uint32_t currentBitrateBps{ this->maxConfiguredBitrateBps };
float avgMaxBitrateKbps{ -1.0f };
float varMaxBitrateKbps{ 0.4f };
RateControlState rateControlState{ RC_HOLD };
RateControlRegion rateControlRegion{ RC_MAX_UNKNOWN };
int64_t timeLastBitrateChange{ -1 };
RateControlInput currentInput;
bool updated = false;
int64_t timeFirstIncomingEstimate = -1;
bool bitrateIsInitialized = false;
float beta = 0.85f;
int64_t rtt = kDefaultRttMs;
int lastDecrease = 0;
bool updated{ false };
int64_t timeFirstIncomingEstimate{ -1 };
bool bitrateIsInitialized{ false };
float beta{ 0.85f };
int64_t rtt{ DefaultRttMs };
int lastDecrease{ 0 };
};
/* Inline methods. */
inline AimdRateControl::AimdRateControl() : currentInput(kBwNormal, 0, 1.0)
inline AimdRateControl::AimdRateControl() : currentInput(BW_NORMAL, 0, 1.0)
{
}
......@@ -137,6 +137,7 @@ namespace RTC
{
this->currentBitrateBps =
ChangeBitrate(this->currentBitrateBps, this->currentInput.incomingBitrate, nowMs);
return this->currentBitrateBps;
}
......@@ -172,6 +173,6 @@ namespace RTC
{
this->rateControlState = newState;
}
}
} // namespace RTC
#endif
......@@ -7,10 +7,10 @@ namespace RTC
{
enum BandwidthUsage
{
kBwNormal,
kBwUnderusing,
kBwOverusing
BW_NORMAL,
BW_UNDERUSING,
BW_OVERUSING
};
}
} // namespace RTC
#endif
......@@ -23,8 +23,8 @@ namespace RTC
public:
// After this many packet groups received out of order InterArrival will
// reset, assuming that clocks have made a jump.
static constexpr int kReorderedResetThreshold = 3;
static constexpr int64_t kArrivalTimeOffsetThresholdMs = 3000;
static constexpr int ReorderedResetThreshold{ 3 };
static constexpr int64_t ArrivalTimeOffsetThresholdMs{ 3000 };
// A timestamp group is defined as all packets with a timestamp which are at
// most timestampGroupLengthTicks older than the first timestamp in that
......@@ -54,11 +54,11 @@ namespace RTC
TimestampGroup();
bool IsFirstPacket() const;
size_t size = 0;
uint32_t firstTimestamp = 0;
uint32_t timestamp = 0;
int64_t completeTimeMs = 0;
int64_t lastSystemTimeMs = 0;
size_t size{ 0 };
uint32_t firstTimestamp{ 0 };
uint32_t timestamp{ 0 };
int64_t completeTimeMs{ 0 };
int64_t lastSystemTimeMs{ 0 };
};
// Returns true if the packet with timestamp |timestamp| arrived in order.
......@@ -69,12 +69,12 @@ namespace RTC
bool BelongsToBurst(int64_t arrivalTimeMs, uint32_t timestamp) const;
void Reset();
const uint32_t kTimestampGroupLengthTicks;
const uint32_t timestampGroupLengthTicks;
TimestampGroup currentTimestampGroup;
TimestampGroup prevTimestampGroup;
double timestampToMsCoeff = 0;
bool burstGrouping = false;
int numConsecutiveReorderedPackets = 0;
double timestampToMsCoeff{ 0 };
bool burstGrouping{ false };
int numConsecutiveReorderedPackets{ 0 };
};
/* Inline methods. */
......@@ -91,11 +91,11 @@ namespace RTC
inline InterArrival::InterArrival(
uint32_t timestampGroupLengthTicks, double timestampToMsCoeff, bool enableBurstGrouping)
: kTimestampGroupLengthTicks(timestampGroupLengthTicks), currentTimestampGroup(),
: timestampGroupLengthTicks(timestampGroupLengthTicks), currentTimestampGroup(),
prevTimestampGroup(), timestampToMsCoeff(timestampToMsCoeff),
burstGrouping(enableBurstGrouping), numConsecutiveReorderedPackets(0)
{
}
}
} // namespace RTC
#endif
......@@ -20,7 +20,7 @@ namespace RTC
class OveruseDetector
{
private:
static constexpr double kOverUsingTimeThreshold = 10;
static constexpr double OverUsingTimeThreshold{ 10 };
public:
OveruseDetector() = default;
......@@ -31,7 +31,7 @@ namespace RTC
// offset was based on, representing the time between detector updates.
// |numOfDeltas| is the number of deltas the offset estimate is based on.
// Returns the state after the detection update.
BandwidthUsage Detect(double offset, double timestampDelta, int numOfDeltas, int64_t nowMs);
BandwidthUsage Detect(double offset, double tsDelta, int numOfDeltas, int64_t nowMs);
// Returns the current detector state.
BandwidthUsage State() const;
......@@ -39,21 +39,21 @@ namespace RTC
void UpdateThreshold(double modifiedOffset, int64_t nowMs);
private:
double kUp = 0.0087;
double kDown = 0.039;
double overusingTimeThreshold = kOverUsingTimeThreshold;
double threshold = 12.5;
int64_t lastUpdateMs = -1;
double prevOffset = 0.0;
double timeOverUsing = -1;
int overuseCounter = 0;
BandwidthUsage hypothesis = kBwNormal;
double up{ 0.0087 };
double down{ 0.039 };
double overusingTimeThreshold{ OverUsingTimeThreshold };
double threshold{ 12.5 };
int64_t lastUpdateMs{ -1 };
double prevOffset{ 0.0 };
double timeOverUsing{ -1 };
int overuseCounter{ 0 };
BandwidthUsage hypothesis{ BW_NORMAL };
};
inline BandwidthUsage OveruseDetector::State() const
{
return this->hypothesis;
}
}
} // namespace RTC
#endif
......@@ -14,6 +14,7 @@
#include "RTC/RemoteBitrateEstimator/BandwidthUsage.hpp"
#include <cstring> // std::memcpy()
#include <deque>
#include <utility>
namespace RTC
{
......@@ -37,7 +38,7 @@ namespace RTC
class OveruseEstimator
{
public:
explicit OveruseEstimator(const OverUseDetectorOptions& options);
explicit OveruseEstimator(OverUseDetectorOptions options);
~OveruseEstimator();
// Update the estimator with a new sample. The deltas should represent deltas
......@@ -61,14 +62,14 @@ namespace RTC
private:
// Must be first member variable. Cannot be const because we need to be copyable.
OverUseDetectorOptions options;
uint16_t numOfDeltas = 0;
double slope = 0;
double offset = 0;
double prevOffset = 0;
double E[2][2];
uint16_t numOfDeltas{ 0 };
double slope{ 0 };
double offset{ 0 };
double prevOffset{ 0 };
double e[2][2];
double processNoise[2];
double avgNoise = 0;
double varNoise = 0;
double avgNoise{ 0 };
double varNoise{ 0 };
std::deque<double> tsDeltaHist;
};
......@@ -85,13 +86,13 @@ 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(),
inline OveruseEstimator::OveruseEstimator(OverUseDetectorOptions options)
: options(std::move(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->e, this->options.initialE, sizeof(this->e));
std::memcpy(this->processNoise, this->options.initialProcessNoise, sizeof(this->processNoise));
}
......@@ -114,6 +115,6 @@ namespace RTC
{
return this->numOfDeltas;
}
}
} // namespace RTC
#endif
......@@ -10,11 +10,11 @@ namespace RTC
{
struct RateControlInput
{
RateControlInput(BandwidthUsage bwState, const uint32_t incomingBitrate, double noiseVar);
RateControlInput(BandwidthUsage bwState, uint32_t incomingBitrate, double noiseVar);
BandwidthUsage bwState;
uint32_t incomingBitrate = 0;
double noiseVar = 0;
uint32_t incomingBitrate{ 0 };
double noiseVar{ 0 };
};
/* Inline methods. */
......@@ -24,6 +24,6 @@ namespace RTC
: bwState(bwState), incomingBitrate(incomingBitrate), noiseVar(noiseVar)
{
}
}
} // namespace RTC
#endif
......@@ -7,10 +7,10 @@ namespace RTC
{
enum RateControlRegion
{
kRcNearMax,
kRcAboveMax,
kRcMaxUnknown
RC_NEAR_MAX,
RC_ABOVE_MAX,
RC_MAX_UNKNOWN
};
}
} // namespace RTC
#endif
......@@ -41,15 +41,15 @@ namespace RTC
{
public:
// Called when a receive channel group has a new bitrate estimate for the incoming streams.
virtual void onReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, uint32_t bitrate) = 0;
virtual void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, uint32_t bitrate) = 0;
};
protected:
static const int64_t kProcessIntervalMs = 500;
static const int64_t kStreamTimeOutMs = 2000;
static const int64_t processIntervalMs{ 500 };
static const int64_t streamTimeOutMs{ 2000 };
public:
virtual ~RemoteBitrateEstimator() = default;
~RemoteBitrateEstimator() override = default;
// Called for each incoming packet. Updates the incoming payload bitrate
// estimate and the over-use detector. If an over-use is detected the
......@@ -57,10 +57,7 @@ namespace RTC
// packet size excluding headers.
// 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;
int64_t arrivalTimeMs, size_t payloadSize, const RtpPacket& packet, uint32_t absSendTime) = 0;
// Removes all data for |ssrc|.
virtual void RemoveStream(uint32_t ssrc) = 0;
......@@ -85,6 +82,6 @@ namespace RTC
// Called on a worker thread.
virtual void Process() = 0;
};
}
} // namespace RTC
#endif
......@@ -12,7 +12,6 @@
#define MS_RTC_REMOTE_BITRATE_ESTIMATOR_ABS_SEND_TIME_HPP
#include "common.hpp"
#include "Logger.hpp"
#include "RTC/RemoteBitrateEstimator/AimdRateControl.hpp"
#include "RTC/RemoteBitrateEstimator/InterArrival.hpp"
#include "RTC/RemoteBitrateEstimator/OveruseDetector.hpp"
......@@ -31,9 +30,9 @@ namespace RTC
{
Probe(int64_t sendTimeMs, int64_t recvTimeMs, size_t payloadSize);
int64_t sendTimeMs = 0;
int64_t recvTimeMs = 0;
size_t payloadSize = 0;
int64_t sendTimeMs{ 0 };
int64_t recvTimeMs{ 0 };
size_t payloadSize{ 0 };
};
struct Cluster
......@@ -41,12 +40,12 @@ namespace RTC
int GetSendBitrateBps() const;
int GetRecvBitrateBps() const;
float sendMeanMs = 0.0f;
float recvMeanMs = 0.0f;
float sendMeanMs{ 0.0f };
float recvMeanMs{ 0.0f };
// TODO(holmer): Add some variance metric as well?
size_t meanSize = 0;
int count = 0;
int numAboveMinDelta = 0;
size_t meanSize{ 0 };
int count{ 0 };
int numAboveMinDelta{ 0 };
};
class RemoteBitrateEstimatorAbsSendTime : public RemoteBitrateEstimator
......@@ -57,13 +56,10 @@ namespace RTC
public:
explicit RemoteBitrateEstimatorAbsSendTime(Listener* observer);
virtual ~RemoteBitrateEstimatorAbsSendTime() = default;
~RemoteBitrateEstimatorAbsSendTime() override = default;
void IncomingPacket(
int64_t arrivalTimeMs,
size_t payloadSize,
const RtpPacket& packet,
const uint32_t absSendTime) override;
int64_t arrivalTimeMs, size_t payloadSize, const RtpPacket& packet, 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;
......@@ -74,39 +70,39 @@ namespace RTC
void SetMinBitrate(int minBitrateBps) override;
private:
typedef std::map<uint32_t, int64_t> Ssrcs;
using Ssrcs = std::map<uint32_t, int64_t>;
enum class ProbeResult
{
kBitrateUpdated,
kNoUpdate
BITRATE_UPDATED,
NO_UPDATE
};
private:
void IncomingPacketInfo(
int64_t arrivalTimeMs, uint32_t sendTime_24bits, size_t payloadSize, uint32_t ssrc);
int64_t arrivalTimeMs, uint32_t sendTime24bits, 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;
// Returns true if a probe which changed the estimate was detected.
ProbeResult ProcessClusters(int64_t nowMs);
bool IsBitrateImproving(int probeBitrateBps) const;
bool IsBitrateImproving(int newBitrateBps) const;
void TimeoutStreams(int64_t nowMs);
private:
Listener* const observer = nullptr;
Listener* const observer{ nullptr };
std::unique_ptr<InterArrival> interArrival;
std::unique_ptr<OveruseEstimator> estimator;
OveruseDetector detector;
RateCalculator incomingBitrate;
bool incomingBitrateInitialized = false;
bool incomingBitrateInitialized{ false };
std::vector<int> recentPropagationDeltaMs;
std::vector<int64_t> recentUpdateTimeMs;
std::list<Probe> probes;
size_t totalProbesReceived = 0;
int64_t firstPacketTimeMs = -1;
int64_t lastUpdateMs = -1;
bool umaRecorded = false;
size_t totalProbesReceived{ 0 };
int64_t firstPacketTimeMs{ -1 };
int64_t lastUpdateMs{ -1 };
bool umaRecorded{ false };
Ssrcs ssrcs;
AimdRateControl remoteRate;
};
......@@ -143,13 +139,13 @@ namespace RTC
inline int64_t RemoteBitrateEstimatorAbsSendTime::TimeUntilNextProcess()
{
const int64_t kDisabledModuleTime = 1000;
return kDisabledModuleTime;
static const int64_t DisabledModuleTime{ 1000 };
return DisabledModuleTime;
}
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);
}
......@@ -162,6 +158,6 @@ namespace RTC
{
this->remoteRate.SetMinBitrate(minBitrateBps);
}
}
} // namespace RTC
#endif
......@@ -27,17 +27,17 @@ namespace RTC
class RemoteBitrateEstimatorSingleStream : public RemoteBitrateEstimator
{
private:
static constexpr double kTimestampToMs = 1.0 / 90.0;
static constexpr double TimestampToMs{ 1.0 / 90.0 };
public:
explicit RemoteBitrateEstimatorSingleStream(Listener* observer);
virtual ~RemoteBitrateEstimatorSingleStream();
~RemoteBitrateEstimatorSingleStream() override;
void IncomingPacket(
int64_t arrivalTimeMs,
size_t payloadSize,
const RtpPacket& packet,
const uint32_t transmissionTimeOffset) override;
uint32_t transmissionTimeOffset) override;
void Process() override;
int64_t TimeUntilNextProcess() override;
void OnRttUpdate(int64_t avgRttMs, int64_t maxRttMs) override;
......@@ -50,7 +50,7 @@ namespace RTC
{
enum
{
kTimestampGroupLengthMs = 5
TIMESTAMP_GROUP_LENGTH_MS = 5
};
explicit Detector(
int64_t lastPacketTimeMs, const OverUseDetectorOptions& options, bool enableBurstGrouping);
......@@ -62,11 +62,11 @@ namespace RTC
};
private:
typedef std::map<uint32_t, Detector*> SsrcOveruseEstimatorMap;
using SsrcOveruseEstimatorMap = std::map<uint32_t, Detector*>;
private:
// Triggers a new estimate calculation.
void UpdateEstimate(int64_t timeNow);
void UpdateEstimate(int64_t nowMs);
void GetSsrcs(std::vector<uint32_t>* ssrcs) const;
// Returns |remoteRate| if the pointed to object exists,
......@@ -76,12 +76,12 @@ namespace RTC
private:
SsrcOveruseEstimatorMap overuseDetectors;
RateCalculator incomingBitrate;
uint32_t lastValidIncomingBitrate = 0;
uint32_t lastValidIncomingBitrate{ 0 };
std::unique_ptr<AimdRateControl> remoteRate;
Listener* observer = nullptr;
int64_t lastProcessTime = -1;
int64_t processIntervalMs = 0;
bool umaRecorded = false;
Listener* observer{ nullptr };
int64_t lastProcessTime{ -1 };
int64_t processIntervalMs{ 0 };
bool umaRecorded{ false };
};
/* Inline Methods. */
......@@ -89,14 +89,14 @@ namespace RTC
inline RemoteBitrateEstimatorSingleStream::Detector::Detector(
int64_t lastPacketTimeMs, const OverUseDetectorOptions& options, bool enableBurstGrouping)
: lastPacketTimeMs(lastPacketTimeMs),
interArrival(90 * kTimestampGroupLengthMs, kTimestampToMs, enableBurstGrouping),
interArrival(90 * TIMESTAMP_GROUP_LENGTH_MS, TimestampToMs, enableBurstGrouping),
estimator(options), detector()
{
}
inline RemoteBitrateEstimatorSingleStream::RemoteBitrateEstimatorSingleStream(Listener* observer)
: incomingBitrate(), remoteRate(new AimdRateControl()), observer(observer),
processIntervalMs(kProcessIntervalMs)
processIntervalMs(RemoteBitrateEstimator::processIntervalMs)
{
// assert(this->observer);
}
......@@ -105,7 +105,8 @@ namespace RTC
{
while (!this->overuseDetectors.empty())
{
SsrcOveruseEstimatorMap::iterator it = this->overuseDetectors.begin();
auto it = this->overuseDetectors.begin();
delete it->second;
this->overuseDetectors.erase(it);
}
......@@ -117,15 +118,15 @@ namespace RTC
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)
{
SsrcOveruseEstimatorMap::iterator it = this->overuseDetectors.find(ssrc);
auto it = this->overuseDetectors.find(ssrc);
if (it != this->overuseDetectors.end())
{
delete it->second;
......@@ -144,6 +145,6 @@ namespace RTC
{
this->remoteRate->SetMinBitrate(minBitrateBps);
}
}
} // namespace RTC
#endif
......@@ -26,7 +26,7 @@ namespace RTC
class Listener
{
public:
virtual void onRoomClosed(RTC::Room* room) = 0;
virtual void OnRoomClosed(RTC::Room* room) = 0;
};
public:
......@@ -44,7 +44,7 @@ namespace RTC
public:
void Destroy();
Json::Value toJson() const;
Json::Value ToJson() const;
void HandleRequest(Channel::Request* request);
const RTC::RtpCapabilities& GetCapabilities() const;
......@@ -55,32 +55,31 @@ namespace RTC
/* Pure virtual methods inherited from RTC::Peer::Listener. */
public:
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 onPeerRtpSenderClosed(const RTC::Peer* peer, RTC::RtpSender* rtpSender) override;
virtual void onPeerRtpPacket(
void OnPeerClosed(const RTC::Peer* peer) override;
void OnPeerCapabilities(RTC::Peer* peer, RTC::RtpCapabilities* capabilities) override;
void OnPeerRtpReceiverParameters(const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver) override;
void OnPeerRtpReceiverClosed(const RTC::Peer* peer, const RTC::RtpReceiver* rtpReceiver) override;
void OnPeerRtpSenderClosed(const RTC::Peer* peer, RTC::RtpSender* rtpSender) override;
void OnPeerRtpPacket(
const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) override;
virtual void onPeerRtcpReceiverReport(
void OnPeerRtcpReceiverReport(
const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::ReceiverReport* report) override;
virtual void onPeerRtcpFeedback(
void OnPeerRtcpFeedback(
const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackPsPacket* packet) override;
virtual void onPeerRtcpFeedback(
void OnPeerRtcpFeedback(
const RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackRtpPacket* packet) override;
virtual void onPeerRtcpSenderReport(
void OnPeerRtcpSenderReport(
const RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RTCP::SenderReport* report) override;
virtual void onFullFrameRequired(RTC::Peer* peer, RTC::RtpSender* rtpSender) override;
void OnFullFrameRequired(RTC::Peer* peer, RTC::RtpSender* rtpSender) override;
public:
// Passed by argument.
uint32_t roomId;
uint32_t roomId{ 0 };
private:
// Passed by argument.
Listener* listener = nullptr;
Channel::Notifier* notifier = nullptr;
Listener* listener{ nullptr };
Channel::Notifier* notifier{ nullptr };
// Others.
RTC::RtpCapabilities capabilities;
std::unordered_map<uint32_t, RTC::Peer*> peers;
......@@ -94,6 +93,6 @@ namespace RTC
{
return this->capabilities;
}
}
} // namespace RTC
#endif
......@@ -12,13 +12,13 @@ namespace RTC
class RateCalculator
{
public:
static constexpr float BpsScale = 8000.0f;
static constexpr float BpsScale2 = 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 = BpsScale);
void Update(size_t count, uint64_t now);
void Update(size_t size, uint64_t now);
uint32_t GetRate(uint64_t now);
void Reset();
......@@ -29,22 +29,22 @@ namespace RTC
private:
struct BufferItem
{
size_t count = 0;
size_t count{ 0 };
};
private:
std::unique_ptr<BufferItem[]> buffer;
// Time (in milliseconds) for oldest item in the time window.
uint64_t oldestTime = 0;
uint64_t oldestTime{ 0 };
// Index for the oldest item in the time window.
uint32_t oldestIndex = 0;
uint32_t oldestIndex{ 0 };
// Total count in the time window.
size_t totalCount = 0;
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 = BpsScale;
const float scale{ BpsScale };
};
class RtpDataCounter
......@@ -57,8 +57,8 @@ namespace RTC
private:
RateCalculator rate;
size_t packets = 0;
size_t bytes = 0;
size_t packets{ 0 };
size_t bytes{ 0 };
};
/* Inline instance methods. */
......@@ -98,6 +98,6 @@ namespace RTC
{
return this->bytes;
}
}
} // namespace RTC
#endif
......@@ -117,8 +117,8 @@ namespace RTC
}
public:
Type type = Type::UNSET;
Subtype subtype = Subtype::UNSET;
Type type{ Type::UNSET };
Subtype subtype{ Subtype::UNSET };
std::string name;
};
......@@ -147,7 +147,7 @@ namespace RTC
public:
explicit RtcpFeedback(Json::Value& data);
Json::Value toJson() const;
Json::Value ToJson() const;
public:
std::string type;
......@@ -160,7 +160,7 @@ namespace RTC
RtpCodecParameters(){};
RtpCodecParameters(Json::Value& data, RTC::Scope scope);
Json::Value toJson() const;
Json::Value ToJson() const;
bool Matches(RtpCodecParameters& codec, bool checkPayloadType = false);
void ReduceRtcpFeedback(std::vector<RtcpFeedback>& supportedRtcpFeedback);
......@@ -168,17 +168,17 @@ namespace RTC
void CheckCodec();
private:
RTC::Scope scope = RTC::Scope::ROOM_CAPABILITY;
RTC::Scope scope{ RTC::Scope::ROOM_CAPABILITY };
public:
Media::Kind kind = Media::Kind::ALL;
Media::Kind kind{ Media::Kind::ALL };
RtpCodecMime mime;
uint8_t payloadType = 0;
bool hasPayloadType = false;
uint32_t clockRate = 0;
uint32_t maxptime = 0;
uint32_t ptime = 0;
uint32_t numChannels = 1;
uint8_t payloadType{ 0 };
bool hasPayloadType{ false };
uint32_t clockRate{ 0 };
uint32_t maxptime{ 0 };
uint32_t ptime{ 0 };
uint32_t numChannels{ 1 };
RTC::Parameters parameters;
std::vector<RtcpFeedback> rtcpFeedback;
};
......@@ -188,14 +188,14 @@ namespace RTC
public:
explicit RtpHeaderExtension(Json::Value& data);
Json::Value toJson() const;
Json::Value ToJson() const;
public:
Media::Kind kind = Media::Kind::ALL;
Media::Kind kind{ Media::Kind::ALL };
std::string uri;
RtpHeaderExtensionUri::Type type;
uint8_t preferredId = 0;
bool preferredEncrypt = false;
uint8_t preferredId{ 0 };
bool preferredEncrypt{ false };
};
class RtpCapabilities
......@@ -204,7 +204,7 @@ namespace RTC
RtpCapabilities(){};
RtpCapabilities(Json::Value& data, RTC::Scope scope);
Json::Value toJson() const;
Json::Value ToJson() const;
void ReduceHeaderExtensions(std::vector<RtpHeaderExtension>& supportedHeaderExtensions);
void ReduceFecMechanisms(std::vector<std::string>& supportedFecMechanisms);
......@@ -223,11 +223,11 @@ namespace RTC
RtpFecParameters(){};
explicit RtpFecParameters(Json::Value& data);
Json::Value toJson() const;
Json::Value ToJson() const;
public:
std::string mechanism;
uint32_t ssrc = 0;
uint32_t ssrc{ 0 };
};
class RtpRtxParameters
......@@ -236,10 +236,10 @@ namespace RTC
RtpRtxParameters(){};
explicit RtpRtxParameters(Json::Value& data);
Json::Value toJson() const;
Json::Value ToJson() const;
public:
uint32_t ssrc = 0;
uint32_t ssrc{ 0 };
};
class RtpEncodingParameters
......@@ -248,20 +248,20 @@ namespace RTC
RtpEncodingParameters(){};
explicit RtpEncodingParameters(Json::Value& data);
Json::Value toJson() const;
Json::Value ToJson() const;
public:
uint32_t ssrc = 0;
uint8_t codecPayloadType = 0;
bool hasCodecPayloadType = false;
uint32_t ssrc{ 0 };
uint8_t codecPayloadType{ 0 };
bool hasCodecPayloadType{ false };
RtpFecParameters fec;
bool hasFec = false;
bool hasFec{ false };
RtpRtxParameters rtx;
bool hasRtx = false;
double resolutionScale = 1.0;
double framerateScale = 1.0;
uint32_t maxFramerate = 0;
bool active = true;
bool hasRtx{ false };
double resolutionScale{ 1.0 };
double framerateScale{ 1.0 };
uint32_t maxFramerate{ 0 };
bool active{ true };
std::string encodingId;
std::vector<std::string> dependencyEncodingIds;
};
......@@ -271,13 +271,13 @@ namespace RTC
public:
explicit RtpHeaderExtensionParameters(Json::Value& data);
Json::Value toJson() const;
Json::Value ToJson() const;
public:
std::string uri;
RtpHeaderExtensionUri::Type type;
uint8_t id = 0;
bool encrypt = false;
uint8_t id{ 0 };
bool encrypt{ false };
RTC::Parameters parameters;
};
......@@ -287,21 +287,21 @@ namespace RTC
RtcpParameters(){};
explicit RtcpParameters(Json::Value& data);
Json::Value toJson() const;
Json::Value ToJson() const;
public:
std::string cname;
uint32_t ssrc = 0;
bool reducedSize = true;
uint32_t ssrc{ 0 };
bool reducedSize{ true };
};
class RtpParameters
{
public:
explicit RtpParameters(Json::Value& data);
explicit RtpParameters(const RtpParameters* RtpParameters);
explicit RtpParameters(const RtpParameters* rtpParameters);
Json::Value toJson() const;
Json::Value ToJson() const;
void ReduceCodecsAndEncodings(RtpCapabilities& capabilities);
void ReduceHeaderExtensions(std::vector<RtpHeaderExtension>& supportedHeaderExtensions);
RTC::RtpCodecParameters& GetCodecForEncoding(RtpEncodingParameters& encoding);
......@@ -316,9 +316,9 @@ namespace RTC
std::vector<RtpEncodingParameters> encodings;
std::vector<RtpHeaderExtensionParameters> headerExtensions;
RtcpParameters rtcp;
bool hasRtcp = false;
bool hasRtcp{ false };
Json::Value userParameters;
};
}
} // namespace RTC
#endif
......@@ -13,7 +13,7 @@ namespace RTC
class RtpListener
{
public:
Json::Value toJson() const;
Json::Value ToJson() const;
bool HasSsrc(uint32_t ssrc, const RTC::RtpReceiver* rtpReceiver) const;
bool HasMuxId(std::string& muxId, const RTC::RtpReceiver* rtpReceiver) const;
bool HasPayloadType(uint8_t payloadType, const RTC::RtpReceiver* rtpReceiver) const;
......@@ -81,6 +81,6 @@ namespace RTC
return (it->second != rtpReceiver);
}
}
}
} // namespace RTC
#endif
......@@ -80,7 +80,7 @@ namespace RTC
Header* header,
ExtensionHeader* extensionHeader,
const uint8_t* payload,
size_t payloadLen,
size_t payloadLength,
uint8_t payloadPadding,
size_t size);
~RtpPacket();
......@@ -120,17 +120,17 @@ namespace RTC
private:
// Passed by argument.
Header* header = nullptr;
uint8_t* csrcList = nullptr;
ExtensionHeader* extensionHeader = nullptr;
Header* header{ nullptr };
uint8_t* csrcList{ nullptr };
ExtensionHeader* extensionHeader{ nullptr };
std::map<uint8_t, OneByteExtension*> oneByteExtensions;
std::map<uint8_t, TwoBytesExtension*> twoBytesExtensions;
std::map<RtpHeaderExtensionUri::Type, uint8_t> extensionMap;
uint8_t* payload = nullptr;
size_t payloadLength = 0;
uint8_t payloadPadding = 0;
size_t size = 0; // Full size of the packet in bytes.
uint32_t seq32 = 0; // Extended seq number.
uint8_t* payload{ nullptr };
size_t payloadLength{ 0 };
uint8_t payloadPadding{ 0 };
size_t size{ 0 }; // Full size of the packet in bytes.
uint32_t seq32{ 0 }; // Extended seq number.
};
/* Inline static methods. */
......@@ -139,7 +139,7 @@ namespace RTC
{
// NOTE: RtcpPacket::IsRtcp() must always be called before this method.
Header* header = const_cast<Header*>(reinterpret_cast<const Header*>(data));
auto header = const_cast<Header*>(reinterpret_cast<const Header*>(data));
return (
(len >= sizeof(Header)) &&
......@@ -183,12 +183,12 @@ namespace RTC
inline uint16_t RtpPacket::GetSequenceNumber() const
{
return (uint16_t)ntohs(this->header->sequenceNumber);
return uint16_t{ ntohs(this->header->sequenceNumber) };
}
inline void RtpPacket::SetSequenceNumber(uint16_t seq)
{
this->header->sequenceNumber = (uint16_t)htons(seq);
this->header->sequenceNumber = uint16_t{ htons(seq) };
}
inline uint32_t RtpPacket::GetExtendedSequenceNumber() const
......@@ -203,22 +203,22 @@ namespace RTC
inline uint32_t RtpPacket::GetTimestamp() const
{
return (uint32_t)ntohl(this->header->timestamp);
return uint32_t{ ntohl(this->header->timestamp) };
}
inline void RtpPacket::SetTimestamp(uint32_t timestamp)
{
this->header->timestamp = (uint32_t)htonl(timestamp);
this->header->timestamp = uint32_t{ htonl(timestamp) };
}
inline uint32_t RtpPacket::GetSsrc() const
{
return (uint32_t)ntohl(this->header->ssrc);
return uint32_t{ ntohl(this->header->ssrc) };
}
inline void RtpPacket::SetSsrc(uint32_t ssrc)
{
this->header->ssrc = (uint32_t)htonl(ssrc);
this->header->ssrc = uint32_t{ htonl(ssrc) };
}
inline bool RtpPacket::HasExtensionHeader() const
......@@ -231,7 +231,7 @@ namespace RTC
if (!this->extensionHeader)
return 0;
return uint16_t(ntohs(this->extensionHeader->id));
return uint16_t{ ntohs(this->extensionHeader->id) };
}
inline size_t RtpPacket::GetExtensionHeaderLength() const
......@@ -239,7 +239,7 @@ namespace RTC
if (!this->extensionHeader)
return 0;
return size_t(ntohs(this->extensionHeader->length) * 4);
return static_cast<size_t>(ntohs(this->extensionHeader->length) * 4);
}
inline uint8_t* RtpPacket::GetExtensionHeaderValue() const
......@@ -339,6 +339,6 @@ namespace RTC
{
return this->payloadLength;
}
}
} // namespace RTC
#endif
......@@ -29,10 +29,10 @@ namespace RTC
class Listener
{
public:
virtual void onRtpReceiverParameters(RTC::RtpReceiver* rtpReceiver) = 0;
virtual void onRtpReceiverParametersDone(RTC::RtpReceiver* rtpReceiver) = 0;
virtual void onRtpPacket(RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) = 0;
virtual void onRtpReceiverClosed(const RTC::RtpReceiver* rtpReceiver) = 0;
virtual void OnRtpReceiverParameters(RTC::RtpReceiver* rtpReceiver) = 0;
virtual void OnRtpReceiverParametersDone(RTC::RtpReceiver* rtpReceiver) = 0;
virtual void OnRtpPacket(RTC::RtpReceiver* rtpReceiver, RTC::RtpPacket* packet) = 0;
virtual void OnRtpReceiverClosed(const RTC::RtpReceiver* rtpReceiver) = 0;
};
public:
......@@ -44,7 +44,7 @@ namespace RTC
public:
void Destroy();
Json::Value toJson() const;
Json::Value ToJson() const;
void HandleRequest(Channel::Request* request);
void SetTransport(RTC::Transport* transport);
RTC::Transport* GetTransport() const;
......@@ -63,29 +63,28 @@ 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 onPliRequired(RTC::RtpStreamRecv* rtpStream) override;
void OnNackRequired(RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) override;
void OnPliRequired(RTC::RtpStreamRecv* rtpStream) override;
public:
// Passed by argument.
uint32_t rtpReceiverId;
uint32_t rtpReceiverId{ 0 };
RTC::Media::Kind kind;
private:
// Passed by argument.
Listener* listener = nullptr;
Channel::Notifier* notifier = nullptr;
RTC::Transport* transport = nullptr;
Listener* listener{ nullptr };
Channel::Notifier* notifier{ nullptr };
RTC::Transport* transport{ nullptr };
// Allocated by this.
RTC::RtpParameters* rtpParameters = nullptr;
RTC::RtpParameters* rtpParameters{ nullptr };
std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams;
// Others.
bool rtpRawEventEnabled = false;
bool rtpObjectEventEnabled = false;
bool rtpRawEventEnabled{ false };
bool rtpObjectEventEnabled{ false };
// Timestamp when last RTCP was sent.
uint64_t lastRtcpSentTime = 0;
uint16_t maxRtcpInterval;
uint64_t lastRtcpSentTime{ 0 };
uint16_t maxRtcpInterval{ 0 };
};
/* Inline methods. */
......@@ -121,6 +120,6 @@ namespace RTC
rtpStream->ReceiveRtcpSenderReport(report);
}
}
}
} // namespace RTC
#endif
......@@ -27,7 +27,7 @@ namespace RTC
class Listener
{
public:
virtual void onRtpSenderClosed(RtpSender* rtpSender) = 0;
virtual void OnRtpSenderClosed(RtpSender* rtpSender) = 0;
};
public:
......@@ -39,7 +39,7 @@ namespace RTC
public:
void Destroy();
Json::Value toJson() const;
Json::Value ToJson() const;
void HandleRequest(Channel::Request* request);
void SetPeerCapabilities(RTC::RtpCapabilities* peerCapabilities);
void Send(RTC::RtpParameters* rtpParameters);
......@@ -61,27 +61,27 @@ namespace RTC
public:
// Passed by argument.
uint32_t rtpSenderId;
uint32_t rtpSenderId{ 0 };
RTC::Media::Kind kind;
private:
// Passed by argument.
Listener* listener = nullptr;
Channel::Notifier* notifier = nullptr;
RTC::Transport* transport = nullptr;
RTC::RtpCapabilities* peerCapabilities = nullptr;
Listener* listener{ nullptr };
Channel::Notifier* notifier{ nullptr };
RTC::Transport* transport{ nullptr };
RTC::RtpCapabilities* peerCapabilities{ nullptr };
// Allocated by this.
RTC::RtpParameters* rtpParameters = nullptr;
RTC::RtpStreamSend* rtpStream = nullptr;
RTC::RtpParameters* rtpParameters{ nullptr };
RTC::RtpStreamSend* rtpStream{ nullptr };
// Others.
std::unordered_set<uint8_t> supportedPayloadTypes;
// Whether this RtpSender is valid according to Peer capabilities.
bool available = false;
bool available{ false };
// Whether this RtpSender has been disabled by the app.
bool disabled = false;
bool disabled{ false };
// Timestamp when last RTCP was sent.
uint64_t lastRtcpSentTime = 0;
uint16_t maxRtcpInterval;
uint64_t lastRtcpSentTime{ 0 };
uint16_t maxRtcpInterval{ 0 };
// RTP counters.
RTC::RtpDataCounter transmittedCounter;
// TODO: keep track of retransmitted data too.
......@@ -130,6 +130,6 @@ namespace RTC
{
return this->transmittedCounter.GetRate(now);
}
}
} // namespace RTC
#endif
......@@ -13,22 +13,22 @@ namespace RTC
public:
struct Params
{
Json::Value toJson() const;
Json::Value ToJson() const;
uint32_t ssrc = 0;
uint8_t payloadType = 0;
uint32_t ssrc{ 0 };
uint8_t payloadType{ 0 };
RTC::RtpCodecMime mime;
uint32_t clockRate = 0;
bool useNack = false;
bool usePli = false;
uint8_t absSendTimeId = 0; // 0 means no abs-send-time id.
uint32_t clockRate{ 0 };
bool useNack{ false };
bool usePli{ false };
uint8_t absSendTimeId{ 0 }; // 0 means no abs-send-time id.
};
public:
explicit RtpStream(RTC::RtpStream::Params& params);
virtual ~RtpStream();
virtual Json::Value toJson() const = 0;
virtual Json::Value ToJson() const = 0;
uint32_t GetSsrc();
virtual bool ReceivePacket(RTC::RtpPacket* packet);
......@@ -38,24 +38,24 @@ namespace RTC
/* Pure virtual methods that must be implemented by the subclass. */
protected:
virtual void onInitSeq() = 0;
virtual void OnInitSeq() = 0;
protected:
// Given as argument.
RtpStream::Params params;
// Others.
bool started = false; // Whether at least a RTP packet has been received.
bool started{ false }; // Whether at least a RTP packet has been received.
// https://tools.ietf.org/html/rfc3550#appendix-A.1 stuff.
uint16_t maxSeq = 0; // Highest seq. number seen.
uint32_t cycles = 0; // Shifted count of seq. number cycles.
uint32_t baseSeq = 0; // Base seq number.
uint32_t badSeq = 0; // Last 'bad' seq number + 1.
uint32_t probation = 0; // Seq. packets till source is valid.
uint32_t received = 0; // Packets received.
uint32_t expectedPrior = 0; // Packet expected at last interval.
uint32_t receivedPrior = 0; // Packet received at last interval.
uint16_t maxSeq{ 0 }; // Highest seq. number seen.
uint32_t cycles{ 0 }; // Shifted count of seq. number cycles.
uint32_t baseSeq{ 0 }; // Base seq number.
uint32_t badSeq{ 0 }; // Last 'bad' seq number + 1.
uint32_t probation{ 0 }; // Seq. packets till source is valid.
uint32_t received{ 0 }; // Packets received.
uint32_t expectedPrior{ 0 }; // Packet expected at last interval.
uint32_t receivedPrior{ 0 }; // Packet received at last interval.
// Others.
uint32_t maxTimestamp = 0; // Highest timestamp seen.
uint32_t maxTimestamp{ 0 }; // Highest timestamp seen.
};
/* Inline instance methods. */
......@@ -64,6 +64,6 @@ namespace RTC
{
return this->params.ssrc;
}
}
} // namespace RTC
#endif
......@@ -14,17 +14,17 @@ namespace RTC
class Listener
{
public:
virtual void onNackRequired(
virtual void OnNackRequired(
RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) = 0;
virtual void onPliRequired(RTC::RtpStreamRecv* rtpStream) = 0;
virtual void OnPliRequired(RTC::RtpStreamRecv* rtpStream) = 0;
};
public:
RtpStreamRecv(Listener* listener, RTC::RtpStream::Params& params);
virtual ~RtpStreamRecv();
~RtpStreamRecv() override;
virtual Json::Value toJson() const override;
virtual bool ReceivePacket(RTC::RtpPacket* packet) override;
Json::Value ToJson() const override;
bool ReceivePacket(RTC::RtpPacket* packet) override;
RTC::RTCP::ReceiverReport* GetRtcpReceiverReport();
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void RequestFullFrame();
......@@ -34,25 +34,25 @@ namespace RTC
/* Pure virtual methods inherited from RtpStream. */
protected:
virtual void onInitSeq() override;
void OnInitSeq() override;
/* Pure virtual methods inherited from RTC::NackGenerator. */
protected:
virtual void onNackRequired(const std::vector<uint16_t>& seqNumbers) override;
virtual void onFullFrameRequired() override;
void OnNackRequired(const std::vector<uint16_t>& seqNumbers) override;
void OnFullFrameRequired() override;
private:
// Passed by argument.
Listener* listener = nullptr;
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 transit = 0; // Relative trans time for prev pkt.
uint32_t jitter = 0; // Estimated jitter.
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;
};
}
} // namespace RTC
#endif
......@@ -20,16 +20,16 @@ namespace RTC
private:
struct BufferItem
{
uint32_t seq32 = 0; // RTP seq in 32 bytes plus 16 bits cycles.
uint64_t resentAtTime = 0;
RTC::RtpPacket* packet = nullptr;
uint32_t seq32{ 0 }; // RTP seq in 32 bytes plus 16 bits cycles.
uint64_t resentAtTime{ 0 };
RTC::RtpPacket* packet{ nullptr };
};
public:
RtpStreamSend(RTC::RtpStream::Params& params, size_t bufferSize);
virtual ~RtpStreamSend();
~RtpStreamSend() override;
virtual Json::Value toJson() const override;
Json::Value ToJson() const override;
bool ReceivePacket(RTC::RtpPacket* packet) override;
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
void RequestRtpRetransmission(
......@@ -43,24 +43,24 @@ namespace RTC
/* Pure virtual methods inherited from RtpStream. */
protected:
virtual void onInitSeq() override;
void OnInitSeq() override;
private:
std::vector<StorageItem> storage;
typedef std::list<BufferItem> Buffer;
using Buffer = std::list<BufferItem>;
Buffer buffer;
private:
size_t receivedBytes = 0; // Bytes received.
uint64_t lastPacketTimeMs = 0; // Time (MS) when the last packet was received.
uint32_t lastPacketRtpTimestamp = 0; // RTP Timestamp of the last packet.
uint32_t rtt = 0; // Round trip time.
size_t receivedBytes{ 0 }; // Bytes received.
uint64_t lastPacketTimeMs{ 0 }; // Time (MS) when the last packet was received.
uint32_t lastPacketRtpTimestamp{ 0 }; // RTP Timestamp of the last packet.
uint32_t rtt{ 0 }; // Round trip time.
};
inline uint32_t RtpStreamSend::GetRtt() const
{
return this->rtt;
}
}
} // namespace RTC
#endif
......@@ -27,7 +27,7 @@ namespace RTC
static void ClassInit();
private:
static void onSrtpEvent(srtp_event_data_t* data);
static void OnSrtpEvent(srtp_event_data_t* data);
public:
SrtpSession(Type type, Profile profile, uint8_t* key, size_t keyLen);
......@@ -45,15 +45,15 @@ namespace RTC
private:
// Allocated by this.
srtp_t session = nullptr;
srtp_t session{ nullptr };
};
/* Inline instance methods. */
inline void SrtpSession::RemoveStream(uint32_t ssrc)
{
srtp_remove_stream(this->session, htonl(ssrc));
srtp_remove_stream(this->session, uint32_t{ htonl(ssrc) });
}
}
} // namespace RTC
#endif
......@@ -12,44 +12,44 @@ namespace RTC
// STUN message class.
enum class Class : uint16_t
{
Request = 0,
Indication = 1,
SuccessResponse = 2,
ErrorResponse = 3
REQUEST = 0,
INDICATION = 1,
SUCCESS_RESPONSE = 2,
ERROR_RESPONSE = 3
};
// STUN message method.
enum class Method : uint16_t
{
Binding = 1
BINDING = 1
};
// Attribute type.
enum class Attribute : uint16_t
{
MappedAddress = 0x0001,
Username = 0x0006,
MessageIntegrity = 0x0008,
ErrorCode = 0x0009,
UnknownAttributes = 0x000A,
Realm = 0x0014,
Nonce = 0x0015,
XorMappedAddress = 0x0020,
Priority = 0x0024,
UseCandidate = 0x0025,
Software = 0x8022,
AlternateServer = 0x8023,
Fingerprint = 0x8028,
IceControlled = 0x8029,
IceControlling = 0x802A
MAPPED_ADDRESS = 0x0001,
USERNAME = 0x0006,
MESSAGE_INTEGRITY = 0x0008,
ERROR_CODE = 0x0009,
UNKNOWN_ATTRIBUTES = 0x000A,
REALM = 0x0014,
NONCE = 0x0015,
XOR_MAPPED_ADDRESS = 0x0020,
PRIORITY = 0x0024,
USE_CANDIDATE = 0x0025,
SOFTWARE = 0x8022,
ALTERNATE_SERVER = 0x8023,
FINGERPRINT = 0x8028,
ICE_CONTROLLED = 0x8029,
ICE_CONTROLLING = 0x802A
};
// Authentication result.
enum class Authentication
{
OK = 0,
Unauthorized = 1,
BadRequest = 2
UNAUTHORIZED = 1,
BAD_REQUEST = 2
};
public:
......@@ -70,9 +70,9 @@ namespace RTC
const uint8_t* GetData() const;
size_t GetSize() const;
void SetUsername(const char* username, size_t len);
void SetPriority(const uint32_t priority);
void SetIceControlling(const uint64_t iceControlling);
void SetIceControlled(const uint64_t iceControlled);
void SetPriority(uint32_t priority);
void SetIceControlling(uint64_t iceControlling);
void SetIceControlled(uint64_t iceControlled);
void SetUseCandidate();
void SetXorMappedAddress(const struct sockaddr* xorMappedAddress);
void SetErrorCode(uint16_t errorCode);
......@@ -95,21 +95,21 @@ namespace RTC
private:
// Passed by argument.
Class klass; // 2 bytes.
Method method; // 2 bytes.
const uint8_t* transactionId = nullptr; // 12 bytes.
uint8_t* data = nullptr; // Pointer to binary data.
size_t size = 0; // The full message size (including header).
Class klass; // 2 bytes.
Method method; // 2 bytes.
const uint8_t* transactionId{ nullptr }; // 12 bytes.
uint8_t* data{ nullptr }; // Pointer to binary data.
size_t size{ 0 }; // The full message size (including header).
// STUN attributes.
std::string username; // Less than 513 bytes.
uint32_t priority = 0; // 4 bytes unsigned integer.
uint64_t iceControlling = 0; // 8 bytes unsigned integer.
uint64_t iceControlled = 0; // 8 bytes unsigned integer.
bool hasUseCandidate = false; // 0 bytes.
const uint8_t* messageIntegrity = nullptr; // 20 bytes.
bool hasFingerprint = false; // 4 bytes.
const struct sockaddr* xorMappedAddress = nullptr; // 8 or 20 bytes.
uint16_t errorCode = 0; // 4 bytes (no reason phrase).
std::string username; // Less than 513 bytes.
uint32_t priority{ 0 }; // 4 bytes unsigned integer.
uint64_t iceControlling{ 0 }; // 8 bytes unsigned integer.
uint64_t iceControlled{ 0 }; // 8 bytes unsigned integer.
bool hasUseCandidate{ false }; // 0 bytes.
const uint8_t* messageIntegrity{ nullptr }; // 20 bytes.
bool hasFingerprint{ false }; // 4 bytes.
const struct sockaddr* xorMappedAddress{ nullptr }; // 8 or 20 bytes.
uint16_t errorCode{ 0 }; // 4 bytes (no reason phrase).
std::string password;
};
......@@ -240,6 +240,6 @@ namespace RTC
{
return this->hasFingerprint;
}
}
} // namespace RTC
#endif
......@@ -12,28 +12,28 @@ namespace RTC
class Listener
{
public:
virtual void onPacketRecv(RTC::TcpConnection* connection, const uint8_t* data, size_t len) = 0;
virtual void OnPacketRecv(RTC::TcpConnection* connection, const uint8_t* data, size_t len) = 0;
};
public:
TcpConnection(Listener* listener, size_t bufferSize);
private:
virtual ~TcpConnection(){};
~TcpConnection() override = default;
public:
void Send(const uint8_t* data, size_t len);
/* Pure virtual methods inherited from ::TcpConnection. */
public:
virtual void userOnTcpConnectionRead() override;
void UserOnTcpConnectionRead() override;
private:
// Passed by argument.
Listener* listener = nullptr;
Listener* listener{ nullptr };
// Others.
size_t frameStart = 0; // Where the latest frame starts.
size_t frameStart{ 0 }; // Where the latest frame starts.
};
}
} // namespace RTC
#endif
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
......@@ -5,8 +5,8 @@
/* Class variables. */
std::string Logger::id = "unset";
Channel::UnixStreamSocket* Logger::channel = nullptr;
std::string Logger::id{ "unset" };
Channel::UnixStreamSocket* Logger::channel{ nullptr };
char Logger::buffer[Logger::bufferSize];
/* Class methods. */
......
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论