mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-27 04:20:13 +08:00
完善范例程序
This commit is contained in:
parent
5ac1fb73a7
commit
a904a42125
@ -104,6 +104,7 @@ onceToken token1([](){
|
|||||||
static onceToken s_token([](){
|
static onceToken s_token([](){
|
||||||
//监听kBroadcastOnGetRtspRealm事件决定rtsp链接是否需要鉴权(传统的rtsp鉴权方案)才能访问
|
//监听kBroadcastOnGetRtspRealm事件决定rtsp链接是否需要鉴权(传统的rtsp鉴权方案)才能访问
|
||||||
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastOnGetRtspRealm,[](BroadcastOnGetRtspRealmArgs){
|
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastOnGetRtspRealm,[](BroadcastOnGetRtspRealmArgs){
|
||||||
|
DebugL << "RTSP是否需要鉴权事件:" << args._schema << " " << args._vhost << " " << args._app << " " << args._streamid << " " << args._param_strs ;
|
||||||
if(string("1") == args._streamid ){
|
if(string("1") == args._streamid ){
|
||||||
// live/1需要认证
|
// live/1需要认证
|
||||||
EventPoller::Instance().async([invoker](){
|
EventPoller::Instance().async([invoker](){
|
||||||
@ -122,7 +123,8 @@ static onceToken s_token([](){
|
|||||||
|
|
||||||
//监听kBroadcastOnRtspAuth事件返回正确的rtsp鉴权用户密码
|
//监听kBroadcastOnRtspAuth事件返回正确的rtsp鉴权用户密码
|
||||||
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastOnRtspAuth,[](BroadcastOnRtspAuthArgs){
|
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastOnRtspAuth,[](BroadcastOnRtspAuthArgs){
|
||||||
InfoL << "用户:" << user_name << (must_no_encrypt ? " Base64" : " MD5" )<< " 方式登录";
|
DebugL << "RTSP播放鉴权:" << args._schema << " " << args._vhost << " " << args._app << " " << args._streamid << " " << args._param_strs ;
|
||||||
|
DebugL << "RTSP用户:" << user_name << (must_no_encrypt ? " Base64" : " MD5" )<< " 方式登录";
|
||||||
string user = user_name;
|
string user = user_name;
|
||||||
//假设我们异步读取数据库
|
//假设我们异步读取数据库
|
||||||
EventPoller::Instance().async([must_no_encrypt,invoker,user](){
|
EventPoller::Instance().async([must_no_encrypt,invoker,user](){
|
||||||
@ -153,7 +155,7 @@ static onceToken s_token([](){
|
|||||||
|
|
||||||
//监听rtsp/rtmp推流事件,返回结果告知是否有推流权限
|
//监听rtsp/rtmp推流事件,返回结果告知是否有推流权限
|
||||||
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastMediaPublish,[](BroadcastMediaPublishArgs){
|
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastMediaPublish,[](BroadcastMediaPublishArgs){
|
||||||
InfoL << args._vhost << " " << args._app << " " << args._streamid << " " << args._param_strs ;
|
DebugL << "推流鉴权:" << args._schema << " " << args._vhost << " " << args._app << " " << args._streamid << " " << args._param_strs ;
|
||||||
EventPoller::Instance().async([invoker](){
|
EventPoller::Instance().async([invoker](){
|
||||||
invoker("");//鉴权成功
|
invoker("");//鉴权成功
|
||||||
//invoker("this is auth failed message");//鉴权失败
|
//invoker("this is auth failed message");//鉴权失败
|
||||||
@ -162,7 +164,7 @@ static onceToken s_token([](){
|
|||||||
|
|
||||||
//监听rtsp/rtsps/rtmp/http-flv播放事件,返回结果告知是否有播放权限(rtsp通过kBroadcastOnRtspAuth或此事件都可以实现鉴权)
|
//监听rtsp/rtsps/rtmp/http-flv播放事件,返回结果告知是否有播放权限(rtsp通过kBroadcastOnRtspAuth或此事件都可以实现鉴权)
|
||||||
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastMediaPlayed,[](BroadcastMediaPlayedArgs){
|
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastMediaPlayed,[](BroadcastMediaPlayedArgs){
|
||||||
InfoL << args._schema << " " << args._vhost << " " << args._app << " " << args._streamid << " " << args._param_strs ;
|
DebugL << "播放鉴权:" << args._schema << " " << args._vhost << " " << args._app << " " << args._streamid << " " << args._param_strs ;
|
||||||
EventPoller::Instance().async([invoker](){
|
EventPoller::Instance().async([invoker](){
|
||||||
invoker("");//鉴权成功
|
invoker("");//鉴权成功
|
||||||
//invoker("this is auth failed message");//鉴权失败
|
//invoker("this is auth failed message");//鉴权失败
|
||||||
@ -171,7 +173,7 @@ static onceToken s_token([](){
|
|||||||
|
|
||||||
//shell登录事件,通过shell可以登录进服务器执行一些命令
|
//shell登录事件,通过shell可以登录进服务器执行一些命令
|
||||||
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastShellLogin,[](BroadcastShellLoginArgs){
|
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastShellLogin,[](BroadcastShellLoginArgs){
|
||||||
InfoL << "shell login:" << user_name << " " << passwd;
|
DebugL << "shell login:" << user_name << " " << passwd;
|
||||||
EventPoller::Instance().async([invoker](){
|
EventPoller::Instance().async([invoker](){
|
||||||
invoker("");//鉴权成功
|
invoker("");//鉴权成功
|
||||||
//invoker("this is auth failed message");//鉴权失败
|
//invoker("this is auth failed message");//鉴权失败
|
||||||
@ -185,6 +187,7 @@ static onceToken s_token([](){
|
|||||||
static mutex s_mtxFlvRecorder;
|
static mutex s_mtxFlvRecorder;
|
||||||
lock_guard<mutex> lck(s_mtxFlvRecorder);
|
lock_guard<mutex> lck(s_mtxFlvRecorder);
|
||||||
if(bRegist){
|
if(bRegist){
|
||||||
|
DebugL << "开始录制RTMP:" << schema << " " << vhost << " " << app << " " << stream;
|
||||||
GET_CONFIG_AND_REGISTER(string,http_root,Http::kRootPath);
|
GET_CONFIG_AND_REGISTER(string,http_root,Http::kRootPath);
|
||||||
auto path = http_root + "/" + vhost + "/" + app + "/" + stream + "_" + to_string(time(NULL)) + ".flv";
|
auto path = http_root + "/" + vhost + "/" + app + "/" + stream + "_" + to_string(time(NULL)) + ".flv";
|
||||||
FlvRecorder::Ptr recorder(new FlvRecorder);
|
FlvRecorder::Ptr recorder(new FlvRecorder);
|
||||||
@ -206,13 +209,13 @@ static onceToken s_token([](){
|
|||||||
* 你可以在这个事件触发时再去拉流,这样就可以实现按需拉流
|
* 你可以在这个事件触发时再去拉流,这样就可以实现按需拉流
|
||||||
* 拉流成功后,ZLMediaKit会把其立即转发给播放器(最大等待时间约为5秒,如果5秒都未拉流成功,播放器会播放失败)
|
* 拉流成功后,ZLMediaKit会把其立即转发给播放器(最大等待时间约为5秒,如果5秒都未拉流成功,播放器会播放失败)
|
||||||
*/
|
*/
|
||||||
DebugL << "未找到流:" << args._vhost << " " << args._app << " " << args._streamid << " " << args._param_strs ;
|
DebugL << "未找到流事件:" << args._schema << " " << args._vhost << " " << args._app << " " << args._streamid << " " << args._param_strs ;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//监听播放或推流结束时消耗流量事件
|
//监听播放或推流结束时消耗流量事件
|
||||||
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastFlowReport,[](BroadcastFlowReportArgs){
|
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastFlowReport,[](BroadcastFlowReportArgs){
|
||||||
DebugL << "播放器(推流器)断开连接:" << args._vhost << " " << args._app << " " << args._streamid << " " << args._param_strs
|
DebugL << "播放器(推流器)断开连接事件:" << args._schema << " " << args._vhost << " " << args._app << " " << args._streamid << " " << args._param_strs
|
||||||
<< "\r\n使用流量:" << totalBytes << " bytes,连接时长:" << totalDuration << "秒" ;
|
<< "\r\n使用流量:" << totalBytes << " bytes,连接时长:" << totalDuration << "秒" ;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user