修复rtsp seek播放时rtsp server返回npt字段不对问题

This commit is contained in:
baiyfcu 2020-04-08 15:37:16 +08:00
parent f7fa4e6407
commit fb77293648
2 changed files with 23 additions and 20 deletions

View File

@ -743,22 +743,22 @@ void RtspSession::handleReq_Play(const Parser &parser) {
}
bool useBuf = true;
_enableSendRtp = false;
if (strRange.size() && !_bFirstPlay) {
_enableSendRtp = false;
float iStartTime = 0;
if (strRange.size() && !_bFirstPlay) {
//这个是seek操作
auto strStart = FindField(strRange.data(), "npt=", "-");
if (strStart == "now") {
strStart = "0";
}
auto iStartTime = 1000 * atof(strStart.data());
InfoP(this) << "rtsp seekTo(ms):" << iStartTime;
useBuf = !pMediaSrc->seekTo(iStartTime);
}else if(pMediaSrc->totalReaderCount() == 0){
//第一个消费者
pMediaSrc->seekTo(0);
}
_bFirstPlay = false;
auto strStart = FindField(strRange.data(), "npt=", "-");
if (strStart == "now") {
strStart = "0";
}
iStartTime = 1000 * atof(strStart.data());
InfoP(this) << "rtsp seekTo(ms):" << iStartTime;
useBuf = !pMediaSrc->seekTo(iStartTime);
}else if(pMediaSrc->totalReaderCount() == 0){
//第一个消费者
pMediaSrc->seekTo(0);
}
_bFirstPlay = false;
_StrPrinter rtp_info;
for(auto &track : _aTrackInfo){
@ -778,10 +778,10 @@ void RtspSession::handleReq_Play(const Parser &parser) {
rtp_info.pop_back();
sendRtspResponse("200 OK",
{"Range", StrPrinter << "npt=" << setiosflags(ios::fixed) << setprecision(2) << pMediaSrc->getTimeStamp(TrackInvalid) / 1000.0 << "-",
"RTP-Info",rtp_info
});
sendRtspResponse("200 OK",
{"Range", StrPrinter << "npt=" << setiosflags(ios::fixed) << setprecision(2) << /*pMediaSrc->getTimeStamp(TrackInvalid) / 1000.0*/iStartTime/1000,
"RTP-Info",rtp_info
});
_enableSendRtp = true;
setSocketFlags();

View File

@ -85,7 +85,10 @@ int main(int argc,char *argv[]) {
//此处选择是否导出调试文件
// mINI::Instance()[RtpProxy::kDumpDir] = "/Users/xzl/Desktop/";
loadFile(argv[1]);
if (argc == 2)
loadFile(argv[1]);
else
ErrorL << "parameter error.";
#else
ErrorL << "please ENABLE_RTPPROXY and then test";
#endif//#if defined(ENABLE_RTPPROXY)