format code style for pusher and player

This commit is contained in:
xiongguangjie 2023-05-03 21:46:25 +08:00
parent 7c89c1655f
commit ffed4b3bb2
4 changed files with 94 additions and 81 deletions

View File

@ -8,24 +8,26 @@
* may be found in the AUTHORS file in the root of the source tree.
*/
#include "Common/config.h"
#include "PlayerProxy.h"
#include "Util/mini.h"
#include "Util/MD5.h"
#include "Util/logger.h"
#include "Common/config.h"
#include "Extension/AAC.h"
#include "Rtmp/RtmpMediaSource.h"
#include "Rtsp/RtspMediaSource.h"
#include "Rtmp/RtmpPlayer.h"
#include "Rtsp/RtspMediaSource.h"
#include "Rtsp/RtspPlayer.h"
#include "Util/MD5.h"
#include "Util/logger.h"
#include "Util/mini.h"
using namespace toolkit;
using namespace std;
namespace mediakit {
PlayerProxy::PlayerProxy(const string &vhost, const string &app, const string &stream_id, const ProtocolOption &option,
int retry_count, const EventPoller::Ptr &poller) : MediaPlayer(poller) , _option(option) {
PlayerProxy::PlayerProxy(
const string &vhost, const string &app, const string &stream_id, const ProtocolOption &option, int retry_count, const EventPoller::Ptr &poller)
: MediaPlayer(poller)
, _option(option) {
_vhost = vhost;
_app = app;
_stream_id = stream_id;
@ -157,7 +159,9 @@ PlayerProxy::~PlayerProxy() {
void PlayerProxy::rePlay(const string &strUrl, int iFailedCnt) {
auto iDelay = MAX(2 * 1000, MIN(iFailedCnt * 3000, 60 * 1000));
weak_ptr<PlayerProxy> weakSelf = shared_from_this();
_timer = std::make_shared<Timer>(iDelay / 1000.0f, [weakSelf, strUrl, iFailedCnt]() {
_timer = std::make_shared<Timer>(
iDelay / 1000.0f,
[weakSelf, strUrl, iFailedCnt]() {
// 播放失败次数越多,则延时越长
auto strongPlayer = weakSelf.lock();
if (!strongPlayer) {
@ -167,7 +171,8 @@ void PlayerProxy::rePlay(const string &strUrl, int iFailedCnt) {
strongPlayer->MediaPlayer::play(strUrl);
strongPlayer->setDirectProxy();
return false;
}, getPoller());
},
getPoller());
}
bool PlayerProxy::close(MediaSource &sender) {

View File

@ -11,21 +11,25 @@
#ifndef SRC_DEVICE_PLAYERPROXY_H_
#define SRC_DEVICE_PLAYERPROXY_H_
#include <memory>
#include "Common/MultiMediaSourceMuxer.h"
#include "Player/MediaPlayer.h"
#include "Util/TimeTicker.h"
#include <memory>
namespace mediakit {
class PlayerProxy : public MediaPlayer, public MediaSourceEvent, public std::enable_shared_from_this<PlayerProxy> {
class PlayerProxy
: public MediaPlayer
, public MediaSourceEvent
, public std::enable_shared_from_this<PlayerProxy> {
public:
using Ptr = std::shared_ptr<PlayerProxy>;
// 如果retry_count<0,则一直重试播放否则重试retry_count次数
// 默认一直重试
PlayerProxy(const std::string &vhost, const std::string &app, const std::string &stream_id,
const ProtocolOption &option, int retry_count = -1, const toolkit::EventPoller::Ptr &poller = nullptr);
PlayerProxy(
const std::string &vhost, const std::string &app, const std::string &stream_id, const ProtocolOption &option, int retry_count = -1,
const toolkit::EventPoller::Ptr &poller = nullptr);
~PlayerProxy() override;
@ -52,7 +56,6 @@ public:
*/
int totalReaderCount();
int getStatus();
uint64_t getLiveSecs();
uint64_t getRePullCount();

View File

@ -100,7 +100,9 @@ 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]() {
_timer = std::make_shared<Timer>(
delay / 1000.0f,
[weak_self, dst_url, failed_cnt]() {
// 推流失败次数越多,则延时越长
auto strong_self = weak_self.lock();
if (!strong_self) {
@ -109,7 +111,8 @@ void PusherProxy::rePublish(const string &dst_url, int failed_cnt) {
WarnL << "推流重试[" << failed_cnt << "]:" << dst_url;
strong_self->MediaPusher::publish(dst_url);
return false;
}, getPoller());
},
getPoller());
}
int PusherProxy::getStatus() {

View File

@ -16,7 +16,9 @@
namespace mediakit {
class PusherProxy : public MediaPusher, public std::enable_shared_from_this<PusherProxy> {
class PusherProxy
: public MediaPusher
, public std::enable_shared_from_this<PusherProxy> {
public:
using Ptr = std::shared_ptr<PusherProxy>;