2019-08-08 19:01:45 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xiongziliang/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.
|
|
|
|
|
*/
|
2019-03-27 18:41:52 +08:00
|
|
|
|
|
|
|
|
|
#ifndef SRC_PUSHER_PUSHERBASE_H_
|
|
|
|
|
#define SRC_PUSHER_PUSHERBASE_H_
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include "Network/Socket.h"
|
|
|
|
|
#include "Util/mini.h"
|
|
|
|
|
#include "Common/MediaSource.h"
|
|
|
|
|
using namespace toolkit;
|
|
|
|
|
|
|
|
|
|
namespace mediakit {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PusherBase : public mINI{
|
|
|
|
|
public:
|
|
|
|
|
typedef std::shared_ptr<PusherBase> Ptr;
|
2019-03-27 18:56:49 +08:00
|
|
|
|
typedef std::function<void(const SockException &ex)> Event;
|
2019-03-27 18:41:52 +08:00
|
|
|
|
|
2019-04-01 10:16:15 +08:00
|
|
|
|
static Ptr createPusher(const EventPoller::Ptr &poller,
|
|
|
|
|
const MediaSource::Ptr &src,
|
2019-03-27 18:41:52 +08:00
|
|
|
|
const string &strUrl);
|
|
|
|
|
|
|
|
|
|
PusherBase();
|
|
|
|
|
virtual ~PusherBase(){}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 开始推流
|
|
|
|
|
* @param strUrl 视频url,支持rtsp/rtmp
|
|
|
|
|
*/
|
|
|
|
|
virtual void publish(const string &strUrl) = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 中断推流
|
|
|
|
|
*/
|
|
|
|
|
virtual void teardown() = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 摄像推流结果回调
|
|
|
|
|
* @param onPublished
|
|
|
|
|
*/
|
|
|
|
|
virtual void setOnPublished(const Event &cb) = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置断开回调
|
|
|
|
|
* @param onShutdown
|
|
|
|
|
*/
|
|
|
|
|
virtual void setOnShutdown(const Event &cb) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-04 10:59:13 +08:00
|
|
|
|
template<typename Parent,typename Delegate>
|
2019-03-27 18:41:52 +08:00
|
|
|
|
class PusherImp : public Parent {
|
|
|
|
|
public:
|
|
|
|
|
typedef std::shared_ptr<PusherImp> Ptr;
|
2019-04-01 10:16:15 +08:00
|
|
|
|
|
|
|
|
|
template<typename ...ArgsType>
|
|
|
|
|
PusherImp(ArgsType &&...args):Parent(std::forward<ArgsType>(args)...){}
|
|
|
|
|
|
2019-03-27 18:41:52 +08:00
|
|
|
|
virtual ~PusherImp(){}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 开始推流
|
|
|
|
|
* @param strUrl 推流url,支持rtsp/rtmp
|
|
|
|
|
*/
|
|
|
|
|
void publish(const string &strUrl) override{
|
2019-12-04 10:59:13 +08:00
|
|
|
|
if (_delegate) {
|
|
|
|
|
_delegate->publish(strUrl);
|
2019-03-27 18:41:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 中断推流
|
|
|
|
|
*/
|
|
|
|
|
void teardown() override{
|
2019-12-04 10:59:13 +08:00
|
|
|
|
if (_delegate) {
|
|
|
|
|
_delegate->teardown();
|
2019-03-27 18:41:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 摄像推流结果回调
|
|
|
|
|
* @param onPublished
|
|
|
|
|
*/
|
|
|
|
|
void setOnPublished(const PusherBase::Event &cb) override{
|
2019-12-04 10:59:13 +08:00
|
|
|
|
if (_delegate) {
|
|
|
|
|
_delegate->setOnPublished(cb);
|
2019-03-27 18:41:52 +08:00
|
|
|
|
}
|
|
|
|
|
_publishCB = cb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置断开回调
|
|
|
|
|
* @param onShutdown
|
|
|
|
|
*/
|
|
|
|
|
void setOnShutdown(const PusherBase::Event &cb) override{
|
2019-12-04 10:59:13 +08:00
|
|
|
|
if (_delegate) {
|
|
|
|
|
_delegate->setOnShutdown(cb);
|
2019-03-27 18:41:52 +08:00
|
|
|
|
}
|
|
|
|
|
_shutdownCB = cb;
|
|
|
|
|
}
|
2020-09-27 11:32:49 +08:00
|
|
|
|
|
|
|
|
|
std::shared_ptr<SockInfo> getSockInfo() const{
|
|
|
|
|
return dynamic_pointer_cast<SockInfo>(_delegate);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 18:41:52 +08:00
|
|
|
|
protected:
|
|
|
|
|
PusherBase::Event _shutdownCB;
|
|
|
|
|
PusherBase::Event _publishCB;
|
2019-12-04 10:59:13 +08:00
|
|
|
|
std::shared_ptr<Delegate> _delegate;
|
2019-03-27 18:41:52 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} /* namespace mediakit */
|
|
|
|
|
|
|
|
|
|
#endif /* SRC_PUSHER_PUSHERBASE_H_ */
|