mirror of
https://gitee.com/xia-chu/ZLMediaKit.git
synced 2026-05-21 17:17:49 +08:00
优化rtsp客户端对点播的支持 (#4575 #4569 #4576)
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
Linux / build (push) Has been cancelled
macOS / build (push) Has been cancelled
Windows / build (push) Has been cancelled
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
Linux / build (push) Has been cancelled
macOS / build (push) Has been cancelled
Windows / build (push) Has been cancelled
Co-authored-by: xia-chu <771730766@qq.com>
This commit is contained in:
parent
1892185b23
commit
8c94395710
@ -464,7 +464,7 @@ void RtspPlayer::sendPause(int type, uint32_t seekMS) {
|
|||||||
// Start or pause RTSP
|
// Start or pause RTSP
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case type_pause: sendRtspRequest("PAUSE", _control_url, {}); break;
|
case type_pause: sendRtspRequest("PAUSE", _control_url, {}); break;
|
||||||
case type_play: sendRtspRequest("PLAY", _content_base); break;
|
case type_play:
|
||||||
case type_seek:
|
case type_seek:
|
||||||
sendRtspRequest("PLAY", _control_url, { "Range", StrPrinter << "npt=" << setiosflags(ios::fixed) << setprecision(2) << seekMS / 1000.0 << "-" });
|
sendRtspRequest("PLAY", _control_url, { "Range", StrPrinter << "npt=" << setiosflags(ios::fixed) << setprecision(2) << seekMS / 1000.0 << "-" });
|
||||||
break;
|
break;
|
||||||
@ -582,6 +582,9 @@ void RtspPlayer::onRtcpPacket(int track_idx, SdpTrack::Ptr &track, uint8_t *data
|
|||||||
|
|
||||||
void RtspPlayer::onRtpSorted(RtpPacket::Ptr rtppt, int trackidx) {
|
void RtspPlayer::onRtpSorted(RtpPacket::Ptr rtppt, int trackidx) {
|
||||||
_stamp[trackidx] = rtppt->getStampMS();
|
_stamp[trackidx] = rtppt->getStampMS();
|
||||||
|
if (!_first_stamp[trackidx]) {
|
||||||
|
_first_stamp[trackidx] = _stamp[trackidx];
|
||||||
|
}
|
||||||
_rtp_recv_ticker.resetTime();
|
_rtp_recv_ticker.resetTime();
|
||||||
onRecvRTP(std::move(rtppt), _sdp_track[trackidx]);
|
onRecvRTP(std::move(rtppt), _sdp_track[trackidx]);
|
||||||
}
|
}
|
||||||
@ -609,7 +612,7 @@ float RtspPlayer::getPacketLossRate(TrackType type) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RtspPlayer::getProgressMilliSecond() const {
|
uint32_t RtspPlayer::getProgressMilliSecond() const {
|
||||||
return MAX(_stamp[0], _stamp[1]);
|
return MAX(_stamp[0] - _first_stamp[0], _stamp[1] - _first_stamp[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtspPlayer::seekToMilliSecond(uint32_t ms) {
|
void RtspPlayer::seekToMilliSecond(uint32_t ms) {
|
||||||
@ -685,14 +688,18 @@ void RtspPlayer::sendRtspRequest(const string &cmd, const string &url, const Str
|
|||||||
printer << cmd << " " << url << " RTSP/1.0\r\n";
|
printer << cmd << " " << url << " RTSP/1.0\r\n";
|
||||||
|
|
||||||
TraceL << cmd << " "<< url;
|
TraceL << cmd << " "<< url;
|
||||||
|
|
||||||
|
if (cmd == "PLAY") {
|
||||||
|
// play命令时支持覆盖更新rtsp头,用于onvif点播等场景
|
||||||
|
for (auto &pr : _custom_header) {
|
||||||
|
header[pr.first] = pr.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (auto &pr : header) {
|
for (auto &pr : header) {
|
||||||
printer << pr.first << ": " << pr.second << "\r\n";
|
printer << pr.first << ": " << pr.second << "\r\n";
|
||||||
}
|
}
|
||||||
if (cmd == "PLAY") {
|
|
||||||
for (auto &pr : _custom_header) {
|
|
||||||
printer << pr.first << ": " << pr.second << "\r\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printer << "\r\n";
|
printer << "\r\n";
|
||||||
SockSender::send(std::move(printer));
|
SockSender::send(std::move(printer));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -184,9 +184,12 @@ protected:
|
|||||||
Rtsp::eRtpType _rtp_type = Rtsp::RTP_TCP;
|
Rtsp::eRtpType _rtp_type = Rtsp::RTP_TCP;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// 起始时间戳
|
||||||
|
uint64_t _first_stamp[2] = {0, 0};
|
||||||
|
|
||||||
// 当前rtp时间戳 [AUTO-TRANSLATED:410f2691]
|
// 当前rtp时间戳 [AUTO-TRANSLATED:410f2691]
|
||||||
// Current rtp timestamp
|
// Current rtp timestamp
|
||||||
uint32_t _stamp[2] = {0, 0};
|
uint64_t _stamp[2] = {0, 0};
|
||||||
|
|
||||||
// 超时功能实现 [AUTO-TRANSLATED:1d603b3a]
|
// 超时功能实现 [AUTO-TRANSLATED:1d603b3a]
|
||||||
// Timeout function implementation
|
// Timeout function implementation
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user