mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +08:00
去除编译警告,修复bug
This commit is contained in:
parent
5d752c89b5
commit
f63b2b1863
@ -1 +1 @@
|
||||
Subproject commit 9c5aad98d0eb50903e643eb9965b8bc34cd9f77d
|
||||
Subproject commit 64a61db77b1adeada5e6229b83fec655b1cc09bc
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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() == '/') {
|
||||
|
@ -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) {
|
||||
//时间戳发生变更
|
||||
|
@ -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<uint32_t> _pts_sorter;
|
||||
};
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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,该帧被废弃";
|
||||
|
@ -48,7 +48,7 @@ private:
|
||||
H264Frame::Ptr obtainFrame();
|
||||
|
||||
private:
|
||||
int _lastSeq = 0;
|
||||
uint16_t _lastSeq = 0;
|
||||
H264Frame::Ptr _h264frame;
|
||||
DtsGenerator _dts_generator;
|
||||
};
|
||||
|
@ -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,该帧被废弃";
|
||||
|
@ -49,7 +49,7 @@ private:
|
||||
H265Frame::Ptr obtainFrame();
|
||||
|
||||
private:
|
||||
int _lastSeq = 0;
|
||||
uint16_t _lastSeq = 0;
|
||||
H265Frame::Ptr _h265frame;
|
||||
DtsGenerator _dts_generator;
|
||||
};
|
||||
|
@ -153,7 +153,7 @@ void HlsPlayer::onParsed(bool is_m3u8_inner,int64_t sequence,const map<int,ts_se
|
||||
}
|
||||
}
|
||||
|
||||
size_t HlsPlayer::onResponseHeader(const string &status, const HttpClient::HttpHeader &headers) {
|
||||
ssize_t HlsPlayer::onResponseHeader(const string &status, const HttpClient::HttpHeader &headers) {
|
||||
if (status != "200" && status != "206") {
|
||||
//失败
|
||||
teardown_l(SockException(Err_shutdown, StrPrinter << "bad http status code:" + status));
|
||||
|
@ -63,7 +63,7 @@ private:
|
||||
* @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;
|
||||
/**
|
||||
* 收到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回复完毕,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<HttpStringBody> 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:
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<HttpChunkedSplitter>([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数据比真实的小,那么我们只截取前面部分的并断开链接
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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<string, HttpCMDHandle> 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<void()> &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<size_t> recvedContentLen = std::make_shared<size_t>(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;
|
||||
|
@ -57,7 +57,7 @@ protected:
|
||||
std::shared_ptr<FlvMuxer> 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<void(const MediaSource::Ptr &src)> &cb);
|
||||
|
||||
|
@ -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状态码不符合预期
|
||||
|
@ -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 ;
|
||||
|
@ -32,7 +32,7 @@ class HttpWsClient;
|
||||
template <typename ClientType,WebSocketHeader::Type DataType>
|
||||
class ClientTypeImp : public ClientType {
|
||||
public:
|
||||
typedef function<size_t (const Buffer::Ptr &buf)> onBeforeSendCB;
|
||||
typedef function<ssize_t (const Buffer::Ptr &buf)> onBeforeSendCB;
|
||||
friend class HttpWsClient<ClientType,DataType>;
|
||||
|
||||
template<typename ...ArgsType>
|
||||
@ -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<HttpHeader &>(headers)["Sec-WebSocket-Accept"]){
|
||||
|
@ -19,7 +19,7 @@
|
||||
*/
|
||||
class SendInterceptor{
|
||||
public:
|
||||
typedef function<size_t (const Buffer::Ptr &buf)> onBeforeSendCB;
|
||||
typedef function<ssize_t (const Buffer::Ptr &buf)> 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);
|
||||
}
|
||||
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ private:
|
||||
};
|
||||
|
||||
private:
|
||||
int _audio_idx = 0;
|
||||
uint32_t _audio_idx = 0;
|
||||
};
|
||||
|
||||
void PlayerProxy::onPlaySuccess() {
|
||||
|
@ -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<int>();
|
||||
auto timeout_ms = (*this)[kMediaTimeoutMS].as<uint64_t>();
|
||||
weak_ptr<RtmpPlayer> weakSelf = dynamic_pointer_cast<RtmpPlayer>(shared_from_this());
|
||||
auto lam = [weakSelf, timeout_ms]() {
|
||||
auto strongSelf = weakSelf.lock();
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
@ -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<int>();
|
||||
auto timeoutMS = (*this)[kMediaTimeoutMS].as<uint64_t>();
|
||||
weak_ptr<RtspPlayer> weakSelf = dynamic_pointer_cast<RtspPlayer>(shared_from_this());
|
||||
auto lam = [weakSelf, timeoutMS]() {
|
||||
auto strongSelf = weakSelf.lock();
|
||||
|
@ -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<BufferString>(std::move(printer))) > 0 ;
|
||||
}
|
||||
|
||||
size_t RtspSession::send(Buffer::Ptr pkt){
|
||||
ssize_t RtspSession::send(Buffer::Ptr pkt){
|
||||
// if(!_enableSendRtp){
|
||||
// DebugP(this) << pkt->data();
|
||||
// }
|
||||
|
@ -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<SockInfo> 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);
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user