Merge branch 'master' of https://github.com/xia-chu/ZLMediaKit into dev

This commit is contained in:
xiongziliang 2021-05-22 10:25:05 +08:00
commit 9f223bc7a2
9 changed files with 38 additions and 10 deletions

@ -1 +1 @@
Subproject commit b678e474f8ba8c9f3e6efd9cec6e4c517e80209d Subproject commit b04d132139399637cbb201c2832dd98dc2786e82

View File

@ -61,6 +61,8 @@ mergeWriteMS=0
modifyStamp=0 modifyStamp=0
#服务器唯一id用于触发hook时区别是哪台服务器 #服务器唯一id用于触发hook时区别是哪台服务器
mediaServerId=your_server_id mediaServerId=your_server_id
#转协议是否全局开启或关闭音频
enable_audio=1
###### 以下是按需转协议的开关在测试ZLMediaKit的接收推流性能时请把下面开关置1 ###### 以下是按需转协议的开关在测试ZLMediaKit的接收推流性能时请把下面开关置1
###### 如果某种协议你用不到你可以把以下开关置1以便节省资源(但是还是可以播放,只是第一个播放者体验稍微差点) ###### 如果某种协议你用不到你可以把以下开关置1以便节省资源(但是还是可以播放,只是第一个播放者体验稍微差点)

View File

