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

View File

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