mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 11:51:57 +00:00
SRT: add srt log handle, srs log supoort multithread
This commit is contained in:
parent
d03c6793b8
commit
910b5945af
5 changed files with 61 additions and 0 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include <srs_kernel_error.hpp>
|
#include <srs_kernel_error.hpp>
|
||||||
#include <srs_app_utility.hpp>
|
#include <srs_app_utility.hpp>
|
||||||
#include <srs_kernel_utility.hpp>
|
#include <srs_kernel_utility.hpp>
|
||||||
|
#include <srs_core_lock.hpp>
|
||||||
|
|
||||||
// the max size of a line of log.
|
// the max size of a line of log.
|
||||||
#define LOG_MAX_SIZE 8192
|
#define LOG_MAX_SIZE 8192
|
||||||
|
@ -35,6 +36,8 @@ SrsFileLog::SrsFileLog()
|
||||||
fd = -1;
|
fd = -1;
|
||||||
log_to_file_tank = false;
|
log_to_file_tank = false;
|
||||||
utc = false;
|
utc = false;
|
||||||
|
|
||||||
|
pthread_mutex_init(&mutex_, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsFileLog::~SrsFileLog()
|
SrsFileLog::~SrsFileLog()
|
||||||
|
@ -49,6 +52,8 @@ SrsFileLog::~SrsFileLog()
|
||||||
if (_srs_config) {
|
if (_srs_config) {
|
||||||
_srs_config->unsubscribe(this);
|
_srs_config->unsubscribe(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_destroy(&mutex_);
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsFileLog::initialize()
|
srs_error_t SrsFileLog::initialize()
|
||||||
|
@ -79,6 +84,8 @@ void SrsFileLog::reopen()
|
||||||
|
|
||||||
void SrsFileLog::verbose(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
void SrsFileLog::verbose(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
||||||
{
|
{
|
||||||
|
SrsScopeLock sl(&mutex_);
|
||||||
|
|
||||||
if (level > SrsLogLevelVerbose) {
|
if (level > SrsLogLevelVerbose) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -99,6 +106,8 @@ void SrsFileLog::verbose(const char* tag, SrsContextId context_id, const char* f
|
||||||
|
|
||||||
void SrsFileLog::info(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
void SrsFileLog::info(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
||||||
{
|
{
|
||||||
|
SrsScopeLock sl(&mutex_);
|
||||||
|
|
||||||
if (level > SrsLogLevelInfo) {
|
if (level > SrsLogLevelInfo) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -119,6 +128,8 @@ void SrsFileLog::info(const char* tag, SrsContextId context_id, const char* fmt,
|
||||||
|
|
||||||
void SrsFileLog::trace(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
void SrsFileLog::trace(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
||||||
{
|
{
|
||||||
|
SrsScopeLock sl(&mutex_);
|
||||||
|
|
||||||
if (level > SrsLogLevelTrace) {
|
if (level > SrsLogLevelTrace) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -139,6 +150,8 @@ void SrsFileLog::trace(const char* tag, SrsContextId context_id, const char* fmt
|
||||||
|
|
||||||
void SrsFileLog::warn(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
void SrsFileLog::warn(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
||||||
{
|
{
|
||||||
|
SrsScopeLock sl(&mutex_);
|
||||||
|
|
||||||
if (level > SrsLogLevelWarn) {
|
if (level > SrsLogLevelWarn) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -159,6 +172,8 @@ void SrsFileLog::warn(const char* tag, SrsContextId context_id, const char* fmt,
|
||||||
|
|
||||||
void SrsFileLog::error(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
void SrsFileLog::error(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
||||||
{
|
{
|
||||||
|
SrsScopeLock sl(&mutex_);
|
||||||
|
|
||||||
if (level > SrsLogLevelError) {
|
if (level > SrsLogLevelError) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,9 @@ private:
|
||||||
bool log_to_file_tank;
|
bool log_to_file_tank;
|
||||||
// Whether use utc time.
|
// Whether use utc time.
|
||||||
bool utc;
|
bool utc;
|
||||||
|
// TODO: FIXME: use macro define like SRS_MULTI_THREAD_LOG to switch enable log mutex or not.
|
||||||
|
// Mutex for multithread log.
|
||||||
|
pthread_mutex_t mutex_;
|
||||||
public:
|
public:
|
||||||
SrsFileLog();
|
SrsFileLog();
|
||||||
virtual ~SrsFileLog();
|
virtual ~SrsFileLog();
|
||||||
|
|
|
@ -267,6 +267,10 @@ srs_error_t SrsSrtServerAdapter::initialize()
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
if ((err = srs_srt_log_initialie()) != srs_success) {
|
||||||
|
return srs_error_wrap(err, "srt log initialize");
|
||||||
|
}
|
||||||
|
|
||||||
_srt_eventloop = new SrsSrtEventLoop();
|
_srt_eventloop = new SrsSrtEventLoop();
|
||||||
|
|
||||||
if ((err = _srt_eventloop->initialize()) != srs_success) {
|
if ((err = _srt_eventloop->initialize()) != srs_success) {
|
||||||
|
|
|
@ -16,6 +16,9 @@ using namespace std;
|
||||||
|
|
||||||
#include <srt/srt.h>
|
#include <srt/srt.h>
|
||||||
|
|
||||||
|
// TODO: FIXME: protocol could no include app's header file, so define TAG_SRT in this file.
|
||||||
|
#define TAG_SRT "SRT"
|
||||||
|
|
||||||
#define SET_SRT_OPT_STR(srtfd, optname, buf, size) \
|
#define SET_SRT_OPT_STR(srtfd, optname, buf, size) \
|
||||||
if (srt_setsockflag(srtfd, optname, buf, size) == SRT_ERROR) { \
|
if (srt_setsockflag(srtfd, optname, buf, size) == SRT_ERROR) { \
|
||||||
std::stringstream ss; \
|
std::stringstream ss; \
|
||||||
|
@ -43,6 +46,7 @@ using namespace std;
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
static srs_error_t do_srs_srt_listen(srs_srt_t srt_fd, addrinfo* r)
|
static srs_error_t do_srs_srt_listen(srs_srt_t srt_fd, addrinfo* r)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
@ -72,6 +76,39 @@ static srs_error_t do_srs_srt_get_streamid(srs_srt_t srt_fd, string& streamid)
|
||||||
return srs_success;
|
return srs_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void srs_srt_log_handler(void* opaque, int level, const char* file, int line, const char* area, const char* message)
|
||||||
|
{
|
||||||
|
switch (level) {
|
||||||
|
case srt_logging::LogLevel::debug:
|
||||||
|
srs_info2(TAG_SRT, "%s:%d(%s) # %s", file, line, area, message);
|
||||||
|
break;
|
||||||
|
case srt_logging::LogLevel::note:
|
||||||
|
srs_trace2(TAG_SRT, "%s:%d(%s) # %s", file, line, area, message);
|
||||||
|
break;
|
||||||
|
case srt_logging::LogLevel::warning:
|
||||||
|
srs_warn2(TAG_SRT, "%s:%d(%s) # %s", file, line, area, message);
|
||||||
|
break;
|
||||||
|
case srt_logging::LogLevel::error:
|
||||||
|
case srt_logging::LogLevel::fatal:
|
||||||
|
srs_error2(TAG_SRT, "%s:%d(%s) # %s", file, line, area, message);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
srs_trace2(TAG_SRT, "%s:%d(%s) # %s", file, line, area, message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
srs_error_t srs_srt_log_initialie()
|
||||||
|
{
|
||||||
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
srt_setlogflags(0 | SRT_LOGF_DISABLE_TIME | SRT_LOGF_DISABLE_SEVERITY |
|
||||||
|
SRT_LOGF_DISABLE_THREADNAME | SRT_LOGF_DISABLE_EOL);
|
||||||
|
srt_setloghandler(NULL, srs_srt_log_handler);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
srs_srt_t srs_srt_socket_invalid()
|
srs_srt_t srs_srt_socket_invalid()
|
||||||
{
|
{
|
||||||
return SRT_INVALID_SOCK;
|
return SRT_INVALID_SOCK;
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
class SrsSrtSocket;
|
class SrsSrtSocket;
|
||||||
|
|
||||||
|
extern srs_error_t srs_srt_log_initialie();
|
||||||
|
|
||||||
typedef int srs_srt_t;
|
typedef int srs_srt_t;
|
||||||
extern srs_srt_t srs_srt_socket_invalid();
|
extern srs_srt_t srs_srt_socket_invalid();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue