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

Merge branch 'master' into unit_testing

# Building
This document is intended for **mediasoup** developers.
## Makefile
The root folder of the project contains a `Makefile` to build the mediasoup worker subproject (under the `worker/` folder).
### `make Release`
Builds the production ready mediasoup worker binary at `worker/out/Release/`. This is the binary used in production when installing the **mediasoup** NPM module with `npm install mediasoup`.
### `make Debug`
Builds a more verbose mediasoup and less optimized worker binary at `worker/out/Debug/` with some C flags enabled (such as `-g` and `-O0`) and some macros defined (such as `DEBUG`, `MS_LOG_FILE_LINE` and `MS_LOG_TRACE`).
Check the meaning of these macros in the [Logger.h](worker/include/Logger.h) header file.
In order to instruct the **mediasoup** Node.js module to use the `Debug` mediasoup worker binary, an environment variable must be set before running the Node.js application or the internal test units:
```bash
$ MEDIASOUP_BUILDTYPE=Debug node myapp.js
```
Or, in order to run the internal test units with the `Debug` mediasoup worker:
```bash
$ MEDIASOUP_BUILDTYPE=Debug gulp test-debug
```
### `make xcode`
Builds a Xcode project for the mediasoup worker subproject.
### `make clean`
Cleans objects and binaries related to the mediasoup worker.
### `make clean-all`
Clean all the objects and binaries, including those generated for library dependencies (such as libuv, openssl and libsrtp).
### `make`
The default task runs the `Release` task.
## gulpfile.js
**mediasoup** comes with a `gulpfile.js` file to enable [gulp](https://www.npmjs.com/package/gulp) tasks.
In order to tun these tasks, `gulp-cli` must be globally installed:
```bash
$ npm install -g gulp-cli
```
### `gulp lint`
Validates the JavaScript code.
### `gulp capabilities`
Reads **mediasoup** [media capabilities](https://github.com/ibc/mediasoup/blob/master/data/supportedCapabilities.js) and inserts them into the worker C++ code. After that, `make Release` or `make Debug` must be called.
### `gulp test`
Run the internal [test units](test/).
### `gulp test-debug`
Run the internal [test units](test/) in a more verbose fashion. Note however that running this task does not use the `Debug` mediasoup worker binary. If you wish to use it, set the `MEDIASOUP_BUILDTYPE` environment variable as explained above.
### `gulp`
The default task runs the `link` task.
......@@ -4,7 +4,7 @@
[![][travis-ci-shield-mediasoup]][travis-ci-mediasoup]
**Status:** Coming soon (check the project [milestones](https://github.com/ibc/mediasoup/milestones)).
**Status:** v1.0.0 coming soon.
## Website and documentation
......@@ -20,6 +20,8 @@ You can support **mediasoup** by making a donation [here][paypal-url]. Thanks!
## Installation
Within your Node.js application:
```bash
$ npm install mediasoup --save
```
......@@ -27,25 +29,26 @@ $ npm install mediasoup --save
## Design goals
* Be a Node.js module
* Be minimalist: just handle the media layer
* Expose a modern ECMAScript 6 [API](/api/) in sync with [ORTC](http://ortc.org/)
* Work with current [WebRTC](https://webrtc.org) client implementations
* Be a Node.js module.
* Be minimalist: just handle the media layer.
* Expose a modern ECMAScript 6 [API](/api/) in sync with [WebRTC 1.0](https://w3c.github.io/webrtc-pc/) and [ORTC](http://ortc.org/).
* Work with current WebRTC client implementations.
## Features
* Multiple conference rooms with multiple participants
* IPv6 ready
* ICE / DTLS / RTP / RTCP over UDP and TCP
* Extremely powerful (media handler subprocess coded in C++ on top of [libuv](http://libuv.org))
* Can handle RTP packets in JavaScript land
* Multiple conference rooms with multiple participants.
* IPv6 ready.
* ICE / DTLS / RTP / RTCP over UDP and TCP.
* Extremely powerful (media worker subprocess coded in C++ on top of [libuv](http://libuv.org)).
* Can handle RTP packets in JavaScript land.
## Requirements
* Node.js >= `v4.0.0`
* POSIX based operating system (Windows not yet supported)
* `Python` 2
* `make`
* `gcc` or `clang` with C++11 support
......
......@@ -47,10 +47,6 @@ gulp.task('capabilities', () =>
.pipe(touch());
});
gulp.task('worker', shell.task(
[ 'make' ]
));
gulp.task('test', shell.task(
[ `tap --bail --color --reporter=spec ${tests.join(' ')}` ],
{
......@@ -61,15 +57,9 @@ gulp.task('test', shell.task(
gulp.task('test-debug', shell.task(
[ `tap --bail --reporter=tap ${tests.join(' ')}` ],
{
env : { DEBUG: '*ERROR* *WARN*' },
env : { DEBUG: '*WARN* *ERROR* *ABORT*' },
verbose : true
}
));
gulp.task('t', gulp.series('test'));
gulp.task('td', gulp.series('test-debug'));
gulp.task('make', gulp.series('capabilities', 'worker'));
gulp.task('default', gulp.series('lint'));
......@@ -12,8 +12,14 @@ const Worker = require('./Worker');
const DEFAULT_NUM_WORKERS = Object.keys(os.cpus()).length;
const VALID_WORKER_PARAMETERS =
[
'logLevel', 'rtcListenIPv4', 'rtcListenIPv6', 'rtcMinPort', 'rtcMaxPort',
'dtlsCertificateFile', 'dtlsPrivateKeyFile'
'logLevel',
'logTags',
'rtcListenIPv4',
'rtcListenIPv6',
'rtcMinPort',
'rtcMaxPort',
'dtlsCertificateFile',
'dtlsPrivateKeyFile'
];
class Server extends EventEmitter
......@@ -43,6 +49,9 @@ class Server extends EventEmitter
if (check.integer(options.numWorkers) && check.positive(options.numWorkers))
numWorkers = options.numWorkers;
if (!check.array(options.logTags))
options.logTags = [];
if (options.rtcListenIPv4 === null || options.rtcListenIPv4 === undefined)
delete options.rtcListenIPv4;
......@@ -71,8 +80,25 @@ class Server extends EventEmitter
for (let key of Object.keys(options))
{
if (check.includes(VALID_WORKER_PARAMETERS, key))
parameters.push(`--${key}=${String(options[key])}`);
if (!check.includes(VALID_WORKER_PARAMETERS, key))
{
logger.warn('ignoring unknown option "%s"', key);
continue;
}
switch (key)
{
case 'logTags':
for (let tag of options.logTags)
{
parameters.push(`--logTag=${String(tag)}`);
}
break;
default:
parameters.push(`--${key}=${String(options[key])}`);
}
}
// Create Worker instances.
......
......@@ -18,10 +18,11 @@ module.exports =
/**
* Create a Server instance.
*
* @param {Object} [options]
* @param {object} [options]
* @param {number} [options.numWorkers=HOST_NUM_CORES] - Number of child workers.
* @param {string} [options.logLevel='debug'] - Log level. Valid values are
* 'debug', 'warn', 'error'.
* @param {array} [options.logTags] - Log tags.
* @param {string|boolean} [options.rtcListenIPv4=true] - IPv4 for RTC. Valid
* values are a IPv4, `true` (auto-detect) and `false` (disabled).
* @param {string|boolean} [options.rtcListenIPv6=true] - IPv6 for RTC. Valid
......
{
"name": "mediasoup",
"version": "0.3.0-pre1",
"version": "0.3.0-pre2",
"description": "Powerful WebRTC SFU for Node.js",
"main": "lib/mediasoup.js",
"repository": {
......
......@@ -25,7 +25,7 @@
},
'Debug':
{
'defines': [ ' MS_DEVEL', 'DEBUG' ],
'defines': [ 'DEBUG', 'MS_LOG_FILE_LINE', 'MS_LOG_TRACE' ],
'cflags': [ '-g', '-O0', '-fwrapv', '-Wno-parentheses-equality' ],
'xcode_settings':
{
......
/**
* Logger facility.
*
* This include file defines logging macros for source files (.cpp). Each
* source file including Logger.h MUST define its own MS_CLASS macro. Include
* files (.h) MUST NOT include Logger.h.
*
* All the logging macros use the same format as printf(). The XXX_STD version
* of a macro logs to stdoud/stderr instead of using the Channel instance.
*
* If the macro MS_LOG_FILE_LINE is defied, all the logging macros print more
* verbose information, including current file and line.
*
* MS_TRACE()
* MS_TRACE_STD()
*
* Logs the current method/function if the current source file defines the
* MS_LOG_TRACE macro.
*
* MS_DEBUG_TAG(tag, ...)
* MS_WARN_TAG(tag, ...)
*
* Logs if the current debug level is satisfied and the given tag is enabled
* (or if the current source file defines the MS_LOG_DEV macro).
* Example:
* MS_WARN_TAG(ice, "ICE failed");
*
* MS_DEBUG_2TAGS(tag1, tag2, ...)
* MS_WARN_2TAGS(tag1, tag2, ...)
*
* Logs if the current debug level is satisfied and any of the given two tags
* is enabled (or if the current source file defines the MS_LOG_DEV macro).
* Example:
* MS_DEBUG_2TAGS(ice, dtls, "media connection established");
*
* MS_DEBUG_DEV(...)
* MS_WARN_DEV(...)
*
* Logs if the current source file defines the MS_LOG_DEV macro.
* Example:
* MS_DEBUG_DEV("Room closed [roomId:%" PRIu32 "]", roomId);
*
* MS_ERROR(...)
* MS_ERROR_STD(...)
*
* Logs an error. Must just be used for internal errors that should not
* happen.
*
* MS_ABORT(...)
*
* Logs the given error to stderr and aborts the process.
*
* MS_ASSERT(condition, ...)
*
* If the condition is not satisfied, it calls MS_ABORT().
*/
#ifndef MS_LOGGER_H
#define MS_LOGGER_H
......@@ -11,39 +68,18 @@
#include <cstdlib> // std::abort()
#define MS_LOGGER_BUFFER_SIZE 10000
/*
* Logger facility.
*
* If the macro MS_DEVEL is set (see below) the output is even more verbose
* (it shows the file number in each log and enables the MS_TRACE() call).
*
* Usage:
*
* - MS_TRACE() Shows current file/line/class/function.
* - MS_DEBUG(...)
* - MS_WARN(...)
* - MS_ERROR(...)
* - MS_ABORT(...)
*
* Arguments to those macros (except MS_TRACE) have the same format as printf.
*
* Examples:
*
* - MS_TRACE();
* - MS_DEBUG("starting worker %d", num);
*/
/*
* Call the compiler with -DMS_DEVEL for more verbose logs.
*/
// #define MS_DEVEL
#define _MS_TAG_ENABLED(tag) Settings::logTags.tag
#define _MS_TAG_ENABLED_2(tag1, tag2) (Settings::logTags.tag1 || Settings::logTags.tag2)
#ifdef MS_LOG_DEV
#define _MS_LOG_DEV_ENABLED true
#else
#define _MS_LOG_DEV_ENABLED false
#endif
class Logger
{
public:
static void Init(const std::string& id, Channel::UnixStreamSocket* channel);
static bool HasDebugLevel();
public:
static std::string id;
......@@ -51,21 +87,11 @@ public:
static char buffer[];
};
/* Inline static methods. */
inline
bool Logger::HasDebugLevel()
{
return (LogLevel::LOG_DEBUG == Settings::configuration.logLevel);
}
// NOTE: Each source file (.cpp) including Logger.h MUST define its own MS_CLASS
// macro.
// NOTE: Include files (.h) MUST NOT include Logger.h.
/* Logging macros. */
#define _MS_LOG_SEPARATOR_CHAR_STD "\n"
#ifdef MS_DEVEL
#ifdef MS_LOG_FILE_LINE
#define _MS_LOG_STR "[%s] %s:%d | %s::%s()"
#define _MS_LOG_STR_DESC _MS_LOG_STR " | "
#define _MS_FILE (std::strchr(__FILE__, '/') ? std::strchr(__FILE__, '/') + 1 : __FILE__)
......@@ -76,88 +102,127 @@ bool Logger::HasDebugLevel()
#define _MS_LOG_ARG ("id:" + Logger::id).c_str(), MS_CLASS, __FUNCTION__
#endif
#ifdef MS_DEVEL
#define MS_TRACE() \
do \
{ \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D(trace) " _MS_LOG_STR, _MS_LOG_ARG); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
} \
while (0)
#define MS_TRACE_STD() \
do \
{ \
std::fprintf(stdout, "(trace) " _MS_LOG_STR _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG); \
std::fflush(stdout); \
} \
while (0)
#ifdef MS_LOG_TRACE
#define MS_TRACE() \
do \
{ \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D(trace) " _MS_LOG_STR, _MS_LOG_ARG); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
} \
while (0)
#define MS_TRACE_STD() \
do \
{ \
std::fprintf(stdout, "(trace) " _MS_LOG_STR _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG); \
std::fflush(stdout); \
} \
while (0)
#else
#define MS_TRACE()
#define MS_TRACE_STD()
#define MS_TRACE()
#define MS_TRACE_STD()
#endif
#define MS_DEBUG(desc, ...) \
do \
{ \
if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel) \
{ \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
} \
} \
#define MS_DEBUG_TAG(tag, desc, ...) \
do \
{ \
if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel && (_MS_TAG_ENABLED(tag) || _MS_LOG_DEV_ENABLED)) \
{ \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
} \
} \
while (0)
#define MS_DEBUG_STD(desc, ...) \
do \
{ \
if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel) \
{ \
std::fprintf(stdout, _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG, ##__VA_ARGS__); \
std::fflush(stdout); \
} \
} \
#define MS_WARN_TAG(tag, desc, ...) \
do \
{ \
if (LogLevel::LOG_WARN <= Settings::configuration.logLevel && (_MS_TAG_ENABLED(tag) || _MS_LOG_DEV_ENABLED)) \
{ \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
} \
} \
while (0)
#define MS_WARN(desc, ...) \
do \
{ \
if (LogLevel::LOG_WARN <= Settings::configuration.logLevel) \
{ \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
} \
} \
#define MS_DEBUG_2TAGS(tag1, tag2, desc, ...) \
do \
{ \
if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel && (_MS_TAG_ENABLED_2(tag1, tag2) || _MS_LOG_DEV_ENABLED)) \
{ \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
} \
} \
while (0)
#define MS_ERROR(desc, ...) \
do \
{ \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "E" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
} \
#define MS_WARN_2TAGS(tag1, tag2, desc, ...) \
do \
{ \
if (LogLevel::LOG_WARN <= Settings::configuration.logLevel && (_MS_TAG_ENABLED_2(tag1, tag2) || _MS_LOG_DEV_ENABLED)) \
{ \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
} \
} \
while (0)
#ifdef MS_LOG_DEV
#define MS_DEBUG_DEV(desc, ...) \
do \
{ \
if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel) \
{ \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
} \
} \
while (0)
#define MS_WARN_DEV(desc, ...) \
do \
{ \
if (LogLevel::LOG_WARN <= Settings::configuration.logLevel) \
{ \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
} \
} \
while (0)
#else
#define MS_DEBUG_DEV(desc, ...)
#define MS_WARN_DEV(desc, ...)
#endif
#define MS_ERROR(desc, ...) \
do \
{ \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "E" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
} \
while (0)
#define MS_ERROR_STD(desc, ...) \
do \
{ \
std::fprintf(stderr, _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG, ##__VA_ARGS__); \
std::fflush(stderr); \
} \
#define MS_ERROR_STD(desc, ...) \
do \
{ \
std::fprintf(stderr, _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG, ##__VA_ARGS__); \
std::fflush(stderr); \
} \
while (0)
#define MS_ABORT(desc, ...) \
do \
{ \
std::fprintf(stderr, "ABORT" _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG, ##__VA_ARGS__); \
std::fflush(stderr); \
std::abort(); \
} \
#define MS_ABORT(desc, ...) \
do \
{ \
std::fprintf(stderr, "ABORT" _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG, ##__VA_ARGS__); \
std::fflush(stderr); \
std::abort(); \
} \
while (0)
#define MS_ASSERT(condition, desc, ...) \
if (!(condition)) \
{ \
MS_ABORT("failed assertion `%s': " desc, #condition, ##__VA_ARGS__); \
#define MS_ASSERT(condition, desc, ...) \
if (!(condition)) \
{ \
MS_ABORT("failed assertion `%s': " desc, #condition, ##__VA_ARGS__); \
}
#ifdef MS_LOG_STD
......
......@@ -17,7 +17,7 @@ namespace RTC { namespace RTCP
uint32_t ssrc;
uint32_t fraction_lost:8;
uint32_t total_lost:24;
uint32_t last_sec;
uint32_t last_seq;
uint32_t jitter;
uint32_t lsr;
uint32_t dlsr;
......@@ -46,8 +46,8 @@ namespace RTC { namespace RTCP
void SetFractionLost(uint8_t fraction_lost);
int32_t GetTotalLost();
void SetTotalLost(int32_t total_lost);
uint32_t GetLastSec();
void SetLastSec(uint32_t last_sec);
uint32_t GetLastSeq();
void SetLastSeq(uint32_t last_seq);
uint32_t GetJitter();
void SetJitter(uint32_t jitter);
uint32_t GetLastSenderReport();
......@@ -161,15 +161,15 @@ namespace RTC { namespace RTCP
}
inline
uint32_t ReceiverReport::GetLastSec()
uint32_t ReceiverReport::GetLastSeq()
{
return (uint32_t)ntohl(this->header->last_sec);
return (uint32_t)ntohl(this->header->last_seq);
}
inline
void ReceiverReport::SetLastSec(uint32_t last_sec)
void ReceiverReport::SetLastSeq(uint32_t last_seq)
{
this->header->last_sec = (uint32_t)htonl(last_sec);
this->header->last_seq = (uint32_t)htonl(last_seq);
}
inline
......
......@@ -31,7 +31,7 @@ namespace RTC { namespace RTCP
{
uint8_t type;
uint8_t length;
char value[];
char value[];
};
public:
......
......@@ -6,7 +6,7 @@
#include "Channel/Request.h"
#include <map>
#include <string>
#include <vector>
class Settings
{
......@@ -17,8 +17,8 @@ public:
LogLevel logLevel { LogLevel::LOG_DEBUG };
std::string rtcListenIPv4;
std::string rtcListenIPv6;
uint16_t rtcMinPort { 10000 };
uint16_t rtcMaxPort { 59999 };
uint16_t rtcMinPort { 10000 };
uint16_t rtcMaxPort { 59999 };
std::string dtlsCertificateFile;
std::string dtlsPrivateKeyFile;
// Private fields.
......@@ -26,6 +26,19 @@ public:
bool hasIPv6 { false };
};
public:
// Log tags.
struct LogTags
{
bool info { false };
bool ice { false };
bool dtls { false };
bool rtp { false };
bool srtp { false };
bool rtcp { false };
// TODO: Add more tags (here and in Settings.cpp).
};
public:
static void SetConfiguration(int argc, char* argv[]);
static void PrintConfiguration();
......@@ -38,9 +51,12 @@ private:
static void SetRtcListenIPv6(const std::string &ip);
static void SetRtcPorts();
static void SetDtlsCertificateAndPrivateKeyFiles();
static void SetLogTags(std::vector<std::string>& tags);
static void SetLogTags(Json::Value& json);
public:
static struct Configuration configuration;
static struct LogTags logTags;
private:
static std::map<std::string, LogLevel> string2LogLevel;
......
#define MS_CLASS "Channel::Notifier"
// #define MS_LOG_DEV
#include "Channel/Notifier.h"
#include "Logger.h"
......
#define MS_CLASS "Channel::Request"
// #define MS_LOG_DEV
#include "Channel/Request.h"
#include "MediaSoupError.h"
......
#define MS_CLASS "Channel::UnixStreamSocket"
// #define MS_LOG_DEV
#include "Channel/UnixStreamSocket.h"
#include "Logger.h"
#include "MediaSoupError.h"
#include <sstream> // std::ostringstream
#include <cstring> // std::memmove()
#include <cmath> // std::ceil()
#include <cstdio> // sprintf()
#include <sstream> // std::ostringstream
#include <cstring> // std::memmove()
#include <cmath> // std::ceil()
#include <cstdio> // sprintf()
extern "C"
{
#include <netstring.h>
......@@ -210,8 +211,6 @@ namespace Channel
switch (ns_ret)
{
case NETSTRING_ERROR_TOO_SHORT:
// MS_DEBUG_STD("received netstring is too short, need more data");
// Check if the buffer is full.
if (this->bufferDataLen == this->bufferSize)
{
......@@ -219,8 +218,6 @@ namespace Channel
// the buffer, so move the incomplete message to the position 0.
if (this->msgStart != 0)
{
// MS_DEBUG_STD("no more space in the buffer, moving parsed bytes to the beginning of the buffer and waiting for more data");
std::memmove(this->buffer, this->buffer + this->msgStart, read_len);
this->msgStart = 0;
this->bufferDataLen = read_len;
......@@ -306,8 +303,6 @@ namespace Channel
// the latest parsed message filled it, then empty the full buffer.
if ((this->msgStart + read_len) == this->bufferSize)
{
// MS_DEBUG_STD("no more space in the buffer, emptying the buffer data");
this->msgStart = 0;
this->bufferDataLen = 0;
}
......@@ -322,8 +317,6 @@ namespace Channel
// then parse again. Otherwise break here and wait for more data.
if (this->bufferDataLen > this->msgStart)
{
// MS_DEBUG_STD("there is more data after the parsed message, continue parsing");
continue;
}
else
......
#define MS_CLASS "DepLibSRTP"
// #define MS_LOG_DEV
#include "DepLibSRTP.h"
#include "MediaSoupError.h"
......@@ -44,7 +45,7 @@ void DepLibSRTP::ClassInit()
srtp_err_status_t err;
MS_DEBUG("loaded libsrtp version: %s", srtp_get_version_string());
MS_DEBUG_TAG(info, "loaded libsrtp version: %s", srtp_get_version_string());
err = srtp_init();
if (DepLibSRTP::IsError(err))
......
#define MS_CLASS "DepLibUV"
// #define MS_LOG_DEV
#include "DepLibUV.h"
#include "Logger.h"
#include <cstdlib> // std::abort()
#include <cstdlib> // std::abort()
/* Static variables. */
......@@ -38,7 +39,7 @@ void DepLibUV::PrintVersion()
{
MS_TRACE();
MS_DEBUG("loaded libuv version: %s", uv_version_string());
MS_DEBUG_TAG(info, "loaded libuv version: %s", uv_version_string());
}
void DepLibUV::RunLoop()
......
#define MS_CLASS "DepOpenSSL"
// #define MS_LOG_DEV
#include "DepOpenSSL.h"
#include "MediaSoupError.h"
#include "Logger.h"
#include <openssl/err.h>
#include <openssl/engine.h> // ENGINE_cleanup()
#include <openssl/engine.h> // ENGINE_cleanup()
/* Static attributes. */
......@@ -18,7 +19,7 @@ void DepOpenSSL::ClassInit()
{
MS_TRACE();
MS_DEBUG("loaded openssl version: %s", SSLeay_version(SSLEAY_VERSION));
MS_DEBUG_TAG(info, "loaded openssl version: %s", SSLeay_version(SSLEAY_VERSION));
// Initialize OpenSSL stuff.
SSL_load_error_strings();
......@@ -105,7 +106,7 @@ void DepOpenSSL::LockingFunction(int mode, int n, const char *file, int line)
* - line: line in the source file calling this function.
*/
// MS_DEBUG("[mode: %s+%s, mutex id: %d, file: %s, line: %d]", mode & CRYPTO_LOCK ? "LOCK" : "UNLOCK", mode & CRYPTO_READ ? "READ" : "WRITE", n, file, line);
// MS_DEBUG_DEV("[mode: %s+%s, mutex id: %d, file: %s, line: %d]", mode & CRYPTO_LOCK ? "LOCK" : "UNLOCK", mode & CRYPTO_READ ? "READ" : "WRITE", n, file, line);
if (mode & CRYPTO_LOCK)
uv_mutex_lock(&DepOpenSSL::mutexes[n]);
......
#define MS_CLASS "DepUsrSCTP"
// #define MS_LOG_DEV
#include "DepUsrSCTP.h"
#include "Logger.h"
......
#define MS_CLASS "Logger"
// #define MS_LOG_DEV
#include "Logger.h"
......
#define MS_CLASS "Loop"
// #define MS_LOG_DEV
#include "Loop.h"
#include "DepLibUV.h"
......@@ -6,9 +7,9 @@
#include "MediaSoupError.h"
#include "Logger.h"
#include <string>
#include <utility> // std::pair()
#include <utility> // std::pair()
#include <cerrno>
#include <iostream> // std::cout, std::cerr
#include <iostream> // std::cout, std::cerr
#include <json/json.h>
/* Instance methods. */
......@@ -31,9 +32,9 @@ Loop::Loop(Channel::UnixStreamSocket* channel) :
this->signalsHandler->AddSignal(SIGINT, "INT");
this->signalsHandler->AddSignal(SIGTERM, "TERM");
MS_DEBUG("starting libuv loop");
MS_DEBUG_DEV("starting libuv loop");
DepLibUV::RunLoop();
MS_DEBUG("libuv loop ended");
MS_DEBUG_DEV("libuv loop ended");
}
Loop::~Loop()
......@@ -112,17 +113,17 @@ void Loop::onSignal(SignalsHandler* signalsHandler, int signum)
switch (signum)
{
case SIGINT:
MS_DEBUG("signal INT received, exiting");
MS_DEBUG_DEV("signal INT received, exiting");
Close();
break;
case SIGTERM:
MS_DEBUG("signal TERM received, exiting");
MS_DEBUG_DEV("signal TERM received, exiting");
Close();
break;
default:
MS_WARN("received a signal (with signum %d) for which there is no handling code", signum);
MS_WARN_DEV("received a signal (with signum %d) for which there is no handling code", signum);
}
}
......@@ -130,7 +131,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
{
MS_TRACE();
MS_DEBUG("'%s' request", request->method.c_str());
MS_DEBUG_DEV("'%s' request", request->method.c_str());
switch (request->methodId)
{
......@@ -199,7 +200,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
this->rooms[roomId] = room;
MS_DEBUG("Room created [roomId:%" PRIu32 "]", roomId);
MS_DEBUG_DEV("Room created [roomId:%" PRIu32 "]", roomId);
Json::Value data(Json::objectValue);
......@@ -271,8 +272,8 @@ void Loop::onChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* so
// If the pipe is remotely closed it means that mediasoup Node process
// abruptly died (SIGKILL?) so we must die.
MS_ERROR_STD("Channel remotely closed, killing myself");
this->channel = nullptr;
this->channel = nullptr;
Close();
}
......
#define MS_CLASS "RTC::IceCandidate"
// #define MS_LOG_DEV
#include "RTC/IceCandidate.h"
......
#define MS_CLASS "RTC::IceServer"
// #define MS_LOG_DEV
#include "RTC/IceServer.h"
#include "Logger.h"
......@@ -14,7 +15,7 @@ namespace RTC
{
MS_TRACE();
MS_DEBUG("[usernameFragment:%s, password:%s]", this->usernameFragment.c_str(), this->password.c_str());
MS_DEBUG_TAG(ice, "[usernameFragment:%s, password:%s]", this->usernameFragment.c_str(), this->password.c_str());
}
void IceServer::Close()
......@@ -33,7 +34,7 @@ namespace RTC
{
if (msg->GetClass() == RTC::StunMessage::Class::Request)
{
MS_DEBUG("unknown method %#.3x in STUN Request => 400", (unsigned int)msg->GetMethod());
MS_WARN_TAG(ice, "unknown method %#.3x in STUN Request => 400", (unsigned int)msg->GetMethod());
// Reply 400.
RTC::StunMessage* response = msg->CreateErrorResponse(400);
......@@ -43,7 +44,7 @@ namespace RTC
}
else
{
MS_DEBUG("ignoring STUN Indication or Response with unknown method %#.3x", (unsigned int)msg->GetMethod());
MS_WARN_TAG(ice, "ignoring STUN Indication or Response with unknown method %#.3x", (unsigned int)msg->GetMethod());
}
return;
......@@ -54,7 +55,7 @@ namespace RTC
{
if (msg->GetClass() == RTC::StunMessage::Class::Request)
{
MS_DEBUG("STUN Binding Request without FINGERPRINT => 400");
MS_WARN_TAG(ice, "STUN Binding Request without FINGERPRINT => 400");
// Reply 400.
RTC::StunMessage* response = msg->CreateErrorResponse(400);
......@@ -64,7 +65,7 @@ namespace RTC
}
else
{
MS_DEBUG("ignoring STUN Binding Response without FINGERPRINT");
MS_WARN_TAG(ice, "ignoring STUN Binding Response without FINGERPRINT");
}
return;
......@@ -77,7 +78,7 @@ namespace RTC
// USERNAME, MESSAGE-INTEGRITY and PRIORITY are required.
if (!msg->HasMessageIntegrity() || !msg->GetPriority() || msg->GetUsername().empty())
{
MS_DEBUG("mising required attributes in STUN Binding Request => 400");
MS_WARN_TAG(ice, "mising required attributes in STUN Binding Request => 400");
// Reply 400.
RTC::StunMessage* response = msg->CreateErrorResponse(400);
......@@ -96,7 +97,7 @@ namespace RTC
case RTC::StunMessage::Authentication::Unauthorized:
{
MS_DEBUG("wrong authentication in STUN Binding Request => 401");
MS_WARN_TAG(ice, "wrong authentication in STUN Binding Request => 401");
// Reply 401.
RTC::StunMessage* response = msg->CreateErrorResponse(401);
......@@ -109,7 +110,7 @@ namespace RTC
case RTC::StunMessage::Authentication::BadRequest:
{
MS_DEBUG("cannot check authentication in STUN Binding Request => 400");
MS_WARN_TAG(ice, "cannot check authentication in STUN Binding Request => 400");
// Reply 400.
RTC::StunMessage* response = msg->CreateErrorResponse(400);
......@@ -124,7 +125,7 @@ namespace RTC
// The remote peer must be ICE controlling.
if (msg->GetIceControlled())
{
MS_DEBUG("peer indicates ICE-CONTROLLED in STUN Binding Request => 487");
MS_WARN_TAG(ice, "peer indicates ICE-CONTROLLED in STUN Binding Request => 487");
// Reply 487 (Role Conflict).
RTC::StunMessage* response = msg->CreateErrorResponse(487);
......@@ -135,8 +136,7 @@ namespace RTC
return;
}
// TODO: yes or no
// MS_DEBUG("processing STUN Binding Request [Priority:%" PRIu32 ", UseCandidate:%s]", (uint32_t)msg->GetPriority(), msg->HasUseCandidate() ? "true" : "false");
MS_DEBUG_TAG(ice, "processing STUN Binding Request [Priority:%" PRIu32 ", UseCandidate:%s]", (uint32_t)msg->GetPriority(), msg->HasUseCandidate() ? "true" : "false");
// Create a success response.
RTC::StunMessage* response = msg->CreateSuccessResponse();
......@@ -160,21 +160,21 @@ namespace RTC
case RTC::StunMessage::Class::Indication:
{
MS_DEBUG("STUN Binding Indication processed");
MS_DEBUG_TAG(ice, "STUN Binding Indication processed");
break;
}
case RTC::StunMessage::Class::SuccessResponse:
{
MS_DEBUG("STUN Binding Success Response processed");
MS_DEBUG_TAG(ice, "STUN Binding Success Response processed");
break;
}
case RTC::StunMessage::Class::ErrorResponse:
{
MS_DEBUG("STUN Binding Error Response processed");
MS_DEBUG_TAG(ice, "STUN Binding Error Response processed");
break;
}
......@@ -194,7 +194,7 @@ namespace RTC
RTC::TransportTuple* removed_tuple = nullptr;
// Find the removed tuple.
for (; it != this->tuples.end(); ++it)
for (; it != this->tuples.end(); it++)
{
RTC::TransportTuple* stored_tuple = std::addressof(*it);
......@@ -269,7 +269,7 @@ namespace RTC
if (!has_use_candidate)
{
MS_DEBUG("transition from state 'new' to 'connected'");
MS_DEBUG_TAG(ice, "transition from state 'new' to 'connected'");
// Store the tuple.
auto stored_tuple = AddTuple(tuple);
......@@ -285,7 +285,7 @@ namespace RTC
}
else
{
MS_DEBUG("transition from state 'new' to 'completed'");
MS_DEBUG_TAG(ice, "transition from state 'new' to 'completed'");
// Store the tuple.
auto stored_tuple = AddTuple(tuple);
......@@ -313,7 +313,7 @@ namespace RTC
if (!has_use_candidate)
{
MS_DEBUG("transition from state 'disconnected' to 'connected'");
MS_DEBUG_TAG(ice, "transition from state 'disconnected' to 'connected'");
// Store the tuple.
auto stored_tuple = AddTuple(tuple);
......@@ -329,7 +329,7 @@ namespace RTC
}
else
{
MS_DEBUG("transition from state 'disconnected' to 'completed'");
MS_DEBUG_TAG(ice, "transition from state 'disconnected' to 'completed'");
// Store the tuple.
auto stored_tuple = AddTuple(tuple);
......@@ -363,7 +363,7 @@ namespace RTC
}
else
{
MS_DEBUG("transition from state 'connected' to 'completed'");
MS_DEBUG_TAG(ice, "transition from state 'connected' to 'completed'");
auto stored_tuple = HasTuple(tuple);
......@@ -449,7 +449,7 @@ namespace RTC
return this->selectedTuple;
// Otherwise check other stored tuples.
for (auto it = this->tuples.begin(); it != this->tuples.end(); ++it)
for (auto it = this->tuples.begin(); it != this->tuples.end(); it++)
{
RTC::TransportTuple* stored_tuple = std::addressof(*it);
......
#define MS_CLASS "RTC::Peer"
// #define MS_LOG_DEV
#include "RTC/Peer.h"
#include "RTC/RtpDictionaries.h"
......@@ -135,11 +136,14 @@ namespace RTC
{
case Channel::Request::MethodId::peer_close:
{
#ifdef MS_LOG_DEV
uint32_t peerId = this->peerId;
#endif
Close();
MS_DEBUG("Peer closed [peerId:%" PRIu32 "]", peerId);
MS_DEBUG_DEV("Peer closed [peerId:%" PRIu32 "]", peerId);
request->Accept();
break;
......@@ -175,8 +179,6 @@ namespace RTC
this->hasCapabilities = true;
MS_DEBUG("capabilities set");
// Notify the listener (Room) who will remove capabilities to make them
// a subset of the room capabilities.
this->listener->onPeerCapabilities(this, std::addressof(this->capabilities));
......@@ -221,7 +223,7 @@ namespace RTC
this->transports[transportId] = transport;
MS_DEBUG("Transport created [transportId:%" PRIu32 "]", transportId);
MS_DEBUG_DEV("Transport created [transportId:%" PRIu32 "]", transportId);
auto data = transport->toJson();
......@@ -297,7 +299,7 @@ namespace RTC
this->rtpReceivers[rtpReceiverId] = rtpReceiver;
MS_DEBUG("RtpReceiver created [rtpReceiverId:%" PRIu32 "]", rtpReceiverId);
MS_DEBUG_DEV("RtpReceiver created [rtpReceiverId:%" PRIu32 "]", rtpReceiverId);
// Set the Transport.
rtpReceiver->SetTransport(transport);
......@@ -474,7 +476,7 @@ namespace RTC
{
MS_TRACE();
for (auto it = this->rtpSenders.begin(); it != this->rtpSenders.end(); ++it)
for (auto it = this->rtpSenders.begin(); it != this->rtpSenders.end(); it++)
{
auto rtpSender = it->second;
auto rtpParameters = rtpSender->GetParameters();
......@@ -482,7 +484,7 @@ namespace RTC
if (!rtpParameters)
continue;
for (auto it2 = rtpParameters->encodings.begin(); it2 != rtpParameters->encodings.end(); ++it2)
for (auto it2 = rtpParameters->encodings.begin(); it2 != rtpParameters->encodings.end(); it2++)
{
auto& encoding = *it2;
......@@ -503,21 +505,21 @@ namespace RTC
MS_TRACE();
// For every transport:
// - Create a CompoundPacket
// - Request every Sender and Receiver of such transport their RTCP data
// - Send the CompoundPacket
// - Create a CompoundPacket.
// - Request every Sender and Receiver of such transport their RTCP data.
// - Send the CompoundPacket.
for (auto it = this->transports.begin(); it != this->transports.end(); ++it)
for (auto it = this->transports.begin(); it != this->transports.end(); it++)
{
RTC::RTCP::CompoundPacket packet;
RTC::Transport* transport = it->second;
for (auto it = this->rtpSenders.begin(); it != this->rtpSenders.end(); ++it)
for (auto it = this->rtpSenders.begin(); it != this->rtpSenders.end(); it++)
{
RTC::RtpSender* rtpSender = it->second;
RTC::RTCP::SenderReport* report = rtpSender->GetRtcpSenderReport();
// TODO: get next rtpSender data on next SendRtcp() call
// TODO: Get next rtpSender data on next SendRtcp() call.
if (report)
{
packet.AddSenderReport(report);
......@@ -530,7 +532,7 @@ namespace RTC
}
}
for (auto it = this->rtpReceivers.begin(); it != this->rtpReceivers.end(); ++it)
for (auto it = this->rtpReceivers.begin(); it != this->rtpReceivers.end(); it++)
{
RTC::RtpReceiver* rtpReceiver = it->second;
RTC::RTCP::ReceiverReport* report = rtpReceiver->GetRtcpReceiverReport();
......@@ -540,9 +542,7 @@ namespace RTC
}
if (packet.GetSenderReportCount() || packet.GetReceiverReportCount())
{
transport->SendRtcpPacket(&packet);
}
}
}
......@@ -662,7 +662,7 @@ namespace RTC
{
auto it = this->capabilities.codecs.begin();
for (; it != this->capabilities.codecs.end(); ++it)
for (; it != this->capabilities.codecs.end(); it++)
{
auto& codecCapability = *it;
......@@ -710,106 +710,103 @@ namespace RTC
/* RTCP coming from a remote receiver which must be forwarded to the corresponding remote sender. */
case RTCP::Type::RR:
{
RTCP::ReceiverReportPacket* rr = (RTCP::ReceiverReportPacket*) packet;
RTCP::ReceiverReportPacket::Iterator it = rr->Begin();
for (; it != rr->End(); ++it) {
{
RTCP::ReceiverReportPacket* rr = static_cast<RTCP::ReceiverReportPacket*>(packet);
auto& report = (*it);
RTCP::ReceiverReportPacket::Iterator it = rr->Begin();
for (; it != rr->End(); it++)
{
auto& report = (*it);
RTC::RtpSender* rtpSender = this->GetRtpSender(report->GetSsrc());
RTC::RtpSender* rtpSender = this->GetRtpSender(report->GetSsrc());
if (!rtpSender) {
MS_WARN("no RtpSender found for ssrc: %u while procesing a Receiver Report", report->GetSsrc());
}
else {
this->listener->onPeerRtcpReceiverReport(this, rtpSender, report);
}
}
if (!rtpSender)
MS_WARN_TAG(rtcp, "no RtpSender found while procesing a Receiver Report [ssrc:%" PRIu32 "]", report->GetSsrc());
else
this->listener->onPeerRtcpReceiverReport(this, rtpSender, report);
}
break;
}
case RTCP::Type::PSFB:
{
RTCP::FeedbackPsPacket* feedback = (RTCP::FeedbackPsPacket*) packet;
{
RTCP::FeedbackPsPacket* feedback = static_cast<RTCP::FeedbackPsPacket*>(packet);
RTC::RtpSender* rtpSender = this->GetRtpSender(feedback->GetMediaSsrc());
RTC::RtpSender* rtpSender = this->GetRtpSender(feedback->GetMediaSsrc());
if (!rtpSender)
MS_WARN_TAG(rtcp, "no RtpSender found while procesing a Feedback packet [ssrc:%" PRIu32 "]", feedback->GetMediaSsrc());
else
this->listener->onPeerRtcpFeedback(this, rtpSender, feedback);
if (!rtpSender) {
MS_WARN("no RtpSender found for ssrc: %u while procesing a Feedback packet", feedback->GetMediaSsrc());
}
else {
this->listener->onPeerRtcpFeedback(this, rtpSender, feedback);
}
}
break;
}
case RTCP::Type::RTPFB:
{
RTCP::FeedbackRtpPacket* feedback = (RTCP::FeedbackRtpPacket*) packet;
{
RTCP::FeedbackRtpPacket* feedback = static_cast<RTCP::FeedbackRtpPacket*>(packet);
RTC::RtpSender* rtpSender = this->GetRtpSender(feedback->GetMediaSsrc());
RTC::RtpSender* rtpSender = this->GetRtpSender(feedback->GetMediaSsrc());
if (!rtpSender)
MS_WARN_TAG(rtcp, "no RtpSender found while procesing a Feedback packet [ssrc:%" PRIu32 "]", feedback->GetMediaSsrc());
else
this->listener->onPeerRtcpFeedback(this, rtpSender, feedback);
if (!rtpSender) {
MS_WARN("no RtpSender found for ssrc: %u while procesing a Feedback packet", feedback->GetMediaSsrc());
}
else {
this->listener->onPeerRtcpFeedback(this, rtpSender, feedback);
}
}
break;
}
/* RTCP coming from a remote sender which must be forwarded to the corresponding remote receivers. */
case RTCP::Type::SR:
{
RTCP::SenderReportPacket* sr = static_cast<RTCP::SenderReportPacket*>(packet);
RTCP::SenderReportPacket::Iterator it = sr->Begin();
// Even if Sender Report packet can only contain one report..
for (; it != sr->End(); it++)
{
RTCP::SenderReportPacket* sr = (RTCP::SenderReportPacket*) packet;
RTCP::SenderReportPacket::Iterator it = sr->Begin();
// Even if Sender Report packet can only contain one report..
for (; it != sr->End(); ++it)
{
auto& report = (*it);
// Get the receiver associated to the SSRC indicated in the report.
RTC::RtpReceiver* rtpReceiver = transport->GetRtpReceiver(report->GetSsrc());
if (!rtpReceiver)
MS_WARN("no RtpReceiver found for ssrc: %u while procesing a Sender Report", report->GetSsrc());
else
this->listener->onPeerRtcpSenderReport(this, rtpReceiver, report);
}
auto& report = (*it);
// Get the receiver associated to the SSRC indicated in the report.
RTC::RtpReceiver* rtpReceiver = transport->GetRtpReceiver(report->GetSsrc());
if (!rtpReceiver)
MS_WARN_TAG(rtcp, "no RtpReceiver found while procesing a Sender Report [ssrc:%" PRIu32 "]", report->GetSsrc());
else
this->listener->onPeerRtcpSenderReport(this, rtpReceiver, report);
}
break;
}
case RTCP::Type::SDES:
{
RTCP::SdesPacket* sdes = (RTCP::SdesPacket*) packet;
RTCP::SdesPacket::Iterator it = sdes->Begin();
{
RTCP::SdesPacket* sdes = static_cast<RTCP::SdesPacket*>(packet);
RTCP::SdesPacket::Iterator it = sdes->Begin();
for (; it != sdes->End(); ++it)
{
auto& chunk = (*it);
for (; it != sdes->End(); it++)
{
auto& chunk = (*it);
// Get the receiver associated to the SSRC indicated in the chunk.
RTC::RtpReceiver* rtpReceiver = transport->GetRtpReceiver(chunk->GetSsrc());
// Get the receiver associated to the SSRC indicated in the chunk.
RTC::RtpReceiver* rtpReceiver = transport->GetRtpReceiver(chunk->GetSsrc());
if (!rtpReceiver)
MS_WARN("no RtpReceiver found for ssrc: %u while procesing a SDES chunk", chunk->GetSsrc());
else
this->listener->onPeerRtcpSdesChunk(this, rtpReceiver, chunk);
}
if (!rtpReceiver)
MS_WARN_TAG(rtcp, "no RtpReceiver found while procesing a SDES chunk [ssrc:%" PRIu32 "]", chunk->GetSsrc());
else
this->listener->onPeerRtcpSdesChunk(this, rtpReceiver, chunk);
}
break;
}
case RTCP::Type::BYE:
break;
default:
MS_WARN("Unhandled RTCP type received to 'RTC::Peer': %u", (uint8_t)packet->GetType());
MS_WARN_TAG(rtcp, "unhandled RTCP type received [type:%" PRIu8 "]", (uint8_t)packet->GetType());
break;
}
......
#define MS_CLASS "RTC::RTCP::Bye"
// #define MS_LOG_DEV
#include "RTC/RTCP/Bye.h"
#include "Utils.h"
......@@ -25,7 +26,8 @@ namespace RTC { namespace RTCP
{
if (sizeof(uint32_t) > len-offset)
{
MS_WARN("not enough space for SSRC in RTCP Bye message");
MS_WARN_TAG(rtcp, "not enough space for SSRC in RTCP Bye message");
return nullptr;
}
......@@ -84,21 +86,19 @@ namespace RTC { namespace RTCP
void ByePacket::Dump()
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
#ifdef MS_LOG_DEV
MS_WARN("<Bye Packet>");
MS_TRACE();
MS_DEBUG_DEV("<ByePacket>");
for (auto ssrc : this->ssrcs)
{
MS_WARN("\tssrc: %u", ssrc);
MS_DEBUG_DEV(" ssrc : %" PRIu32, ssrc);
}
if (!this->reason.empty())
MS_WARN("\treason: %s", this->reason.c_str());
MS_DEBUG_DEV(" reason : %s", this->reason.c_str());
MS_DEBUG_DEV("</ByePacket>");
MS_WARN("</Bye Packet>");
#endif
}
}}
#define MS_CLASS "RTC::RTCP::CompoundPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/CompoundPacket.h"
#include "Logger.h"
......@@ -18,15 +19,12 @@ namespace RTC { namespace RTCP
MS_TRACE();
// Calculate the total required size for the entire message.
if (this->senderReportPacket.GetCount())
{
this->size = this->senderReportPacket.GetSize();
if (this->receiverReportPacket.GetCount())
{
this->size += sizeof(ReceiverReport::Header) * this->receiverReportPacket.GetCount();
}
}
// If no sender nor receiver reports are present send an empty Receiver Report
// packet as the head of the compound packet.
......@@ -56,7 +54,7 @@ namespace RTC { namespace RTCP
header->length += (sizeof(ReceiverReport::Header) * this->receiverReportPacket.GetCount()) / 4;
ReceiverReportPacket::Iterator it = this->receiverReportPacket.Begin();
for (; it != this->receiverReportPacket.End(); ++it)
for (; it != this->receiverReportPacket.End(); it++)
{
ReceiverReport* report = (*it);
......@@ -80,10 +78,9 @@ namespace RTC { namespace RTCP
void CompoundPacket::Dump()
{
MS_TRACE();
#ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel())
return;
MS_TRACE();
if (this->senderReportPacket.GetCount())
{
......@@ -93,8 +90,10 @@ namespace RTC { namespace RTCP
{
ReceiverReportPacket::Iterator it = this->receiverReportPacket.Begin();
for (; it != this->receiverReportPacket.End(); ++it)
for (; it != this->receiverReportPacket.End(); it++)
{
(*it)->Dump();
}
}
}
else
......@@ -104,6 +103,8 @@ namespace RTC { namespace RTCP
if (this->sdesPacket.GetCount())
this->sdesPacket.Dump();
#endif
}
void CompoundPacket::AddSenderReport(SenderReport* report)
......
#define MS_CLASS "RTC::RTCP::Feedback"
// #define MS_LOG_DEV
#include "RTC/RTCP/Feedback.h"
// Feedback RTP.
......@@ -41,7 +42,7 @@ namespace RTC { namespace RTCP
Packet(RTCP::Type(commonHeader->packet_type)),
messageType(typename T::MessageType(commonHeader->count))
{
// 1 => sizeof(CommonHeader)
// 1 => sizeof(CommonHeader).
this->header = (Header*)(commonHeader + 1);
}
......@@ -83,12 +84,9 @@ namespace RTC { namespace RTCP
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_WARN("\tsender_ssrc: %u", ntohl(this->header->s_ssrc));
MS_WARN("\tmedia_ssrc: %u", ntohl(this->header->m_ssrc));
MS_WARN("\tsize: %zu", this->GetSize());
MS_DEBUG_DEV(" sender ssrc : %" PRIu32, ntohl(this->header->s_ssrc));
MS_DEBUG_DEV(" media ssrc : %" PRIu32, ntohl(this->header->m_ssrc));
MS_DEBUG_DEV(" size : %zu", this->GetSize());
}
/* Specialization for Ps class. */
......@@ -119,7 +117,8 @@ namespace RTC { namespace RTCP
if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len)
{
MS_WARN("not enough space for Feedback packet, discarded");
MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded");
return nullptr;
}
......@@ -171,7 +170,7 @@ namespace RTC { namespace RTCP
break;
default:
MS_WARN("unknown RTCP PS Feedback message type [packet_type:%" PRIu8 "]", commonHeader->count);
MS_WARN_TAG(rtcp, "unknown RTCP PS Feedback message type [packet_type:%" PRIu8 "]", commonHeader->count);
}
return packet;
......@@ -205,7 +204,8 @@ namespace RTC { namespace RTCP
if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len)
{
MS_WARN("not enough space for Feedback packet, discarded");
MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded");
return nullptr;
}
......@@ -248,7 +248,7 @@ namespace RTC { namespace RTCP
break;
default:
MS_WARN("unknown RTCP RTP Feedback message type [packet_type:%" PRIu8 "]", commonHeader->count);
MS_WARN_TAG(rtcp, "unknown RTCP RTP Feedback message type [packet_type:%" PRIu8 "]", commonHeader->count);
}
return packet;
......
#define MS_CLASS "RTC::RTCP::FeedbackPsPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPs.h"
#include "RTC/RTCP/FeedbackPsSli.h"
......@@ -20,7 +21,8 @@ namespace RTC { namespace RTCP
if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len)
{
MS_WARN("not enough space for Feedback packet, discarded");
MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded");
return nullptr;
}
......@@ -67,20 +69,19 @@ namespace RTC { namespace RTCP
template<typename Item>
void FeedbackPsItemPacket<Item>::Dump()
{
MS_TRACE();
#ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel())
return;
MS_TRACE();
MS_WARN("\t<%s>", FeedbackPsPacket::MessageType2String(Item::MessageType).c_str());
MS_DEBUG_DEV("<%s>", FeedbackPsPacket::MessageType2String(Item::MessageType).c_str());
FeedbackPsPacket::Dump();
for (auto item : this->items)
{
item->Dump();
}
MS_DEBUG_DEV("</%s>", FeedbackPsPacket::MessageType2String(Item::MessageType).c_str());
MS_WARN("\t<%s>", FeedbackPsPacket::MessageType2String(Item::MessageType).c_str());
#endif
}
// explicit instantiation to have all FeedbackRtpPacket definitions in this file.
......
#define MS_CLASS "RTC::RTCP::FeedbackPsAfbPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsAfb.h"
#include "Logger.h"
......@@ -14,7 +15,8 @@ namespace RTC { namespace RTCP
if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len)
{
MS_WARN("not enough space for Feedback packet, discarded");
MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded");
return nullptr;
}
......@@ -38,13 +40,14 @@ namespace RTC { namespace RTCP
void FeedbackPsAfbPacket::Dump()
{
MS_TRACE();
#ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel())
return;
MS_TRACE();
MS_WARN("\t<FeedbackPsAfbPacket>");
MS_DEBUG_DEV("<FeedbackPsAfbPacket>");
FeedbackPsPacket::Dump();
MS_WARN("\t</FeedbackPsAfbPacket>");
MS_DEBUG_DEV("</FeedbackPsAfbPacket>");
#endif
}
}}
#define MS_CLASS "RTC::RTCP::FeedbackPsFirPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsFir.h"
#include "Logger.h"
......@@ -16,7 +17,8 @@ namespace RTC { namespace RTCP
// data size must be >= header.
if (sizeof(Header) > len)
{
MS_WARN("not enough space for Fir item, discarded");
MS_WARN_TAG(rtcp, "not enough space for Fir item, discarded");
return nullptr;
}
......@@ -54,12 +56,9 @@ namespace RTC { namespace RTCP
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_WARN("\t\t<Fir Item>");
MS_WARN("\t\t\tssrc: %u", ntohl(this->header->ssrc));
MS_WARN("\t\t\tsequence_number: %u", this->header->sequence_number);
MS_WARN("\t\t</Fir Item>");
MS_DEBUG_DEV("<FirItem>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, ntohl(this->header->ssrc));
MS_DEBUG_DEV(" sequence number : %" PRIu8, this->header->sequence_number);
MS_DEBUG_DEV("\t\t</FirItem>");
}
}}
#define MS_CLASS "RTC::RTCP::FeedbackPsPsLeiPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsLei.h"
#include "Logger.h"
......@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value.
if (sizeof(Header) > len)
{
MS_WARN("not enough space for PsLei item, discarded");
MS_WARN_TAG(rtcp, "not enough space for PsLei item, discarded");
return nullptr;
}
......@@ -46,11 +48,8 @@ namespace RTC { namespace RTCP
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_WARN("\t\t<PsLei Item>");
MS_WARN("\t\t\tssrc: %u", ntohl(this->header->ssrc));
MS_WARN("\t\t</PsLei Item>");
MS_DEBUG_DEV("<PsLeiItem>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, ntohl(this->header->ssrc));
MS_DEBUG_DEV("</PsLeiItem>");
}
}}
#define MS_CLASS "RTC::RTCP::FeedbackPsPliPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsPli.h"
#include "Logger.h"
......@@ -13,7 +14,8 @@ namespace RTC { namespace RTCP
if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len)
{
MS_WARN("not enough space for Feedback packet, discarded");
MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded");
return nullptr;
}
......@@ -25,13 +27,14 @@ namespace RTC { namespace RTCP
void FeedbackPsPliPacket::Dump()
{
MS_TRACE();
#ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel())
return;
MS_TRACE();
MS_WARN("\t<FeedbackPsPliPacket>");
MS_DEBUG_DEV("<FeedbackPsPliPacket>");
FeedbackPsPacket::Dump();
MS_WARN("\t</FeedbackPsPliPacket>");
MS_DEBUG_DEV("</FeedbackPsPliPacket>");
#endif
}
}}
#define MS_CLASS "RTC::RTCP::FeedbackPsRpsiPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsRpsi.h"
#include "Logger.h"
......@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP
// data size must be >= header.
if (sizeof(Header) > len)
{
MS_WARN("not enough space for Rpsi item, discarded");
MS_WARN_TAG(rtcp, "not enough space for Rpsi item, discarded");
return nullptr;
}
......@@ -37,15 +39,19 @@ namespace RTC { namespace RTCP
this->header = header;
// Calculate bit_string length.
if (this->header->padding_bits % 8 != 0) {
MS_WARN("invalid Rpsi packet with fractional padding bytes value");
if (this->header->padding_bits % 8 != 0)
{
MS_WARN_TAG(rtcp, "invalid Rpsi packet with fractional padding bytes value");
isCorrect = false;
}
size_t paddingBytes = this->header->padding_bits / 8;
if (paddingBytes > RpsiItem::MaxBitStringSize) {
MS_WARN("invalid Rpsi packet with too many padding bytes");
if (paddingBytes > RpsiItem::MaxBitStringSize)
{
MS_WARN_TAG(rtcp, "invalid Rpsi packet with too many padding bytes");
isCorrect = false;
}
......@@ -89,13 +95,10 @@ namespace RTC { namespace RTCP
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_WARN("\t\t<Rpsi Item>");
MS_WARN("\t\t\tpadding bits: %u", this->header->padding_bits);
MS_WARN("\t\t\tpayload_type: %u", this->header->payload_type);
MS_WARN("\t\t\tlength: %zu", this->length);
MS_WARN("\t\t</Rpsi Item>");
MS_DEBUG_DEV("<RpsiItem>");
MS_DEBUG_DEV(" padding bits : %" PRIu8, this->header->padding_bits);
MS_DEBUG_DEV(" payload type : %" PRIu8, this->header->payload_type);
MS_DEBUG_DEV(" length : %zu", this->length);
MS_DEBUG_DEV("</RpsiItem>");
}
}}
#define MS_CLASS "RTC::RTCP::FeedbackPsSliPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsSli.h"
#include "Logger.h"
......@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value.
if (sizeof(Header) > len)
{
MS_WARN("not enough space for Sli item, discarded");
MS_WARN_TAG(rtcp, "not enough space for Sli item, discarded");
return nullptr;
}
......@@ -54,14 +56,11 @@ namespace RTC { namespace RTCP
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_WARN("\t\t<Sli Item>");
MS_WARN("\t\t\tfirst: %u", this->first);
MS_WARN("\t\t\tnumber: %u", this->number);
MS_WARN("\t\t\tpictureId: %u", this->pictureId);
MS_WARN("\t\t</Sli Item>");
MS_DEBUG_DEV("<SliItem>");
MS_DEBUG_DEV(" first : %" PRIu16, this->first);
MS_DEBUG_DEV(" number : %" PRIu16, this->number);
MS_DEBUG_DEV(" picture id : %" PRIu8, this->pictureId);
MS_DEBUG_DEV("</SliItem>");
}
}}
#define MS_CLASS "RTC::RTCP::FeedbackPsTstPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsTst.h"
#include "Logger.h"
......@@ -16,7 +17,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value.
if (sizeof(Header) > len)
{
MS_WARN("not enough space for Tst item, discarded");
MS_WARN_TAG(rtcp, "not enough space for Tst item, discarded");
return nullptr;
}
......@@ -56,14 +58,11 @@ namespace RTC { namespace RTCP
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_WARN("\t\t<Tst Item>");
MS_WARN("\t\t\tssrc: %u", ntohl(this->header->ssrc));
MS_WARN("\t\t\tsequence_number: %u", this->header->sequence_number);
MS_WARN("\t\t\tindex: %u", this->header->index);
MS_WARN("\t\t</Tst Item>");
MS_DEBUG_DEV("<TstItem>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, ntohl(this->header->ssrc));
MS_DEBUG_DEV(" sequence number : %" PRIu32, this->header->sequence_number);
MS_DEBUG_DEV(" index : %" PRIu32, this->header->index);
MS_DEBUG_DEV("</TstItem>");
}
/* Specialization for Tstr class. */
......
#define MS_CLASS "RTC::RTCP::FeedbackPsVbcmPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsVbcm.h"
#include "Logger.h"
......@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value.
if (sizeof(Header) > len)
{
MS_WARN("not enough space for Vbcm item, discarded");
MS_WARN_TAG(rtcp, "not enough space for Vbcm item, discarded");
return nullptr;
}
......@@ -64,14 +66,11 @@ namespace RTC { namespace RTCP
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_WARN("\t\t<Vbcm Item>");
MS_WARN("\t\t\tssrc: %u", ntohl(this->header->ssrc));
MS_WARN("\t\t\tsequence_number: %u", this->header->sequence_number);
MS_WARN("\t\t\tpayload type: %u", this->header->payload_type);
MS_WARN("\t\t\tlength: %u", ntohs(this->header->length));
MS_WARN("\t\t</Vbcm Item>");
MS_DEBUG_DEV("<VbcmItem>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, ntohl(this->header->ssrc));
MS_DEBUG_DEV(" sequence number : %" PRIu8, this->header->sequence_number);
MS_DEBUG_DEV(" payload type : %" PRIu8, this->header->payload_type);
MS_DEBUG_DEV(" length : %" PRIu16, ntohs(this->header->length));
MS_DEBUG_DEV("</Vbcm Item>");
}
}}
#define MS_CLASS "RTC::RTCP::FeedbackRtpPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackRtp.h"
#include "RTC/RTCP/FeedbackRtpNack.h"
......@@ -18,7 +19,8 @@ namespace RTC { namespace RTCP
if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len)
{
MS_WARN("not enough space for Feedback packet, discarded");
MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded");
return nullptr;
}
......@@ -65,20 +67,19 @@ namespace RTC { namespace RTCP
template<typename Item>
void FeedbackRtpItemPacket<Item>::Dump()
{
MS_TRACE();
#ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel())
return;
MS_TRACE();
MS_WARN("\t<%s>", FeedbackRtpPacket::MessageType2String(Item::MessageType).c_str());
MS_DEBUG_DEV("<%s>", FeedbackRtpPacket::MessageType2String(Item::MessageType).c_str());
FeedbackRtpPacket::Dump();
for (auto item : this->items)
{
item->Dump();
}
MS_DEBUG_DEV("</%s>", FeedbackRtpPacket::MessageType2String(Item::MessageType).c_str());
MS_WARN("\t<%s>", FeedbackRtpPacket::MessageType2String(Item::MessageType).c_str());
#endif
}
// Explicit instantiation to have all FeedbackRtpPacket definitions in this file.
......
#define MS_CLASS "RTC::RTCP::FeedbackRtpEcnPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackRtpEcn.h"
#include "Logger.h"
......@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value.
if (sizeof(Header) > len)
{
MS_WARN("not enough space for Ecn item, discarded");
MS_WARN_TAG(rtcp, "not enough space for Ecn item, discarded");
return nullptr;
}
......@@ -38,17 +40,14 @@ namespace RTC { namespace RTCP
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_WARN("\t\t<Ecn Item>");
MS_WARN("\t\tsequence_number: %d", ntohl(this->header->sequence_number));
MS_WARN("\t\tect0_counter: %d", ntohl(this->header->ect0_counter));
MS_WARN("\t\tect1_counter: %d", ntohl(this->header->ect1_counter));
MS_WARN("\t\tecn_ce_counter: %d", ntohs(this->header->ecn_ce_counter));
MS_WARN("\t\tnot_ect_counter: %d", ntohs(this->header->not_ect_counter));
MS_WARN("\t\tlost_packets: %d", ntohs(this->header->lost_packets));
MS_WARN("\t\tduplicated_packets: %d", ntohs(this->header->duplicated_packets));
MS_WARN("\t\t</Ecn Item>");
MS_DEBUG_DEV("<EcnItem>");
MS_DEBUG_DEV(" sequence number : %" PRIu32, ntohl(this->header->sequence_number));
MS_DEBUG_DEV(" ect0 counter : %" PRIu32, ntohl(this->header->ect0_counter));
MS_DEBUG_DEV(" ect1 counter : %" PRIu32, ntohl(this->header->ect1_counter));
MS_DEBUG_DEV(" ecn ce counter : %" PRIu16, ntohs(this->header->ecn_ce_counter));
MS_DEBUG_DEV(" not ect counter : %" PRIu16, ntohs(this->header->not_ect_counter));
MS_DEBUG_DEV(" lost packets : %" PRIu16, ntohs(this->header->lost_packets));
MS_DEBUG_DEV(" duplicated packets : %" PRIu16, ntohs(this->header->duplicated_packets));
MS_DEBUG_DEV("</EcnItem>");
}
}}
#define MS_CLASS "RTC::RTCP::FeedbackRtpNackPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackRtpNack.h"
#include "Logger.h"
......@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value.
if (sizeof(Header) > len)
{
MS_WARN("not enough space for Nack item, discarded");
MS_WARN_TAG(rtcp, "not enough space for Nack item, discarded");
return nullptr;
}
......@@ -48,12 +50,9 @@ namespace RTC { namespace RTCP
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_WARN("\t\t<Nack Item>");
MS_WARN("\t\t\tpid: %u", ntohl(this->header->packet_id));
MS_WARN("\t\t\tbpl: %u", ntohl(this->header->lost_packet_bitmask));
MS_WARN("\t\t</Nack Item>");
MS_DEBUG_DEV("<NackItem>");
MS_DEBUG_DEV(" pid : %" PRIu16, ntohl(this->header->packet_id));
MS_DEBUG_DEV(" bpl : %" PRIu16, ntohl(this->header->lost_packet_bitmask));
MS_DEBUG_DEV("</NackItem>");
}
}}
#define MS_CLASS "RTC::RTCP::FeedbackRtpSrReqPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackRtpSrReq.h"
#include "Logger.h"
......@@ -13,7 +14,8 @@ namespace RTC { namespace RTCP
if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len)
{
MS_WARN("not enough space for Feedback packet, discarded");
MS_WARN_TAG(rtcp, "not enough space for Feedback packet, discarded");
return nullptr;
}
......@@ -24,13 +26,14 @@ namespace RTC { namespace RTCP
void FeedbackRtpSrReqPacket::Dump()
{
MS_TRACE();
#ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel())
return;
MS_TRACE();
MS_WARN("\t<FeedbackRtpSrReqPacket>");
MS_DEBUG_DEV("<FeedbackRtpSrReqPacket>");
FeedbackRtpPacket::Dump();
MS_WARN("\t</FeedbackRtpSrReqPacket>");
MS_DEBUG_DEV("</FeedbackRtpSrReqPacket>");
#endif
}
}}
#define MS_CLASS "RTC::RTCP::FeedbackRtpTlleiPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackRtpTllei.h"
#include "Logger.h"
......@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value.
if (sizeof(Header) > len)
{
MS_WARN("not enough space for Tllei item, discarded");
MS_WARN_TAG(rtcp, "not enough space for Tllei item, discarded");
return nullptr;
}
......@@ -48,12 +50,9 @@ namespace RTC { namespace RTCP
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_WARN("\t\t<Tllei Item>");
MS_WARN("\t\t\tpid: %u", ntohl(this->header->packet_id));
MS_WARN("\t\t\tbpl: %u", ntohl(this->header->lost_packet_bitmask));
MS_WARN("\t\t</Tllei Item>");
MS_DEBUG_DEV("<TlleiItem>");
MS_DEBUG_DEV(" pid: %" PRIu16, ntohl(this->header->packet_id));
MS_DEBUG_DEV(" bpl: %" PRIu16, ntohl(this->header->lost_packet_bitmask));
MS_DEBUG_DEV("</TlleiItem>");
}
}}
#define MS_CLASS "RTC::RTCP::FeedbackRtpTmmbPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackRtpTmmb.h"
#include "Logger.h"
......@@ -18,7 +19,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value.
if (sizeof(Header) > len)
{
MS_WARN("not enough space for Tmmb item, discarded");
MS_WARN_TAG(rtcp, "not enough space for Tmmb item, discarded");
return nullptr;
}
......@@ -45,7 +47,8 @@ namespace RTC { namespace RTCP
if ((this->bitrate >> exponent) != mantissa)
{
MS_WARN("invalid TMMB bitrate value : %u *2^%u", mantissa, exponent);
MS_WARN_TAG(rtcp, "invalid TMMB bitrate value : %u *2^%u", mantissa, exponent);
this->isCorrect = false;
}
}
......@@ -78,14 +81,11 @@ namespace RTC { namespace RTCP
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_WARN("\t\t<Tmmb Item>");
MS_WARN("\t\t\tssrc: %u", ntohl(this->header->ssrc));
MS_WARN("\t\t\tbitrate: %" PRIu64, this->bitrate);
MS_WARN("\t\t\toverhead: %u", this->overhead);
MS_WARN("\t\t</Tmmb Item>");
MS_DEBUG_DEV("<TmmbItem>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, ntohl(this->header->ssrc));
MS_DEBUG_DEV(" bitrate : %" PRIu64, this->bitrate);
MS_DEBUG_DEV(" overhead : %" PRIu16, this->overhead);
MS_DEBUG_DEV("</TmmbItem>");
}
/* Specialization for Tmmbr class. */
......
#define MS_CLASS "RTC::RTCP::Packet"
// #define MS_LOG_DEV
#include "RTC/RTCP/Packet.h"
#include "RTC/RTCP/ReceiverReport.h"
......@@ -36,7 +37,7 @@ namespace RTC { namespace RTCP
{
if (!Packet::IsRtcp(data, len))
{
MS_WARN("data is not a RTCP packet");
MS_WARN_TAG(rtcp, "data is not a RTCP packet");
return first;
}
......@@ -46,7 +47,7 @@ namespace RTC { namespace RTCP
if (len < packet_len)
{
MS_WARN("packet length exceeds remaining data [len:%zu, packet_len:%zu]", len, packet_len);
MS_WARN_TAG(rtcp, "packet length exceeds remaining data [len:%zu, packet_len:%zu]", len, packet_len);
return first;
}
......@@ -110,7 +111,8 @@ namespace RTC { namespace RTCP
default:
{
MS_WARN("unknown RTCP packet type [packet_type:%" PRIu8 "]", header->packet_type);
MS_WARN_TAG(rtcp, "unknown RTCP packet type [packet_type:%" PRIu8 "]", header->packet_type);
current = nullptr;
}
}
......@@ -120,21 +122,18 @@ namespace RTC { namespace RTCP
std::string packetType = Type2String(Type(header->packet_type));
if (Type(header->packet_type) == Type::PSFB)
{
packetType += " " + FeedbackPsPacket::MessageType2String(FeedbackPs::MessageType(header->count));
}
else if (Type(header->packet_type) == Type::RTPFB)
{
packetType += " " + FeedbackRtpPacket::MessageType2String(FeedbackRtp::MessageType(header->count));
}
MS_WARN("error parsing %s Packet", packetType.c_str());
MS_WARN_TAG(rtcp, "error parsing %s Packet", packetType.c_str());
return first;
}
// TODO: REMOVE
current->Dump();
#ifdef MS_LOG_DEV
// current->Dump();
#endif
data += packet_len;
len -= packet_len;
......
#define MS_CLASS "RTC::RTCP::ReceiverReport"
// #define MS_LOG_DEV
#include "RTC/RTCP/ReceiverReport.h"
#include "Utils.h"
......@@ -19,7 +20,8 @@ namespace RTC { namespace RTCP
// Packet size must be >= header size.
if (sizeof(Header) > len)
{
MS_WARN("not enough space for receiver report, packet discarded");
MS_WARN_TAG(rtcp, "not enough space for receiver report, packet discarded");
return nullptr;
}
......@@ -32,18 +34,15 @@ namespace RTC { namespace RTCP
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_WARN("\t<ReceiverReport>");
MS_WARN("\t\tssrc: %u", ntohl(this->header->ssrc));
MS_WARN("\t\tfraction_lost: %u", this->header->fraction_lost);
MS_WARN("\t\ttotal_lost: %d", this->GetTotalLost());
MS_WARN("\t\tlast_sec: %u", ntohl(this->header->last_sec));
MS_WARN("\t\tjitter: %u", ntohl(this->header->jitter));
MS_WARN("\t\tlsr: %u", ntohl(this->header->lsr));
MS_WARN("\t\tdlsr: %u", ntohl(this->header->dlsr));
MS_WARN("\t</ReceiverReport>");
MS_DEBUG_DEV("<ReceiverReport>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, ntohl(this->header->ssrc));
MS_DEBUG_DEV(" fraction lost : %" PRIu32, this->header->fraction_lost);
MS_DEBUG_DEV(" total lost : %" PRIu32, this->GetTotalLost());
MS_DEBUG_DEV(" last seq : %" PRIu32, ntohl(this->header->last_seq));
MS_DEBUG_DEV(" jitter : %" PRIu32, ntohl(this->header->jitter));
MS_DEBUG_DEV(" lsr : %" PRIu32, ntohl(this->header->lsr));
MS_DEBUG_DEV(" dlsr : %" PRIu32, ntohl(this->header->dlsr));
MS_DEBUG_DEV("</ReceiverReport>");
}
void ReceiverReport::Serialize()
......@@ -137,17 +136,16 @@ namespace RTC { namespace RTCP
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_WARN("<ReceiverReportPacket>");
MS_WARN("\tssrc: %u", (uint32_t)ntohl(this->ssrc));
#ifdef MS_LOG_DEV
MS_DEBUG_DEV("<ReceiverReportPacket>");
MS_DEBUG_DEV(" ssrc: %" PRIu32, (uint32_t)ntohl(this->ssrc));
for (auto report : this->reports)
{
report->Dump();
}
MS_DEBUG_DEV("</ReceiverReportPacket>");
MS_WARN("</ReceiverReportPacket>");
#endif
}
}}
#define MS_CLASS "RTC::RTCP::Sdes"
// #define MS_LOG_DEV
#include "RTC/RTCP/Sdes.h"
#include "Utils.h"
......@@ -34,7 +35,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value.
if (sizeof(uint8_t)*2 + header->length > len)
{
MS_WARN("not enough space for SDES item, discarded");
MS_WARN_TAG(rtcp, "not enough space for SDES item, discarded");
return nullptr;
}
......@@ -74,14 +76,11 @@ namespace RTC { namespace RTCP
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_WARN("\t\t<Sdes Item>");
MS_WARN("\t\t\ttype: %s", Type2String(this->GetType()).c_str());
MS_WARN("\t\t\tlength: %u", this->header->length);
MS_WARN("\t\t\tvalue: %.*s", this->header->length, this->header->value);
MS_WARN("\t\t</Sdes Item>");
MS_DEBUG_DEV("<SdesItem>");
MS_DEBUG_DEV(" type : %s", Type2String(this->GetType()).c_str());
MS_DEBUG_DEV(" length : %" PRIu8, this->header->length);
MS_DEBUG_DEV(" value : %.*s", this->header->length, this->header->value);
MS_DEBUG_DEV("</SdesItem>");
}
void SdesItem::Serialize()
......@@ -117,7 +116,8 @@ namespace RTC { namespace RTCP
// data size must be > SSRC field.
if (sizeof(uint32_t) /* ssrc */ > len)
{
MS_WARN("not enough space for SDES chunk, discarded");
MS_WARN_TAG(rtcp, "not enough space for SDES chunk, discarded");
return nullptr;
}
......@@ -182,20 +182,19 @@ namespace RTC { namespace RTCP
void SdesChunk::Dump()
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
#ifdef MS_LOG_DEV
MS_WARN("\t<Sdes Chunk>");
MS_WARN("\t\tssrc: %u", (uint32_t)ntohl(this->ssrc));
MS_TRACE();
MS_DEBUG_DEV("<SdesChunk>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, (uint32_t)ntohl(this->ssrc));
for (auto item : this->items)
{
item->Dump();
}
MS_DEBUG_DEV("</SdesChunk>");
MS_WARN("\t</Sdes Chunk>");
#endif
}
/* Class methods. */
......@@ -245,18 +244,17 @@ namespace RTC { namespace RTCP
void SdesPacket::Dump()
{
MS_TRACE();
#ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel())
return;
MS_WARN("<Sdes Packet>");
MS_TRACE();
MS_DEBUG_DEV("<SdesPacket>");
for (auto chunk : this->chunks)
{
chunk->Dump();
}
MS_DEBUG_DEV("</SdesPacket>");
MS_WARN("</Sdes Packet>");
#endif
}
}}
#define MS_CLASS "RTC::RTCP::SenderReport"
// #define MS_LOG_DEV
#include "RTC/RTCP/SenderReport.h"
#include "Logger.h"
......@@ -18,7 +19,8 @@ namespace RTC { namespace RTCP
// Packet size must be >= header size.
if (sizeof(Header) > len)
{
MS_WARN("not enough space for sender report, packet discarded");
MS_WARN_TAG(rtcp, "not enough space for sender report, packet discarded");
return nullptr;
}
......@@ -31,17 +33,14 @@ namespace RTC { namespace RTCP
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_WARN("\t<SenderReport>");
MS_WARN("\t\tssrc: %u", ntohl(this->header->ssrc));
MS_WARN("\t\tntp_sec: %u", ntohl(this->header->ntp_sec));
MS_WARN("\t\tntp_frac: %u", ntohl(this->header->ntp_frac));
MS_WARN("\t\trtp_ts: %u", ntohl(this->header->rtp_ts));
MS_WARN("\t\tpacket_count: %u", ntohl(this->header->packet_count));
MS_WARN("\t\toctet_count: %u", ntohl(this->header->octet_count));
MS_WARN("\t</SenderReport>");
MS_DEBUG_DEV("<SenderReport>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, ntohl(this->header->ssrc));
MS_DEBUG_DEV(" ntp sec : %" PRIu32, ntohl(this->header->ntp_sec));
MS_DEBUG_DEV(" ntp frac : %" PRIu32, ntohl(this->header->ntp_frac));
MS_DEBUG_DEV(" rtp ts : %" PRIu32, ntohl(this->header->rtp_ts));
MS_DEBUG_DEV(" packet count : %" PRIu32, ntohl(this->header->packet_count));
MS_DEBUG_DEV(" octet count : %" PRIu32, ntohl(this->header->octet_count));
MS_DEBUG_DEV("</SenderReport>");
}
void SenderReport::Serialize()
......@@ -82,13 +81,9 @@ namespace RTC { namespace RTCP
SenderReport* report = SenderReport::Parse(data+offset, len-offset);
if (report)
{
packet->AddReport(report);
}
else
{
return packet.release();
}
return packet.release();
}
......@@ -114,18 +109,17 @@ namespace RTC { namespace RTCP
void SenderReportPacket::Dump()
{
MS_TRACE();
#ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel())
return;
MS_WARN("<SenderReportPacket>");
MS_TRACE();
MS_DEBUG_DEV("<SenderReportPacket>");
for (auto report : this->reports)
{
report->Dump();
}
MS_DEBUG_DEV("</SenderReportPacket>");
MS_WARN("</SenderReportPacket>");
#endif
}
}}
#define MS_CLASS "RTC::Room"
// #define MS_LOG_DEV
#include "RTC/Room.h"
#include "RTC/RTCP/FeedbackRtpNack.h"
......@@ -194,11 +195,14 @@ namespace RTC
{
case Channel::Request::MethodId::room_close:
{
#ifdef MS_LOG_DEV
uint32_t roomId = this->roomId;
#endif
Close();
MS_DEBUG("Room closed [roomId:%" PRIu32 "]", roomId);
MS_DEBUG_DEV("Room closed [roomId:%" PRIu32 "]", roomId);
request->Accept();
break;
......@@ -258,7 +262,7 @@ namespace RTC
// Store the new Peer.
this->peers[peerId] = peer;
MS_DEBUG("Peer created [peerId:%u, peerName:'%s']", peerId, peerName.c_str());
MS_DEBUG_DEV("Peer created [peerId:%u, peerName:'%s']", peerId, peerName.c_str());
request->Accept();
......@@ -441,7 +445,7 @@ namespace RTC
auto& peerCodecCapability = *it;
auto it2 = this->capabilities.codecs.begin();
for (; it2 != this->capabilities.codecs.end(); ++it2)
for (; it2 != this->capabilities.codecs.end(); it2++)
{
auto& roomCodecCapability = *it2;
......@@ -450,13 +454,9 @@ namespace RTC
}
if (it2 != this->capabilities.codecs.end())
{
it++;
}
else
{
it = capabilities->codecs.erase(it);
}
}
// TODO: Remove unsupported header extensions.
......@@ -692,8 +692,8 @@ namespace RTC
{
MS_TRACE();
// Tell all the peers but the one in the argument to generate and send their RTCP
for (auto it = this->peers.begin(); it != this->peers.end(); ++it)
// Tell all the peers but the one in the argument to generate and send their RTCP.
for (auto it = this->peers.begin(); it != this->peers.end(); it++)
{
if (it->second != peer) {
it->second->SendRtcp();
......
#define MS_CLASS "RTC::Media"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h"
#include "Utils.h"
......
#define MS_CLASS "RTC::Parameters"
// #define MS_LOG_DEV
#include "RTC/Parameters.h"
#include "Logger.h"
......@@ -71,7 +72,7 @@ namespace RTC
MS_ASSERT(data.isObject(), "data is not a JSON object");
for (Json::Value::iterator it = data.begin(); it != data.end(); ++it)
for (Json::Value::iterator it = data.begin(); it != data.end(); it++)
{
std::string key = it.key().asString();
Json::Value value = (*it);
......@@ -141,7 +142,7 @@ namespace RTC
}
default:
; // Just ignore other value types.
; // Just ignore other value types.
}
}
}
......
#define MS_CLASS "RTC::RtcpFeedback"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtcpParameters"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpCapabilities"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpCodecMime"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h"
#include "Utils.h"
......
#define MS_CLASS "RTC::RtpCodecParameters"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpEncodingParameters"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpFecParameters"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpHeaderExtension"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpHeaderExtensionParameters"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpParameters"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h"
......@@ -186,7 +187,7 @@ namespace RTC
int32_t apt = codec.parameters.GetInteger(k_apt);
auto it = this->codecs.begin();
for (; it != this->codecs.end(); ++it)
for (; it != this->codecs.end(); it++)
{
auto codec = *it;
......@@ -222,7 +223,7 @@ namespace RTC
{
auto it = this->codecs.begin();
for (; it != this->codecs.end(); ++it)
for (; it != this->codecs.end(); it++)
{
auto& codec = *it;
......@@ -265,7 +266,7 @@ namespace RTC
{
auto it = this->codecs.begin();
for (; it != this->codecs.end(); ++it)
for (; it != this->codecs.end(); it++)
{
auto codec = *it;
......
#define MS_CLASS "RTC::RtpRtxParameters"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpListener"
// #define MS_LOG_DEV
#include "RTC/RtpListener.h"
#include "MediaSoupError.h"
......@@ -194,7 +195,7 @@ namespace RTC
{
auto it = rtpParameters->encodings.begin();
for (; it != rtpParameters->encodings.end(); ++it)
for (; it != rtpParameters->encodings.end(); it++)
{
auto& encoding = *it;
......@@ -283,8 +284,7 @@ namespace RTC
}
// RTP PT not present.
// TODO: We don't want to log every warning.
MS_WARN("unknown RTP payloadType [payloadType:%" PRIu8 "]", packet->GetPayloadType());
MS_WARN_TAG(rtp, "unknown RTP payloadType [payloadType:%" PRIu8 "]", packet->GetPayloadType());
// TODO: We may emit "unhandledrtp" event.
return nullptr;
......
#define MS_CLASS "RTC::RtpPacket"
// #define MS_LOG_DEV
#include "RTC/RtpPacket.h"
#include "Utils.h"
......@@ -32,7 +33,7 @@ namespace RTC
// Packet size must be >= header size + CSRC list.
if (len < pos + csrc_list_size)
{
MS_DEBUG("not enough space for the announced CSRC list, packet discarded");
MS_WARN_TAG(rtp, "not enough space for the announced CSRC list, packet discarded");
return nullptr;
}
......@@ -48,7 +49,7 @@ namespace RTC
// The extension header is at least 4 bytes.
if (len < pos + 4)
{
MS_DEBUG("not enough space for the announced extension header, packet discarded");
MS_WARN_TAG(rtp, "not enough space for the announced extension header, packet discarded");
return nullptr;
}
......@@ -62,7 +63,7 @@ namespace RTC
// Packet size must be >= header size + CSRC list + header extension size.
if (len < pos + 4 + extension_value_size)
{
MS_DEBUG("not enough space for the announced header extension value, packet discarded");
MS_WARN_TAG(rtp, "not enough space for the announced header extension value, packet discarded");
return nullptr;
}
......@@ -82,7 +83,7 @@ namespace RTC
// Must be at least a single payload byte.
if (payloadLength == 0)
{
MS_DEBUG("padding bit is set but no space for a padding byte, packet discarded");
MS_WARN_TAG(rtp, "padding bit is set but no space for a padding byte, packet discarded");
return nullptr;
}
......@@ -90,14 +91,14 @@ namespace RTC
payloadPadding = data[len - 1];
if (payloadPadding == 0)
{
MS_DEBUG("padding byte cannot be 0, packet discarded");
MS_WARN_TAG(rtp, "padding byte cannot be 0, packet discarded");
return nullptr;
}
if (payloadLength < (size_t)payloadPadding)
{
MS_DEBUG("number of padding octets is greater than available space for payload, packet discarded");
MS_WARN_TAG(rtp, "number of padding octets is greater than available space for payload, packet discarded");
return nullptr;
}
......@@ -139,27 +140,28 @@ namespace RTC
void RtpPacket::Dump()
{
MS_TRACE();
#ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel())
return;
MS_TRACE();
MS_DEBUG("<RtpPacket>");
MS_DEBUG("padding: %s", this->header->padding ? "true" : "false");
MS_DEBUG("extension: %s", HasExtensionHeader() ? "true" : "false");
MS_DEBUG_DEV("<RtpPacket>");
MS_DEBUG_DEV(" padding : %s", this->header->padding ? "true" : "false");
MS_DEBUG_DEV(" extension header : %s", HasExtensionHeader() ? "true" : "false");
if (HasExtensionHeader())
{
MS_DEBUG("extension ID: %" PRIu16, GetExtensionHeaderId());
MS_DEBUG("extension length: %zu bytes", GetExtensionHeaderLength());
MS_DEBUG_DEV(" id : %" PRIu16, GetExtensionHeaderId());
MS_DEBUG_DEV(" length : %zu bytes", GetExtensionHeaderLength());
}
MS_DEBUG("CSRC count: %" PRIu8, this->header->csrc_count); // TODO: method?
MS_DEBUG("marker: %s", HasMarker() ? "true" : "false");
MS_DEBUG("payload type: %" PRIu8, GetPayloadType());
MS_DEBUG("sequence number: %" PRIu16, GetSequenceNumber());
MS_DEBUG("timestamp: %" PRIu32, GetTimestamp());
MS_DEBUG("SSRC: %" PRIu32, GetSsrc());
MS_DEBUG("payload size: %zu bytes", GetPayloadLength());
MS_DEBUG("</RtpPacket>");
MS_DEBUG_DEV(" csrc count : %" PRIu8, this->header->csrc_count);
MS_DEBUG_DEV(" marker : %s", HasMarker() ? "true" : "false");
MS_DEBUG_DEV(" payload type : %" PRIu8, GetPayloadType());
MS_DEBUG_DEV(" sequence number : %" PRIu16, GetSequenceNumber());
MS_DEBUG_DEV(" timestamp : %" PRIu32, GetTimestamp());
MS_DEBUG_DEV(" ssrc : %" PRIu32, GetSsrc());
MS_DEBUG_DEV(" payload size : %zu bytes", GetPayloadLength());
MS_DEBUG_DEV("</RtpPacket>");
#endif
}
void RtpPacket::Serialize()
......
#define MS_CLASS "RTC::RtpReceiver"
// #define MS_LOG_DEV
#include "RTC/RtpReceiver.h"
#include "RTC/Transport.h"
......@@ -102,11 +103,14 @@ namespace RTC
{
case Channel::Request::MethodId::rtpReceiver_close:
{
#ifdef MS_LOG_DEV
uint32_t rtpReceiverId = this->rtpReceiverId;
#endif
Close();
MS_DEBUG("RtpReceiver closed [rtpReceiverId:%" PRIu32 "]", rtpReceiverId);
MS_DEBUG_DEV("RtpReceiver closed [rtpReceiverId:%" PRIu32 "]", rtpReceiverId);
request->Accept();
break;
......@@ -224,7 +228,7 @@ namespace RTC
static const Json::StaticString k_timestamp("timestamp");
static const Json::StaticString k_ssrc("ssrc");
// TODO: Check if stopped, etc (not yet done)
// TODO: Check if stopped, etc (not yet done).
// Process the packet.
// TODO: Must check what kind of packet we are checking. For example, RTX
......
#define MS_CLASS "RTC::RtpSender"
// #define MS_LOG_DEV
#include "RTC/RtpSender.h"
#include "MediaSoupError.h"
......@@ -53,7 +54,6 @@ namespace RTC
static const Json::StaticString k_rtpParameters("rtpParameters");
static const Json::StaticString k_hasTransport("hasTransport");
static const Json::StaticString k_available("available");
// TODO: TMP
static const Json::StaticString k_mapPayloadTypes("mapPayloadTypes");
Json::Value json(Json::objectValue);
......@@ -71,7 +71,6 @@ namespace RTC
json[k_available] = this->available;
// TODO: TMP
json[k_mapPayloadTypes] = Json::objectValue;
for (auto& kv : this->mapPayloadTypes)
{
......@@ -143,7 +142,7 @@ namespace RTC
auto& codec = *it;
auto it2 = this->peerCapabilities->codecs.begin();
for (; it2 != this->peerCapabilities->codecs.end(); ++it2)
for (; it2 != this->peerCapabilities->codecs.end(); it2++)
{
auto& codecCapability = *it2;
......@@ -222,8 +221,7 @@ namespace RTC
// TODO: We should not report an error here but just ignore it.
if (it == this->mapPayloadTypes.end())
{
MS_ERROR("payload type not mapped [payloadType:%" PRIu8 "]",
originalPayloadType);
MS_ERROR("payload type not mapped [payloadType:%" PRIu8 "]", originalPayloadType);
return;
}
......@@ -264,7 +262,7 @@ namespace RTC
{
auto it = this->peerCapabilities->codecs.begin();
for (; it != this->peerCapabilities->codecs.end(); ++it)
for (; it != this->peerCapabilities->codecs.end(); it++)
{
auto& codecCapability = *it;
......
// TODO: https://tools.ietf.org/html/rfc3550#appendix-A.1
// DOC: https://tools.ietf.org/html/rfc3550#appendix-A.1
#define MS_CLASS "RTC::RtpStream"
// #define MS_LOG_DEV
#include "RTC/RtpStream.h"
#include "Logger.h"
......@@ -47,8 +48,7 @@ namespace RTC
// If not a valid packet ignore it.
if (!UpdateSeq(seq))
{
// TODO: remove
MS_WARN("invalid packet [seq:%" PRIu16 "]", packet->GetSequenceNumber());
MS_WARN_TAG(rtp, "invalid packet [seq:%" PRIu16 "]", packet->GetSequenceNumber());
return false;
}
......@@ -305,7 +305,7 @@ namespace RTC
// NOTE: This should never happen.
if (buffer_it_r == this->buffer.rend())
{
MS_WARN("packet is older than anything in the buffer, ignoring it");
MS_WARN_TAG(rtp, "packet is older than anything in the buffer, ignoring it");
return;
}
......@@ -338,17 +338,17 @@ namespace RTC
{
MS_TRACE();
MS_WARN("<DUMP>");
MS_DEBUG_TAG(rtp, "<RtpStream>");
MS_WARN(" [buffer.size:%zu, storage.size:%zu]", this->buffer.size(), this->storage.size());
MS_DEBUG_TAG(rtp, " [buffer.size:%zu, storage.size:%zu]", this->buffer.size(), this->storage.size());
for (auto& buffer_item : this->buffer)
{
auto packet = buffer_item.packet;
MS_WARN(" packet [seq:%" PRIu16 ", seq32:%" PRIu32 "]", packet->GetSequenceNumber(), buffer_item.seq32);
MS_DEBUG_TAG(rtp, " packet [seq:%" PRIu16 ", seq32:%" PRIu32 "]", packet->GetSequenceNumber(), buffer_item.seq32);
}
MS_WARN("</DUMP>");
MS_DEBUG_TAG(rtp, "</RtpStream>");
}
}
#define MS_CLASS "RTC::SrtpSession"
// #define MS_LOG_DEV
#include "RTC/SrtpSession.h"
#include "DepLibSRTP.h"
#include "MediaSoupError.h"
#include "Logger.h"
#include <cstring> // std::memset(), std::memcpy()
#include <cstring> // std::memset(), std::memcpy()
#define MS_ENCRYPT_BUFFER_SIZE 65536
......@@ -34,16 +35,16 @@ namespace RTC
switch (data->event)
{
case event_ssrc_collision:
MS_WARN("SSRC collision occurred");
MS_WARN_TAG(srtp, "SSRC collision occurred");
break;
case event_key_soft_limit:
MS_WARN("stream reached the soft key usage limit and will expire soon");
MS_WARN_TAG(srtp, "stream reached the soft key usage limit and will expire soon");
break;
case event_key_hard_limit:
MS_WARN("stream reached the hard key usage limit and has expired");
MS_WARN_TAG(srtp, "stream reached the hard key usage limit and has expired");
break;
case event_packet_index_limit:
MS_WARN("stream reached the hard packet limit (2^48 packets)");
MS_WARN_TAG(srtp, "stream reached the hard packet limit (2^48 packets)");
break;
}
}
......@@ -126,7 +127,7 @@ namespace RTC
// Ensure that the resulting SRTP packet fits into the encrypt buffer.
if (*len + SRTP_MAX_TRAILER_LEN > MS_ENCRYPT_BUFFER_SIZE)
{
MS_WARN("cannot encrypt RTP packet, size too big (%zu bytes)", *len);
MS_WARN_TAG(srtp, "cannot encrypt RTP packet, size too big (%zu bytes)", *len);
return false;
}
......@@ -138,8 +139,7 @@ namespace RTC
err = srtp_protect(this->session, (void*)SrtpSession::encryptBuffer, (int*)len);
if (DepLibSRTP::IsError(err))
{
// TODO
MS_WARN("srtp_protect() failed: %s", DepLibSRTP::GetErrorString(err));
MS_WARN_TAG(srtp, "srtp_protect() failed: %s", DepLibSRTP::GetErrorString(err));
return false;
}
......@@ -159,8 +159,7 @@ namespace RTC
err = srtp_unprotect(this->session, (void*)data, (int*)len);
if (DepLibSRTP::IsError(err))
{
// TODO
MS_WARN("srtp_unprotect() failed: %s", DepLibSRTP::GetErrorString(err));
MS_WARN_TAG(srtp, "srtp_unprotect() failed: %s", DepLibSRTP::GetErrorString(err));
return false;
}
......@@ -175,7 +174,7 @@ namespace RTC
// Ensure that the resulting SRTCP packet fits into the encrypt buffer.
if (*len + SRTP_MAX_TRAILER_LEN > MS_ENCRYPT_BUFFER_SIZE)
{
MS_WARN("cannot encrypt RTCP packet, size too big (%zu bytes)", *len);
MS_WARN_TAG(srtp, "cannot encrypt RTCP packet, size too big (%zu bytes)", *len);
return false;
}
......@@ -187,8 +186,7 @@ namespace RTC
err = srtp_protect_rtcp(this->session, (void*)SrtpSession::encryptBuffer, (int*)len);
if (DepLibSRTP::IsError(err))
{
// TODO
MS_WARN("srtp_protect_rtcp() failed: %s", DepLibSRTP::GetErrorString(err));
MS_WARN_TAG(srtp, "srtp_protect_rtcp() failed: %s", DepLibSRTP::GetErrorString(err));
return false;
}
......@@ -208,8 +206,7 @@ namespace RTC
err = srtp_unprotect_rtcp(this->session, (void*)data, (int*)len);
if (DepLibSRTP::IsError(err))
{
// TODO
MS_WARN("srtp_unprotect_rtcp() failed: %s", DepLibSRTP::GetErrorString(err));
MS_WARN_TAG(srtp, "srtp_unprotect_rtcp() failed: %s", DepLibSRTP::GetErrorString(err));
return false;
}
......
#define MS_CLASS "RTC::StunMessage"
// #define MS_LOG_DEV
#include "RTC/StunMessage.h"
#include "Utils.h"
......@@ -49,7 +50,7 @@ namespace RTC
// length field must be total size minus header's 20 bytes, and must be multiple of 4 Bytes.
if (((size_t)msg_length != len - 20) || (msg_length & 0x03))
{
MS_DEBUG("length field + 20 does not match total size (or it is not multiple of 4 bytes), message discarded");
MS_WARN_TAG(ice, "length field + 20 does not match total size (or it is not multiple of 4 bytes), message discarded");
return nullptr;
}
......@@ -102,7 +103,7 @@ namespace RTC
// Ensure the attribute length is not greater than the remaining size.
if ((pos + 4 + attr_length) > len)
{
MS_DEBUG("the attribute length exceeds the remaining size, message discarded");
MS_WARN_TAG(ice, "the attribute length exceeds the remaining size, message discarded");
delete msg;
return nullptr;
......@@ -111,7 +112,7 @@ namespace RTC
// FINGERPRINT must be the last attribute.
if (has_fingerprint)
{
MS_DEBUG("attribute after FINGERPRINT is not allowed, message discarded");
MS_WARN_TAG(ice, "attribute after FINGERPRINT is not allowed, message discarded");
delete msg;
return nullptr;
......@@ -120,7 +121,7 @@ namespace RTC
// After a MESSAGE-INTEGRITY attribute just FINGERPRINT is allowed.
if (has_message_integrity && attr_type != Attribute::Fingerprint)
{
MS_DEBUG("attribute after MESSAGE_INTEGRITY other than FINGERPRINT is not allowed, message discarded");
MS_WARN_TAG(ice, "attribute after MESSAGE_INTEGRITY other than FINGERPRINT is not allowed, message discarded");
delete msg;
return nullptr;
......@@ -173,7 +174,7 @@ namespace RTC
// Ensure current position matches the total length.
if (pos != len)
{
MS_DEBUG("computed message size does not match total size, message discarded");
MS_WARN_TAG(ice, "computed message size does not match total size, message discarded");
delete msg;
return nullptr;
......@@ -189,7 +190,7 @@ namespace RTC
// Compare with the FINGERPRINT value in the message.
if (fingerprint != computed_fingerprint)
{
MS_DEBUG("computed FINGERPRINT value does not match the value in the message,| message discarded");
MS_WARN_TAG(ice, "computed FINGERPRINT value does not match the value in the message,| message discarded");
delete msg;
return nullptr;
......@@ -223,50 +224,48 @@ namespace RTC
{
MS_TRACE();
if (!Logger::HasDebugLevel())
return;
MS_DEBUG("<StunMessage>");
MS_DEBUG_DEV("<StunMessage>");
std::string klass;
switch (this->klass)
{
case Class::Request: klass = "Request"; break;
case Class::Indication: klass = "Indication"; break;
case Class::SuccessResponse: klass = "SuccessResponse"; break;
case Class::ErrorResponse: klass = "ErrorResponse"; break;
case Class::Request : klass = "Request"; break;
case Class::Indication : klass = "Indication"; break;
case Class::SuccessResponse : klass = "SuccessResponse"; break;
case Class::ErrorResponse : klass = "ErrorResponse"; break;
}
if (this->method == Method::Binding)
MS_DEBUG("Binding %s", klass.c_str());
MS_DEBUG_DEV(" Binding %s", klass.c_str());
else
// This prints the unknown method number. Example: TURN Allocate => 0x003.
MS_DEBUG("%s with unknown method %#.3x", klass.c_str(), (uint16_t)this->method);
MS_DEBUG("length (with header): %zu bytes", this->length);
MS_DEBUG_DEV(" %s with unknown method %#.3x", klass.c_str(), (uint16_t)this->method);
MS_DEBUG_DEV(" length (with header): %zu bytes", this->length);
char transaction_id[25];
for (int i=0; i<12; i++)
{
// NOTE: n must be 3 because snprintf adds a \0 after printed chars.
std::snprintf(transaction_id+(i*2), 3, "%.2x", this->transactionId[i]);
}
MS_DEBUG("transactionId: %s", transaction_id);
MS_DEBUG_DEV(" transactionId: %s", transaction_id);
if (this->errorCode)
MS_DEBUG("errorCode: %" PRIu16, this->errorCode);
MS_DEBUG_DEV(" errorCode: %" PRIu16, this->errorCode);
if (!this->username.empty())
MS_DEBUG("username: %s", this->username.c_str());
MS_DEBUG_DEV(" username: %s", this->username.c_str());
if (this->priority)
MS_DEBUG("priority: %" PRIu32, this->priority);
MS_DEBUG_DEV(" priority: %" PRIu32, this->priority);
if (this->iceControlling)
MS_DEBUG("iceControlling: %" PRIu64, this->iceControlling);
MS_DEBUG_DEV(" iceControlling: %" PRIu64, this->iceControlling);
if (this->iceControlled)
MS_DEBUG("iceControlled: %" PRIu64, this->iceControlled);
MS_DEBUG_DEV(" iceControlled: %" PRIu64, this->iceControlled);
if (this->hasUseCandidate)
MS_DEBUG("useCandidate");
MS_DEBUG_DEV(" useCandidate");
if (this->xorMappedAddress)
{
int family;
uint16_t port;
std::string ip;
Utils::IP::GetAddressInfo(this->xorMappedAddress, &family, ip, &port);
MS_DEBUG("xorMappedAddress: %s : %" PRIu16, ip.c_str(), port);
MS_DEBUG_DEV(" xorMappedAddress: %s : %" PRIu16, ip.c_str(), port);
}
if (this->messageIntegrity)
{
......@@ -275,11 +274,12 @@ namespace RTC
{
std::snprintf(message_integrity+(i*2), 3, "%.2x", this->messageIntegrity[i]);
}
MS_DEBUG("messageIntegrity: %s", message_integrity);
MS_DEBUG_DEV(" messageIntegrity: %s", message_integrity);
}
if (this->hasFingerprint)
MS_DEBUG("fingerprint");
MS_DEBUG("</StunMessage>");
MS_DEBUG_DEV(" fingerprint");
MS_DEBUG_DEV("</StunMessage>");
}
StunMessage::Authentication StunMessage::CheckAuthentication(const std::string &local_username, const std::string &local_password)
......
#define MS_CLASS "RTC::TcpConnection"
// #define MS_LOG_DEV
#include "RTC/TcpConnection.h"
#include "Utils.h"
#include "Logger.h"
#include <cstring> // std::memmove()
#include <cstring> // std::memmove()
namespace RTC
{
......@@ -25,7 +26,7 @@ namespace RTC
{
MS_TRACE();
MS_DEBUG("data received [local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]",
MS_DEBUG_DEV("data received [local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]",
GetLocalIP().c_str(), GetLocalPort(),
GetPeerIP().c_str(), GetPeerPort());
......@@ -75,7 +76,7 @@ namespace RTC
// the latest parsed frame filled it, then empty the full buffer.
if ((this->frameStart + 2 + packet_len) == this->bufferSize)
{
MS_DEBUG("no more space in the buffer, emptying the buffer data");
MS_DEBUG_DEV("no more space in the buffer, emptying the buffer data");
this->frameStart = 0;
this->bufferDataLen = 0;
......@@ -91,7 +92,7 @@ namespace RTC
// parse again. Otherwise break here and wait for more data.
if (this->bufferDataLen > this->frameStart)
{
// MS_DEBUG("there is more data after the parsed frame, continue parsing");
MS_DEBUG_DEV("there is more data after the parsed frame, continue parsing");
continue;
}
......@@ -111,7 +112,7 @@ namespace RTC
// the buffer, so move the frame to the position 0.
if (this->frameStart != 0)
{
// MS_DEBUG("no more space in the buffer, moving parsed bytes to the beginning of the buffer and wait for more data");
MS_DEBUG_DEV("no more space in the buffer, moving parsed bytes to the beginning of the buffer and wait for more data");
std::memmove(this->buffer, this->buffer + this->frameStart, this->bufferSize - this->frameStart);
this->bufferDataLen = this->bufferSize - this->frameStart;
......@@ -121,7 +122,7 @@ namespace RTC
// The frame is too big, so close the connection.
else
{
MS_WARN("no more space in the buffer for the unfinished frame being parsed, closing the connection");
MS_WARN_DEV("no more space in the buffer for the unfinished frame being parsed, closing the connection");
// Close the socket.
Close();
......@@ -130,7 +131,7 @@ namespace RTC
// The buffer is not full.
else
{
MS_DEBUG("frame not finished yet, waiting for more data");
MS_DEBUG_DEV("frame not finished yet, waiting for more data");
}
// Exit the parsing loop.
......
#define MS_CLASS "RTC::TcpServer"
// #define MS_LOG_DEV
#include "RTC/TcpServer.h"
#include "Settings.h"
......@@ -125,13 +126,11 @@ namespace RTC
// Check whether the chosen port is available.
if (!(*available_ports)[iterating_port])
{
MS_DEBUG("port in use, trying again [port:%" PRIu16 ", attempt:%" PRIu16 "]", iterating_port, attempt);
MS_DEBUG_DEV("port in use, trying again [port:%" PRIu16 ", attempt:%" PRIu16 "]", iterating_port, attempt);
// If we have tried all the ports in the range raise an error.
if (iterating_port == initial_port)
{
MS_THROW_ERROR("no more available ports for IP '%s'", listen_ip);
}
continue;
}
......@@ -165,27 +164,21 @@ namespace RTC
err = uv_tcp_bind(uvHandle, (const struct sockaddr*)&bind_addr, flags);
if (err)
{
MS_WARN("uv_tcp_bind() failed [port:%" PRIu16 ", attempt:%" PRIu16 "]: %s", attempt, iterating_port, uv_strerror(err));
MS_WARN_DEV("uv_tcp_bind() failed [port:%" PRIu16 ", attempt:%" PRIu16 "]: %s", attempt, iterating_port, uv_strerror(err));
uv_close((uv_handle_t*)uvHandle, (uv_close_cb)on_error_close);
// If bind() fails due to "too many open files" stop here.
if (err == UV_EMFILE)
{
MS_THROW_ERROR("uv_tcp_bind() fails due to many open files");
}
// If bind() fails for more that MAX_BIND_ATTEMPTS then raise an error.
if (bind_attempt > MAX_BIND_ATTEMPTS)
{
MS_THROW_ERROR("uv_tcp_bind() fails more than %u times for IP '%s'", MAX_BIND_ATTEMPTS, listen_ip);
}
// If we have tried all the ports in the range raise an error.
if (iterating_port == initial_port)
{
MS_THROW_ERROR("no more available ports for IP '%s'", listen_ip);
}
continue;
}
......@@ -193,8 +186,8 @@ namespace RTC
// Set the port as unavailable.
(*available_ports)[iterating_port] = false;
MS_DEBUG("bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]",
listen_ip, iterating_port, attempt);
MS_DEBUG_DEV("bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]",
listen_ip, iterating_port, attempt);
return uvHandle;
};
......
#define MS_CLASS "RTC::TransportTuple"
// #define MS_LOG_DEV
#include "RTC/TransportTuple.h"
#include "Logger.h"
......@@ -41,13 +42,11 @@ namespace RTC
return json;
}
// TODO: TMP
void TransportTuple::Dump()
{
MS_TRACE();
#ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel())
return;
MS_TRACE();
switch (this->protocol)
{
......@@ -59,7 +58,7 @@ namespace RTC
Utils::IP::GetAddressInfo(GetRemoteAddress(), &remote_family, remote_ip, &remote_port);
MS_DEBUG("[UDP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]",
MS_DEBUG_DEV("[UDP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]",
this->udpSocket->GetLocalIP().c_str(), this->udpSocket->GetLocalPort(),
remote_ip.c_str(), remote_port);
break;
......@@ -67,11 +66,13 @@ namespace RTC
case Protocol::TCP:
{
MS_DEBUG("[TCP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]",
MS_DEBUG_DEV("[TCP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 "]",
this->tcpConnection->GetLocalIP().c_str(), this->tcpConnection->GetLocalPort(),
this->tcpConnection->GetPeerIP().c_str(), this->tcpConnection->GetPeerPort());
break;
}
}
#endif
}
}
#define MS_CLASS "RTC::UdpSocket"
// #define MS_LOG_DEV
#include "RTC/UdpSocket.h"
#include "Settings.h"
......@@ -124,7 +125,7 @@ namespace RTC
// Check whether the chosen port is available.
if (!(*available_ports)[iterating_port])
{
MS_DEBUG("port in use, trying again [port:%" PRIu16 ", attempt:%" PRIu16 "]", iterating_port, attempt);
MS_DEBUG_DEV("port in use, trying again [port:%" PRIu16 ", attempt:%" PRIu16 "]", iterating_port, attempt);
// If we have tried all the ports in the range raise an error.
if (iterating_port == initial_port) {
......@@ -163,27 +164,21 @@ namespace RTC
err = uv_udp_bind(uvHandle, (const struct sockaddr*)&bind_addr, flags);
if (err)
{
MS_WARN("uv_udp_bind() failed [port:%" PRIu16 ", attempt:%" PRIu16 "]: %s", attempt, iterating_port, uv_strerror(err));
MS_WARN_DEV("uv_udp_bind() failed [port:%" PRIu16 ", attempt:%" PRIu16 "]: %s", attempt, iterating_port, uv_strerror(err));
uv_close((uv_handle_t*)uvHandle, (uv_close_cb)on_error_close);
// If bind() fails due to "too many open files" stop here.
if (err == UV_EMFILE)
{
MS_THROW_ERROR("uv_udp_bind() fails due to many open files");
}
// If bind() fails for more that MAX_BIND_ATTEMPTS then raise an error.
if (bind_attempt > MAX_BIND_ATTEMPTS)
{
MS_THROW_ERROR("uv_udp_bind() fails more than %u times for IP '%s'", MAX_BIND_ATTEMPTS, listen_ip);
}
// If we have tried all the ports in the range raise an error.
if (iterating_port == initial_port)
{
MS_THROW_ERROR("no more available ports for IP '%s'", listen_ip);
}
continue;
}
......@@ -191,8 +186,8 @@ namespace RTC
// Set the port as unavailable.
(*available_ports)[iterating_port] = false;
MS_DEBUG("bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]",
listen_ip, iterating_port, attempt);
MS_DEBUG_DEV("bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]",
listen_ip, iterating_port, attempt);
return uvHandle;
};
......@@ -221,18 +216,6 @@ namespace RTC
return;
}
if (Logger::HasDebugLevel())
{
int family;
uint16_t port;
std::string ip;
Utils::IP::GetAddressInfo(addr, &family, ip, &port);
// TODO: REMOVE
// MS_DEBUG("datagram received [local:%s :%" PRIu16 ", remote:%s :%" PRIu16 ", len:%zu]",
// GetLocalIP().c_str(), GetLocalPort(), ip.c_str(), port, len);
}
// Notify the reader.
this->listener->onPacketRecv(this, data, len, addr);
}
......
#define MS_CLASS "Settings"
// #define MS_LOG_DEV
#include "Settings.h"
#include "Utils.h"
#include "MediaSoupError.h"
#include "Logger.h"
#include <string>
#include <map>
#include <cctype> // isprint()
#include <cctype> // isprint()
#include <cerrno>
#include <unistd.h> // close()
#include <unistd.h> // close()
#include <uv.h>
extern "C"
{
......@@ -23,6 +22,7 @@ bool IsBindableIP(const std::string &ip, int family, int* _bind_err);
/* Class variables. */
struct Settings::Configuration Settings::configuration;
struct Settings::LogTags Settings::logTags;
std::map<std::string, LogLevel> Settings::string2LogLevel =
{
{ "debug", LogLevel::LOG_DEBUG },
......@@ -54,10 +54,12 @@ void Settings::SetConfiguration(int argc, char* argv[])
int c;
int option_index = 0;
std::string value_string;
std::vector<std::string> log_tags;
struct option options[] =
{
{ "logLevel", optional_argument, nullptr, 'l' },
{ "logTag", optional_argument, nullptr, 't' },
{ "rtcListenIPv4", optional_argument, nullptr, '4' },
{ "rtcListenIPv6", optional_argument, nullptr, '6' },
{ "rtcMinPort", optional_argument, nullptr, 'm' },
......@@ -82,6 +84,11 @@ void Settings::SetConfiguration(int argc, char* argv[])
SetLogLevel(value_string);
break;
case 't':
value_string = std::string(optarg);
log_tags.push_back(value_string);
break;
case '4':
value_string = std::string(optarg);
SetRtcListenIPv4(value_string);
......@@ -129,6 +136,10 @@ void Settings::SetConfiguration(int argc, char* argv[])
/* Post configuration. */
// Set logTags.
if (!log_tags.empty())
Settings::SetLogTags(log_tags);
// RTC must have at least 'listenIPv4' or 'listenIPv6'.
if (!Settings::configuration.hasIPv4 && !Settings::configuration.hasIPv6)
MS_THROW_ERROR("at least rtcListenIPv4 or rtcListenIPv6 must be enabled");
......@@ -144,26 +155,45 @@ void Settings::PrintConfiguration()
{
MS_TRACE();
MS_DEBUG("<configuration>");
MS_DEBUG("logLevel: \"%s\"", Settings::logLevel2String[Settings::configuration.logLevel].c_str());
std::vector<std::string> log_tags;
if (Settings::logTags.info)
log_tags.push_back("info");
if (Settings::logTags.ice)
log_tags.push_back("ice");
if (Settings::logTags.dtls)
log_tags.push_back("dtls");
if (Settings::logTags.rtp)
log_tags.push_back("rtp");
if (Settings::logTags.srtp)
log_tags.push_back("srtp");
if (Settings::logTags.rtcp)
log_tags.push_back("rtcp");
MS_DEBUG_TAG(info, "<configuration>");
MS_DEBUG_TAG(info, "logLevel: \"%s\"", Settings::logLevel2String[Settings::configuration.logLevel].c_str());
for (auto& tag : log_tags)
{
MS_DEBUG_TAG(info, "logTag: \"%s\"", tag.c_str());
}
if (Settings::configuration.hasIPv4)
MS_DEBUG("rtcListenIPv4: \"%s\"", Settings::configuration.rtcListenIPv4.c_str());
MS_DEBUG_TAG(info, "rtcListenIPv4: \"%s\"", Settings::configuration.rtcListenIPv4.c_str());
else
MS_DEBUG("rtcListenIPv4: (unavailable)");
MS_DEBUG_TAG(info, "rtcListenIPv4: (unavailable)");
if (Settings::configuration.hasIPv6)
MS_DEBUG("rtcListenIPv6: \"%s\"", Settings::configuration.rtcListenIPv6.c_str());
MS_DEBUG_TAG(info, "rtcListenIPv6: \"%s\"", Settings::configuration.rtcListenIPv6.c_str());
else
MS_DEBUG("rtcListenIPv6: (unavailable)");
MS_DEBUG("rtcMinPort: %" PRIu16, Settings::configuration.rtcMinPort);
MS_DEBUG("rtcMaxPort: %" PRIu16, Settings::configuration.rtcMaxPort);
MS_DEBUG_TAG(info, "rtcListenIPv6: (unavailable)");
MS_DEBUG_TAG(info, "rtcMinPort: %" PRIu16, Settings::configuration.rtcMinPort);
MS_DEBUG_TAG(info, "rtcMaxPort: %" PRIu16, Settings::configuration.rtcMaxPort);
if (!Settings::configuration.dtlsCertificateFile.empty())
{
MS_DEBUG("dtlsCertificateFile: \"%s\"", Settings::configuration.dtlsCertificateFile.c_str());
MS_DEBUG("dtlsPrivateKeyFile: \"%s\"", Settings::configuration.dtlsPrivateKeyFile.c_str());
MS_DEBUG_TAG(info, "dtlsCertificateFile: \"%s\"", Settings::configuration.dtlsCertificateFile.c_str());
MS_DEBUG_TAG(info, "dtlsPrivateKeyFile: \"%s\"", Settings::configuration.dtlsPrivateKeyFile.c_str());
}
MS_DEBUG("</configuration>");
MS_DEBUG_TAG(info, "</configuration>");
}
void Settings::HandleRequest(Channel::Request* request)
......@@ -175,8 +205,10 @@ void Settings::HandleRequest(Channel::Request* request)
case Channel::Request::MethodId::worker_updateSettings:
{
static const Json::StaticString k_logLevel("logLevel");
static const Json::StaticString k_logTags("logTags");
Json::Value json_logLevel = request->data[k_logLevel];
Json::Value json_logTags = request->data[k_logTags];
try
{
......@@ -187,6 +219,12 @@ void Settings::HandleRequest(Channel::Request* request)
Settings::SetLogLevel(logLevel);
}
// Update logTags if requested.
if (json_logTags.isArray())
{
Settings::SetLogTags(json_logTags);
}
}
catch (const MediaSoupError &error)
{
......@@ -194,9 +232,7 @@ void Settings::HandleRequest(Channel::Request* request)
return;
}
MS_DEBUG("updated settings:");
// Print configuration.
// Print the new effective configuration.
Settings::PrintConfiguration();
request->Accept();
......@@ -429,6 +465,49 @@ void Settings::SetDtlsCertificateAndPrivateKeyFiles()
Settings::configuration.dtlsPrivateKeyFile = dtlsPrivateKeyFile;
}
void Settings::SetLogTags(std::vector<std::string>& tags)
{
MS_TRACE();
// Reset logTags.
struct LogTags newLogTags;
Settings::logTags = newLogTags;
for (auto& tag : tags)
{
if (tag == "info")
Settings::logTags.info = true;
else if (tag == "ice")
Settings::logTags.ice = true;
else if (tag == "dtls")
Settings::logTags.dtls = true;
else if (tag == "rtp")
Settings::logTags.rtp = true;
else if (tag == "srtp")
Settings::logTags.srtp = true;
else if (tag == "rtcp")
Settings::logTags.rtcp = true;
}
}
void Settings::SetLogTags(Json::Value& json)
{
MS_TRACE();
std::vector<std::string> tags;
for (Json::UInt i = 0; i < json.size(); i++)
{
Json::Value entry = json[i];
if (entry.isString())
tags.push_back(entry.asString());
}
Settings::SetLogTags(tags);
}
/* Helpers. */
bool IsBindableIP(const std::string &ip, int family, int* bind_errno)
......
#define MS_CLASS "Utils::Crypto"
// #define MS_LOG_DEV
#include "Utils.h"
#include "Logger.h"
......
#define MS_CLASS "Utils::File"
// #define MS_LOG_DEV
#include "Utils.h"
#include "MediaSoupError.h"
#include "Logger.h"
#include <cerrno>
#include <unistd.h> // access(), R_OK
#include <sys/stat.h> // stat()
#include <unistd.h> // access(), R_OK
#include <sys/stat.h> // stat()
namespace Utils
{
......
#define MS_CLASS "Utils::IP"
// #define MS_LOG_DEV
#include "Utils.h"
#include "Logger.h"
......
#define MS_CLASS "SignalsHandler"
// #define MS_LOG_DEV
#include "handles/SignalsHandler.h"
#include "DepLibUV.h"
......
#define MS_CLASS "TcpConnection"
// #define MS_LOG_DEV
#include "handles/TcpConnection.h"
#include "Utils.h"
#include "DepLibUV.h"
#include "MediaSoupError.h"
#include "Logger.h"
#include <cstring> // std::memcpy()
#include <cstdlib> // std::malloc(), std::free()
#include <cstring> // std::memcpy()
#include <cstdlib> // std::malloc(), std::free()
/* Static methods for UV callbacks. */
......@@ -83,6 +84,7 @@ void TcpConnection::Setup(Listener* listener, struct sockaddr_storage* localAddr
{
delete this->uvHandle;
this->uvHandle = nullptr;
MS_THROW_ERROR("uv_tcp_init() failed: %s", uv_strerror(err));
}
......@@ -131,7 +133,7 @@ void TcpConnection::Close()
void TcpConnection::Dump()
{
MS_DEBUG("[Tcp, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 ", status:%s]",
MS_DEBUG_DEV("[Tcp, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 ", status:%s]",
this->localIP.c_str(), (uint16_t)this->localPort,
this->peerIP.c_str(), (uint16_t)this->peerPort,
(!this->isClosing) ? "open" : "closed");
......@@ -189,13 +191,13 @@ void TcpConnection::Write(const uint8_t* data, size_t len)
// Error. Should not happen.
else if (written < 0)
{
MS_WARN("uv_try_write() failed, closing the connection: %s", uv_strerror(written));
MS_WARN_DEV("uv_try_write() failed, closing the connection: %s", uv_strerror(written));
Close();
return;
}
// MS_DEBUG("could just write %zu bytes (%zu given) at first time, using uv_write() now", (size_t)written, len);
// MS_DEBUG_DEV("could just write %zu bytes (%zu given) at first time, using uv_write() now", (size_t)written, len);
size_t pending_len = len - written;
......@@ -249,13 +251,13 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data
// Error. Should not happen.
else if (written < 0)
{
MS_WARN("uv_try_write() failed, closing the connection: %s", uv_strerror(written));
MS_WARN_DEV("uv_try_write() failed, closing the connection: %s", uv_strerror(written));
Close();
return;
}
// MS_DEBUG("could just write %zu bytes (%zu given) at first time, using uv_write() now", (size_t)written, total_len);
// MS_DEBUG_DEV("could just write %zu bytes (%zu given) at first time, using uv_write() now", (size_t)written, total_len);
size_t pending_len = total_len - written;
......@@ -324,7 +326,7 @@ void TcpConnection::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf)
{
buf->len = 0;
MS_WARN("no available space in the buffer");
MS_WARN_DEV("no available space in the buffer");
}
}
......@@ -351,7 +353,7 @@ void TcpConnection::onUvRead(ssize_t nread, const uv_buf_t* buf)
// Client disconneted.
else if (nread == UV_EOF || nread == UV_ECONNRESET)
{
MS_DEBUG("connection closed by peer, closing server side");
MS_DEBUG_DEV("connection closed by peer, closing server side");
this->isClosedByPeer = true;
......@@ -361,7 +363,7 @@ void TcpConnection::onUvRead(ssize_t nread, const uv_buf_t* buf)
// Some error.
else
{
MS_DEBUG("read error, closing the connection: %s", uv_strerror(nread));
MS_WARN_DEV("read error, closing the connection: %s", uv_strerror(nread));
this->hasError = true;
......@@ -380,11 +382,11 @@ void TcpConnection::onUvWriteError(int error)
if (error == UV_EPIPE || error == UV_ENOTCONN)
{
MS_DEBUG("write error, closing the connection: %s", uv_strerror(error));
MS_WARN_DEV("write error, closing the connection: %s", uv_strerror(error));
}
else
{
MS_DEBUG("write error, closing the connection: %s", uv_strerror(error));
MS_WARN_DEV("write error, closing the connection: %s", uv_strerror(error));
this->hasError = true;
}
......@@ -400,9 +402,9 @@ void TcpConnection::onUvShutdown(uv_shutdown_t* req, int status)
delete req;
if (status == UV_EPIPE || status == UV_ENOTCONN || status == UV_ECANCELED)
MS_DEBUG("shutdown error: %s", uv_strerror(status));
MS_WARN_DEV("shutdown error: %s", uv_strerror(status));
else if (status)
MS_DEBUG("shutdown error: %s", uv_strerror(status));
MS_WARN_DEV("shutdown error: %s", uv_strerror(status));
// Now do close the handle.
uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close);
......
#define MS_CLASS "TcpServer"
// #define MS_LOG_DEV
#include "handles/TcpServer.h"
#include "Utils.h"
......@@ -141,9 +142,9 @@ void TcpServer::Close()
// Otherwise close all the connections (but not the TCP server).
else
{
MS_DEBUG("closing %zu active connections", this->connections.size());
MS_DEBUG_DEV("closing %zu active connections", this->connections.size());
for (auto it = this->connections.begin(); it != this->connections.end(); ++it)
for (auto it = this->connections.begin(); it != this->connections.end(); it++)
{
TcpConnection* connection = *it;
connection->Close();
......@@ -153,7 +154,7 @@ void TcpServer::Close()
void TcpServer::Dump()
{
MS_DEBUG("[TCP, local:%s :%" PRIu16 ", status:%s, connections:%zu]",
MS_DEBUG_DEV("[TCP, local:%s :%" PRIu16 ", status:%s, connections:%zu]",
this->localIP.c_str(), (uint16_t)this->localPort,
(!this->isClosing) ? "open" : "closed",
this->connections.size());
......@@ -290,7 +291,7 @@ void TcpServer::onTcpConnectionClosed(TcpConnection* connection, bool is_closed_
bool wasClosing = this->isClosing;
MS_DEBUG("TCP connection closed:");
MS_DEBUG_DEV("TCP connection closed");
connection->Dump();
// Remove the TcpConnection from the set.
......
#define MS_CLASS "Timer"
// #define MS_LOG_DEV
#include "handles/Timer.h"
#include "MediaSoupError.h"
......
#define MS_CLASS "UdpSocket"
// #define MS_LOG_DEV
#include "handles/UdpSocket.h"
#include "Utils.h"
......@@ -171,7 +172,7 @@ void UdpSocket::Close()
void UdpSocket::Dump()
{
MS_DEBUG("[UDP, local:%s :%" PRIu16 ", status:%s]",
MS_DEBUG_DEV("[UDP, local:%s :%" PRIu16 ", status:%s]",
this->localIP.c_str(), (uint16_t)this->localPort,
(!this->isClosing) ? "open" : "closed");
}
......@@ -203,20 +204,20 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add
}
else if (sent >= 0)
{
MS_WARN("datagram truncated (just %d of %zu bytes were sent)", sent, len);
MS_WARN_DEV("datagram truncated (just %d of %zu bytes were sent)", sent, len);
return;
}
// Error,
else if (sent != UV_EAGAIN)
{
MS_WARN("uv_udp_try_send() failed: %s", uv_strerror(sent));
MS_WARN_DEV("uv_udp_try_send() failed: %s", uv_strerror(sent));
return;
}
// Otherwise UV_EAGAIN was returned so cannot send data at first time. Use uv_udp_send().
// MS_DEBUG("could not send the datagram at first time, using uv_udp_send() now");
// MS_DEBUG_DEV("could not send the datagram at first time, using uv_udp_send() now");
// Allocate a special UvSendData struct pointer.
UvSendData* send_data = (UvSendData*)std::malloc(sizeof(UvSendData) + len);
......@@ -232,7 +233,7 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add
{
// NOTE: uv_udp_send() returns error if a wrong INET family is given
// (IPv6 destination on a IPv4 binded socket), so be ready.
MS_WARN("uv_udp_send() failed: %s", uv_strerror(err));
MS_WARN_DEV("uv_udp_send() failed: %s", uv_strerror(err));
// Delete the UvSendData struct (which includes the uv_req_t and the store char[]).
std::free(send_data);
......@@ -339,7 +340,7 @@ void UdpSocket::onUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockad
// Some error.
else
{
MS_DEBUG("read error: %s", uv_strerror(nread));
MS_DEBUG_DEV("read error: %s", uv_strerror(nread));
}
}
......@@ -351,7 +352,7 @@ void UdpSocket::onUvSendError(int error)
if (this->isClosing)
return;
MS_DEBUG("send error: %s", uv_strerror(error));
MS_DEBUG_DEV("send error: %s", uv_strerror(error));
}
inline
......
/**
* NOTE: This code cannot use MS_DEBUG, MS_WARN, MS_ERROR since this is the base
* code of the intercommunication Channel.
* NOTE: This code cannot log to the Channel since this is the base code of the
* Channel.
*/
#define MS_CLASS "UnixStreamSocket"
// #define MS_LOG_DEV
#include "handles/UnixStreamSocket.h"
#include "DepLibUV.h"
#include "MediaSoupError.h"
#include "Logger.h"
#include <cstring> // std::memcpy()
#include <cstdlib> // std::malloc(), std::free()
#include <cstring> // std::memcpy()
#include <cstdlib> // std::malloc(), std::free()
/* Static methods for UV callbacks. */
......@@ -206,7 +207,6 @@ void UnixStreamSocket::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf)
if (this->bufferSize > this->bufferDataLen)
{
buf->len = this->bufferSize - this->bufferDataLen;
// MS_DEBUG_STD("available space in the buffer: %zu", buf->len);
}
else
{
......@@ -236,8 +236,6 @@ void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf)
// Peer disconneted.
else if (nread == UV_EOF || nread == UV_ECONNRESET)
{
MS_DEBUG("connection closed by peer, closing server side");
this->isClosedByPeer = true;
// Close local side of the pipe.
......@@ -265,11 +263,11 @@ void UnixStreamSocket::onUvWriteError(int error)
if (error == UV_EPIPE || error == UV_ENOTCONN)
{
MS_DEBUG_STD("write error, closing the pipe: %s", uv_strerror(error));
MS_ERROR_STD("write error, closing the pipe: %s", uv_strerror(error));
}
else
{
MS_DEBUG_STD("write error, closing the pipe: %s", uv_strerror(error));
MS_ERROR_STD("write error, closing the pipe: %s", uv_strerror(error));
this->hasError = true;
}
......@@ -285,9 +283,9 @@ void UnixStreamSocket::onUvShutdown(uv_shutdown_t* req, int status)
delete req;
if (status == UV_EPIPE || status == UV_ENOTCONN || status == UV_ECANCELED)
MS_DEBUG_STD("shutdown error: %s", uv_strerror(status));
MS_ERROR_STD("shutdown error: %s", uv_strerror(status));
else if (status)
MS_DEBUG_STD("shutdown error: %s", uv_strerror(status));
MS_ERROR_STD("shutdown error: %s", uv_strerror(status));
// Now do close the handle.
uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close);
......
#define MS_CLASS "main"
// #define MS_LOG_DEV
#include "common.h"
#include "Settings.h"
......@@ -17,7 +18,7 @@
#include "Logger.h"
#include <map>
#include <string>
#include <iostream> // std::cerr, std::endl
#include <iostream> // std::cout, std::cerr, std::endl
#include <cstdlib> // std::_Exit(), std::genenv()
#include <csignal> // sigaction()
#include <cerrno>
......@@ -66,20 +67,20 @@ int main(int argc, char* argv[])
// Print the effective configuration.
Settings::PrintConfiguration();
MS_DEBUG("starting " MS_PROCESS_NAME " [pid:%ld]", (long)getpid());
MS_DEBUG_TAG(info, "starting " MS_PROCESS_NAME " [pid:%ld]", (long)getpid());
#if defined(MS_LITTLE_ENDIAN)
MS_DEBUG("Little-Endian CPU detected");
MS_DEBUG_TAG(info, "Little-Endian CPU detected");
#elif defined(MS_BIG_ENDIAN)
MS_DEBUG("Big-Endian CPU detected");
MS_DEBUG_TAG(info, "Big-Endian CPU detected");
#endif
#if defined(INTPTR_MAX) && defined(INT32_MAX) && (INTPTR_MAX == INT32_MAX)
MS_DEBUG("32 bits architecture detected");
MS_DEBUG_TAG(info, "32 bits architecture detected");
#elif defined(INTPTR_MAX) && defined(INT64_MAX) && (INTPTR_MAX == INT64_MAX)
MS_DEBUG("64 bits architecture detected");
MS_DEBUG_TAG(info, "64 bits architecture detected");
#else
MS_WARN("can not determine whether the architecture is 32 or 64 bits");
MS_WARN_TAG(info, "can not determine whether the architecture is 32 or 64 bits");
#endif
try
......@@ -89,9 +90,8 @@ int main(int argc, char* argv[])
// Run the Loop.
Loop loop(channel);
// Loop ended.
destroy();
MS_DEBUG_STD("success exit");
exitSuccess();
}
catch (const MediaSoupError &error)
......@@ -144,7 +144,7 @@ void ignoreSignals()
if (err)
MS_THROW_ERROR("sigfillset() failed: %s", std::strerror(errno));
for (auto it = ignored_signals.begin(); it != ignored_signals.end(); ++it)
for (auto it = ignored_signals.begin(); it != ignored_signals.end(); it++)
{
auto& sig_name = it->first;
int sig_id = it->second;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论