优化Parser代码命名

This commit is contained in:
xia-chu
2023-06-10 11:04:52 +08:00
committed by 夏楚
parent 52c7bc1d34
commit af0ebf4633
24 changed files with 156 additions and 147 deletions

View File

@@ -33,7 +33,7 @@ RtspPlayer::RtspPlayer(const EventPoller::Ptr &poller)
: TcpClient(poller) {}
RtspPlayer::~RtspPlayer(void) {
DebugL << endl;
DebugL;
}
void RtspPlayer::sendTeardown() {
@@ -170,11 +170,11 @@ bool RtspPlayer::handleAuthenticationFailure(const string &paramsStr) {
bool RtspPlayer::handleResponse(const string &cmd, const Parser &parser) {
string authInfo = parser["WWW-Authenticate"];
// 发送DESCRIBE命令后的回复
if ((parser.Url() == "401") && handleAuthenticationFailure(authInfo)) {
if ((parser.status() == "401") && handleAuthenticationFailure(authInfo)) {
sendOptions();
return false;
}
if (parser.Url() == "302" || parser.Url() == "301") {
if (parser.status() == "302" || parser.status() == "301") {
auto newUrl = parser["Location"];
if (newUrl.empty()) {
throw std::runtime_error("未找到Location字段(跳转url)");
@@ -182,8 +182,8 @@ bool RtspPlayer::handleResponse(const string &cmd, const Parser &parser) {
play(newUrl);
return false;
}
if (parser.Url() != "200") {
throw std::runtime_error(StrPrinter << cmd << ":" << parser.Url() << " " << parser.Tail() << endl);
if (parser.status() != "200") {
throw std::runtime_error(StrPrinter << cmd << ":" << parser.status() << " " << parser.statusStr() << endl);
}
return true;
}
@@ -201,7 +201,7 @@ void RtspPlayer::handleResDESCRIBE(const Parser &parser) {
}
// 解析sdp
SdpParser sdpParser(parser.Content());
SdpParser sdpParser(parser.content());
string sdp;
auto play_track = (TrackType)((int)(*this)[Client::kPlayTrack] - 1);
@@ -267,8 +267,8 @@ void RtspPlayer::sendSetup(unsigned int track_idx) {
}
void RtspPlayer::handleResSETUP(const Parser &parser, unsigned int track_idx) {
if (parser.Url() != "200") {
throw std::runtime_error(StrPrinter << "SETUP:" << parser.Url() << " " << parser.Tail() << endl);
if (parser.status() != "200") {
throw std::runtime_error(StrPrinter << "SETUP:" << parser.status() << " " << parser.statusStr() << endl);
}
if (track_idx == 0) {
_session_id = parser["Session"];
@@ -446,14 +446,14 @@ void RtspPlayer::speed(float speed) {
}
void RtspPlayer::handleResPAUSE(const Parser &parser, int type) {
if (parser.Url() != "200") {
if (parser.status() != "200") {
switch (type) {
case type_pause: WarnL << "Pause failed:" << parser.Url() << " " << parser.Tail() << endl; break;
case type_pause: WarnL << "Pause failed:" << parser.status() << " " << parser.statusStr(); break;
case type_play:
WarnL << "Play failed:" << parser.Url() << " " << parser.Tail() << endl;
onPlayResult_l(SockException(Err_shutdown, StrPrinter << "rtsp play failed:" << parser.Url() << " " << parser.Tail()), !_play_check_timer);
WarnL << "Play failed:" << parser.status() << " " << parser.statusStr();
onPlayResult_l(SockException(Err_shutdown, StrPrinter << "rtsp play failed:" << parser.status() << " " << parser.statusStr()), !_play_check_timer);
break;
case type_seek: WarnL << "Seek failed:" << parser.Url() << " " << parser.Tail() << endl; break;
case type_seek: WarnL << "Seek failed:" << parser.status() << " " << parser.statusStr(); break;
}
return;
}
@@ -487,7 +487,7 @@ void RtspPlayer::onWholeRtspPacket(Parser &parser) {
if (func) {
func(parser);
}
parser.Clear();
parser.clear();
} catch (std::exception &err) {
// 定时器_pPlayTimer为空后表明握手结束了
onPlayResult_l(SockException(Err_other, err.what()), !_play_check_timer);

View File

@@ -28,7 +28,7 @@ public:
RtspPlayerImp(const toolkit::EventPoller::Ptr &poller) : Super(poller) {}
~RtspPlayerImp() override {
DebugL << std::endl;
DebugL;
}
float getProgress() const override {

View File

@@ -26,7 +26,7 @@ RtspPusher::RtspPusher(const EventPoller::Ptr &poller, const RtspMediaSource::Pt
RtspPusher::~RtspPusher() {
teardown();
DebugL << endl;
DebugL;
}
void RtspPusher::sendTeardown(){
@@ -147,7 +147,7 @@ void RtspPusher::onWholeRtspPacket(Parser &parser) {
if (func) {
func(parser);
}
parser.Clear();
parser.clear();
}
void RtspPusher::onRtpPacket(const char *data, size_t len) {
@@ -188,11 +188,11 @@ void RtspPusher::sendAnnounce() {
void RtspPusher::handleResAnnounce(const Parser &parser) {
string authInfo = parser["WWW-Authenticate"];
//发送DESCRIBE命令后的回复
if ((parser.Url() == "401") && handleAuthenticationFailure(authInfo)) {
if ((parser.status() == "401") && handleAuthenticationFailure(authInfo)) {
sendAnnounce();
return;
}
if (parser.Url() == "302") {
if (parser.status() == "302") {
auto newUrl = parser["Location"];
if (newUrl.empty()) {
throw std::runtime_error("未找到Location字段(跳转url)");
@@ -200,8 +200,8 @@ void RtspPusher::handleResAnnounce(const Parser &parser) {
publish(newUrl);
return;
}
if (parser.Url() != "200") {
throw std::runtime_error(StrPrinter << "ANNOUNCE:" << parser.Url() << " " << parser.Tail());
if (parser.status() != "200") {
throw std::runtime_error(StrPrinter << "ANNOUNCE:" << parser.status() << " " << parser.statusStr());
}
_content_base = parser["Content-Base"];
@@ -285,8 +285,8 @@ void RtspPusher::sendSetup(unsigned int track_idx) {
}
void RtspPusher::handleResSetup(const Parser &parser, unsigned int track_idx) {
if (parser.Url() != "200") {
throw std::runtime_error(StrPrinter << "SETUP:" << parser.Url() << " " << parser.Tail() << endl);
if (parser.status() != "200") {
throw std::runtime_error(StrPrinter << "SETUP:" << parser.status() << " " << parser.statusStr() << endl);
}
if (track_idx == 0) {
_session_id = parser["Session"];

View File

@@ -128,11 +128,11 @@ void RtspSession::onRecv(const Buffer::Ptr &buf) {
}
void RtspSession::onWholeRtspPacket(Parser &parser) {
string method = parser.Method(); //提取出请求命令字
string method = parser.method(); //提取出请求命令字
_cseq = atoi(parser["CSeq"].data());
if (_content_base.empty() && method != "GET") {
_content_base = parser.Url();
_media_info.parse(parser.FullUrl());
_content_base = parser.url();
_media_info.parse(parser.fullUrl());
_media_info.schema = RTSP_SCHEMA;
}
@@ -160,7 +160,7 @@ void RtspSession::onWholeRtspPacket(Parser &parser) {
}
(this->*(it->second))(parser);
parser.Clear();
parser.clear();
}
void RtspSession::onRtpPacket(const char *data, size_t len) {
@@ -187,7 +187,7 @@ void RtspSession::onRtcpPacket(int track_idx, SdpTrack::Ptr &track, const char *
}
ssize_t RtspSession::getContentLength(Parser &parser) {
if(parser.Method() == "POST"){
if(parser.method() == "POST"){
//http post请求的content数据部分是base64编码后的rtsp请求信令包
return remainDataSize();
}
@@ -200,7 +200,7 @@ void RtspSession::handleReq_Options(const Parser &parser) {
}
void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
auto full_url = parser.FullUrl();
auto full_url = parser.fullUrl();
_content_base = full_url;
if (end_with(full_url, ".sdp")) {
//去除.sdp后缀防止EasyDarwin推流器强制添加.sdp后缀
@@ -250,7 +250,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
throw SockException(Err_shutdown, err);
}
SdpParser sdpParser(parser.Content());
SdpParser sdpParser(parser.content());
_sessionid = makeRandStr(12);
_sdp_track = sdpParser.getAvailableTrack();
if (_sdp_track.empty()) {
@@ -270,7 +270,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
//获取所有权
_push_src_ownership = _push_src->getOwnership();
_push_src->setProtocolOption(option);
_push_src->setSdp(parser.Content());
_push_src->setSdp(parser.content());
}
_push_src->setListener(static_pointer_cast<RtspSession>(shared_from_this()));
@@ -628,7 +628,7 @@ void RtspSession::send_SessionNotFound() {
void RtspSession::handleReq_Setup(const Parser &parser) {
//处理setup命令该函数可能进入多次
int trackIdx = getTrackIndexByControlUrl(parser.FullUrl());
int trackIdx = getTrackIndexByControlUrl(parser.fullUrl());
SdpTrack::Ptr &trackRef = _sdp_track[trackIdx];
if (trackRef->_inited) {
//已经初始化过该Track
@@ -915,9 +915,9 @@ void RtspSession::handleReq_Post(const Parser &parser) {
});
};
if(!parser.Content().empty()){
if(!parser.content().empty()){
//http poster后面的粘包
_on_recv(std::make_shared<BufferString>(parser.Content()));
_on_recv(std::make_shared<BufferString>(parser.content()));
}
sendRtspResponse("200 OK",

View File

@@ -65,7 +65,7 @@ ssize_t RtspSplitter::onRecvHeader(const char *data, size_t len) {
auto ret = getContentLength(_parser);
if(ret == 0){
onWholeRtspPacket(_parser);
_parser.Clear();
_parser.clear();
}
return ret;
}
@@ -73,7 +73,7 @@ ssize_t RtspSplitter::onRecvHeader(const char *data, size_t len) {
void RtspSplitter::onRecvContent(const char *data, size_t len) {
_parser.setContent(string(data,len));
onWholeRtspPacket(_parser);
_parser.Clear();
_parser.clear();
}
void RtspSplitter::enableRecvRtp(bool enable) {