Commit 6870292f by xiongziliang

完善seek相关的逻辑

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