添加推流代理器

This commit is contained in:
monktan
2021-06-16 19:40:08 +08:00
parent fadef1cac3
commit cd7ae27276
3 changed files with 269 additions and 0 deletions

70
src/Pusher/PusherProxy.h Normal file
View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
*
* Use of this source code is governed by MIT license that can be found in the
* 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"
using namespace std;
using namespace toolkit;
namespace mediakit {
class PusherProxy : public MediaPusher, public std::enable_shared_from_this<PusherProxy> {
public:
typedef std::shared_ptr<PusherProxy> Ptr;
// 如果retry_count<0,则一直重试播放否则重试retry_count次数
// 默认一直重试创建此对象时候需要外部保证mediaSource存在
PusherProxy(const string& schema, const string &vhost, const string &app, const string &stream,
int retry_count = -1, const EventPoller::Ptr &poller = nullptr);
~PusherProxy() override;
/**
* 设置push结果回调只触发一次在publish执行之前有效
* @param cb 回调对象
*/
void setPushCallbackOnce(const function<void(const SockException &ex)> &cb);
/**
* 设置主动关闭回调
* @param cb 回调对象
*/
void setOnClose(const function<void(const SockException &ex)> &cb);
/**
* 开始拉流播放
* @param dstUrl 目标推流地址
*/
void publish(const string& dstUrl) override;
private:
// 重推逻辑函数
void rePublish(const string &dstUrl, int iFailedCnt);
private:
int _retry_count;
std::string _schema;
string _vhost;
string _app;
string _stream_id;
std::string _publish_url;
Timer::Ptr _timer;
function<void(const SockException &ex)> _on_close;
function<void(const SockException &ex)> _on_publish;
};
} /* namespace mediakit */
#endif //SRC_DEVICE_PUSHERPROXY_H