1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

SRT: add srt log handle, srs log supoort multithread

This commit is contained in:
hondaxiao 2022-06-12 23:18:18 +08:00 committed by winlin
parent d03c6793b8
commit 910b5945af
5 changed files with 61 additions and 0 deletions

View file

@ -16,6 +16,9 @@ using namespace std;
#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) \
if (srt_setsockflag(srtfd, optname, buf, size) == SRT_ERROR) { \
std::stringstream ss; \
@ -43,6 +46,7 @@ using namespace std;
} \
} while (0)
static srs_error_t do_srs_srt_listen(srs_srt_t srt_fd, addrinfo* r)
{
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;
}
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()
{
return SRT_INVALID_SOCK;

View file

@ -15,6 +15,8 @@
class SrsSrtSocket;
extern srs_error_t srs_srt_log_initialie();
typedef int srs_srt_t;
extern srs_srt_t srs_srt_socket_invalid();