Commit 6870292f by xiongziliang

完善seek相关的逻辑

parent 52f0d89d
...@@ -54,11 +54,7 @@ public: ...@@ -54,11 +54,7 @@ public:
//拖动进度条 //拖动进度条
return false; return false;
} }
virtual uint32_t getStamp() { virtual bool close() {
//获取时间戳
return 0;
}
virtual bool shutDown() {
//通知其停止推流 //通知其停止推流
return false; return false;
} }
...@@ -143,19 +139,14 @@ public: ...@@ -143,19 +139,14 @@ public:
return listener->seekTo(ui32Stamp); return listener->seekTo(ui32Stamp);
} }
uint32_t getStamp() { virtual uint32_t getTimeStamp(TrackType trackType) = 0;
auto listener = _listener.lock();
if(!listener){ bool close() {
return 0;
}
return listener->getStamp();
}
bool shutDown() {
auto listener = _listener.lock(); auto listener = _listener.lock();
if(!listener){ if(!listener){
return false; return false;
} }
return listener->shutDown(); return listener->close();
} }
void setListener(const std::weak_ptr<MediaSourceEvent> &listener){ void setListener(const std::weak_ptr<MediaSourceEvent> &listener){
_listener = listener; _listener = listener;
......
...@@ -192,7 +192,7 @@ void PlayerProxy::initMedia() { ...@@ -192,7 +192,7 @@ void PlayerProxy::initMedia() {
// _pChn->initAudio(info); // _pChn->initAudio(info);
// } // }
} }
bool PlayerProxy::shutDown() { bool PlayerProxy::close() {
//通知其停止推流 //通知其停止推流
weak_ptr<PlayerProxy> weakSlef = dynamic_pointer_cast<PlayerProxy>(shared_from_this()); weak_ptr<PlayerProxy> weakSlef = dynamic_pointer_cast<PlayerProxy>(shared_from_this());
auto executor = getExecutor(); auto executor = getExecutor();
......
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
virtual ~PlayerProxy(); virtual ~PlayerProxy();
void play(const char* strUrl) override; void play(const char* strUrl) override;
bool shutDown() override; bool close() override;
private: private:
void initMedia(); void initMedia();
void rePlay(const string &strUrl,int iFailedCnt); void rePlay(const string &strUrl,int iFailedCnt);
......
...@@ -177,10 +177,7 @@ void MediaReader::startReadMP4() { ...@@ -177,10 +177,7 @@ void MediaReader::startReadMP4() {
seek(ui32Stamp); seek(ui32Stamp);
return true; return true;
} }
uint32_t MediaReader::getStamp() { bool MediaReader::close(){
return _iSeekTime + _ticker.elapsedTime();
}
bool MediaReader::shutDown(){
AsyncTaskThread::Instance().CancelTask(reinterpret_cast<uint64_t>(this)); AsyncTaskThread::Instance().CancelTask(reinterpret_cast<uint64_t>(this));
return true; return true;
} }
......
...@@ -46,8 +46,7 @@ public: ...@@ -46,8 +46,7 @@ public:
static MediaSource::Ptr onMakeMediaSource(const string &strSchema,const string &strVhost,const string &strApp, const string &strId); static MediaSource::Ptr onMakeMediaSource(const string &strSchema,const string &strVhost,const string &strApp, const string &strId);
public: public:
bool seekTo(uint32_t ui32Stamp) override; bool seekTo(uint32_t ui32Stamp) override;
uint32_t getStamp() override; bool close() override;
bool shutDown() override;
private: private:
#ifdef ENABLE_MP4V2 #ifdef ENABLE_MP4V2
......
...@@ -93,7 +93,7 @@ public: ...@@ -93,7 +93,7 @@ public:
void onWrite(const RtmpPacket::Ptr &pkt,bool isKey = true) override { void onWrite(const RtmpPacket::Ptr &pkt,bool isKey = true) override {
lock_guard<recursive_mutex> lock(_mtxMap); lock_guard<recursive_mutex> lock(_mtxMap);
if (pkt->isCfgFrame()) { if (pkt->isCfgFrame()) {
_mapCfgFrame.emplace(pkt->typeId, pkt); _mapCfgFrame[pkt->typeId] = pkt;
if(_bAsyncRegist && !_bRegisted && _mapCfgFrame.size() == _iCfgFrameSize){ if(_bAsyncRegist && !_bRegisted && _mapCfgFrame.size() == _iCfgFrameSize){
_bAsyncRegist = false; _bAsyncRegist = false;
...@@ -101,9 +101,21 @@ public: ...@@ -101,9 +101,21 @@ public:
_bRegisted = true; _bRegisted = true;
} }
} }
_mapStamp[pkt->typeId] = pkt->timeStamp;
_pRing->write(pkt,pkt->isVideoKeyFrame()); _pRing->write(pkt,pkt->isVideoKeyFrame());
} }
uint32_t getTimeStamp(TrackType trackType) override {
lock_guard<recursive_mutex> lock(_mtxMap);
switch (trackType){
case TrackVideo:
return _mapStamp[MSG_VIDEO];
case TrackAudio:
return _mapStamp[MSG_AUDIO];
default:
return MAX(_mapStamp[MSG_VIDEO],_mapStamp[MSG_AUDIO]);
}
}
private: private:
bool ready(){ bool ready(){
lock_guard<recursive_mutex> lock(_mtxMap); lock_guard<recursive_mutex> lock(_mtxMap);
...@@ -111,7 +123,8 @@ private: ...@@ -111,7 +123,8 @@ private:
} }
protected: protected:
AMFValue _metadata; AMFValue _metadata;
unordered_map<int, RtmpPacket::Ptr> _mapCfgFrame; map<int, RtmpPacket::Ptr> _mapCfgFrame;
map<int,uint32_t> _mapStamp;
mutable recursive_mutex _mtxMap; mutable recursive_mutex _mtxMap;
RingBuffer<RtmpPacket::Ptr>::Ptr _pRing; //rtp环形缓冲 RingBuffer<RtmpPacket::Ptr>::Ptr _pRing; //rtp环形缓冲
int _iCfgFrameSize = -1; int _iCfgFrameSize = -1;
......
...@@ -79,7 +79,7 @@ private: ...@@ -79,7 +79,7 @@ private:
sendResponse(MSG_CMD, invoke.data()); sendResponse(MSG_CMD, invoke.data());
} }
bool shutDown() override { bool close() override {
InfoL << "kick out:" << _mediaInfo._vhost << " " << _mediaInfo._app << " " << _mediaInfo._streamid; InfoL << "kick out:" << _mediaInfo._vhost << " " << _mediaInfo._app << " " << _mediaInfo._streamid;
safeShutdown(); safeShutdown();
return true; return true;
......
...@@ -84,12 +84,18 @@ public: ...@@ -84,12 +84,18 @@ public:
} }
return track->_seq; return track->_seq;
} }
virtual uint32_t getTimeStamp(TrackType trackType) {
uint32_t getTimeStamp(TrackType trackType) override {
auto track = _sdpAttr.getTrack(trackType); auto track = _sdpAttr.getTrack(trackType);
if(!track){ if(track) {
return 0; return track->_time_stamp;
}
auto tracks = _sdpAttr.getAvailableTrack();
switch (tracks.size()){
case 0: return 0;
case 1: return tracks[0]->_time_stamp;
default:return MAX(tracks[0]->_time_stamp,tracks[1]->_time_stamp);
} }
return track->_time_stamp;
} }
virtual void setTimeStamp(uint32_t uiStamp) { virtual void setTimeStamp(uint32_t uiStamp) {
......
...@@ -723,13 +723,13 @@ bool RtspSession::handleReq_Play() { ...@@ -723,13 +723,13 @@ bool RtspSession::handleReq_Play() {
auto iStartTime = 1000 * atof(strStart.data()); auto iStartTime = 1000 * atof(strStart.data());
InfoL << "rtsp seekTo(ms):" << iStartTime; InfoL << "rtsp seekTo(ms):" << iStartTime;
pMediaSrc->seekTo(iStartTime); pMediaSrc->seekTo(iStartTime);
iStamp = pMediaSrc->getStamp(); iStamp = pMediaSrc->getTimeStamp(TrackInvalid);
}else if(pMediaSrc->getRing()->readerCount() == 1){ }else if(pMediaSrc->getRing()->readerCount() == 1){
//第一个消费者 //第一个消费者
pMediaSrc->seekTo(0); pMediaSrc->seekTo(0);
iStamp = 0; iStamp = 0;
}else{ }else{
iStamp = pMediaSrc->getStamp(); iStamp = pMediaSrc->getTimeStamp(TrackInvalid);
} }
for(auto &track : _aTrackInfo){ for(auto &track : _aTrackInfo){
......
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
if(!media) { if(!media) {
break; break;
} }
if(!media->shutDown()) { if(!media->close()) {
break; break;
} }
(*stream) << "\t踢出成功:" (*stream) << "\t踢出成功:"
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论