From 5d752c89b514aa0932bb39d63a3249ba592fcc98 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 17 Jan 2021 20:15:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpart/ZLToolKit | 2 +- api/tests/server.c | 4 ++-- server/FFmpegSource.cpp | 4 ++-- server/FFmpegSource.h | 2 +- server/System.cpp | 9 ++++----- server/WebApi.cpp | 2 +- src/Common/MultiMediaSourceMuxer.cpp | 2 +- src/Http/HlsPlayer.cpp | 2 +- src/Http/HttpBody.cpp | 6 +++--- src/Http/HttpSession.cpp | 2 +- src/Http/WebSocketSplitter.cpp | 2 +- src/Http/WebSocketSplitter.h | 12 ++++++------ src/Record/MP4.cpp | 2 +- src/Rtmp/RtmpPlayer.cpp | 2 +- src/Rtp/RtpProcess.cpp | 2 +- src/Rtp/RtpProcess.h | 4 +--- src/Rtp/RtpSelector.cpp | 4 ++-- src/Rtp/RtpSession.cpp | 4 ++-- src/Rtsp/Rtsp.cpp | 2 +- src/Rtsp/RtspPusher.cpp | 2 +- 20 files changed, 34 insertions(+), 37 deletions(-) diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index 3b5de80f..9c5aad98 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit 3b5de80f9effe28c4a38fef5beec50eadfc916cf +Subproject commit 9c5aad98d0eb50903e643eb9965b8bc34cd9f77d diff --git a/api/tests/server.c b/api/tests/server.c index c8cf9834..48ef088b 100644 --- a/api/tests/server.c +++ b/api/tests/server.c @@ -371,8 +371,8 @@ void API_CALL on_mk_shell_login(const char *user_name, * @param peer_port 客户端端口号 */ void API_CALL on_mk_flow_report(const mk_media_info url_info, - uint64_t total_bytes, - uint64_t total_seconds, + size_t total_bytes, + size_t total_seconds, int is_player, const mk_sock_info sender) { char ip[64]; diff --git a/server/FFmpegSource.cpp b/server/FFmpegSource.cpp index 331ecdcc..150b0603 100644 --- a/server/FFmpegSource.cpp +++ b/server/FFmpegSource.cpp @@ -59,7 +59,7 @@ static bool is_local_ip(const string &ip){ return false; } -void FFmpegSource::setupRecord(bool enable_hls, bool enable_mp4){ +void FFmpegSource::setupRecordFlag(bool enable_hls, bool enable_mp4){ _enable_hls = enable_hls; _enable_mp4 = enable_mp4; } @@ -173,7 +173,7 @@ void FFmpegSource::findAsync(int maxWaitMS, const function_poller->async([listener_tag,weakSelf,cb](){ + strongSelf->_poller->async([weakSelf,cb](){ auto strongSelf = weakSelf.lock(); if(!strongSelf) { return; diff --git a/server/FFmpegSource.h b/server/FFmpegSource.h index cabb7bb8..8bc8cff5 100644 --- a/server/FFmpegSource.h +++ b/server/FFmpegSource.h @@ -67,7 +67,7 @@ public: * @param enable_hls 是否开启hls直播或录制 * @param enable_mp4 是否录制mp4 */ - void setupRecord(bool enable_hls, bool enable_mp4); + void setupRecordFlag(bool enable_hls, bool enable_mp4); private: void findAsync(int maxWaitMS ,const function &cb); diff --git a/server/System.cpp b/server/System.cpp index 2769fcb5..20441f29 100644 --- a/server/System.cpp +++ b/server/System.cpp @@ -51,11 +51,6 @@ string System::execute(const string &cmd) { } #if !defined(ANDROID) && !defined(_WIN32) -static string addr2line(const string &address) { - string cmd = StrPrinter << "addr2line -C -f -e " << exePath() << " " << address; - return System::execute(cmd); -} - static void sig_crash(int sig) { signal(sig, SIG_DFL); void *array[MAX_STACK_FRAMES]; @@ -68,6 +63,10 @@ static void sig_crash(int sig) { std::string symbol(strings[i]); ref.emplace_back(symbol); #if defined(__linux) || defined(__linux__) + static auto addr2line = [](const string &address) { + string cmd = StrPrinter << "addr2line -C -f -e " << exePath() << " " << address; + return System::execute(cmd); + }; size_t pos1 = symbol.find_first_of("["); size_t pos2 = symbol.find_last_of("]"); std::string address = symbol.substr(pos1 + 1, pos2 - pos1 - 1); diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 44306347..d608d8fc 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -683,7 +683,7 @@ void installWebApi() { lock_guard lck(s_ffmpegMapMtx); s_ffmpegMap.erase(key); }); - ffmpeg->setupRecord(enable_hls, enable_mp4); + ffmpeg->setupRecordFlag(enable_hls, enable_mp4); ffmpeg->play(src_url, dst_url, timeout_ms, [cb, key](const SockException &ex) { if (ex) { lock_guard lck(s_ffmpegMapMtx); diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index e90480b2..cbd87b26 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -260,7 +260,7 @@ static string getTrackInfoStr(const TrackSource *track_src){ break; } } - return codec_info; + return std::move(codec_info); } void MultiMuxerPrivate::onAllTrackReady() { diff --git a/src/Http/HlsPlayer.cpp b/src/Http/HlsPlayer.cpp index dd30f6be..ed260ae4 100644 --- a/src/Http/HlsPlayer.cpp +++ b/src/Http/HlsPlayer.cpp @@ -83,7 +83,7 @@ void HlsPlayer::playNextTs(bool force){ strongSelf->playNextTs(true); } else { //下一个切片慢点播放 - strongSelf->_timer_ts.reset(new Timer(delay / 1000.0f, [weakSelf, delay]() { + strongSelf->_timer_ts.reset(new Timer(delay / 1000.0f, [weakSelf]() { auto strongSelf = weakSelf.lock(); if (!strongSelf) { return false; diff --git a/src/Http/HttpBody.cpp b/src/Http/HttpBody.cpp index d36cb47c..fc316949 100644 --- a/src/Http/HttpBody.cpp +++ b/src/Http/HttpBody.cpp @@ -144,7 +144,7 @@ Buffer::Ptr HttpFileBody::readData(size_t size) { //读到数据了 ret->setSize(iRead); _offset += iRead; - return ret; + return std::move(ret); } //读取文件异常,文件真实长度小于声明长度 _offset = _max_size; @@ -218,7 +218,7 @@ string HttpMultiFormBody::multiFormBodySuffix(const string &boundary){ string endMPboundary = MPboundary + "--"; _StrPrinter body; body << "\r\n" << endMPboundary; - return body; + return std::move(body); } size_t HttpMultiFormBody::fileSize(FILE *fp) { @@ -244,7 +244,7 @@ string HttpMultiFormBody::multiFormBodyPrefix(const HttpArgs &args,const string body << MPboundary << "\r\n"; body << "Content-Disposition: form-data; name=\"" << "file" << "\";filename=\"" << fileName << "\"\r\n"; body << "Content-Type: application/octet-stream\r\n\r\n" ; - return body; + return std::move(body); } }//namespace mediakit diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 15ed9e9b..108d87bf 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -674,7 +674,7 @@ void HttpSession::Handle_Req_POST(size_t &content_len) { //返回不固定长度的content content_len = -1; auto parserCopy = _parser; - std::shared_ptr recvedContentLen = std::make_shared(0); + std::shared_ptr recvedContentLen = std::make_shared(0); bool bClose = !strcasecmp(_parser["Connection"].data(),"close"); _contentCallBack = [this,parserCopy,totalContentLen,recvedContentLen,bClose](const char *data,size_t len){ diff --git a/src/Http/WebSocketSplitter.cpp b/src/Http/WebSocketSplitter.cpp index 569a71ad..091a2e4c 100644 --- a/src/Http/WebSocketSplitter.cpp +++ b/src/Http/WebSocketSplitter.cpp @@ -53,7 +53,7 @@ do{ \ } \ }while(0) \ -void WebSocketSplitter::decode(uint8_t *data,size_t len) { +void WebSocketSplitter::decode(uint8_t *data, size_t len) { uint8_t *ptr = data; if(!_got_header) { //还没有获取数据头 diff --git a/src/Http/WebSocketSplitter.h b/src/Http/WebSocketSplitter.h index 4b43722d..8c89d5c7 100644 --- a/src/Http/WebSocketSplitter.h +++ b/src/Http/WebSocketSplitter.h @@ -95,7 +95,7 @@ public: * @param data 需要解包的数据,可能是不完整的包或多个包 * @param len 数据长度 */ - void decode(uint8_t *data,uint64_t len); + void decode(uint8_t *data, size_t len); /** * 编码一个数据包 @@ -119,7 +119,7 @@ protected: * @param len 负载数据长度 * @param recved 已接收数据长度(包含本次数据长度),等于header._payload_len时则接受完毕 */ - virtual void onWebSocketDecodePayload(const WebSocketHeader &header, const uint8_t *ptr, uint64_t len, uint64_t recved) {}; + virtual void onWebSocketDecodePayload(const WebSocketHeader &header, const uint8_t *ptr, size_t len, size_t recved) {}; /** * 接收到完整的一个webSocket数据包后回调 @@ -135,13 +135,13 @@ protected: virtual void onWebSocketEncodeData(Buffer::Ptr buffer){}; private: - void onPayloadData(uint8_t *data, uint64_t len); + void onPayloadData(uint8_t *data, size_t len); private: - string _remain_data; - int _mask_offset = 0; bool _got_header = false; - uint64_t _payload_offset = 0; + int _mask_offset = 0; + size_t _payload_offset = 0; + string _remain_data; }; } /* namespace mediakit */ diff --git a/src/Record/MP4.cpp b/src/Record/MP4.cpp index 679e750a..e344aafb 100644 --- a/src/Record/MP4.cpp +++ b/src/Record/MP4.cpp @@ -121,7 +121,7 @@ static struct mov_buffer_t s_io = { }, [](void *ctx) { MP4FileIO *thiz = (MP4FileIO *) ctx; - return thiz->onTell(); + return (uint64_t)thiz->onTell(); } }; diff --git a/src/Rtmp/RtmpPlayer.cpp b/src/Rtmp/RtmpPlayer.cpp index 2b128ca7..eeda3f2a 100644 --- a/src/Rtmp/RtmpPlayer.cpp +++ b/src/Rtmp/RtmpPlayer.cpp @@ -214,7 +214,7 @@ inline void RtmpPlayer::send_play() { AMFEncoder enc; enc << "play" << ++_send_req_id << nullptr << _stream_id << (double) _stream_index; sendRequest(MSG_CMD, enc.data()); - auto fun = [this](AMFValue &val) { + auto fun = [](AMFValue &val) { //TraceL << "play onStatus"; auto level = val["level"].as_string(); auto code = val["code"].as_string(); diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index c234ae20..ec2bf167 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -192,7 +192,7 @@ string RtpProcess::getIdentifier() const { return _media_info._streamid; } -int RtpProcess::totalReaderCount() { +int RtpProcess::getTotalReaderCount() { return _muxer ? _muxer->totalReaderCount() : 0; } diff --git a/src/Rtp/RtpProcess.h b/src/Rtp/RtpProcess.h index bd533553..3b78f35f 100644 --- a/src/Rtp/RtpProcess.h +++ b/src/Rtp/RtpProcess.h @@ -15,8 +15,6 @@ #include "ProcessInterface.h" #include "Common/MultiMediaSourceMuxer.h" -using namespace mediakit; - namespace mediakit { class RtpProcess : public SockInfo, public MediaSinkInterface, public MediaSourceEventInterceptor, public std::enable_shared_from_this{ @@ -65,7 +63,7 @@ public: uint16_t get_peer_port() override; string getIdentifier() const override; - int totalReaderCount(); + int getTotalReaderCount(); void setListener(const std::weak_ptr &listener); protected: diff --git a/src/Rtp/RtpSelector.cpp b/src/Rtp/RtpSelector.cpp index 57e84451..71fa02bd 100644 --- a/src/Rtp/RtpSelector.cpp +++ b/src/Rtp/RtpSelector.cpp @@ -138,7 +138,7 @@ void RtpProcessHelper::attachEvent() { bool RtpProcessHelper::close(MediaSource &sender, bool force) { //此回调在其他线程触发 - if (!_process || (!force && _process->totalReaderCount())) { + if (!_process || (!force && _process->getTotalReaderCount())) { return false; } auto parent = _parent.lock(); @@ -151,7 +151,7 @@ bool RtpProcessHelper::close(MediaSource &sender, bool force) { } int RtpProcessHelper::totalReaderCount(MediaSource &sender) { - return _process ? _process->totalReaderCount() : sender.totalReaderCount(); + return _process ? _process->getTotalReaderCount() : sender.totalReaderCount(); } RtpProcess::Ptr &RtpProcessHelper::getProcess() { diff --git a/src/Rtp/RtpSession.cpp b/src/Rtp/RtpSession.cpp index fed21095..bf89073d 100644 --- a/src/Rtp/RtpSession.cpp +++ b/src/Rtp/RtpSession.cpp @@ -79,7 +79,7 @@ void RtpSession::onRtpPacket(const char *data, size_t len) { bool RtpSession::close(MediaSource &sender, bool force) { //此回调在其他线程触发 - if(!_process || (!force && _process->totalReaderCount())){ + if(!_process || (!force && _process->getTotalReaderCount())){ return false; } string err = StrPrinter << "close media:" << sender.getSchema() << "/" << sender.getVhost() << "/" << sender.getApp() << "/" << sender.getId() << " " << force; @@ -89,7 +89,7 @@ bool RtpSession::close(MediaSource &sender, bool force) { int RtpSession::totalReaderCount(MediaSource &sender) { //此回调在其他线程触发 - return _process ? _process->totalReaderCount() : sender.totalReaderCount(); + return _process ? _process->getTotalReaderCount() : sender.totalReaderCount(); } }//namespace mediakit diff --git a/src/Rtsp/Rtsp.cpp b/src/Rtsp/Rtsp.cpp index 0467dc38..d6cf72b8 100644 --- a/src/Rtsp/Rtsp.cpp +++ b/src/Rtsp/Rtsp.cpp @@ -121,7 +121,7 @@ string SdpTrack::toString() const { default: break; } - return _printer; + return std::move(_printer); } static TrackType toTrackType(const string &str) { diff --git a/src/Rtsp/RtspPusher.cpp b/src/Rtsp/RtspPusher.cpp index db7eba9d..38354653 100644 --- a/src/Rtsp/RtspPusher.cpp +++ b/src/Rtsp/RtspPusher.cpp @@ -309,7 +309,7 @@ void RtspPusher::handleResSetup(const Parser &parser, unsigned int track_idx) { } void RtspPusher::sendOptions() { - _on_res_func = [this](const Parser &parser) {}; + _on_res_func = [](const Parser &parser) {}; sendRtspRequest("OPTIONS", _content_base); }