From b4228f91c3230bdad0edc2189e65e0d8bb93b16e Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 24 Apr 2020 12:39:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8DZLToolKit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpart/ZLToolKit | 2 +- server/Process.cpp | 2 +- src/Common/MediaSource.h | 4 ++-- src/Http/HttpDownloader.cpp | 2 +- src/Http/HttpFileManager.cpp | 5 ++--- src/Http/HttpSession.cpp | 2 +- src/Http/HttpSession.h | 10 +++++----- src/Record/HlsMakerImp.cpp | 2 +- src/Record/MP4.cpp | 2 +- src/Rtmp/FlvMuxer.cpp | 2 +- src/Rtp/RtpProcess.cpp | 26 +++++++++++++------------- src/Rtp/RtpProcess.h | 8 +++----- 12 files changed, 32 insertions(+), 35 deletions(-) diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index ebd96d98..2dad545f 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit ebd96d983d8dd3268e3e77ed08fb57d67666061c +Subproject commit 2dad545fb22083dc9bdcd7ad60e2f90498197320 diff --git a/server/Process.cpp b/server/Process.cpp index 1eeb8081..79870f14 100644 --- a/server/Process.cpp +++ b/server/Process.cpp @@ -75,7 +75,7 @@ void Process::run(const string &cmd, const string &log_file_tmp) { int log_fd = -1; int flags = O_CREAT | O_WRONLY | O_APPEND; mode_t mode = S_IRWXO | S_IRWXG | S_IRWXU;// S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH; - File::createfile_path(log_file.data(), mode); + File::create_path(log_file.data(), mode); if ((log_fd = ::open(log_file.c_str(), flags, mode)) < 0) { fprintf(stderr, "open log file %s failed:%d(%s)\r\n", log_file.data(), errno, strerror(errno)); } diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index c743d574..cddfb272 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -185,7 +185,7 @@ private: template > > class VideoPacketCache { public: - VideoPacketCache() : _policy(true) { + VideoPacketCache() : _policy(false) { _cache = std::make_shared(); } @@ -231,7 +231,7 @@ private: template > > class AudioPacketCache { public: - AudioPacketCache() : _policy(false) { + AudioPacketCache() : _policy(true) { _cache = std::make_shared(); } diff --git a/src/Http/HttpDownloader.cpp b/src/Http/HttpDownloader.cpp index f5148db4..a634c114 100644 --- a/src/Http/HttpDownloader.cpp +++ b/src/Http/HttpDownloader.cpp @@ -28,7 +28,7 @@ void HttpDownloader::startDownload(const string& url, const string& filePath,boo if(_filePath.empty()){ _filePath = exeDir() + "HttpDownloader/" + MD5(url).hexdigest(); } - _saveFile = File::createfile_file(_filePath.data(),bAppend ? "ab" : "wb"); + _saveFile = File::create_file(_filePath.data(), bAppend ? "ab" : "wb"); if(!_saveFile){ auto strErr = StrPrinter << "打开文件失败:" << filePath << endl; throw std::runtime_error(strErr); diff --git a/src/Http/HttpFileManager.cpp b/src/Http/HttpFileManager.cpp index 11551fe7..584b6f25 100644 --- a/src/Http/HttpFileManager.cpp +++ b/src/Http/HttpFileManager.cpp @@ -315,7 +315,7 @@ public: SockInfoImp() = default; ~SockInfoImp() override = default; - const string &get_local_ip() override{ + string get_local_ip() override{ return _local_ip; } @@ -323,9 +323,8 @@ public: return _local_port; } - const string &get_peer_ip() override{ + string get_peer_ip() override{ return _peer_ip; - } uint16_t get_peer_port() override{ diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 35de0c2f..26056ed0 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -59,7 +59,7 @@ int64_t HttpSession::onRecvHeader(const char *header,uint64_t len) { string cmd = _parser.Method(); auto it = s_func_map.find(cmd); if (it == s_func_map.end()) { - WarnL << "不支持该命令:" << cmd; + WarnP(this) << "不支持该命令:" << cmd; sendResponse("405 Not Allowed", true); return 0; } diff --git a/src/Http/HttpSession.h b/src/Http/HttpSession.h index 540a7e3c..09bcfca5 100644 --- a/src/Http/HttpSession.h +++ b/src/Http/HttpSession.h @@ -41,11 +41,11 @@ public: typedef std::function HttpAccessPathInvoker; HttpSession(const Socket::Ptr &pSock); - virtual ~HttpSession(); + ~HttpSession() override; - virtual void onRecv(const Buffer::Ptr &) override; - virtual void onError(const SockException &err) override; - virtual void onManager() override; + void onRecv(const Buffer::Ptr &) override; + void onError(const SockException &err) override; + void onManager() override; static string urlDecode(const string &str); protected: //FlvMuxer override @@ -80,7 +80,7 @@ protected: * @return true代表允许websocket连接,否则拒绝 */ virtual bool onWebSocketConnect(const Parser &header){ - WarnL << "http server do not support websocket default"; + WarnP(this) << "http server do not support websocket default"; return false; } diff --git a/src/Record/HlsMakerImp.cpp b/src/Record/HlsMakerImp.cpp index c0b64c19..28f88714 100644 --- a/src/Record/HlsMakerImp.cpp +++ b/src/Record/HlsMakerImp.cpp @@ -92,7 +92,7 @@ void HlsMakerImp::onWriteHls(const char *data, int len) { std::shared_ptr HlsMakerImp::makeFile(const string &file,bool setbuf) { auto file_buf = _file_buf; - auto ret= shared_ptr(File::createfile_file(file.data(), "wb"), [file_buf](FILE *fp) { + auto ret= shared_ptr(File::create_file(file.data(), "wb"), [file_buf](FILE *fp) { if (fp) { fclose(fp); } diff --git a/src/Record/MP4.cpp b/src/Record/MP4.cpp index 878c62c0..571efa16 100644 --- a/src/Record/MP4.cpp +++ b/src/Record/MP4.cpp @@ -72,7 +72,7 @@ MP4File::Reader MP4File::createReader(){ void MP4File::openFile(const char *file,const char *mode) { //创建文件 - auto fp = File::createfile_file(file,mode); + auto fp = File::create_file(file, mode); if(!fp){ throw std::runtime_error(string("打开文件失败:") + file); } diff --git a/src/Rtmp/FlvMuxer.cpp b/src/Rtmp/FlvMuxer.cpp index b3df0459..94ad3996 100644 --- a/src/Rtmp/FlvMuxer.cpp +++ b/src/Rtmp/FlvMuxer.cpp @@ -177,7 +177,7 @@ void FlvRecorder::startRecord(const EventPoller::Ptr &poller,const RtmpMediaSour } }); //新建文件 - _file.reset(File::createfile_file(file_path.data(),"wb"),[fileBuf](FILE *fp){ + _file.reset(File::create_file(file_path.data(), "wb"), [fileBuf](FILE *fp){ if(fp){ fflush(fp); fclose(fp); diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index a886bf5c..fe5d5870 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -76,7 +76,7 @@ RtpProcess::RtpProcess(uint32_t ssrc) { GET_CONFIG(string,dump_dir,RtpProxy::kDumpDir); { - FILE *fp = !dump_dir.empty() ? File::createfile_file(File::absolutePath(_media_info._streamid + ".rtp",dump_dir).data(),"wb") : nullptr; + FILE *fp = !dump_dir.empty() ? File::create_file(File::absolutePath(_media_info._streamid + ".rtp", dump_dir).data(), "wb") : nullptr; if(fp){ _save_file_rtp.reset(fp,[](FILE *fp){ fclose(fp); @@ -85,7 +85,7 @@ RtpProcess::RtpProcess(uint32_t ssrc) { } { - FILE *fp = !dump_dir.empty() ? File::createfile_file(File::absolutePath(_media_info._streamid + ".mp2",dump_dir).data(),"wb") : nullptr; + FILE *fp = !dump_dir.empty() ? File::create_file(File::absolutePath(_media_info._streamid + ".mp2", dump_dir).data(), "wb") : nullptr; if(fp){ _save_file_ps.reset(fp,[](FILE *fp){ fclose(fp); @@ -94,7 +94,7 @@ RtpProcess::RtpProcess(uint32_t ssrc) { } { - FILE *fp = !dump_dir.empty() ? File::createfile_file(File::absolutePath(_media_info._streamid + ".video",dump_dir).data(),"wb") : nullptr; + FILE *fp = !dump_dir.empty() ? File::create_file(File::absolutePath(_media_info._streamid + ".video", dump_dir).data(), "wb") : nullptr; if(fp){ _save_file_video.reset(fp,[](FILE *fp){ fclose(fp); @@ -119,8 +119,8 @@ RtpProcess::~RtpProcess() { //流量统计事件广播 GET_CONFIG(uint32_t, iFlowThreshold, General::kFlowThreshold); - if (_ui64TotalBytes > iFlowThreshold * 1024) { - NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _media_info, _ui64TotalBytes, duration, false, static_cast(*this)); + if (_total_bytes > iFlowThreshold * 1024) { + NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _media_info, _total_bytes, duration, false, static_cast(*this)); } } @@ -146,7 +146,7 @@ bool RtpProcess::inputRtp(const Socket::Ptr &sock, const char *data, int data_le return false; } - _ui64TotalBytes += data_len; + _total_bytes += data_len; _last_rtp_time.resetTime(); bool ret = handleOneRtp(0,_track,(unsigned char *)data,data_len); if(dts_out){ @@ -328,11 +328,11 @@ bool RtpProcess::alive() { return false; } -const string& RtpProcess::get_peer_ip() { - if(_peer_ip.empty() && _addr){ - _peer_ip = SockUtil::inet_ntoa(((struct sockaddr_in *) _addr)->sin_addr); +string RtpProcess::get_peer_ip() { + if(_addr){ + return SockUtil::inet_ntoa(((struct sockaddr_in *) _addr)->sin_addr); } - return _peer_ip; + return "0.0.0.0"; } uint16_t RtpProcess::get_peer_port() { @@ -342,11 +342,11 @@ uint16_t RtpProcess::get_peer_port() { return ntohs(((struct sockaddr_in *) _addr)->sin_port); } -const string& RtpProcess::get_local_ip() { +string RtpProcess::get_local_ip() { if(_sock){ - _local_ip = _sock->get_local_ip(); + return _sock->get_local_ip(); } - return _local_ip; + return "0.0.0.0"; } uint16_t RtpProcess::get_local_port() { diff --git a/src/Rtp/RtpProcess.h b/src/Rtp/RtpProcess.h index a5e9b937..cf252301 100644 --- a/src/Rtp/RtpProcess.h +++ b/src/Rtp/RtpProcess.h @@ -32,9 +32,9 @@ public: bool inputRtp(const Socket::Ptr &sock, const char *data,int data_len, const struct sockaddr *addr , uint32_t *dts_out = nullptr); bool alive(); - const string &get_local_ip() override; + string get_local_ip() override; uint16_t get_local_port() override; - const string &get_peer_ip() override; + string get_peer_ip() override; uint16_t get_peer_port() override; string getIdentifier() const override; @@ -65,11 +65,9 @@ private: unordered_map _stamps; uint32_t _dts = 0; Decoder::Ptr _decoder; - string _peer_ip; - string _local_ip; std::weak_ptr _listener; MediaInfo _media_info; - uint64_t _ui64TotalBytes = 0; + uint64_t _total_bytes = 0; Socket::Ptr _sock; };