mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +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")
|
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||||
SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/linux/${BuildType})
|
SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/linux/${BuildType})
|
||||||
SET(EXECUTABLE_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")
|
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||||
SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/windows/${BuildType})
|
SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/windows/${BuildType})
|
||||||
SET(EXECUTABLE_OUTPUT_PATH ${RELEASE_DIR}/windows/${BuildType})
|
SET(EXECUTABLE_OUTPUT_PATH ${RELEASE_DIR}/windows/${BuildType})
|
||||||
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
||||||
SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/mac/${BuildType})
|
SET(LIBRARY_OUTPUT_PATH ${RELEASE_DIR}/mac/${BuildType})
|
||||||
SET(EXECUTABLE_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 ()
|
endif ()
|
||||||
|
|
||||||
LINK_DIRECTORIES(${LIBRARY_OUTPUT_PATH})
|
LINK_DIRECTORIES(${LIBRARY_OUTPUT_PATH})
|
||||||
@ -106,7 +106,7 @@ if(${CMAKE_BUILD_TYPE} MATCHES "Release")
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
#set(VS_FALGS "/wd4819 /wd4996 /wd4018 /wd4267 /wd4244 /wd4101 /wd4828 /wd4309 /wd4573 /wd4996" )
|
#set(VS_FALGS "/wd4819 /wd4996 /wd4018 /wd4267 /wd4244 /wd4101 /wd4828 /wd4309 /wd4573 /wd4996" )
|
||||||
set(VS_FALGS "/wd4018" )
|
set(VS_FALGS "/wd4819" )
|
||||||
|
|
||||||
#添加mpeg用于支持ts生成
|
#添加mpeg用于支持ts生成
|
||||||
if(ENABLE_HLS)
|
if(ENABLE_HLS)
|
||||||
|
@ -148,7 +148,7 @@ void System::systemSetup(){
|
|||||||
ss << "## exe: " << exeName() << endl;
|
ss << "## exe: " << exeName() << endl;
|
||||||
ss << "## signal: " << sig << endl;
|
ss << "## signal: " << sig << endl;
|
||||||
ss << "## stack: " << endl;
|
ss << "## stack: " << endl;
|
||||||
for (int i = 0; i < stack.size(); ++i) {
|
for (size_t i = 0; i < stack.size(); ++i) {
|
||||||
ss << "[" << i << "]: ";
|
ss << "[" << i << "]: ";
|
||||||
for (auto &str : stack[i]){
|
for (auto &str : stack[i]){
|
||||||
ss << str << endl;
|
ss << str << endl;
|
||||||
|
@ -187,7 +187,7 @@ static inline void addHttpListener(){
|
|||||||
const HttpBody::Ptr &body) {
|
const HttpBody::Ptr &body) {
|
||||||
|
|
||||||
//body默认为空
|
//body默认为空
|
||||||
size_t size = 0;
|
ssize_t size = 0;
|
||||||
if (body && body->remainSize()) {
|
if (body && body->remainSize()) {
|
||||||
//有body,获取body大小
|
//有body,获取body大小
|
||||||
size = body->remainSize();
|
size = body->remainSize();
|
||||||
|
@ -466,7 +466,7 @@ void MediaInfo::parse(const string &url_in){
|
|||||||
}
|
}
|
||||||
if (split_vec.size() > 2) {
|
if (split_vec.size() > 2) {
|
||||||
string stream_id;
|
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] + "/");
|
stream_id.append(split_vec[i] + "/");
|
||||||
}
|
}
|
||||||
if (stream_id.back() == '/') {
|
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的差值
|
//pts和dts的差值
|
||||||
auto pts_dts_diff = pts - dts;
|
int64_t pts_dts_diff = pts - dts;
|
||||||
|
|
||||||
if (_last_dts_in != dts) {
|
if (_last_dts_in != dts) {
|
||||||
//时间戳发生变更
|
//时间戳发生变更
|
||||||
|
@ -108,9 +108,9 @@ private:
|
|||||||
uint32_t _last_dts = 0;
|
uint32_t _last_dts = 0;
|
||||||
uint32_t _last_pts = 0;
|
uint32_t _last_pts = 0;
|
||||||
uint32_t _last_max_pts = 0;
|
uint32_t _last_max_pts = 0;
|
||||||
int _frames_since_last_max_pts = 0;
|
size_t _frames_since_last_max_pts = 0;
|
||||||
int _sorter_max_size = 0;
|
size_t _sorter_max_size = 0;
|
||||||
int _count_sorter_max_size = 0;
|
size_t _count_sorter_max_size = 0;
|
||||||
set<uint32_t> _pts_sorter;
|
set<uint32_t> _pts_sorter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include "CommonRtp.h"
|
#include "CommonRtp.h"
|
||||||
|
|
||||||
CommonRtpDecoder::CommonRtpDecoder(CodecId codec, int max_frame_size ){
|
CommonRtpDecoder::CommonRtpDecoder(CodecId codec, size_t max_frame_size ){
|
||||||
_codec = codec;
|
_codec = codec;
|
||||||
_max_frame_size = max_frame_size;
|
_max_frame_size = max_frame_size;
|
||||||
obtainFrame();
|
obtainFrame();
|
||||||
|
@ -30,7 +30,7 @@ public:
|
|||||||
* @param codec 编码id
|
* @param codec 编码id
|
||||||
* @param max_frame_size 允许的最大帧大小
|
* @param max_frame_size 允许的最大帧大小
|
||||||
*/
|
*/
|
||||||
CommonRtpDecoder(CodecId codec, int max_frame_size = 2 * 1024);
|
CommonRtpDecoder(CodecId codec, size_t max_frame_size = 2 * 1024);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回编码类型ID
|
* 返回编码类型ID
|
||||||
@ -50,7 +50,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
bool _drop_flag = false;
|
bool _drop_flag = false;
|
||||||
uint16_t _last_seq = 0;
|
uint16_t _last_seq = 0;
|
||||||
int _max_frame_size;
|
size_t _max_frame_size;
|
||||||
CodecId _codec;
|
CodecId _codec;
|
||||||
FrameImp::Ptr _frame;
|
FrameImp::Ptr _frame;
|
||||||
};
|
};
|
||||||
|
@ -36,7 +36,7 @@ Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
string aac_cfg;
|
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;
|
unsigned int cfg;
|
||||||
sscanf(aac_cfg_str.substr(i * 2, 2).data(), "%02X", &cfg);
|
sscanf(aac_cfg_str.substr(i * 2, 2).data(), "%02X", &cfg);
|
||||||
cfg &= 0x00FF;
|
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) {
|
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) {
|
if (memcmp(buf + i, subbuf, sublen) == 0) {
|
||||||
return buf + i;
|
return buf + i;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
|
|||||||
return _h264frame->keyFrame();
|
return _h264frame->keyFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rtppack->sequence != _lastSeq + 1 && rtppack->sequence != 0) {
|
if (rtppack->sequence != (uint16_t)(_lastSeq + 1) && rtppack->sequence != 0) {
|
||||||
//中间的或末尾的rtp包,其seq必须连续(如果回环了则判定为连续),否则说明rtp丢包,那么该帧不完整,必须得丢弃
|
//中间的或末尾的rtp包,其seq必须连续(如果回环了则判定为连续),否则说明rtp丢包,那么该帧不完整,必须得丢弃
|
||||||
_h264frame->_buffer.clear();
|
_h264frame->_buffer.clear();
|
||||||
WarnL << "rtp丢包: " << rtppack->sequence << " != " << _lastSeq << " + 1,该帧被废弃";
|
WarnL << "rtp丢包: " << rtppack->sequence << " != " << _lastSeq << " + 1,该帧被废弃";
|
||||||
|
@ -48,7 +48,7 @@ private:
|
|||||||
H264Frame::Ptr obtainFrame();
|
H264Frame::Ptr obtainFrame();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _lastSeq = 0;
|
uint16_t _lastSeq = 0;
|
||||||
H264Frame::Ptr _h264frame;
|
H264Frame::Ptr _h264frame;
|
||||||
DtsGenerator _dts_generator;
|
DtsGenerator _dts_generator;
|
||||||
};
|
};
|
||||||
|
@ -92,7 +92,7 @@ bool H265RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
|
|||||||
return (_h265frame->keyFrame()); //i frame
|
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丢包,那么该帧不完整,必须得丢弃
|
//中间的或末尾的rtp包,其seq必须连续(如果回环了则判定为连续),否则说明rtp丢包,那么该帧不完整,必须得丢弃
|
||||||
_h265frame->_buffer.clear();
|
_h265frame->_buffer.clear();
|
||||||
WarnL << "rtp丢包: " << rtppack->sequence << " != " << _lastSeq << " + 1,该帧被废弃";
|
WarnL << "rtp丢包: " << rtppack->sequence << " != " << _lastSeq << " + 1,该帧被废弃";
|
||||||
|
@ -49,7 +49,7 @@ private:
|
|||||||
H265Frame::Ptr obtainFrame();
|
H265Frame::Ptr obtainFrame();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _lastSeq = 0;
|
uint16_t _lastSeq = 0;
|
||||||
H265Frame::Ptr _h265frame;
|
H265Frame::Ptr _h265frame;
|
||||||
DtsGenerator _dts_generator;
|
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") {
|
if (status != "200" && status != "206") {
|
||||||
//失败
|
//失败
|
||||||
teardown_l(SockException(Err_shutdown, StrPrinter << "bad http status code:" + status));
|
teardown_l(SockException(Err_shutdown, StrPrinter << "bad http status code:" + status));
|
||||||
|
@ -63,7 +63,7 @@ private:
|
|||||||
* @return 返回后续content的长度;-1:后续数据全是content;>=0:固定长度content
|
* @return 返回后续content的长度;-1:后续数据全是content;>=0:固定长度content
|
||||||
* 需要指出的是,在http头中带有Content-Length字段时,该返回值无效
|
* 需要指出的是,在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数据
|
* 收到http conten数据
|
||||||
* @param buf 数据指针
|
* @param buf 数据指针
|
||||||
|
@ -27,12 +27,12 @@ HttpStringBody::HttpStringBody(const string &str){
|
|||||||
_str = str;
|
_str = str;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t HttpStringBody::remainSize() {
|
ssize_t HttpStringBody::remainSize() {
|
||||||
return _str.size() - _offset;
|
return _str.size() - _offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer::Ptr HttpStringBody::readData(size_t size) {
|
Buffer::Ptr HttpStringBody::readData(size_t size) {
|
||||||
size = MIN(remainSize(),size);
|
size = MIN((size_t)remainSize(), size);
|
||||||
if(!size){
|
if(!size){
|
||||||
//没有剩余字节了
|
//没有剩余字节了
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -121,19 +121,19 @@ private:
|
|||||||
size_t _size;
|
size_t _size;
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t HttpFileBody::remainSize() {
|
ssize_t HttpFileBody::remainSize() {
|
||||||
return _max_size - _offset;
|
return _max_size - _offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer::Ptr HttpFileBody::readData(size_t size) {
|
Buffer::Ptr HttpFileBody::readData(size_t size) {
|
||||||
size = MIN(remainSize(),size);
|
size = MIN((size_t)remainSize(),size);
|
||||||
if(!size){
|
if(!size){
|
||||||
//没有剩余字节了
|
//没有剩余字节了
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if(!_map_addr){
|
if(!_map_addr){
|
||||||
//fread模式
|
//fread模式
|
||||||
size_t iRead;
|
ssize_t iRead;
|
||||||
auto ret = _pool.obtain();
|
auto ret = _pool.obtain();
|
||||||
ret->setCapacity(size + 1);
|
ret->setCapacity(size + 1);
|
||||||
do{
|
do{
|
||||||
@ -180,7 +180,7 @@ HttpMultiFormBody::HttpMultiFormBody(const HttpArgs &args,const string &filePath
|
|||||||
_totalSize = _bodyPrefix.size() + _bodySuffix.size() + _fileBody->remainSize();
|
_totalSize = _bodyPrefix.size() + _bodySuffix.size() + _fileBody->remainSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t HttpMultiFormBody::remainSize() {
|
ssize_t HttpMultiFormBody::remainSize() {
|
||||||
return _totalSize - _offset;
|
return _totalSize - _offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* 剩余数据大小,如果返回-1, 那么就不设置content-length
|
* 剩余数据大小,如果返回-1, 那么就不设置content-length
|
||||||
*/
|
*/
|
||||||
virtual size_t remainSize() { return 0;};
|
virtual ssize_t remainSize() { return 0;};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取一定字节数,返回大小可能小于size
|
* 读取一定字节数,返回大小可能小于size
|
||||||
@ -70,7 +70,7 @@ public:
|
|||||||
typedef std::shared_ptr<HttpStringBody> Ptr;
|
typedef std::shared_ptr<HttpStringBody> Ptr;
|
||||||
HttpStringBody(const string &str);
|
HttpStringBody(const string &str);
|
||||||
virtual ~HttpStringBody(){}
|
virtual ~HttpStringBody(){}
|
||||||
size_t remainSize() override;
|
ssize_t remainSize() override;
|
||||||
Buffer::Ptr readData(size_t size) override ;
|
Buffer::Ptr readData(size_t size) override ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -95,7 +95,7 @@ public:
|
|||||||
HttpFileBody(const string &file_path);
|
HttpFileBody(const string &file_path);
|
||||||
~HttpFileBody(){};
|
~HttpFileBody(){};
|
||||||
|
|
||||||
size_t remainSize() override ;
|
ssize_t remainSize() override ;
|
||||||
Buffer::Ptr readData(size_t size) override;
|
Buffer::Ptr readData(size_t size) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -126,7 +126,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
HttpMultiFormBody(const HttpArgs &args,const string &filePath,const string &boundary = "0xKhTmLbOuNdArY");
|
HttpMultiFormBody(const HttpArgs &args,const string &filePath,const string &boundary = "0xKhTmLbOuNdArY");
|
||||||
virtual ~HttpMultiFormBody(){}
|
virtual ~HttpMultiFormBody(){}
|
||||||
size_t remainSize() override ;
|
ssize_t remainSize() override ;
|
||||||
Buffer::Ptr readData(size_t size) override;
|
Buffer::Ptr readData(size_t size) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -25,7 +25,7 @@ void HttpChunkedSplitter::onRecvContent(const char *data, size_t len) {
|
|||||||
onRecvChunk(data,len - 2);
|
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);
|
string str(data,len - 2);
|
||||||
int ret;
|
int ret;
|
||||||
sscanf(str.data(),"%X",&ret);
|
sscanf(str.data(),"%X",&ret);
|
||||||
|
@ -29,7 +29,7 @@ public:
|
|||||||
~HttpChunkedSplitter() override {} ;
|
~HttpChunkedSplitter() override {} ;
|
||||||
|
|
||||||
protected:
|
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;
|
void onRecvContent(const char *data,size_t len) override;
|
||||||
const char *onSearchPacketTail(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);
|
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);
|
_parser.Parse(data);
|
||||||
if(_parser.Url() == "302" || _parser.Url() == "301"){
|
if(_parser.Url() == "302" || _parser.Url() == "301"){
|
||||||
auto newUrl = _parser["Location"];
|
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){
|
_chunkedSplitter = std::make_shared<HttpChunkedSplitter>([this](const char *data,size_t len){
|
||||||
if(len > 0){
|
if(len > 0){
|
||||||
auto recvedBodySize = _recvedBodySize + len;
|
auto recvedBodySize = _recvedBodySize + len;
|
||||||
onResponseBody(data, len, recvedBodySize, INT64_MAX);
|
onResponseBody(data, len, recvedBodySize, SIZE_MAX);
|
||||||
_recvedBodySize = recvedBodySize;
|
_recvedBodySize = recvedBodySize;
|
||||||
}else{
|
}else{
|
||||||
onResponseCompleted_l();
|
onResponseCompleted_l();
|
||||||
@ -188,14 +188,14 @@ void HttpClient::onRecvContent(const char *data, size_t len) {
|
|||||||
}
|
}
|
||||||
auto recvedBodySize = _recvedBodySize + len;
|
auto recvedBodySize = _recvedBodySize + len;
|
||||||
if(_totalBodySize < 0){
|
if(_totalBodySize < 0){
|
||||||
//不限长度的content,最大支持INT64_MAX个字节
|
//不限长度的content,最大支持SIZE_MAX个字节
|
||||||
onResponseBody(data, len, recvedBodySize, INT64_MAX);
|
onResponseBody(data, len, recvedBodySize, SIZE_MAX);
|
||||||
_recvedBodySize = recvedBodySize;
|
_recvedBodySize = recvedBodySize;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//固定长度的content
|
//固定长度的content
|
||||||
if ( recvedBodySize < _totalBodySize ) {
|
if (recvedBodySize < (size_t)_totalBodySize ) {
|
||||||
//content还未接收完毕
|
//content还未接收完毕
|
||||||
onResponseBody(data, len, recvedBodySize, _totalBodySize);
|
onResponseBody(data, len, recvedBodySize, _totalBodySize);
|
||||||
_recvedBodySize = recvedBodySize;
|
_recvedBodySize = recvedBodySize;
|
||||||
@ -204,7 +204,7 @@ void HttpClient::onRecvContent(const char *data, size_t len) {
|
|||||||
|
|
||||||
//content接收完毕
|
//content接收完毕
|
||||||
onResponseBody(data, _totalBodySize - _recvedBodySize, _totalBodySize, _totalBodySize);
|
onResponseBody(data, _totalBodySize - _recvedBodySize, _totalBodySize, _totalBodySize);
|
||||||
bool biggerThanExpected = recvedBodySize > _totalBodySize;
|
bool biggerThanExpected = recvedBodySize > (size_t)_totalBodySize;
|
||||||
onResponseCompleted_l();
|
onResponseCompleted_l();
|
||||||
if(biggerThanExpected) {
|
if(biggerThanExpected) {
|
||||||
//声明的content数据比真实的小,那么我们只截取前面部分的并断开链接
|
//声明的content数据比真实的小,那么我们只截取前面部分的并断开链接
|
||||||
|
@ -110,11 +110,11 @@ protected:
|
|||||||
* @return 返回后续content的长度;-1:后续数据全是content;>=0:固定长度content
|
* @return 返回后续content的长度;-1:后续数据全是content;>=0:固定长度content
|
||||||
* 需要指出的是,在http头中带有Content-Length字段时,该返回值无效
|
* 需要指出的是,在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;
|
DebugL << status;
|
||||||
//无Content-Length字段时默认后面全是content
|
//无Content-Length字段时默认后面全是content
|
||||||
return -1;
|
return -1;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 收到http conten数据
|
* 收到http conten数据
|
||||||
@ -125,7 +125,7 @@ protected:
|
|||||||
*/
|
*/
|
||||||
virtual void onResponseBody(const char *buf, size_t size, size_t recvedSize, size_t totalSize) {
|
virtual void onResponseBody(const char *buf, size_t size, size_t recvedSize, size_t totalSize) {
|
||||||
DebugL << size << " " << recvedSize << " " << totalSize;
|
DebugL << size << " " << recvedSize << " " << totalSize;
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接收http回复完毕,
|
* 接收http回复完毕,
|
||||||
@ -149,7 +149,7 @@ protected:
|
|||||||
virtual bool onRedirectUrl(const string &url,bool temporary){ return true;};
|
virtual bool onRedirectUrl(const string &url,bool temporary){ return true;};
|
||||||
|
|
||||||
//HttpRequestSplitter 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;
|
void onRecvContent(const char *data,size_t len) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -174,7 +174,7 @@ private:
|
|||||||
string _path;
|
string _path;
|
||||||
//recv
|
//recv
|
||||||
size_t _recvedBodySize;
|
size_t _recvedBodySize;
|
||||||
size_t _totalBodySize;
|
ssize_t _totalBodySize;
|
||||||
Parser _parser;
|
Parser _parser;
|
||||||
string _lastHost;
|
string _lastHost;
|
||||||
Ticker _aliveTicker;
|
Ticker _aliveTicker;
|
||||||
|
@ -47,7 +47,7 @@ void HttpDownloader::startDownload(const string& url, const string& filePath,boo
|
|||||||
sendRequest(url,timeOutSecond);
|
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"){
|
if(status != "200" && status != "206"){
|
||||||
//失败
|
//失败
|
||||||
shutdown(SockException(Err_shutdown,StrPrinter << "Http Status:" << status));
|
shutdown(SockException(Err_shutdown,StrPrinter << "Http Status:" << status));
|
||||||
|
@ -31,7 +31,7 @@ public:
|
|||||||
_onResult = cb;
|
_onResult = cb;
|
||||||
}
|
}
|
||||||
private:
|
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 onResponseBody(const char *buf, size_t size, size_t recvedSize, size_t totalSize) override;
|
||||||
void onResponseCompleted() override;
|
void onResponseCompleted() override;
|
||||||
void onDisconnect(const SockException &ex) override;
|
void onDisconnect(const SockException &ex) override;
|
||||||
|
@ -44,7 +44,7 @@ void HttpRequestSplitter::input(const char *data,size_t len) {
|
|||||||
}
|
}
|
||||||
//_content_len == 0,这是请求头
|
//_content_len == 0,这是请求头
|
||||||
const char *header_ptr = ptr;
|
const char *header_ptr = ptr;
|
||||||
auto header_size = index - ptr;
|
ssize_t header_size = index - ptr;
|
||||||
ptr = index;
|
ptr = index;
|
||||||
_remain_data_size = len - (ptr - data);
|
_remain_data_size = len - (ptr - data);
|
||||||
_content_len = onRecvHeader(header_ptr, header_size);
|
_content_len = onRecvHeader(header_ptr, header_size);
|
||||||
@ -71,7 +71,7 @@ void HttpRequestSplitter::input(const char *data,size_t len) {
|
|||||||
//已经找到http头了
|
//已经找到http头了
|
||||||
if(_content_len > 0){
|
if(_content_len > 0){
|
||||||
//数据按照固定长度content处理
|
//数据按照固定长度content处理
|
||||||
if(_remain_data_size < _content_len){
|
if(_remain_data_size < (size_t)_content_len){
|
||||||
//数据不够,缓存定位到剩余数据部分
|
//数据不够,缓存定位到剩余数据部分
|
||||||
_remain_data.assign(ptr, _remain_data_size);
|
_remain_data.assign(ptr, _remain_data_size);
|
||||||
return;
|
return;
|
||||||
@ -101,7 +101,7 @@ void HttpRequestSplitter::input(const char *data,size_t len) {
|
|||||||
_remain_data.clear();
|
_remain_data.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpRequestSplitter::setContentLen(size_t content_len) {
|
void HttpRequestSplitter::setContentLen(ssize_t content_len) {
|
||||||
_content_len = content_len;
|
_content_len = content_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ protected:
|
|||||||
* 0 : 代表为后面数据还是请求头,
|
* 0 : 代表为后面数据还是请求头,
|
||||||
* >0 : 代表后面数据为固定长度content,此时将缓存content并等到所有content接收完毕一次性通过onRecvContent函数回调出去
|
* >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分片或全部数据
|
* 收到content分片或全部数据
|
||||||
@ -62,7 +62,7 @@ protected:
|
|||||||
/**
|
/**
|
||||||
* 设置content len
|
* 设置content len
|
||||||
*/
|
*/
|
||||||
void setContentLen(size_t content_len);
|
void setContentLen(ssize_t content_len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 恢复初始设置
|
* 恢复初始设置
|
||||||
@ -75,7 +75,7 @@ protected:
|
|||||||
size_t remainDataSize();
|
size_t remainDataSize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t _content_len = 0;
|
ssize_t _content_len = 0;
|
||||||
size_t _remain_data_size = 0;
|
size_t _remain_data_size = 0;
|
||||||
BufferLikeString _remain_data;
|
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();
|
_strRecvBody.clear();
|
||||||
//无Content-Length字段时默认后面没有content
|
//无Content-Length字段时默认后面没有content
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -26,7 +26,7 @@ public:
|
|||||||
void startRequester(const string &url,const HttpRequesterResult &onResult,float timeOutSecond = 10);
|
void startRequester(const string &url,const HttpRequesterResult &onResult,float timeOutSecond = 10);
|
||||||
void clear() override ;
|
void clear() override ;
|
||||||
private:
|
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 onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) override;
|
||||||
void onResponseCompleted() override;
|
void onResponseCompleted() override;
|
||||||
void onDisconnect(const SockException &ex) override;
|
void onDisconnect(const SockException &ex) override;
|
||||||
|
@ -31,15 +31,15 @@ HttpSession::~HttpSession() {
|
|||||||
TraceP(this);
|
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的流程返回
|
//暂时全部返回200 OK,因为HTTP GET存在按需生成流的操作,所以不能按照HTTP GET的流程返回
|
||||||
//如果直接返回404,那么又会导致按需生成流的逻辑失效,所以HTTP HEAD在静态文件或者已存在资源时才有效
|
//如果直接返回404,那么又会导致按需生成流的逻辑失效,所以HTTP HEAD在静态文件或者已存在资源时才有效
|
||||||
//对于按需生成流的直播场景并不适用
|
//对于按需生成流的直播场景并不适用
|
||||||
sendResponse(200, true);
|
sendResponse(200, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t HttpSession::onRecvHeader(const char *header,size_t len) {
|
ssize_t HttpSession::onRecvHeader(const char *header,size_t len) {
|
||||||
typedef void (HttpSession::*HttpCMDHandle)(size_t &);
|
typedef void (HttpSession::*HttpCMDHandle)(ssize_t &);
|
||||||
static unordered_map<string, HttpCMDHandle> s_func_map;
|
static unordered_map<string, HttpCMDHandle> s_func_map;
|
||||||
static onceToken token([]() {
|
static onceToken token([]() {
|
||||||
s_func_map.emplace("GET",&HttpSession::Handle_Req_GET);
|
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"];
|
_origin = _parser["Origin"];
|
||||||
|
|
||||||
//默认后面数据不是content而是header
|
//默认后面数据不是content而是header
|
||||||
size_t content_len = 0;
|
ssize_t content_len = 0;
|
||||||
auto &fun = it->second;
|
auto &fun = it->second;
|
||||||
try {
|
try {
|
||||||
(this->*fun)(content_len);
|
(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);
|
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请求
|
//先看看是否为WebSocket请求
|
||||||
if (checkWebSocket()) {
|
if (checkWebSocket()) {
|
||||||
content_len = -1;
|
content_len = -1;
|
||||||
@ -506,7 +506,7 @@ void HttpSession::sendResponse(int code,
|
|||||||
GET_CONFIG(uint32_t,keepAliveSec,Http::kKeepAliveSecond);
|
GET_CONFIG(uint32_t,keepAliveSec,Http::kKeepAliveSecond);
|
||||||
|
|
||||||
//body默认为空
|
//body默认为空
|
||||||
size_t size = 0;
|
ssize_t size = 0;
|
||||||
if (body && body->remainSize()) {
|
if (body && body->remainSize()) {
|
||||||
//有body,获取body大小
|
//有body,获取body大小
|
||||||
size = body->remainSize();
|
size = body->remainSize();
|
||||||
@ -515,7 +515,7 @@ void HttpSession::sendResponse(int code,
|
|||||||
if(no_content_length){
|
if(no_content_length){
|
||||||
//http-flv直播是Keep-Alive类型
|
//http-flv直播是Keep-Alive类型
|
||||||
bClose = false;
|
bClose = false;
|
||||||
}else if(size >= INT64_MAX || size < 0 ){
|
}else if(size >= SIZE_MAX || size < 0 ){
|
||||||
//不固定长度的body,那么发送完body后应该关闭socket,以便浏览器做下载完毕的判断
|
//不固定长度的body,那么发送完body后应该关闭socket,以便浏览器做下载完毕的判断
|
||||||
bClose = true;
|
bClose = true;
|
||||||
}
|
}
|
||||||
@ -537,7 +537,7 @@ void HttpSession::sendResponse(int code,
|
|||||||
headerOut.emplace(kAccessControlAllowCredentials, "true");
|
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
|
//文件长度为固定值,且不是http-flv强制设置Content-Length
|
||||||
headerOut[kContentLength] = to_string(size);
|
headerOut[kContentLength] = to_string(size);
|
||||||
}
|
}
|
||||||
@ -642,10 +642,10 @@ bool HttpSession::emitHttpEvent(bool doInvoke){
|
|||||||
return consumed;
|
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);
|
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){
|
if(totalContentLen == 0){
|
||||||
//content为空
|
//content为空
|
||||||
@ -654,7 +654,7 @@ void HttpSession::Handle_Req_POST(size_t &content_len) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(totalContentLen > 0 && totalContentLen < maxReqSize ){
|
if(totalContentLen > 0 && (size_t)totalContentLen < maxReqSize ){
|
||||||
//返回固定长度的content
|
//返回固定长度的content
|
||||||
content_len = totalContentLen;
|
content_len = totalContentLen;
|
||||||
auto parserCopy = _parser;
|
auto parserCopy = _parser;
|
||||||
@ -671,7 +671,7 @@ void HttpSession::Handle_Req_POST(size_t &content_len) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
}else{
|
}else{
|
||||||
//返回不固定长度的content
|
//返回不固定长度的content或者超过长度限制的content
|
||||||
content_len = -1;
|
content_len = -1;
|
||||||
auto parserCopy = _parser;
|
auto parserCopy = _parser;
|
||||||
std::shared_ptr<size_t> recvedContentLen = std::make_shared<size_t>(0);
|
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){
|
_contentCallBack = [this,parserCopy,totalContentLen,recvedContentLen,bClose](const char *data,size_t len){
|
||||||
*(recvedContentLen) += len;
|
*(recvedContentLen) += len;
|
||||||
|
if (totalContentLen < 0) {
|
||||||
|
//不固定长度的content,源源不断接收数据
|
||||||
|
onRecvUnlimitedContent(parserCopy, data, len, SIZE_MAX, *(recvedContentLen));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//长度超过限制的content
|
||||||
onRecvUnlimitedContent(parserCopy,data,len,totalContentLen,*(recvedContentLen));
|
onRecvUnlimitedContent(parserCopy,data,len,totalContentLen,*(recvedContentLen));
|
||||||
|
|
||||||
if(*(recvedContentLen) < totalContentLen){
|
if(*(recvedContentLen) < (size_t)totalContentLen){
|
||||||
//数据还没接收完毕
|
//数据还没接收完毕
|
||||||
//_contentCallBack是可持续的,后面还要处理后续content数据
|
//_contentCallBack是可持续的,后面还要处理后续content数据
|
||||||
return true;
|
return true;
|
||||||
|
@ -57,7 +57,7 @@ protected:
|
|||||||
std::shared_ptr<FlvMuxer> getSharedPtr() override;
|
std::shared_ptr<FlvMuxer> getSharedPtr() override;
|
||||||
|
|
||||||
//HttpRequestSplitter 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;
|
void onRecvContent(const char *data,size_t len) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,10 +101,10 @@ protected:
|
|||||||
void onWebSocketDecodeComplete(const WebSocketHeader &header_in) override;
|
void onWebSocketDecodeComplete(const WebSocketHeader &header_in) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Handle_Req_GET(size_t &content_len);
|
void Handle_Req_GET(ssize_t &content_len);
|
||||||
void Handle_Req_GET_l(size_t &content_len, bool sendBody);
|
void Handle_Req_GET_l(ssize_t &content_len, bool sendBody);
|
||||||
void Handle_Req_POST(size_t &content_len);
|
void Handle_Req_POST(ssize_t &content_len);
|
||||||
void Handle_Req_HEAD(size_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);
|
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() {}
|
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;
|
_status = status;
|
||||||
if (status != "200" && status != "206") {
|
if (status != "200" && status != "206") {
|
||||||
//http状态码不符合预期
|
//http状态码不符合预期
|
||||||
|
@ -33,7 +33,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
///HttpClient override///
|
///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 onResponseBody(const char *buf,size_t size,size_t recvedSize,size_t totalSize) override;
|
||||||
void onResponseCompleted() override;
|
void onResponseCompleted() override;
|
||||||
void onDisconnect(const SockException &ex) override ;
|
void onDisconnect(const SockException &ex) override ;
|
||||||
|
@ -32,7 +32,7 @@ class HttpWsClient;
|
|||||||
template <typename ClientType,WebSocketHeader::Type DataType>
|
template <typename ClientType,WebSocketHeader::Type DataType>
|
||||||
class ClientTypeImp : public ClientType {
|
class ClientTypeImp : public ClientType {
|
||||||
public:
|
public:
|
||||||
typedef function<size_t (const Buffer::Ptr &buf)> onBeforeSendCB;
|
typedef function<ssize_t (const Buffer::Ptr &buf)> onBeforeSendCB;
|
||||||
friend class HttpWsClient<ClientType,DataType>;
|
friend class HttpWsClient<ClientType,DataType>;
|
||||||
|
|
||||||
template<typename ...ArgsType>
|
template<typename ...ArgsType>
|
||||||
@ -43,7 +43,7 @@ protected:
|
|||||||
/**
|
/**
|
||||||
* 发送前拦截并打包为websocket协议
|
* 发送前拦截并打包为websocket协议
|
||||||
*/
|
*/
|
||||||
size_t send(Buffer::Ptr buf) override{
|
ssize_t send(Buffer::Ptr buf) override{
|
||||||
if(_beforeSendCB){
|
if(_beforeSendCB){
|
||||||
return _beforeSendCB(buf);
|
return _beforeSendCB(buf);
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ protected:
|
|||||||
* @return 返回后续content的长度;-1:后续数据全是content;>=0:固定长度content
|
* @return 返回后续content的长度;-1:后续数据全是content;>=0:固定长度content
|
||||||
* 需要指出的是,在http头中带有Content-Length字段时,该返回值无效
|
* 需要指出的是,在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"){
|
if(status == "101"){
|
||||||
auto Sec_WebSocket_Accept = encodeBase64(SHA1::encode_bin(_Sec_WebSocket_Key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"));
|
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"]){
|
if(Sec_WebSocket_Accept == const_cast<HttpHeader &>(headers)["Sec-WebSocket-Accept"]){
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
class SendInterceptor{
|
class SendInterceptor{
|
||||||
public:
|
public:
|
||||||
typedef function<size_t (const Buffer::Ptr &buf)> onBeforeSendCB;
|
typedef function<ssize_t (const Buffer::Ptr &buf)> onBeforeSendCB;
|
||||||
SendInterceptor() = default;
|
SendInterceptor() = default;
|
||||||
virtual ~SendInterceptor() = default;
|
virtual ~SendInterceptor() = default;
|
||||||
virtual void setOnBeforeSendCB(const onBeforeSendCB &cb) = 0;
|
virtual void setOnBeforeSendCB(const onBeforeSendCB &cb) = 0;
|
||||||
@ -53,7 +53,7 @@ protected:
|
|||||||
* @param buf 需要截取的数据
|
* @param buf 需要截取的数据
|
||||||
* @return 数据字节数
|
* @return 数据字节数
|
||||||
*/
|
*/
|
||||||
size_t send(Buffer::Ptr buf) override {
|
ssize_t send(Buffer::Ptr buf) override {
|
||||||
if (_beforeSendCB) {
|
if (_beforeSendCB) {
|
||||||
return _beforeSendCB(buf);
|
return _beforeSendCB(buf);
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ begin_decode:
|
|||||||
|
|
||||||
void WebSocketSplitter::onPayloadData(uint8_t *data, size_t len) {
|
void WebSocketSplitter::onPayloadData(uint8_t *data, size_t len) {
|
||||||
if(_mask_flag){
|
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];
|
*(data) ^= _mask[(i + _mask_offset) % 4];
|
||||||
}
|
}
|
||||||
_mask_offset = (_mask_offset + len) % 4;
|
_mask_offset = (_mask_offset + len) % 4;
|
||||||
@ -184,7 +184,7 @@ void WebSocketSplitter::encode(const WebSocketHeader &header,const Buffer::Ptr &
|
|||||||
if(len > 0){
|
if(len > 0){
|
||||||
if(mask_flag){
|
if(mask_flag){
|
||||||
uint8_t *ptr = (uint8_t*)buffer->data();
|
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];
|
*(ptr) ^= header._mask[i % 4];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ PlayerBase::PlayerBase() {
|
|||||||
|
|
||||||
///////////////////////////Demuxer//////////////////////////////
|
///////////////////////////Demuxer//////////////////////////////
|
||||||
bool Demuxer::isInited(int analysisMs) {
|
bool Demuxer::isInited(int analysisMs) {
|
||||||
if(analysisMs && _ticker.createdTime() > analysisMs){
|
if(analysisMs && _ticker.createdTime() > (uint64_t)analysisMs){
|
||||||
//analysisMs毫秒后强制初始化完毕
|
//analysisMs毫秒后强制初始化完毕
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -232,7 +232,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _audio_idx = 0;
|
uint32_t _audio_idx = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void PlayerProxy::onPlaySuccess() {
|
void PlayerProxy::onPlaySuccess() {
|
||||||
|
@ -115,7 +115,7 @@ void RtmpPlayer::onPlayResult_l(const SockException &ex, bool handshake_done) {
|
|||||||
if (!ex) {
|
if (!ex) {
|
||||||
//播放成功,恢复rtmp接收超时定时器
|
//播放成功,恢复rtmp接收超时定时器
|
||||||
_rtmp_recv_ticker.resetTime();
|
_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());
|
weak_ptr<RtmpPlayer> weakSelf = dynamic_pointer_cast<RtmpPlayer>(shared_from_this());
|
||||||
auto lam = [weakSelf, timeout_ms]() {
|
auto lam = [weakSelf, timeout_ms]() {
|
||||||
auto strongSelf = weakSelf.lock();
|
auto strongSelf = weakSelf.lock();
|
||||||
|
@ -48,7 +48,7 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
//// HttpRequestSplitter override ////
|
//// 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;
|
const char *onSearchPacketTail(const char *data, size_t len) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -38,7 +38,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void onRtpSorted(const RtpPacket::Ptr &rtp, int track_index) override ;
|
void onRtpSorted(const RtpPacket::Ptr &rtp, int track_index) override ;
|
||||||
const char *onSearchPacketTail(const char *data,size_t len) 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:
|
private:
|
||||||
void onRtpDecode(const Frame::Ptr &frame);
|
void onRtpDecode(const Frame::Ptr &frame);
|
||||||
|
@ -139,7 +139,7 @@ bool RtpProcess::alive() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
GET_CONFIG(int, timeoutSec, RtpProxy::kTimeoutSec)
|
GET_CONFIG(uint64_t, timeoutSec, RtpProxy::kTimeoutSec)
|
||||||
if (_last_frame_time.elapsedTime() / 1000 < timeoutSec) {
|
if (_last_frame_time.elapsedTime() / 1000 < timeoutSec) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ static const int kEHOME_OFFSET = 256;
|
|||||||
RtpSplitter::RtpSplitter() {}
|
RtpSplitter::RtpSplitter() {}
|
||||||
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;
|
data += _offset;
|
||||||
len -= _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) {
|
const char *RtpSplitter::onSearchPacketTail_l(const char *data, size_t len) {
|
||||||
//这是rtp包
|
//这是rtp包
|
||||||
uint16_t length = (((uint8_t *) data)[0] << 8) | ((uint8_t *) data)[1];
|
uint16_t length = (((uint8_t *) data)[0] << 8) | ((uint8_t *) data)[1];
|
||||||
if (len < length + 2) {
|
if (len < (size_t)(length + 2)) {
|
||||||
//数据不够
|
//数据不够
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ protected:
|
|||||||
virtual void onRtpPacket(const char *data, size_t len) = 0;
|
virtual void onRtpPacket(const char *data, size_t len) = 0;
|
||||||
|
|
||||||
protected:
|
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(const char *data, size_t len) override;
|
||||||
const char *onSearchPacketTail_l(const char *data, size_t len);
|
const char *onSearchPacketTail_l(const char *data, size_t len);
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ void TSSegment::setOnSegment(const TSSegment::onSegment &cb) {
|
|||||||
_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)) {
|
if (!isTSPacket(data, len)) {
|
||||||
WarnL << "不是ts包:" << (int) (data[0]) << " " << len;
|
WarnL << "不是ts包:" << (int) (data[0]) << " " << len;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -31,7 +31,7 @@ public:
|
|||||||
static bool isTSPacket(const char *data, size_t len);
|
static bool isTSPacket(const char *data, size_t len);
|
||||||
|
|
||||||
protected:
|
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(const char *data, size_t len) override ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -775,7 +775,7 @@ void RtspPlayer::onPlayResult_l(const SockException &ex , bool handshake_done) {
|
|||||||
if (!ex) {
|
if (!ex) {
|
||||||
//播放成功,恢复rtp接收超时定时器
|
//播放成功,恢复rtp接收超时定时器
|
||||||
_rtp_recv_ticker.resetTime();
|
_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());
|
weak_ptr<RtspPlayer> weakSelf = dynamic_pointer_cast<RtspPlayer>(shared_from_this());
|
||||||
auto lam = [weakSelf, timeoutMS]() {
|
auto lam = [weakSelf, timeoutMS]() {
|
||||||
auto strongSelf = weakSelf.lock();
|
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){}
|
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"){
|
if(parser.Method() == "POST"){
|
||||||
//http post请求的content数据部分是base64编码后的rtsp请求信令包
|
//http post请求的content数据部分是base64编码后的rtsp请求信令包
|
||||||
return remainDataSize();
|
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 ;
|
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){
|
// if(!_enableSendRtp){
|
||||||
// DebugP(this) << pkt->data();
|
// DebugP(this) << pkt->data();
|
||||||
// }
|
// }
|
||||||
|
@ -75,7 +75,7 @@ protected:
|
|||||||
//收到rtp包回调
|
//收到rtp包回调
|
||||||
void onRtpPacket(const char *data, size_t len) override;
|
void onRtpPacket(const char *data, size_t len) override;
|
||||||
//从rtsp头中获取Content长度
|
//从rtsp头中获取Content长度
|
||||||
size_t getContentLength(Parser &parser) override;
|
ssize_t getContentLength(Parser &parser) override;
|
||||||
|
|
||||||
////RtpReceiver override////
|
////RtpReceiver override////
|
||||||
void onRtpSorted(const RtpPacket::Ptr &rtp, int track_idx) 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;
|
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
|
||||||
|
|
||||||
/////TcpSession override////
|
/////TcpSession override////
|
||||||
size_t send(Buffer::Ptr pkt) override;
|
ssize_t send(Buffer::Ptr pkt) override;
|
||||||
//收到RTCP包回调
|
//收到RTCP包回调
|
||||||
virtual void onRtcpPacket(int track_idx, SdpTrack::Ptr &track, const char *data, size_t len);
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
uint16_t length = (((uint8_t *)data)[2] << 8) | ((uint8_t *)data)[3];
|
uint16_t length = (((uint8_t *)data)[2] << 8) | ((uint8_t *)data)[3];
|
||||||
if(len < length + 4){
|
if(len < (size_t)(length + 4)){
|
||||||
//数据不够
|
//数据不够
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ const char *RtspSplitter::onSearchPacketTail_l(const char *data, size_t len) {
|
|||||||
return data + 4 + length;
|
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){
|
if(_isRtpPacket){
|
||||||
onRtpPacket(data,len);
|
onRtpPacket(data,len);
|
||||||
return 0;
|
return 0;
|
||||||
@ -77,7 +77,7 @@ void RtspSplitter::enableRecvRtp(bool enable) {
|
|||||||
_enableRecvRtp = enable;
|
_enableRecvRtp = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t RtspSplitter::getContentLength(Parser &parser) {
|
ssize_t RtspSplitter::getContentLength(Parser &parser) {
|
||||||
return atoi(parser["Content-Length"].data());
|
return atoi(parser["Content-Length"].data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,12 +45,12 @@ protected:
|
|||||||
* @param parser
|
* @param parser
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
virtual size_t getContentLength(Parser &parser);
|
virtual ssize_t getContentLength(Parser &parser);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const char *onSearchPacketTail(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) ;
|
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;
|
void onRecvContent(const char *data,size_t len) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user