mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-05 10:58:11 +08:00
转协议选项抽象为ProtocolOption对象
This commit is contained in:
@@ -28,12 +28,6 @@ using namespace std;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
DevChannel::DevChannel(const string &vhost, const string &app, const string &stream_id,
|
||||
float duration, bool enable_hls, bool enable_mp4) :
|
||||
MultiMediaSourceMuxer(vhost, app, stream_id, duration, true, true, enable_hls, enable_mp4) {}
|
||||
|
||||
DevChannel::~DevChannel() {}
|
||||
|
||||
bool DevChannel::inputYUV(char* apcYuv[3], int aiYuvLen[3], uint32_t uiStamp) {
|
||||
#ifdef ENABLE_X264
|
||||
//TimeTicker1(50);
|
||||
|
||||
@@ -44,12 +44,14 @@ public:
|
||||
*/
|
||||
class DevChannel : public MultiMediaSourceMuxer{
|
||||
public:
|
||||
typedef std::shared_ptr<DevChannel> Ptr;
|
||||
//fDuration<=0为直播,否则为点播
|
||||
DevChannel(const std::string &vhost, const std::string &app, const std::string &stream_id,
|
||||
float duration = 0, bool enable_hls = true, bool enable_mp4 = false);
|
||||
using Ptr = std::shared_ptr<DevChannel>;
|
||||
|
||||
~DevChannel() override ;
|
||||
//fDuration<=0为直播,否则为点播
|
||||
DevChannel(
|
||||
const std::string &vhost, const std::string &app, const std::string &stream_id, float duration = 0,
|
||||
const ProtocolOption &option = ProtocolOption())
|
||||
: MultiMediaSourceMuxer(vhost, app, stream_id, duration, option) {}
|
||||
~DevChannel() override = default;
|
||||
|
||||
/**
|
||||
* 初始化视频Track
|
||||
|
||||
@@ -21,6 +21,13 @@ namespace toolkit {
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
ProtocolOption::ProtocolOption() {
|
||||
GET_CONFIG(bool, toHls, General::kPublishToHls);
|
||||
GET_CONFIG(bool, toMP4, General::kPublishToMP4);
|
||||
enable_hls = toHls;
|
||||
enable_mp4 = toMP4;
|
||||
}
|
||||
|
||||
static std::shared_ptr<MediaSinkInterface> makeRecorder(MediaSource &sender, const vector<Track::Ptr> &tracks, Recorder::type type, const string &custom_path, size_t max_second){
|
||||
auto recorder = Recorder::createRecorder(type, sender.getVhost(), sender.getApp(), sender.getId(), custom_path, max_second);
|
||||
for (auto &track : tracks) {
|
||||
@@ -59,8 +66,7 @@ static string getTrackInfoStr(const TrackSource *track_src){
|
||||
return std::move(codec_info);
|
||||
}
|
||||
|
||||
MultiMediaSourceMuxer::MultiMediaSourceMuxer(const string &vhost, const string &app, const string &stream, float dur_sec,
|
||||
bool enable_rtsp, bool enable_rtmp, bool enable_hls, bool enable_mp4) {
|
||||
MultiMediaSourceMuxer::MultiMediaSourceMuxer(const string &vhost, const string &app, const string &stream, float dur_sec, const ProtocolOption &option) {
|
||||
_get_origin_url = [this, vhost, app, stream]() {
|
||||
auto ret = getOriginUrl(*MediaSource::NullMediaSource);
|
||||
if (!ret.empty()) {
|
||||
@@ -69,25 +75,27 @@ MultiMediaSourceMuxer::MultiMediaSourceMuxer(const string &vhost, const string &
|
||||
return vhost + "/" + app + "/" + stream;
|
||||
};
|
||||
|
||||
if (enable_rtmp) {
|
||||
if (option.enable_rtmp) {
|
||||
_rtmp = std::make_shared<RtmpMediaSourceMuxer>(vhost, app, stream, std::make_shared<TitleMeta>(dur_sec));
|
||||
}
|
||||
if (enable_rtsp) {
|
||||
if (option.enable_rtsp) {
|
||||
_rtsp = std::make_shared<RtspMediaSourceMuxer>(vhost, app, stream, std::make_shared<TitleSdp>(dur_sec));
|
||||
}
|
||||
|
||||
if (enable_hls) {
|
||||
if (option.enable_hls) {
|
||||
_hls = dynamic_pointer_cast<HlsRecorder>(Recorder::createRecorder(Recorder::type_hls, vhost, app, stream));
|
||||
}
|
||||
|
||||
if (enable_mp4) {
|
||||
if (option.enable_mp4) {
|
||||
_mp4 = Recorder::createRecorder(Recorder::type_mp4, vhost, app, stream);
|
||||
}
|
||||
|
||||
_ts = std::make_shared<TSMediaSourceMuxer>(vhost, app, stream);
|
||||
|
||||
if (option.enable_ts) {
|
||||
_ts = std::make_shared<TSMediaSourceMuxer>(vhost, app, stream);
|
||||
}
|
||||
#if defined(ENABLE_MP4)
|
||||
_fmp4 = std::make_shared<FMP4MediaSourceMuxer>(vhost, app, stream);
|
||||
if (option.enable_fmp4) {
|
||||
_fmp4 = std::make_shared<FMP4MediaSourceMuxer>(vhost, app, stream);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,25 @@
|
||||
#include "TS/TSMediaSourceMuxer.h"
|
||||
#include "FMP4/FMP4MediaSourceMuxer.h"
|
||||
|
||||
namespace mediakit{
|
||||
namespace mediakit {
|
||||
|
||||
class ProtocolOption {
|
||||
public:
|
||||
ProtocolOption();
|
||||
|
||||
//是否开启转换为hls
|
||||
bool enable_hls = false;
|
||||
//是否开启MP4录制
|
||||
bool enable_mp4 = false;
|
||||
//是否开启转换为rtsp/webrtc
|
||||
bool enable_rtsp = true;
|
||||
//是否开启转换为rtmp/flv
|
||||
bool enable_rtmp = true;
|
||||
//是否开启转换为http-ts/ws-ts
|
||||
bool enable_ts = true;
|
||||
//是否开启转换为http-fmp4/ws-fmp4
|
||||
bool enable_fmp4 = true;
|
||||
};
|
||||
|
||||
class MultiMediaSourceMuxer : public MediaSourceEventInterceptor, public MediaSink, public std::enable_shared_from_this<MultiMediaSourceMuxer>{
|
||||
public:
|
||||
@@ -34,9 +52,8 @@ public:
|
||||
virtual void onAllTrackReady() = 0;
|
||||
};
|
||||
|
||||
MultiMediaSourceMuxer(const std::string &vhost, const std::string &app, const std::string &stream, float dur_sec = 0.0,const ProtocolOption &option = ProtocolOption());
|
||||
~MultiMediaSourceMuxer() override = default;
|
||||
MultiMediaSourceMuxer(const std::string &vhost, const std::string &app, const std::string &stream, float dur_sec = 0.0,
|
||||
bool enable_rtsp = true, bool enable_rtmp = true, bool enable_hls = true, bool enable_mp4 = false);
|
||||
|
||||
/**
|
||||
* 设置事件监听器
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class ProtocolOption;
|
||||
|
||||
//加载配置文件,如果配置文件不存在,那么会导出默认配置并生成配置文件
|
||||
//加载配置文件成功后会触发kBroadcastUpdateConfig广播
|
||||
//如果指定的文件名(ini_path)为空,那么会加载默认配置文件
|
||||
@@ -65,18 +67,16 @@ extern const std::string kBroadcastOnRtspAuth;
|
||||
#define BroadcastOnRtspAuthArgs const MediaInfo &args,const std::string &realm,const std::string &user_name,const bool &must_no_encrypt,const RtspSession::onAuth &invoker,SockInfo &sender
|
||||
|
||||
//推流鉴权结果回调对象
|
||||
//如果errMessage为空则代表鉴权成功
|
||||
//enableHls: 是否允许转换hls
|
||||
//enableMP4: 是否运行MP4录制
|
||||
typedef std::function<void(const std::string &errMessage, bool enableHls, bool enableMP4)> PublishAuthInvoker;
|
||||
//如果err为空则代表鉴权成功
|
||||
using PublishAuthInvoker = std::function<void(const std::string &err, const ProtocolOption &option)>;
|
||||
|
||||
//收到rtsp/rtmp推流事件广播,通过该事件控制推流鉴权
|
||||
extern const std::string kBroadcastMediaPublish;
|
||||
#define BroadcastMediaPublishArgs const MediaOriginType &type, const MediaInfo &args, const Broadcast::PublishAuthInvoker &invoker,SockInfo &sender
|
||||
#define BroadcastMediaPublishArgs const MediaOriginType &type, const MediaInfo &args, const Broadcast::PublishAuthInvoker &invoker,SockInfo &sender
|
||||
|
||||
//播放鉴权结果回调对象
|
||||
//如果errMessage为空则代表鉴权成功
|
||||
typedef std::function<void(const std::string &errMessage)> AuthInvoker;
|
||||
//如果err为空则代表鉴权成功
|
||||
using AuthInvoker = std::function<void(const std::string &err)>;
|
||||
|
||||
//播放rtsp/rtmp/http-flv事件广播,通过该事件控制播放鉴权
|
||||
extern const std::string kBroadcastMediaPlayed;
|
||||
|
||||
Reference in New Issue
Block a user