diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index 9c5aad98..64a61db7 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit 9c5aad98d0eb50903e643eb9965b8bc34cd9f77d +Subproject commit 64a61db77b1adeada5e6229b83fec655b1cc09bc diff --git a/CMakeLists.txt b/CMakeLists.txt index 783cdd99..545a4d9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,14 +20,14 @@ set(RELEASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/release) if (CMAKE_SYSTEM_NAME MATCHES "Linux") SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/linux/${BuildType}) SET(EXECUTABLE_OUTPUT_PATH ${RELEASE_DIR}/linux/${BuildType}) - add_compile_options(-fPIC -Wall -Wno-sign-compare -Wno-unused-variable -Wno-unused-value) + add_compile_options(-fPIC -Wall -Wno-unused-variable -Wno-unused-value) elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/windows/${BuildType}) SET(EXECUTABLE_OUTPUT_PATH ${RELEASE_DIR}/windows/${BuildType}) elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin") SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/mac/${BuildType}) SET(EXECUTABLE_OUTPUT_PATH ${RELEASE_DIR}/mac/${BuildType}) - add_compile_options(-Wall -Wno-sign-compare -Wno-unused-variable -Wno-unused-value) + add_compile_options(-Wall -Wno-unused-variable -Wno-unused-value) endif () LINK_DIRECTORIES(${LIBRARY_OUTPUT_PATH}) @@ -106,7 +106,7 @@ if(${CMAKE_BUILD_TYPE} MATCHES "Release") endif() #set(VS_FALGS "/wd4819 /wd4996 /wd4018 /wd4267 /wd4244 /wd4101 /wd4828 /wd4309 /wd4573 /wd4996" ) -set(VS_FALGS "/wd4018" ) +set(VS_FALGS "/wd4819" ) #添加mpeg用于支持ts生成 if(ENABLE_HLS) diff --git a/server/System.cpp b/server/System.cpp index 20441f29..0ca3a807 100644 --- a/server/System.cpp +++ b/server/System.cpp @@ -148,7 +148,7 @@ void System::systemSetup(){ ss << "## exe: " << exeName() << endl; ss << "## signal: " << sig << endl; ss << "## stack: " << endl; - for (int i = 0; i < stack.size(); ++i) { + for (size_t i = 0; i < stack.size(); ++i) { ss << "[" << i << "]: "; for (auto &str : stack[i]){ ss << str << endl; diff --git a/server/WebApi.cpp b/server/WebApi.cpp index d608d8fc..d393f78a 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -187,7 +187,7 @@ static inline void addHttpListener(){ const HttpBody::Ptr &body) { //body默认为空 - size_t size = 0; + ssize_t size = 0; if (body && body->remainSize()) { //有body,获取body大小 size = body->remainSize(); diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index 1825113e..f46122f2 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -466,7 +466,7 @@ void MediaInfo::parse(const string &url_in){ } if (split_vec.size() > 2) { string stream_id; - for (int i = 2; i < split_vec.size(); ++i) { + for (size_t i = 2; i < split_vec.size(); ++i) { stream_id.append(split_vec[i] + "/"); } if (stream_id.back() == '/') { diff --git a/src/Common/Stamp.cpp b/src/Common/Stamp.cpp index f679aab8..acb67e08 100644 --- a/src/Common/Stamp.cpp +++ b/src/Common/Stamp.cpp @@ -101,7 +101,7 @@ void Stamp::revise_l2(int64_t dts, int64_t pts, int64_t &dts_out, int64_t &pts_o } //pts和dts的差值 - auto pts_dts_diff = pts - dts; + int64_t pts_dts_diff = pts - dts; if (_last_dts_in != dts) { //时间戳发生变更 diff --git a/src/Common/Stamp.h b/src/Common/Stamp.h index 77af2823..2d4e9841 100644 --- a/src/Common/Stamp.h +++ b/src/Common/Stamp.h @@ -108,9 +108,9 @@ private: uint32_t _last_dts = 0; uint32_t _last_pts = 0; uint32_t _last_max_pts = 0; - int _frames_since_last_max_pts = 0; - int _sorter_max_size = 0; - int _count_sorter_max_size = 0; + size_t _frames_since_last_max_pts = 0; + size_t _sorter_max_size = 0; + size_t _count_sorter_max_size = 0; set _pts_sorter; }; diff --git a/src/Extension/CommonRtp.cpp b/src/Extension/CommonRtp.cpp index 1a8dc6cf..6ce91bbe 100644 --- a/src/Extension/CommonRtp.cpp +++ b/src/Extension/CommonRtp.cpp @@ -10,7 +10,7 @@ #include "CommonRtp.h" -CommonRtpDecoder::CommonRtpDecoder(CodecId codec, int max_frame_size ){ +CommonRtpDecoder::CommonRtpDecoder(CodecId codec, size_t max_frame_size ){ _codec = codec; _max_frame_size = max_frame_size; obtainFrame(); diff --git a/src/Extension/CommonRtp.h b/src/Extension/CommonRtp.h index a6ff279e..f03189cd 100644 --- a/src/Extension/CommonRtp.h +++ b/src/Extension/CommonRtp.h @@ -30,7 +30,7 @@ public: * @param codec 编码id * @param max_frame_size 允许的最大帧大小 */ - CommonRtpDecoder(CodecId codec, int max_frame_size = 2 * 1024); + CommonRtpDecoder(CodecId codec, size_t max_frame_size = 2 * 1024); /** * 返回编码类型ID @@ -50,7 +50,7 @@ private: private: bool _drop_flag = false; uint16_t _last_seq = 0; - int _max_frame_size; + size_t _max_frame_size; CodecId _codec; FrameImp::Ptr _frame; }; diff --git a/src/Extension/Factory.cpp b/src/Extension/Factory.cpp index 88e3ad4e..25c0e0fd 100644 --- a/src/Extension/Factory.cpp +++ b/src/Extension/Factory.cpp @@ -36,7 +36,7 @@ Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) { return nullptr; } string aac_cfg; - for(int i = 0 ; i < aac_cfg_str.size() / 2 ; ++i ){ + for(size_t i = 0 ; i < aac_cfg_str.size() / 2 ; ++i ){ unsigned int cfg; sscanf(aac_cfg_str.substr(i * 2, 2).data(), "%02X", &cfg); cfg &= 0x00FF; diff --git a/src/Extension/H264.cpp b/src/Extension/H264.cpp index 29d9cc84..e8797556 100644 --- a/src/Extension/H264.cpp +++ b/src/Extension/H264.cpp @@ -36,7 +36,7 @@ bool getAVCInfo(const string &strSps, int &iVideoWidth, int &iVideoHeight, float } static const char *memfind(const char *buf, size_t len, const char *subbuf, size_t sublen) { - for (auto i = 0; i < len - sublen; ++i) { + for (ssize_t i = 0; i < (ssize_t)(len - sublen); ++i) { if (memcmp(buf + i, subbuf, sublen) == 0) { return buf + i; } diff --git a/src/Extension/H264Rtp.cpp b/src/Extension/H264Rtp.cpp index 76463672..4b0e8129 100644 --- a/src/Extension/H264Rtp.cpp +++ b/src/Extension/H264Rtp.cpp @@ -133,7 +133,7 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) { return _h264frame->keyFrame(); } - if (rtppack->sequence != _lastSeq + 1 && rtppack->sequence != 0) { + if (rtppack->sequence != (uint16_t)(_lastSeq + 1) && rtppack->sequence != 0) { //中间的或末尾的rtp包,其seq必须连续(如果回环了则判定为连续),否则说明rtp丢包,那么该帧不完整,必须得丢弃 _h264frame->_buffer.clear(); WarnL << "rtp丢包: " << rtppack->sequence << " != " << _lastSeq << " + 1,该帧被废弃"; diff --git a/src/Extension/H264Rtp.h b/src/Extension/H264Rtp.h index c28b601f..51b9aaaf 100644 --- a/src/Extension/H264Rtp.h +++ b/src/Extension/H264Rtp.h @@ -48,7 +48,7 @@ private: H264Frame::Ptr obtainFrame(); private: - int _lastSeq = 0; + uint16_t _lastSeq = 0; H264Frame::Ptr _h264frame; DtsGenerator _dts_generator; }; diff --git a/src/Extension/H265Rtp.cpp b/src/Extension/H265Rtp.cpp index 6735fb57..9cb64859 100644 --- a/src/Extension/H265Rtp.cpp +++ b/src/Extension/H265Rtp.cpp @@ -92,7 +92,7 @@ bool H265RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) { return (_h265frame->keyFrame()); //i frame } - if (rtppack->sequence != _lastSeq + 1 && rtppack->sequence != 0) { + if (rtppack->sequence != (uint16_t)(_lastSeq + 1) && rtppack->sequence != 0) { //中间的或末尾的rtp包,其seq必须连续(如果回环了则判定为连续),否则说明rtp丢包,那么该帧不完整,必须得丢弃 _h265frame->_buffer.clear(); WarnL << "rtp丢包: " << rtppack->sequence << " != " << _lastSeq << " + 1,该帧被废弃"; diff --git a/src/Extension/H265Rtp.h b/src/Extension/H265Rtp.h index 1f50a8bd..8757a868 100644 --- a/src/Extension/H265Rtp.h +++ b/src/Extension/H265Rtp.h @@ -49,7 +49,7 @@ private: H265Frame::Ptr obtainFrame(); private: - int _lastSeq = 0; + uint16_t _lastSeq = 0; H265Frame::Ptr _h265frame; DtsGenerator _dts_generator; }; diff --git a/src/Http/HlsPlayer.cpp b/src/Http/HlsPlayer.cpp index ed260ae4..28a3f431 100644 --- a/src/Http/HlsPlayer.cpp +++ b/src/Http/HlsPlayer.cpp @@ -153,7 +153,7 @@ void HlsPlayer::onParsed(bool is_m3u8_inner,int64_t sequence,const map=0:固定长度content * 需要指出的是,在http头中带有Content-Length字段时,该返回值无效 */ - size_t onResponseHeader(const string &status,const HttpHeader &headers) override; + ssize_t onResponseHeader(const string &status,const HttpHeader &headers) override; /** * 收到http conten数据 * @param buf 数据指针 @@ -71,7 +71,7 @@ private: * @param recvedSize 已收数据大小(包含本次数据大小),当其等于totalSize时将触发onResponseCompleted回调 * @param totalSize 总数据大小 */ - void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) override; + void onResponseBody(const char *buf,size_t size,size_t recvedSize, size_t totalSize) override; /** * 接收http回复完毕, diff --git a/src/Http/HttpBody.cpp b/src/Http/HttpBody.cpp index fc316949..348c2108 100644 --- a/src/Http/HttpBody.cpp +++ b/src/Http/HttpBody.cpp @@ -27,12 +27,12 @@ HttpStringBody::HttpStringBody(const string &str){ _str = str; } -size_t HttpStringBody::remainSize() { +ssize_t HttpStringBody::remainSize() { return _str.size() - _offset; } Buffer::Ptr HttpStringBody::readData(size_t size) { - size = MIN(remainSize(),size); + size = MIN((size_t)remainSize(), size); if(!size){ //没有剩余字节了 return nullptr; @@ -121,19 +121,19 @@ private: size_t _size; }; -size_t HttpFileBody::remainSize() { +ssize_t HttpFileBody::remainSize() { return _max_size - _offset; } Buffer::Ptr HttpFileBody::readData(size_t size) { - size = MIN(remainSize(),size); + size = MIN((size_t)remainSize(),size); if(!size){ //没有剩余字节了 return nullptr; } if(!_map_addr){ //fread模式 - size_t iRead; + ssize_t iRead; auto ret = _pool.obtain(); ret->setCapacity(size + 1); do{ @@ -180,7 +180,7 @@ HttpMultiFormBody::HttpMultiFormBody(const HttpArgs &args,const string &filePath _totalSize = _bodyPrefix.size() + _bodySuffix.size() + _fileBody->remainSize(); } -size_t HttpMultiFormBody::remainSize() { +ssize_t HttpMultiFormBody::remainSize() { return _totalSize - _offset; } diff --git a/src/Http/HttpBody.h b/src/Http/HttpBody.h index 43177b8c..6cdd3473 100644 --- a/src/Http/HttpBody.h +++ b/src/Http/HttpBody.h @@ -40,7 +40,7 @@ public: /** * 剩余数据大小,如果返回-1, 那么就不设置content-length */ - virtual size_t remainSize() { return 0;}; + virtual ssize_t remainSize() { return 0;}; /** * 读取一定字节数,返回大小可能小于size @@ -70,7 +70,7 @@ public: typedef std::shared_ptr Ptr; HttpStringBody(const string &str); virtual ~HttpStringBody(){} - size_t remainSize() override; + ssize_t remainSize() override; Buffer::Ptr readData(size_t size) override ; private: @@ -95,7 +95,7 @@ public: HttpFileBody(const string &file_path); ~HttpFileBody(){}; - size_t remainSize() override ; + ssize_t remainSize() override ; Buffer::Ptr readData(size_t size) override; private: @@ -126,7 +126,7 @@ public: */ HttpMultiFormBody(const HttpArgs &args,const string &filePath,const string &boundary = "0xKhTmLbOuNdArY"); virtual ~HttpMultiFormBody(){} - size_t remainSize() override ; + ssize_t remainSize() override ; Buffer::Ptr readData(size_t size) override; public: diff --git a/src/Http/HttpChunkedSplitter.cpp b/src/Http/HttpChunkedSplitter.cpp index 40a139ee..205bedf3 100644 --- a/src/Http/HttpChunkedSplitter.cpp +++ b/src/Http/HttpChunkedSplitter.cpp @@ -25,7 +25,7 @@ void HttpChunkedSplitter::onRecvContent(const char *data, size_t len) { onRecvChunk(data,len - 2); } -size_t HttpChunkedSplitter::onRecvHeader(const char *data, size_t len) { +ssize_t HttpChunkedSplitter::onRecvHeader(const char *data, size_t len) { string str(data,len - 2); int ret; sscanf(str.data(),"%X",&ret); diff --git a/src/Http/HttpChunkedSplitter.h b/src/Http/HttpChunkedSplitter.h index 5ae77ab7..ae16c58d 100644 --- a/src/Http/HttpChunkedSplitter.h +++ b/src/Http/HttpChunkedSplitter.h @@ -29,7 +29,7 @@ public: ~HttpChunkedSplitter() override {} ; protected: - size_t onRecvHeader(const char *data,size_t len) override; + ssize_t onRecvHeader(const char *data,size_t len) override; void onRecvContent(const char *data,size_t len) override; const char *onSearchPacketTail(const char *data,size_t len) override; diff --git a/src/Http/HttpClient.cpp b/src/Http/HttpClient.cpp index af372a6f..41217047 100644 --- a/src/Http/HttpClient.cpp +++ b/src/Http/HttpClient.cpp @@ -129,7 +129,7 @@ void HttpClient::onErr(const SockException &ex) { onDisconnect(ex); } -size_t HttpClient::onRecvHeader(const char *data, size_t len) { +ssize_t HttpClient::onRecvHeader(const char *data, size_t len) { _parser.Parse(data); if(_parser.Url() == "302" || _parser.Url() == "301"){ auto newUrl = _parser["Location"]; @@ -159,7 +159,7 @@ size_t HttpClient::onRecvHeader(const char *data, size_t len) { _chunkedSplitter = std::make_shared([this](const char *data,size_t len){ if(len > 0){ auto recvedBodySize = _recvedBodySize + len; - onResponseBody(data, len, recvedBodySize, INT64_MAX); + onResponseBody(data, len, recvedBodySize, SIZE_MAX); _recvedBodySize = recvedBodySize; }else{ onResponseCompleted_l(); @@ -188,14 +188,14 @@ void HttpClient::onRecvContent(const char *data, size_t len) { } auto recvedBodySize = _recvedBodySize + len; if(_totalBodySize < 0){ - //不限长度的content,最大支持INT64_MAX个字节 - onResponseBody(data, len, recvedBodySize, INT64_MAX); + //不限长度的content,最大支持SIZE_MAX个字节 + onResponseBody(data, len, recvedBodySize, SIZE_MAX); _recvedBodySize = recvedBodySize; return; } //固定长度的content - if ( recvedBodySize < _totalBodySize ) { + if (recvedBodySize < (size_t)_totalBodySize ) { //content还未接收完毕 onResponseBody(data, len, recvedBodySize, _totalBodySize); _recvedBodySize = recvedBodySize; @@ -204,7 +204,7 @@ void HttpClient::onRecvContent(const char *data, size_t len) { //content接收完毕 onResponseBody(data, _totalBodySize - _recvedBodySize, _totalBodySize, _totalBodySize); - bool biggerThanExpected = recvedBodySize > _totalBodySize; + bool biggerThanExpected = recvedBodySize > (size_t)_totalBodySize; onResponseCompleted_l(); if(biggerThanExpected) { //声明的content数据比真实的小,那么我们只截取前面部分的并断开链接 diff --git a/src/Http/HttpClient.h b/src/Http/HttpClient.h index 1e380c1a..37602dcb 100644 --- a/src/Http/HttpClient.h +++ b/src/Http/HttpClient.h @@ -110,11 +110,11 @@ protected: * @return 返回后续content的长度;-1:后续数据全是content;>=0:固定长度content * 需要指出的是,在http头中带有Content-Length字段时,该返回值无效 */ - virtual size_t onResponseHeader(const string &status,const HttpHeader &headers){ + virtual ssize_t onResponseHeader(const string &status,const HttpHeader &headers){ DebugL << status; //无Content-Length字段时默认后面全是content return -1; - }; + } /** * 收到http conten数据 @@ -123,9 +123,9 @@ protected: * @param recvedSize 已收数据大小(包含本次数据大小),当其等于totalSize时将触发onResponseCompleted回调 * @param totalSize 总数据大小 */ - virtual void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize){ - DebugL << size << " " << recvedSize << " " << totalSize; - }; + virtual void onResponseBody(const char *buf, size_t size, size_t recvedSize, size_t totalSize) { + DebugL << size << " " << recvedSize << " " << totalSize; + } /** * 接收http回复完毕, @@ -149,7 +149,7 @@ protected: virtual bool onRedirectUrl(const string &url,bool temporary){ return true;}; //HttpRequestSplitter override - size_t onRecvHeader(const char *data,size_t len) override; + ssize_t onRecvHeader(const char *data,size_t len) override; void onRecvContent(const char *data,size_t len) override; protected: @@ -174,7 +174,7 @@ private: string _path; //recv size_t _recvedBodySize; - size_t _totalBodySize; + ssize_t _totalBodySize; Parser _parser; string _lastHost; Ticker _aliveTicker; diff --git a/src/Http/HttpDownloader.cpp b/src/Http/HttpDownloader.cpp index 0bab074c..1d2e9e9a 100644 --- a/src/Http/HttpDownloader.cpp +++ b/src/Http/HttpDownloader.cpp @@ -47,7 +47,7 @@ void HttpDownloader::startDownload(const string& url, const string& filePath,boo sendRequest(url,timeOutSecond); } -size_t HttpDownloader::onResponseHeader(const string& status,const HttpHeader& headers) { +ssize_t HttpDownloader::onResponseHeader(const string& status,const HttpHeader& headers) { if(status != "200" && status != "206"){ //失败 shutdown(SockException(Err_shutdown,StrPrinter << "Http Status:" << status)); diff --git a/src/Http/HttpDownloader.h b/src/Http/HttpDownloader.h index 1cf7d501..124994e7 100644 --- a/src/Http/HttpDownloader.h +++ b/src/Http/HttpDownloader.h @@ -31,7 +31,7 @@ public: _onResult = cb; } private: - size_t onResponseHeader(const string &status, const HttpHeader &headers) override; + ssize_t onResponseHeader(const string &status, const HttpHeader &headers) override; void onResponseBody(const char *buf, size_t size, size_t recvedSize, size_t totalSize) override; void onResponseCompleted() override; void onDisconnect(const SockException &ex) override; diff --git a/src/Http/HttpRequestSplitter.cpp b/src/Http/HttpRequestSplitter.cpp index e609b4d9..465bf296 100644 --- a/src/Http/HttpRequestSplitter.cpp +++ b/src/Http/HttpRequestSplitter.cpp @@ -44,7 +44,7 @@ void HttpRequestSplitter::input(const char *data,size_t len) { } //_content_len == 0,这是请求头 const char *header_ptr = ptr; - auto header_size = index - ptr; + ssize_t header_size = index - ptr; ptr = index; _remain_data_size = len - (ptr - data); _content_len = onRecvHeader(header_ptr, header_size); @@ -71,7 +71,7 @@ void HttpRequestSplitter::input(const char *data,size_t len) { //已经找到http头了 if(_content_len > 0){ //数据按照固定长度content处理 - if(_remain_data_size < _content_len){ + if(_remain_data_size < (size_t)_content_len){ //数据不够,缓存定位到剩余数据部分 _remain_data.assign(ptr, _remain_data_size); return; @@ -101,7 +101,7 @@ void HttpRequestSplitter::input(const char *data,size_t len) { _remain_data.clear(); } -void HttpRequestSplitter::setContentLen(size_t content_len) { +void HttpRequestSplitter::setContentLen(ssize_t content_len) { _content_len = content_len; } diff --git a/src/Http/HttpRequestSplitter.h b/src/Http/HttpRequestSplitter.h index 254f8260..efe1ec90 100644 --- a/src/Http/HttpRequestSplitter.h +++ b/src/Http/HttpRequestSplitter.h @@ -41,7 +41,7 @@ protected: * 0 : 代表为后面数据还是请求头, * >0 : 代表后面数据为固定长度content,此时将缓存content并等到所有content接收完毕一次性通过onRecvContent函数回调出去 */ - virtual size_t onRecvHeader(const char *data,size_t len) = 0; + virtual ssize_t onRecvHeader(const char *data,size_t len) = 0; /** * 收到content分片或全部数据 @@ -62,7 +62,7 @@ protected: /** * 设置content len */ - void setContentLen(size_t content_len); + void setContentLen(ssize_t content_len); /** * 恢复初始设置 @@ -75,7 +75,7 @@ protected: size_t remainDataSize(); private: - size_t _content_len = 0; + ssize_t _content_len = 0; size_t _remain_data_size = 0; BufferLikeString _remain_data; }; diff --git a/src/Http/HttpRequester.cpp b/src/Http/HttpRequester.cpp index fb3a72df..2ac7efe2 100644 --- a/src/Http/HttpRequester.cpp +++ b/src/Http/HttpRequester.cpp @@ -19,7 +19,7 @@ HttpRequester::~HttpRequester(){ } -size_t HttpRequester::onResponseHeader(const string &status,const HttpHeader &headers) { +ssize_t HttpRequester::onResponseHeader(const string &status,const HttpHeader &headers) { _strRecvBody.clear(); //无Content-Length字段时默认后面没有content return 0; diff --git a/src/Http/HttpRequester.h b/src/Http/HttpRequester.h index 3853fb5c..a653e13e 100644 --- a/src/Http/HttpRequester.h +++ b/src/Http/HttpRequester.h @@ -26,7 +26,7 @@ public: void startRequester(const string &url,const HttpRequesterResult &onResult,float timeOutSecond = 10); void clear() override ; private: - size_t onResponseHeader(const string &status,const HttpHeader &headers) override; + ssize_t onResponseHeader(const string &status,const HttpHeader &headers) override; void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) override; void onResponseCompleted() override; void onDisconnect(const SockException &ex) override; diff --git a/src/Http/HttpSession.cpp b/src/Http/HttpSession.cpp index 108d87bf..95815457 100644 --- a/src/Http/HttpSession.cpp +++ b/src/Http/HttpSession.cpp @@ -31,15 +31,15 @@ HttpSession::~HttpSession() { TraceP(this); } -void HttpSession::Handle_Req_HEAD(size_t &content_len){ +void HttpSession::Handle_Req_HEAD(ssize_t &content_len){ //暂时全部返回200 OK,因为HTTP GET存在按需生成流的操作,所以不能按照HTTP GET的流程返回 //如果直接返回404,那么又会导致按需生成流的逻辑失效,所以HTTP HEAD在静态文件或者已存在资源时才有效 //对于按需生成流的直播场景并不适用 sendResponse(200, true); } -size_t HttpSession::onRecvHeader(const char *header,size_t len) { - typedef void (HttpSession::*HttpCMDHandle)(size_t &); +ssize_t HttpSession::onRecvHeader(const char *header,size_t len) { + typedef void (HttpSession::*HttpCMDHandle)(ssize_t &); static unordered_map s_func_map; static onceToken token([]() { s_func_map.emplace("GET",&HttpSession::Handle_Req_GET); @@ -61,7 +61,7 @@ size_t HttpSession::onRecvHeader(const char *header,size_t len) { _origin = _parser["Origin"]; //默认后面数据不是content而是header - size_t content_len = 0; + ssize_t content_len = 0; auto &fun = it->second; try { (this->*fun)(content_len); @@ -353,11 +353,11 @@ bool HttpSession::checkLiveStreamFlv(const function &cb){ }); } -void HttpSession::Handle_Req_GET(size_t &content_len) { +void HttpSession::Handle_Req_GET(ssize_t &content_len) { Handle_Req_GET_l(content_len, true); } -void HttpSession::Handle_Req_GET_l(size_t &content_len, bool sendBody) { +void HttpSession::Handle_Req_GET_l(ssize_t &content_len, bool sendBody) { //先看看是否为WebSocket请求 if (checkWebSocket()) { content_len = -1; @@ -506,7 +506,7 @@ void HttpSession::sendResponse(int code, GET_CONFIG(uint32_t,keepAliveSec,Http::kKeepAliveSecond); //body默认为空 - size_t size = 0; + ssize_t size = 0; if (body && body->remainSize()) { //有body,获取body大小 size = body->remainSize(); @@ -515,7 +515,7 @@ void HttpSession::sendResponse(int code, if(no_content_length){ //http-flv直播是Keep-Alive类型 bClose = false; - }else if(size >= INT64_MAX || size < 0 ){ + }else if(size >= SIZE_MAX || size < 0 ){ //不固定长度的body,那么发送完body后应该关闭socket,以便浏览器做下载完毕的判断 bClose = true; } @@ -537,7 +537,7 @@ void HttpSession::sendResponse(int code, headerOut.emplace(kAccessControlAllowCredentials, "true"); } - if(!no_content_length && size >= 0 && size < INT64_MAX){ + if(!no_content_length && size >= 0 && size < SIZE_MAX){ //文件长度为固定值,且不是http-flv强制设置Content-Length headerOut[kContentLength] = to_string(size); } @@ -642,10 +642,10 @@ bool HttpSession::emitHttpEvent(bool doInvoke){ return consumed; } -void HttpSession::Handle_Req_POST(size_t &content_len) { +void HttpSession::Handle_Req_POST(ssize_t &content_len) { GET_CONFIG(size_t,maxReqSize,Http::kMaxReqSize); - size_t totalContentLen = _parser["Content-Length"].empty() ? -1 : atoll(_parser["Content-Length"].data()); + ssize_t totalContentLen = _parser["Content-Length"].empty() ? -1 : atoll(_parser["Content-Length"].data()); if(totalContentLen == 0){ //content为空 @@ -654,7 +654,7 @@ void HttpSession::Handle_Req_POST(size_t &content_len) { return; } - if(totalContentLen > 0 && totalContentLen < maxReqSize ){ + if(totalContentLen > 0 && (size_t)totalContentLen < maxReqSize ){ //返回固定长度的content content_len = totalContentLen; auto parserCopy = _parser; @@ -671,7 +671,7 @@ void HttpSession::Handle_Req_POST(size_t &content_len) { return false; }; }else{ - //返回不固定长度的content + //返回不固定长度的content或者超过长度限制的content content_len = -1; auto parserCopy = _parser; std::shared_ptr recvedContentLen = std::make_shared(0); @@ -679,10 +679,16 @@ void HttpSession::Handle_Req_POST(size_t &content_len) { _contentCallBack = [this,parserCopy,totalContentLen,recvedContentLen,bClose](const char *data,size_t len){ *(recvedContentLen) += len; + if (totalContentLen < 0) { + //不固定长度的content,源源不断接收数据 + onRecvUnlimitedContent(parserCopy, data, len, SIZE_MAX, *(recvedContentLen)); + return true; + } + //长度超过限制的content onRecvUnlimitedContent(parserCopy,data,len,totalContentLen,*(recvedContentLen)); - if(*(recvedContentLen) < totalContentLen){ + if(*(recvedContentLen) < (size_t)totalContentLen){ //数据还没接收完毕 //_contentCallBack是可持续的,后面还要处理后续content数据 return true; diff --git a/src/Http/HttpSession.h b/src/Http/HttpSession.h index 16652b82..98549439 100644 --- a/src/Http/HttpSession.h +++ b/src/Http/HttpSession.h @@ -57,7 +57,7 @@ protected: std::shared_ptr getSharedPtr() override; //HttpRequestSplitter override - size_t onRecvHeader(const char *data,size_t len) override; + ssize_t onRecvHeader(const char *data,size_t len) override; void onRecvContent(const char *data,size_t len) override; /** @@ -101,10 +101,10 @@ protected: void onWebSocketDecodeComplete(const WebSocketHeader &header_in) override; private: - void Handle_Req_GET(size_t &content_len); - void Handle_Req_GET_l(size_t &content_len, bool sendBody); - void Handle_Req_POST(size_t &content_len); - void Handle_Req_HEAD(size_t &content_len); + void Handle_Req_GET(ssize_t &content_len); + void Handle_Req_GET_l(ssize_t &content_len, bool sendBody); + void Handle_Req_POST(ssize_t &content_len); + void Handle_Req_HEAD(ssize_t &content_len); bool checkLiveStream(const string &schema, const string &url_suffix, const function &cb); diff --git a/src/Http/HttpTSPlayer.cpp b/src/Http/HttpTSPlayer.cpp index eb43e478..70cf3b42 100644 --- a/src/Http/HttpTSPlayer.cpp +++ b/src/Http/HttpTSPlayer.cpp @@ -19,7 +19,7 @@ HttpTSPlayer::HttpTSPlayer(const EventPoller::Ptr &poller, bool split_ts){ HttpTSPlayer::~HttpTSPlayer() {} -size_t HttpTSPlayer::onResponseHeader(const string &status, const HttpClient::HttpHeader &headers) { +ssize_t HttpTSPlayer::onResponseHeader(const string &status, const HttpClient::HttpHeader &headers) { _status = status; if (status != "200" && status != "206") { //http状态码不符合预期 diff --git a/src/Http/HttpTSPlayer.h b/src/Http/HttpTSPlayer.h index 0fee37f9..2dbe4aa9 100644 --- a/src/Http/HttpTSPlayer.h +++ b/src/Http/HttpTSPlayer.h @@ -33,7 +33,7 @@ public: protected: ///HttpClient override/// - size_t onResponseHeader(const string &status,const HttpHeader &headers) override; + ssize_t onResponseHeader(const string &status,const HttpHeader &headers) override; void onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) override; void onResponseCompleted() override; void onDisconnect(const SockException &ex) override ; diff --git a/src/Http/WebSocketClient.h b/src/Http/WebSocketClient.h index dd6e131e..eaedd687 100644 --- a/src/Http/WebSocketClient.h +++ b/src/Http/WebSocketClient.h @@ -32,7 +32,7 @@ class HttpWsClient; template class ClientTypeImp : public ClientType { public: - typedef function onBeforeSendCB; + typedef function onBeforeSendCB; friend class HttpWsClient; template @@ -43,7 +43,7 @@ protected: /** * 发送前拦截并打包为websocket协议 */ - size_t send(Buffer::Ptr buf) override{ + ssize_t send(Buffer::Ptr buf) override{ if(_beforeSendCB){ return _beforeSendCB(buf); } @@ -120,7 +120,7 @@ protected: * @return 返回后续content的长度;-1:后续数据全是content;>=0:固定长度content * 需要指出的是,在http头中带有Content-Length字段时,该返回值无效 */ - size_t onResponseHeader(const string &status,const HttpHeader &headers) override { + ssize_t onResponseHeader(const string &status,const HttpHeader &headers) override { if(status == "101"){ auto Sec_WebSocket_Accept = encodeBase64(SHA1::encode_bin(_Sec_WebSocket_Key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11")); if(Sec_WebSocket_Accept == const_cast(headers)["Sec-WebSocket-Accept"]){ diff --git a/src/Http/WebSocketSession.h b/src/Http/WebSocketSession.h index 80c8179d..d6fb6d4a 100644 --- a/src/Http/WebSocketSession.h +++ b/src/Http/WebSocketSession.h @@ -19,7 +19,7 @@ */ class SendInterceptor{ public: - typedef function onBeforeSendCB; + typedef function onBeforeSendCB; SendInterceptor() = default; virtual ~SendInterceptor() = default; virtual void setOnBeforeSendCB(const onBeforeSendCB &cb) = 0; @@ -53,7 +53,7 @@ protected: * @param buf 需要截取的数据 * @return 数据字节数 */ - size_t send(Buffer::Ptr buf) override { + ssize_t send(Buffer::Ptr buf) override { if (_beforeSendCB) { return _beforeSendCB(buf); } diff --git a/src/Http/WebSocketSplitter.cpp b/src/Http/WebSocketSplitter.cpp index 091a2e4c..e67ac53f 100644 --- a/src/Http/WebSocketSplitter.cpp +++ b/src/Http/WebSocketSplitter.cpp @@ -140,7 +140,7 @@ begin_decode: void WebSocketSplitter::onPayloadData(uint8_t *data, size_t len) { if(_mask_flag){ - for(int i = 0; i < len ; ++i,++data){ + for(size_t i = 0; i < len ; ++i,++data){ *(data) ^= _mask[(i + _mask_offset) % 4]; } _mask_offset = (_mask_offset + len) % 4; @@ -184,7 +184,7 @@ void WebSocketSplitter::encode(const WebSocketHeader &header,const Buffer::Ptr & if(len > 0){ if(mask_flag){ uint8_t *ptr = (uint8_t*)buffer->data(); - for(int i = 0; i < len ; ++i,++ptr){ + for(size_t i = 0; i < len ; ++i,++ptr){ *(ptr) ^= header._mask[i % 4]; } } diff --git a/src/Player/PlayerBase.cpp b/src/Player/PlayerBase.cpp index df1a3de1..289c01ef 100644 --- a/src/Player/PlayerBase.cpp +++ b/src/Player/PlayerBase.cpp @@ -64,7 +64,7 @@ PlayerBase::PlayerBase() { ///////////////////////////Demuxer////////////////////////////// bool Demuxer::isInited(int analysisMs) { - if(analysisMs && _ticker.createdTime() > analysisMs){ + if(analysisMs && _ticker.createdTime() > (uint64_t)analysisMs){ //analysisMs毫秒后强制初始化完毕 return true; } diff --git a/src/Player/PlayerProxy.cpp b/src/Player/PlayerProxy.cpp index 299c4774..40ffa33b 100644 --- a/src/Player/PlayerProxy.cpp +++ b/src/Player/PlayerProxy.cpp @@ -232,7 +232,7 @@ private: }; private: - int _audio_idx = 0; + uint32_t _audio_idx = 0; }; void PlayerProxy::onPlaySuccess() { diff --git a/src/Rtmp/RtmpPlayer.cpp b/src/Rtmp/RtmpPlayer.cpp index eeda3f2a..3852780e 100644 --- a/src/Rtmp/RtmpPlayer.cpp +++ b/src/Rtmp/RtmpPlayer.cpp @@ -115,7 +115,7 @@ void RtmpPlayer::onPlayResult_l(const SockException &ex, bool handshake_done) { if (!ex) { //播放成功,恢复rtmp接收超时定时器 _rtmp_recv_ticker.resetTime(); - int timeout_ms = (*this)[kMediaTimeoutMS].as(); + auto timeout_ms = (*this)[kMediaTimeoutMS].as(); weak_ptr weakSelf = dynamic_pointer_cast(shared_from_this()); auto lam = [weakSelf, timeout_ms]() { auto strongSelf = weakSelf.lock(); diff --git a/src/Rtmp/RtmpProtocol.h b/src/Rtmp/RtmpProtocol.h index a571e274..cdfbc59b 100644 --- a/src/Rtmp/RtmpProtocol.h +++ b/src/Rtmp/RtmpProtocol.h @@ -48,7 +48,7 @@ protected: protected: //// HttpRequestSplitter override //// - size_t onRecvHeader(const char *data, size_t len) override { return 0; } + ssize_t onRecvHeader(const char *data, size_t len) override { return 0; } const char *onSearchPacketTail(const char *data, size_t len) override; protected: diff --git a/src/Rtp/GB28181Process.h b/src/Rtp/GB28181Process.h index 85c41b0a..9238fed6 100644 --- a/src/Rtp/GB28181Process.h +++ b/src/Rtp/GB28181Process.h @@ -38,7 +38,7 @@ public: protected: void onRtpSorted(const RtpPacket::Ptr &rtp, int track_index) override ; const char *onSearchPacketTail(const char *data,size_t len) override; - size_t onRecvHeader(const char *data,size_t len) override { return 0; }; + ssize_t onRecvHeader(const char *data,size_t len) override { return 0; }; private: void onRtpDecode(const Frame::Ptr &frame); diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index ec2bf167..91317120 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -139,7 +139,7 @@ bool RtpProcess::alive() { return true; } - GET_CONFIG(int, timeoutSec, RtpProxy::kTimeoutSec) + GET_CONFIG(uint64_t, timeoutSec, RtpProxy::kTimeoutSec) if (_last_frame_time.elapsedTime() / 1000 < timeoutSec) { return true; } diff --git a/src/Rtp/RtpSplitter.cpp b/src/Rtp/RtpSplitter.cpp index 9692b2ff..636340a2 100644 --- a/src/Rtp/RtpSplitter.cpp +++ b/src/Rtp/RtpSplitter.cpp @@ -19,7 +19,7 @@ static const int kEHOME_OFFSET = 256; RtpSplitter::RtpSplitter() {} RtpSplitter::~RtpSplitter() {} -size_t RtpSplitter::onRecvHeader(const char *data,size_t len){ +ssize_t RtpSplitter::onRecvHeader(const char *data,size_t len){ //忽略偏移量 data += _offset; len -= _offset; @@ -73,7 +73,7 @@ const char *RtpSplitter::onSearchPacketTail(const char *data, size_t len) { const char *RtpSplitter::onSearchPacketTail_l(const char *data, size_t len) { //这是rtp包 uint16_t length = (((uint8_t *) data)[0] << 8) | ((uint8_t *) data)[1]; - if (len < length + 2) { + if (len < (size_t)(length + 2)) { //数据不够 return nullptr; } diff --git a/src/Rtp/RtpSplitter.h b/src/Rtp/RtpSplitter.h index e2cd9942..5e0c51e6 100644 --- a/src/Rtp/RtpSplitter.h +++ b/src/Rtp/RtpSplitter.h @@ -30,7 +30,7 @@ protected: virtual void onRtpPacket(const char *data, size_t len) = 0; protected: - size_t onRecvHeader(const char *data, size_t len) override; + ssize_t onRecvHeader(const char *data, size_t len) override; const char *onSearchPacketTail(const char *data, size_t len) override; const char *onSearchPacketTail_l(const char *data, size_t len); diff --git a/src/Rtp/TSDecoder.cpp b/src/Rtp/TSDecoder.cpp index 7b8f1b28..31dae4a2 100644 --- a/src/Rtp/TSDecoder.cpp +++ b/src/Rtp/TSDecoder.cpp @@ -19,7 +19,7 @@ void TSSegment::setOnSegment(const TSSegment::onSegment &cb) { _onSegment = cb; } -size_t TSSegment::onRecvHeader(const char *data, size_t len) { +ssize_t TSSegment::onRecvHeader(const char *data, size_t len) { if (!isTSPacket(data, len)) { WarnL << "不是ts包:" << (int) (data[0]) << " " << len; return 0; diff --git a/src/Rtp/TSDecoder.h b/src/Rtp/TSDecoder.h index 533a0322..2f92421a 100644 --- a/src/Rtp/TSDecoder.h +++ b/src/Rtp/TSDecoder.h @@ -31,7 +31,7 @@ public: static bool isTSPacket(const char *data, size_t len); protected: - size_t onRecvHeader(const char *data, size_t len) override ; + ssize_t onRecvHeader(const char *data, size_t len) override ; const char *onSearchPacketTail(const char *data, size_t len) override ; private: diff --git a/src/Rtsp/RtspPlayer.cpp b/src/Rtsp/RtspPlayer.cpp index 59ad0e15..b43c8a51 100644 --- a/src/Rtsp/RtspPlayer.cpp +++ b/src/Rtsp/RtspPlayer.cpp @@ -775,7 +775,7 @@ void RtspPlayer::onPlayResult_l(const SockException &ex , bool handshake_done) { if (!ex) { //播放成功,恢复rtp接收超时定时器 _rtp_recv_ticker.resetTime(); - int timeoutMS = (*this)[kMediaTimeoutMS].as(); + auto timeoutMS = (*this)[kMediaTimeoutMS].as(); weak_ptr weakSelf = dynamic_pointer_cast(shared_from_this()); auto lam = [weakSelf, timeoutMS]() { auto strongSelf = weakSelf.lock(); diff --git a/src/Rtsp/RtspSession.cpp b/src/Rtsp/RtspSession.cpp index 9cb2c7bc..c73b808f 100644 --- a/src/Rtsp/RtspSession.cpp +++ b/src/Rtsp/RtspSession.cpp @@ -187,7 +187,7 @@ void RtspSession::onRtpPacket(const char *data, size_t len) { void RtspSession::onRtcpPacket(int track_idx, SdpTrack::Ptr &track, const char *data, size_t len){} -size_t RtspSession::getContentLength(Parser &parser) { +ssize_t RtspSession::getContentLength(Parser &parser) { if(parser.Method() == "POST"){ //http post请求的content数据部分是base64编码后的rtsp请求信令包 return remainDataSize(); @@ -1030,7 +1030,7 @@ bool RtspSession::sendRtspResponse(const string &res_code, const StrCaseMap &hea return send(std::make_shared(std::move(printer))) > 0 ; } -size_t RtspSession::send(Buffer::Ptr pkt){ +ssize_t RtspSession::send(Buffer::Ptr pkt){ // if(!_enableSendRtp){ // DebugP(this) << pkt->data(); // } diff --git a/src/Rtsp/RtspSession.h b/src/Rtsp/RtspSession.h index a1e15094..d469238e 100644 --- a/src/Rtsp/RtspSession.h +++ b/src/Rtsp/RtspSession.h @@ -75,7 +75,7 @@ protected: //收到rtp包回调 void onRtpPacket(const char *data, size_t len) override; //从rtsp头中获取Content长度 - size_t getContentLength(Parser &parser) override; + ssize_t getContentLength(Parser &parser) override; ////RtpReceiver override//// void onRtpSorted(const RtpPacket::Ptr &rtp, int track_idx) override; @@ -93,7 +93,7 @@ protected: std::shared_ptr getOriginSock(MediaSource &sender) const override; /////TcpSession override//// - size_t send(Buffer::Ptr pkt) override; + ssize_t send(Buffer::Ptr pkt) override; //收到RTCP包回调 virtual void onRtcpPacket(int track_idx, SdpTrack::Ptr &track, const char *data, size_t len); diff --git a/src/Rtsp/RtspSplitter.cpp b/src/Rtsp/RtspSplitter.cpp index e647423b..808894d1 100644 --- a/src/Rtsp/RtspSplitter.cpp +++ b/src/Rtsp/RtspSplitter.cpp @@ -44,7 +44,7 @@ const char *RtspSplitter::onSearchPacketTail_l(const char *data, size_t len) { return nullptr; } uint16_t length = (((uint8_t *)data)[2] << 8) | ((uint8_t *)data)[3]; - if(len < length + 4){ + if(len < (size_t)(length + 4)){ //数据不够 return nullptr; } @@ -53,7 +53,7 @@ const char *RtspSplitter::onSearchPacketTail_l(const char *data, size_t len) { return data + 4 + length; } -size_t RtspSplitter::onRecvHeader(const char *data, size_t len) { +ssize_t RtspSplitter::onRecvHeader(const char *data, size_t len) { if(_isRtpPacket){ onRtpPacket(data,len); return 0; @@ -77,7 +77,7 @@ void RtspSplitter::enableRecvRtp(bool enable) { _enableRecvRtp = enable; } -size_t RtspSplitter::getContentLength(Parser &parser) { +ssize_t RtspSplitter::getContentLength(Parser &parser) { return atoi(parser["Content-Length"].data()); } diff --git a/src/Rtsp/RtspSplitter.h b/src/Rtsp/RtspSplitter.h index 25bde7c5..ab310eb4 100644 --- a/src/Rtsp/RtspSplitter.h +++ b/src/Rtsp/RtspSplitter.h @@ -45,12 +45,12 @@ protected: * @param parser * @return */ - virtual size_t getContentLength(Parser &parser); + virtual ssize_t getContentLength(Parser &parser); protected: const char *onSearchPacketTail(const char *data,size_t len) override ; const char *onSearchPacketTail_l(const char *data,size_t len) ; - size_t onRecvHeader(const char *data,size_t len) override; + ssize_t onRecvHeader(const char *data,size_t len) override; void onRecvContent(const char *data,size_t len) override; private: