格式化HttpSession.cpp代码

This commit is contained in:
xia-chu 2023-06-10 09:45:46 +08:00 committed by 夏楚
parent 7e1078bbcc
commit fff53cf0e2

View File

@ -53,15 +53,15 @@ void HttpSession::Handle_Req_OPTIONS(ssize_t &content_len) {
} }
ssize_t HttpSession::onRecvHeader(const char *header, size_t len) { ssize_t HttpSession::onRecvHeader(const char *header, size_t len) {
typedef void (HttpSession::*HttpCMDHandle)(ssize_t &); using func_type = void (HttpSession::*)(ssize_t &);
static unordered_map<string, HttpCMDHandle> s_func_map; static unordered_map<string, func_type> 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);
s_func_map.emplace("DELETE", &HttpSession::Handle_Req_GET); s_func_map.emplace("DELETE", &HttpSession::Handle_Req_GET);
s_func_map.emplace("POST", &HttpSession::Handle_Req_POST); s_func_map.emplace("POST", &HttpSession::Handle_Req_POST);
s_func_map.emplace("HEAD", &HttpSession::Handle_Req_HEAD); s_func_map.emplace("HEAD", &HttpSession::Handle_Req_HEAD);
s_func_map.emplace("OPTIONS", &HttpSession::Handle_Req_OPTIONS); s_func_map.emplace("OPTIONS", &HttpSession::Handle_Req_OPTIONS);
}, nullptr); });
_parser.Parse(header); _parser.Parse(header);
CHECK(_parser.Url()[0] == '/'); CHECK(_parser.Url()[0] == '/');
@ -89,12 +89,10 @@ ssize_t HttpSession::onRecvHeader(const char *header,size_t len) {
} }
void HttpSession::onRecvContent(const char *data, size_t len) { void HttpSession::onRecvContent(const char *data, size_t len) {
if(_contentCallBack){ if (_contentCallBack && !_contentCallBack(data, len)) {
if(!_contentCallBack(data,len)){
_contentCallBack = nullptr; _contentCallBack = nullptr;
} }
} }
}
void HttpSession::onRecv(const Buffer::Ptr &pBuf) { void HttpSession::onRecv(const Buffer::Ptr &pBuf) {
_ticker.resetTime(); _ticker.resetTime();
@ -105,15 +103,11 @@ void HttpSession::onError(const SockException& err) {
if (_is_live_stream) { if (_is_live_stream) {
// flv/ts播放器 // flv/ts播放器
uint64_t duration = _ticker.createdTime() / 1000; uint64_t duration = _ticker.createdTime() / 1000;
WarnP(this) << "FLV/TS/FMP4播放器(" WarnP(this) << "FLV/TS/FMP4播放器(" << _mediaInfo.shortUrl() << ")断开:" << err << ",耗时(s):" << duration;
<< _mediaInfo.shortUrl()
<< ")断开:" << err
<< ",耗时(s):" << duration;
GET_CONFIG(uint32_t, iFlowThreshold, General::kFlowThreshold); GET_CONFIG(uint32_t, iFlowThreshold, General::kFlowThreshold);
if (_total_bytes_usage >= iFlowThreshold * 1024) { if (_total_bytes_usage >= iFlowThreshold * 1024) {
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _total_bytes_usage, NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastFlowReport, _mediaInfo, _total_bytes_usage, duration, true, static_cast<SockInfo &>(*this));
duration, true, static_cast<SockInfo &>(*this));
} }
return; return;
} }
@ -298,9 +292,7 @@ bool HttpSession::checkLiveStreamFMP4(const function<void()> &cb){
} }
size_t i = 0; size_t i = 0;
auto size = fmp4_list->size(); auto size = fmp4_list->size();
fmp4_list->for_each([&](const FMP4Packet::Ptr &ts) { fmp4_list->for_each([&](const FMP4Packet::Ptr &ts) { strong_self->onWrite(ts, ++i == size); });
strong_self->onWrite(ts, ++i == size);
});
}); });
}); });
} }
@ -340,9 +332,7 @@ bool HttpSession::checkLiveStreamTS(const function<void()> &cb){
} }
size_t i = 0; size_t i = 0;
auto size = ts_list->size(); auto size = ts_list->size();
ts_list->for_each([&](const TSPacket::Ptr &ts) { ts_list->for_each([&](const TSPacket::Ptr &ts) { strong_self->onWrite(ts, ++i == size); });
strong_self->onWrite(ts, ++i == size);
});
}); });
}); });
} }
@ -370,8 +360,7 @@ bool HttpSession::checkLiveStreamFlv(const function<void()> &cb){
for (auto &track : tracks) { for (auto &track : tracks) {
switch (track->getCodecId()) { switch (track->getCodecId()) {
case CodecH264: case CodecH264:
case CodecAAC: case CodecAAC: break;
break;
default: { default: {
WarnP(this) << "flv播放器一般只支持H264和AAC编码,该编码格式可能不被播放器支持:" << track->getCodecName(); WarnP(this) << "flv播放器一般只支持H264和AAC编码,该编码格式可能不被播放器支持:" << track->getCodecName();
break; break;