修复rtmp多层级url解析异常问题 (#2435)

解析多层级rtmp url会丢失某些层级信息:  #2433
This commit is contained in:
BackT0TheFuture 2023-05-05 17:34:32 +08:00 committed by GitHub
parent ffed4b3bb2
commit e97e0d86bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 23 deletions

View File

@ -81,27 +81,23 @@ void RtmpSession::onCmd_connect(AMFDecoder &dec) {
///////////set peerBandwidth//////////////// ///////////set peerBandwidth////////////////
sendPeerBandwidth(5000000); sendPeerBandwidth(5000000);
_media_info._app = params["app"].as_string(); auto tc_url = params["tcUrl"].as_string();
_tc_url = params["tcUrl"].as_string(); if (tc_url.empty()) {
if(_tc_url.empty()){ // defaultVhost:默认vhost
//defaultVhost:默认vhost tc_url = string(RTMP_SCHEMA) + "://" + DEFAULT_VHOST + "/" + _media_info._app;
_tc_url = string(RTMP_SCHEMA) + "://" + DEFAULT_VHOST + "/" + _media_info._app;
} else { } else {
auto pos = _tc_url.rfind('?'); auto pos = tc_url.rfind('?');
if (pos != string::npos) { if (pos != string::npos) {
//tc_url 中可能包含?以及参数参见issue: #692 // tc_url 中可能包含?以及参数参见issue: #692
_tc_url = _tc_url.substr(0, pos); tc_url = tc_url.substr(0, pos);
}
auto stream_start = _tc_url.rfind('/');
if (stream_start != string::npos && stream_start > 1) {
auto protocol_end = _tc_url.find("://") + 2;
auto app_start = _tc_url.rfind('/', stream_start - 1);
if (app_start != protocol_end) {
// contain stream name part
_tc_url = _tc_url.substr(0, stream_start);
}
} }
} }
// 初步解析只用于获取vhost信息
_media_info.parse(tc_url);
_media_info._schema = RTMP_SCHEMA;
// 赋值rtmp app
_media_info._app = params["app"].as_string();
bool ok = true; //(app == APP_NAME); bool ok = true; //(app == APP_NAME);
AMFValue version(AMF_OBJECT); AMFValue version(AMF_OBJECT);
version.set("fmsVer", "FMS/3,0,1,123"); version.set("fmsVer", "FMS/3,0,1,123");
@ -135,8 +131,10 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
} }
})); }));
dec.load<AMFValue>();/* NULL */ dec.load<AMFValue>();/* NULL */
_media_info.parse(_tc_url + "/" + getStreamId(dec.load<std::string>())); // 赋值为rtmp stream id 信息
_media_info._schema = RTMP_SCHEMA; _media_info._streamid = getStreamId(dec.load<std::string>());
// 再解析url切割url为app/stream_id (不一定符合rtmp url切割规范)
_media_info.parse(_media_info._schema + "://" + _media_info._vhost + '/' + _media_info._app + '/' + _media_info._streamid);
auto now_stream_index = _now_stream_index; auto now_stream_index = _now_stream_index;
auto on_res = [this, token, now_stream_index](const string &err, const ProtocolOption &option) { auto on_res = [this, token, now_stream_index](const string &err, const ProtocolOption &option) {
@ -433,9 +431,11 @@ string RtmpSession::getStreamId(const string &str){
} }
void RtmpSession::onCmd_play(AMFDecoder &dec) { void RtmpSession::onCmd_play(AMFDecoder &dec) {
dec.load<AMFValue>();/* NULL */ dec.load<AMFValue>(); /* NULL */
_media_info.parse(_tc_url + "/" + getStreamId(dec.load<std::string>())); // 赋值为rtmp stream id 信息
_media_info._schema = RTMP_SCHEMA; _media_info._streamid = getStreamId(dec.load<std::string>());
// 再解析url切割url为app/stream_id (不一定符合rtmp url切割规范)
_media_info.parse(_media_info._schema + "://" + _media_info._vhost + '/' + _media_info._app + '/' + _media_info._streamid);
doPlay(dec); doPlay(dec);
} }

View File

@ -92,7 +92,6 @@ private:
uint32_t _continue_push_ms = 0; uint32_t _continue_push_ms = 0;
//消耗的总流量 //消耗的总流量
uint64_t _total_bytes = 0; uint64_t _total_bytes = 0;
std::string _tc_url;
//数据接收超时计时器 //数据接收超时计时器
toolkit::Ticker _ticker; toolkit::Ticker _ticker;
MediaInfo _media_info; MediaInfo _media_info;