From 0fc1499643de28fffef2f5d68caf4a798345deef Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Wed, 8 Apr 2020 11:16:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=80=A7=E8=83=BD=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/config.cpp | 2 ++ src/Common/config.h | 2 ++ src/Rtmp/RtmpPlayer.cpp | 7 +++++++ src/Rtmp/RtmpPlayer.h | 2 ++ src/Rtsp/RtspPlayer.cpp | 7 +++++++ src/Rtsp/RtspPlayer.h | 2 ++ tests/test_benchmark.cpp | 1 + 7 files changed, 23 insertions(+) diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 4b6b5680..332554a0 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -286,6 +286,8 @@ const string kTimeoutMS = "protocol_timeout_ms"; const string kMediaTimeoutMS = "media_timeout_ms"; const string kBeatIntervalMS = "beat_interval_ms"; const string kMaxAnalysisMS = "max_analysis_ms"; +const string kBenchmarkMode = "benchmark_mode"; + } } // namespace mediakit diff --git a/src/Common/config.h b/src/Common/config.h index 77bd6b1c..b58e3a99 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -315,6 +315,8 @@ extern const string kMediaTimeoutMS; extern const string kBeatIntervalMS; //Track编码格式探测最大时间,单位毫秒,默认2000 extern const string kMaxAnalysisMS; +//是否为性能测试模式,性能测试模式开启后不会解析rtp或rtmp包 +extern const string kBenchmarkMode; } } // namespace mediakit diff --git a/src/Rtmp/RtmpPlayer.cpp b/src/Rtmp/RtmpPlayer.cpp index 54f1e106..09556454 100644 --- a/src/Rtmp/RtmpPlayer.cpp +++ b/src/Rtmp/RtmpPlayer.cpp @@ -118,6 +118,8 @@ void RtmpPlayer::onPlayResult_l(const SockException &ex , bool handshakeComplete //开始播放阶段 _pPlayTimer.reset(); onPlayResult(ex); + //是否为性能测试模式 + _benchmark_mode = (*this)[Client::kBenchmarkMode].as(); } else if (ex) { //播放成功后异常断开回调 onShutdown(ex); @@ -146,6 +148,11 @@ void RtmpPlayer::onConnect(const SockException &err){ } void RtmpPlayer::onRecv(const Buffer::Ptr &pBuf){ try { + if(_benchmark_mode && !_pPlayTimer){ + //在性能测试模式下,如果rtmp握手完毕后,不再解析rtmp包 + _mediaTicker.resetTime(); + return; + } onParseRtmp(pBuf->data(), pBuf->size()); } catch (exception &e) { SockException ex(Err_other, e.what()); diff --git a/src/Rtmp/RtmpPlayer.h b/src/Rtmp/RtmpPlayer.h index d3f61fc6..9b7f1b66 100644 --- a/src/Rtmp/RtmpPlayer.h +++ b/src/Rtmp/RtmpPlayer.h @@ -102,6 +102,8 @@ private: uint32_t _aiNowStamp[2] = { 0, 0 }; Ticker _aNowStampTicker[2]; bool _metadata_got = false; + //是否为性能测试模式 + bool _benchmark_mode = false; }; } /* namespace mediakit */ diff --git a/src/Rtsp/RtspPlayer.cpp b/src/Rtsp/RtspPlayer.cpp index e96c3d1f..4b79d93d 100644 --- a/src/Rtsp/RtspPlayer.cpp +++ b/src/Rtsp/RtspPlayer.cpp @@ -112,6 +112,11 @@ void RtspPlayer::onConnect(const SockException &err){ } void RtspPlayer::onRecv(const Buffer::Ptr& pBuf) { + if(_benchmark_mode && !_pPlayTimer){ + //在性能测试模式下,如果rtsp握手完毕后,不再解析rtp包 + _rtpTicker.resetTime(); + return; + } input(pBuf->data(),pBuf->size()); } void RtspPlayer::onErr(const SockException &ex) { @@ -750,6 +755,8 @@ void RtspPlayer::onPlayResult_l(const SockException &ex , bool handshakeComplete //开始播放阶段 _pPlayTimer.reset(); onPlayResult(ex); + //是否为性能测试模式 + _benchmark_mode = (*this)[Client::kBenchmarkMode].as(); } else if (ex) { //播放成功后异常断开回调 onShutdown(ex); diff --git a/src/Rtsp/RtspPlayer.h b/src/Rtsp/RtspPlayer.h index 4a094e4e..e2830799 100644 --- a/src/Rtsp/RtspPlayer.h +++ b/src/Rtsp/RtspPlayer.h @@ -139,6 +139,8 @@ private: //是否为rtsp点播 bool _is_play_back; + //是否为性能测试模式 + bool _benchmark_mode = false; }; } /* namespace mediakit */ diff --git a/tests/test_benchmark.cpp b/tests/test_benchmark.cpp index 3dd65944..a3214bc8 100644 --- a/tests/test_benchmark.cpp +++ b/tests/test_benchmark.cpp @@ -55,6 +55,7 @@ int main(int argc, char *argv[]) { player->setOnShutdown([&](const SockException &ex) { --alivePlayerCnt; }); + (*player)[kBenchmarkMode] = true; (*player)[kRtpType] = atoi(argv[4]); player->play(argv[3]); playerList.push_back(player);