mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-05 10:58:11 +08:00
转协议选项抽象为ProtocolOption对象
This commit is contained in:
@@ -76,23 +76,28 @@ public:
|
||||
|
||||
/**
|
||||
* 设置协议转换
|
||||
* @param enableHls 是否转换成hls
|
||||
* @param enableMP4 是否mp4录制
|
||||
*/
|
||||
void setProtocolTranslation(bool enableHls, bool enableMP4) {
|
||||
void setProtocolOption(const ProtocolOption &option) {
|
||||
//不重复生成rtmp
|
||||
_muxer = std::make_shared<MultiMediaSourceMuxer>(getVhost(), getApp(), getId(), _demuxer->getDuration(), true, false, enableHls, enableMP4);
|
||||
_option = option;
|
||||
//不重复生成rtmp协议
|
||||
_option.enable_rtmp = false;
|
||||
_muxer = std::make_shared<MultiMediaSourceMuxer>(getVhost(), getApp(), getId(), _demuxer->getDuration(), _option);
|
||||
_muxer->setMediaListener(getListener());
|
||||
_muxer->setTrackListener(std::static_pointer_cast<RtmpMediaSourceImp>(shared_from_this()));
|
||||
//让_muxer对象拦截一部分事件(比如说录像相关事件)
|
||||
MediaSource::setListener(_muxer);
|
||||
|
||||
for(auto &track : _demuxer->getTracks(false)){
|
||||
for (auto &track : _demuxer->getTracks(false)) {
|
||||
_muxer->addTrack(track);
|
||||
track->addDelegate(_muxer);
|
||||
}
|
||||
}
|
||||
|
||||
const ProtocolOption &getProtocolOption() const {
|
||||
return _option;
|
||||
}
|
||||
|
||||
/**
|
||||
* _demuxer触发的添加Track事件
|
||||
*/
|
||||
@@ -153,6 +158,7 @@ public:
|
||||
private:
|
||||
bool _all_track_ready = false;
|
||||
bool _recreate_metadata = false;
|
||||
ProtocolOption _option;
|
||||
AMFValue _metadata;
|
||||
RtmpDemuxer::Ptr _demuxer;
|
||||
MultiMediaSourceMuxer::Ptr _muxer;
|
||||
|
||||
@@ -135,7 +135,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
|
||||
_media_info.parse(_tc_url + "/" + getStreamId(dec.load<std::string>()));
|
||||
_media_info._schema = RTMP_SCHEMA;
|
||||
|
||||
auto on_res = [this, pToken](const string &err, bool enableHls, bool enableMP4) {
|
||||
auto on_res = [this, pToken](const string &err, const ProtocolOption &option) {
|
||||
if (!err.empty()) {
|
||||
sendStatus({ "level", "error",
|
||||
"code", "NetStream.Publish.BadAuth",
|
||||
@@ -180,7 +180,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
|
||||
_push_src = std::make_shared<RtmpMediaSourceImp>(_media_info._vhost, _media_info._app, _media_info._streamid);
|
||||
//获取所有权
|
||||
_push_src_ownership = _push_src->getOwnership();
|
||||
_push_src->setProtocolTranslation(enableHls, enableMP4);
|
||||
_push_src->setProtocolOption(option);
|
||||
}
|
||||
|
||||
_push_src->setListener(dynamic_pointer_cast<MediaSourceEvent>(shared_from_this()));
|
||||
@@ -195,29 +195,27 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
|
||||
|
||||
if(_media_info._app.empty() || _media_info._streamid.empty()){
|
||||
//不允许莫名其妙的推流url
|
||||
on_res("rtmp推流url非法", false, false);
|
||||
on_res("rtmp推流url非法", ProtocolOption());
|
||||
return;
|
||||
}
|
||||
|
||||
Broadcast::PublishAuthInvoker invoker = [weak_self, on_res, pToken](const string &err, bool enableHls, bool enableMP4) {
|
||||
Broadcast::PublishAuthInvoker invoker = [weak_self, on_res, pToken](const string &err, const ProtocolOption &option) {
|
||||
auto strongSelf = weak_self.lock();
|
||||
if (!strongSelf) {
|
||||
return;
|
||||
}
|
||||
strongSelf->async([weak_self, on_res, err, pToken, enableHls, enableMP4]() {
|
||||
strongSelf->async([weak_self, on_res, err, pToken, option]() {
|
||||
auto strongSelf = weak_self.lock();
|
||||
if (!strongSelf) {
|
||||
return;
|
||||
}
|
||||
on_res(err, enableHls, enableMP4);
|
||||
on_res(err, option);
|
||||
});
|
||||
};
|
||||
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPublish, MediaOriginType::rtmp_push, _media_info, invoker, static_cast<SockInfo &>(*this));
|
||||
if(!flag){
|
||||
//该事件无人监听,默认鉴权成功
|
||||
GET_CONFIG(bool,to_hls,General::kPublishToHls);
|
||||
GET_CONFIG(bool,to_mp4,General::kPublishToMP4);
|
||||
on_res("", to_hls, to_mp4);
|
||||
on_res("", ProtocolOption());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user