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
cc7844a9
Commit
cc7844a9
authored
Dec 28, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
适配ZLToolKit代码,简化程序退出流程代码
parent
315cd180
显示空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
43 行增加
和
93 行删除
+43
-93
ZLToolKit
+1
-1
src/Rtsp/UDPServer.cpp
+3
-7
src/Rtsp/UDPServer.h
+11
-5
src/RtspMuxer/H264RtpCodec.cpp
+1
-1
tests/test_benchmark.cpp
+5
-13
tests/test_httpApi.cpp
+4
-10
tests/test_httpClient.cpp
+4
-9
tests/test_player.cpp
+3
-7
tests/test_rtmpPusher.cpp
+3
-14
tests/test_rtmpPusherMp4.cpp
+3
-12
tests/test_server.cpp
+5
-14
没有找到文件。
ZLToolKit
@
98d824bd
Subproject commit
d3a1bd9d8a3162d0237954034d85f1313008cab2
Subproject commit
98d824bdc6604b4e761657922c913ea46bd90223
src/Rtsp/UDPServer.cpp
查看文件 @
cc7844a9
...
...
@@ -26,17 +26,13 @@
#include "UDPServer.h"
#include "Util/TimeTicker.h"
#include "Util/onceToken.h"
using
namespace
toolkit
;
namespace
mediakit
{
UDPServer
&
UDPServer
::
Instance
()
{
static
UDPServer
*
instance
(
new
UDPServer
());
return
*
instance
;
}
void
UDPServer
::
Destory
()
{
delete
&
UDPServer
::
Instance
();
}
INSTANCE_IMP
(
UDPServer
);
UDPServer
::
UDPServer
()
{
}
...
...
src/Rtsp/UDPServer.h
查看文件 @
cc7844a9
...
...
@@ -27,8 +27,9 @@
#ifndef RTSP_UDPSERVER_H_
#define RTSP_UDPSERVER_H_
#include <mutex>
#include <stdint.h>
#include <mutex>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include "Util/util.h"
...
...
@@ -40,18 +41,23 @@ using namespace toolkit;
namespace
mediakit
{
class
UDPServer
{
class
UDPServer
:
public
std
::
enable_shared_from_this
<
UDPServer
>
{
public
:
typedef
function
<
bool
(
int
,
const
Buffer
::
Ptr
&
,
struct
sockaddr
*
)
>
onRecvData
;
UDPServer
();
virtual
~
UDPServer
();
~
UDPServer
();
static
UDPServer
&
Instance
();
static
void
Destory
();
/**
* 废弃的接口,无实际操作
* @deprecated
*/
static
void
Destory
(){};
Socket
::
Ptr
getSock
(
const
char
*
strLocalIp
,
int
iTrackIndex
,
uint16_t
iLocalPort
=
0
);
void
listenPeer
(
const
char
*
strPeerIp
,
void
*
pSelf
,
const
onRecvData
&
cb
);
void
stopListenPeer
(
const
char
*
strPeerIp
,
void
*
pSelf
);
private
:
UDPServer
();
void
onRcvData
(
int
iTrackId
,
const
Buffer
::
Ptr
&
pBuf
,
struct
sockaddr
*
pPeerAddr
);
void
onErr
(
const
string
&
strKey
,
const
SockException
&
err
);
unordered_map
<
string
,
Socket
::
Ptr
>
_mapUpdSock
;
...
...
src/RtspMuxer/H264RtpCodec.cpp
查看文件 @
cc7844a9
...
...
@@ -142,7 +142,7 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
return
false
;
}
WarnL
<<
"不支持的rtp类型:"
<<
nal
.
type
<<
" "
<<
rtppack
->
sequence
;
WarnL
<<
"不支持的rtp类型:"
<<
(
int
)
nal
.
type
<<
" "
<<
rtppack
->
sequence
;
return
false
;
// 29 FU-B 单NAL单元B模式
// 24 STAP-A 单一时间的组合包
...
...
tests/test_benchmark.cpp
查看文件 @
cc7844a9
...
...
@@ -41,9 +41,10 @@ using namespace mediakit;
int
main
(
int
argc
,
char
*
argv
[])
{
//设置退出信号处理函数
signal
(
SIGINT
,
[](
int
)
{
EventPoller
::
Instance
().
shutdown
();
});
signal
(
SIGINT
,
[](
int
)
{
EventPollerPool
::
Instance
().
shutdown
();
});
//设置日志
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
(
"stdout"
,
LTrace
));
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
());
Logger
::
Instance
().
setWriter
(
std
::
make_shared
<
AsyncLogWriter
>
());
if
(
argc
!=
5
)
{
...
...
@@ -55,7 +56,6 @@ int main(int argc, char *argv[]) {
return
0
;
}
{
list
<
MediaPlayer
::
Ptr
>
playerList
;
auto
playerCnt
=
atoi
(
argv
[
1
]);
//启动的播放器个数
atomic_int
alivePlayerCnt
(
0
);
...
...
@@ -80,17 +80,9 @@ int main(int argc, char *argv[]) {
InfoL
<<
"存活播放器个数:"
<<
alivePlayerCnt
.
load
();
return
true
;
});
EventPoller
::
Instance
().
runLoop
();
AsyncTaskThread
::
Instance
().
CancelTask
(
0
);
}
static
onceToken
token
(
nullptr
,
[]()
{
WorkThreadPool
::
Instance
();
UDPServer
::
Destory
();
EventPoller
::
Destory
();
AsyncTaskThread
::
Destory
();
Logger
::
Destory
();
});
EventPollerPool
::
Instance
().
wait
();
AsyncTaskThread
::
Instance
().
CancelTask
(
0
);
return
0
;
}
tests/test_httpApi.cpp
查看文件 @
cc7844a9
...
...
@@ -102,10 +102,11 @@ static onceToken s_token([](){
int
main
(
int
argc
,
char
*
argv
[]){
//设置退出信号处理函数
signal
(
SIGINT
,
[](
int
){
EventPoller
::
Instance
().
shutdown
();});
signal
(
SIGINT
,
[](
int
){
EventPoller
Pool
::
Instance
().
shutdown
();});
//设置日志
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
(
"stdout"
,
LTrace
));
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
());
Logger
::
Instance
().
setWriter
(
std
::
make_shared
<
AsyncLogWriter
>
());
//加载配置文件,如果配置文件不存在就创建一个
loadIniConfig
();
...
...
@@ -132,14 +133,7 @@ int main(int argc,char *argv[]){
InfoL
<<
"你可以在浏览器输入:http://127.0.0.1/api/my_api?key0=val0&key1=参数1"
<<
endl
;
EventPoller
::
Instance
().
runLoop
();
static
onceToken
s_token
(
nullptr
,[]()
{
//TcpServer用到了WorkThreadPool
WorkThreadPool
::
Destory
();
EventPoller
::
Destory
();
Logger
::
Destory
();
});
EventPollerPool
::
Instance
().
wait
();
return
0
;
}
tests/test_httpClient.cpp
查看文件 @
cc7844a9
...
...
@@ -41,11 +41,11 @@ using namespace mediakit;
int
main
(
int
argc
,
char
*
argv
[])
{
//设置退出信号处理函数
signal
(
SIGINT
,
[](
int
)
{
EventPoller
::
Instance
().
shutdown
();
});
signal
(
SIGINT
,
[](
int
)
{
EventPoller
Pool
::
Instance
().
shutdown
();
});
//设置日志
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
(
"stdout"
,
LTrace
));
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
());
Logger
::
Instance
().
setWriter
(
std
::
make_shared
<
AsyncLogWriter
>
());
{
///////////////////////////////http downloader///////////////////////
//下载器map
map
<
string
,
HttpDownloader
::
Ptr
>
downloaderMap
;
...
...
@@ -183,12 +183,7 @@ int main(int argc, char *argv[]) {
});
//事件轮询
EventPoller
::
Instance
().
runLoop
();
}
//程序开始退出
EventPoller
::
Destory
();
AsyncTaskThread
::
Destory
();
Logger
::
Destory
();
EventPollerPool
::
Instance
().
wait
();
return
0
;
}
tests/test_player.cpp
查看文件 @
cc7844a9
...
...
@@ -43,7 +43,8 @@ int main(int argc, char *argv[]) {
//设置退出信号处理函数
signal
(
SIGINT
,
[](
int
)
{
SDLDisplayerHelper
::
Instance
().
shutdown
();
});
//设置日志
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
(
"stdout"
,
LTrace
));
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
());
Logger
::
Instance
().
setWriter
(
std
::
make_shared
<
AsyncLogWriter
>
());
if
(
argc
!=
3
)
{
ErrorL
<<
"
\r\n
测试方法:./test_player rtxp_url rtp_type
\r\n
"
...
...
@@ -54,7 +55,6 @@ int main(int argc, char *argv[]) {
}
{
MediaPlayer
::
Ptr
player
(
new
MediaPlayer
());
weak_ptr
<
MediaPlayer
>
weakPlayer
=
player
;
player
->
setOnPlayResult
([
weakPlayer
](
const
SockException
&
ex
)
{
...
...
@@ -93,12 +93,8 @@ int main(int argc, char *argv[]) {
});
(
*
player
)[
RtspPlayer
::
kRtpType
]
=
atoi
(
argv
[
2
]);
player
->
play
(
argv
[
1
]);
SDLDisplayerHelper
::
Instance
().
runLoop
();
}
UDPServer
::
Destory
();
EventPoller
::
Destory
();
AsyncTaskThread
::
Destory
();
Logger
::
Destory
();
return
0
;
}
tests/test_rtmpPusher.cpp
查看文件 @
cc7844a9
...
...
@@ -83,12 +83,11 @@ void rePushDelay(const string &app, const string &stream, const string &url) {
//这里才是真正执行main函数,你可以把函数名(domain)改成main,然后就可以输入自定义url了
int
domain
(
const
string
&
playUrl
,
const
string
&
pushUrl
)
{
//设置退出信号处理函数
signal
(
SIGINT
,
[](
int
)
{
EventPoller
::
Instance
().
shutdown
();
});
signal
(
SIGINT
,
[](
int
)
{
EventPoller
Pool
::
Instance
().
shutdown
();
});
//设置日志
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
(
"stdout"
,
LTrace
));
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
());
Logger
::
Instance
().
setWriter
(
std
::
make_shared
<
AsyncLogWriter
>
());
{
//拉一个流,生成一个RtmpMediaSource,源的名称是"app/stream"
//你也可以以其他方式生成RtmpMediaSource,比如说MP4文件(请查看test_rtmpPusherMp4.cpp代码)
PlayerProxy
::
Ptr
player
(
new
PlayerProxy
(
DEFAULT_VHOST
,
"app"
,
"stream"
));
...
...
@@ -102,18 +101,8 @@ int domain(const string &playUrl, const string &pushUrl) {
createPusher
(
app
,
stream
,
pushUrl
);
}
});
//事件轮询
EventPoller
::
Instance
().
runLoop
();
pusher
.
reset
();
}
//删除事件监听
NoticeCenter
::
Instance
().
delListener
(
nullptr
);
//清理程序
EventPoller
::
Destory
();
AsyncTaskThread
::
Destory
();
Logger
::
Destory
();
EventPollerPool
::
Instance
().
wait
();
return
0
;
}
...
...
tests/test_rtmpPusherMp4.cpp
查看文件 @
cc7844a9
...
...
@@ -92,9 +92,9 @@ void rePushDelay(const string &app,const string &stream,const string &url){
//这里才是真正执行main函数,你可以把函数名(domain)改成main,然后就可以输入自定义url了
int
domain
(
const
string
&
filePath
,
const
string
&
pushUrl
){
//设置退出信号处理函数
signal
(
SIGINT
,
[](
int
){
EventPoller
::
Instance
().
shutdown
();});
signal
(
SIGINT
,
[](
int
){
EventPoller
Pool
::
Instance
().
shutdown
();});
//设置日志
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
(
"stdout"
,
LTrace
));
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
());
Logger
::
Instance
().
setWriter
(
std
::
make_shared
<
AsyncLogWriter
>
());
//录像应用名称默认为record
...
...
@@ -104,16 +104,7 @@ int domain(const string & filePath,const string & pushUrl){
createPusher
(
appName
,
filePath
,
pushUrl
);
//开始事件轮询
EventPoller
::
Instance
().
runLoop
();
//删除事件监听
NoticeCenter
::
Instance
().
delListener
(
nullptr
);
//销毁推流器
pusher
.
reset
();
//程序清理
EventPoller
::
Destory
();
AsyncTaskThread
::
Destory
();
Logger
::
Destory
();
EventPollerPool
::
Instance
().
wait
();
return
0
;
}
...
...
tests/test_server.cpp
查看文件 @
cc7844a9
...
...
@@ -229,15 +229,16 @@ static onceToken s_token([](){
int
main
(
int
argc
,
char
*
argv
[])
{
//设置退出信号处理函数
signal
(
SIGINT
,
[](
int
)
{
EventPoller
::
Instance
().
shutdown
();
});
signal
(
SIGINT
,
[](
int
)
{
EventPoller
Pool
::
Instance
().
shutdown
();
});
signal
(
SIGHUP
,
[](
int
)
{
loadIniConfig
();
});
//设置日志
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
(
"stdout"
,
LTrace
));
Logger
::
Instance
().
add
(
std
::
make_shared
<
ConsoleChannel
>
());
Logger
::
Instance
().
add
(
std
::
make_shared
<
FileChannel
>
());
Logger
::
Instance
().
setWriter
(
std
::
make_shared
<
AsyncLogWriter
>
());
//加载配置文件,如果配置文件不存在就创建一个
loadIniConfig
();
{
//这里是拉流地址,支持rtmp/rtsp协议,负载必须是H264+AAC
//如果是其他不识别的音视频将会被忽略(譬如说h264+adpcm转发后会去除音频)
auto
urlList
=
{
"rtmp://live.hkstv.hk.lxdns.com/live/hks1"
,
...
...
@@ -353,17 +354,7 @@ int main(int argc,char *argv[]) {
}
});
EventPoller
::
Instance
().
runLoop
();
}
//设置作用域,作用域结束后会销毁临时变量;省去手动注销服务器
//rtsp服务器用到udp端口分配器了
UDPServer
::
Destory
();
//TcpServer用到了WorkThreadPool
WorkThreadPool
::
Destory
();
EventPoller
::
Destory
();
AsyncTaskThread
::
Destory
();
Logger
::
Destory
();
EventPollerPool
::
Instance
().
wait
();
return
0
;
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论