Files
ZLMediaKit/src/Pusher/PusherProxy.h

72 lines
2.2 KiB
C++
Raw Normal View History

2021-06-28 16:02:13 +08:00
/*
2023-12-09 16:23:51 +08:00
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
2021-06-16 19:40:08 +08:00
*
2023-12-09 16:23:51 +08:00
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
2021-06-16 19:40:08 +08:00
*
2023-12-09 16:23:51 +08:00
* Use of this source code is governed by MIT-like license that can be found in the
2021-06-16 19:40:08 +08:00
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
#ifndef SRC_DEVICE_PUSHERPROXY_H
#define SRC_DEVICE_PUSHERPROXY_H
#include "Pusher/MediaPusher.h"
#include "Util/TimeTicker.h"
namespace mediakit {
class PusherProxy
: public MediaPusher
, public std::enable_shared_from_this<PusherProxy> {
2021-06-16 19:40:08 +08:00
public:
2022-12-02 14:43:06 +08:00
using Ptr = std::shared_ptr<PusherProxy>;
2021-06-16 19:40:08 +08:00
// 如果retry_count<0,则一直重试播放否则重试retry_count次数
// 默认一直重试创建此对象时候需要外部保证MediaSource存在
PusherProxy(const MediaSource::Ptr &src, int retry_count = -1, const toolkit::EventPoller::Ptr &poller = nullptr);
2021-06-16 19:40:08 +08:00
~PusherProxy() override;
/**
* push结果回调publish执行之前有效
* @param cb
*/
void setPushCallbackOnce(const std::function<void(const toolkit::SockException &ex)> &cb);
2021-06-16 19:40:08 +08:00
/**
*
* @param cb
*/
void setOnClose(const std::function<void(const toolkit::SockException &ex)> &cb);
2021-06-16 19:40:08 +08:00
/**
*
* @param dstUrl
*/
void publish(const std::string &dstUrl) override;
2021-06-16 19:40:08 +08:00
int getStatus();
uint64_t getLiveSecs();
uint64_t getRePublishCount();
2021-06-16 19:40:08 +08:00
private:
// 重推逻辑函数
void rePublish(const std::string &dstUrl, int iFailedCnt);
2021-06-16 19:40:08 +08:00
private:
int _retry_count;
toolkit::Timer::Ptr _timer;
toolkit::Ticker _live_ticker;
// 0 表示正常 1 表示正在尝试推流
std::atomic<int> _live_status;
std::atomic<uint64_t> _live_secs;
std::atomic<uint64_t> _republish_count;
std::weak_ptr<MediaSource> _weak_src;
std::function<void(const toolkit::SockException &ex)> _on_close;
std::function<void(const toolkit::SockException &ex)> _on_publish;
2021-06-16 19:40:08 +08:00
};
} /* namespace mediakit */
#endif // SRC_DEVICE_PUSHERPROXY_H