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
ef7e9378
Commit
ef7e9378
authored
Dec 18, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加pusher接口
整理代码
parent
ee4659a1
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
61 行增加
和
24 行删除
+61
-24
api/include/media.h
+2
-1
api/include/mediakit.h
+1
-0
api/include/player.h
+3
-3
api/include/proxyplayer.h
+11
-1
api/source/common.cpp
+3
-1
api/source/flvrecorder.cpp
+3
-2
api/source/httpdownloader.cpp
+2
-0
api/source/media.cpp
+11
-2
api/source/player.cpp
+4
-9
api/source/proxyplayer.cpp
+21
-5
没有找到文件。
api/include/media.h
查看文件 @
ef7e9378
...
...
@@ -37,6 +37,7 @@ typedef void *mk_media;
/**
* 创建一个媒体源
* @param vhost 虚拟主机名,一般为__defaultVhost__
* @param app 应用名,推荐为live
* @param stream 流id,例如camera
* @param duration 时长(单位秒),直播则为0
...
...
@@ -44,7 +45,7 @@ typedef void *mk_media;
* @param mp4_enabled 是否生成mp4
* @return 对象指针
*/
API_EXPORT
mk_media
API_CALL
mk_media_create
(
const
char
*
app
,
const
char
*
stream
,
float
duration
,
int
hls_enabled
,
int
mp4_enabled
);
API_EXPORT
mk_media
API_CALL
mk_media_create
(
const
char
*
vhost
,
const
char
*
app
,
const
char
*
stream
,
float
duration
,
int
hls_enabled
,
int
mp4_enabled
);
/**
* 销毁媒体源
...
...
api/include/mediakit.h
查看文件 @
ef7e9378
...
...
@@ -33,5 +33,6 @@
#include "proxyplayer.h"
#include "flvrecorder.h"
#include "player.h"
#include "pusher.h"
#endif
/* MK_API_H_ */
api/include/player.h
查看文件 @
ef7e9378
...
...
@@ -56,7 +56,7 @@ typedef void(API_CALL *on_mk_play_event)(void *user_data,int err_code,const char
typedef
void
(
API_CALL
*
on_mk_play_data
)(
void
*
user_data
,
int
track_type
,
int
codec_id
,
void
*
data
,
int
len
,
uint32_t
dts
,
uint32_t
pts
);
/**
* 创建一个播放器,支持rtmp
/rtsp
* 创建一个播放器,支持rtmp
[s]/rtsp[s]
* @return 播放器指针
*/
API_EXPORT
mk_player
API_CALL
mk_player_create
();
...
...
@@ -78,7 +78,7 @@ API_EXPORT void API_CALL mk_player_set_option(mk_player ctx, const char *key, co
/**
* 开始播放url
* @param ctx 播放器指针
* @param url rtsp
/rtmp
url
* @param url rtsp
[s]/rtmp[s]
url
*/
API_EXPORT
void
API_CALL
mk_player_play
(
mk_player
ctx
,
const
char
*
url
);
...
...
@@ -99,7 +99,7 @@ API_EXPORT void API_CALL mk_player_seekto(mk_player ctx, float progress);
/**
* 设置播放器开启播放结果回调函数
* @param ctx 播放器指针
* @param cb 回调函数指针
* @param cb 回调函数指针
,不得为null
* @param user_data 用户数据指针
*/
API_EXPORT
void
API_CALL
mk_player_set_on_result
(
mk_player
ctx
,
on_mk_play_event
cb
,
void
*
user_data
);
...
...
api/include/proxyplayer.h
查看文件 @
ef7e9378
...
...
@@ -37,6 +37,7 @@ typedef void *mk_proxy_player;
/**
* 创建一个代理播放器
* @param vhost 虚拟主机名,一般为__defaultVhost__
* @param app 应用名
* @param stream 流名
* @param rtp_type rtsp播放方式:RTP_TCP = 0, RTP_UDP = 1, RTP_MULTICAST = 2
...
...
@@ -44,7 +45,7 @@ typedef void *mk_proxy_player;
* @param mp4_enabled 是否生成mp4
* @return 对象指针
*/
API_EXPORT
mk_proxy_player
API_CALL
mk_proxy_player_create
(
const
char
*
app
,
const
char
*
stream
,
int
rtp_type
,
int
hls_enabled
,
int
mp4_enabled
);
API_EXPORT
mk_proxy_player
API_CALL
mk_proxy_player_create
(
const
char
*
vhost
,
const
char
*
app
,
const
char
*
stream
,
int
hls_enabled
,
int
mp4_enabled
);
/**
* 销毁代理播放器
...
...
@@ -52,6 +53,15 @@ API_EXPORT mk_proxy_player API_CALL mk_proxy_player_create(const char *app, cons
*/
API_EXPORT
void
API_CALL
mk_proxy_player_release
(
mk_proxy_player
ctx
);
/**
* 设置代理播放器配置选项
* @param ctx 代理播放器指针
* @param key 配置项键,支持 net_adapter/rtp_type/rtsp_user/rtsp_pwd/protocol_timeout_ms/media_timeout_ms/beat_interval_ms/max_analysis_ms
* @param val 配置项值,如果是整形,需要转换成统一转换成string
*/
API_EXPORT
void
API_CALL
mk_proxy_player_set_option
(
mk_proxy_player
ctx
,
const
char
*
key
,
const
char
*
val
);
/**
* 开始播放
* @param ctx 对象指针
...
...
api/source/common.cpp
查看文件 @
ef7e9378
...
...
@@ -45,7 +45,7 @@ static TcpServer::Ptr http_server[2];
//////////////////////////environment init///////////////////////////
API_EXPORT
void
API_CALL
mk_env_init
(
const
config
*
cfg
)
{
assert
(
cfg
!=
nullptr
);
assert
(
cfg
);
static
onceToken
token
([
&
]()
{
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
(
"console"
,
(
LogLevel
)
cfg
->
log_level
));
Logger
::
Instance
().
setWriter
(
std
::
make_shared
<
AsyncLogWriter
>
());
...
...
@@ -70,6 +70,7 @@ API_EXPORT void API_CALL mk_env_init(const config *cfg) {
}
API_EXPORT
void
API_CALL
mk_set_option
(
const
char
*
key
,
const
char
*
val
)
{
assert
(
key
&&
val
);
if
(
mINI
::
Instance
().
find
(
key
)
==
mINI
::
Instance
().
end
())
{
WarnL
<<
"key:"
<<
key
<<
" not existed!"
;
return
;
...
...
@@ -129,6 +130,7 @@ API_EXPORT uint16_t API_CALL mk_rtmp_server_start(uint16_t port, int ssl) {
}
API_EXPORT
void
API_CALL
mk_log_printf
(
int
level
,
const
char
*
file
,
const
char
*
function
,
int
line
,
const
char
*
fmt
,
...)
{
assert
(
file
&&
function
&&
fmt
);
LogContextCapturer
info
(
Logger
::
Instance
(),
(
LogLevel
)
level
,
file
,
function
,
line
);
va_list
pArg
;
va_start
(
pArg
,
fmt
);
...
...
api/source/flvrecorder.cpp
查看文件 @
ef7e9378
...
...
@@ -34,13 +34,14 @@ API_EXPORT mk_flv_recorder API_CALL mk_flv_recorder_create(){
return
ret
;
}
API_EXPORT
void
API_CALL
mk_flv_recorder_release
(
mk_flv_recorder
ctx
){
assert
(
ctx
);
FlvRecorder
::
Ptr
*
record
=
(
FlvRecorder
::
Ptr
*
)(
ctx
);
delete
record
;
}
API_EXPORT
int
API_CALL
mk_flv_recorder_start
(
mk_flv_recorder
ctx
,
const
char
*
app
,
const
char
*
stream
,
const
char
*
file_path
){
DebugL
<<
app
<<
" "
<<
stream
<<
" "
<<
file_path
;
FlvRecorder
::
Ptr
*
record
=
(
FlvRecorder
::
Ptr
*
)(
ctx
);
assert
(
ctx
&&
app
&&
stream
&&
file_path
);
try
{
FlvRecorder
::
Ptr
*
record
=
(
FlvRecorder
::
Ptr
*
)(
ctx
);
(
*
record
)
->
startRecord
(
EventPollerPool
::
Instance
().
getPoller
(),
DEFAULT_VHOST
,
app
,
stream
,
file_path
);
return
0
;
}
catch
(
std
::
exception
&
ex
){
...
...
api/source/httpdownloader.cpp
查看文件 @
ef7e9378
...
...
@@ -37,11 +37,13 @@ API_EXPORT mk_http_downloader API_CALL mk_http_downloader_create() {
}
API_EXPORT
void
API_CALL
mk_http_downloader_release
(
mk_http_downloader
ctx
)
{
assert
(
ctx
);
HttpDownloader
::
Ptr
*
obj
=
(
HttpDownloader
::
Ptr
*
)
ctx
;
delete
obj
;
}
API_EXPORT
void
API_CALL
mk_http_downloader_start
(
mk_http_downloader
ctx
,
const
char
*
url
,
const
char
*
file
,
on_mk_download_complete
cb
,
void
*
user_data
)
{
assert
(
ctx
&&
url
&&
file
);
HttpDownloader
::
Ptr
*
obj
=
(
HttpDownloader
::
Ptr
*
)
ctx
;
(
*
obj
)
->
setOnResult
([
cb
,
user_data
](
ErrCode
code
,
const
string
&
errMsg
,
const
string
&
filePath
)
{
if
(
cb
)
{
...
...
api/source/media.cpp
查看文件 @
ef7e9378
...
...
@@ -32,17 +32,20 @@ using namespace std;
using
namespace
toolkit
;
using
namespace
mediakit
;
API_EXPORT
mk_media
API_CALL
mk_media_create
(
const
char
*
app
,
const
char
*
stream
,
float
duration
,
int
hls_enabled
,
int
mp4_enabled
)
{
DevChannel
::
Ptr
*
obj
(
new
DevChannel
::
Ptr
(
new
DevChannel
(
DEFAULT_VHOST
,
app
,
stream
,
duration
,
true
,
true
,
hls_enabled
,
mp4_enabled
)));
API_EXPORT
mk_media
API_CALL
mk_media_create
(
const
char
*
vhost
,
const
char
*
app
,
const
char
*
stream
,
float
duration
,
int
hls_enabled
,
int
mp4_enabled
)
{
assert
(
vhost
&&
app
&&
stream
);
DevChannel
::
Ptr
*
obj
(
new
DevChannel
::
Ptr
(
new
DevChannel
(
vhost
,
app
,
stream
,
duration
,
true
,
true
,
hls_enabled
,
mp4_enabled
)));
return
(
mk_media
)
obj
;
}
API_EXPORT
void
API_CALL
mk_media_release
(
mk_media
ctx
)
{
assert
(
ctx
);
DevChannel
::
Ptr
*
obj
=
(
DevChannel
::
Ptr
*
)
ctx
;
delete
obj
;
}
API_EXPORT
void
API_CALL
mk_media_init_h264
(
mk_media
ctx
,
int
width
,
int
height
,
int
frameRate
)
{
assert
(
ctx
);
DevChannel
::
Ptr
*
obj
=
(
DevChannel
::
Ptr
*
)
ctx
;
VideoInfo
info
;
info
.
iFrameRate
=
frameRate
;
...
...
@@ -52,6 +55,7 @@ API_EXPORT void API_CALL mk_media_init_h264(mk_media ctx, int width, int height,
}
API_EXPORT
void
API_CALL
mk_media_init_h265
(
mk_media
ctx
,
int
width
,
int
height
,
int
frameRate
)
{
assert
(
ctx
);
DevChannel
::
Ptr
*
obj
=
(
DevChannel
::
Ptr
*
)
ctx
;
VideoInfo
info
;
info
.
iFrameRate
=
frameRate
;
...
...
@@ -61,6 +65,7 @@ API_EXPORT void API_CALL mk_media_init_h265(mk_media ctx, int width, int height,
}
API_EXPORT
void
API_CALL
mk_media_init_aac
(
mk_media
ctx
,
int
channel
,
int
sample_bit
,
int
sample_rate
,
int
profile
)
{
assert
(
ctx
);
DevChannel
::
Ptr
*
obj
=
(
DevChannel
::
Ptr
*
)
ctx
;
AudioInfo
info
;
info
.
iSampleRate
=
sample_rate
;
...
...
@@ -71,21 +76,25 @@ API_EXPORT void API_CALL mk_media_init_aac(mk_media ctx, int channel, int sample
}
API_EXPORT
void
API_CALL
mk_media_input_h264
(
mk_media
ctx
,
void
*
data
,
int
len
,
uint32_t
dts
,
uint32_t
pts
)
{
assert
(
ctx
&&
data
&&
len
>
0
);
DevChannel
::
Ptr
*
obj
=
(
DevChannel
::
Ptr
*
)
ctx
;
(
*
obj
)
->
inputH264
((
char
*
)
data
,
len
,
dts
,
pts
);
}
API_EXPORT
void
API_CALL
mk_media_input_h265
(
mk_media
ctx
,
void
*
data
,
int
len
,
uint32_t
dts
,
uint32_t
pts
)
{
assert
(
ctx
&&
data
&&
len
>
0
);
DevChannel
::
Ptr
*
obj
=
(
DevChannel
::
Ptr
*
)
ctx
;
(
*
obj
)
->
inputH265
((
char
*
)
data
,
len
,
dts
,
pts
);
}
API_EXPORT
void
API_CALL
mk_media_input_aac
(
mk_media
ctx
,
void
*
data
,
int
len
,
uint32_t
dts
,
int
with_adts_header
)
{
assert
(
ctx
&&
data
&&
len
>
0
);
DevChannel
::
Ptr
*
obj
=
(
DevChannel
::
Ptr
*
)
ctx
;
(
*
obj
)
->
inputAAC
((
char
*
)
data
,
len
,
dts
,
with_adts_header
);
}
API_EXPORT
void
API_CALL
mk_media_input_aac1
(
mk_media
ctx
,
void
*
data
,
int
len
,
uint32_t
dts
,
void
*
adts
)
{
assert
(
ctx
&&
data
&&
len
>
0
&&
adts
);
DevChannel
::
Ptr
*
obj
=
(
DevChannel
::
Ptr
*
)
ctx
;
(
*
obj
)
->
inputAAC
((
char
*
)
data
,
len
,
dts
,
(
char
*
)
adts
);
}
...
...
api/source/player.cpp
查看文件 @
ef7e9378
...
...
@@ -42,9 +42,7 @@ API_EXPORT void API_CALL mk_player_release(mk_player ctx) {
}
API_EXPORT
void
API_CALL
mk_player_set_option
(
mk_player
ctx
,
const
char
*
key
,
const
char
*
val
){
assert
(
ctx
);
assert
(
key
);
assert
(
val
);
assert
(
ctx
&&
key
&&
val
);
MediaPlayer
::
Ptr
&
player
=
*
((
MediaPlayer
::
Ptr
*
)
ctx
);
string
key_str
(
key
),
val_str
(
val
);
player
->
getPoller
()
->
async
([
key_str
,
val_str
,
player
](){
...
...
@@ -53,8 +51,7 @@ API_EXPORT void API_CALL mk_player_set_option(mk_player ctx,const char* key,cons
});
}
API_EXPORT
void
API_CALL
mk_player_play
(
mk_player
ctx
,
const
char
*
url
)
{
assert
(
ctx
);
assert
(
url
);
assert
(
ctx
&&
url
);
MediaPlayer
::
Ptr
&
player
=
*
((
MediaPlayer
::
Ptr
*
)
ctx
);
string
url_str
(
url
);
player
->
getPoller
()
->
async
([
url_str
,
player
](){
...
...
@@ -82,8 +79,7 @@ API_EXPORT void API_CALL mk_player_seekto(mk_player ctx, float progress) {
}
static
void
mk_player_set_on_event
(
mk_player
ctx
,
on_mk_play_event
cb
,
void
*
user_data
,
int
type
)
{
assert
(
ctx
);
assert
(
cb
);
assert
(
ctx
&&
cb
);
MediaPlayer
::
Ptr
&
player
=
*
((
MediaPlayer
::
Ptr
*
)
ctx
);
player
->
getPoller
()
->
async
([
cb
,
user_data
,
type
,
player
](){
//切换线程后再操作
...
...
@@ -108,8 +104,7 @@ API_EXPORT void API_CALL mk_player_set_on_shutdown(mk_player ctx, on_mk_play_eve
}
API_EXPORT
void
API_CALL
mk_player_set_on_data
(
mk_player
ctx
,
on_mk_play_data
cb
,
void
*
user_data
)
{
assert
(
ctx
);
assert
(
cb
);
assert
(
ctx
&&
cb
);
MediaPlayer
::
Ptr
&
player
=
*
((
MediaPlayer
::
Ptr
*
)
ctx
);
player
->
getPoller
()
->
async
([
player
,
cb
,
user_data
](){
//切换线程后再操作
...
...
api/source/proxyplayer.cpp
查看文件 @
ef7e9378
...
...
@@ -30,18 +30,34 @@
using
namespace
toolkit
;
using
namespace
mediakit
;
API_EXPORT
mk_proxy_player
API_CALL
mk_proxy_player_create
(
const
char
*
app
,
const
char
*
stream
,
int
rtp_type
,
int
hls_enabled
,
int
mp4_enabled
)
{
PlayerProxy
::
Ptr
*
obj
(
new
PlayerProxy
::
Ptr
(
new
PlayerProxy
(
DEFAULT_VHOST
,
app
,
stream
,
true
,
true
,
hls_enabled
,
mp4_enabled
))
);
(
**
obj
)[
Client
::
kRtpType
]
=
rtp_type
;
API_EXPORT
mk_proxy_player
API_CALL
mk_proxy_player_create
(
const
char
*
vhost
,
const
char
*
app
,
const
char
*
stream
,
int
hls_enabled
,
int
mp4_enabled
)
{
assert
(
vhost
&&
app
&&
stream
);
PlayerProxy
::
Ptr
*
obj
(
new
PlayerProxy
::
Ptr
(
new
PlayerProxy
(
vhost
,
app
,
stream
,
true
,
true
,
hls_enabled
,
mp4_enabled
)))
;
return
(
mk_proxy_player
)
obj
;
}
API_EXPORT
void
API_CALL
mk_proxy_player_release
(
mk_proxy_player
ctx
)
{
assert
(
ctx
);
PlayerProxy
::
Ptr
*
obj
=
(
PlayerProxy
::
Ptr
*
)
ctx
;
delete
obj
;
}
API_EXPORT
void
API_CALL
mk_proxy_player_set_option
(
mk_proxy_player
ctx
,
const
char
*
key
,
const
char
*
val
){
assert
(
ctx
&&
key
&&
val
);
PlayerProxy
::
Ptr
&
obj
=
*
((
PlayerProxy
::
Ptr
*
)
ctx
);
string
key_str
(
key
),
val_str
(
val
);
obj
->
getPoller
()
->
async
([
obj
,
key_str
,
val_str
](){
//切换线程再操作
(
*
obj
)[
key_str
]
=
val_str
;
});
}
API_EXPORT
void
API_CALL
mk_proxy_player_play
(
mk_proxy_player
ctx
,
const
char
*
url
)
{
PlayerProxy
::
Ptr
*
obj
=
(
PlayerProxy
::
Ptr
*
)
ctx
;
(
*
obj
)
->
play
(
url
);
assert
(
ctx
&&
url
);
PlayerProxy
::
Ptr
&
obj
=
*
((
PlayerProxy
::
Ptr
*
)
ctx
);
string
url_str
(
url
);
obj
->
getPoller
()
->
async
([
obj
,
url_str
](){
//切换线程再操作
obj
->
play
(
url_str
);
});
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论