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
b6946a59
Commit
b6946a59
authored
Apr 23, 2020
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
事件广播触发者改成SockInfo对象
parent
4d84661a
显示空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
153 行增加
和
119 行删除
+153
-119
3rdpart/ZLToolKit
+1
-1
api/include/mk_events.h
+9
-9
api/include/mk_tcp.h
+32
-8
api/source/mk_tcp.cpp
+37
-23
api/source/mk_tcp_private.h
+3
-3
api/tests/server.c
+45
-45
server/WebApi.cpp
+1
-1
src/Common/MediaSource.cpp
+1
-1
src/Common/config.h
+9
-9
src/Http/HttpFileManager.cpp
+3
-3
src/Http/HttpSession.cpp
+3
-2
src/Rtmp/RtmpSession.cpp
+3
-5
src/Rtsp/RtspSession.cpp
+5
-8
src/Shell/ShellSession.cpp
+1
-1
没有找到文件。
ZLToolKit
@
07d21ac6
Subproject commit
fac78b63701ce6febd9ac6acefb637886c651873
Subproject commit
07d21ac61be6c7a4eba90a5d2d26b15daa882cf7
api/include/mk_events.h
查看文件 @
b6946a59
...
...
@@ -36,7 +36,7 @@ typedef struct {
*/
void
(
API_CALL
*
on_mk_media_publish
)(
const
mk_media_info
url_info
,
const
mk_publish_auth_invoker
invoker
,
const
mk_
tcp_session
sender
);
const
mk_
sock_info
sender
);
/**
* 播放rtsp/rtmp/http-flv/hls事件广播,通过该事件控制播放鉴权
...
...
@@ -47,7 +47,7 @@ typedef struct {
*/
void
(
API_CALL
*
on_mk_media_play
)(
const
mk_media_info
url_info
,
const
mk_auth_invoker
invoker
,
const
mk_
tcp_session
sender
);
const
mk_
sock_info
sender
);
/**
* 未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了
...
...
@@ -55,7 +55,7 @@ typedef struct {
* @param sender 播放客户端相关信息
*/
void
(
API_CALL
*
on_mk_media_not_found
)(
const
mk_media_info
url_info
,
const
mk_
tcp_session
sender
);
const
mk_
sock_info
sender
);
/**
* 某个流无人消费时触发,目的为了实现无人观看时主动断开拉流等业务逻辑
...
...
@@ -73,7 +73,7 @@ typedef struct {
void
(
API_CALL
*
on_mk_http_request
)(
const
mk_parser
parser
,
const
mk_http_response_invoker
invoker
,
int
*
consumed
,
const
mk_
tcp_session
sender
);
const
mk_
sock_info
sender
);
/**
* 在http文件服务器中,收到http访问文件或目录的广播,通过该事件控制访问http目录的权限
...
...
@@ -87,7 +87,7 @@ typedef struct {
const
char
*
path
,
int
is_dir
,
const
mk_http_access_path_invoker
invoker
,
mk_tcp_session
sender
);
const
mk_sock_info
sender
);
/**
* 在http文件服务器中,收到http访问文件或目录前的广播,通过该事件可以控制http url到文件路径的映射
...
...
@@ -98,7 +98,7 @@ typedef struct {
*/
void
(
API_CALL
*
on_mk_http_before_access
)(
const
mk_parser
parser
,
char
*
path
,
const
mk_
tcp_session
sender
);
const
mk_
sock_info
sender
);
/**
* 该rtsp流是否需要认证?是的话调用invoker并传入realm,否则传入空的realm
...
...
@@ -108,7 +108,7 @@ typedef struct {
*/
void
(
API_CALL
*
on_mk_rtsp_get_realm
)(
const
mk_media_info
url_info
,
const
mk_rtsp_get_realm_invoker
invoker
,
const
mk_
tcp_session
sender
);
const
mk_
sock_info
sender
);
/**
* 请求认证用户密码事件,user_name为用户名,must_no_encrypt如果为true,则必须提供明文密码(因为此时是base64认证方式),否则会导致认证失败
...
...
@@ -125,7 +125,7 @@ typedef struct {
const
char
*
user_name
,
int
must_no_encrypt
,
const
mk_rtsp_auth_invoker
invoker
,
const
mk_
tcp_session
sender
);
const
mk_
sock_info
sender
);
/**
* 录制mp4分片文件成功后广播
...
...
@@ -138,7 +138,7 @@ typedef struct {
void
(
API_CALL
*
on_mk_shell_login
)(
const
char
*
user_name
,
const
char
*
passwd
,
const
mk_auth_invoker
invoker
,
const
mk_
tcp_session
sender
);
const
mk_
sock_info
sender
);
/**
* 停止rtsp/rtmp/http-flv会话后流量汇报事件广播
...
...
api/include/mk_tcp.h
查看文件 @
b6946a59
...
...
@@ -17,19 +17,41 @@
extern
"C"
{
#endif
///////////////////////////////////////////SockInfo/////////////////////////////////////////////
//SockInfo对象的C映射
typedef
void
*
mk_sock_info
;
//SockInfo::get_peer_ip()
API_EXPORT
const
char
*
API_CALL
mk_sock_info_peer_ip
(
const
mk_sock_info
ctx
);
//SockInfo::get_local_ip()
API_EXPORT
const
char
*
API_CALL
mk_sock_info_local_ip
(
const
mk_sock_info
ctx
);
//SockInfo::get_peer_port()
API_EXPORT
uint16_t
API_CALL
mk_sock_info_peer_port
(
const
mk_sock_info
ctx
);
//SockInfo::get_local_port()
API_EXPORT
uint16_t
API_CALL
mk_sock_info_local_port
(
const
mk_sock_info
ctx
);
#ifndef SOCK_INFO_API_RENAME
#define SOCK_INFO_API_RENAME
//mk_tcp_session对象转换成mk_sock_info对象后再获取网络相关信息
#define mk_tcp_session_peer_ip(x) mk_sock_info_peer_ip(mk_tcp_session_get_sock_info(x))
#define mk_tcp_session_local_ip(x) mk_sock_info_local_ip(mk_tcp_session_get_sock_info(x))
#define mk_tcp_session_peer_port(x) mk_sock_info_peer_port(mk_tcp_session_get_sock_info(x))
#define mk_tcp_session_local_port(x) mk_sock_info_local_port(mk_tcp_session_get_sock_info(x))
//mk_tcp_client对象转换成mk_sock_info对象后再获取网络相关信息
#define mk_tcp_client_peer_ip(x) mk_sock_info_peer_ip(mk_tcp_client_get_sock_info(x))
#define mk_tcp_client_local_ip(x) mk_sock_info_local_ip(mk_tcp_client_get_sock_info(x))
#define mk_tcp_client_peer_port(x) mk_sock_info_peer_port(mk_tcp_client_get_sock_info(x))
#define mk_tcp_client_local_port(x) mk_sock_info_local_port(mk_tcp_client_get_sock_info(x))
#endif
///////////////////////////////////////////TcpSession/////////////////////////////////////////////
//TcpSession对象的C映射
typedef
void
*
mk_tcp_session
;
//获取基类指针以便获取其网络相关信息
API_EXPORT
mk_sock_info
API_CALL
mk_tcp_session_get_sock_info
(
const
mk_tcp_session
ctx
);
//TcpSession::safeShutdown()
API_EXPORT
void
API_CALL
mk_tcp_session_shutdown
(
const
mk_tcp_session
ctx
,
int
err
,
const
char
*
err_msg
);
//TcpSession::get_peer_ip()
API_EXPORT
const
char
*
API_CALL
mk_tcp_session_peer_ip
(
const
mk_tcp_session
ctx
);
//TcpSession::get_local_ip()
API_EXPORT
const
char
*
API_CALL
mk_tcp_session_local_ip
(
const
mk_tcp_session
ctx
);
//TcpSession::get_peer_port()
API_EXPORT
uint16_t
API_CALL
mk_tcp_session_peer_port
(
const
mk_tcp_session
ctx
);
//TcpSession::get_local_port()
API_EXPORT
uint16_t
API_CALL
mk_tcp_session_local_port
(
const
mk_tcp_session
ctx
);
//TcpSession::send()
API_EXPORT
void
API_CALL
mk_tcp_session_send
(
const
mk_tcp_session
ctx
,
const
char
*
data
,
int
len
);
//切换到该对象所在线程后再TcpSession::send()
...
...
@@ -115,6 +137,8 @@ API_EXPORT void API_CALL mk_tcp_server_events_listen(const mk_tcp_session_events
///////////////////////////////////////////自定义tcp客户端/////////////////////////////////////////////
typedef
void
*
mk_tcp_client
;
//获取基类指针以便获取其网络相关信息
API_EXPORT
mk_sock_info
API_CALL
mk_tcp_client_get_sock_info
(
const
mk_tcp_client
ctx
);
typedef
struct
{
/**
...
...
api/source/mk_tcp.cpp
查看文件 @
b6946a59
...
...
@@ -14,38 +14,46 @@
#include "Http/WebSocketSession.h"
using
namespace
mediakit
;
////////////////////////////////////////////////////////////////////////////////////////
API_EXPORT
void
API_CALL
mk_tcp_session_shutdown
(
const
mk_tcp_session
ctx
,
int
err
,
const
char
*
err_msg
){
API_EXPORT
const
char
*
API_CALL
mk_sock_info_peer_ip
(
const
mk_sock_info
ctx
){
assert
(
ctx
);
TcpSession
*
session
=
(
TcpSession
*
)
ctx
;
session
->
safeShutdown
(
SockException
((
ErrCode
)
err
,
err_msg
));
SockInfo
*
sock
=
(
SockInfo
*
)
ctx
;
return
sock
->
get_peer_ip
().
c_str
();
}
API_EXPORT
const
char
*
API_CALL
mk_sock_info_local_ip
(
const
mk_sock_info
ctx
){
assert
(
ctx
);
SockInfo
*
sock
=
(
SockInfo
*
)
ctx
;
return
sock
->
get_local_ip
().
c_str
();
}
API_EXPORT
const
char
*
API_CALL
mk_tcp_session_peer_ip
(
const
mk_tcp_session
ctx
){
API_EXPORT
uint16_t
API_CALL
mk_sock_info_peer_port
(
const
mk_sock_info
ctx
){
assert
(
ctx
);
TcpSession
*
session
=
(
TcpSession
*
)
ctx
;
return
s
ession
->
get_peer_ip
().
c_str
();
SockInfo
*
sock
=
(
SockInfo
*
)
ctx
;
return
s
ock
->
get_peer_port
();
}
API_EXPORT
const
char
*
API_CALL
mk_tcp_session_local_ip
(
const
mk_tcp_session
ctx
){
API_EXPORT
uint16_t
API_CALL
mk_sock_info_local_port
(
const
mk_sock_info
ctx
){
assert
(
ctx
);
TcpSession
*
session
=
(
TcpSession
*
)
ctx
;
return
s
ession
->
get_local_ip
().
c_str
();
SockInfo
*
sock
=
(
SockInfo
*
)
ctx
;
return
s
ock
->
get_local_port
();
}
API_EXPORT
uint16_t
API_CALL
mk_tcp_session_peer_port
(
const
mk_tcp_session
ctx
){
////////////////////////////////////////////////////////////////////////////////////////
API_EXPORT
mk_sock_info
API_CALL
mk_tcp_session_get_sock_info
(
const
mk_tcp_session
ctx
){
assert
(
ctx
);
TcpSession
*
session
=
(
TcpSession
*
)
ctx
;
return
session
->
get_peer_port
()
;
TcpSession
ForC
*
session
=
(
TcpSessionForC
*
)
ctx
;
return
(
SockInfo
*
)
session
;
}
API_EXPORT
uint16_t
API_CALL
mk_tcp_session_local_port
(
const
mk_tcp_session
ctx
){
API_EXPORT
void
API_CALL
mk_tcp_session_shutdown
(
const
mk_tcp_session
ctx
,
int
err
,
const
char
*
err_msg
){
assert
(
ctx
);
TcpSession
*
session
=
(
TcpSession
*
)
ctx
;
return
session
->
get_local_port
(
);
TcpSession
ForC
*
session
=
(
TcpSessionForC
*
)
ctx
;
session
->
safeShutdown
(
SockException
((
ErrCode
)
err
,
err_msg
)
);
}
API_EXPORT
void
API_CALL
mk_tcp_session_send
(
const
mk_tcp_session
ctx
,
const
char
*
data
,
int
len
){
assert
(
ctx
&&
data
);
if
(
!
len
){
len
=
strlen
(
data
);
}
TcpSession
*
session
=
(
TcpSession
*
)
ctx
;
TcpSession
ForC
*
session
=
(
TcpSessionForC
*
)
ctx
;
session
->
SockSender
::
send
(
data
,
len
);
}
...
...
@@ -55,9 +63,9 @@ API_EXPORT void API_CALL mk_tcp_session_send_safe(const mk_tcp_session ctx,const
len
=
strlen
(
data
);
}
try
{
weak_ptr
<
TcpSession
>
weak_session
=
((
TcpSession
*
)
ctx
)
->
shared_from_this
();
weak_ptr
<
TcpSession
>
weak_session
=
((
TcpSession
ForC
*
)
ctx
)
->
shared_from_this
();
string
str
=
string
(
data
,
len
);
((
TcpSession
*
)
ctx
)
->
async
([
weak_session
,
str
](){
((
TcpSession
ForC
*
)
ctx
)
->
async
([
weak_session
,
str
](){
auto
session_session
=
weak_session
.
lock
();
if
(
session_session
){
session_session
->
SockSender
::
send
(
str
);
...
...
@@ -205,6 +213,12 @@ TcpClientForC::Ptr *mk_tcp_client_create_l(mk_tcp_client_events *events, mk_tcp_
}
}
API_EXPORT
mk_sock_info
API_CALL
mk_tcp_client_get_sock_info
(
const
mk_tcp_client
ctx
){
assert
(
ctx
);
TcpClientForC
::
Ptr
*
client
=
(
TcpClientForC
::
Ptr
*
)
ctx
;
return
(
SockInfo
*
)
client
->
get
();
}
API_EXPORT
mk_tcp_client
API_CALL
mk_tcp_client_create
(
mk_tcp_client_events
*
events
,
mk_tcp_type
type
){
auto
ret
=
mk_tcp_client_create_l
(
events
,
type
);
(
*
ret
)
->
setClient
(
ret
);
...
...
@@ -213,25 +227,25 @@ API_EXPORT mk_tcp_client API_CALL mk_tcp_client_create(mk_tcp_client_events *eve
API_EXPORT
void
API_CALL
mk_tcp_client_release
(
mk_tcp_client
ctx
){
assert
(
ctx
);
TcpClient
::
Ptr
*
client
=
(
TcpClient
::
Ptr
*
)
ctx
;
TcpClient
ForC
::
Ptr
*
client
=
(
TcpClientForC
::
Ptr
*
)
ctx
;
delete
client
;
}
API_EXPORT
void
API_CALL
mk_tcp_client_connect
(
mk_tcp_client
ctx
,
const
char
*
host
,
uint16_t
port
,
float
time_out_sec
){
assert
(
ctx
);
TcpClient
::
Ptr
*
client
=
(
TcpClient
::
Ptr
*
)
ctx
;
TcpClient
ForC
::
Ptr
*
client
=
(
TcpClientForC
::
Ptr
*
)
ctx
;
(
*
client
)
->
startConnect
(
host
,
port
);
}
API_EXPORT
void
API_CALL
mk_tcp_client_send
(
mk_tcp_client
ctx
,
const
char
*
data
,
int
len
){
assert
(
ctx
&&
data
);
TcpClient
::
Ptr
*
client
=
(
TcpClient
::
Ptr
*
)
ctx
;
TcpClient
ForC
::
Ptr
*
client
=
(
TcpClientForC
::
Ptr
*
)
ctx
;
(
*
client
)
->
SockSender
::
send
(
data
,
len
);
}
API_EXPORT
void
API_CALL
mk_tcp_client_send_safe
(
mk_tcp_client
ctx
,
const
char
*
data
,
int
len
){
assert
(
ctx
&&
data
);
TcpClient
::
Ptr
*
client
=
(
TcpClient
::
Ptr
*
)
ctx
;
TcpClient
ForC
::
Ptr
*
client
=
(
TcpClientForC
::
Ptr
*
)
ctx
;
weak_ptr
<
TcpClient
>
weakClient
=
*
client
;
Buffer
::
Ptr
buf
=
(
*
client
)
->
obtainBuffer
(
data
,
len
);
(
*
client
)
->
async
([
weakClient
,
buf
](){
...
...
api/source/mk_tcp_private.h
查看文件 @
b6946a59
...
...
@@ -17,7 +17,7 @@
using
namespace
toolkit
;
class
TcpClientForC
:
public
TcpClient
{
public
:
public
:
typedef
std
::
shared_ptr
<
TcpClientForC
>
Ptr
;
TcpClientForC
(
mk_tcp_client_events
*
events
)
;
~
TcpClientForC
()
override
;
...
...
@@ -27,13 +27,13 @@ class TcpClientForC : public TcpClient {
void
onConnect
(
const
SockException
&
ex
)
override
;
void
setClient
(
mk_tcp_client
client
);
void
*
_user_data
;
private
:
private
:
mk_tcp_client_events
_events
;
mk_tcp_client
_client
;
};
class
TcpSessionForC
:
public
TcpSession
{
public
:
public
:
TcpSessionForC
(
const
Socket
::
Ptr
&
pSock
)
;
~
TcpSessionForC
()
override
=
default
;
void
onRecv
(
const
Buffer
::
Ptr
&
buffer
)
override
;
...
...
api/tests/server.c
查看文件 @
b6946a59
...
...
@@ -46,14 +46,14 @@ void API_CALL on_mk_media_changed(int regist,
*/
void
API_CALL
on_mk_media_publish
(
const
mk_media_info
url_info
,
const
mk_publish_auth_invoker
invoker
,
const
mk_
tcp_session
sender
)
{
const
mk_
sock_info
sender
)
{
log_printf
(
LOG_LEV
,
"client info, local: %s:%d, peer: %s:%d
\n
"
"%s/%s/%s/%s, url params: %s"
,
mk_
tcp_session
_local_ip
(
sender
),
mk_
tcp_session
_local_port
(
sender
),
mk_
tcp_session
_peer_ip
(
sender
),
mk_
tcp_session
_peer_port
(
sender
),
mk_
sock_info
_local_ip
(
sender
),
mk_
sock_info
_local_port
(
sender
),
mk_
sock_info
_peer_ip
(
sender
),
mk_
sock_info
_peer_port
(
sender
),
mk_media_info_get_schema
(
url_info
),
mk_media_info_get_vhost
(
url_info
),
mk_media_info_get_app
(
url_info
),
...
...
@@ -73,15 +73,15 @@ void API_CALL on_mk_media_publish(const mk_media_info url_info,
*/
void
API_CALL
on_mk_media_play
(
const
mk_media_info
url_info
,
const
mk_auth_invoker
invoker
,
const
mk_
tcp_session
sender
)
{
const
mk_
sock_info
sender
)
{
log_printf
(
LOG_LEV
,
"client info, local: %s:%d, peer: %s:%d
\n
"
"%s/%s/%s/%s, url params: %s"
,
mk_
tcp_session
_local_ip
(
sender
),
mk_
tcp_session
_local_port
(
sender
),
mk_
tcp_session
_peer_ip
(
sender
),
mk_
tcp_session
_peer_port
(
sender
),
mk_
sock_info
_local_ip
(
sender
),
mk_
sock_info
_local_port
(
sender
),
mk_
sock_info
_peer_ip
(
sender
),
mk_
sock_info
_peer_port
(
sender
),
mk_media_info_get_schema
(
url_info
),
mk_media_info_get_vhost
(
url_info
),
mk_media_info_get_app
(
url_info
),
...
...
@@ -98,14 +98,14 @@ void API_CALL on_mk_media_play(const mk_media_info url_info,
* @param sender 播放客户端相关信息
*/
void
API_CALL
on_mk_media_not_found
(
const
mk_media_info
url_info
,
const
mk_
tcp_session
sender
)
{
const
mk_
sock_info
sender
)
{
log_printf
(
LOG_LEV
,
"client info, local: %s:%d, peer: %s:%d
\n
"
"%s/%s/%s/%s, url params: %s"
,
mk_
tcp_session
_local_ip
(
sender
),
mk_
tcp_session
_local_port
(
sender
),
mk_
tcp_session
_peer_ip
(
sender
),
mk_
tcp_session
_peer_port
(
sender
),
mk_
sock_info
_local_ip
(
sender
),
mk_
sock_info
_local_port
(
sender
),
mk_
sock_info
_peer_ip
(
sender
),
mk_
sock_info
_peer_port
(
sender
),
mk_media_info_get_schema
(
url_info
),
mk_media_info_get_vhost
(
url_info
),
mk_media_info_get_app
(
url_info
),
...
...
@@ -137,17 +137,17 @@ void API_CALL on_mk_media_no_reader(const mk_media_source sender) {
void
API_CALL
on_mk_http_request
(
const
mk_parser
parser
,
const
mk_http_response_invoker
invoker
,
int
*
consumed
,
const
mk_
tcp_session
sender
)
{
const
mk_
sock_info
sender
)
{
log_printf
(
LOG_LEV
,
"client info, local: %s:%d, peer: %s:%d
\n
"
"%s %s?%s %s
\n
"
"User-Agent: %s
\n
"
"%s"
,
mk_
tcp_session
_local_ip
(
sender
),
mk_
tcp_session
_local_port
(
sender
),
mk_
tcp_session
_peer_ip
(
sender
),
mk_
tcp_session
_peer_port
(
sender
),
mk_
sock_info
_local_ip
(
sender
),
mk_
sock_info
_local_port
(
sender
),
mk_
sock_info
_peer_ip
(
sender
),
mk_
sock_info
_peer_port
(
sender
),
mk_parser_get_method
(
parser
),
mk_parser_get_url
(
parser
),
mk_parser_get_url_params
(
parser
),
...
...
@@ -191,17 +191,17 @@ void API_CALL on_mk_http_access(const mk_parser parser,
const
char
*
path
,
int
is_dir
,
const
mk_http_access_path_invoker
invoker
,
mk_tcp_session
sender
)
{
const
mk_sock_info
sender
)
{
log_printf
(
LOG_LEV
,
"client info, local: %s:%d, peer: %s:%d, path: %s ,is_dir: %d
\n
"
"%s %s?%s %s
\n
"
"User-Agent: %s
\n
"
"%s"
,
mk_
tcp_session
_local_ip
(
sender
),
mk_
tcp_session
_local_port
(
sender
),
mk_
tcp_session
_peer_ip
(
sender
),
mk_
tcp_session
_peer_port
(
sender
),
mk_
sock_info
_local_ip
(
sender
),
mk_
sock_info
_local_port
(
sender
),
mk_
sock_info
_peer_ip
(
sender
),
mk_
sock_info
_peer_port
(
sender
),
path
,(
int
)
is_dir
,
mk_parser_get_method
(
parser
),
mk_parser_get_url
(
parser
),
...
...
@@ -223,16 +223,16 @@ void API_CALL on_mk_http_access(const mk_parser parser,
*/
void
API_CALL
on_mk_http_before_access
(
const
mk_parser
parser
,
char
*
path
,
const
mk_
tcp_session
sender
)
{
const
mk_
sock_info
sender
)
{
log_printf
(
LOG_LEV
,
"client info, local: %s:%d, peer: %s:%d, path: %s
\n
"
"%s %s?%s %s
\n
"
"User-Agent: %s
\n
"
"%s"
,
mk_
tcp_session
_local_ip
(
sender
),
mk_
tcp_session
_local_port
(
sender
),
mk_
tcp_session
_peer_ip
(
sender
),
mk_
tcp_session
_peer_port
(
sender
),
mk_
sock_info
_local_ip
(
sender
),
mk_
sock_info
_local_port
(
sender
),
mk_
sock_info
_peer_ip
(
sender
),
mk_
sock_info
_peer_port
(
sender
),
path
,
mk_parser_get_method
(
parser
),
mk_parser_get_url
(
parser
),
...
...
@@ -251,14 +251,14 @@ void API_CALL on_mk_http_before_access(const mk_parser parser,
*/
void
API_CALL
on_mk_rtsp_get_realm
(
const
mk_media_info
url_info
,
const
mk_rtsp_get_realm_invoker
invoker
,
const
mk_
tcp_session
sender
)
{
const
mk_
sock_info
sender
)
{
log_printf
(
LOG_LEV
,
"client info, local: %s:%d, peer: %s:%d
\n
"
"%s/%s/%s/%s, url params: %s"
,
mk_
tcp_session
_local_ip
(
sender
),
mk_
tcp_session
_local_port
(
sender
),
mk_
tcp_session
_peer_ip
(
sender
),
mk_
tcp_session
_peer_port
(
sender
),
mk_
sock_info
_local_ip
(
sender
),
mk_
sock_info
_local_port
(
sender
),
mk_
sock_info
_peer_ip
(
sender
),
mk_
sock_info
_peer_port
(
sender
),
mk_media_info_get_schema
(
url_info
),
mk_media_info_get_vhost
(
url_info
),
mk_media_info_get_app
(
url_info
),
...
...
@@ -284,16 +284,16 @@ void API_CALL on_mk_rtsp_auth(const mk_media_info url_info,
const
char
*
user_name
,
int
must_no_encrypt
,
const
mk_rtsp_auth_invoker
invoker
,
const
mk_
tcp_session
sender
)
{
const
mk_
sock_info
sender
)
{
log_printf
(
LOG_LEV
,
"client info, local: %s:%d, peer: %s:%d
\n
"
"%s/%s/%s/%s, url params: %s
\n
"
"realm: %s, user_name: %s, must_no_encrypt: %d"
,
mk_
tcp_session
_local_ip
(
sender
),
mk_
tcp_session
_local_port
(
sender
),
mk_
tcp_session
_peer_ip
(
sender
),
mk_
tcp_session
_peer_port
(
sender
),
mk_
sock_info
_local_ip
(
sender
),
mk_
sock_info
_local_port
(
sender
),
mk_
sock_info
_peer_ip
(
sender
),
mk_
sock_info
_peer_port
(
sender
),
mk_media_info_get_schema
(
url_info
),
mk_media_info_get_vhost
(
url_info
),
mk_media_info_get_app
(
url_info
),
...
...
@@ -338,13 +338,13 @@ void API_CALL on_mk_record_mp4(const mk_mp4_info mp4) {
void
API_CALL
on_mk_shell_login
(
const
char
*
user_name
,
const
char
*
passwd
,
const
mk_auth_invoker
invoker
,
const
mk_
tcp_session
sender
)
{
const
mk_
sock_info
sender
)
{
log_printf
(
LOG_LEV
,
"client info, local: %s:%d, peer: %s:%d
\n
"
"user_name: %s, passwd: %s"
,
mk_
tcp_session
_local_ip
(
sender
),
mk_
tcp_session
_local_port
(
sender
),
mk_
tcp_session
_peer_ip
(
sender
),
mk_
tcp_session
_peer_port
(
sender
),
mk_
sock_info
_local_ip
(
sender
),
mk_
sock_info
_local_port
(
sender
),
mk_
sock_info
_peer_ip
(
sender
),
mk_
sock_info
_peer_port
(
sender
),
user_name
,
passwd
);
//允许登录shell
mk_auth_invoker_do
(
invoker
,
NULL
);
...
...
server/WebApi.cpp
查看文件 @
b6946a59
...
...
@@ -86,7 +86,7 @@ public:
~
SuccessException
()
=
default
;
};
#define API_ARGS1
TcpSession
&sender,HttpSession::KeyValue &headerIn, HttpSession::KeyValue &headerOut, ApiArgsType &allArgs, Json::Value &val
#define API_ARGS1
SockInfo
&sender,HttpSession::KeyValue &headerIn, HttpSession::KeyValue &headerOut, ApiArgsType &allArgs, Json::Value &val
#define API_ARGS2 API_ARGS1, const HttpSession::HttpResponseInvoker &invoker
#define API_ARGS_VALUE1 sender,headerIn,headerOut,allArgs,val
#define API_ARGS_VALUE2 API_ARGS_VALUE1, invoker
...
...
src/Common/MediaSource.cpp
查看文件 @
b6946a59
...
...
@@ -190,7 +190,7 @@ void findAsync_l(const MediaInfo &info, const std::shared_ptr<TcpSession> &sessi
void
*
listener_tag
=
session
.
get
();
weak_ptr
<
TcpSession
>
weakSession
=
session
;
//广播未找到流,此时可以立即去拉流,这样还来得及
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastNotFoundStream
,
info
,
*
session
);
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastNotFoundStream
,
info
,
static_cast
<
SockInfo
&>
(
*
session
)
);
//最多等待一定时间,如果这个时间内,流未注册上,那么返回未找到流
GET_CONFIG
(
int
,
maxWaitMS
,
General
::
kMaxStreamWaitTimeMS
);
...
...
src/Common/config.h
查看文件 @
b6946a59
...
...
@@ -62,25 +62,25 @@ extern const string kBroadcastRecordMP4;
//收到http api请求广播
extern
const
string
kBroadcastHttpRequest
;
#define BroadcastHttpRequestArgs const Parser &parser,const HttpSession::HttpResponseInvoker &invoker,bool &consumed,
TcpSession
&sender
#define BroadcastHttpRequestArgs const Parser &parser,const HttpSession::HttpResponseInvoker &invoker,bool &consumed,
SockInfo
&sender
//在http文件服务器中,收到http访问文件或目录的广播,通过该事件控制访问http目录的权限
extern
const
string
kBroadcastHttpAccess
;
#define BroadcastHttpAccessArgs const Parser &parser,const string &path,const bool &is_dir,const HttpSession::HttpAccessPathInvoker &invoker,
TcpSession
&sender
#define BroadcastHttpAccessArgs const Parser &parser,const string &path,const bool &is_dir,const HttpSession::HttpAccessPathInvoker &invoker,
SockInfo
&sender
//在http文件服务器中,收到http访问文件或目录前的广播,通过该事件可以控制http url到文件路径的映射
//在该事件中通过自行覆盖path参数,可以做到譬如根据虚拟主机或者app选择不同http根目录的目的
extern
const
string
kBroadcastHttpBeforeAccess
;
#define BroadcastHttpBeforeAccessArgs const Parser &parser,string &path,
TcpSession
&sender
#define BroadcastHttpBeforeAccessArgs const Parser &parser,string &path,
SockInfo
&sender
//该流是否需要认证?是的话调用invoker并传入realm,否则传入空的realm.如果该事件不监听则不认证
extern
const
string
kBroadcastOnGetRtspRealm
;
#define BroadcastOnGetRtspRealmArgs const MediaInfo &args,const RtspSession::onGetRealm &invoker,
TcpSession
&sender
#define BroadcastOnGetRtspRealmArgs const MediaInfo &args,const RtspSession::onGetRealm &invoker,
SockInfo
&sender
//请求认证用户密码事件,user_name为用户名,must_no_encrypt如果为true,则必须提供明文密码(因为此时是base64认证方式),否则会导致认证失败
//获取到密码后请调用invoker并输入对应类型的密码和密码类型,invoker执行时会匹配密码
extern
const
string
kBroadcastOnRtspAuth
;
#define BroadcastOnRtspAuthArgs const MediaInfo &args,const string &realm,const string &user_name,const bool &must_no_encrypt,const RtspSession::onAuth &invoker,
TcpSession
&sender
#define BroadcastOnRtspAuthArgs const MediaInfo &args,const string &realm,const string &user_name,const bool &must_no_encrypt,const RtspSession::onAuth &invoker,
SockInfo
&sender
//推流鉴权结果回调对象
//如果errMessage为空则代表鉴权成功
...
...
@@ -91,7 +91,7 @@ typedef std::function<void(const string &errMessage,bool enableRtxp,bool enableH
//收到rtsp/rtmp推流事件广播,通过该事件控制推流鉴权
extern
const
string
kBroadcastMediaPublish
;
#define BroadcastMediaPublishArgs const MediaInfo &args,const Broadcast::PublishAuthInvoker &invoker,
TcpSession
&sender
#define BroadcastMediaPublishArgs const MediaInfo &args,const Broadcast::PublishAuthInvoker &invoker,
SockInfo
&sender
//播放鉴权结果回调对象
//如果errMessage为空则代表鉴权成功
...
...
@@ -99,11 +99,11 @@ typedef std::function<void(const string &errMessage)> AuthInvoker;
//播放rtsp/rtmp/http-flv事件广播,通过该事件控制播放鉴权
extern
const
string
kBroadcastMediaPlayed
;
#define BroadcastMediaPlayedArgs const MediaInfo &args,const Broadcast::AuthInvoker &invoker,
TcpSession
&sender
#define BroadcastMediaPlayedArgs const MediaInfo &args,const Broadcast::AuthInvoker &invoker,
SockInfo
&sender
//shell登录鉴权
extern
const
string
kBroadcastShellLogin
;
#define BroadcastShellLoginArgs const string &user_name,const string &passwd,const Broadcast::AuthInvoker &invoker,
TcpSession
&sender
#define BroadcastShellLoginArgs const string &user_name,const string &passwd,const Broadcast::AuthInvoker &invoker,
SockInfo
&sender
//停止rtsp/rtmp/http-flv会话后流量汇报事件广播
extern
const
string
kBroadcastFlowReport
;
...
...
@@ -111,7 +111,7 @@ extern const string kBroadcastFlowReport;
//未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了
extern
const
string
kBroadcastNotFoundStream
;
#define BroadcastNotFoundStreamArgs const MediaInfo &args,
TcpSession
&sender
#define BroadcastNotFoundStreamArgs const MediaInfo &args,
SockInfo
&sender
//某个流无人消费时触发,目的为了实现无人观看时主动断开拉流等业务逻辑
extern
const
string
kBroadcastStreamNoneReader
;
...
...
src/Http/HttpFileManager.cpp
查看文件 @
b6946a59
...
...
@@ -306,7 +306,7 @@ static bool emitHlsPlayed(const Parser &parser, const MediaInfo &mediaInfo, cons
//cookie有效期为kHlsCookieSecond
invoker
(
err
,
""
,
kHlsCookieSecond
);
};
return
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
mediaInfo
,
mediaAuthInvoker
,
s
ender
);
return
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
mediaInfo
,
mediaAuthInvoker
,
s
tatic_cast
<
SockInfo
&>
(
sender
)
);
}
...
...
@@ -407,7 +407,7 @@ static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaI
}
//事件未被拦截,则认为是http下载请求
bool
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastHttpAccess
,
parser
,
path
,
is_dir
,
accessPathInvoker
,
s
ender
);
bool
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastHttpAccess
,
parser
,
path
,
is_dir
,
accessPathInvoker
,
s
tatic_cast
<
SockInfo
&>
(
sender
)
);
if
(
!
flag
)
{
//此事件无人监听,我们默认都有权限访问
callback
(
""
,
nullptr
);
...
...
@@ -521,7 +521,7 @@ static string getFilePath(const Parser &parser,const MediaInfo &mediaInfo, TcpSe
GET_CONFIG
(
bool
,
enableVhost
,
General
::
kEnableVhost
);
GET_CONFIG
(
string
,
rootPath
,
Http
::
kRootPath
);
auto
ret
=
File
::
absolutePath
(
enableVhost
?
mediaInfo
.
_vhost
+
parser
.
Url
()
:
parser
.
Url
(),
rootPath
);
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastHttpBeforeAccess
,
parser
,
ret
,
s
ender
);
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastHttpBeforeAccess
,
parser
,
ret
,
s
tatic_cast
<
SockInfo
&>
(
sender
)
);
return
std
::
move
(
ret
);
}
...
...
src/Http/HttpSession.cpp
查看文件 @
b6946a59
...
...
@@ -241,7 +241,7 @@ bool HttpSession::checkLiveFlvStream(const function<void()> &cb){
onRes
(
err
);
});
};
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
_mediaInfo
,
invoker
,
*
this
);
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
_mediaInfo
,
invoker
,
static_cast
<
SockInfo
&>
(
*
this
)
);
if
(
!
flag
){
//该事件无人监听,默认不鉴权
onRes
(
""
);
...
...
@@ -520,7 +520,8 @@ bool HttpSession::emitHttpEvent(bool doInvoke){
};
///////////////////广播HTTP事件///////////////////////////
bool
consumed
=
false
;
//该事件是否被消费
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastHttpRequest
,
_parser
,
invoker
,
consumed
,
*
this
);
TcpSession
&
session
=
static_cast
<
TcpSession
&>
(
*
this
);
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastHttpRequest
,
_parser
,
invoker
,
consumed
,
static_cast
<
SockInfo
&>
(
*
this
));
if
(
!
consumed
&&
doInvoke
){
//该事件无人消费,所以返回404
invoker
(
"404 Not Found"
,
KeyValue
(),
HttpBody
::
Ptr
());
...
...
src/Rtmp/RtmpSession.cpp
查看文件 @
b6946a59
...
...
@@ -171,10 +171,7 @@ void RtmpSession::onCmd_publish(AMFDecoder &dec) {
onRes
(
err
,
enableRtxp
,
enableHls
,
enableMP4
);
});
};
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPublish
,
_mediaInfo
,
invoker
,
*
this
);
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPublish
,
_mediaInfo
,
invoker
,
static_cast
<
SockInfo
&>
(
*
this
));
if
(
!
flag
){
//该事件无人监听,默认鉴权成功
GET_CONFIG
(
bool
,
toRtxp
,
General
::
kPublishToRtxp
);
...
...
@@ -346,7 +343,8 @@ void RtmpSession::doPlay(AMFDecoder &dec){
strongSelf
->
doPlayResponse
(
err
,[
pToken
](
bool
){});
});
};
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
_mediaInfo
,
invoker
,
*
this
);
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
_mediaInfo
,
invoker
,
static_cast
<
SockInfo
&>
(
*
this
));
if
(
!
flag
){
//该事件无人监听,默认不鉴权
doPlayResponse
(
""
,[
pToken
](
bool
){});
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
b6946a59
...
...
@@ -302,7 +302,7 @@ void RtspSession::handleReq_RECORD(const Parser &parser){
};
//rtsp推流需要鉴权
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPublish
,
_mediaInfo
,
invoker
,
*
this
);
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPublish
,
_mediaInfo
,
invoker
,
static_cast
<
SockInfo
&>
(
*
this
)
);
if
(
!
flag
){
//该事件无人监听,默认不鉴权
GET_CONFIG
(
bool
,
toRtxp
,
General
::
kPublishToRtxp
);
...
...
@@ -341,10 +341,7 @@ void RtspSession::handleReq_Describe(const Parser &parser) {
};
//广播是否需要认证事件
if
(
!
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastOnGetRtspRealm
,
_mediaInfo
,
invoker
,
*
this
)){
if
(
!
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastOnGetRtspRealm
,
_mediaInfo
,
invoker
,
static_cast
<
SockInfo
&>
(
*
this
))){
//无人监听此事件,说明无需认证
invoker
(
""
);
}
...
...
@@ -446,7 +443,7 @@ void RtspSession::onAuthBasic(const string &realm,const string &strBase64){
};
//此时必须提供明文密码
if
(
!
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastOnRtspAuth
,
_mediaInfo
,
realm
,
user
,
true
,
invoker
,
*
this
)){
if
(
!
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastOnRtspAuth
,
_mediaInfo
,
realm
,
user
,
true
,
invoker
,
static_cast
<
SockInfo
&>
(
*
this
)
)){
//表明该流需要认证却没监听请求密码事件,这一般是大意的程序所为,警告之
WarnP
(
this
)
<<
"请监听kBroadcastOnRtspAuth事件!"
;
//但是我们还是忽略认证以便完成播放
...
...
@@ -530,7 +527,7 @@ void RtspSession::onAuthDigest(const string &realm,const string &strMd5){
};
//此时可以提供明文或md5加密的密码
if
(
!
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastOnRtspAuth
,
_mediaInfo
,
realm
,
username
,
false
,
invoker
,
*
this
)){
if
(
!
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastOnRtspAuth
,
_mediaInfo
,
realm
,
username
,
false
,
invoker
,
static_cast
<
SockInfo
&>
(
*
this
)
)){
//表明该流需要认证却没监听请求密码事件,这一般是大意的程序所为,警告之
WarnP
(
this
)
<<
"请监听kBroadcastOnRtspAuth事件!"
;
//但是我们还是忽略认证以便完成播放
...
...
@@ -824,7 +821,7 @@ void RtspSession::handleReq_Play(const Parser &parser) {
};
if
(
_bFirstPlay
){
//第一次收到play命令,需要鉴权
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
_mediaInfo
,
invoker
,
*
this
);
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastMediaPlayed
,
_mediaInfo
,
invoker
,
static_cast
<
SockInfo
&>
(
*
this
)
);
if
(
!
flag
){
//该事件无人监听,默认不鉴权
onRes
(
""
);
...
...
src/Shell/ShellSession.cpp
查看文件 @
b6946a59
...
...
@@ -136,7 +136,7 @@ inline void ShellSession::pleaseInputPasswd() {
});
};
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastShellLogin
,
_strUserName
,
passwd
,
invoker
,
*
this
);
auto
flag
=
NoticeCenter
::
Instance
().
emitEvent
(
Broadcast
::
kBroadcastShellLogin
,
_strUserName
,
passwd
,
invoker
,
static_cast
<
SockInfo
&>
(
*
this
)
);
if
(
!
flag
){
//如果无人监听shell登录事件,那么默认shell无法登录
onAuth
(
"please listen kBroadcastShellLogin event"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论