From 68d29ba0252808b56ef5a7061d593b0f02dd88b7 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Mon, 14 Oct 2019 16:52:15 +0800 Subject: [PATCH 01/13] =?UTF-8?q?rtsp=E5=BF=BD=E7=95=A5=E6=97=A0=E6=95=88?= =?UTF-8?q?=E7=9A=84aac=20track?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Extension/Factory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Extension/Factory.cpp b/src/Extension/Factory.cpp index 763ba27c..d65dbb56 100644 --- a/src/Extension/Factory.cpp +++ b/src/Extension/Factory.cpp @@ -41,8 +41,8 @@ Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) { aac_cfg_str = FindField(track->_fmtp.data(), "config=", ";"); } if (aac_cfg_str.empty()) { - //延后获取adts头 - return std::make_shared(); + //如果sdp中获取不到aac config信息,那么在rtp也无法获取,那么忽略该Track + return nullptr; } string aac_cfg; From f816ea172788f7064a096d052f6544163ab11178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=A5=9A?= <771730766@qq.com> Date: Tue, 15 Oct 2019 18:23:14 +0800 Subject: [PATCH 02/13] Create FUNDING.yml --- .github/FUNDING.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..6aa69528 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms + + +custom: ['https://www.paypal.me/xiachu'] From 065b2cf678750d3299ead59217a445a5662ddd45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=A5=9A?= <771730766@qq.com> Date: Tue, 15 Oct 2019 18:49:35 +0800 Subject: [PATCH 03/13] Update FUNDING.yml --- .github/FUNDING.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 6aa69528..4bf33d7a 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,4 +1,5 @@ # These are supported funding model platforms - - custom: ['https://www.paypal.me/xiachu'] +ko_fi: xiachu +issuehunt: xiongziliang +liberapay: xiachu From 82098a284c4528b609864f89a71ed015c3cd6c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=A5=9A?= <771730766@qq.com> Date: Wed, 16 Oct 2019 10:40:19 +0800 Subject: [PATCH 04/13] Update .gitattributes --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitattributes b/.gitattributes index 292d29d3..b6649863 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,4 @@ release/ filter=lfs diff=lfs merge=lfs -text *.a filter=lfs diff=lfs merge=lfs -text +*.h linguist-language=cpp +*.c linguist-language=cpp From 3bad329f09437e765d2cbb81d8f3c5461233d923 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Wed, 16 Oct 2019 11:10:20 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E4=BF=AE=E5=A4=8DresetTracks=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8B=20MP4=E5=BD=95=E5=88=B6=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MediaFile/MP4Recorder.cpp | 8 ++++++++ src/MediaFile/MP4Recorder.h | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/src/MediaFile/MP4Recorder.cpp b/src/MediaFile/MP4Recorder.cpp index 658243c9..0f36561c 100644 --- a/src/MediaFile/MP4Recorder.cpp +++ b/src/MediaFile/MP4Recorder.cpp @@ -153,6 +153,14 @@ void MP4Recorder::onTrackReady(const Track::Ptr & track){ } } +void MP4Recorder::resetTracks() { + closeFile(); + _tracks.clear(); + _haveVideo = false; + _createFileTicker.resetTime(); + MediaSink::resetTracks(); +} + } /* namespace mediakit */ diff --git a/src/MediaFile/MP4Recorder.h b/src/MediaFile/MP4Recorder.h index ca97cb3f..0c619461 100644 --- a/src/MediaFile/MP4Recorder.h +++ b/src/MediaFile/MP4Recorder.h @@ -63,6 +63,11 @@ public: const string &strApp, const string &strStreamId); virtual ~MP4Recorder(); + + /** + * 重置所有Track + */ + void resetTracks() override; private: /** * 某Track输出frame,在onAllTrackReady触发后才会调用此方法 From 67d2beb52a1e04434ec1411c8b9af05c2502cd30 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 18 Oct 2019 09:51:20 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=84=EF=BC=8C?= =?UTF-8?q?http=E6=96=87=E4=BB=B6=E6=9C=8D=E5=8A=A1=E5=99=A8=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E8=AE=BF=E9=97=AE=E6=A0=B9=E7=9B=AE=E5=BD=95=E7=88=B6?= =?UTF-8?q?=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpart/ZLToolKit | 2 +- server/FFmpegSource.cpp | 4 ++-- src/Common/config.cpp | 2 +- src/Http/HttpSession.cpp | 7 ++----- src/MediaFile/MediaReader.cpp | 5 +++-- src/MediaFile/MediaRecorder.cpp | 15 +++++++++------ 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index 665f53b6..ace77b13 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit 665f53b6a4385e2312d3bf09aa305d7e3bf079e6 +Subproject commit ace77b132039d6ef8a97b6dad92115f88821bc45 diff --git a/server/FFmpegSource.cpp b/server/FFmpegSource.cpp index 90805cd5..536bd63d 100644 --- a/server/FFmpegSource.cpp +++ b/server/FFmpegSource.cpp @@ -39,7 +39,7 @@ const char kLog[] = FFmpeg_FIELD"log"; onceToken token([]() { mINI::Instance()[kBin] = trim(System::execute("which ffmpeg")); mINI::Instance()[kCmd] = "%s -i %s -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s"; - mINI::Instance()[kLog] = exeDir() + "ffmpeg/ffmpeg.log"; + mINI::Instance()[kLog] = "./ffmpeg/ffmpeg.log"; }); } @@ -64,7 +64,7 @@ void FFmpegSource::play(const string &src_url,const string &dst_url,int timeout_ char cmd[1024] = {0}; snprintf(cmd, sizeof(cmd),ffmpeg_cmd.data(),ffmpeg_bin.data(),src_url.data(),dst_url.data()); - _process.run(cmd,ffmpeg_log); + _process.run(cmd,File::absolutePath("",true,ffmpeg_log)); InfoL << cmd; if(_media_info._host == "127.0.0.1"){ diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 1f6763ac..15540bcd 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -122,7 +122,7 @@ const string kMaxReqCount = HTTP_FIELD"maxReqCount"; const string kCharSet = HTTP_FIELD"charSet"; //http 服务器根目录 -#define HTTP_ROOT_PATH (exeDir() + "httpRoot") +#define HTTP_ROOT_PATH "./httpRoot" const string kRootPath = HTTP_FIELD"rootPath"; //http 404错误提示内容 diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 02283d04..b794c731 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -375,10 +375,7 @@ static bool checkHls(BroadcastHttpAccessArgs){ return NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed,args_copy,mediaAuthInvoker,sender); } -void HttpSession::canAccessPath(const string &path_in,bool is_dir,const function &callback_in){ - auto path = path_in; - replace(const_cast(path),"//","/"); - +void HttpSession::canAccessPath(const string &path,bool is_dir,const function &callback_in){ auto callback = [callback_in,this](const string &errMsg,const HttpServerCookie::Ptr &cookie){ try { callback_in(errMsg,cookie); @@ -507,7 +504,7 @@ void HttpSession::Handle_Req_GET(int64_t &content_len) { GET_CONFIG(uint32_t,reqCnt,Http::kMaxReqCount); GET_CONFIG(bool,enableVhost,General::kEnableVhost); GET_CONFIG(string,rootPath,Http::kRootPath); - string strFile = enableVhost ? rootPath + "/" + _mediaInfo._vhost + _parser.Url() :rootPath + _parser.Url(); + auto strFile = File::absolutePath(enableVhost ? _mediaInfo._vhost + _parser.Url() : _parser.Url(), false, rootPath); bool bClose = (strcasecmp(_parser["Connection"].data(),"close") == 0) || ( ++_iReqCnt > reqCnt); do{ diff --git a/src/MediaFile/MediaReader.cpp b/src/MediaFile/MediaReader.cpp index 22683b4e..4bcdcfc7 100644 --- a/src/MediaFile/MediaReader.cpp +++ b/src/MediaFile/MediaReader.cpp @@ -44,10 +44,11 @@ MediaReader::MediaReader(const string &strVhost,const string &strApp, const stri GET_CONFIG(string,recordPath,Record::kFilePath); GET_CONFIG(bool,enableVhost,General::kEnableVhost); if(enableVhost){ - strFileName = recordPath + "/" + strVhost + "/" + strApp + "/" + strId; + strFileName = strVhost + "/" + strApp + "/" + strId; }else{ - strFileName = recordPath + "/" + strApp + "/" + strId; + strFileName = strApp + "/" + strId; } + strFileName = File::absolutePath(strFileName,true,recordPath); } _hMP4File = MP4Read(strFileName.data()); diff --git a/src/MediaFile/MediaRecorder.cpp b/src/MediaFile/MediaRecorder.cpp index 3f348778..467f33cb 100644 --- a/src/MediaFile/MediaRecorder.cpp +++ b/src/MediaFile/MediaRecorder.cpp @@ -56,13 +56,15 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp, #if defined(ENABLE_HLS) if(enableHls) { string m3u8FilePath; + string params; if(enableVhost){ - m3u8FilePath = hlsPath + "/" + strVhost + "/" + strApp + "/" + strId + "/hls.m3u8"; - _hlsRecorder.reset(new HlsRecorder(m3u8FilePath,string(VHOST_KEY) + "=" + strVhost ,hlsBufSize, hlsDuration, hlsNum)); + m3u8FilePath = strVhost + "/" + strApp + "/" + strId + "/hls.m3u8"; + params = string(VHOST_KEY) + "=" + strVhost; }else{ - m3u8FilePath = hlsPath + "/" + strApp + "/" + strId + "/hls.m3u8"; - _hlsRecorder.reset(new HlsRecorder(m3u8FilePath,"",hlsBufSize, hlsDuration, hlsNum)); + m3u8FilePath = strApp + "/" + strId + "/hls.m3u8"; } + m3u8FilePath = File::absolutePath(m3u8FilePath,true,hlsPath); + _hlsRecorder.reset(new HlsRecorder(m3u8FilePath,params,hlsBufSize, hlsDuration, hlsNum)); } #endif //defined(ENABLE_HLS) @@ -73,10 +75,11 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp, if(enableMp4){ string mp4FilePath; if(enableVhost){ - mp4FilePath = recordPath + "/" + strVhost + "/" + recordAppName + "/" + strApp + "/" + strId + "/"; + mp4FilePath = strVhost + "/" + recordAppName + "/" + strApp + "/" + strId + "/"; } else { - mp4FilePath = recordPath + "/" + recordAppName + "/" + strApp + "/" + strId + "/"; + mp4FilePath = recordAppName + "/" + strApp + "/" + strId + "/"; } + mp4FilePath = File::absolutePath(mp4FilePath,true,recordPath); _mp4Recorder.reset(new MP4Recorder(mp4FilePath,strVhost,strApp,strId)); } #endif //defined(ENABLE_MP4RECORD) From 0f5582689b07f368f7d0e87c5b903590998eef53 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 18 Oct 2019 09:58:22 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E8=B6=8A=E6=9D=83?= =?UTF-8?q?=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/FFmpegSource.cpp | 2 +- src/MediaFile/MediaReader.cpp | 2 +- src/MediaFile/MediaRecorder.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/FFmpegSource.cpp b/server/FFmpegSource.cpp index 536bd63d..8d348453 100644 --- a/server/FFmpegSource.cpp +++ b/server/FFmpegSource.cpp @@ -64,7 +64,7 @@ void FFmpegSource::play(const string &src_url,const string &dst_url,int timeout_ char cmd[1024] = {0}; snprintf(cmd, sizeof(cmd),ffmpeg_cmd.data(),ffmpeg_bin.data(),src_url.data(),dst_url.data()); - _process.run(cmd,File::absolutePath("",true,ffmpeg_log)); + _process.run(cmd,File::absolutePath("",false,ffmpeg_log)); InfoL << cmd; if(_media_info._host == "127.0.0.1"){ diff --git a/src/MediaFile/MediaReader.cpp b/src/MediaFile/MediaReader.cpp index 4bcdcfc7..09d18659 100644 --- a/src/MediaFile/MediaReader.cpp +++ b/src/MediaFile/MediaReader.cpp @@ -48,7 +48,7 @@ MediaReader::MediaReader(const string &strVhost,const string &strApp, const stri }else{ strFileName = strApp + "/" + strId; } - strFileName = File::absolutePath(strFileName,true,recordPath); + strFileName = File::absolutePath(strFileName, false,recordPath); } _hMP4File = MP4Read(strFileName.data()); diff --git a/src/MediaFile/MediaRecorder.cpp b/src/MediaFile/MediaRecorder.cpp index 467f33cb..6ec9ae41 100644 --- a/src/MediaFile/MediaRecorder.cpp +++ b/src/MediaFile/MediaRecorder.cpp @@ -63,7 +63,7 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp, }else{ m3u8FilePath = strApp + "/" + strId + "/hls.m3u8"; } - m3u8FilePath = File::absolutePath(m3u8FilePath,true,hlsPath); + m3u8FilePath = File::absolutePath(m3u8FilePath,false,hlsPath); _hlsRecorder.reset(new HlsRecorder(m3u8FilePath,params,hlsBufSize, hlsDuration, hlsNum)); } #endif //defined(ENABLE_HLS) @@ -79,7 +79,7 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp, } else { mp4FilePath = recordAppName + "/" + strApp + "/" + strId + "/"; } - mp4FilePath = File::absolutePath(mp4FilePath,true,recordPath); + mp4FilePath = File::absolutePath(mp4FilePath,false,recordPath); _mp4Recorder.reset(new MP4Recorder(mp4FilePath,strVhost,strApp,strId)); } #endif //defined(ENABLE_MP4RECORD) From 0aa28b284823d74e6a3a3c01bfff1e43b58cd0e1 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 18 Oct 2019 10:02:42 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpart/ZLToolKit | 2 +- server/FFmpegSource.cpp | 2 +- src/Http/HttpSession.cpp | 2 +- src/MediaFile/MediaReader.cpp | 2 +- src/MediaFile/MediaRecorder.cpp | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index ace77b13..1f99a167 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit ace77b132039d6ef8a97b6dad92115f88821bc45 +Subproject commit 1f99a1679dd9136edc3e3b64edcc2c74ad7bd259 diff --git a/server/FFmpegSource.cpp b/server/FFmpegSource.cpp index 8d348453..e55e6dbb 100644 --- a/server/FFmpegSource.cpp +++ b/server/FFmpegSource.cpp @@ -64,7 +64,7 @@ void FFmpegSource::play(const string &src_url,const string &dst_url,int timeout_ char cmd[1024] = {0}; snprintf(cmd, sizeof(cmd),ffmpeg_cmd.data(),ffmpeg_bin.data(),src_url.data(),dst_url.data()); - _process.run(cmd,File::absolutePath("",false,ffmpeg_log)); + _process.run(cmd,File::absolutePath("",ffmpeg_log)); InfoL << cmd; if(_media_info._host == "127.0.0.1"){ diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index b794c731..32765c84 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -504,7 +504,7 @@ void HttpSession::Handle_Req_GET(int64_t &content_len) { GET_CONFIG(uint32_t,reqCnt,Http::kMaxReqCount); GET_CONFIG(bool,enableVhost,General::kEnableVhost); GET_CONFIG(string,rootPath,Http::kRootPath); - auto strFile = File::absolutePath(enableVhost ? _mediaInfo._vhost + _parser.Url() : _parser.Url(), false, rootPath); + auto strFile = File::absolutePath(enableVhost ? _mediaInfo._vhost + _parser.Url() : _parser.Url(),rootPath); bool bClose = (strcasecmp(_parser["Connection"].data(),"close") == 0) || ( ++_iReqCnt > reqCnt); do{ diff --git a/src/MediaFile/MediaReader.cpp b/src/MediaFile/MediaReader.cpp index 09d18659..eae430bd 100644 --- a/src/MediaFile/MediaReader.cpp +++ b/src/MediaFile/MediaReader.cpp @@ -48,7 +48,7 @@ MediaReader::MediaReader(const string &strVhost,const string &strApp, const stri }else{ strFileName = strApp + "/" + strId; } - strFileName = File::absolutePath(strFileName, false,recordPath); + strFileName = File::absolutePath(strFileName,recordPath); } _hMP4File = MP4Read(strFileName.data()); diff --git a/src/MediaFile/MediaRecorder.cpp b/src/MediaFile/MediaRecorder.cpp index 6ec9ae41..e422b6e5 100644 --- a/src/MediaFile/MediaRecorder.cpp +++ b/src/MediaFile/MediaRecorder.cpp @@ -63,7 +63,7 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp, }else{ m3u8FilePath = strApp + "/" + strId + "/hls.m3u8"; } - m3u8FilePath = File::absolutePath(m3u8FilePath,false,hlsPath); + m3u8FilePath = File::absolutePath(m3u8FilePath,hlsPath); _hlsRecorder.reset(new HlsRecorder(m3u8FilePath,params,hlsBufSize, hlsDuration, hlsNum)); } #endif //defined(ENABLE_HLS) @@ -79,7 +79,7 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp, } else { mp4FilePath = recordAppName + "/" + strApp + "/" + strId + "/"; } - mp4FilePath = File::absolutePath(mp4FilePath,false,recordPath); + mp4FilePath = File::absolutePath(mp4FilePath,recordPath); _mp4Recorder.reset(new MP4Recorder(mp4FilePath,strVhost,strApp,strId)); } #endif //defined(ENABLE_MP4RECORD) From a4dab8767f509f6629c7244833bedf59a3dca781 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 18 Oct 2019 10:06:18 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=9B=B8=E5=AF=B9?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/config.ini | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/conf/config.ini b/conf/config.ini index 28112f69..cbbcb96d 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -6,12 +6,13 @@ apiDebug=1 secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc [ffmpeg] -#FFmpeg可执行程序路径 +#FFmpeg可执行程序绝对路径 bin=/usr/local/bin/ffmpeg #FFmpeg拉流再推流的命令模板,通过该模板可以设置再编码的一些参数 cmd=%s -i %s -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s #FFmpeg日志的路径,如果置空则不生成FFmpeg日志 -log=/Users/xzl/git/ZLMediaKit/release/mac/Release/ffmpeg/ffmpeg.log +#可以为相对(相对于本可执行程序目录)或绝对路径 +log=./ffmpeg/ffmpeg.log [general] #是否启用虚拟主机 @@ -40,7 +41,8 @@ resetWhenRePlay=1 #hls写文件的buf大小,调整参数可以提高文件io性能 fileBufSize=65536 #hls保存文件路径 -filePath=/Users/xzl/git/ZLMediaKit/release/mac/Release/httpRoot +#可以为相对(相对于本可执行程序目录)或绝对路径 +filePath=./httpRoot #hls最大切片时间 segDur=3 #m3u8索引中,hls保留切片个数(实际保留切片个数大2~3个) @@ -93,7 +95,8 @@ notFound=404 Not Found Date: Mon, 21 Oct 2019 09:03:11 +0800 Subject: [PATCH 10/13] =?UTF-8?q?=E6=9B=B4=E6=96=B0ZLToolKit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpart/ZLToolKit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index 1f99a167..4a6029b7 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit 1f99a1679dd9136edc3e3b64edcc2c74ad7bd259 +Subproject commit 4a6029b74b4f2339e32b8c546388de51e4ec1bcb From a739bd7304198da31470c50b6912bb1aeb87d8dc Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Wed, 23 Oct 2019 12:00:53 +0800 Subject: [PATCH 11/13] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/HttpSession.cpp | 32 ++++++++++++++++++++++---------- src/Http/HttpSession.h | 1 + src/Rtmp/RtmpSession.cpp | 8 ++++++-- src/Rtsp/RtspSession.cpp | 9 +++++++-- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 32765c84..e9ab7e81 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -169,21 +169,32 @@ void HttpSession::onRecv(const Buffer::Ptr &pBuf) { } void HttpSession::onError(const SockException& err) { + if(_is_flv_stream){ + //flv播放器 + WarnP(this) << "播放器(" + << _mediaInfo._vhost << "/" + << _mediaInfo._app << "/" + << _mediaInfo._streamid + << ")断开:" << err.what(); + + GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold); + if(_ui64TotalBytes > iFlowThreshold * 1024){ + NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, + _mediaInfo, + _ui64TotalBytes, + _ticker.createdTime()/1000, + true, + *this); + } + return; + } + + //http客户端 if(_ticker.createdTime() < 10 * 1000){ TraceP(this) << err.what(); }else{ WarnP(this) << err.what(); } - - GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold); - if(_ui64TotalBytes > iFlowThreshold * 1024){ - NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, - _mediaInfo, - _ui64TotalBytes, - _ticker.createdTime()/1000, - true, - *this); - } } void HttpSession::onManager() { @@ -291,6 +302,7 @@ bool HttpSession::checkLiveFlvStream(const function &cb){ try{ start(getPoller(),rtmp_src); + _is_flv_stream = true; }catch (std::exception &ex){ //该rtmp源不存在 shutdown(SockException(Err_shutdown,"rtmp mediasource released")); diff --git a/src/Http/HttpSession.h b/src/Http/HttpSession.h index e6199668..19445780 100644 --- a/src/Http/HttpSession.h +++ b/src/Http/HttpSession.h @@ -160,6 +160,7 @@ private: //处理content数据的callback function _contentCallBack; bool _flv_over_websocket = false; + bool _is_flv_stream = false; }; diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index 2cd38528..62787b1d 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -44,13 +44,17 @@ RtmpSession::~RtmpSession() { } void RtmpSession::onError(const SockException& err) { - WarnP(this) << err.what(); + bool isPlayer = !_pPublisherSrc; + WarnP(this) << (isPlayer ? "播放器(" : "推流器(") + << _mediaInfo._vhost << "/" + << _mediaInfo._app << "/" + << _mediaInfo._streamid + << ")断开:" << err.what(); //流量统计事件广播 GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold); if(_ui64TotalBytes > iFlowThreshold * 1024){ - bool isPlayer = !_pPublisherSrc; NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index efd0dc7e..3985ebec 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -85,7 +85,13 @@ RtspSession::~RtspSession() { } void RtspSession::onError(const SockException& err) { - WarnP(this) << err.what(); + bool isPlayer = !_pushSrc; + WarnP(this) << (isPlayer ? "播放器(" : "推流器(") + << _mediaInfo._vhost << "/" + << _mediaInfo._app << "/" + << _mediaInfo._streamid + << ")断开:" << err.what(); + if (_rtpType == Rtsp::RTP_MULTICAST) { //取消UDP端口监听 UDPServer::Instance().stopListenPeer(get_peer_ip().data(), this); @@ -100,7 +106,6 @@ void RtspSession::onError(const SockException& err) { //流量统计事件广播 GET_CONFIG(uint32_t,iFlowThreshold,General::kFlowThreshold); if(_ui64TotalBytes > iFlowThreshold * 1024){ - bool isPlayer = !_pushSrc; NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _ui64TotalBytes, From 1f89a868923a53a7eb5265a54a55a594029774ed Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Thu, 24 Oct 2019 11:21:55 +0800 Subject: [PATCH 12/13] =?UTF-8?q?=E6=96=B0=E5=A2=9EgetWorkThreadsLoad?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 3209b439..6a040011 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -45,6 +45,7 @@ #include "Util/MD5.h" #include "WebApi.h" #include "WebHook.h" +#include "Thread/WorkThreadPool.h" #if !defined(_WIN32) #include "FFmpegSource.h" @@ -281,6 +282,23 @@ void installWebApi() { }); }); + //获取后台工作线程负载 + //测试url http://127.0.0.1/index/api/getWorkThreadsLoad + API_REGIST_INVOKER(api, getWorkThreadsLoad, { + WorkThreadPool::Instance().getExecutorDelay([invoker, headerOut](const vector &vecDelay) { + Value val; + auto vec = WorkThreadPool::Instance().getExecutorLoad(); + int i = 0; + for (auto load : vec) { + Value obj(objectValue); + obj["load"] = load; + obj["delay"] = vecDelay[i++]; + val["data"].append(obj); + } + invoker("200 OK", headerOut, val.toStyledString()); + }); + }); + //获取服务器配置 //测试url http://127.0.0.1/index/api/getServerConfig API_REGIST(api, getServerConfig, { From 8e48ab3463cdb232c7ad34c1296f6d8f38c5e5fc Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Thu, 24 Oct 2019 11:42:39 +0800 Subject: [PATCH 13/13] =?UTF-8?q?=E8=A7=A3=E5=86=B3defunct=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/Process.cpp | 107 ++++++++++++++++++++++++++++----------------- server/Process.h | 2 +- 2 files changed, 69 insertions(+), 40 deletions(-) diff --git a/server/Process.cpp b/server/Process.cpp index 3b67145a..e215dc81 100644 --- a/server/Process.cpp +++ b/server/Process.cpp @@ -34,9 +34,8 @@ #include "Util/File.h" #include "Util/logger.h" #include "Util/uv_errno.h" -#include "Util/TimeTicker.h" +#include "Thread/WorkThreadPool.h" #include "Process.h" -#include "Poller/Timer.h" using namespace toolkit; void Process::run(const string &cmd, const string &log_file_tmp) { @@ -46,12 +45,11 @@ void Process::run(const string &cmd, const string &log_file_tmp) { throw std::runtime_error(StrPrinter << "fork child process falied,err:" << get_uv_errmsg()); } if (_pid == 0) { - //子进程 - //子进程关闭core文件生成 struct rlimit rlim = {0,0}; setrlimit(RLIMIT_CORE, &rlim); + //在启动子进程时,暂时禁用SIGINT、SIGTERM信号 // ignore the SIGINT and SIGTERM signal(SIGINT, SIG_IGN); signal(SIGTERM, SIG_IGN); @@ -109,24 +107,73 @@ void Process::run(const string &cmd, const string &log_file_tmp) { InfoL << "start child proces " << _pid; } -void Process::kill(int max_delay) { + +/** + * 获取进程是否存活状态 + * @param pid 进程号 + * @param exit_code_ptr 进程返回代码 + * @param block 是否阻塞等待 + * @return 进程是否还在运行 + */ +static bool s_wait(pid_t pid,int *exit_code_ptr,bool block) { + if (pid <= 0) { + return false; + } + int status = 0; + pid_t p = waitpid(pid, &status, block ? 0 : WNOHANG); + int exit_code = (status & 0xFF00) >> 8; + if(exit_code_ptr){ + *exit_code_ptr = (status & 0xFF00) >> 8; + } + if (p < 0) { + WarnL << "waitpid failed, pid=" << pid << ", err=" << get_uv_errmsg(); + return false; + } + if (p > 0) { + InfoL << "process terminated, pid=" << pid << ", exit code=" << exit_code; + return false; + } + //WarnL << "process is running, pid=" << _pid; + return true; +} + +static void s_kill(pid_t pid,int max_delay,bool force){ + if (pid <= 0) { + //pid无效 + return; + } + + if (::kill(pid, force ? SIGKILL : SIGTERM) == -1) { + //进程可能已经退出了 + WarnL << "kill process " << pid << " failed:" << get_uv_errmsg(); + return; + } + + if(force){ + //发送SIGKILL信号后,阻塞等待退出 + s_wait(pid, NULL, true); + DebugL << "force kill " << pid << " success!"; + return; + } + + //发送SIGTERM信号后,2秒后检查子进程是否已经退出 + WorkThreadPool::Instance().getPoller()->doDelayTask(max_delay,[pid](){ + if (!s_wait(pid, nullptr, false)) { + //进程已经退出了 + return 0; + } + //进程还在运行 + WarnL << "process still working,force kill it:" << pid; + s_kill(pid,0, true); + return 0; + }); +} + +void Process::kill(int max_delay,bool force) { if (_pid <= 0) { return; } - if (::kill(_pid, SIGTERM) == -1) { - WarnL << "kill process " << _pid << " falied,err:" << get_uv_errmsg(); - } else { - //等待子进程退出 - auto pid = _pid; - EventPollerPool::Instance().getPoller()->doDelayTask(max_delay,[pid](){ - //最多等待2秒,2秒后强制杀掉程序 - if (waitpid(pid, NULL, WNOHANG) == 0) { - ::kill(pid, SIGKILL); - WarnL << "force kill process " << pid; - } - return 0; - }); - } + s_kill(_pid,max_delay,force); _pid = -1; } @@ -134,28 +181,10 @@ Process::~Process() { kill(2000); } -Process::Process() { -} +Process::Process() {} bool Process::wait(bool block) { - if (_pid <= 0) { - return false; - } - int status = 0; - pid_t p = waitpid(_pid, &status, block ? 0 : WNOHANG); - - _exit_code = (status & 0xFF00) >> 8; - if (p < 0) { - WarnL << "waitpid failed, pid=" << _pid << ", err=" << get_uv_errmsg(); - return false; - } - if (p > 0) { - InfoL << "process terminated, pid=" << _pid << ", exit code=" << _exit_code; - return false; - } - - //WarnL << "process is running, pid=" << _pid; - return true; + return s_wait(_pid,&_exit_code,block); } int Process::exit_code() { diff --git a/server/Process.h b/server/Process.h index b0b994d9..cce8470a 100644 --- a/server/Process.h +++ b/server/Process.h @@ -36,7 +36,7 @@ public: Process(); ~Process(); void run(const string &cmd,const string &log_file); - void kill(int max_delay); + void kill(int max_delay,bool force = false); bool wait(bool block = true); int exit_code(); private: