From 5a717186ddda0a96a060eb583230ba1d9093bc8f Mon Sep 17 00:00:00 2001 From: Lidaofu <746101210@qq.com> Date: Fri, 28 Jun 2024 12:43:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=8B=89=E6=B5=81?= =?UTF-8?q?=E4=BB=A3=E7=90=86rtsp=E6=97=B6=E6=8F=90=E4=BE=9B=E5=80=8D?= =?UTF-8?q?=E9=80=9F=E5=8A=9F=E8=83=BD=E6=94=AF=E6=8C=81=20(#3669)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: lidaofu --- api/include/mk_proxyplayer.h | 2 +- src/Common/config.cpp | 1 + src/Common/config.h | 2 ++ src/Rtsp/RtspPlayer.cpp | 11 ++++++++++- src/Rtsp/RtspPlayer.h | 2 ++ 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/api/include/mk_proxyplayer.h b/api/include/mk_proxyplayer.h index bbd4d14c..4bd20333 100644 --- a/api/include/mk_proxyplayer.h +++ b/api/include/mk_proxyplayer.h @@ -79,7 +79,7 @@ API_EXPORT void API_CALL mk_proxy_player_release(mk_proxy_player ctx); /** * 设置代理播放器配置选项 * @param ctx 代理播放器指针 - * @param key 配置项键,支持 net_adapter/rtp_type/rtsp_user/rtsp_pwd/protocol_timeout_ms/media_timeout_ms/beat_interval_ms + * @param key 配置项键,支持 net_adapter/rtp_type/rtsp_user/rtsp_pwd/protocol_timeout_ms/media_timeout_ms/beat_interval_ms/rtsp_speed * @param val 配置项值,如果是整形,需要转换成统一转换成string */ API_EXPORT void API_CALL mk_proxy_player_set_option(mk_proxy_player ctx, const char *key, const char *val); diff --git a/src/Common/config.cpp b/src/Common/config.cpp index f2ec0354..3c10404d 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -375,6 +375,7 @@ const string kBenchmarkMode = "benchmark_mode"; const string kWaitTrackReady = "wait_track_ready"; const string kPlayTrack = "play_track"; const string kProxyUrl = "proxy_url"; +const string kRtspSpeed = "rtsp_speed"; } // namespace Client } // namespace mediakit diff --git a/src/Common/config.h b/src/Common/config.h index 4b6423a5..3a4f6d58 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -447,6 +447,8 @@ extern const std::string kWaitTrackReady; extern const std::string kPlayTrack; //设置代理url,目前只支持http协议 extern const std::string kProxyUrl; +//设置开始rtsp倍速播放 +extern const std::string kRtspSpeed; } // namespace Client } // namespace mediakit diff --git a/src/Rtsp/RtspPlayer.cpp b/src/Rtsp/RtspPlayer.cpp index 5d279fd7..2ba0a2a7 100644 --- a/src/Rtsp/RtspPlayer.cpp +++ b/src/Rtsp/RtspPlayer.cpp @@ -88,6 +88,7 @@ void RtspPlayer::play(const string &strUrl) { _rtp_type = (Rtsp::eRtpType)(int)(*this)[Client::kRtpType]; _beat_type = (*this)[Client::kRtspBeatType].as(); _beat_interval_ms = (*this)[Client::kBeatIntervalMS].as(); + _speed = (*this)[Client::kRtspSpeed].as(); DebugL << url._url << " " << (url._user.size() ? url._user : "null") << " " << (url._passwd.size() ? url._passwd : "null") << " " << _rtp_type; weak_ptr weakSelf = static_pointer_cast(shared_from_this()); @@ -387,7 +388,12 @@ void RtspPlayer::handleResSETUP(const Parser &parser, unsigned int track_idx) { } // 所有setup命令发送完毕 // 发送play命令 - sendPause(type_play, 0); + if (_speed==0.0f) { + sendPause(type_play, 0); + } else { + sendPause(type_speed, 0); + } + } void RtspPlayer::sendDescribe() { @@ -436,6 +442,9 @@ void RtspPlayer::sendPause(int type, uint32_t seekMS) { case type_seek: sendRtspRequest("PLAY", _control_url, { "Range", StrPrinter << "npt=" << setiosflags(ios::fixed) << setprecision(2) << seekMS / 1000.0 << "-" }); break; + case type_speed: + speed(_speed); + break; default: WarnL << "unknown type : " << type; _on_response = nullptr; diff --git a/src/Rtsp/RtspPlayer.h b/src/Rtsp/RtspPlayer.h index c40d72b7..cdc6dfb2 100644 --- a/src/Rtsp/RtspPlayer.h +++ b/src/Rtsp/RtspPlayer.h @@ -120,6 +120,8 @@ private: uint32_t _beat_interval_ms = 0; std::string _play_url; + // rtsp开始倍速 + float _speed= 0.0f; std::vector _sdp_track; std::function _on_response; //RTP端口,trackid idx 为数组下标