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