mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-23 03:10:04 +08:00
on_publish hook新增多种选项
This commit is contained in:
parent
490656ec3e
commit
0f1120b8a6
@ -287,11 +287,26 @@ void installWebHook(){
|
||||
if (err.empty()) {
|
||||
//推流鉴权成功
|
||||
//兼容用户不传递enableHls、enableMP4参数
|
||||
if (obj.isMember("enableHls")) {
|
||||
option.enable_hls = obj["enableHls"].asBool();
|
||||
if (obj.isMember("enable_hls")) {
|
||||
option.enable_hls = obj["enable_hls"].asBool();
|
||||
}
|
||||
if (obj.isMember("enableMP4")) {
|
||||
option.enable_mp4 = obj["enableMP4"].asBool();
|
||||
if (obj.isMember("enable_mp4")) {
|
||||
option.enable_mp4 = obj["enable_mp4"].asBool();
|
||||
}
|
||||
if (obj.isMember("enable_audio")) {
|
||||
option.enable_audio = obj["enable_audio"].asBool();
|
||||
}
|
||||
if (obj.isMember("add_mute_audio")) {
|
||||
option.add_mute_audio = obj["add_mute_audio"].asBool();
|
||||
}
|
||||
if (obj.isMember("mp4_save_path")) {
|
||||
option.mp4_save_path = obj["mp4_save_path"].asString();
|
||||
}
|
||||
if (obj.isMember("mp4_max_second")) {
|
||||
option.mp4_max_second = obj["mp4_max_second"].asUInt();
|
||||
}
|
||||
if (obj.isMember("hls_save_path")) {
|
||||
option.hls_save_path = obj["hls_save_path"].asString();
|
||||
}
|
||||
invoker(err, option);
|
||||
} else {
|
||||
|
@ -16,8 +16,7 @@ using namespace std;
|
||||
namespace mediakit{
|
||||
|
||||
bool MediaSink::addTrack(const Track::Ptr &track_in) {
|
||||
GET_CONFIG(bool, enabel_audio, General::kEnableAudio);
|
||||
if (!enabel_audio) {
|
||||
if (!_enable_audio) {
|
||||
//关闭音频时,加快单视频流注册速度
|
||||
_max_track_size = 1;
|
||||
if (track_in->getTrackType() == TrackAudio) {
|
||||
@ -169,8 +168,7 @@ void MediaSink::emitAllTrackReady() {
|
||||
|
||||
void MediaSink::onAllTrackReady_l() {
|
||||
//是否添加静音音频
|
||||
GET_CONFIG(bool, add_mute_audio, General::kAddMuteAudio);
|
||||
if (add_mute_audio) {
|
||||
if (_add_mute_audio) {
|
||||
addMuteAudioTrack();
|
||||
}
|
||||
onAllTrackReady();
|
||||
@ -241,8 +239,7 @@ bool MuteAudioMaker::inputFrame(const Frame::Ptr &frame) {
|
||||
}
|
||||
|
||||
bool MediaSink::addMuteAudioTrack() {
|
||||
GET_CONFIG(bool, enabel_audio, General::kEnableAudio);
|
||||
if (!enabel_audio) {
|
||||
if (!_enable_audio) {
|
||||
return false;
|
||||
}
|
||||
if (_track_map.find(TrackAudio) != _track_map.end()) {
|
||||
@ -262,4 +259,16 @@ bool MediaSink::addMuteAudioTrack() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MediaSink::isAllTrackReady() const {
|
||||
return _all_track_ready;
|
||||
}
|
||||
|
||||
void MediaSink::enableAudio(bool flag) {
|
||||
_enable_audio = flag;
|
||||
}
|
||||
|
||||
void MediaSink::enableMuteAudio(bool flag) {
|
||||
_add_mute_audio = flag;
|
||||
}
|
||||
|
||||
}//namespace mediakit
|
||||
|
@ -108,14 +108,17 @@ public:
|
||||
/**
|
||||
* 返回是否所有track已经准备完成
|
||||
*/
|
||||
bool isAllTrackReady() const {
|
||||
return _all_track_ready;
|
||||
}
|
||||
bool isAllTrackReady() const;
|
||||
|
||||
/**
|
||||
* 添加aac静音轨道
|
||||
* 设置是否开启音频
|
||||
*/
|
||||
bool addMuteAudioTrack();
|
||||
void enableAudio(bool flag);
|
||||
|
||||
/**
|
||||
* 设置是否开启添加静音音频
|
||||
*/
|
||||
void enableMuteAudio(bool flag);
|
||||
|
||||
protected:
|
||||
/**
|
||||
@ -147,8 +150,14 @@ private:
|
||||
*/
|
||||
void checkTrackIfReady();
|
||||
void onAllTrackReady_l();
|
||||
/**
|
||||
* 添加aac静音轨道
|
||||
*/
|
||||
bool addMuteAudioTrack();
|
||||
|
||||
private:
|
||||
bool _enable_audio = true;
|
||||
bool _add_mute_audio = true;
|
||||
bool _all_track_ready = false;
|
||||
size_t _max_track_size = 2;
|
||||
std::unordered_map<int, std::pair<Track::Ptr, bool/*got frame*/> > _track_map;
|
||||
|
@ -22,10 +22,15 @@ namespace toolkit {
|
||||
namespace mediakit {
|
||||
|
||||
ProtocolOption::ProtocolOption() {
|
||||
GET_CONFIG(bool, toHls, General::kPublishToHls);
|
||||
GET_CONFIG(bool, toMP4, General::kPublishToMP4);
|
||||
enable_hls = toHls;
|
||||
enable_mp4 = toMP4;
|
||||
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);
|
||||
|
||||
enable_hls = s_to_hls;
|
||||
enable_mp4 = s_to_mp4;
|
||||
enable_audio = s_enabel_audio;
|
||||
add_mute_audio = s_add_mute_audio;
|
||||
}
|
||||
|
||||
static std::shared_ptr<MediaSinkInterface> makeRecorder(MediaSource &sender, const vector<Track::Ptr> &tracks, Recorder::type type, const string &custom_path, size_t max_second){
|
||||
@ -81,13 +86,11 @@ MultiMediaSourceMuxer::MultiMediaSourceMuxer(const string &vhost, const string &
|
||||
if (option.enable_rtsp) {
|
||||
_rtsp = std::make_shared<RtspMediaSourceMuxer>(vhost, app, stream, std::make_shared<TitleSdp>(dur_sec));
|
||||
}
|
||||
|
||||
if (option.enable_hls) {
|
||||
_hls = dynamic_pointer_cast<HlsRecorder>(Recorder::createRecorder(Recorder::type_hls, vhost, app, stream));
|
||||
_hls = dynamic_pointer_cast<HlsRecorder>(Recorder::createRecorder(Recorder::type_hls, vhost, app, stream, option.hls_save_path));
|
||||
}
|
||||
|
||||
if (option.enable_mp4) {
|
||||
_mp4 = Recorder::createRecorder(Recorder::type_mp4, vhost, app, stream);
|
||||
_mp4 = Recorder::createRecorder(Recorder::type_mp4, vhost, app, stream, option.mp4_save_path, option.mp4_max_second);
|
||||
}
|
||||
if (option.enable_ts) {
|
||||
_ts = std::make_shared<TSMediaSourceMuxer>(vhost, app, stream);
|
||||
@ -97,6 +100,10 @@ MultiMediaSourceMuxer::MultiMediaSourceMuxer(const string &vhost, const string &
|
||||
_fmp4 = std::make_shared<FMP4MediaSourceMuxer>(vhost, app, stream);
|
||||
}
|
||||
#endif
|
||||
|
||||
//音频相关设置
|
||||
enableAudio(option.enable_audio);
|
||||
enableMuteAudio(option.add_mute_audio);
|
||||
}
|
||||
|
||||
void MultiMediaSourceMuxer::setMediaListener(const std::weak_ptr<MediaSourceEvent> &listener) {
|
||||
|
@ -39,6 +39,19 @@ public:
|
||||
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;
|
||||
};
|
||||
|
||||
class MultiMediaSourceMuxer : public MediaSourceEventInterceptor, public MediaSink, public std::enable_shared_from_this<MultiMediaSourceMuxer>{
|
||||
|
Loading…
Reference in New Issue
Block a user