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
38894097
Commit
38894097
authored
Apr 09, 2021
by
xia-chu
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://gitee.com/xia-chu/ZLMediaKit
into dev
parents
b2afae0e
67e1b1f1
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
68 行增加
和
64 行删除
+68
-64
server/WebApi.cpp
+58
-59
server/WebApi.h
+1
-1
server/WebHook.cpp
+9
-4
没有找到文件。
server/WebApi.cpp
查看文件 @
38894097
...
...
@@ -278,6 +278,61 @@ static inline string getProxyKey(const string &vhost,const string &app,const str
return
vhost
+
"/"
+
app
+
"/"
+
stream
;
}
Value
makeMediaSourceJson
(
MediaSource
&
media
){
Value
item
;
item
[
"schema"
]
=
media
.
getSchema
();
item
[
"vhost"
]
=
media
.
getVhost
();
item
[
"app"
]
=
media
.
getApp
();
item
[
"stream"
]
=
media
.
getId
();
item
[
"createStamp"
]
=
(
Json
::
UInt64
)
media
.
getCreateStamp
();
item
[
"aliveSecond"
]
=
(
Json
::
UInt64
)
media
.
getAliveSecond
();
item
[
"bytesSpeed"
]
=
media
.
getBytesSpeed
();
item
[
"readerCount"
]
=
media
.
readerCount
();
item
[
"totalReaderCount"
]
=
media
.
totalReaderCount
();
item
[
"originType"
]
=
(
int
)
media
.
getOriginType
();
item
[
"originTypeStr"
]
=
getOriginTypeString
(
media
.
getOriginType
());
item
[
"originUrl"
]
=
media
.
getOriginUrl
();
auto
originSock
=
media
.
getOriginSock
();
if
(
originSock
)
{
item
[
"originSock"
][
"local_ip"
]
=
originSock
->
get_local_ip
();
item
[
"originSock"
][
"local_port"
]
=
originSock
->
get_local_port
();
item
[
"originSock"
][
"peer_ip"
]
=
originSock
->
get_peer_ip
();
item
[
"originSock"
][
"peer_port"
]
=
originSock
->
get_peer_port
();
item
[
"originSock"
][
"identifier"
]
=
originSock
->
getIdentifier
();
}
else
{
item
[
"originSock"
]
=
Json
::
nullValue
;
}
for
(
auto
&
track
:
media
.
getTracks
()){
Value
obj
;
auto
codec_type
=
track
->
getTrackType
();
obj
[
"codec_id"
]
=
track
->
getCodecId
();
obj
[
"codec_id_name"
]
=
track
->
getCodecName
();
obj
[
"ready"
]
=
track
->
ready
();
obj
[
"codec_type"
]
=
codec_type
;
switch
(
codec_type
){
case
TrackAudio
:
{
auto
audio_track
=
dynamic_pointer_cast
<
AudioTrack
>
(
track
);
obj
[
"sample_rate"
]
=
audio_track
->
getAudioSampleRate
();
obj
[
"channels"
]
=
audio_track
->
getAudioChannel
();
obj
[
"sample_bit"
]
=
audio_track
->
getAudioSampleBit
();
break
;
}
case
TrackVideo
:
{
auto
video_track
=
dynamic_pointer_cast
<
VideoTrack
>
(
track
);
obj
[
"width"
]
=
video_track
->
getVideoWidth
();
obj
[
"height"
]
=
video_track
->
getVideoHeight
();
obj
[
"fps"
]
=
round
(
video_track
->
getVideoFps
());
break
;
}
default
:
break
;
}
item
[
"tracks"
].
append
(
obj
);
}
return
item
;
}
/**
* 安装api接口
* 所有api都支持GET和POST两种方式
...
...
@@ -401,62 +456,6 @@ void installWebApi() {
});
#endif//#if !defined(_WIN32)
static
auto
makeMediaSourceJson
=
[](
const
MediaSource
::
Ptr
&
media
){
Value
item
;
item
[
"schema"
]
=
media
->
getSchema
();
item
[
"vhost"
]
=
media
->
getVhost
();
item
[
"app"
]
=
media
->
getApp
();
item
[
"stream"
]
=
media
->
getId
();
item
[
"createStamp"
]
=
(
Json
::
UInt64
)
media
->
getCreateStamp
();
item
[
"aliveSecond"
]
=
(
Json
::
UInt64
)
media
->
getAliveSecond
();
item
[
"bytesSpeed"
]
=
media
->
getBytesSpeed
();
item
[
"readerCount"
]
=
media
->
readerCount
();
item
[
"totalReaderCount"
]
=
media
->
totalReaderCount
();
item
[
"originType"
]
=
(
int
)
media
->
getOriginType
();
item
[
"originTypeStr"
]
=
getOriginTypeString
(
media
->
getOriginType
());
item
[
"originUrl"
]
=
media
->
getOriginUrl
();
auto
originSock
=
media
->
getOriginSock
();
if
(
originSock
)
{
item
[
"originSock"
][
"local_ip"
]
=
originSock
->
get_local_ip
();
item
[
"originSock"
][
"local_port"
]
=
originSock
->
get_local_port
();
item
[
"originSock"
][
"peer_ip"
]
=
originSock
->
get_peer_ip
();
item
[
"originSock"
][
"peer_port"
]
=
originSock
->
get_peer_port
();
item
[
"originSock"
][
"identifier"
]
=
originSock
->
getIdentifier
();
}
else
{
item
[
"originSock"
]
=
Json
::
nullValue
;
}
for
(
auto
&
track
:
media
->
getTracks
()){
Value
obj
;
auto
codec_type
=
track
->
getTrackType
();
obj
[
"codec_id"
]
=
track
->
getCodecId
();
obj
[
"codec_id_name"
]
=
track
->
getCodecName
();
obj
[
"ready"
]
=
track
->
ready
();
obj
[
"codec_type"
]
=
codec_type
;
switch
(
codec_type
){
case
TrackAudio
:
{
auto
audio_track
=
dynamic_pointer_cast
<
AudioTrack
>
(
track
);
obj
[
"sample_rate"
]
=
audio_track
->
getAudioSampleRate
();
obj
[
"channels"
]
=
audio_track
->
getAudioChannel
();
obj
[
"sample_bit"
]
=
audio_track
->
getAudioSampleBit
();
break
;
}
case
TrackVideo
:
{
auto
video_track
=
dynamic_pointer_cast
<
VideoTrack
>
(
track
);
obj
[
"width"
]
=
video_track
->
getVideoWidth
();
obj
[
"height"
]
=
video_track
->
getVideoHeight
();
obj
[
"fps"
]
=
round
(
video_track
->
getVideoFps
());
break
;
}
default
:
break
;
}
item
[
"tracks"
].
append
(
obj
);
}
return
item
;
};
//获取流列表,可选筛选参数
//测试url0(获取所有流) http://127.0.0.1/index/api/getMediaList
//测试url1(获取虚拟主机为"__defaultVost__"的流) http://127.0.0.1/index/api/getMediaList?vhost=__defaultVost__
...
...
@@ -477,7 +476,7 @@ void installWebApi() {
if
(
!
allArgs
[
"stream"
].
empty
()
&&
allArgs
[
"stream"
]
!=
media
->
getId
())
{
return
;
}
val
[
"data"
].
append
(
makeMediaSourceJson
(
media
));
val
[
"data"
].
append
(
makeMediaSourceJson
(
*
media
));
});
});
...
...
@@ -497,7 +496,7 @@ void installWebApi() {
val
[
"online"
]
=
false
;
return
;
}
val
=
makeMediaSourceJson
(
src
);
val
=
makeMediaSourceJson
(
*
src
);
val
[
"online"
]
=
true
;
val
[
"code"
]
=
API
::
Success
;
});
...
...
@@ -1198,7 +1197,7 @@ void installWebApi() {
val
[
"passwd"
]
=
allArgs
[
"user_name"
].
data
();
});
api_regist
(
"/index/hook/on_stream_changed"
,[](
API_ARGS_
MAP
){
api_regist
(
"/index/hook/on_stream_changed"
,[](
API_ARGS_
JSON
){
//媒体注册或反注册事件
});
...
...
server/WebApi.h
查看文件 @
38894097
...
...
@@ -141,5 +141,5 @@ bool checkArgs(const Parser &args, First &&first, KeyTypes &&...keys) {
void
installWebApi
();
void
unInstallWebApi
();
Value
makeMediaSourceJson
(
MediaSource
&
media
);
#endif //ZLMEDIAKIT_WEBAPI_H
server/WebHook.cpp
查看文件 @
38894097
...
...
@@ -19,6 +19,7 @@
#include "Rtsp/RtspSession.h"
#include "Http/HttpSession.h"
#include "WebHook.h"
#include "WebApi.h"
using
namespace
toolkit
;
using
namespace
mediakit
;
...
...
@@ -301,10 +302,14 @@ void installWebHook(){
}
ArgsType
body
;
body
[
"regist"
]
=
bRegist
;
body
[
"schema"
]
=
sender
.
getSchema
();
body
[
"vhost"
]
=
sender
.
getVhost
();
body
[
"app"
]
=
sender
.
getApp
();
body
[
"stream"
]
=
sender
.
getId
();
if
(
bRegist
)
{
body
=
makeMediaSourceJson
(
sender
);
}
else
{
body
[
"schema"
]
=
sender
.
getSchema
();
body
[
"vhost"
]
=
sender
.
getVhost
();
body
[
"app"
]
=
sender
.
getApp
();
body
[
"stream"
]
=
sender
.
getId
();
}
//执行hook
do_http_hook
(
hook_stream_chaned
,
body
,
nullptr
);
});
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论