mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-14 12:05:58 +08:00
format code style for pusher and player
This commit is contained in:
@@ -16,7 +16,7 @@ using namespace std;
|
||||
namespace mediakit {
|
||||
|
||||
PusherProxy::PusherProxy(const MediaSource::Ptr &src, int retry_count, const EventPoller::Ptr &poller)
|
||||
: MediaPusher(src, poller){
|
||||
: MediaPusher(src, poller) {
|
||||
_retry_count = retry_count;
|
||||
_on_close = [](const SockException &) {};
|
||||
_weak_src = src;
|
||||
@@ -65,7 +65,7 @@ void PusherProxy::publish(const string &dst_url) {
|
||||
strong_self->_live_status = 1;
|
||||
strong_self->rePublish(dst_url, (*failed_cnt)++);
|
||||
} else {
|
||||
//如果媒体源已经注销, 或达到了最大重试次数,回调关闭
|
||||
// 如果媒体源已经注销, 或达到了最大重试次数,回调关闭
|
||||
strong_self->_on_close(err);
|
||||
}
|
||||
});
|
||||
@@ -76,20 +76,20 @@ void PusherProxy::publish(const string &dst_url) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(*failed_cnt == 0){
|
||||
if (*failed_cnt == 0) {
|
||||
// 第一次重推更新时长
|
||||
strong_self->_live_secs += strong_self->_live_ticker.elapsedTime()/1000;
|
||||
strong_self->_live_secs += strong_self->_live_ticker.elapsedTime() / 1000;
|
||||
strong_self->_live_ticker.resetTime();
|
||||
TraceL<<" live secs "<<strong_self->_live_secs;
|
||||
TraceL << " live secs " << strong_self->_live_secs;
|
||||
}
|
||||
|
||||
auto src = strong_self->_weak_src.lock();
|
||||
//推流异常中断,延时重试播放
|
||||
// 推流异常中断,延时重试播放
|
||||
if (src && (*failed_cnt < strong_self->_retry_count || strong_self->_retry_count < 0)) {
|
||||
strong_self->_republish_count++;
|
||||
strong_self->rePublish(dst_url, (*failed_cnt)++);
|
||||
} else {
|
||||
//如果媒体源已经注销, 或达到了最大重试次数,回调关闭
|
||||
// 如果媒体源已经注销, 或达到了最大重试次数,回调关闭
|
||||
strong_self->_on_close(err);
|
||||
}
|
||||
});
|
||||
@@ -100,30 +100,33 @@ void PusherProxy::publish(const string &dst_url) {
|
||||
void PusherProxy::rePublish(const string &dst_url, int failed_cnt) {
|
||||
auto delay = MAX(2 * 1000, MIN(failed_cnt * 3000, 60 * 1000));
|
||||
weak_ptr<PusherProxy> weak_self = shared_from_this();
|
||||
_timer = std::make_shared<Timer>(delay / 1000.0f, [weak_self, dst_url, failed_cnt]() {
|
||||
//推流失败次数越多,则延时越长
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
_timer = std::make_shared<Timer>(
|
||||
delay / 1000.0f,
|
||||
[weak_self, dst_url, failed_cnt]() {
|
||||
// 推流失败次数越多,则延时越长
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
return false;
|
||||
}
|
||||
WarnL << "推流重试[" << failed_cnt << "]:" << dst_url;
|
||||
strong_self->MediaPusher::publish(dst_url);
|
||||
return false;
|
||||
}
|
||||
WarnL << "推流重试[" << failed_cnt << "]:" << dst_url;
|
||||
strong_self->MediaPusher::publish(dst_url);
|
||||
return false;
|
||||
}, getPoller());
|
||||
},
|
||||
getPoller());
|
||||
}
|
||||
|
||||
int PusherProxy::getStatus() {
|
||||
return _live_status.load();
|
||||
}
|
||||
uint64_t PusherProxy::getLiveSecs() {
|
||||
if(_live_status == 0){
|
||||
return _live_secs + _live_ticker.elapsedTime()/1000;
|
||||
}else{
|
||||
if (_live_status == 0) {
|
||||
return _live_secs + _live_ticker.elapsedTime() / 1000;
|
||||
} else {
|
||||
return _live_secs;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t PusherProxy::getRePublishCount(){
|
||||
uint64_t PusherProxy::getRePublishCount() {
|
||||
return _republish_count;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user