动态代理拉流等待拉流结果

This commit is contained in:
xiongziliang
2019-05-20 18:08:55 +08:00
parent fbead02868
commit ce7a0223f1
3 changed files with 32 additions and 6 deletions

View File

@@ -75,6 +75,10 @@ PlayerProxy::PlayerProxy(const string &strVhost,
_bEnableMp4 = bEnableMp4;
_iRetryCount = iRetryCount;
}
void PlayerProxy::setPlayCallbackOnce(const function<void(const SockException &ex)> &cb){
_playCB = cb;
}
void PlayerProxy::play(const string &strUrlTmp) {
weak_ptr<PlayerProxy> weakSelf = shared_from_this();
std::shared_ptr<int> piFailedCnt(new int(0)); //连续播放失败次数
@@ -83,6 +87,12 @@ void PlayerProxy::play(const string &strUrlTmp) {
if(!strongSelf) {
return;
}
if(strongSelf->_playCB) {
strongSelf->_playCB(err);
strongSelf->_playCB = nullptr;
}
if(!err) {
// 播放成功
*piFailedCnt = 0;//连续播放失败次数清0

View File

@@ -56,7 +56,14 @@ public:
virtual ~PlayerProxy();
/**
* 设置play结果回调只触发一次在play执行之前有效
* @param cb
*/
void setPlayCallbackOnce(const function<void(const SockException &ex)> &cb);
void play(const string &strUrl) override;
bool close() override;
private:
void rePlay(const string &strUrl,int iFailedCnt);
@@ -70,6 +77,7 @@ private:
string _strApp;
string _strSrc;
Timer::Ptr _timer;
function<void(const SockException &ex)> _playCB;
};
} /* namespace mediakit */