mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-03 17:27:33 +08:00
全面整理转协议相关配置文件
This commit is contained in:
@@ -8,12 +8,13 @@
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "MediaSource.h"
|
||||
#include "Record/MP4Reader.h"
|
||||
#include "Util/util.h"
|
||||
#include "Util/NoticeCenter.h"
|
||||
#include "Network/sockutil.h"
|
||||
#include "Network/TcpSession.h"
|
||||
#include "Util/NoticeCenter.h"
|
||||
#include "MediaSource.h"
|
||||
#include "Common/config.h"
|
||||
#include "Record/MP4Reader.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
@@ -49,6 +50,59 @@ string getOriginTypeString(MediaOriginType type){
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ProtocolOption::ProtocolOption() {
|
||||
GET_CONFIG(bool, s_modify_stamp, Protocol::kModifyStamp);
|
||||
GET_CONFIG(bool, s_enabel_audio, Protocol::kEnableAudio);
|
||||
GET_CONFIG(bool, s_add_mute_audio, Protocol::kAddMuteAudio);
|
||||
GET_CONFIG(uint32_t, s_continue_push_ms, Protocol::kContinuePushMS);
|
||||
|
||||
GET_CONFIG(bool, s_enable_hls, Protocol::kEnableHls);
|
||||
GET_CONFIG(bool, s_enable_mp4, Protocol::kEnableMP4);
|
||||
GET_CONFIG(bool, s_enable_rtsp, Protocol::kEnableRtsp);
|
||||
GET_CONFIG(bool, s_enable_rtmp, Protocol::kEnableRtmp);
|
||||
GET_CONFIG(bool, s_enable_ts, Protocol::kEnableTS);
|
||||
GET_CONFIG(bool, s_enable_fmp4, Protocol::kEnableFMP4);
|
||||
|
||||
GET_CONFIG(bool, s_hls_demand, Protocol::kHlsDemand);
|
||||
GET_CONFIG(bool, s_rtsp_demand, Protocol::kRtspDemand);
|
||||
GET_CONFIG(bool, s_rtmp_demand, Protocol::kRtmpDemand);
|
||||
GET_CONFIG(bool, s_ts_demand, Protocol::kTSDemand);
|
||||
GET_CONFIG(bool, s_fmp4_demand, Protocol::kFMP4Demand);
|
||||
|
||||
GET_CONFIG(bool, s_mp4_as_player, Protocol::kMP4AsPlayer);
|
||||
GET_CONFIG(uint32_t, s_mp4_max_second, Protocol::kMP4MaxSecond);
|
||||
GET_CONFIG(string, s_mp4_save_path, Protocol::kMP4SavePath);
|
||||
|
||||
GET_CONFIG(string, s_hls_save_path, Protocol::kHlsSavePath);
|
||||
|
||||
modify_stamp = s_modify_stamp;
|
||||
enable_audio = s_enabel_audio;
|
||||
add_mute_audio = s_add_mute_audio;
|
||||
continue_push_ms = s_continue_push_ms;
|
||||
|
||||
enable_hls = s_enable_hls;
|
||||
enable_mp4 = s_enable_mp4;
|
||||
enable_rtsp = s_enable_rtsp;
|
||||
enable_rtmp = s_enable_rtmp;
|
||||
enable_ts = s_enable_ts;
|
||||
enable_fmp4 = s_enable_fmp4;
|
||||
|
||||
hls_demand = s_hls_demand;
|
||||
rtsp_demand = s_rtsp_demand;
|
||||
rtmp_demand = s_rtmp_demand;
|
||||
ts_demand = s_ts_demand;
|
||||
fmp4_demand = s_fmp4_demand;
|
||||
|
||||
mp4_as_player = s_mp4_as_player;
|
||||
mp4_max_second = s_mp4_max_second;
|
||||
mp4_save_path = s_mp4_save_path;
|
||||
|
||||
hls_save_path = s_hls_save_path;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct MediaSourceNull : public MediaSource {
|
||||
MediaSourceNull() : MediaSource("schema", "vhost", "app", "stream") {};
|
||||
int readerCount() override { return 0; }
|
||||
|
||||
@@ -134,6 +134,91 @@ private:
|
||||
toolkit::Timer::Ptr _async_close_timer;
|
||||
};
|
||||
|
||||
class ProtocolOption {
|
||||
public:
|
||||
ProtocolOption();
|
||||
|
||||
//时间戳修复这一路流标志位
|
||||
bool modify_stamp;
|
||||
//转协议是否开启音频
|
||||
bool enable_audio;
|
||||
//添加静音音频,在关闭音频时,此开关无效
|
||||
bool add_mute_audio;
|
||||
//断连续推延时,单位毫秒,默认采用配置文件
|
||||
uint32_t continue_push_ms;
|
||||
|
||||
//是否开启转换为hls
|
||||
bool enable_hls;
|
||||
//是否开启MP4录制
|
||||
bool enable_mp4;
|
||||
//是否开启转换为rtsp/webrtc
|
||||
bool enable_rtsp;
|
||||
//是否开启转换为rtmp/flv
|
||||
bool enable_rtmp;
|
||||
//是否开启转换为http-ts/ws-ts
|
||||
bool enable_ts;
|
||||
//是否开启转换为http-fmp4/ws-fmp4
|
||||
bool enable_fmp4;
|
||||
|
||||
// hls协议是否按需生成,如果hls.segNum配置为0(意味着hls录制),那么hls将一直生成(不管此开关)
|
||||
bool hls_demand;
|
||||
// rtsp[s]协议是否按需生成
|
||||
bool rtsp_demand;
|
||||
// rtmp[s]、http[s]-flv、ws[s]-flv协议是否按需生成
|
||||
bool rtmp_demand;
|
||||
// http[s]-ts协议是否按需生成
|
||||
bool ts_demand;
|
||||
// http[s]-fmp4、ws[s]-fmp4协议是否按需生成
|
||||
bool fmp4_demand;
|
||||
|
||||
//是否将mp4录制当做观看者
|
||||
bool mp4_as_player;
|
||||
//mp4切片大小,单位秒
|
||||
size_t mp4_max_second;
|
||||
//mp4录制保存路径
|
||||
std::string mp4_save_path;
|
||||
|
||||
//hls录制保存路径
|
||||
std::string hls_save_path;
|
||||
|
||||
template <typename MAP>
|
||||
ProtocolOption(const MAP &allArgs) : ProtocolOption() {
|
||||
#define GET_OPT_VALUE(key) getArgsValue(allArgs, #key, key)
|
||||
GET_OPT_VALUE(modify_stamp);
|
||||
GET_OPT_VALUE(enable_audio);
|
||||
GET_OPT_VALUE(add_mute_audio);
|
||||
GET_OPT_VALUE(continue_push_ms);
|
||||
|
||||
GET_OPT_VALUE(enable_hls);
|
||||
GET_OPT_VALUE(enable_mp4);
|
||||
GET_OPT_VALUE(enable_rtsp);
|
||||
GET_OPT_VALUE(enable_rtmp);
|
||||
GET_OPT_VALUE(enable_ts);
|
||||
GET_OPT_VALUE(enable_fmp4);
|
||||
|
||||
GET_OPT_VALUE(hls_demand);
|
||||
GET_OPT_VALUE(rtsp_demand);
|
||||
GET_OPT_VALUE(rtmp_demand);
|
||||
GET_OPT_VALUE(ts_demand);
|
||||
GET_OPT_VALUE(fmp4_demand);
|
||||
|
||||
GET_OPT_VALUE(mp4_max_second);
|
||||
GET_OPT_VALUE(mp4_as_player);
|
||||
GET_OPT_VALUE(mp4_save_path);
|
||||
|
||||
GET_OPT_VALUE(hls_save_path);
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename MAP, typename KEY, typename TYPE>
|
||||
static void getArgsValue(const MAP &allArgs, const KEY &key, TYPE &value) {
|
||||
auto val = ((MAP &)allArgs)[key];
|
||||
if (!val.empty()) {
|
||||
value = (TYPE)val;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//该对象用于拦截感兴趣的MediaSourceEvent事件
|
||||
class MediaSourceEventInterceptor : public MediaSourceEvent {
|
||||
public:
|
||||
|
||||
@@ -21,26 +21,8 @@ namespace toolkit {
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
ProtocolOption::ProtocolOption() {
|
||||
GET_CONFIG(bool, s_to_hls, General::kPublishToHls);
|
||||
GET_CONFIG(bool, s_to_mp4, General::kPublishToMP4);
|
||||
GET_CONFIG(bool, s_enabel_audio, General::kEnableAudio);
|
||||
GET_CONFIG(bool, s_add_mute_audio, General::kAddMuteAudio);
|
||||
GET_CONFIG(bool, s_mp4_as_player, Record::kMP4AsPlayer);
|
||||
GET_CONFIG(uint32_t, s_continue_push_ms, General::kContinuePushMS);
|
||||
GET_CONFIG(bool, s_modify_stamp, General::kModifyStamp);
|
||||
|
||||
enable_hls = s_to_hls;
|
||||
enable_mp4 = s_to_mp4;
|
||||
enable_audio = s_enabel_audio;
|
||||
add_mute_audio = s_add_mute_audio;
|
||||
continue_push_ms = s_continue_push_ms;
|
||||
mp4_as_player = s_mp4_as_player;
|
||||
modify_stamp = s_modify_stamp;
|
||||
}
|
||||
|
||||
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);
|
||||
static std::shared_ptr<MediaSinkInterface> makeRecorder(MediaSource &sender, const vector<Track::Ptr> &tracks, Recorder::type type, const ProtocolOption &option){
|
||||
auto recorder = Recorder::createRecorder(type, sender.getVhost(), sender.getApp(), sender.getId(), option);
|
||||
for (auto &track : tracks) {
|
||||
recorder->addTrack(track);
|
||||
}
|
||||
@@ -106,23 +88,23 @@ MultiMediaSourceMuxer::MultiMediaSourceMuxer(const string &vhost, const string &
|
||||
_option = option;
|
||||
|
||||
if (option.enable_rtmp) {
|
||||
_rtmp = std::make_shared<RtmpMediaSourceMuxer>(vhost, app, stream, std::make_shared<TitleMeta>(dur_sec));
|
||||
_rtmp = std::make_shared<RtmpMediaSourceMuxer>(vhost, app, stream, option, std::make_shared<TitleMeta>(dur_sec));
|
||||
}
|
||||
if (option.enable_rtsp) {
|
||||
_rtsp = std::make_shared<RtspMediaSourceMuxer>(vhost, app, stream, std::make_shared<TitleSdp>(dur_sec));
|
||||
_rtsp = std::make_shared<RtspMediaSourceMuxer>(vhost, app, stream, option, std::make_shared<TitleSdp>(dur_sec));
|
||||
}
|
||||
if (option.enable_hls) {
|
||||
_hls = dynamic_pointer_cast<HlsRecorder>(Recorder::createRecorder(Recorder::type_hls, vhost, app, stream, option.hls_save_path));
|
||||
_hls = dynamic_pointer_cast<HlsRecorder>(Recorder::createRecorder(Recorder::type_hls, vhost, app, stream, option));
|
||||
}
|
||||
if (option.enable_mp4) {
|
||||
_mp4 = Recorder::createRecorder(Recorder::type_mp4, vhost, app, stream, option.mp4_save_path, option.mp4_max_second);
|
||||
_mp4 = Recorder::createRecorder(Recorder::type_mp4, vhost, app, stream, option);
|
||||
}
|
||||
if (option.enable_ts) {
|
||||
_ts = std::make_shared<TSMediaSourceMuxer>(vhost, app, stream);
|
||||
_ts = std::make_shared<TSMediaSourceMuxer>(vhost, app, stream, option);
|
||||
}
|
||||
#if defined(ENABLE_MP4)
|
||||
if (option.enable_fmp4) {
|
||||
_fmp4 = std::make_shared<FMP4MediaSourceMuxer>(vhost, app, stream);
|
||||
_fmp4 = std::make_shared<FMP4MediaSourceMuxer>(vhost, app, stream, option);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -212,7 +194,8 @@ bool MultiMediaSourceMuxer::setupRecord(MediaSource &sender, Recorder::type type
|
||||
case Recorder::type_hls : {
|
||||
if (start && !_hls) {
|
||||
//开始录制
|
||||
auto hls = dynamic_pointer_cast<HlsRecorder>(makeRecorder(sender, getTracks(), type, custom_path, max_second));
|
||||
_option.hls_save_path = custom_path;
|
||||
auto hls = dynamic_pointer_cast<HlsRecorder>(makeRecorder(sender, getTracks(), type, _option));
|
||||
if (hls) {
|
||||
//设置HlsMediaSource的事件监听器
|
||||
hls->setListener(shared_from_this());
|
||||
@@ -227,7 +210,9 @@ bool MultiMediaSourceMuxer::setupRecord(MediaSource &sender, Recorder::type type
|
||||
case Recorder::type_mp4 : {
|
||||
if (start && !_mp4) {
|
||||
//开始录制
|
||||
_mp4 = makeRecorder(sender, getTracks(), type, custom_path, max_second);
|
||||
_option.mp4_save_path = custom_path;
|
||||
_option.mp4_max_second = max_second;
|
||||
_mp4 = makeRecorder(sender, getTracks(), type, _option);
|
||||
} else if (!start && _mp4) {
|
||||
//停止录制
|
||||
_mp4 = nullptr;
|
||||
|
||||
@@ -23,73 +23,6 @@
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class ProtocolOption {
|
||||
public:
|
||||
ProtocolOption();
|
||||
|
||||
//是否开启转换为hls
|
||||
bool enable_hls = false;
|
||||
//是否开启MP4录制
|
||||
bool enable_mp4 = false;
|
||||
//是否将mp4录制当做观看者
|
||||
bool mp4_as_player = 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;
|
||||
|
||||
//转协议是否开启音频
|
||||
bool enable_audio = true;
|
||||
//添加静音音频,在关闭音频时,此开关无效
|
||||
bool add_mute_audio = true;
|
||||
|
||||
//mp4录制保存路径
|
||||
std::string mp4_save_path;
|
||||
//mp4切片大小,单位秒
|
||||
size_t mp4_max_second = 0;
|
||||
|
||||
//hls录制保存路径
|
||||
std::string hls_save_path;
|
||||
|
||||
//断连续推延时,单位毫秒,默认采用配置文件
|
||||
uint32_t continue_push_ms;
|
||||
|
||||
//时间戳修复这一路流标志位
|
||||
bool modify_stamp;
|
||||
|
||||
template <typename MAP>
|
||||
ProtocolOption(const MAP &allArgs) : ProtocolOption() {
|
||||
#define GET_OPT_VALUE(key) getArgsValue(allArgs, #key, key)
|
||||
GET_OPT_VALUE(enable_hls);
|
||||
GET_OPT_VALUE(enable_mp4);
|
||||
GET_OPT_VALUE(mp4_as_player);
|
||||
GET_OPT_VALUE(enable_rtsp);
|
||||
GET_OPT_VALUE(enable_rtmp);
|
||||
GET_OPT_VALUE(enable_ts);
|
||||
GET_OPT_VALUE(enable_fmp4);
|
||||
GET_OPT_VALUE(enable_audio);
|
||||
GET_OPT_VALUE(add_mute_audio);
|
||||
GET_OPT_VALUE(mp4_save_path);
|
||||
GET_OPT_VALUE(mp4_max_second);
|
||||
GET_OPT_VALUE(hls_save_path);
|
||||
GET_OPT_VALUE(continue_push_ms);
|
||||
GET_OPT_VALUE(modify_stamp);
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename MAP, typename KEY, typename TYPE>
|
||||
static void getArgsValue(const MAP &allArgs, const KEY &key, TYPE &value) {
|
||||
auto val = ((MAP &)allArgs)[key];
|
||||
if (!val.empty()) {
|
||||
value = (TYPE)val;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class MultiMediaSourceMuxer : public MediaSourceEventInterceptor, public MediaSink, public std::enable_shared_from_this<MultiMediaSourceMuxer>{
|
||||
public:
|
||||
typedef std::shared_ptr<MultiMediaSourceMuxer> Ptr;
|
||||
|
||||
@@ -68,53 +68,84 @@ const string kFlowThreshold = GENERAL_FIELD "flowThreshold";
|
||||
const string kStreamNoneReaderDelayMS = GENERAL_FIELD "streamNoneReaderDelayMS";
|
||||
const string kMaxStreamWaitTimeMS = GENERAL_FIELD "maxStreamWaitMS";
|
||||
const string kEnableVhost = GENERAL_FIELD "enableVhost";
|
||||
const string kAddMuteAudio = GENERAL_FIELD "addMuteAudio";
|
||||
const string kResetWhenRePlay = GENERAL_FIELD "resetWhenRePlay";
|
||||
const string kPublishToHls = GENERAL_FIELD "publishToHls";
|
||||
const string kPublishToMP4 = GENERAL_FIELD "publishToMP4";
|
||||
const string kMergeWriteMS = GENERAL_FIELD "mergeWriteMS";
|
||||
const string kModifyStamp = GENERAL_FIELD "modifyStamp";
|
||||
const string kHlsDemand = GENERAL_FIELD "hls_demand";
|
||||
const string kRtspDemand = GENERAL_FIELD "rtsp_demand";
|
||||
const string kRtmpDemand = GENERAL_FIELD "rtmp_demand";
|
||||
const string kTSDemand = GENERAL_FIELD "ts_demand";
|
||||
const string kFMP4Demand = GENERAL_FIELD "fmp4_demand";
|
||||
const string kEnableAudio = GENERAL_FIELD "enable_audio";
|
||||
const string kCheckNvidiaDev = GENERAL_FIELD "check_nvidia_dev";
|
||||
const string kEnableFFmpegLog = GENERAL_FIELD "enable_ffmpeg_log";
|
||||
const string kWaitTrackReadyMS = GENERAL_FIELD "wait_track_ready_ms";
|
||||
const string kWaitAddTrackMS = GENERAL_FIELD "wait_add_track_ms";
|
||||
const string kUnreadyFrameCache = GENERAL_FIELD "unready_frame_cache";
|
||||
const string kContinuePushMS = GENERAL_FIELD "continue_push_ms";
|
||||
|
||||
static onceToken token([]() {
|
||||
mINI::Instance()[kFlowThreshold] = 1024;
|
||||
mINI::Instance()[kStreamNoneReaderDelayMS] = 20 * 1000;
|
||||
mINI::Instance()[kMaxStreamWaitTimeMS] = 15 * 1000;
|
||||
mINI::Instance()[kEnableVhost] = 0;
|
||||
mINI::Instance()[kAddMuteAudio] = 1;
|
||||
mINI::Instance()[kResetWhenRePlay] = 1;
|
||||
mINI::Instance()[kPublishToHls] = 1;
|
||||
mINI::Instance()[kPublishToMP4] = 0;
|
||||
mINI::Instance()[kMergeWriteMS] = 0;
|
||||
mINI::Instance()[kModifyStamp] = 0;
|
||||
mINI::Instance()[kMediaServerId] = makeRandStr(16);
|
||||
mINI::Instance()[kHlsDemand] = 0;
|
||||
mINI::Instance()[kRtspDemand] = 0;
|
||||
mINI::Instance()[kRtmpDemand] = 0;
|
||||
mINI::Instance()[kTSDemand] = 0;
|
||||
mINI::Instance()[kFMP4Demand] = 0;
|
||||
mINI::Instance()[kEnableAudio] = 1;
|
||||
mINI::Instance()[kCheckNvidiaDev] = 1;
|
||||
mINI::Instance()[kEnableFFmpegLog] = 0;
|
||||
mINI::Instance()[kWaitTrackReadyMS] = 10000;
|
||||
mINI::Instance()[kWaitAddTrackMS] = 3000;
|
||||
mINI::Instance()[kUnreadyFrameCache] = 100;
|
||||
mINI::Instance()[kContinuePushMS] = 15 * 1000;
|
||||
});
|
||||
|
||||
} // namespace General
|
||||
|
||||
namespace Protocol {
|
||||
#define PROTOCOL_FIELD "protocol."
|
||||
const string kModifyStamp = PROTOCOL_FIELD "modify_stamp";
|
||||
const string kEnableAudio = PROTOCOL_FIELD "enable_audio";
|
||||
const string kAddMuteAudio = PROTOCOL_FIELD "add_mute_audio";
|
||||
const string kContinuePushMS = PROTOCOL_FIELD "continue_push_ms";
|
||||
|
||||
const string kEnableHls = PROTOCOL_FIELD "enable_hls";
|
||||
const string kEnableMP4 = PROTOCOL_FIELD "enable_mp4";
|
||||
const string kEnableRtsp = PROTOCOL_FIELD "enable_rtsp";
|
||||
const string kEnableRtmp = PROTOCOL_FIELD "enable_rtmp";
|
||||
const string kEnableTS = PROTOCOL_FIELD "enable_ts";
|
||||
const string kEnableFMP4 = PROTOCOL_FIELD "enable_fmp4";
|
||||
|
||||
const string kMP4AsPlayer = PROTOCOL_FIELD "mp4_as_player";
|
||||
const string kMP4MaxSecond = PROTOCOL_FIELD "mp4_max_second";
|
||||
const string kMP4SavePath = PROTOCOL_FIELD "mp4_save_path";
|
||||
|
||||
const string kHlsSavePath = PROTOCOL_FIELD "hls_save_path";
|
||||
|
||||
const string kHlsDemand = PROTOCOL_FIELD "hls_demand";
|
||||
const string kRtspDemand = PROTOCOL_FIELD "rtsp_demand";
|
||||
const string kRtmpDemand = PROTOCOL_FIELD "rtmp_demand";
|
||||
const string kTSDemand = PROTOCOL_FIELD "ts_demand";
|
||||
const string kFMP4Demand = PROTOCOL_FIELD "fmp4_demand";
|
||||
|
||||
static onceToken token([]() {
|
||||
mINI::Instance()[kModifyStamp] = 0;
|
||||
mINI::Instance()[kEnableAudio] = 1;
|
||||
mINI::Instance()[kAddMuteAudio] = 1;
|
||||
mINI::Instance()[kContinuePushMS] = 15000;
|
||||
|
||||
mINI::Instance()[kEnableHls] = 1;
|
||||
mINI::Instance()[kEnableMP4] = 0;
|
||||
mINI::Instance()[kEnableRtsp] = 1;
|
||||
mINI::Instance()[kEnableRtmp] = 1;
|
||||
mINI::Instance()[kEnableTS] = 1;
|
||||
mINI::Instance()[kEnableFMP4] = 1;
|
||||
|
||||
mINI::Instance()[kMP4AsPlayer] = 0;
|
||||
mINI::Instance()[kMP4MaxSecond] = 3600;
|
||||
mINI::Instance()[kMP4SavePath] = "./www";
|
||||
|
||||
mINI::Instance()[kHlsSavePath] = "./www";
|
||||
|
||||
mINI::Instance()[kHlsDemand] = 0;
|
||||
mINI::Instance()[kRtspDemand] = 0;
|
||||
mINI::Instance()[kRtmpDemand] = 0;
|
||||
mINI::Instance()[kTSDemand] = 0;
|
||||
mINI::Instance()[kFMP4Demand] = 0;
|
||||
});
|
||||
} // !Protocol
|
||||
|
||||
////////////HTTP配置///////////
|
||||
namespace Http {
|
||||
#define HTTP_FIELD "http."
|
||||
@@ -242,22 +273,16 @@ namespace Record {
|
||||
#define RECORD_FIELD "record."
|
||||
const string kAppName = RECORD_FIELD "appName";
|
||||
const string kSampleMS = RECORD_FIELD "sampleMS";
|
||||
const string kFileSecond = RECORD_FIELD "fileSecond";
|
||||
const string kFilePath = RECORD_FIELD "filePath";
|
||||
const string kFileBufSize = RECORD_FIELD "fileBufSize";
|
||||
const string kFastStart = RECORD_FIELD "fastStart";
|
||||
const string kFileRepeat = RECORD_FIELD "fileRepeat";
|
||||
const string kMP4AsPlayer = RECORD_FIELD "mp4_as_player";
|
||||
|
||||
static onceToken token([]() {
|
||||
mINI::Instance()[kAppName] = "record";
|
||||
mINI::Instance()[kSampleMS] = 500;
|
||||
mINI::Instance()[kFileSecond] = 60 * 60;
|
||||
mINI::Instance()[kFilePath] = "./www";
|
||||
mINI::Instance()[kFileBufSize] = 64 * 1024;
|
||||
mINI::Instance()[kFastStart] = false;
|
||||
mINI::Instance()[kFileRepeat] = false;
|
||||
mINI::Instance()[kMP4AsPlayer] = false;
|
||||
});
|
||||
} // namespace Record
|
||||
|
||||
@@ -269,7 +294,6 @@ const string kSegmentNum = HLS_FIELD "segNum";
|
||||
const string kSegmentKeep = HLS_FIELD "segKeep";
|
||||
const string kSegmentRetain = HLS_FIELD "segRetain";
|
||||
const string kFileBufSize = HLS_FIELD "fileBufSize";
|
||||
const string kFilePath = HLS_FIELD "filePath";
|
||||
const string kBroadcastRecordTs = HLS_FIELD "broadcastRecordTs";
|
||||
const string kDeleteDelaySec = HLS_FIELD "deleteDelaySec";
|
||||
|
||||
@@ -279,7 +303,6 @@ static onceToken token([]() {
|
||||
mINI::Instance()[kSegmentKeep] = false;
|
||||
mINI::Instance()[kSegmentRetain] = 5;
|
||||
mINI::Instance()[kFileBufSize] = 64 * 1024;
|
||||
mINI::Instance()[kFilePath] = "./www";
|
||||
mINI::Instance()[kBroadcastRecordTs] = false;
|
||||
mINI::Instance()[kDeleteDelaySec] = 10;
|
||||
});
|
||||
|
||||
@@ -45,14 +45,11 @@ extern const std::string kBroadcastRecordTs;
|
||||
|
||||
// 收到http api请求广播
|
||||
extern const std::string kBroadcastHttpRequest;
|
||||
#define BroadcastHttpRequestArgs \
|
||||
const Parser &parser, const HttpSession::HttpResponseInvoker &invoker, bool &consumed, SockInfo &sender
|
||||
#define BroadcastHttpRequestArgs const Parser &parser, const HttpSession::HttpResponseInvoker &invoker, bool &consumed, SockInfo &sender
|
||||
|
||||
// 在http文件服务器中,收到http访问文件或目录的广播,通过该事件控制访问http目录的权限
|
||||
extern const std::string kBroadcastHttpAccess;
|
||||
#define BroadcastHttpAccessArgs \
|
||||
const Parser &parser, const std::string &path, const bool &is_dir, \
|
||||
const HttpSession::HttpAccessPathInvoker &invoker, SockInfo &sender
|
||||
#define BroadcastHttpAccessArgs const Parser &parser, const std::string &path, const bool &is_dir, const HttpSession::HttpAccessPathInvoker &invoker, SockInfo &sender
|
||||
|
||||
// 在http文件服务器中,收到http访问文件或目录前的广播,通过该事件可以控制http url到文件路径的映射
|
||||
// 在该事件中通过自行覆盖path参数,可以做到譬如根据虚拟主机或者app选择不同http根目录的目的
|
||||
@@ -66,9 +63,7 @@ extern const std::string kBroadcastOnGetRtspRealm;
|
||||
// 请求认证用户密码事件,user_name为用户名,must_no_encrypt如果为true,则必须提供明文密码(因为此时是base64认证方式),否则会导致认证失败
|
||||
// 获取到密码后请调用invoker并输入对应类型的密码和密码类型,invoker执行时会匹配密码
|
||||
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
|
||||
#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
|
||||
|
||||
// 推流鉴权结果回调对象
|
||||
// 如果err为空则代表鉴权成功
|
||||
@@ -76,8 +71,7 @@ using PublishAuthInvoker = std::function<void(const std::string &err, const Prot
|
||||
|
||||
// 收到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
|
||||
|
||||
// 播放鉴权结果回调对象
|
||||
// 如果err为空则代表鉴权成功
|
||||
@@ -89,14 +83,11 @@ extern const std::string kBroadcastMediaPlayed;
|
||||
|
||||
// shell登录鉴权
|
||||
extern const std::string kBroadcastShellLogin;
|
||||
#define BroadcastShellLoginArgs \
|
||||
const std::string &user_name, const std::string &passwd, const Broadcast::AuthInvoker &invoker, SockInfo &sender
|
||||
#define BroadcastShellLoginArgs const std::string &user_name, const std::string &passwd, const Broadcast::AuthInvoker &invoker, SockInfo &sender
|
||||
|
||||
// 停止rtsp/rtmp/http-flv会话后流量汇报事件广播
|
||||
extern const std::string kBroadcastFlowReport;
|
||||
#define BroadcastFlowReportArgs \
|
||||
const MediaInfo &args, const uint64_t &totalBytes, const uint64_t &totalDuration, const bool &isPlayer, \
|
||||
SockInfo &sender
|
||||
#define BroadcastFlowReportArgs const MediaInfo &args, const uint64_t &totalBytes, const uint64_t &totalDuration, const bool &isPlayer, SockInfo &sender
|
||||
|
||||
// 未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了
|
||||
extern const std::string kBroadcastNotFoundStream;
|
||||
@@ -173,28 +164,12 @@ extern const std::string kStreamNoneReaderDelayMS;
|
||||
extern const std::string kMaxStreamWaitTimeMS;
|
||||
// 是否启动虚拟主机
|
||||
extern const std::string kEnableVhost;
|
||||
// 拉流代理时是否添加静音音频
|
||||
extern const std::string kAddMuteAudio;
|
||||
// 拉流代理时如果断流再重连成功是否删除前一次的媒体流数据,如果删除将重新开始,
|
||||
// 如果不删除将会接着上一次的数据继续写(录制hls/mp4时会继续在前一个文件后面写)
|
||||
extern const std::string kResetWhenRePlay;
|
||||
// 是否默认推流时转换成hls,hook接口(on_publish)中可以覆盖该设置
|
||||
extern const std::string kPublishToHls;
|
||||
// 是否默认推流时mp4录像,hook接口(on_publish)中可以覆盖该设置
|
||||
extern const std::string kPublishToMP4;
|
||||
// 合并写缓存大小(单位毫秒),合并写指服务器缓存一定的数据后才会一次性写入socket,这样能提高性能,但是会提高延时
|
||||
// 开启后会同时关闭TCP_NODELAY并开启MSG_MORE
|
||||
extern const std::string kMergeWriteMS;
|
||||
// 全局的时间戳覆盖开关,在转协议时,对frame进行时间戳覆盖
|
||||
extern const std::string kModifyStamp;
|
||||
// 按需转协议的开关
|
||||
extern const std::string kHlsDemand;
|
||||
extern const std::string kRtspDemand;
|
||||
extern const std::string kRtmpDemand;
|
||||
extern const std::string kTSDemand;
|
||||
extern const std::string kFMP4Demand;
|
||||
// 转协议是否全局开启或忽略音频
|
||||
extern const std::string kEnableAudio;
|
||||
// 在docker环境下,不能通过英伟达驱动是否存在来判断是否支持硬件转码
|
||||
extern const std::string kCheckNvidiaDev;
|
||||
// 是否开启ffmpeg日志
|
||||
@@ -206,11 +181,49 @@ extern const std::string kWaitTrackReadyMS;
|
||||
extern const std::string kWaitAddTrackMS;
|
||||
// 如果track未就绪,我们先缓存帧数据,但是有最大个数限制(100帧时大约4秒),防止内存溢出
|
||||
extern const std::string kUnreadyFrameCache;
|
||||
// 推流断开后可以在超时时间内重新连接上继续推流,这样播放器会接着播放。
|
||||
// 置0关闭此特性(推流断开会导致立即断开播放器)
|
||||
extern const std::string kContinuePushMS;
|
||||
} // namespace General
|
||||
|
||||
namespace Protocol {
|
||||
//时间戳修复这一路流标志位
|
||||
extern const std::string kModifyStamp;
|
||||
//转协议是否开启音频
|
||||
extern const std::string kEnableAudio;
|
||||
//添加静音音频,在关闭音频时,此开关无效
|
||||
extern const std::string kAddMuteAudio;
|
||||
//断连续推延时,单位毫秒,默认采用配置文件
|
||||
extern const std::string kContinuePushMS;
|
||||
|
||||
//是否开启转换为hls
|
||||
extern const std::string kEnableHls;
|
||||
//是否开启MP4录制
|
||||
extern const std::string kEnableMP4;
|
||||
//是否开启转换为rtsp/webrtc
|
||||
extern const std::string kEnableRtsp;
|
||||
//是否开启转换为rtmp/flv
|
||||
extern const std::string kEnableRtmp;
|
||||
//是否开启转换为http-ts/ws-ts
|
||||
extern const std::string kEnableTS;
|
||||
//是否开启转换为http-fmp4/ws-fmp4
|
||||
extern const std::string kEnableFMP4;
|
||||
|
||||
//是否将mp4录制当做观看者
|
||||
extern const std::string kMP4AsPlayer;
|
||||
//mp4切片大小,单位秒
|
||||
extern const std::string kMP4MaxSecond;
|
||||
//mp4录制保存路径
|
||||
extern const std::string kMP4SavePath;
|
||||
|
||||
//hls录制保存路径
|
||||
extern const std::string kHlsSavePath;
|
||||
|
||||
// 按需转协议的开关
|
||||
extern const std::string kHlsDemand;
|
||||
extern const std::string kRtspDemand;
|
||||
extern const std::string kRtmpDemand;
|
||||
extern const std::string kTSDemand;
|
||||
extern const std::string kFMP4Demand;
|
||||
} // !Protocol
|
||||
|
||||
////////////HTTP配置///////////
|
||||
namespace Http {
|
||||
// http 文件发送缓存大小
|
||||
@@ -262,8 +275,6 @@ extern const std::string kLowLatency;
|
||||
|
||||
////////////RTMP服务器配置///////////
|
||||
namespace Rtmp {
|
||||
// rtmp推流时间戳覆盖开关
|
||||
extern const std::string kModifyStamp;
|
||||
// 握手超时时间,默认15秒
|
||||
extern const std::string kHandshakeSecond;
|
||||
// 维持链接超时时间,默认15秒
|
||||
@@ -298,18 +309,12 @@ namespace Record {
|
||||
extern const std::string kAppName;
|
||||
// 每次流化MP4文件的时长,单位毫秒
|
||||
extern const std::string kSampleMS;
|
||||
// MP4文件录制大小,默认一个小时
|
||||
extern const std::string kFileSecond;
|
||||
// 录制文件路径
|
||||
extern const std::string kFilePath;
|
||||
// mp4文件写缓存大小
|
||||
extern const std::string kFileBufSize;
|
||||
// mp4录制完成后是否进行二次关键帧索引写入头部
|
||||
extern const std::string kFastStart;
|
||||
// mp4文件是否重头循环读取
|
||||
extern const std::string kFileRepeat;
|
||||
// MP4录制是否当做播放器参与播放人数统计
|
||||
extern const std::string kMP4AsPlayer;
|
||||
} // namespace Record
|
||||
|
||||
////////////HLS相关配置///////////
|
||||
@@ -324,8 +329,6 @@ extern const std::string kSegmentKeep;
|
||||
extern const std::string kSegmentRetain;
|
||||
// HLS文件写缓存大小
|
||||
extern const std::string kFileBufSize;
|
||||
// 录制文件路径
|
||||
extern const std::string kFilePath;
|
||||
// 是否广播 ts 切片完成通知
|
||||
extern const std::string kBroadcastRecordTs;
|
||||
// hls直播文件删除延时,单位秒
|
||||
|
||||
Reference in New Issue
Block a user