修复时间戳相关的bug

This commit is contained in:
xiongziliang 2018-10-26 14:48:09 +08:00
parent 620e180a49
commit 52f0d89d7a
6 changed files with 9 additions and 24 deletions

View File

@ -274,7 +274,7 @@ inline MP4SampleId MediaReader::getAudioSampleId(int iTimeInc) {
audio_current = MAX(0,MIN(_audio_num_samples,audio_current));
return audio_current;
}
inline void MediaReader::setSeekTime(int iSeekTime){
inline void MediaReader::setSeekTime(uint32_t iSeekTime){
_iSeekTime = MAX(0, MIN(iSeekTime,_iDuration));
_ticker.resetTime();
if (_audio_trId != MP4_INVALID_TRACK_ID) {
@ -288,7 +288,7 @@ inline void MediaReader::setSeekTime(int iSeekTime){
inline uint32_t MediaReader::getVideoCurrentTime(){
return (double)_video_current * _video_ms /_video_num_samples;
}
void MediaReader::seek(int iSeekTime,bool bReStart){
void MediaReader::seek(uint32_t iSeekTime,bool bReStart){
lock_guard<recursive_mutex> lck(_mtx);
if(iSeekTime == 0 || _video_trId == MP4_INVALID_TRACK_ID){
setSeekTime(iSeekTime);

View File

@ -83,8 +83,8 @@ private:
Ticker _alive;
recursive_mutex _mtx;
void seek(int iSeekTime,bool bReStart = true);
inline void setSeekTime(int iSeekTime);
void seek(uint32_t iSeekTime,bool bReStart = true);
inline void setSeekTime(uint32_t iSeekTime);
inline uint32_t getVideoCurrentTime();
void startReadMP4();
inline MP4SampleId getVideoSampleId(int iTimeInc = 0);

View File

@ -339,7 +339,7 @@ void RtmpPlayer::seekToMilliSecond(uint32_t seekMS){
//TraceL << "seek result";
_aNowStampTicker[0].resetTime();
_aNowStampTicker[1].resetTime();
auto iTimeInc = seekMS - getProgressMilliSecond();
int iTimeInc = seekMS - getProgressMilliSecond();
for(auto i = 0 ;i < 2 ;i++){
_aiFistStamp[i] = _aiNowStamp[i] + iTimeInc;
_aiNowStamp[i] = _aiFistStamp[i];

View File

@ -435,7 +435,7 @@ bool RtspPlayer::sendPause(bool bPause,uint32_t seekMS){
//修改时间轴
_aNowStampTicker[0].resetTime();
_aNowStampTicker[1].resetTime();
auto iTimeInc = seekMS - getProgressMilliSecond();
int iTimeInc = seekMS - getProgressMilliSecond();
for(unsigned int i = 0 ;i < _aTrackInfo.size() ;i++){
_aiFistStamp[i] = _aiNowStamp[i] + iTimeInc;
_aiNowStamp[i] = _aiFistStamp[i];

View File

@ -720,9 +720,9 @@ bool RtspSession::handleReq_Play() {
if (strStart == "now") {
strStart = "0";
}
auto iStartTime = atof(strStart.data());
InfoL << "rtsp seekTo:" << iStartTime;
pMediaSrc->seekTo(iStartTime * 1000);
auto iStartTime = 1000 * atof(strStart.data());
InfoL << "rtsp seekTo(ms):" << iStartTime;
pMediaSrc->seekTo(iStartTime);
iStamp = pMediaSrc->getStamp();
}else if(pMediaSrc->getRing()->readerCount() == 1){
//第一个消费者

View File

@ -35,21 +35,6 @@ using namespace std;
namespace mediakit {
static int getTimeInSDP(const string &sdp) {
auto strRange = FindField(sdp.data(), "a=range:npt=", "\r\n");
strRange.append(" ");
auto iPos = strRange.find('-');
if (iPos == string::npos) {
return 0;
}
auto strStart = strRange.substr(0, iPos);
auto strEnd = strRange.substr(iPos + 1);
strEnd.pop_back();
if (strStart == "now") {
strStart = "0";
}
return atof(strEnd.data()) - atof(strStart.data());
}
RtspDemuxer::RtspDemuxer(const string& sdp) {
loadSdp(SdpAttr(sdp));
}