@ -281,7 +281,7 @@ static inline string getProxyKey(const string &vhost,const string &app,const str
Value makeMediaSourceJson(MediaSource &media){ Value makeMediaSourceJson(MediaSource &media){
Value item; Value item;
item["schema"] = media.getSchema(); item["schema"] = media.getSchema();
item["vhost"] = media.getVhost(); item[VHOST_KEY] = media.getVhost();
item["app"] = media.getApp(); item["app"] = media.getApp();
item["stream"] = media.getId(); item["stream"] = media.getId();
item["createStamp"] = (Json::UInt64) media.getCreateStamp(); item["createStamp"] = (Json::UInt64) media.getCreateStamp();
@ -292,6 +292,8 @@ Value makeMediaSourceJson(MediaSource &media){
item["originType"] = (int) media.getOriginType(); item["originType"] = (int) media.getOriginType();
item["originTypeStr"] = getOriginTypeString(media.getOriginType()); item["originTypeStr"] = getOriginTypeString(media.getOriginType());
item["originUrl"] = media.getOriginUrl(); item["originUrl"] = media.getOriginUrl();
item["isRecordingMP4"] = media.isRecording(Recorder::type_mp4);
item["isRecordingHLS"] = media.isRecording(Recorder::type_hls);
auto originSock = media.getOriginSock(); auto originSock = media.getOriginSock();
if (originSock) { if (originSock) {
item["originSock"]["local_ip"] = originSock->get_local_ip(); item["originSock"]["local_ip"] = originSock->get_local_ip();

View File

@ -113,6 +113,17 @@ const char *getContentType(const HttpArgs &value){
return "application/x-www-form-urlencoded"; return "application/x-www-form-urlencoded";
} }
string getVhost(const Value &value) {
const char *key = VHOST_KEY;
auto val = value.find(key, key + sizeof(VHOST_KEY) - 1);
return val ? val->asString() : "";
}
string getVhost(const HttpArgs &value) {
auto val = value.find(VHOST_KEY);
return val != value.end() ? val->second : "";
}
void do_http_hook(const string &url,const ArgsType &body,const function<void(const Value &,const string &)> &func){ void do_http_hook(const string &url,const ArgsType &body,const function<void(const Value &,const string &)> &func){
GET_CONFIG(string, mediaServerId, General::kMediaServerId); GET_CONFIG(string, mediaServerId, General::kMediaServerId);
GET_CONFIG(float, hook_timeoutSec, Hook::kTimeoutSec); GET_CONFIG(float, hook_timeoutSec, Hook::kTimeoutSec);
@ -123,6 +134,10 @@ void do_http_hook(const string &url,const ArgsType &body,const function<void(con
auto bodyStr = to_string(body); auto bodyStr = to_string(body);
requester->setBody(bodyStr); requester->setBody(bodyStr);
requester->addHeader("Content-Type", getContentType(body)); requester->addHeader("Content-Type", getContentType(body));
auto vhost = getVhost(body);
if (!vhost.empty()) {
requester->addHeader("X-VHOST", vhost);
}
std::shared_ptr<Ticker> pTicker(new Ticker); std::shared_ptr<Ticker> pTicker(new Ticker);
requester->startRequester(url, [url, func, bodyStr, requester, pTicker](const SockException &ex, requester->startRequester(url, [url, func, bodyStr, requester, pTicker](const SockException &ex,
const string &status, const string &status,
@ -147,7 +162,7 @@ void do_http_hook(const string &url,const ArgsType &body,const function<void(con
static ArgsType make_json(const MediaInfo &args){ static ArgsType make_json(const MediaInfo &args){
ArgsType body; ArgsType body;
body["schema"] = args._schema; body["schema"] = args._schema;
body["vhost"] = args._vhost; body[VHOST_KEY] = args._vhost;
body["app"] = args._app; body["app"] = args._app;
body["stream"] = args._streamid; body["stream"] = args._streamid;
body["params"] = args._param_strs; body["params"] = args._param_strs;
@ -306,7 +321,7 @@ void installWebHook(){
body["regist"] = bRegist; body["regist"] = bRegist;
} else { } else {
body["schema"] = sender.getSchema(); body["schema"] = sender.getSchema();
body["vhost"] = sender.getVhost(); body[VHOST_KEY] = sender.getVhost();
body["app"] = sender.getApp(); body["app"] = sender.getApp();
body["stream"] = sender.getId(); body["stream"] = sender.getId();
body["regist"] = bRegist; body["regist"] = bRegist;
@ -342,7 +357,7 @@ void installWebHook(){
body["url"] = info.url; body["url"] = info.url;
body["app"] = info.app; body["app"] = info.app;
body["stream"] = info.stream; body["stream"] = info.stream;
body["vhost"] = info.vhost; body[VHOST_KEY] = info.vhost;
return body; return body;
}; };
@ -394,7 +409,7 @@ void installWebHook(){
ArgsType body; ArgsType body;
body["schema"] = sender.getSchema(); body["schema"] = sender.getSchema();
body["vhost"] = sender.getVhost(); body[VHOST_KEY] = sender.getVhost();
body["app"] = sender.getApp(); body["app"] = sender.getApp();
body["stream"] = sender.getId(); body["stream"] = sender.getId();
weak_ptr<MediaSource> weakSrc = sender.shared_from_this(); weak_ptr<MediaSource> weakSrc = sender.shared_from_this();

View File

@ -22,6 +22,11 @@ static size_t constexpr kMaxUnreadyFrame = 100;
namespace mediakit{ namespace mediakit{
void MediaSink::addTrack(const Track::Ptr &track_in) { void MediaSink::addTrack(const Track::Ptr &track_in) {
GET_CONFIG(bool, enabel_audio, General::kEnableAudio);
if (!enabel_audio && track_in->getTrackType() == TrackAudio) {
//音频被全局忽略
return;
}
lock_guard<recursive_mutex> lck(_mtx); lock_guard<recursive_mutex> lck(_mtx);
if (_all_track_ready) { if (_all_track_ready) {
WarnL << "all track is ready, add this track too late!"; WarnL << "all track is ready, add this track too late!";

View File

@ -74,6 +74,7 @@ const string kRtspDemand = GENERAL_FIELD"rtsp_demand";
const string kRtmpDemand = GENERAL_FIELD"rtmp_demand"; const string kRtmpDemand = GENERAL_FIELD"rtmp_demand";
const string kTSDemand = GENERAL_FIELD"ts_demand"; const string kTSDemand = GENERAL_FIELD"ts_demand";
const string kFMP4Demand = GENERAL_FIELD"fmp4_demand"; const string kFMP4Demand = GENERAL_FIELD"fmp4_demand";
const string kEnableAudio = GENERAL_FIELD"enable_audio";
onceToken token([](){ onceToken token([](){
mINI::Instance()[kFlowThreshold] = 1024; mINI::Instance()[kFlowThreshold] = 1024;
@ -92,6 +93,7 @@ onceToken token([](){
mINI::Instance()[kRtmpDemand] = 0; mINI::Instance()[kRtmpDemand] = 0;
mINI::Instance()[kTSDemand] = 0; mINI::Instance()[kTSDemand] = 0;
mINI::Instance()[kFMP4Demand] = 0; mINI::Instance()[kFMP4Demand] = 0;
mINI::Instance()[kEnableAudio] = 1;
},nullptr); },nullptr);

View File

@ -187,6 +187,8 @@ extern const string kRtspDemand;
extern const string kRtmpDemand; extern const string kRtmpDemand;
extern const string kTSDemand; extern const string kTSDemand;
extern const string kFMP4Demand; extern const string kFMP4Demand;
//转协议是否全局开启或忽略音频
extern const string kEnableAudio;
}//namespace General }//namespace General

View File

@ -21,8 +21,7 @@ HttpRequester::~HttpRequester(){
ssize_t HttpRequester::onResponseHeader(const string &status,const HttpHeader &headers) { ssize_t HttpRequester::onResponseHeader(const string &status,const HttpHeader &headers) {
_strRecvBody.clear(); _strRecvBody.clear();
//无Content-Length字段时默认后面没有content return HttpClientImp::onResponseHeader(status, headers);
return 0;
} }
void HttpRequester::onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) { void HttpRequester::onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) {

View File

@ -213,6 +213,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
} }
auto full_url = parser.FullUrl(); auto full_url = parser.FullUrl();
_content_base = full_url;
if (end_with(full_url, ".sdp")) { if (end_with(full_url, ".sdp")) {
//去除.sdp后缀防止EasyDarwin推流器强制添加.sdp后缀 //去除.sdp后缀防止EasyDarwin推流器强制添加.sdp后缀
full_url = full_url.substr(0, full_url.length() - 4); full_url = full_url.substr(0, full_url.length() - 4);
@ -252,7 +253,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
_push_src->setListener(dynamic_pointer_cast<MediaSourceEvent>(shared_from_this())); _push_src->setListener(dynamic_pointer_cast<MediaSourceEvent>(shared_from_this()));
_push_src->setProtocolTranslation(enableHls, enableMP4); _push_src->setProtocolTranslation(enableHls, enableMP4);
_push_src->setSdp(sdpParser.toString()); _push_src->setSdp(sdpParser.toString());
sendRtspResponse("200 OK", {"Content-Base", _content_base + "/"}); sendRtspResponse("200 OK");
}; };
weak_ptr<RtspSession> weakSelf = dynamic_pointer_cast<RtspSession>(shared_from_this()); weak_ptr<RtspSession> weakSelf = dynamic_pointer_cast<RtspSession>(shared_from_this());
@ -613,7 +614,7 @@ void RtspSession::send_SessionNotFound() {
void RtspSession::handleReq_Setup(const Parser &parser) { void RtspSession::handleReq_Setup(const Parser &parser) {
//处理setup命令该函数可能进入多次 //处理setup命令该函数可能进入多次
int trackIdx = getTrackIndexByControlUrl(parser.Url()); int trackIdx = getTrackIndexByControlUrl(parser.FullUrl());
SdpTrack::Ptr &trackRef = _sdp_track[trackIdx]; SdpTrack::Ptr &trackRef = _sdp_track[trackIdx];
if (trackRef->_inited) { if (trackRef->_inited) {
//已经初始化过该Track //已经初始化过该Track