Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
06784d86
Commit
06784d86
authored
5 years ago
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善websocket-flv直播错误响应
parent
1cff9468
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
21 行增加
和
12 行删除
+21
-12
src/Http/HttpSession.cpp
+20
-11
src/Http/HttpSession.h
+1
-1
没有找到文件。
src/Http/HttpSession.cpp
查看文件 @
06784d86
...
@@ -211,13 +211,25 @@ inline bool HttpSession::checkWebSocket(){
...
@@ -211,13 +211,25 @@ inline bool HttpSession::checkWebSocket(){
if
(
!
_parser
[
"Sec-WebSocket-Protocol"
].
empty
()){
if
(
!
_parser
[
"Sec-WebSocket-Protocol"
].
empty
()){
headerOut
[
"Sec-WebSocket-Protocol"
]
=
_parser
[
"Sec-WebSocket-Protocol"
];
headerOut
[
"Sec-WebSocket-Protocol"
]
=
_parser
[
"Sec-WebSocket-Protocol"
];
}
}
auto
res_cb
=
[
this
,
headerOut
](){
_flv_over_websocket
=
true
;
sendResponse
(
"101 Switching Protocols"
,
headerOut
,
""
);
};
//判断是否为websocket-flv
if
(
checkLiveFlvStream
(
res_cb
)){
//这里是websocket-flv直播请求
return
true
;
}
//如果checkLiveFlvStream返回false,则代表不是websocket-flv,而是普通的websocket连接
sendResponse
(
"101 Switching Protocols"
,
headerOut
,
""
);
sendResponse
(
"101 Switching Protocols"
,
headerOut
,
""
);
checkLiveFlvStream
(
true
);
return
true
;
return
true
;
}
}
//http-flv 链接格式:http://vhost-url:port/app/streamid.flv?key1=value1&key2=value2
//http-flv 链接格式:http://vhost-url:port/app/streamid.flv?key1=value1&key2=value2
//如果url(除去?以及后面的参数)后缀是.flv,那么表明该url是一个http-flv直播。
//如果url(除去?以及后面的参数)后缀是.flv,那么表明该url是一个http-flv直播。
inline
bool
HttpSession
::
checkLiveFlvStream
(
bool
over_websocket
){
inline
bool
HttpSession
::
checkLiveFlvStream
(
const
function
<
void
()
>
&
cb
){
auto
pos
=
strrchr
(
_parser
.
Url
().
data
(),
'.'
);
auto
pos
=
strrchr
(
_parser
.
Url
().
data
(),
'.'
);
if
(
!
pos
){
if
(
!
pos
){
//未找到".flv"后缀
//未找到".flv"后缀
...
@@ -240,7 +252,7 @@ inline bool HttpSession::checkLiveFlvStream(bool over_websocket){
...
@@ -240,7 +252,7 @@ inline bool HttpSession::checkLiveFlvStream(bool over_websocket){
bool
bClose
=
(
strcasecmp
(
_parser
[
"Connection"
].
data
(),
"close"
)
==
0
)
||
(
++
_iReqCnt
>
reqCnt
);
bool
bClose
=
(
strcasecmp
(
_parser
[
"Connection"
].
data
(),
"close"
)
==
0
)
||
(
++
_iReqCnt
>
reqCnt
);
weak_ptr
<
HttpSession
>
weakSelf
=
dynamic_pointer_cast
<
HttpSession
>
(
shared_from_this
());
weak_ptr
<
HttpSession
>
weakSelf
=
dynamic_pointer_cast
<
HttpSession
>
(
shared_from_this
());
MediaSource
::
findAsync
(
_mediaInfo
,
weakSelf
.
lock
(),
true
,[
weakSelf
,
bClose
,
this
,
over_websocket
](
const
MediaSource
::
Ptr
&
src
){
MediaSource
::
findAsync
(
_mediaInfo
,
weakSelf
.
lock
(),
true
,[
weakSelf
,
bClose
,
this
,
cb
](
const
MediaSource
::
Ptr
&
src
){
auto
strongSelf
=
weakSelf
.
lock
();
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
if
(
!
strongSelf
){
//本对象已经销毁
//本对象已经销毁
...
@@ -249,35 +261,32 @@ inline bool HttpSession::checkLiveFlvStream(bool over_websocket){
...
@@ -249,35 +261,32 @@ inline bool HttpSession::checkLiveFlvStream(bool over_websocket){
auto
rtmp_src
=
dynamic_pointer_cast
<
RtmpMediaSource
>
(
src
);
auto
rtmp_src
=
dynamic_pointer_cast
<
RtmpMediaSource
>
(
src
);
if
(
!
rtmp_src
){
if
(
!
rtmp_src
){
//未找到该流
//未找到该流
if
(
!
over_websocket
){
sendNotFound
(
bClose
);
sendNotFound
(
bClose
);
}
if
(
bClose
){
if
(
bClose
){
shutdown
(
SockException
(
Err_shutdown
,
"flv stream not found"
));
shutdown
(
SockException
(
Err_shutdown
,
"flv stream not found"
));
}
}
return
;
return
;
}
}
//找到流了
//找到流了
auto
onRes
=
[
this
,
rtmp_src
,
over_websocket
](
const
string
&
err
){
auto
onRes
=
[
this
,
rtmp_src
,
cb
](
const
string
&
err
){
bool
authSuccess
=
err
.
empty
();
bool
authSuccess
=
err
.
empty
();
if
(
!
authSuccess
){
if
(
!
authSuccess
){
if
(
!
over_websocket
){
sendResponse
(
"401 Unauthorized"
,
makeHttpHeader
(
true
,
err
.
size
()),
err
);
sendResponse
(
"401 Unauthorized"
,
makeHttpHeader
(
true
,
err
.
size
()),
err
);
}
shutdown
(
SockException
(
Err_shutdown
,
StrPrinter
<<
"401 Unauthorized:"
<<
err
));
shutdown
(
SockException
(
Err_shutdown
,
StrPrinter
<<
"401 Unauthorized:"
<<
err
));
return
;
return
;
}
}
if
(
!
over_websocket
)
{
if
(
!
cb
)
{
//找到rtmp源,发送http头,负载后续发送
//找到rtmp源,发送http头,负载后续发送
sendResponse
(
"200 OK"
,
makeHttpHeader
(
false
,
0
,
get_mime_type
(
".flv"
)),
""
);
sendResponse
(
"200 OK"
,
makeHttpHeader
(
false
,
0
,
get_mime_type
(
".flv"
)),
""
);
}
else
{
cb
();
}
}
//开始发送rtmp负载
//开始发送rtmp负载
//关闭tcp_nodelay ,优化性能
//关闭tcp_nodelay ,优化性能
SockUtil
::
setNoDelay
(
_sock
->
rawFD
(),
false
);
SockUtil
::
setNoDelay
(
_sock
->
rawFD
(),
false
);
(
*
this
)
<<
SocketFlags
(
kSockFlags
);
(
*
this
)
<<
SocketFlags
(
kSockFlags
);
_flv_over_websocket
=
over_websocket
;
try
{
try
{
start
(
getPoller
(),
rtmp_src
);
start
(
getPoller
(),
rtmp_src
);
}
catch
(
std
::
exception
&
ex
){
}
catch
(
std
::
exception
&
ex
){
...
@@ -480,7 +489,7 @@ inline void HttpSession::Handle_Req_GET(int64_t &content_len) {
...
@@ -480,7 +489,7 @@ inline void HttpSession::Handle_Req_GET(int64_t &content_len) {
}
}
//再看看是否为http-flv直播请求
//再看看是否为http-flv直播请求
if
(
checkLiveFlvStream
(
false
)){
if
(
checkLiveFlvStream
()){
return
;
return
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/Http/HttpSession.h
查看文件 @
06784d86
...
@@ -110,7 +110,7 @@ protected:
...
@@ -110,7 +110,7 @@ protected:
private
:
private
:
inline
void
Handle_Req_GET
(
int64_t
&
content_len
);
inline
void
Handle_Req_GET
(
int64_t
&
content_len
);
inline
void
Handle_Req_POST
(
int64_t
&
content_len
);
inline
void
Handle_Req_POST
(
int64_t
&
content_len
);
inline
bool
checkLiveFlvStream
(
bool
over_websocket
=
false
);
inline
bool
checkLiveFlvStream
(
const
function
<
void
()
>
&
cb
=
nullptr
);
inline
bool
checkWebSocket
();
inline
bool
checkWebSocket
();
inline
bool
emitHttpEvent
(
bool
doInvoke
);
inline
bool
emitHttpEvent
(
bool
doInvoke
);
inline
void
urlDecode
(
Parser
&
parser
);
inline
void
urlDecode
(
Parser
&
parser
);
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论