From 7ee2d66eaa37a8131f6f8264f7b184bccc32f4f8 Mon Sep 17 00:00:00 2001 From: ljx0305 Date: Thu, 19 Oct 2023 17:55:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=BB=A3=E7=A0=81=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E9=A3=8E=E6=A0=BC=20(#2910)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit openRtpServer时,如果开启tcp模式,从tcp端口池获取 --- .github/workflows/c-cpp.yml | 34 ++++++++++++++++++++++++++++++++++ server/WebHook.cpp | 4 ++-- src/Common/config.cpp | 2 +- src/Common/config.h | 2 +- src/Http/HttpSession.cpp | 12 ++++++------ src/Http/HttpSession.h | 2 +- src/Rtp/RtpServer.cpp | 4 ++-- 7 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/c-cpp.yml diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml new file mode 100644 index 00000000..4418c935 --- /dev/null +++ b/.github/workflows/c-cpp.yml @@ -0,0 +1,34 @@ +name: Linux + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v1 + + - name: 下载submodule源码 + run: mv -f .gitmodules_github .gitmodules && git submodule sync && git submodule update --init + + - name: apt-get安装依赖库(非必选) + run: sudo apt-get update && sudo apt-get install -y cmake libssl-dev libsdl-dev libavcodec-dev libavutil-dev libswscale-dev libresample-dev libusrsctp-dev + + - name: 下载 SRTP + uses: actions/checkout@v2 + with: + repository: cisco/libsrtp + fetch-depth: 1 + ref: v2.3.0 + path: 3rdpart/libsrtp + + - name: 编译 SRTP + run: cd 3rdpart/libsrtp && ./configure --enable-openssl && make -j4 && sudo make install + + - name: 编译 + run: mkdir -p linux_build && cd linux_build && cmake .. -DENABLE_WEBRTC=true -DENABLE_FFMPEG=true && make -j $(nproc) + + - name: 运行MediaServer + run: pwd && cd release/linux/Debug && sudo ./MediaServer -d & diff --git a/server/WebHook.cpp b/server/WebHook.cpp index d05c4f60..43329927 100755 --- a/server/WebHook.cpp +++ b/server/WebHook.cpp @@ -674,7 +674,7 @@ void installWebHook() { }); }); - NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::KBroadcastRtpServerTimeout, [](BroadcastRtpServerTimeoutArgs) { + NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::kBroadcastRtpServerTimeout, [](BroadcastRtpServerTimeoutArgs) { GET_CONFIG(string, rtp_server_timeout, Hook::kOnRtpServerTimeout); if (!hook_enable || rtp_server_timeout.empty()) { return; @@ -703,4 +703,4 @@ void unInstallWebHook() { void onProcessExited() { reportServerExited(); -} \ No newline at end of file +} diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 6e75e27d..603c434c 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -57,7 +57,7 @@ const string kBroadcastNotFoundStream = "kBroadcastNotFoundStream"; const string kBroadcastStreamNoneReader = "kBroadcastStreamNoneReader"; const string kBroadcastHttpBeforeAccess = "kBroadcastHttpBeforeAccess"; const string kBroadcastSendRtpStopped = "kBroadcastSendRtpStopped"; -const string KBroadcastRtpServerTimeout = "KBroadcastRtpServerTimeout"; +const string kBroadcastRtpServerTimeout = "kBroadcastRtpServerTimeout"; } // namespace Broadcast diff --git a/src/Common/config.h b/src/Common/config.h index 341f1d6c..25f36271 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -106,7 +106,7 @@ extern const std::string kBroadcastReloadConfig; #define BroadcastReloadConfigArgs void // rtp server 超时 -extern const std::string KBroadcastRtpServerTimeout; +extern const std::string kBroadcastRtpServerTimeout; #define BroadcastRtpServerTimeoutArgs uint16_t &local_port, const string &stream_id,int &tcp_mode, bool &re_use_port, uint32_t &ssrc #define ReloadConfigTag ((void *)(0xFF)) diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 69407928..c6d390d1 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -166,11 +166,11 @@ void HttpSession::onError(const SockException &err) { if (_is_live_stream) { // flv/ts播放器 uint64_t duration = _ticker.createdTime() / 1000; - WarnP(this) << "FLV/TS/FMP4播放器(" << _mediaInfo.shortUrl() << ")断开:" << err << ",耗时(s):" << duration; + WarnP(this) << "FLV/TS/FMP4播放器(" << _media_info.shortUrl() << ")断开:" << err << ",耗时(s):" << duration; GET_CONFIG(uint32_t, iFlowThreshold, General::kFlowThreshold); if (_total_bytes_usage >= iFlowThreshold * 1024) { - NOTICE_EMIT(BroadcastFlowReportArgs, Broadcast::kBroadcastFlowReport, _mediaInfo, _total_bytes_usage, duration, true, *this); + NOTICE_EMIT(BroadcastFlowReportArgs, Broadcast::kBroadcastFlowReport, _media_info, _total_bytes_usage, duration, true, *this); } return; } @@ -263,9 +263,9 @@ bool HttpSession::checkLiveStream(const string &schema, const string &url_suffix } // 解析带上协议+参数完整的url - _mediaInfo.parse(schema + "://" + _parser["Host"] + url); + _media_info.parse(schema + "://" + _parser["Host"] + url); - if (_mediaInfo.app.empty() || _mediaInfo.stream.empty()) { + if (_media_info.app.empty() || _media_info.stream.empty()) { // url不合法 return false; } @@ -288,7 +288,7 @@ bool HttpSession::checkLiveStream(const string &schema, const string &url_suffix } // 异步查找直播流 - MediaSource::findAsync(strong_self->_mediaInfo, strong_self, [weak_self, close_flag, cb](const MediaSource::Ptr &src) { + MediaSource::findAsync(strong_self->_media_info, strong_self, [weak_self, close_flag, cb](const MediaSource::Ptr &src) { auto strong_self = weak_self.lock(); if (!strong_self) { // 本对象已经销毁 @@ -311,7 +311,7 @@ bool HttpSession::checkLiveStream(const string &schema, const string &url_suffix } }; - auto flag = NOTICE_EMIT(BroadcastMediaPlayedArgs, Broadcast::kBroadcastMediaPlayed, _mediaInfo, invoker, *this); + auto flag = NOTICE_EMIT(BroadcastMediaPlayedArgs, Broadcast::kBroadcastMediaPlayed, _media_info, invoker, *this); if (!flag) { // 该事件无人监听,默认不鉴权 onRes(""); diff --git a/src/Http/HttpSession.h b/src/Http/HttpSession.h index 513f8b63..98b43d71 100644 --- a/src/Http/HttpSession.h +++ b/src/Http/HttpSession.h @@ -124,7 +124,7 @@ private: void setSocketFlags(); protected: - MediaInfo _mediaInfo; + MediaInfo _media_info; private: bool _is_live_stream = false; diff --git a/src/Rtp/RtpServer.cpp b/src/Rtp/RtpServer.cpp index 78aee8e1..e40eeda7 100644 --- a/src/Rtp/RtpServer.cpp +++ b/src/Rtp/RtpServer.cpp @@ -102,7 +102,7 @@ public: process->setOnDetach(std::move(strong_self->_on_detach)); } if (!process) { // process 未创建,触发rtp server 超时事件 - NOTICE_EMIT(BroadcastRtpServerTimeoutArgs, Broadcast::KBroadcastRtpServerTimeout, strong_self->_local_port, strong_self->_stream_id, + NOTICE_EMIT(BroadcastRtpServerTimeoutArgs, Broadcast::kBroadcastRtpServerTimeout, strong_self->_local_port, strong_self->_stream_id, (int)strong_self->_tcp_mode, strong_self->_re_use_port, strong_self->_ssrc); } } @@ -161,7 +161,7 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, TcpMode tcp_ if (local_port == 0) { //随机端口,rtp端口采用偶数 auto pair = std::make_pair(rtp_socket, rtcp_socket); - makeSockPair(pair, local_ip, re_use_port); + makeSockPair(pair, local_ip, re_use_port, TcpMode::NONE == tcp_mode); local_port = rtp_socket->get_local_port(); } else if (!rtp_socket->bindUdpSock(local_port, local_ip, re_use_port)) { //用户指定端口