mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-04 01:37:33 +08:00
完善主动关断流机制
This commit is contained in:
@@ -79,6 +79,11 @@ PlayerProxy::PlayerProxy(const string &strVhost,
|
||||
void PlayerProxy::setPlayCallbackOnce(const function<void(const SockException &ex)> &cb){
|
||||
_playCB = cb;
|
||||
}
|
||||
|
||||
void PlayerProxy::setOnClose(const function<void()> &cb){
|
||||
_onClose = cb;
|
||||
}
|
||||
|
||||
void PlayerProxy::play(const string &strUrlTmp) {
|
||||
weak_ptr<PlayerProxy> weakSelf = shared_from_this();
|
||||
std::shared_ptr<int> piFailedCnt(new int(0)); //连续播放失败次数
|
||||
@@ -148,6 +153,9 @@ bool PlayerProxy::close() {
|
||||
if (stronSelf) {
|
||||
stronSelf->_mediaMuxer.reset();
|
||||
stronSelf->teardown();
|
||||
if(stronSelf->_onClose){
|
||||
stronSelf->_onClose();
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
|
||||
@@ -62,8 +62,23 @@ public:
|
||||
*/
|
||||
void setPlayCallbackOnce(const function<void(const SockException &ex)> &cb);
|
||||
|
||||
void play(const string &strUrl) override;
|
||||
/**
|
||||
* 设置主动关闭回调
|
||||
* @param cb
|
||||
*/
|
||||
void setOnClose(const function<void()> &cb);
|
||||
|
||||
/**
|
||||
* 开始拉流播放
|
||||
* @param strUrl
|
||||
*/
|
||||
void play(const string &strUrl) override;
|
||||
|
||||
|
||||
/**
|
||||
* 被主动关闭
|
||||
* @return
|
||||
*/
|
||||
bool close() override;
|
||||
private:
|
||||
void rePlay(const string &strUrl,int iFailedCnt);
|
||||
@@ -78,6 +93,7 @@ private:
|
||||
string _strSrc;
|
||||
Timer::Ptr _timer;
|
||||
function<void(const SockException &ex)> _playCB;
|
||||
function<void()> _onClose;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
Reference in New Issue
Block a user