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

New Logger macros and log tags mechanism (#46)

Logger macros documentation detailed at the top of include/Logger.h.
New logTags mechanism for runtime verbose logging uses a list of tags defined in include/Settings.h and src/Settings.cpp. These tags are set in the Server JS constructor options and Server.updateSettings() method.
上级 653453b9
...@@ -12,8 +12,14 @@ const Worker = require('./Worker'); ...@@ -12,8 +12,14 @@ const Worker = require('./Worker');
const DEFAULT_NUM_WORKERS = Object.keys(os.cpus()).length; const DEFAULT_NUM_WORKERS = Object.keys(os.cpus()).length;
const VALID_WORKER_PARAMETERS = const VALID_WORKER_PARAMETERS =
[ [
'logLevel', 'rtcListenIPv4', 'rtcListenIPv6', 'rtcMinPort', 'rtcMaxPort', 'logLevel',
'dtlsCertificateFile', 'dtlsPrivateKeyFile' 'logTags',
'rtcListenIPv4',
'rtcListenIPv6',
'rtcMinPort',
'rtcMaxPort',
'dtlsCertificateFile',
'dtlsPrivateKeyFile'
]; ];
class Server extends EventEmitter class Server extends EventEmitter
...@@ -43,6 +49,9 @@ class Server extends EventEmitter ...@@ -43,6 +49,9 @@ class Server extends EventEmitter
if (check.integer(options.numWorkers) && check.positive(options.numWorkers)) if (check.integer(options.numWorkers) && check.positive(options.numWorkers))
numWorkers = options.numWorkers; numWorkers = options.numWorkers;
if (!check.array(options.logTags))
options.logTags = [];
if (options.rtcListenIPv4 === null || options.rtcListenIPv4 === undefined) if (options.rtcListenIPv4 === null || options.rtcListenIPv4 === undefined)
delete options.rtcListenIPv4; delete options.rtcListenIPv4;
...@@ -71,9 +80,26 @@ class Server extends EventEmitter ...@@ -71,9 +80,26 @@ class Server extends EventEmitter
for (let key of Object.keys(options)) for (let key of Object.keys(options))
{ {
if (check.includes(VALID_WORKER_PARAMETERS, 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])}`); parameters.push(`--${key}=${String(options[key])}`);
} }
}
// Create Worker instances. // Create Worker instances.
for (let i = 1; i <= numWorkers; i++) for (let i = 1; i <= numWorkers; i++)
......
...@@ -18,10 +18,11 @@ module.exports = ...@@ -18,10 +18,11 @@ module.exports =
/** /**
* Create a Server instance. * Create a Server instance.
* *
* @param {Object} [options] * @param {object} [options]
* @param {number} [options.numWorkers=HOST_NUM_CORES] - Number of child workers. * @param {number} [options.numWorkers=HOST_NUM_CORES] - Number of child workers.
* @param {string} [options.logLevel='debug'] - Log level. Valid values are * @param {string} [options.logLevel='debug'] - Log level. Valid values are
* 'debug', 'warn', 'error'. * 'debug', 'warn', 'error'.
* @param {array} [options.logTags] - Log tags.
* @param {string|boolean} [options.rtcListenIPv4=true] - IPv4 for RTC. Valid * @param {string|boolean} [options.rtcListenIPv4=true] - IPv4 for RTC. Valid
* values are a IPv4, `true` (auto-detect) and `false` (disabled). * values are a IPv4, `true` (auto-detect) and `false` (disabled).
* @param {string|boolean} [options.rtcListenIPv6=true] - IPv6 for RTC. Valid * @param {string|boolean} [options.rtcListenIPv6=true] - IPv6 for RTC. Valid
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
}, },
'Debug': 'Debug':
{ {
'defines': [ ' MS_DEVEL', 'DEBUG' ], 'defines': [ 'DEBUG', 'MS_LOG_FILE_LINE', 'MS_LOG_TRACE' ],
'cflags': [ '-g', '-O0', '-fwrapv', '-Wno-parentheses-equality' ], 'cflags': [ '-g', '-O0', '-fwrapv', '-Wno-parentheses-equality' ],
'xcode_settings': '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 #ifndef MS_LOGGER_H
#define MS_LOGGER_H #define MS_LOGGER_H
...@@ -11,39 +68,18 @@ ...@@ -11,39 +68,18 @@
#include <cstdlib> // std::abort() #include <cstdlib> // std::abort()
#define MS_LOGGER_BUFFER_SIZE 10000 #define MS_LOGGER_BUFFER_SIZE 10000
#define _MS_TAG_ENABLED(tag) Settings::logTags.tag
/* #define _MS_TAG_ENABLED_2(tag1, tag2) (Settings::logTags.tag1 || Settings::logTags.tag2)
* Logger facility. #ifdef MS_LOG_DEV
* #define _MS_LOG_DEV_ENABLED true
* If the macro MS_DEVEL is set (see below) the output is even more verbose #else
* (it shows the file number in each log and enables the MS_TRACE() call). #define _MS_LOG_DEV_ENABLED false
* #endif
* 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
class Logger class Logger
{ {
public: public:
static void Init(const std::string& id, Channel::UnixStreamSocket* channel); static void Init(const std::string& id, Channel::UnixStreamSocket* channel);
static bool HasDebugLevel();
public: public:
static std::string id; static std::string id;
...@@ -51,21 +87,11 @@ public: ...@@ -51,21 +87,11 @@ public:
static char buffer[]; static char buffer[];
}; };
/* Inline static methods. */ /* Logging macros. */
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.
#define _MS_LOG_SEPARATOR_CHAR_STD "\n" #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 "[%s] %s:%d | %s::%s()"
#define _MS_LOG_STR_DESC _MS_LOG_STR " | " #define _MS_LOG_STR_DESC _MS_LOG_STR " | "
#define _MS_FILE (std::strchr(__FILE__, '/') ? std::strchr(__FILE__, '/') + 1 : __FILE__) #define _MS_FILE (std::strchr(__FILE__, '/') ? std::strchr(__FILE__, '/') + 1 : __FILE__)
...@@ -76,15 +102,16 @@ bool Logger::HasDebugLevel() ...@@ -76,15 +102,16 @@ bool Logger::HasDebugLevel()
#define _MS_LOG_ARG ("id:" + Logger::id).c_str(), MS_CLASS, __FUNCTION__ #define _MS_LOG_ARG ("id:" + Logger::id).c_str(), MS_CLASS, __FUNCTION__
#endif #endif
#ifdef MS_DEVEL #ifdef MS_LOG_TRACE
#define MS_TRACE() \ #define MS_TRACE() \
do \ do \
{ \ { \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D(trace) " _MS_LOG_STR, _MS_LOG_ARG); \ 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); \ Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
} \ } \
while (0) while (0)
#define MS_TRACE_STD() \
#define MS_TRACE_STD() \
do \ do \
{ \ { \
std::fprintf(stdout, "(trace) " _MS_LOG_STR _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG); \ std::fprintf(stdout, "(trace) " _MS_LOG_STR _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG); \
...@@ -92,14 +119,14 @@ bool Logger::HasDebugLevel() ...@@ -92,14 +119,14 @@ bool Logger::HasDebugLevel()
} \ } \
while (0) while (0)
#else #else
#define MS_TRACE() #define MS_TRACE()
#define MS_TRACE_STD() #define MS_TRACE_STD()
#endif #endif
#define MS_DEBUG(desc, ...) \ #define MS_DEBUG_TAG(tag, desc, ...) \
do \ do \
{ \ { \
if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel) \ 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__); \ 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); \ Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
...@@ -107,18 +134,52 @@ bool Logger::HasDebugLevel() ...@@ -107,18 +134,52 @@ bool Logger::HasDebugLevel()
} \ } \
while (0) while (0)
#define MS_DEBUG_STD(desc, ...) \ #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_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_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 \ do \
{ \ { \
if (LogLevel::LOG_DEBUG == Settings::configuration.logLevel) \ 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__); \ int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
std::fflush(stdout); \ Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
} \ } \
} \ } \
while (0) while (0)
#define MS_WARN(desc, ...) \ #define MS_WARN_DEV(desc, ...) \
do \ do \
{ \ { \
if (LogLevel::LOG_WARN <= Settings::configuration.logLevel) \ if (LogLevel::LOG_WARN <= Settings::configuration.logLevel) \
...@@ -128,6 +189,10 @@ bool Logger::HasDebugLevel() ...@@ -128,6 +189,10 @@ bool Logger::HasDebugLevel()
} \ } \
} \ } \
while (0) while (0)
#else
#define MS_DEBUG_DEV(desc, ...)
#define MS_WARN_DEV(desc, ...)
#endif
#define MS_ERROR(desc, ...) \ #define MS_ERROR(desc, ...) \
do \ do \
......
...@@ -17,7 +17,7 @@ namespace RTC { namespace RTCP ...@@ -17,7 +17,7 @@ namespace RTC { namespace RTCP
uint32_t ssrc; uint32_t ssrc;
uint32_t fraction_lost:8; uint32_t fraction_lost:8;
uint32_t total_lost:24; uint32_t total_lost:24;
uint32_t last_sec; uint32_t last_seq;
uint32_t jitter; uint32_t jitter;
uint32_t lsr; uint32_t lsr;
uint32_t dlsr; uint32_t dlsr;
...@@ -46,8 +46,8 @@ namespace RTC { namespace RTCP ...@@ -46,8 +46,8 @@ namespace RTC { namespace RTCP
void SetFractionLost(uint8_t fraction_lost); void SetFractionLost(uint8_t fraction_lost);
int32_t GetTotalLost(); int32_t GetTotalLost();
void SetTotalLost(int32_t total_lost); void SetTotalLost(int32_t total_lost);
uint32_t GetLastSec(); uint32_t GetLastSeq();
void SetLastSec(uint32_t last_sec); void SetLastSeq(uint32_t last_seq);
uint32_t GetJitter(); uint32_t GetJitter();
void SetJitter(uint32_t jitter); void SetJitter(uint32_t jitter);
uint32_t GetLastSenderReport(); uint32_t GetLastSenderReport();
...@@ -161,15 +161,15 @@ namespace RTC { namespace RTCP ...@@ -161,15 +161,15 @@ namespace RTC { namespace RTCP
} }
inline 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 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 inline
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "Channel/Request.h" #include "Channel/Request.h"
#include <map> #include <map>
#include <string> #include <string>
#include <vector>
class Settings class Settings
{ {
...@@ -26,6 +26,19 @@ public: ...@@ -26,6 +26,19 @@ public:
bool hasIPv6 { false }; 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: public:
static void SetConfiguration(int argc, char* argv[]); static void SetConfiguration(int argc, char* argv[]);
static void PrintConfiguration(); static void PrintConfiguration();
...@@ -38,9 +51,12 @@ private: ...@@ -38,9 +51,12 @@ private:
static void SetRtcListenIPv6(const std::string &ip); static void SetRtcListenIPv6(const std::string &ip);
static void SetRtcPorts(); static void SetRtcPorts();
static void SetDtlsCertificateAndPrivateKeyFiles(); static void SetDtlsCertificateAndPrivateKeyFiles();
static void SetLogTags(std::vector<std::string>& tags);
static void SetLogTags(Json::Value& json);
public: public:
static struct Configuration configuration; static struct Configuration configuration;
static struct LogTags logTags;
private: private:
static std::map<std::string, LogLevel> string2LogLevel; static std::map<std::string, LogLevel> string2LogLevel;
......
#define MS_CLASS "Channel::Notifier" #define MS_CLASS "Channel::Notifier"
// #define MS_LOG_DEV
#include "Channel/Notifier.h" #include "Channel/Notifier.h"
#include "Logger.h" #include "Logger.h"
......
#define MS_CLASS "Channel::Request" #define MS_CLASS "Channel::Request"
// #define MS_LOG_DEV
#include "Channel/Request.h" #include "Channel/Request.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
......
#define MS_CLASS "Channel::UnixStreamSocket" #define MS_CLASS "Channel::UnixStreamSocket"
// #define MS_LOG_DEV
#include "Channel/UnixStreamSocket.h" #include "Channel/UnixStreamSocket.h"
#include "Logger.h" #include "Logger.h"
...@@ -210,8 +211,6 @@ namespace Channel ...@@ -210,8 +211,6 @@ namespace Channel
switch (ns_ret) switch (ns_ret)
{ {
case NETSTRING_ERROR_TOO_SHORT: case NETSTRING_ERROR_TOO_SHORT:
// MS_DEBUG_STD("received netstring is too short, need more data");
// Check if the buffer is full. // Check if the buffer is full.
if (this->bufferDataLen == this->bufferSize) if (this->bufferDataLen == this->bufferSize)
{ {
...@@ -219,8 +218,6 @@ namespace Channel ...@@ -219,8 +218,6 @@ namespace Channel
// the buffer, so move the incomplete message to the position 0. // the buffer, so move the incomplete message to the position 0.
if (this->msgStart != 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); std::memmove(this->buffer, this->buffer + this->msgStart, read_len);
this->msgStart = 0; this->msgStart = 0;
this->bufferDataLen = read_len; this->bufferDataLen = read_len;
...@@ -306,8 +303,6 @@ namespace Channel ...@@ -306,8 +303,6 @@ namespace Channel
// the latest parsed message filled it, then empty the full buffer. // the latest parsed message filled it, then empty the full buffer.
if ((this->msgStart + read_len) == this->bufferSize) if ((this->msgStart + read_len) == this->bufferSize)
{ {
// MS_DEBUG_STD("no more space in the buffer, emptying the buffer data");
this->msgStart = 0; this->msgStart = 0;
this->bufferDataLen = 0; this->bufferDataLen = 0;
} }
...@@ -322,8 +317,6 @@ namespace Channel ...@@ -322,8 +317,6 @@ namespace Channel
// then parse again. Otherwise break here and wait for more data. // then parse again. Otherwise break here and wait for more data.
if (this->bufferDataLen > this->msgStart) if (this->bufferDataLen > this->msgStart)
{ {
// MS_DEBUG_STD("there is more data after the parsed message, continue parsing");
continue; continue;
} }
else else
......
#define MS_CLASS "DepLibSRTP" #define MS_CLASS "DepLibSRTP"
// #define MS_LOG_DEV
#include "DepLibSRTP.h" #include "DepLibSRTP.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
...@@ -44,7 +45,7 @@ void DepLibSRTP::ClassInit() ...@@ -44,7 +45,7 @@ void DepLibSRTP::ClassInit()
srtp_err_status_t err; 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(); err = srtp_init();
if (DepLibSRTP::IsError(err)) if (DepLibSRTP::IsError(err))
......
#define MS_CLASS "DepLibUV" #define MS_CLASS "DepLibUV"
// #define MS_LOG_DEV
#include "DepLibUV.h" #include "DepLibUV.h"
#include "Logger.h" #include "Logger.h"
...@@ -38,7 +39,7 @@ void DepLibUV::PrintVersion() ...@@ -38,7 +39,7 @@ void DepLibUV::PrintVersion()
{ {
MS_TRACE(); 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() void DepLibUV::RunLoop()
......
#define MS_CLASS "DepOpenSSL" #define MS_CLASS "DepOpenSSL"
// #define MS_LOG_DEV
#include "DepOpenSSL.h" #include "DepOpenSSL.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
...@@ -18,7 +19,7 @@ void DepOpenSSL::ClassInit() ...@@ -18,7 +19,7 @@ void DepOpenSSL::ClassInit()
{ {
MS_TRACE(); 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. // Initialize OpenSSL stuff.
SSL_load_error_strings(); SSL_load_error_strings();
...@@ -105,7 +106,7 @@ void DepOpenSSL::LockingFunction(int mode, int n, const char *file, int line) ...@@ -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. * - 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) if (mode & CRYPTO_LOCK)
uv_mutex_lock(&DepOpenSSL::mutexes[n]); uv_mutex_lock(&DepOpenSSL::mutexes[n]);
......
#define MS_CLASS "DepUsrSCTP" #define MS_CLASS "DepUsrSCTP"
// #define MS_LOG_DEV
#include "DepUsrSCTP.h" #include "DepUsrSCTP.h"
#include "Logger.h" #include "Logger.h"
......
#define MS_CLASS "Logger" #define MS_CLASS "Logger"
// #define MS_LOG_DEV
#include "Logger.h" #include "Logger.h"
......
#define MS_CLASS "Loop" #define MS_CLASS "Loop"
// #define MS_LOG_DEV
#include "Loop.h" #include "Loop.h"
#include "DepLibUV.h" #include "DepLibUV.h"
...@@ -31,9 +32,9 @@ Loop::Loop(Channel::UnixStreamSocket* channel) : ...@@ -31,9 +32,9 @@ Loop::Loop(Channel::UnixStreamSocket* channel) :
this->signalsHandler->AddSignal(SIGINT, "INT"); this->signalsHandler->AddSignal(SIGINT, "INT");
this->signalsHandler->AddSignal(SIGTERM, "TERM"); this->signalsHandler->AddSignal(SIGTERM, "TERM");
MS_DEBUG("starting libuv loop"); MS_DEBUG_DEV("starting libuv loop");
DepLibUV::RunLoop(); DepLibUV::RunLoop();
MS_DEBUG("libuv loop ended"); MS_DEBUG_DEV("libuv loop ended");
} }
Loop::~Loop() Loop::~Loop()
...@@ -112,17 +113,17 @@ void Loop::onSignal(SignalsHandler* signalsHandler, int signum) ...@@ -112,17 +113,17 @@ void Loop::onSignal(SignalsHandler* signalsHandler, int signum)
switch (signum) switch (signum)
{ {
case SIGINT: case SIGINT:
MS_DEBUG("signal INT received, exiting"); MS_DEBUG_DEV("signal INT received, exiting");
Close(); Close();
break; break;
case SIGTERM: case SIGTERM:
MS_DEBUG("signal TERM received, exiting"); MS_DEBUG_DEV("signal TERM received, exiting");
Close(); Close();
break; break;
default: 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 ...@@ -130,7 +131,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG("'%s' request", request->method.c_str()); MS_DEBUG_DEV("'%s' request", request->method.c_str());
switch (request->methodId) switch (request->methodId)
{ {
...@@ -199,7 +200,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request ...@@ -199,7 +200,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
this->rooms[roomId] = room; this->rooms[roomId] = room;
MS_DEBUG("Room created [roomId:%" PRIu32 "]", roomId); MS_DEBUG_DEV("Room created [roomId:%" PRIu32 "]", roomId);
Json::Value data(Json::objectValue); Json::Value data(Json::objectValue);
...@@ -271,8 +272,8 @@ void Loop::onChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* so ...@@ -271,8 +272,8 @@ void Loop::onChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* so
// If the pipe is remotely closed it means that mediasoup Node process // If the pipe is remotely closed it means that mediasoup Node process
// abruptly died (SIGKILL?) so we must die. // abruptly died (SIGKILL?) so we must die.
MS_ERROR_STD("Channel remotely closed, killing myself"); MS_ERROR_STD("Channel remotely closed, killing myself");
this->channel = nullptr;
this->channel = nullptr;
Close(); Close();
} }
......
#define MS_CLASS "RTC::IceCandidate" #define MS_CLASS "RTC::IceCandidate"
// #define MS_LOG_DEV
#include "RTC/IceCandidate.h" #include "RTC/IceCandidate.h"
......
#define MS_CLASS "RTC::IceServer" #define MS_CLASS "RTC::IceServer"
// #define MS_LOG_DEV
#include "RTC/IceServer.h" #include "RTC/IceServer.h"
#include "Logger.h" #include "Logger.h"
...@@ -14,7 +15,7 @@ namespace RTC ...@@ -14,7 +15,7 @@ namespace RTC
{ {
MS_TRACE(); 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() void IceServer::Close()
...@@ -33,7 +34,7 @@ namespace RTC ...@@ -33,7 +34,7 @@ namespace RTC
{ {
if (msg->GetClass() == RTC::StunMessage::Class::Request) 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. // Reply 400.
RTC::StunMessage* response = msg->CreateErrorResponse(400); RTC::StunMessage* response = msg->CreateErrorResponse(400);
...@@ -43,7 +44,7 @@ namespace RTC ...@@ -43,7 +44,7 @@ namespace RTC
} }
else 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; return;
...@@ -54,7 +55,7 @@ namespace RTC ...@@ -54,7 +55,7 @@ namespace RTC
{ {
if (msg->GetClass() == RTC::StunMessage::Class::Request) 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. // Reply 400.
RTC::StunMessage* response = msg->CreateErrorResponse(400); RTC::StunMessage* response = msg->CreateErrorResponse(400);
...@@ -64,7 +65,7 @@ namespace RTC ...@@ -64,7 +65,7 @@ namespace RTC
} }
else else
{ {
MS_DEBUG("ignoring STUN Binding Response without FINGERPRINT"); MS_WARN_TAG(ice, "ignoring STUN Binding Response without FINGERPRINT");
} }
return; return;
...@@ -77,7 +78,7 @@ namespace RTC ...@@ -77,7 +78,7 @@ namespace RTC
// USERNAME, MESSAGE-INTEGRITY and PRIORITY are required. // USERNAME, MESSAGE-INTEGRITY and PRIORITY are required.
if (!msg->HasMessageIntegrity() || !msg->GetPriority() || msg->GetUsername().empty()) 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. // Reply 400.
RTC::StunMessage* response = msg->CreateErrorResponse(400); RTC::StunMessage* response = msg->CreateErrorResponse(400);
...@@ -96,7 +97,7 @@ namespace RTC ...@@ -96,7 +97,7 @@ namespace RTC
case RTC::StunMessage::Authentication::Unauthorized: 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. // Reply 401.
RTC::StunMessage* response = msg->CreateErrorResponse(401); RTC::StunMessage* response = msg->CreateErrorResponse(401);
...@@ -109,7 +110,7 @@ namespace RTC ...@@ -109,7 +110,7 @@ namespace RTC
case RTC::StunMessage::Authentication::BadRequest: 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. // Reply 400.
RTC::StunMessage* response = msg->CreateErrorResponse(400); RTC::StunMessage* response = msg->CreateErrorResponse(400);
...@@ -124,7 +125,7 @@ namespace RTC ...@@ -124,7 +125,7 @@ namespace RTC
// The remote peer must be ICE controlling. // The remote peer must be ICE controlling.
if (msg->GetIceControlled()) 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). // Reply 487 (Role Conflict).
RTC::StunMessage* response = msg->CreateErrorResponse(487); RTC::StunMessage* response = msg->CreateErrorResponse(487);
...@@ -135,8 +136,7 @@ namespace RTC ...@@ -135,8 +136,7 @@ namespace RTC
return; return;
} }
// TODO: yes or no MS_DEBUG_TAG(ice, "processing STUN Binding Request [Priority:%" PRIu32 ", UseCandidate:%s]", (uint32_t)msg->GetPriority(), msg->HasUseCandidate() ? "true" : "false");
// MS_DEBUG("processing STUN Binding Request [Priority:%" PRIu32 ", UseCandidate:%s]", (uint32_t)msg->GetPriority(), msg->HasUseCandidate() ? "true" : "false");
// Create a success response. // Create a success response.
RTC::StunMessage* response = msg->CreateSuccessResponse(); RTC::StunMessage* response = msg->CreateSuccessResponse();
...@@ -160,21 +160,21 @@ namespace RTC ...@@ -160,21 +160,21 @@ namespace RTC
case RTC::StunMessage::Class::Indication: case RTC::StunMessage::Class::Indication:
{ {
MS_DEBUG("STUN Binding Indication processed"); MS_DEBUG_TAG(ice, "STUN Binding Indication processed");
break; break;
} }
case RTC::StunMessage::Class::SuccessResponse: case RTC::StunMessage::Class::SuccessResponse:
{ {
MS_DEBUG("STUN Binding Success Response processed"); MS_DEBUG_TAG(ice, "STUN Binding Success Response processed");
break; break;
} }
case RTC::StunMessage::Class::ErrorResponse: case RTC::StunMessage::Class::ErrorResponse:
{ {
MS_DEBUG("STUN Binding Error Response processed"); MS_DEBUG_TAG(ice, "STUN Binding Error Response processed");
break; break;
} }
...@@ -194,7 +194,7 @@ namespace RTC ...@@ -194,7 +194,7 @@ namespace RTC
RTC::TransportTuple* removed_tuple = nullptr; RTC::TransportTuple* removed_tuple = nullptr;
// Find the removed tuple. // Find the removed tuple.
for (; it != this->tuples.end(); ++it) for (; it != this->tuples.end(); it++)
{ {
RTC::TransportTuple* stored_tuple = std::addressof(*it); RTC::TransportTuple* stored_tuple = std::addressof(*it);
...@@ -269,7 +269,7 @@ namespace RTC ...@@ -269,7 +269,7 @@ namespace RTC
if (!has_use_candidate) 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. // Store the tuple.
auto stored_tuple = AddTuple(tuple); auto stored_tuple = AddTuple(tuple);
...@@ -285,7 +285,7 @@ namespace RTC ...@@ -285,7 +285,7 @@ namespace RTC
} }
else else
{ {
MS_DEBUG("transition from state 'new' to 'completed'"); MS_DEBUG_TAG(ice, "transition from state 'new' to 'completed'");
// Store the tuple. // Store the tuple.
auto stored_tuple = AddTuple(tuple); auto stored_tuple = AddTuple(tuple);
...@@ -313,7 +313,7 @@ namespace RTC ...@@ -313,7 +313,7 @@ namespace RTC
if (!has_use_candidate) 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. // Store the tuple.
auto stored_tuple = AddTuple(tuple); auto stored_tuple = AddTuple(tuple);
...@@ -329,7 +329,7 @@ namespace RTC ...@@ -329,7 +329,7 @@ namespace RTC
} }
else else
{ {
MS_DEBUG("transition from state 'disconnected' to 'completed'"); MS_DEBUG_TAG(ice, "transition from state 'disconnected' to 'completed'");
// Store the tuple. // Store the tuple.
auto stored_tuple = AddTuple(tuple); auto stored_tuple = AddTuple(tuple);
...@@ -363,7 +363,7 @@ namespace RTC ...@@ -363,7 +363,7 @@ namespace RTC
} }
else else
{ {
MS_DEBUG("transition from state 'connected' to 'completed'"); MS_DEBUG_TAG(ice, "transition from state 'connected' to 'completed'");
auto stored_tuple = HasTuple(tuple); auto stored_tuple = HasTuple(tuple);
...@@ -449,7 +449,7 @@ namespace RTC ...@@ -449,7 +449,7 @@ namespace RTC
return this->selectedTuple; return this->selectedTuple;
// Otherwise check other stored tuples. // 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); RTC::TransportTuple* stored_tuple = std::addressof(*it);
......
#define MS_CLASS "RTC::Peer" #define MS_CLASS "RTC::Peer"
// #define MS_LOG_DEV
#include "RTC/Peer.h" #include "RTC/Peer.h"
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
...@@ -135,11 +136,14 @@ namespace RTC ...@@ -135,11 +136,14 @@ namespace RTC
{ {
case Channel::Request::MethodId::peer_close: case Channel::Request::MethodId::peer_close:
{ {
#ifdef MS_LOG_DEV
uint32_t peerId = this->peerId; uint32_t peerId = this->peerId;
#endif
Close(); Close();
MS_DEBUG("Peer closed [peerId:%" PRIu32 "]", peerId); MS_DEBUG_DEV("Peer closed [peerId:%" PRIu32 "]", peerId);
request->Accept(); request->Accept();
break; break;
...@@ -175,8 +179,6 @@ namespace RTC ...@@ -175,8 +179,6 @@ namespace RTC
this->hasCapabilities = true; this->hasCapabilities = true;
MS_DEBUG("capabilities set");
// Notify the listener (Room) who will remove capabilities to make them // Notify the listener (Room) who will remove capabilities to make them
// a subset of the room capabilities. // a subset of the room capabilities.
this->listener->onPeerCapabilities(this, std::addressof(this->capabilities)); this->listener->onPeerCapabilities(this, std::addressof(this->capabilities));
...@@ -221,7 +223,7 @@ namespace RTC ...@@ -221,7 +223,7 @@ namespace RTC
this->transports[transportId] = transport; this->transports[transportId] = transport;
MS_DEBUG("Transport created [transportId:%" PRIu32 "]", transportId); MS_DEBUG_DEV("Transport created [transportId:%" PRIu32 "]", transportId);
auto data = transport->toJson(); auto data = transport->toJson();
...@@ -297,7 +299,7 @@ namespace RTC ...@@ -297,7 +299,7 @@ namespace RTC
this->rtpReceivers[rtpReceiverId] = rtpReceiver; this->rtpReceivers[rtpReceiverId] = rtpReceiver;
MS_DEBUG("RtpReceiver created [rtpReceiverId:%" PRIu32 "]", rtpReceiverId); MS_DEBUG_DEV("RtpReceiver created [rtpReceiverId:%" PRIu32 "]", rtpReceiverId);
// Set the Transport. // Set the Transport.
rtpReceiver->SetTransport(transport); rtpReceiver->SetTransport(transport);
...@@ -474,7 +476,7 @@ namespace RTC ...@@ -474,7 +476,7 @@ namespace RTC
{ {
MS_TRACE(); 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 rtpSender = it->second;
auto rtpParameters = rtpSender->GetParameters(); auto rtpParameters = rtpSender->GetParameters();
...@@ -482,7 +484,7 @@ namespace RTC ...@@ -482,7 +484,7 @@ namespace RTC
if (!rtpParameters) if (!rtpParameters)
continue; 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; auto& encoding = *it2;
...@@ -503,21 +505,21 @@ namespace RTC ...@@ -503,21 +505,21 @@ namespace RTC
MS_TRACE(); MS_TRACE();
// For every transport: // For every transport:
// - Create a CompoundPacket // - Create a CompoundPacket.
// - Request every Sender and Receiver of such transport their RTCP data // - Request every Sender and Receiver of such transport their RTCP data.
// - Send the CompoundPacket // - 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::RTCP::CompoundPacket packet;
RTC::Transport* transport = it->second; 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::RtpSender* rtpSender = it->second;
RTC::RTCP::SenderReport* report = rtpSender->GetRtcpSenderReport(); 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) if (report)
{ {
packet.AddSenderReport(report); packet.AddSenderReport(report);
...@@ -530,7 +532,7 @@ namespace RTC ...@@ -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::RtpReceiver* rtpReceiver = it->second;
RTC::RTCP::ReceiverReport* report = rtpReceiver->GetRtcpReceiverReport(); RTC::RTCP::ReceiverReport* report = rtpReceiver->GetRtcpReceiverReport();
...@@ -540,11 +542,9 @@ namespace RTC ...@@ -540,11 +542,9 @@ namespace RTC
} }
if (packet.GetSenderReportCount() || packet.GetReceiverReportCount()) if (packet.GetSenderReportCount() || packet.GetReceiverReportCount())
{
transport->SendRtcpPacket(&packet); transport->SendRtcpPacket(&packet);
} }
} }
}
RTC::Transport* Peer::GetTransportFromRequest(Channel::Request* request, uint32_t* transportId) RTC::Transport* Peer::GetTransportFromRequest(Channel::Request* request, uint32_t* transportId)
{ {
...@@ -662,7 +662,7 @@ namespace RTC ...@@ -662,7 +662,7 @@ namespace RTC
{ {
auto it = this->capabilities.codecs.begin(); auto it = this->capabilities.codecs.begin();
for (; it != this->capabilities.codecs.end(); ++it) for (; it != this->capabilities.codecs.end(); it++)
{ {
auto& codecCapability = *it; auto& codecCapability = *it;
...@@ -711,64 +711,61 @@ namespace RTC ...@@ -711,64 +711,61 @@ namespace RTC
case RTCP::Type::RR: case RTCP::Type::RR:
{ {
RTCP::ReceiverReportPacket* rr = (RTCP::ReceiverReportPacket*) packet; RTCP::ReceiverReportPacket* rr = static_cast<RTCP::ReceiverReportPacket*>(packet);
RTCP::ReceiverReportPacket::Iterator it = rr->Begin(); RTCP::ReceiverReportPacket::Iterator it = rr->Begin();
for (; it != rr->End(); ++it) { for (; it != rr->End(); it++)
{
auto& report = (*it); auto& report = (*it);
RTC::RtpSender* rtpSender = this->GetRtpSender(report->GetSsrc()); RTC::RtpSender* rtpSender = this->GetRtpSender(report->GetSsrc());
if (!rtpSender) { if (!rtpSender)
MS_WARN("no RtpSender found for ssrc: %u while procesing a Receiver Report", report->GetSsrc()); MS_WARN_TAG(rtcp, "no RtpSender found while procesing a Receiver Report [ssrc:%" PRIu32 "]", report->GetSsrc());
} else
else {
this->listener->onPeerRtcpReceiverReport(this, rtpSender, report); this->listener->onPeerRtcpReceiverReport(this, rtpSender, report);
} }
}
}
break; break;
}
case RTCP::Type::PSFB: 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) { if (!rtpSender)
MS_WARN("no RtpSender found for ssrc: %u while procesing a Feedback packet", feedback->GetMediaSsrc()); MS_WARN_TAG(rtcp, "no RtpSender found while procesing a Feedback packet [ssrc:%" PRIu32 "]", feedback->GetMediaSsrc());
} else
else {
this->listener->onPeerRtcpFeedback(this, rtpSender, feedback); this->listener->onPeerRtcpFeedback(this, rtpSender, feedback);
}
}
break; break;
}
case RTCP::Type::RTPFB: 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) { if (!rtpSender)
MS_WARN("no RtpSender found for ssrc: %u while procesing a Feedback packet", feedback->GetMediaSsrc()); MS_WARN_TAG(rtcp, "no RtpSender found while procesing a Feedback packet [ssrc:%" PRIu32 "]", feedback->GetMediaSsrc());
} else
else {
this->listener->onPeerRtcpFeedback(this, rtpSender, feedback); this->listener->onPeerRtcpFeedback(this, rtpSender, feedback);
}
}
break; break;
}
/* RTCP coming from a remote sender which must be forwarded to the corresponding remote receivers. */ /* RTCP coming from a remote sender which must be forwarded to the corresponding remote receivers. */
case RTCP::Type::SR: case RTCP::Type::SR:
{ {
RTCP::SenderReportPacket* sr = (RTCP::SenderReportPacket*) packet; RTCP::SenderReportPacket* sr = static_cast<RTCP::SenderReportPacket*>(packet);
RTCP::SenderReportPacket::Iterator it = sr->Begin(); RTCP::SenderReportPacket::Iterator it = sr->Begin();
// Even if Sender Report packet can only contain one report.. // Even if Sender Report packet can only contain one report..
for (; it != sr->End(); ++it) for (; it != sr->End(); it++)
{ {
auto& report = (*it); auto& report = (*it);
...@@ -776,20 +773,20 @@ namespace RTC ...@@ -776,20 +773,20 @@ namespace RTC
RTC::RtpReceiver* rtpReceiver = transport->GetRtpReceiver(report->GetSsrc()); RTC::RtpReceiver* rtpReceiver = transport->GetRtpReceiver(report->GetSsrc());
if (!rtpReceiver) if (!rtpReceiver)
MS_WARN("no RtpReceiver found for ssrc: %u while procesing a Sender Report", report->GetSsrc()); MS_WARN_TAG(rtcp, "no RtpReceiver found while procesing a Sender Report [ssrc:%" PRIu32 "]", report->GetSsrc());
else else
this->listener->onPeerRtcpSenderReport(this, rtpReceiver, report); this->listener->onPeerRtcpSenderReport(this, rtpReceiver, report);
} }
}
break; break;
}
case RTCP::Type::SDES: case RTCP::Type::SDES:
{ {
RTCP::SdesPacket* sdes = (RTCP::SdesPacket*) packet; RTCP::SdesPacket* sdes = static_cast<RTCP::SdesPacket*>(packet);
RTCP::SdesPacket::Iterator it = sdes->Begin(); RTCP::SdesPacket::Iterator it = sdes->Begin();
for (; it != sdes->End(); ++it) for (; it != sdes->End(); it++)
{ {
auto& chunk = (*it); auto& chunk = (*it);
...@@ -797,19 +794,19 @@ namespace RTC ...@@ -797,19 +794,19 @@ namespace RTC
RTC::RtpReceiver* rtpReceiver = transport->GetRtpReceiver(chunk->GetSsrc()); RTC::RtpReceiver* rtpReceiver = transport->GetRtpReceiver(chunk->GetSsrc());
if (!rtpReceiver) if (!rtpReceiver)
MS_WARN("no RtpReceiver found for ssrc: %u while procesing a SDES chunk", chunk->GetSsrc()); MS_WARN_TAG(rtcp, "no RtpReceiver found while procesing a SDES chunk [ssrc:%" PRIu32 "]", chunk->GetSsrc());
else else
this->listener->onPeerRtcpSdesChunk(this, rtpReceiver, chunk); this->listener->onPeerRtcpSdesChunk(this, rtpReceiver, chunk);
} }
}
break; break;
}
case RTCP::Type::BYE: case RTCP::Type::BYE:
break; break;
default: 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; break;
} }
......
#define MS_CLASS "RTC::RTCP::Bye" #define MS_CLASS "RTC::RTCP::Bye"
// #define MS_LOG_DEV
#include "RTC/RTCP/Bye.h" #include "RTC/RTCP/Bye.h"
#include "Utils.h" #include "Utils.h"
...@@ -25,7 +26,8 @@ namespace RTC { namespace RTCP ...@@ -25,7 +26,8 @@ namespace RTC { namespace RTCP
{ {
if (sizeof(uint32_t) > len-offset) 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; return nullptr;
} }
...@@ -78,21 +80,19 @@ namespace RTC { namespace RTCP ...@@ -78,21 +80,19 @@ namespace RTC { namespace RTCP
void ByePacket::Dump() void ByePacket::Dump()
{ {
MS_TRACE(); #ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel())
return;
MS_WARN("<Bye Packet>"); MS_TRACE();
MS_DEBUG_DEV("<ByePacket>");
for (auto ssrc : this->ssrcs) for (auto ssrc : this->ssrcs)
{ {
MS_WARN("\tssrc: %u", ssrc); MS_DEBUG_DEV(" ssrc : %" PRIu32, ssrc);
} }
if (!this->reason.empty()) 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_CLASS "RTC::RTCP::CompoundPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/CompoundPacket.h" #include "RTC/RTCP/CompoundPacket.h"
#include "Logger.h" #include "Logger.h"
...@@ -18,16 +19,13 @@ namespace RTC { namespace RTCP ...@@ -18,16 +19,13 @@ namespace RTC { namespace RTCP
MS_TRACE(); MS_TRACE();
// Calculate the total required size for the entire message. // Calculate the total required size for the entire message.
if (this->senderReportPacket.GetCount()) if (this->senderReportPacket.GetCount())
{ {
this->size = this->senderReportPacket.GetSize(); this->size = this->senderReportPacket.GetSize();
if (this->receiverReportPacket.GetCount()) if (this->receiverReportPacket.GetCount())
{
this->size += sizeof(ReceiverReport::Header) * this->receiverReportPacket.GetCount(); this->size += sizeof(ReceiverReport::Header) * this->receiverReportPacket.GetCount();
} }
}
// If no sender nor receiver reports are present send an empty Receiver Report // If no sender nor receiver reports are present send an empty Receiver Report
// packet as the head of the compound packet. // packet as the head of the compound packet.
else else
...@@ -56,7 +54,7 @@ namespace RTC { namespace RTCP ...@@ -56,7 +54,7 @@ namespace RTC { namespace RTCP
header->length += (sizeof(ReceiverReport::Header) * this->receiverReportPacket.GetCount()) / 4; header->length += (sizeof(ReceiverReport::Header) * this->receiverReportPacket.GetCount()) / 4;
ReceiverReportPacket::Iterator it = this->receiverReportPacket.Begin(); ReceiverReportPacket::Iterator it = this->receiverReportPacket.Begin();
for (; it != this->receiverReportPacket.End(); ++it) for (; it != this->receiverReportPacket.End(); it++)
{ {
ReceiverReport* report = (*it); ReceiverReport* report = (*it);
...@@ -80,10 +78,9 @@ namespace RTC { namespace RTCP ...@@ -80,10 +78,9 @@ namespace RTC { namespace RTCP
void CompoundPacket::Dump() void CompoundPacket::Dump()
{ {
MS_TRACE(); #ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel()) MS_TRACE();
return;
if (this->senderReportPacket.GetCount()) if (this->senderReportPacket.GetCount())
{ {
...@@ -93,10 +90,12 @@ namespace RTC { namespace RTCP ...@@ -93,10 +90,12 @@ namespace RTC { namespace RTCP
{ {
ReceiverReportPacket::Iterator it = this->receiverReportPacket.Begin(); ReceiverReportPacket::Iterator it = this->receiverReportPacket.Begin();
for (; it != this->receiverReportPacket.End(); ++it) for (; it != this->receiverReportPacket.End(); it++)
{
(*it)->Dump(); (*it)->Dump();
} }
} }
}
else else
{ {
this->receiverReportPacket.Dump(); this->receiverReportPacket.Dump();
...@@ -104,6 +103,8 @@ namespace RTC { namespace RTCP ...@@ -104,6 +103,8 @@ namespace RTC { namespace RTCP
if (this->sdesPacket.GetCount()) if (this->sdesPacket.GetCount())
this->sdesPacket.Dump(); this->sdesPacket.Dump();
#endif
} }
void CompoundPacket::AddSenderReport(SenderReport* report) void CompoundPacket::AddSenderReport(SenderReport* report)
......
#define MS_CLASS "RTC::RTCP::Feedback" #define MS_CLASS "RTC::RTCP::Feedback"
// #define MS_LOG_DEV
#include "RTC/RTCP/Feedback.h" #include "RTC/RTCP/Feedback.h"
// Feedback RTP. // Feedback RTP.
...@@ -41,7 +42,7 @@ namespace RTC { namespace RTCP ...@@ -41,7 +42,7 @@ namespace RTC { namespace RTCP
Packet(RTCP::Type(commonHeader->packet_type)), Packet(RTCP::Type(commonHeader->packet_type)),
messageType(typename T::MessageType(commonHeader->count)) messageType(typename T::MessageType(commonHeader->count))
{ {
// 1 => sizeof(CommonHeader) // 1 => sizeof(CommonHeader).
this->header = (Header*)(commonHeader + 1); this->header = (Header*)(commonHeader + 1);
} }
...@@ -83,12 +84,9 @@ namespace RTC { namespace RTCP ...@@ -83,12 +84,9 @@ namespace RTC { namespace RTCP
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) MS_DEBUG_DEV(" sender ssrc : %" PRIu32, ntohl(this->header->s_ssrc));
return; MS_DEBUG_DEV(" media ssrc : %" PRIu32, ntohl(this->header->m_ssrc));
MS_DEBUG_DEV(" size : %zu", this->GetSize());
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());
} }
/* Specialization for Ps class. */ /* Specialization for Ps class. */
...@@ -119,7 +117,8 @@ namespace RTC { namespace RTCP ...@@ -119,7 +117,8 @@ namespace RTC { namespace RTCP
if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) 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; return nullptr;
} }
...@@ -171,7 +170,7 @@ namespace RTC { namespace RTCP ...@@ -171,7 +170,7 @@ namespace RTC { namespace RTCP
break; break;
default: 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; return packet;
...@@ -205,7 +204,8 @@ namespace RTC { namespace RTCP ...@@ -205,7 +204,8 @@ namespace RTC { namespace RTCP
if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) 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; return nullptr;
} }
...@@ -248,7 +248,7 @@ namespace RTC { namespace RTCP ...@@ -248,7 +248,7 @@ namespace RTC { namespace RTCP
break; break;
default: 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; return packet;
......
#define MS_CLASS "RTC::RTCP::FeedbackPsPacket" #define MS_CLASS "RTC::RTCP::FeedbackPsPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPs.h" #include "RTC/RTCP/FeedbackPs.h"
#include "RTC/RTCP/FeedbackPsSli.h" #include "RTC/RTCP/FeedbackPsSli.h"
...@@ -20,7 +21,8 @@ namespace RTC { namespace RTCP ...@@ -20,7 +21,8 @@ namespace RTC { namespace RTCP
if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) 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; return nullptr;
} }
...@@ -67,20 +69,19 @@ namespace RTC { namespace RTCP ...@@ -67,20 +69,19 @@ namespace RTC { namespace RTCP
template<typename Item> template<typename Item>
void FeedbackPsItemPacket<Item>::Dump() void FeedbackPsItemPacket<Item>::Dump()
{ {
MS_TRACE(); #ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel()) MS_TRACE();
return;
MS_WARN("\t<%s>", FeedbackPsPacket::MessageType2String(Item::MessageType).c_str()); MS_DEBUG_DEV("<%s>", FeedbackPsPacket::MessageType2String(Item::MessageType).c_str());
FeedbackPsPacket::Dump(); FeedbackPsPacket::Dump();
for (auto item : this->items) for (auto item : this->items)
{ {
item->Dump(); 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. // explicit instantiation to have all FeedbackRtpPacket definitions in this file.
......
#define MS_CLASS "RTC::RTCP::FeedbackPsAfbPacket" #define MS_CLASS "RTC::RTCP::FeedbackPsAfbPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsAfb.h" #include "RTC/RTCP/FeedbackPsAfb.h"
#include "Logger.h" #include "Logger.h"
...@@ -14,7 +15,8 @@ namespace RTC { namespace RTCP ...@@ -14,7 +15,8 @@ namespace RTC { namespace RTCP
if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) 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; return nullptr;
} }
...@@ -38,13 +40,14 @@ namespace RTC { namespace RTCP ...@@ -38,13 +40,14 @@ namespace RTC { namespace RTCP
void FeedbackPsAfbPacket::Dump() void FeedbackPsAfbPacket::Dump()
{ {
MS_TRACE(); #ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel()) MS_TRACE();
return;
MS_WARN("\t<FeedbackPsAfbPacket>"); MS_DEBUG_DEV("<FeedbackPsAfbPacket>");
FeedbackPsPacket::Dump(); FeedbackPsPacket::Dump();
MS_WARN("\t</FeedbackPsAfbPacket>"); MS_DEBUG_DEV("</FeedbackPsAfbPacket>");
#endif
} }
}} }}
#define MS_CLASS "RTC::RTCP::FeedbackPsFirPacket" #define MS_CLASS "RTC::RTCP::FeedbackPsFirPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsFir.h" #include "RTC/RTCP/FeedbackPsFir.h"
#include "Logger.h" #include "Logger.h"
...@@ -16,7 +17,8 @@ namespace RTC { namespace RTCP ...@@ -16,7 +17,8 @@ namespace RTC { namespace RTCP
// data size must be >= header. // data size must be >= header.
if (sizeof(Header) > len) 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; return nullptr;
} }
...@@ -54,12 +56,9 @@ namespace RTC { namespace RTCP ...@@ -54,12 +56,9 @@ namespace RTC { namespace RTCP
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) MS_DEBUG_DEV("<FirItem>");
return; MS_DEBUG_DEV(" ssrc : %" PRIu32, ntohl(this->header->ssrc));
MS_DEBUG_DEV(" sequence number : %" PRIu8, this->header->sequence_number);
MS_WARN("\t\t<Fir Item>"); MS_DEBUG_DEV("\t\t</FirItem>");
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>");
} }
}} }}
#define MS_CLASS "RTC::RTCP::FeedbackPsPsLeiPacket" #define MS_CLASS "RTC::RTCP::FeedbackPsPsLeiPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsLei.h" #include "RTC/RTCP/FeedbackPsLei.h"
#include "Logger.h" #include "Logger.h"
...@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP ...@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value. // data size must be >= header + length value.
if (sizeof(Header) > len) 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; return nullptr;
} }
...@@ -46,11 +48,8 @@ namespace RTC { namespace RTCP ...@@ -46,11 +48,8 @@ namespace RTC { namespace RTCP
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) MS_DEBUG_DEV("<PsLeiItem>");
return; MS_DEBUG_DEV(" ssrc : %" PRIu32, ntohl(this->header->ssrc));
MS_DEBUG_DEV("</PsLeiItem>");
MS_WARN("\t\t<PsLei Item>");
MS_WARN("\t\t\tssrc: %u", ntohl(this->header->ssrc));
MS_WARN("\t\t</PsLei Item>");
} }
}} }}
#define MS_CLASS "RTC::RTCP::FeedbackPsPliPacket" #define MS_CLASS "RTC::RTCP::FeedbackPsPliPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsPli.h" #include "RTC/RTCP/FeedbackPsPli.h"
#include "Logger.h" #include "Logger.h"
...@@ -13,7 +14,8 @@ namespace RTC { namespace RTCP ...@@ -13,7 +14,8 @@ namespace RTC { namespace RTCP
if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) 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; return nullptr;
} }
...@@ -25,13 +27,14 @@ namespace RTC { namespace RTCP ...@@ -25,13 +27,14 @@ namespace RTC { namespace RTCP
void FeedbackPsPliPacket::Dump() void FeedbackPsPliPacket::Dump()
{ {
MS_TRACE(); #ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel()) MS_TRACE();
return;
MS_WARN("\t<FeedbackPsPliPacket>"); MS_DEBUG_DEV("<FeedbackPsPliPacket>");
FeedbackPsPacket::Dump(); FeedbackPsPacket::Dump();
MS_WARN("\t</FeedbackPsPliPacket>"); MS_DEBUG_DEV("</FeedbackPsPliPacket>");
#endif
} }
}} }}
#define MS_CLASS "RTC::RTCP::FeedbackPsRpsiPacket" #define MS_CLASS "RTC::RTCP::FeedbackPsRpsiPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsRpsi.h" #include "RTC/RTCP/FeedbackPsRpsi.h"
#include "Logger.h" #include "Logger.h"
...@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP ...@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP
// data size must be >= header. // data size must be >= header.
if (sizeof(Header) > len) 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; return nullptr;
} }
...@@ -37,15 +39,19 @@ namespace RTC { namespace RTCP ...@@ -37,15 +39,19 @@ namespace RTC { namespace RTCP
this->header = header; this->header = header;
// Calculate bit_string length. // Calculate bit_string length.
if (this->header->padding_bits % 8 != 0) { if (this->header->padding_bits % 8 != 0)
MS_WARN("invalid Rpsi packet with fractional padding bytes value"); {
MS_WARN_TAG(rtcp, "invalid Rpsi packet with fractional padding bytes value");
isCorrect = false; isCorrect = false;
} }
size_t paddingBytes = this->header->padding_bits / 8; size_t paddingBytes = this->header->padding_bits / 8;
if (paddingBytes > RpsiItem::MaxBitStringSize) { if (paddingBytes > RpsiItem::MaxBitStringSize)
MS_WARN("invalid Rpsi packet with too many padding bytes"); {
MS_WARN_TAG(rtcp, "invalid Rpsi packet with too many padding bytes");
isCorrect = false; isCorrect = false;
} }
...@@ -89,13 +95,10 @@ namespace RTC { namespace RTCP ...@@ -89,13 +95,10 @@ namespace RTC { namespace RTCP
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) MS_DEBUG_DEV("<RpsiItem>");
return; MS_DEBUG_DEV(" padding bits : %" PRIu8, this->header->padding_bits);
MS_DEBUG_DEV(" payload type : %" PRIu8, this->header->payload_type);
MS_WARN("\t\t<Rpsi Item>"); MS_DEBUG_DEV(" length : %zu", this->length);
MS_WARN("\t\t\tpadding bits: %u", this->header->padding_bits); MS_DEBUG_DEV("</RpsiItem>");
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>");
} }
}} }}
#define MS_CLASS "RTC::RTCP::FeedbackPsSliPacket" #define MS_CLASS "RTC::RTCP::FeedbackPsSliPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsSli.h" #include "RTC/RTCP/FeedbackPsSli.h"
#include "Logger.h" #include "Logger.h"
...@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP ...@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value. // data size must be >= header + length value.
if (sizeof(Header) > len) 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; return nullptr;
} }
...@@ -54,14 +56,11 @@ namespace RTC { namespace RTCP ...@@ -54,14 +56,11 @@ namespace RTC { namespace RTCP
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) MS_DEBUG_DEV("<SliItem>");
return; MS_DEBUG_DEV(" first : %" PRIu16, this->first);
MS_DEBUG_DEV(" number : %" PRIu16, this->number);
MS_WARN("\t\t<Sli Item>"); MS_DEBUG_DEV(" picture id : %" PRIu8, this->pictureId);
MS_WARN("\t\t\tfirst: %u", this->first); MS_DEBUG_DEV("</SliItem>");
MS_WARN("\t\t\tnumber: %u", this->number);
MS_WARN("\t\t\tpictureId: %u", this->pictureId);
MS_WARN("\t\t</Sli Item>");
} }
}} }}
#define MS_CLASS "RTC::RTCP::FeedbackPsTstPacket" #define MS_CLASS "RTC::RTCP::FeedbackPsTstPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsTst.h" #include "RTC/RTCP/FeedbackPsTst.h"
#include "Logger.h" #include "Logger.h"
...@@ -16,7 +17,8 @@ namespace RTC { namespace RTCP ...@@ -16,7 +17,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value. // data size must be >= header + length value.
if (sizeof(Header) > len) 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; return nullptr;
} }
...@@ -56,14 +58,11 @@ namespace RTC { namespace RTCP ...@@ -56,14 +58,11 @@ namespace RTC { namespace RTCP
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) MS_DEBUG_DEV("<TstItem>");
return; MS_DEBUG_DEV(" ssrc : %" PRIu32, ntohl(this->header->ssrc));
MS_DEBUG_DEV(" sequence number : %" PRIu32, this->header->sequence_number);
MS_WARN("\t\t<Tst Item>"); MS_DEBUG_DEV(" index : %" PRIu32, this->header->index);
MS_WARN("\t\t\tssrc: %u", ntohl(this->header->ssrc)); MS_DEBUG_DEV("</TstItem>");
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>");
} }
/* Specialization for Tstr class. */ /* Specialization for Tstr class. */
......
#define MS_CLASS "RTC::RTCP::FeedbackPsVbcmPacket" #define MS_CLASS "RTC::RTCP::FeedbackPsVbcmPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackPsVbcm.h" #include "RTC/RTCP/FeedbackPsVbcm.h"
#include "Logger.h" #include "Logger.h"
...@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP ...@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value. // data size must be >= header + length value.
if (sizeof(Header) > len) 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; return nullptr;
} }
...@@ -64,14 +66,11 @@ namespace RTC { namespace RTCP ...@@ -64,14 +66,11 @@ namespace RTC { namespace RTCP
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) MS_DEBUG_DEV("<VbcmItem>");
return; MS_DEBUG_DEV(" ssrc : %" PRIu32, ntohl(this->header->ssrc));
MS_DEBUG_DEV(" sequence number : %" PRIu8, this->header->sequence_number);
MS_WARN("\t\t<Vbcm Item>"); MS_DEBUG_DEV(" payload type : %" PRIu8, this->header->payload_type);
MS_WARN("\t\t\tssrc: %u", ntohl(this->header->ssrc)); MS_DEBUG_DEV(" length : %" PRIu16, ntohs(this->header->length));
MS_WARN("\t\t\tsequence_number: %u", this->header->sequence_number); MS_DEBUG_DEV("</Vbcm Item>");
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>");
} }
}} }}
#define MS_CLASS "RTC::RTCP::FeedbackRtpPacket" #define MS_CLASS "RTC::RTCP::FeedbackRtpPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackRtp.h" #include "RTC/RTCP/FeedbackRtp.h"
#include "RTC/RTCP/FeedbackRtpNack.h" #include "RTC/RTCP/FeedbackRtpNack.h"
...@@ -18,7 +19,8 @@ namespace RTC { namespace RTCP ...@@ -18,7 +19,8 @@ namespace RTC { namespace RTCP
if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) 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; return nullptr;
} }
...@@ -65,20 +67,19 @@ namespace RTC { namespace RTCP ...@@ -65,20 +67,19 @@ namespace RTC { namespace RTCP
template<typename Item> template<typename Item>
void FeedbackRtpItemPacket<Item>::Dump() void FeedbackRtpItemPacket<Item>::Dump()
{ {
MS_TRACE(); #ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel()) MS_TRACE();
return;
MS_WARN("\t<%s>", FeedbackRtpPacket::MessageType2String(Item::MessageType).c_str()); MS_DEBUG_DEV("<%s>", FeedbackRtpPacket::MessageType2String(Item::MessageType).c_str());
FeedbackRtpPacket::Dump(); FeedbackRtpPacket::Dump();
for (auto item : this->items) for (auto item : this->items)
{ {
item->Dump(); 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. // Explicit instantiation to have all FeedbackRtpPacket definitions in this file.
......
#define MS_CLASS "RTC::RTCP::FeedbackRtpEcnPacket" #define MS_CLASS "RTC::RTCP::FeedbackRtpEcnPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackRtpEcn.h" #include "RTC/RTCP/FeedbackRtpEcn.h"
#include "Logger.h" #include "Logger.h"
...@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP ...@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value. // data size must be >= header + length value.
if (sizeof(Header) > len) 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; return nullptr;
} }
...@@ -38,17 +40,14 @@ namespace RTC { namespace RTCP ...@@ -38,17 +40,14 @@ namespace RTC { namespace RTCP
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) MS_DEBUG_DEV("<EcnItem>");
return; MS_DEBUG_DEV(" sequence number : %" PRIu32, ntohl(this->header->sequence_number));
MS_DEBUG_DEV(" ect0 counter : %" PRIu32, ntohl(this->header->ect0_counter));
MS_WARN("\t\t<Ecn Item>"); MS_DEBUG_DEV(" ect1 counter : %" PRIu32, ntohl(this->header->ect1_counter));
MS_WARN("\t\tsequence_number: %d", ntohl(this->header->sequence_number)); MS_DEBUG_DEV(" ecn ce counter : %" PRIu16, ntohs(this->header->ecn_ce_counter));
MS_WARN("\t\tect0_counter: %d", ntohl(this->header->ect0_counter)); MS_DEBUG_DEV(" not ect counter : %" PRIu16, ntohs(this->header->not_ect_counter));
MS_WARN("\t\tect1_counter: %d", ntohl(this->header->ect1_counter)); MS_DEBUG_DEV(" lost packets : %" PRIu16, ntohs(this->header->lost_packets));
MS_WARN("\t\tecn_ce_counter: %d", ntohs(this->header->ecn_ce_counter)); MS_DEBUG_DEV(" duplicated packets : %" PRIu16, ntohs(this->header->duplicated_packets));
MS_WARN("\t\tnot_ect_counter: %d", ntohs(this->header->not_ect_counter)); MS_DEBUG_DEV("</EcnItem>");
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>");
} }
}} }}
#define MS_CLASS "RTC::RTCP::FeedbackRtpNackPacket" #define MS_CLASS "RTC::RTCP::FeedbackRtpNackPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackRtpNack.h" #include "RTC/RTCP/FeedbackRtpNack.h"
#include "Logger.h" #include "Logger.h"
...@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP ...@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value. // data size must be >= header + length value.
if (sizeof(Header) > len) 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; return nullptr;
} }
...@@ -48,12 +50,9 @@ namespace RTC { namespace RTCP ...@@ -48,12 +50,9 @@ namespace RTC { namespace RTCP
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) MS_DEBUG_DEV("<NackItem>");
return; MS_DEBUG_DEV(" pid : %" PRIu16, ntohl(this->header->packet_id));
MS_DEBUG_DEV(" bpl : %" PRIu16, ntohl(this->header->lost_packet_bitmask));
MS_WARN("\t\t<Nack Item>"); MS_DEBUG_DEV("</NackItem>");
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>");
} }
}} }}
#define MS_CLASS "RTC::RTCP::FeedbackRtpSrReqPacket" #define MS_CLASS "RTC::RTCP::FeedbackRtpSrReqPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackRtpSrReq.h" #include "RTC/RTCP/FeedbackRtpSrReq.h"
#include "Logger.h" #include "Logger.h"
...@@ -13,7 +14,8 @@ namespace RTC { namespace RTCP ...@@ -13,7 +14,8 @@ namespace RTC { namespace RTCP
if (sizeof(CommonHeader) + sizeof(FeedbackPacket::Header) > len) 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; return nullptr;
} }
...@@ -24,13 +26,14 @@ namespace RTC { namespace RTCP ...@@ -24,13 +26,14 @@ namespace RTC { namespace RTCP
void FeedbackRtpSrReqPacket::Dump() void FeedbackRtpSrReqPacket::Dump()
{ {
MS_TRACE(); #ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel()) MS_TRACE();
return;
MS_WARN("\t<FeedbackRtpSrReqPacket>"); MS_DEBUG_DEV("<FeedbackRtpSrReqPacket>");
FeedbackRtpPacket::Dump(); FeedbackRtpPacket::Dump();
MS_WARN("\t</FeedbackRtpSrReqPacket>"); MS_DEBUG_DEV("</FeedbackRtpSrReqPacket>");
#endif
} }
}} }}
#define MS_CLASS "RTC::RTCP::FeedbackRtpTlleiPacket" #define MS_CLASS "RTC::RTCP::FeedbackRtpTlleiPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackRtpTllei.h" #include "RTC/RTCP/FeedbackRtpTllei.h"
#include "Logger.h" #include "Logger.h"
...@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP ...@@ -15,7 +16,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value. // data size must be >= header + length value.
if (sizeof(Header) > len) 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; return nullptr;
} }
...@@ -48,12 +50,9 @@ namespace RTC { namespace RTCP ...@@ -48,12 +50,9 @@ namespace RTC { namespace RTCP
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) MS_DEBUG_DEV("<TlleiItem>");
return; MS_DEBUG_DEV(" pid: %" PRIu16, ntohl(this->header->packet_id));
MS_DEBUG_DEV(" bpl: %" PRIu16, ntohl(this->header->lost_packet_bitmask));
MS_WARN("\t\t<Tllei Item>"); MS_DEBUG_DEV("</TlleiItem>");
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>");
} }
}} }}
#define MS_CLASS "RTC::RTCP::FeedbackRtpTmmbPacket" #define MS_CLASS "RTC::RTCP::FeedbackRtpTmmbPacket"
// #define MS_LOG_DEV
#include "RTC/RTCP/FeedbackRtpTmmb.h" #include "RTC/RTCP/FeedbackRtpTmmb.h"
#include "Logger.h" #include "Logger.h"
...@@ -18,7 +19,8 @@ namespace RTC { namespace RTCP ...@@ -18,7 +19,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value. // data size must be >= header + length value.
if (sizeof(Header) > len) 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; return nullptr;
} }
...@@ -45,7 +47,8 @@ namespace RTC { namespace RTCP ...@@ -45,7 +47,8 @@ namespace RTC { namespace RTCP
if ((this->bitrate >> exponent) != mantissa) 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; this->isCorrect = false;
} }
} }
...@@ -78,14 +81,11 @@ namespace RTC { namespace RTCP ...@@ -78,14 +81,11 @@ namespace RTC { namespace RTCP
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) MS_DEBUG_DEV("<TmmbItem>");
return; MS_DEBUG_DEV(" ssrc : %" PRIu32, ntohl(this->header->ssrc));
MS_DEBUG_DEV(" bitrate : %" PRIu64, this->bitrate);
MS_WARN("\t\t<Tmmb Item>"); MS_DEBUG_DEV(" overhead : %" PRIu16, this->overhead);
MS_WARN("\t\t\tssrc: %u", ntohl(this->header->ssrc)); MS_DEBUG_DEV("</TmmbItem>");
MS_WARN("\t\t\tbitrate: %" PRIu64, this->bitrate);
MS_WARN("\t\t\toverhead: %u", this->overhead);
MS_WARN("\t\t</Tmmb Item>");
} }
/* Specialization for Tmmbr class. */ /* Specialization for Tmmbr class. */
......
#define MS_CLASS "RTC::RTCP::Packet" #define MS_CLASS "RTC::RTCP::Packet"
// #define MS_LOG_DEV
#include "RTC/RTCP/Packet.h" #include "RTC/RTCP/Packet.h"
#include "RTC/RTCP/ReceiverReport.h" #include "RTC/RTCP/ReceiverReport.h"
...@@ -36,7 +37,7 @@ namespace RTC { namespace RTCP ...@@ -36,7 +37,7 @@ namespace RTC { namespace RTCP
{ {
if (!Packet::IsRtcp(data, len)) 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; return first;
} }
...@@ -46,7 +47,7 @@ namespace RTC { namespace RTCP ...@@ -46,7 +47,7 @@ namespace RTC { namespace RTCP
if (len < packet_len) 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; return first;
} }
...@@ -110,7 +111,8 @@ namespace RTC { namespace RTCP ...@@ -110,7 +111,8 @@ namespace RTC { namespace RTCP
default: 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; current = nullptr;
} }
} }
...@@ -120,21 +122,18 @@ namespace RTC { namespace RTCP ...@@ -120,21 +122,18 @@ namespace RTC { namespace RTCP
std::string packetType = Type2String(Type(header->packet_type)); std::string packetType = Type2String(Type(header->packet_type));
if (Type(header->packet_type) == Type::PSFB) if (Type(header->packet_type) == Type::PSFB)
{
packetType += " " + FeedbackPsPacket::MessageType2String(FeedbackPs::MessageType(header->count)); packetType += " " + FeedbackPsPacket::MessageType2String(FeedbackPs::MessageType(header->count));
}
else if (Type(header->packet_type) == Type::RTPFB) else if (Type(header->packet_type) == Type::RTPFB)
{
packetType += " " + FeedbackRtpPacket::MessageType2String(FeedbackRtp::MessageType(header->count)); 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; return first;
} }
// TODO: REMOVE #ifdef MS_LOG_DEV
current->Dump(); // current->Dump();
#endif
data += packet_len; data += packet_len;
len -= packet_len; len -= packet_len;
......
#define MS_CLASS "RTC::RTCP::ReceiverReport" #define MS_CLASS "RTC::RTCP::ReceiverReport"
// #define MS_LOG_DEV
#include "RTC/RTCP/ReceiverReport.h" #include "RTC/RTCP/ReceiverReport.h"
#include "Utils.h" #include "Utils.h"
...@@ -19,7 +20,8 @@ namespace RTC { namespace RTCP ...@@ -19,7 +20,8 @@ namespace RTC { namespace RTCP
// Packet size must be >= header size. // Packet size must be >= header size.
if (sizeof(Header) > len) 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; return nullptr;
} }
...@@ -32,18 +34,15 @@ namespace RTC { namespace RTCP ...@@ -32,18 +34,15 @@ namespace RTC { namespace RTCP
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) MS_DEBUG_DEV("<ReceiverReport>");
return; MS_DEBUG_DEV(" ssrc : %" PRIu32, ntohl(this->header->ssrc));
MS_DEBUG_DEV(" fraction lost : %" PRIu32, this->header->fraction_lost);
MS_WARN("\t<ReceiverReport>"); MS_DEBUG_DEV(" total lost : %" PRIu32, this->GetTotalLost());
MS_WARN("\t\tssrc: %u", ntohl(this->header->ssrc)); MS_DEBUG_DEV(" last seq : %" PRIu32, ntohl(this->header->last_seq));
MS_WARN("\t\tfraction_lost: %u", this->header->fraction_lost); MS_DEBUG_DEV(" jitter : %" PRIu32, ntohl(this->header->jitter));
MS_WARN("\t\ttotal_lost: %d", this->GetTotalLost()); MS_DEBUG_DEV(" lsr : %" PRIu32, ntohl(this->header->lsr));
MS_WARN("\t\tlast_sec: %u", ntohl(this->header->last_sec)); MS_DEBUG_DEV(" dlsr : %" PRIu32, ntohl(this->header->dlsr));
MS_WARN("\t\tjitter: %u", ntohl(this->header->jitter)); MS_DEBUG_DEV("</ReceiverReport>");
MS_WARN("\t\tlsr: %u", ntohl(this->header->lsr));
MS_WARN("\t\tdlsr: %u", ntohl(this->header->dlsr));
MS_WARN("\t</ReceiverReport>");
} }
void ReceiverReport::Serialize() void ReceiverReport::Serialize()
...@@ -137,17 +136,16 @@ namespace RTC { namespace RTCP ...@@ -137,17 +136,16 @@ namespace RTC { namespace RTCP
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) #ifdef MS_LOG_DEV
return;
MS_WARN("<ReceiverReportPacket>");
MS_WARN("\tssrc: %u", (uint32_t)ntohl(this->ssrc));
MS_DEBUG_DEV("<ReceiverReportPacket>");
MS_DEBUG_DEV(" ssrc: %" PRIu32, (uint32_t)ntohl(this->ssrc));
for (auto report : this->reports) for (auto report : this->reports)
{ {
report->Dump(); report->Dump();
} }
MS_DEBUG_DEV("</ReceiverReportPacket>");
MS_WARN("</ReceiverReportPacket>"); #endif
} }
}} }}
#define MS_CLASS "RTC::RTCP::Sdes" #define MS_CLASS "RTC::RTCP::Sdes"
// #define MS_LOG_DEV
#include "RTC/RTCP/Sdes.h" #include "RTC/RTCP/Sdes.h"
#include "Utils.h" #include "Utils.h"
...@@ -34,7 +35,8 @@ namespace RTC { namespace RTCP ...@@ -34,7 +35,8 @@ namespace RTC { namespace RTCP
// data size must be >= header + length value. // data size must be >= header + length value.
if (sizeof(uint8_t)*2 + header->length > len) 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; return nullptr;
} }
...@@ -74,14 +76,11 @@ namespace RTC { namespace RTCP ...@@ -74,14 +76,11 @@ namespace RTC { namespace RTCP
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) MS_DEBUG_DEV("<SdesItem>");
return; MS_DEBUG_DEV(" type : %s", Type2String(this->GetType()).c_str());
MS_DEBUG_DEV(" length : %" PRIu8, this->header->length);
MS_WARN("\t\t<Sdes Item>"); MS_DEBUG_DEV(" value : %.*s", this->header->length, this->header->value);
MS_WARN("\t\t\ttype: %s", Type2String(this->GetType()).c_str()); MS_DEBUG_DEV("</SdesItem>");
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>");
} }
void SdesItem::Serialize() void SdesItem::Serialize()
...@@ -117,7 +116,8 @@ namespace RTC { namespace RTCP ...@@ -117,7 +116,8 @@ namespace RTC { namespace RTCP
// data size must be > SSRC field. // data size must be > SSRC field.
if (sizeof(uint32_t) /* ssrc */ > len) 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; return nullptr;
} }
...@@ -182,20 +182,19 @@ namespace RTC { namespace RTCP ...@@ -182,20 +182,19 @@ namespace RTC { namespace RTCP
void SdesChunk::Dump() void SdesChunk::Dump()
{ {
MS_TRACE(); #ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel())
return;
MS_WARN("\t<Sdes Chunk>"); MS_TRACE();
MS_WARN("\t\tssrc: %u", (uint32_t)ntohl(this->ssrc));
MS_DEBUG_DEV("<SdesChunk>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, (uint32_t)ntohl(this->ssrc));
for (auto item : this->items) for (auto item : this->items)
{ {
item->Dump(); item->Dump();
} }
MS_DEBUG_DEV("</SdesChunk>");
MS_WARN("\t</Sdes Chunk>"); #endif
} }
/* Class methods. */ /* Class methods. */
...@@ -245,18 +244,17 @@ namespace RTC { namespace RTCP ...@@ -245,18 +244,17 @@ namespace RTC { namespace RTCP
void SdesPacket::Dump() void SdesPacket::Dump()
{ {
MS_TRACE(); #ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel()) MS_TRACE();
return;
MS_WARN("<Sdes Packet>");
MS_DEBUG_DEV("<SdesPacket>");
for (auto chunk : this->chunks) for (auto chunk : this->chunks)
{ {
chunk->Dump(); chunk->Dump();
} }
MS_DEBUG_DEV("</SdesPacket>");
MS_WARN("</Sdes Packet>"); #endif
} }
}} }}
#define MS_CLASS "RTC::RTCP::SenderReport" #define MS_CLASS "RTC::RTCP::SenderReport"
// #define MS_LOG_DEV
#include "RTC/RTCP/SenderReport.h" #include "RTC/RTCP/SenderReport.h"
#include "Logger.h" #include "Logger.h"
...@@ -18,7 +19,8 @@ namespace RTC { namespace RTCP ...@@ -18,7 +19,8 @@ namespace RTC { namespace RTCP
// Packet size must be >= header size. // Packet size must be >= header size.
if (sizeof(Header) > len) 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; return nullptr;
} }
...@@ -31,17 +33,14 @@ namespace RTC { namespace RTCP ...@@ -31,17 +33,14 @@ namespace RTC { namespace RTCP
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) MS_DEBUG_DEV("<SenderReport>");
return; MS_DEBUG_DEV(" ssrc : %" PRIu32, ntohl(this->header->ssrc));
MS_DEBUG_DEV(" ntp sec : %" PRIu32, ntohl(this->header->ntp_sec));
MS_WARN("\t<SenderReport>"); MS_DEBUG_DEV(" ntp frac : %" PRIu32, ntohl(this->header->ntp_frac));
MS_WARN("\t\tssrc: %u", ntohl(this->header->ssrc)); MS_DEBUG_DEV(" rtp ts : %" PRIu32, ntohl(this->header->rtp_ts));
MS_WARN("\t\tntp_sec: %u", ntohl(this->header->ntp_sec)); MS_DEBUG_DEV(" packet count : %" PRIu32, ntohl(this->header->packet_count));
MS_WARN("\t\tntp_frac: %u", ntohl(this->header->ntp_frac)); MS_DEBUG_DEV(" octet count : %" PRIu32, ntohl(this->header->octet_count));
MS_WARN("\t\trtp_ts: %u", ntohl(this->header->rtp_ts)); MS_DEBUG_DEV("</SenderReport>");
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>");
} }
void SenderReport::Serialize() void SenderReport::Serialize()
...@@ -82,13 +81,9 @@ namespace RTC { namespace RTCP ...@@ -82,13 +81,9 @@ namespace RTC { namespace RTCP
SenderReport* report = SenderReport::Parse(data+offset, len-offset); SenderReport* report = SenderReport::Parse(data+offset, len-offset);
if (report) if (report)
{
packet->AddReport(report); packet->AddReport(report);
}
else else
{
return packet.release(); return packet.release();
}
return packet.release(); return packet.release();
} }
...@@ -114,18 +109,17 @@ namespace RTC { namespace RTCP ...@@ -114,18 +109,17 @@ namespace RTC { namespace RTCP
void SenderReportPacket::Dump() void SenderReportPacket::Dump()
{ {
MS_TRACE(); #ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel()) MS_TRACE();
return;
MS_WARN("<SenderReportPacket>");
MS_DEBUG_DEV("<SenderReportPacket>");
for (auto report : this->reports) for (auto report : this->reports)
{ {
report->Dump(); report->Dump();
} }
MS_DEBUG_DEV("</SenderReportPacket>");
MS_WARN("</SenderReportPacket>"); #endif
} }
}} }}
#define MS_CLASS "RTC::Room" #define MS_CLASS "RTC::Room"
// #define MS_LOG_DEV
#include "RTC/Room.h" #include "RTC/Room.h"
#include "RTC/RTCP/FeedbackRtpNack.h" #include "RTC/RTCP/FeedbackRtpNack.h"
...@@ -194,11 +195,14 @@ namespace RTC ...@@ -194,11 +195,14 @@ namespace RTC
{ {
case Channel::Request::MethodId::room_close: case Channel::Request::MethodId::room_close:
{ {
#ifdef MS_LOG_DEV
uint32_t roomId = this->roomId; uint32_t roomId = this->roomId;
#endif
Close(); Close();
MS_DEBUG("Room closed [roomId:%" PRIu32 "]", roomId); MS_DEBUG_DEV("Room closed [roomId:%" PRIu32 "]", roomId);
request->Accept(); request->Accept();
break; break;
...@@ -258,7 +262,7 @@ namespace RTC ...@@ -258,7 +262,7 @@ namespace RTC
// Store the new Peer. // Store the new Peer.
this->peers[peerId] = 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(); request->Accept();
...@@ -441,7 +445,7 @@ namespace RTC ...@@ -441,7 +445,7 @@ namespace RTC
auto& peerCodecCapability = *it; auto& peerCodecCapability = *it;
auto it2 = this->capabilities.codecs.begin(); auto it2 = this->capabilities.codecs.begin();
for (; it2 != this->capabilities.codecs.end(); ++it2) for (; it2 != this->capabilities.codecs.end(); it2++)
{ {
auto& roomCodecCapability = *it2; auto& roomCodecCapability = *it2;
...@@ -450,14 +454,10 @@ namespace RTC ...@@ -450,14 +454,10 @@ namespace RTC
} }
if (it2 != this->capabilities.codecs.end()) if (it2 != this->capabilities.codecs.end())
{
it++; it++;
}
else else
{
it = capabilities->codecs.erase(it); it = capabilities->codecs.erase(it);
} }
}
// TODO: Remove unsupported header extensions. // TODO: Remove unsupported header extensions.
...@@ -692,8 +692,8 @@ namespace RTC ...@@ -692,8 +692,8 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// Tell all the peers but the one in the argument to generate and send their RTCP // 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) for (auto it = this->peers.begin(); it != this->peers.end(); it++)
{ {
if (it->second != peer) { if (it->second != peer) {
it->second->SendRtcp(); it->second->SendRtcp();
......
#define MS_CLASS "RTC::Media" #define MS_CLASS "RTC::Media"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "Utils.h" #include "Utils.h"
......
#define MS_CLASS "RTC::Parameters" #define MS_CLASS "RTC::Parameters"
// #define MS_LOG_DEV
#include "RTC/Parameters.h" #include "RTC/Parameters.h"
#include "Logger.h" #include "Logger.h"
...@@ -71,7 +72,7 @@ namespace RTC ...@@ -71,7 +72,7 @@ namespace RTC
MS_ASSERT(data.isObject(), "data is not a JSON object"); 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(); std::string key = it.key().asString();
Json::Value value = (*it); Json::Value value = (*it);
......
#define MS_CLASS "RTC::RtcpFeedback" #define MS_CLASS "RTC::RtcpFeedback"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtcpParameters" #define MS_CLASS "RTC::RtcpParameters"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpCapabilities" #define MS_CLASS "RTC::RtpCapabilities"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpCodecMime" #define MS_CLASS "RTC::RtpCodecMime"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "Utils.h" #include "Utils.h"
......
#define MS_CLASS "RTC::RtpCodecParameters" #define MS_CLASS "RTC::RtpCodecParameters"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpEncodingParameters" #define MS_CLASS "RTC::RtpEncodingParameters"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpFecParameters" #define MS_CLASS "RTC::RtpFecParameters"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpHeaderExtension" #define MS_CLASS "RTC::RtpHeaderExtension"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpHeaderExtensionParameters" #define MS_CLASS "RTC::RtpHeaderExtensionParameters"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpParameters" #define MS_CLASS "RTC::RtpParameters"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
...@@ -186,7 +187,7 @@ namespace RTC ...@@ -186,7 +187,7 @@ namespace RTC
int32_t apt = codec.parameters.GetInteger(k_apt); int32_t apt = codec.parameters.GetInteger(k_apt);
auto it = this->codecs.begin(); auto it = this->codecs.begin();
for (; it != this->codecs.end(); ++it) for (; it != this->codecs.end(); it++)
{ {
auto codec = *it; auto codec = *it;
...@@ -222,7 +223,7 @@ namespace RTC ...@@ -222,7 +223,7 @@ namespace RTC
{ {
auto it = this->codecs.begin(); auto it = this->codecs.begin();
for (; it != this->codecs.end(); ++it) for (; it != this->codecs.end(); it++)
{ {
auto& codec = *it; auto& codec = *it;
...@@ -265,7 +266,7 @@ namespace RTC ...@@ -265,7 +266,7 @@ namespace RTC
{ {
auto it = this->codecs.begin(); auto it = this->codecs.begin();
for (; it != this->codecs.end(); ++it) for (; it != this->codecs.end(); it++)
{ {
auto codec = *it; auto codec = *it;
......
#define MS_CLASS "RTC::RtpRtxParameters" #define MS_CLASS "RTC::RtpRtxParameters"
// #define MS_LOG_DEV
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
......
#define MS_CLASS "RTC::RtpListener" #define MS_CLASS "RTC::RtpListener"
// #define MS_LOG_DEV
#include "RTC/RtpListener.h" #include "RTC/RtpListener.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
...@@ -194,7 +195,7 @@ namespace RTC ...@@ -194,7 +195,7 @@ namespace RTC
{ {
auto it = rtpParameters->encodings.begin(); auto it = rtpParameters->encodings.begin();
for (; it != rtpParameters->encodings.end(); ++it) for (; it != rtpParameters->encodings.end(); it++)
{ {
auto& encoding = *it; auto& encoding = *it;
...@@ -283,8 +284,7 @@ namespace RTC ...@@ -283,8 +284,7 @@ namespace RTC
} }
// RTP PT not present. // RTP PT not present.
// TODO: We don't want to log every warning. MS_WARN_TAG(rtp, "unknown RTP payloadType [payloadType:%" PRIu8 "]", packet->GetPayloadType());
MS_WARN("unknown RTP payloadType [payloadType:%" PRIu8 "]", packet->GetPayloadType());
// TODO: We may emit "unhandledrtp" event. // TODO: We may emit "unhandledrtp" event.
return nullptr; return nullptr;
......
#define MS_CLASS "RTC::RtpPacket" #define MS_CLASS "RTC::RtpPacket"
// #define MS_LOG_DEV
#include "RTC/RtpPacket.h" #include "RTC/RtpPacket.h"
#include "Utils.h" #include "Utils.h"
...@@ -32,7 +33,7 @@ namespace RTC ...@@ -32,7 +33,7 @@ namespace RTC
// Packet size must be >= header size + CSRC list. // Packet size must be >= header size + CSRC list.
if (len < pos + csrc_list_size) 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; return nullptr;
} }
...@@ -48,7 +49,7 @@ namespace RTC ...@@ -48,7 +49,7 @@ namespace RTC
// The extension header is at least 4 bytes. // The extension header is at least 4 bytes.
if (len < pos + 4) 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; return nullptr;
} }
...@@ -62,7 +63,7 @@ namespace RTC ...@@ -62,7 +63,7 @@ namespace RTC
// Packet size must be >= header size + CSRC list + header extension size. // Packet size must be >= header size + CSRC list + header extension size.
if (len < pos + 4 + extension_value_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; return nullptr;
} }
...@@ -82,7 +83,7 @@ namespace RTC ...@@ -82,7 +83,7 @@ namespace RTC
// Must be at least a single payload byte. // Must be at least a single payload byte.
if (payloadLength == 0) 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; return nullptr;
} }
...@@ -90,14 +91,14 @@ namespace RTC ...@@ -90,14 +91,14 @@ namespace RTC
payloadPadding = data[len - 1]; payloadPadding = data[len - 1];
if (payloadPadding == 0) 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; return nullptr;
} }
if (payloadLength < (size_t)payloadPadding) 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; return nullptr;
} }
...@@ -139,27 +140,28 @@ namespace RTC ...@@ -139,27 +140,28 @@ namespace RTC
void RtpPacket::Dump() void RtpPacket::Dump()
{ {
MS_TRACE(); #ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel()) MS_TRACE();
return;
MS_DEBUG("<RtpPacket>"); MS_DEBUG_DEV("<RtpPacket>");
MS_DEBUG("padding: %s", this->header->padding ? "true" : "false"); MS_DEBUG_DEV(" padding : %s", this->header->padding ? "true" : "false");
MS_DEBUG("extension: %s", HasExtensionHeader() ? "true" : "false"); MS_DEBUG_DEV(" extension header : %s", HasExtensionHeader() ? "true" : "false");
if (HasExtensionHeader()) if (HasExtensionHeader())
{ {
MS_DEBUG("extension ID: %" PRIu16, GetExtensionHeaderId()); MS_DEBUG_DEV(" id : %" PRIu16, GetExtensionHeaderId());
MS_DEBUG("extension length: %zu bytes", GetExtensionHeaderLength()); MS_DEBUG_DEV(" length : %zu bytes", GetExtensionHeaderLength());
} }
MS_DEBUG("CSRC count: %" PRIu8, this->header->csrc_count); // TODO: method? MS_DEBUG_DEV(" csrc count : %" PRIu8, this->header->csrc_count);
MS_DEBUG("marker: %s", HasMarker() ? "true" : "false"); MS_DEBUG_DEV(" marker : %s", HasMarker() ? "true" : "false");
MS_DEBUG("payload type: %" PRIu8, GetPayloadType()); MS_DEBUG_DEV(" payload type : %" PRIu8, GetPayloadType());
MS_DEBUG("sequence number: %" PRIu16, GetSequenceNumber()); MS_DEBUG_DEV(" sequence number : %" PRIu16, GetSequenceNumber());
MS_DEBUG("timestamp: %" PRIu32, GetTimestamp()); MS_DEBUG_DEV(" timestamp : %" PRIu32, GetTimestamp());
MS_DEBUG("SSRC: %" PRIu32, GetSsrc()); MS_DEBUG_DEV(" ssrc : %" PRIu32, GetSsrc());
MS_DEBUG("payload size: %zu bytes", GetPayloadLength()); MS_DEBUG_DEV(" payload size : %zu bytes", GetPayloadLength());
MS_DEBUG("</RtpPacket>"); MS_DEBUG_DEV("</RtpPacket>");
#endif
} }
void RtpPacket::Serialize() void RtpPacket::Serialize()
......
#define MS_CLASS "RTC::RtpReceiver" #define MS_CLASS "RTC::RtpReceiver"
// #define MS_LOG_DEV
#include "RTC/RtpReceiver.h" #include "RTC/RtpReceiver.h"
#include "RTC/Transport.h" #include "RTC/Transport.h"
...@@ -102,11 +103,14 @@ namespace RTC ...@@ -102,11 +103,14 @@ namespace RTC
{ {
case Channel::Request::MethodId::rtpReceiver_close: case Channel::Request::MethodId::rtpReceiver_close:
{ {
#ifdef MS_LOG_DEV
uint32_t rtpReceiverId = this->rtpReceiverId; uint32_t rtpReceiverId = this->rtpReceiverId;
#endif
Close(); Close();
MS_DEBUG("RtpReceiver closed [rtpReceiverId:%" PRIu32 "]", rtpReceiverId); MS_DEBUG_DEV("RtpReceiver closed [rtpReceiverId:%" PRIu32 "]", rtpReceiverId);
request->Accept(); request->Accept();
break; break;
...@@ -224,7 +228,7 @@ namespace RTC ...@@ -224,7 +228,7 @@ namespace RTC
static const Json::StaticString k_timestamp("timestamp"); static const Json::StaticString k_timestamp("timestamp");
static const Json::StaticString k_ssrc("ssrc"); 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. // Process the packet.
// TODO: Must check what kind of packet we are checking. For example, RTX // TODO: Must check what kind of packet we are checking. For example, RTX
......
#define MS_CLASS "RTC::RtpSender" #define MS_CLASS "RTC::RtpSender"
// #define MS_LOG_DEV
#include "RTC/RtpSender.h" #include "RTC/RtpSender.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
...@@ -53,7 +54,6 @@ namespace RTC ...@@ -53,7 +54,6 @@ namespace RTC
static const Json::StaticString k_rtpParameters("rtpParameters"); static const Json::StaticString k_rtpParameters("rtpParameters");
static const Json::StaticString k_hasTransport("hasTransport"); static const Json::StaticString k_hasTransport("hasTransport");
static const Json::StaticString k_available("available"); static const Json::StaticString k_available("available");
// TODO: TMP
static const Json::StaticString k_mapPayloadTypes("mapPayloadTypes"); static const Json::StaticString k_mapPayloadTypes("mapPayloadTypes");
Json::Value json(Json::objectValue); Json::Value json(Json::objectValue);
...@@ -71,7 +71,6 @@ namespace RTC ...@@ -71,7 +71,6 @@ namespace RTC
json[k_available] = this->available; json[k_available] = this->available;
// TODO: TMP
json[k_mapPayloadTypes] = Json::objectValue; json[k_mapPayloadTypes] = Json::objectValue;
for (auto& kv : this->mapPayloadTypes) for (auto& kv : this->mapPayloadTypes)
{ {
...@@ -143,7 +142,7 @@ namespace RTC ...@@ -143,7 +142,7 @@ namespace RTC
auto& codec = *it; auto& codec = *it;
auto it2 = this->peerCapabilities->codecs.begin(); auto it2 = this->peerCapabilities->codecs.begin();
for (; it2 != this->peerCapabilities->codecs.end(); ++it2) for (; it2 != this->peerCapabilities->codecs.end(); it2++)
{ {
auto& codecCapability = *it2; auto& codecCapability = *it2;
...@@ -222,8 +221,7 @@ namespace RTC ...@@ -222,8 +221,7 @@ namespace RTC
// TODO: We should not report an error here but just ignore it. // TODO: We should not report an error here but just ignore it.
if (it == this->mapPayloadTypes.end()) if (it == this->mapPayloadTypes.end())
{ {
MS_ERROR("payload type not mapped [payloadType:%" PRIu8 "]", MS_ERROR("payload type not mapped [payloadType:%" PRIu8 "]", originalPayloadType);
originalPayloadType);
return; return;
} }
...@@ -264,7 +262,7 @@ namespace RTC ...@@ -264,7 +262,7 @@ namespace RTC
{ {
auto it = this->peerCapabilities->codecs.begin(); auto it = this->peerCapabilities->codecs.begin();
for (; it != this->peerCapabilities->codecs.end(); ++it) for (; it != this->peerCapabilities->codecs.end(); it++)
{ {
auto& codecCapability = *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_CLASS "RTC::RtpStream"
// #define MS_LOG_DEV
#include "RTC/RtpStream.h" #include "RTC/RtpStream.h"
#include "Logger.h" #include "Logger.h"
...@@ -47,8 +48,7 @@ namespace RTC ...@@ -47,8 +48,7 @@ namespace RTC
// If not a valid packet ignore it. // If not a valid packet ignore it.
if (!UpdateSeq(seq)) if (!UpdateSeq(seq))
{ {
// TODO: remove MS_WARN_TAG(rtp, "invalid packet [seq:%" PRIu16 "]", packet->GetSequenceNumber());
MS_WARN("invalid packet [seq:%" PRIu16 "]", packet->GetSequenceNumber());
return false; return false;
} }
...@@ -305,7 +305,7 @@ namespace RTC ...@@ -305,7 +305,7 @@ namespace RTC
// NOTE: This should never happen. // NOTE: This should never happen.
if (buffer_it_r == this->buffer.rend()) 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; return;
} }
...@@ -338,17 +338,17 @@ namespace RTC ...@@ -338,17 +338,17 @@ namespace RTC
{ {
MS_TRACE(); 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) for (auto& buffer_item : this->buffer)
{ {
auto packet = buffer_item.packet; 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_CLASS "RTC::SrtpSession"
// #define MS_LOG_DEV
#include "RTC/SrtpSession.h" #include "RTC/SrtpSession.h"
#include "DepLibSRTP.h" #include "DepLibSRTP.h"
...@@ -34,16 +35,16 @@ namespace RTC ...@@ -34,16 +35,16 @@ namespace RTC
switch (data->event) switch (data->event)
{ {
case event_ssrc_collision: case event_ssrc_collision:
MS_WARN("SSRC collision occurred"); MS_WARN_TAG(srtp, "SSRC collision occurred");
break; break;
case event_key_soft_limit: 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; break;
case event_key_hard_limit: 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; break;
case event_packet_index_limit: 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; break;
} }
} }
...@@ -126,7 +127,7 @@ namespace RTC ...@@ -126,7 +127,7 @@ namespace RTC
// Ensure that the resulting SRTP packet fits into the encrypt buffer. // Ensure that the resulting SRTP packet fits into the encrypt buffer.
if (*len + SRTP_MAX_TRAILER_LEN > MS_ENCRYPT_BUFFER_SIZE) 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; return false;
} }
...@@ -138,8 +139,7 @@ namespace RTC ...@@ -138,8 +139,7 @@ namespace RTC
err = srtp_protect(this->session, (void*)SrtpSession::encryptBuffer, (int*)len); err = srtp_protect(this->session, (void*)SrtpSession::encryptBuffer, (int*)len);
if (DepLibSRTP::IsError(err)) if (DepLibSRTP::IsError(err))
{ {
// TODO MS_WARN_TAG(srtp, "srtp_protect() failed: %s", DepLibSRTP::GetErrorString(err));
MS_WARN("srtp_protect() failed: %s", DepLibSRTP::GetErrorString(err));
return false; return false;
} }
...@@ -159,8 +159,7 @@ namespace RTC ...@@ -159,8 +159,7 @@ namespace RTC
err = srtp_unprotect(this->session, (void*)data, (int*)len); err = srtp_unprotect(this->session, (void*)data, (int*)len);
if (DepLibSRTP::IsError(err)) if (DepLibSRTP::IsError(err))
{ {
// TODO MS_WARN_TAG(srtp, "srtp_unprotect() failed: %s", DepLibSRTP::GetErrorString(err));
MS_WARN("srtp_unprotect() failed: %s", DepLibSRTP::GetErrorString(err));
return false; return false;
} }
...@@ -175,7 +174,7 @@ namespace RTC ...@@ -175,7 +174,7 @@ namespace RTC
// Ensure that the resulting SRTCP packet fits into the encrypt buffer. // Ensure that the resulting SRTCP packet fits into the encrypt buffer.
if (*len + SRTP_MAX_TRAILER_LEN > MS_ENCRYPT_BUFFER_SIZE) 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; return false;
} }
...@@ -187,8 +186,7 @@ namespace RTC ...@@ -187,8 +186,7 @@ namespace RTC
err = srtp_protect_rtcp(this->session, (void*)SrtpSession::encryptBuffer, (int*)len); err = srtp_protect_rtcp(this->session, (void*)SrtpSession::encryptBuffer, (int*)len);
if (DepLibSRTP::IsError(err)) if (DepLibSRTP::IsError(err))
{ {
// TODO MS_WARN_TAG(srtp, "srtp_protect_rtcp() failed: %s", DepLibSRTP::GetErrorString(err));
MS_WARN("srtp_protect_rtcp() failed: %s", DepLibSRTP::GetErrorString(err));
return false; return false;
} }
...@@ -208,8 +206,7 @@ namespace RTC ...@@ -208,8 +206,7 @@ namespace RTC
err = srtp_unprotect_rtcp(this->session, (void*)data, (int*)len); err = srtp_unprotect_rtcp(this->session, (void*)data, (int*)len);
if (DepLibSRTP::IsError(err)) if (DepLibSRTP::IsError(err))
{ {
// TODO MS_WARN_TAG(srtp, "srtp_unprotect_rtcp() failed: %s", DepLibSRTP::GetErrorString(err));
MS_WARN("srtp_unprotect_rtcp() failed: %s", DepLibSRTP::GetErrorString(err));
return false; return false;
} }
......
#define MS_CLASS "RTC::StunMessage" #define MS_CLASS "RTC::StunMessage"
// #define MS_LOG_DEV
#include "RTC/StunMessage.h" #include "RTC/StunMessage.h"
#include "Utils.h" #include "Utils.h"
...@@ -49,7 +50,7 @@ namespace RTC ...@@ -49,7 +50,7 @@ namespace RTC
// length field must be total size minus header's 20 bytes, and must be multiple of 4 Bytes. // 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)) 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; return nullptr;
} }
...@@ -102,7 +103,7 @@ namespace RTC ...@@ -102,7 +103,7 @@ namespace RTC
// Ensure the attribute length is not greater than the remaining size. // Ensure the attribute length is not greater than the remaining size.
if ((pos + 4 + attr_length) > len) 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; delete msg;
return nullptr; return nullptr;
...@@ -111,7 +112,7 @@ namespace RTC ...@@ -111,7 +112,7 @@ namespace RTC
// FINGERPRINT must be the last attribute. // FINGERPRINT must be the last attribute.
if (has_fingerprint) 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; delete msg;
return nullptr; return nullptr;
...@@ -120,7 +121,7 @@ namespace RTC ...@@ -120,7 +121,7 @@ namespace RTC
// After a MESSAGE-INTEGRITY attribute just FINGERPRINT is allowed. // After a MESSAGE-INTEGRITY attribute just FINGERPRINT is allowed.
if (has_message_integrity && attr_type != Attribute::Fingerprint) 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; delete msg;
return nullptr; return nullptr;
...@@ -173,7 +174,7 @@ namespace RTC ...@@ -173,7 +174,7 @@ namespace RTC
// Ensure current position matches the total length. // Ensure current position matches the total length.
if (pos != len) 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; delete msg;
return nullptr; return nullptr;
...@@ -189,7 +190,7 @@ namespace RTC ...@@ -189,7 +190,7 @@ namespace RTC
// Compare with the FINGERPRINT value in the message. // Compare with the FINGERPRINT value in the message.
if (fingerprint != computed_fingerprint) 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; delete msg;
return nullptr; return nullptr;
...@@ -223,50 +224,48 @@ namespace RTC ...@@ -223,50 +224,48 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (!Logger::HasDebugLevel()) MS_DEBUG_DEV("<StunMessage>");
return;
MS_DEBUG("<StunMessage>");
std::string klass; std::string klass;
switch (this->klass) switch (this->klass)
{ {
case Class::Request: klass = "Request"; break; case Class::Request : klass = "Request"; break;
case Class::Indication: klass = "Indication"; break; case Class::Indication : klass = "Indication"; break;
case Class::SuccessResponse: klass = "SuccessResponse"; break; case Class::SuccessResponse : klass = "SuccessResponse"; break;
case Class::ErrorResponse: klass = "ErrorResponse"; break; case Class::ErrorResponse : klass = "ErrorResponse"; break;
} }
if (this->method == Method::Binding) if (this->method == Method::Binding)
MS_DEBUG("Binding %s", klass.c_str()); MS_DEBUG_DEV(" Binding %s", klass.c_str());
else else
// This prints the unknown method number. Example: TURN Allocate => 0x003. // 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_DEV(" %s with unknown method %#.3x", klass.c_str(), (uint16_t)this->method);
MS_DEBUG("length (with header): %zu bytes", this->length); MS_DEBUG_DEV(" length (with header): %zu bytes", this->length);
char transaction_id[25]; char transaction_id[25];
for (int i=0; i<12; i++) for (int i=0; i<12; i++)
{ {
// NOTE: n must be 3 because snprintf adds a \0 after printed chars. // NOTE: n must be 3 because snprintf adds a \0 after printed chars.
std::snprintf(transaction_id+(i*2), 3, "%.2x", this->transactionId[i]); 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) if (this->errorCode)
MS_DEBUG("errorCode: %" PRIu16, this->errorCode); MS_DEBUG_DEV(" errorCode: %" PRIu16, this->errorCode);
if (!this->username.empty()) if (!this->username.empty())
MS_DEBUG("username: %s", this->username.c_str()); MS_DEBUG_DEV(" username: %s", this->username.c_str());
if (this->priority) if (this->priority)
MS_DEBUG("priority: %" PRIu32, this->priority); MS_DEBUG_DEV(" priority: %" PRIu32, this->priority);
if (this->iceControlling) if (this->iceControlling)
MS_DEBUG("iceControlling: %" PRIu64, this->iceControlling); MS_DEBUG_DEV(" iceControlling: %" PRIu64, this->iceControlling);
if (this->iceControlled) if (this->iceControlled)
MS_DEBUG("iceControlled: %" PRIu64, this->iceControlled); MS_DEBUG_DEV(" iceControlled: %" PRIu64, this->iceControlled);
if (this->hasUseCandidate) if (this->hasUseCandidate)
MS_DEBUG("useCandidate"); MS_DEBUG_DEV(" useCandidate");
if (this->xorMappedAddress) if (this->xorMappedAddress)
{ {
int family; int family;
uint16_t port; uint16_t port;
std::string ip; std::string ip;
Utils::IP::GetAddressInfo(this->xorMappedAddress, &family, ip, &port); 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) if (this->messageIntegrity)
{ {
...@@ -275,11 +274,12 @@ namespace RTC ...@@ -275,11 +274,12 @@ namespace RTC
{ {
std::snprintf(message_integrity+(i*2), 3, "%.2x", this->messageIntegrity[i]); 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) if (this->hasFingerprint)
MS_DEBUG("fingerprint"); MS_DEBUG_DEV(" fingerprint");
MS_DEBUG("</StunMessage>"); MS_DEBUG_DEV("</StunMessage>");
} }
StunMessage::Authentication StunMessage::CheckAuthentication(const std::string &local_username, const std::string &local_password) StunMessage::Authentication StunMessage::CheckAuthentication(const std::string &local_username, const std::string &local_password)
......
#define MS_CLASS "RTC::TcpConnection" #define MS_CLASS "RTC::TcpConnection"
// #define MS_LOG_DEV
#include "RTC/TcpConnection.h" #include "RTC/TcpConnection.h"
#include "Utils.h" #include "Utils.h"
...@@ -25,7 +26,7 @@ namespace RTC ...@@ -25,7 +26,7 @@ namespace RTC
{ {
MS_TRACE(); 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(), GetLocalIP().c_str(), GetLocalPort(),
GetPeerIP().c_str(), GetPeerPort()); GetPeerIP().c_str(), GetPeerPort());
...@@ -75,7 +76,7 @@ namespace RTC ...@@ -75,7 +76,7 @@ namespace RTC
// the latest parsed frame filled it, then empty the full buffer. // the latest parsed frame filled it, then empty the full buffer.
if ((this->frameStart + 2 + packet_len) == this->bufferSize) 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->frameStart = 0;
this->bufferDataLen = 0; this->bufferDataLen = 0;
...@@ -91,7 +92,7 @@ namespace RTC ...@@ -91,7 +92,7 @@ namespace RTC
// parse again. Otherwise break here and wait for more data. // parse again. Otherwise break here and wait for more data.
if (this->bufferDataLen > this->frameStart) 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; continue;
} }
...@@ -111,7 +112,7 @@ namespace RTC ...@@ -111,7 +112,7 @@ namespace RTC
// the buffer, so move the frame to the position 0. // the buffer, so move the frame to the position 0.
if (this->frameStart != 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); std::memmove(this->buffer, this->buffer + this->frameStart, this->bufferSize - this->frameStart);
this->bufferDataLen = this->bufferSize - this->frameStart; this->bufferDataLen = this->bufferSize - this->frameStart;
...@@ -121,7 +122,7 @@ namespace RTC ...@@ -121,7 +122,7 @@ namespace RTC
// The frame is too big, so close the connection. // The frame is too big, so close the connection.
else 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 the socket.
Close(); Close();
...@@ -130,7 +131,7 @@ namespace RTC ...@@ -130,7 +131,7 @@ namespace RTC
// The buffer is not full. // The buffer is not full.
else 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. // Exit the parsing loop.
......
#define MS_CLASS "RTC::TcpServer" #define MS_CLASS "RTC::TcpServer"
// #define MS_LOG_DEV
#include "RTC/TcpServer.h" #include "RTC/TcpServer.h"
#include "Settings.h" #include "Settings.h"
...@@ -125,13 +126,11 @@ namespace RTC ...@@ -125,13 +126,11 @@ namespace RTC
// Check whether the chosen port is available. // Check whether the chosen port is available.
if (!(*available_ports)[iterating_port]) 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 we have tried all the ports in the range raise an error.
if (iterating_port == initial_port) if (iterating_port == initial_port)
{
MS_THROW_ERROR("no more available ports for IP '%s'", listen_ip); MS_THROW_ERROR("no more available ports for IP '%s'", listen_ip);
}
continue; continue;
} }
...@@ -165,27 +164,21 @@ namespace RTC ...@@ -165,27 +164,21 @@ namespace RTC
err = uv_tcp_bind(uvHandle, (const struct sockaddr*)&bind_addr, flags); err = uv_tcp_bind(uvHandle, (const struct sockaddr*)&bind_addr, flags);
if (err) 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); uv_close((uv_handle_t*)uvHandle, (uv_close_cb)on_error_close);
// If bind() fails due to "too many open files" stop here. // If bind() fails due to "too many open files" stop here.
if (err == UV_EMFILE) if (err == UV_EMFILE)
{
MS_THROW_ERROR("uv_tcp_bind() fails due to many open files"); 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() fails for more that MAX_BIND_ATTEMPTS then raise an error.
if (bind_attempt > MAX_BIND_ATTEMPTS) 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); 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 we have tried all the ports in the range raise an error.
if (iterating_port == initial_port) if (iterating_port == initial_port)
{
MS_THROW_ERROR("no more available ports for IP '%s'", listen_ip); MS_THROW_ERROR("no more available ports for IP '%s'", listen_ip);
}
continue; continue;
} }
...@@ -193,7 +186,7 @@ namespace RTC ...@@ -193,7 +186,7 @@ namespace RTC
// Set the port as unavailable. // Set the port as unavailable.
(*available_ports)[iterating_port] = false; (*available_ports)[iterating_port] = false;
MS_DEBUG("bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]", MS_DEBUG_DEV("bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]",
listen_ip, iterating_port, attempt); listen_ip, iterating_port, attempt);
return uvHandle; return uvHandle;
......
#define MS_CLASS "RTC::TransportTuple" #define MS_CLASS "RTC::TransportTuple"
// #define MS_LOG_DEV
#include "RTC/TransportTuple.h" #include "RTC/TransportTuple.h"
#include "Logger.h" #include "Logger.h"
...@@ -41,13 +42,11 @@ namespace RTC ...@@ -41,13 +42,11 @@ namespace RTC
return json; return json;
} }
// TODO: TMP
void TransportTuple::Dump() void TransportTuple::Dump()
{ {
MS_TRACE(); #ifdef MS_LOG_DEV
if (!Logger::HasDebugLevel()) MS_TRACE();
return;
switch (this->protocol) switch (this->protocol)
{ {
...@@ -59,7 +58,7 @@ namespace RTC ...@@ -59,7 +58,7 @@ namespace RTC
Utils::IP::GetAddressInfo(GetRemoteAddress(), &remote_family, remote_ip, &remote_port); 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(), this->udpSocket->GetLocalIP().c_str(), this->udpSocket->GetLocalPort(),
remote_ip.c_str(), remote_port); remote_ip.c_str(), remote_port);
break; break;
...@@ -67,11 +66,13 @@ namespace RTC ...@@ -67,11 +66,13 @@ namespace RTC
case Protocol::TCP: 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->GetLocalIP().c_str(), this->tcpConnection->GetLocalPort(),
this->tcpConnection->GetPeerIP().c_str(), this->tcpConnection->GetPeerPort()); this->tcpConnection->GetPeerIP().c_str(), this->tcpConnection->GetPeerPort());
break; break;
} }
} }
#endif
} }
} }
#define MS_CLASS "RTC::UdpSocket" #define MS_CLASS "RTC::UdpSocket"
// #define MS_LOG_DEV
#include "RTC/UdpSocket.h" #include "RTC/UdpSocket.h"
#include "Settings.h" #include "Settings.h"
...@@ -124,7 +125,7 @@ namespace RTC ...@@ -124,7 +125,7 @@ namespace RTC
// Check whether the chosen port is available. // Check whether the chosen port is available.
if (!(*available_ports)[iterating_port]) 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 we have tried all the ports in the range raise an error.
if (iterating_port == initial_port) { if (iterating_port == initial_port) {
...@@ -163,27 +164,21 @@ namespace RTC ...@@ -163,27 +164,21 @@ namespace RTC
err = uv_udp_bind(uvHandle, (const struct sockaddr*)&bind_addr, flags); err = uv_udp_bind(uvHandle, (const struct sockaddr*)&bind_addr, flags);
if (err) 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); uv_close((uv_handle_t*)uvHandle, (uv_close_cb)on_error_close);
// If bind() fails due to "too many open files" stop here. // If bind() fails due to "too many open files" stop here.
if (err == UV_EMFILE) if (err == UV_EMFILE)
{
MS_THROW_ERROR("uv_udp_bind() fails due to many open files"); 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() fails for more that MAX_BIND_ATTEMPTS then raise an error.
if (bind_attempt > MAX_BIND_ATTEMPTS) 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); 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 we have tried all the ports in the range raise an error.
if (iterating_port == initial_port) if (iterating_port == initial_port)
{
MS_THROW_ERROR("no more available ports for IP '%s'", listen_ip); MS_THROW_ERROR("no more available ports for IP '%s'", listen_ip);
}
continue; continue;
} }
...@@ -191,7 +186,7 @@ namespace RTC ...@@ -191,7 +186,7 @@ namespace RTC
// Set the port as unavailable. // Set the port as unavailable.
(*available_ports)[iterating_port] = false; (*available_ports)[iterating_port] = false;
MS_DEBUG("bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]", MS_DEBUG_DEV("bind success [ip:%s, port:%" PRIu16 ", attempt:%" PRIu16 "]",
listen_ip, iterating_port, attempt); listen_ip, iterating_port, attempt);
return uvHandle; return uvHandle;
...@@ -221,18 +216,6 @@ namespace RTC ...@@ -221,18 +216,6 @@ namespace RTC
return; 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. // Notify the reader.
this->listener->onPacketRecv(this, data, len, addr); this->listener->onPacketRecv(this, data, len, addr);
} }
......
#define MS_CLASS "Settings" #define MS_CLASS "Settings"
// #define MS_LOG_DEV
#include "Settings.h" #include "Settings.h"
#include "Utils.h" #include "Utils.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
#include "Logger.h" #include "Logger.h"
#include <string>
#include <map>
#include <cctype> // isprint() #include <cctype> // isprint()
#include <cerrno> #include <cerrno>
#include <unistd.h> // close() #include <unistd.h> // close()
...@@ -23,6 +22,7 @@ bool IsBindableIP(const std::string &ip, int family, int* _bind_err); ...@@ -23,6 +22,7 @@ bool IsBindableIP(const std::string &ip, int family, int* _bind_err);
/* Class variables. */ /* Class variables. */
struct Settings::Configuration Settings::configuration; struct Settings::Configuration Settings::configuration;
struct Settings::LogTags Settings::logTags;
std::map<std::string, LogLevel> Settings::string2LogLevel = std::map<std::string, LogLevel> Settings::string2LogLevel =
{ {
{ "debug", LogLevel::LOG_DEBUG }, { "debug", LogLevel::LOG_DEBUG },
...@@ -54,10 +54,12 @@ void Settings::SetConfiguration(int argc, char* argv[]) ...@@ -54,10 +54,12 @@ void Settings::SetConfiguration(int argc, char* argv[])
int c; int c;
int option_index = 0; int option_index = 0;
std::string value_string; std::string value_string;
std::vector<std::string> log_tags;
struct option options[] = struct option options[] =
{ {
{ "logLevel", optional_argument, nullptr, 'l' }, { "logLevel", optional_argument, nullptr, 'l' },
{ "logTag", optional_argument, nullptr, 't' },
{ "rtcListenIPv4", optional_argument, nullptr, '4' }, { "rtcListenIPv4", optional_argument, nullptr, '4' },
{ "rtcListenIPv6", optional_argument, nullptr, '6' }, { "rtcListenIPv6", optional_argument, nullptr, '6' },
{ "rtcMinPort", optional_argument, nullptr, 'm' }, { "rtcMinPort", optional_argument, nullptr, 'm' },
...@@ -82,6 +84,11 @@ void Settings::SetConfiguration(int argc, char* argv[]) ...@@ -82,6 +84,11 @@ void Settings::SetConfiguration(int argc, char* argv[])
SetLogLevel(value_string); SetLogLevel(value_string);
break; break;
case 't':
value_string = std::string(optarg);
log_tags.push_back(value_string);
break;
case '4': case '4':
value_string = std::string(optarg); value_string = std::string(optarg);
SetRtcListenIPv4(value_string); SetRtcListenIPv4(value_string);
...@@ -129,6 +136,10 @@ void Settings::SetConfiguration(int argc, char* argv[]) ...@@ -129,6 +136,10 @@ void Settings::SetConfiguration(int argc, char* argv[])
/* Post configuration. */ /* Post configuration. */
// Set logTags.
if (!log_tags.empty())
Settings::SetLogTags(log_tags);
// RTC must have at least 'listenIPv4' or 'listenIPv6'. // RTC must have at least 'listenIPv4' or 'listenIPv6'.
if (!Settings::configuration.hasIPv4 && !Settings::configuration.hasIPv6) if (!Settings::configuration.hasIPv4 && !Settings::configuration.hasIPv6)
MS_THROW_ERROR("at least rtcListenIPv4 or rtcListenIPv6 must be enabled"); MS_THROW_ERROR("at least rtcListenIPv4 or rtcListenIPv6 must be enabled");
...@@ -144,26 +155,45 @@ void Settings::PrintConfiguration() ...@@ -144,26 +155,45 @@ void Settings::PrintConfiguration()
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG("<configuration>"); std::vector<std::string> log_tags;
MS_DEBUG("logLevel: \"%s\"", Settings::logLevel2String[Settings::configuration.logLevel].c_str()); 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) 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 else
MS_DEBUG("rtcListenIPv4: (unavailable)"); MS_DEBUG_TAG(info, "rtcListenIPv4: (unavailable)");
if (Settings::configuration.hasIPv6) 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 else
MS_DEBUG("rtcListenIPv6: (unavailable)"); MS_DEBUG_TAG(info, "rtcListenIPv6: (unavailable)");
MS_DEBUG("rtcMinPort: %" PRIu16, Settings::configuration.rtcMinPort); MS_DEBUG_TAG(info, "rtcMinPort: %" PRIu16, Settings::configuration.rtcMinPort);
MS_DEBUG("rtcMaxPort: %" PRIu16, Settings::configuration.rtcMaxPort); MS_DEBUG_TAG(info, "rtcMaxPort: %" PRIu16, Settings::configuration.rtcMaxPort);
if (!Settings::configuration.dtlsCertificateFile.empty()) if (!Settings::configuration.dtlsCertificateFile.empty())
{ {
MS_DEBUG("dtlsCertificateFile: \"%s\"", Settings::configuration.dtlsCertificateFile.c_str()); MS_DEBUG_TAG(info, "dtlsCertificateFile: \"%s\"", Settings::configuration.dtlsCertificateFile.c_str());
MS_DEBUG("dtlsPrivateKeyFile: \"%s\"", Settings::configuration.dtlsPrivateKeyFile.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) void Settings::HandleRequest(Channel::Request* request)
...@@ -175,8 +205,10 @@ void Settings::HandleRequest(Channel::Request* request) ...@@ -175,8 +205,10 @@ void Settings::HandleRequest(Channel::Request* request)
case Channel::Request::MethodId::worker_updateSettings: case Channel::Request::MethodId::worker_updateSettings:
{ {
static const Json::StaticString k_logLevel("logLevel"); 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_logLevel = request->data[k_logLevel];
Json::Value json_logTags = request->data[k_logTags];
try try
{ {
...@@ -187,6 +219,12 @@ void Settings::HandleRequest(Channel::Request* request) ...@@ -187,6 +219,12 @@ void Settings::HandleRequest(Channel::Request* request)
Settings::SetLogLevel(logLevel); Settings::SetLogLevel(logLevel);
} }
// Update logTags if requested.
if (json_logTags.isArray())
{
Settings::SetLogTags(json_logTags);
}
} }
catch (const MediaSoupError &error) catch (const MediaSoupError &error)
{ {
...@@ -194,9 +232,7 @@ void Settings::HandleRequest(Channel::Request* request) ...@@ -194,9 +232,7 @@ void Settings::HandleRequest(Channel::Request* request)
return; return;
} }
MS_DEBUG("updated settings:"); // Print the new effective configuration.
// Print configuration.
Settings::PrintConfiguration(); Settings::PrintConfiguration();
request->Accept(); request->Accept();
...@@ -429,6 +465,49 @@ void Settings::SetDtlsCertificateAndPrivateKeyFiles() ...@@ -429,6 +465,49 @@ void Settings::SetDtlsCertificateAndPrivateKeyFiles()
Settings::configuration.dtlsPrivateKeyFile = dtlsPrivateKeyFile; 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. */ /* Helpers. */
bool IsBindableIP(const std::string &ip, int family, int* bind_errno) bool IsBindableIP(const std::string &ip, int family, int* bind_errno)
......
#define MS_CLASS "Utils::Crypto" #define MS_CLASS "Utils::Crypto"
// #define MS_LOG_DEV
#include "Utils.h" #include "Utils.h"
#include "Logger.h" #include "Logger.h"
......
#define MS_CLASS "Utils::File" #define MS_CLASS "Utils::File"
// #define MS_LOG_DEV
#include "Utils.h" #include "Utils.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
......
#define MS_CLASS "Utils::IP" #define MS_CLASS "Utils::IP"
// #define MS_LOG_DEV
#include "Utils.h" #include "Utils.h"
#include "Logger.h" #include "Logger.h"
......
#define MS_CLASS "SignalsHandler" #define MS_CLASS "SignalsHandler"
// #define MS_LOG_DEV
#include "handles/SignalsHandler.h" #include "handles/SignalsHandler.h"
#include "DepLibUV.h" #include "DepLibUV.h"
......
#define MS_CLASS "TcpConnection" #define MS_CLASS "TcpConnection"
// #define MS_LOG_DEV
#include "handles/TcpConnection.h" #include "handles/TcpConnection.h"
#include "Utils.h" #include "Utils.h"
...@@ -83,6 +84,7 @@ void TcpConnection::Setup(Listener* listener, struct sockaddr_storage* localAddr ...@@ -83,6 +84,7 @@ void TcpConnection::Setup(Listener* listener, struct sockaddr_storage* localAddr
{ {
delete this->uvHandle; delete this->uvHandle;
this->uvHandle = nullptr; this->uvHandle = nullptr;
MS_THROW_ERROR("uv_tcp_init() failed: %s", uv_strerror(err)); MS_THROW_ERROR("uv_tcp_init() failed: %s", uv_strerror(err));
} }
...@@ -131,7 +133,7 @@ void TcpConnection::Close() ...@@ -131,7 +133,7 @@ void TcpConnection::Close()
void TcpConnection::Dump() 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->localIP.c_str(), (uint16_t)this->localPort,
this->peerIP.c_str(), (uint16_t)this->peerPort, this->peerIP.c_str(), (uint16_t)this->peerPort,
(!this->isClosing) ? "open" : "closed"); (!this->isClosing) ? "open" : "closed");
...@@ -189,13 +191,13 @@ void TcpConnection::Write(const uint8_t* data, size_t len) ...@@ -189,13 +191,13 @@ void TcpConnection::Write(const uint8_t* data, size_t len)
// Error. Should not happen. // Error. Should not happen.
else if (written < 0) 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(); Close();
return; 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; size_t pending_len = len - written;
...@@ -249,13 +251,13 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data ...@@ -249,13 +251,13 @@ void TcpConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data
// Error. Should not happen. // Error. Should not happen.
else if (written < 0) 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(); Close();
return; 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; size_t pending_len = total_len - written;
...@@ -324,7 +326,7 @@ void TcpConnection::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf) ...@@ -324,7 +326,7 @@ void TcpConnection::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf)
{ {
buf->len = 0; 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) ...@@ -351,7 +353,7 @@ void TcpConnection::onUvRead(ssize_t nread, const uv_buf_t* buf)
// Client disconneted. // Client disconneted.
else if (nread == UV_EOF || nread == UV_ECONNRESET) 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; this->isClosedByPeer = true;
...@@ -361,7 +363,7 @@ void TcpConnection::onUvRead(ssize_t nread, const uv_buf_t* buf) ...@@ -361,7 +363,7 @@ void TcpConnection::onUvRead(ssize_t nread, const uv_buf_t* buf)
// Some error. // Some error.
else 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; this->hasError = true;
...@@ -380,11 +382,11 @@ void TcpConnection::onUvWriteError(int error) ...@@ -380,11 +382,11 @@ void TcpConnection::onUvWriteError(int error)
if (error == UV_EPIPE || error == UV_ENOTCONN) 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 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; this->hasError = true;
} }
...@@ -400,9 +402,9 @@ void TcpConnection::onUvShutdown(uv_shutdown_t* req, int status) ...@@ -400,9 +402,9 @@ void TcpConnection::onUvShutdown(uv_shutdown_t* req, int status)
delete req; delete req;
if (status == UV_EPIPE || status == UV_ENOTCONN || status == UV_ECANCELED) 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) 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. // Now do close the handle.
uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close); uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close);
......
#define MS_CLASS "TcpServer" #define MS_CLASS "TcpServer"
// #define MS_LOG_DEV
#include "handles/TcpServer.h" #include "handles/TcpServer.h"
#include "Utils.h" #include "Utils.h"
...@@ -141,9 +142,9 @@ void TcpServer::Close() ...@@ -141,9 +142,9 @@ void TcpServer::Close()
// Otherwise close all the connections (but not the TCP server). // Otherwise close all the connections (but not the TCP server).
else 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; TcpConnection* connection = *it;
connection->Close(); connection->Close();
...@@ -153,7 +154,7 @@ void TcpServer::Close() ...@@ -153,7 +154,7 @@ void TcpServer::Close()
void TcpServer::Dump() 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->localIP.c_str(), (uint16_t)this->localPort,
(!this->isClosing) ? "open" : "closed", (!this->isClosing) ? "open" : "closed",
this->connections.size()); this->connections.size());
...@@ -290,7 +291,7 @@ void TcpServer::onTcpConnectionClosed(TcpConnection* connection, bool is_closed_ ...@@ -290,7 +291,7 @@ void TcpServer::onTcpConnectionClosed(TcpConnection* connection, bool is_closed_
bool wasClosing = this->isClosing; bool wasClosing = this->isClosing;
MS_DEBUG("TCP connection closed:"); MS_DEBUG_DEV("TCP connection closed");
connection->Dump(); connection->Dump();
// Remove the TcpConnection from the set. // Remove the TcpConnection from the set.
......
#define MS_CLASS "Timer" #define MS_CLASS "Timer"
// #define MS_LOG_DEV
#include "handles/Timer.h" #include "handles/Timer.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
......
#define MS_CLASS "UdpSocket" #define MS_CLASS "UdpSocket"
// #define MS_LOG_DEV
#include "handles/UdpSocket.h" #include "handles/UdpSocket.h"
#include "Utils.h" #include "Utils.h"
...@@ -171,7 +172,7 @@ void UdpSocket::Close() ...@@ -171,7 +172,7 @@ void UdpSocket::Close()
void UdpSocket::Dump() 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->localIP.c_str(), (uint16_t)this->localPort,
(!this->isClosing) ? "open" : "closed"); (!this->isClosing) ? "open" : "closed");
} }
...@@ -203,20 +204,20 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add ...@@ -203,20 +204,20 @@ void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* add
} }
else if (sent >= 0) 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; return;
} }
// Error, // Error,
else if (sent != UV_EAGAIN) 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; return;
} }
// Otherwise UV_EAGAIN was returned so cannot send data at first time. Use uv_udp_send(). // 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. // Allocate a special UvSendData struct pointer.
UvSendData* send_data = (UvSendData*)std::malloc(sizeof(UvSendData) + len); 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 ...@@ -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 // NOTE: uv_udp_send() returns error if a wrong INET family is given
// (IPv6 destination on a IPv4 binded socket), so be ready. // (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[]). // Delete the UvSendData struct (which includes the uv_req_t and the store char[]).
std::free(send_data); std::free(send_data);
...@@ -339,7 +340,7 @@ void UdpSocket::onUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockad ...@@ -339,7 +340,7 @@ void UdpSocket::onUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockad
// Some error. // Some error.
else 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) ...@@ -351,7 +352,7 @@ void UdpSocket::onUvSendError(int error)
if (this->isClosing) if (this->isClosing)
return; return;
MS_DEBUG("send error: %s", uv_strerror(error)); MS_DEBUG_DEV("send error: %s", uv_strerror(error));
} }
inline inline
......
/** /**
* NOTE: This code cannot use MS_DEBUG, MS_WARN, MS_ERROR since this is the base * NOTE: This code cannot log to the Channel since this is the base code of the
* code of the intercommunication Channel. * Channel.
*/ */
#define MS_CLASS "UnixStreamSocket" #define MS_CLASS "UnixStreamSocket"
// #define MS_LOG_DEV
#include "handles/UnixStreamSocket.h" #include "handles/UnixStreamSocket.h"
#include "DepLibUV.h" #include "DepLibUV.h"
...@@ -206,7 +207,6 @@ void UnixStreamSocket::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf) ...@@ -206,7 +207,6 @@ void UnixStreamSocket::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf)
if (this->bufferSize > this->bufferDataLen) if (this->bufferSize > this->bufferDataLen)
{ {
buf->len = this->bufferSize - this->bufferDataLen; buf->len = this->bufferSize - this->bufferDataLen;
// MS_DEBUG_STD("available space in the buffer: %zu", buf->len);
} }
else else
{ {
...@@ -236,8 +236,6 @@ void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf) ...@@ -236,8 +236,6 @@ void UnixStreamSocket::onUvRead(ssize_t nread, const uv_buf_t* buf)
// Peer disconneted. // Peer disconneted.
else if (nread == UV_EOF || nread == UV_ECONNRESET) else if (nread == UV_EOF || nread == UV_ECONNRESET)
{ {
MS_DEBUG("connection closed by peer, closing server side");
this->isClosedByPeer = true; this->isClosedByPeer = true;
// Close local side of the pipe. // Close local side of the pipe.
...@@ -265,11 +263,11 @@ void UnixStreamSocket::onUvWriteError(int error) ...@@ -265,11 +263,11 @@ void UnixStreamSocket::onUvWriteError(int error)
if (error == UV_EPIPE || error == UV_ENOTCONN) 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 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; this->hasError = true;
} }
...@@ -285,9 +283,9 @@ void UnixStreamSocket::onUvShutdown(uv_shutdown_t* req, int status) ...@@ -285,9 +283,9 @@ void UnixStreamSocket::onUvShutdown(uv_shutdown_t* req, int status)
delete req; delete req;
if (status == UV_EPIPE || status == UV_ENOTCONN || status == UV_ECANCELED) 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) 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. // Now do close the handle.
uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close); uv_close((uv_handle_t*)this->uvHandle, (uv_close_cb)on_close);
......
#define MS_CLASS "main" #define MS_CLASS "main"
// #define MS_LOG_DEV
#include "common.h" #include "common.h"
#include "Settings.h" #include "Settings.h"
...@@ -17,7 +18,7 @@ ...@@ -17,7 +18,7 @@
#include "Logger.h" #include "Logger.h"
#include <map> #include <map>
#include <string> #include <string>
#include <iostream> // std::cerr, std::endl #include <iostream> // std::cout, std::cerr, std::endl
#include <cstdlib> // std::_Exit(), std::genenv() #include <cstdlib> // std::_Exit(), std::genenv()
#include <csignal> // sigaction() #include <csignal> // sigaction()
#include <cerrno> #include <cerrno>
...@@ -66,20 +67,20 @@ int main(int argc, char* argv[]) ...@@ -66,20 +67,20 @@ int main(int argc, char* argv[])
// Print the effective configuration. // Print the effective configuration.
Settings::PrintConfiguration(); 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) #if defined(MS_LITTLE_ENDIAN)
MS_DEBUG("Little-Endian CPU detected"); MS_DEBUG_TAG(info, "Little-Endian CPU detected");
#elif defined(MS_BIG_ENDIAN) #elif defined(MS_BIG_ENDIAN)
MS_DEBUG("Big-Endian CPU detected"); MS_DEBUG_TAG(info, "Big-Endian CPU detected");
#endif #endif
#if defined(INTPTR_MAX) && defined(INT32_MAX) && (INTPTR_MAX == INT32_MAX) #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) #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 #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 #endif
try try
...@@ -89,9 +90,8 @@ int main(int argc, char* argv[]) ...@@ -89,9 +90,8 @@ int main(int argc, char* argv[])
// Run the Loop. // Run the Loop.
Loop loop(channel); Loop loop(channel);
// Loop ended.
destroy(); destroy();
MS_DEBUG_STD("success exit");
exitSuccess(); exitSuccess();
} }
catch (const MediaSoupError &error) catch (const MediaSoupError &error)
...@@ -144,7 +144,7 @@ void ignoreSignals() ...@@ -144,7 +144,7 @@ void ignoreSignals()
if (err) if (err)
MS_THROW_ERROR("sigfillset() failed: %s", std::strerror(errno)); 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; auto& sig_name = it->first;
int sig_id = it->second; int sig_id = it->second;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论