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
b5c3830a
Commit
b5c3830a
authored
Mar 26, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
简化rtmp推流器代码
parent
dc1cae21
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
12 行增加
和
19 行删除
+12
-19
ZLToolKit
+1
-1
src/Rtmp/RtmpPusher.cpp
+10
-12
src/Rtmp/RtmpPusher.h
+1
-6
没有找到文件。
ZLToolKit
@
8e90a8db
Subproject commit
e589ef61db16b3d7c43661f1e421b451227af07e
Subproject commit
8e90a8dbefe9060fdb86b9dc8036345aa69faf41
src/Rtmp/RtmpPusher.cpp
查看文件 @
b5c3830a
...
@@ -35,26 +35,16 @@ namespace mediakit {
...
@@ -35,26 +35,16 @@ namespace mediakit {
static
int
kSockFlags
=
SOCKET_DEFAULE_FLAGS
|
FLAG_MORE
;
static
int
kSockFlags
=
SOCKET_DEFAULE_FLAGS
|
FLAG_MORE
;
unordered_map
<
string
,
RtmpPusher
::
rtmpCMDHandle
>
RtmpPusher
::
g_mapCmd
;
RtmpPusher
::
RtmpPusher
(
const
char
*
strVhost
,
const
char
*
strApp
,
const
char
*
strStream
)
{
RtmpPusher
::
RtmpPusher
(
const
char
*
strVhost
,
const
char
*
strApp
,
const
char
*
strStream
)
{
auto
src
=
dynamic_pointer_cast
<
RtmpMediaSource
>
(
MediaSource
::
find
(
RTMP_SCHEMA
,
strVhost
,
strApp
,
strStream
));
auto
src
=
dynamic_pointer_cast
<
RtmpMediaSource
>
(
MediaSource
::
find
(
RTMP_SCHEMA
,
strVhost
,
strApp
,
strStream
));
if
(
!
src
)
{
if
(
!
src
)
{
auto
strErr
=
StrPrinter
<<
"media source:"
<<
strVhost
<<
"/"
<<
strApp
<<
"/"
<<
strStream
<<
"not found!"
<<
endl
;
auto
strErr
=
StrPrinter
<<
"media source:"
<<
strVhost
<<
"/"
<<
strApp
<<
"/"
<<
strStream
<<
"not found!"
<<
endl
;
throw
std
::
runtime_error
(
strErr
);
throw
std
::
runtime_error
(
strErr
);
}
}
init
(
src
)
;
_pMediaSrc
=
src
;
}
}
RtmpPusher
::
RtmpPusher
(
const
RtmpMediaSource
::
Ptr
&
src
){
RtmpPusher
::
RtmpPusher
(
const
RtmpMediaSource
::
Ptr
&
src
){
init
(
src
);
_pMediaSrc
=
src
;
}
void
RtmpPusher
::
init
(
const
RtmpMediaSource
::
Ptr
&
src
){
static
onceToken
token
([]()
{
g_mapCmd
.
emplace
(
"_error"
,
&
RtmpPusher
::
onCmd_result
);
g_mapCmd
.
emplace
(
"_result"
,
&
RtmpPusher
::
onCmd_result
);
g_mapCmd
.
emplace
(
"onStatus"
,
&
RtmpPusher
::
onCmd_onStatus
);
},
[]()
{});
_pMediaSrc
=
src
;
}
}
RtmpPusher
::~
RtmpPusher
()
{
RtmpPusher
::~
RtmpPusher
()
{
...
@@ -266,6 +256,14 @@ void RtmpPusher::onRtmpChunk(RtmpPacket &chunkData) {
...
@@ -266,6 +256,14 @@ void RtmpPusher::onRtmpChunk(RtmpPacket &chunkData) {
switch
(
chunkData
.
typeId
)
{
switch
(
chunkData
.
typeId
)
{
case
MSG_CMD
:
case
MSG_CMD
:
case
MSG_CMD3
:
{
case
MSG_CMD3
:
{
typedef
void
(
RtmpPusher
::*
rtmpCMDHandle
)(
AMFDecoder
&
dec
);
static
unordered_map
<
string
,
rtmpCMDHandle
>
g_mapCmd
;
static
onceToken
token
([]()
{
g_mapCmd
.
emplace
(
"_error"
,
&
RtmpPusher
::
onCmd_result
);
g_mapCmd
.
emplace
(
"_result"
,
&
RtmpPusher
::
onCmd_result
);
g_mapCmd
.
emplace
(
"onStatus"
,
&
RtmpPusher
::
onCmd_onStatus
);
},
[]()
{});
AMFDecoder
dec
(
chunkData
.
strBuf
,
0
);
AMFDecoder
dec
(
chunkData
.
strBuf
,
0
);
std
::
string
type
=
dec
.
load
<
std
::
string
>
();
std
::
string
type
=
dec
.
load
<
std
::
string
>
();
auto
it
=
g_mapCmd
.
find
(
type
);
auto
it
=
g_mapCmd
.
find
(
type
);
...
...
src/Rtmp/RtmpPusher.h
查看文件 @
b5c3830a
...
@@ -64,7 +64,6 @@ protected:
...
@@ -64,7 +64,6 @@ protected:
send
(
buffer
);
send
(
buffer
);
}
}
private
:
private
:
void
init
(
const
RtmpMediaSource
::
Ptr
&
src
);
void
onShutdown
(
const
SockException
&
ex
)
{
void
onShutdown
(
const
SockException
&
ex
)
{
_pPublishTimer
.
reset
();
_pPublishTimer
.
reset
();
if
(
_onShutdown
){
if
(
_onShutdown
){
...
@@ -99,6 +98,7 @@ private:
...
@@ -99,6 +98,7 @@ private:
inline
void
send_publish
();
inline
void
send_publish
();
inline
void
send_metaData
();
inline
void
send_metaData
();
private
:
string
_strApp
;
string
_strApp
;
string
_strStream
;
string
_strStream
;
string
_strTcUrl
;
string
_strTcUrl
;
...
@@ -107,13 +107,8 @@ private:
...
@@ -107,13 +107,8 @@ private:
recursive_mutex
_mtxOnResultCB
;
recursive_mutex
_mtxOnResultCB
;
deque
<
function
<
void
(
AMFValue
&
dec
)
>
>
_dqOnStatusCB
;
deque
<
function
<
void
(
AMFValue
&
dec
)
>
>
_dqOnStatusCB
;
recursive_mutex
_mtxOnStatusCB
;
recursive_mutex
_mtxOnStatusCB
;
typedef
void
(
RtmpPusher
::*
rtmpCMDHandle
)(
AMFDecoder
&
dec
);
static
unordered_map
<
string
,
rtmpCMDHandle
>
g_mapCmd
;
//超时功能实现
//超时功能实现
std
::
shared_ptr
<
Timer
>
_pPublishTimer
;
std
::
shared_ptr
<
Timer
>
_pPublishTimer
;
//源
//源
std
::
weak_ptr
<
RtmpMediaSource
>
_pMediaSrc
;
std
::
weak_ptr
<
RtmpMediaSource
>
_pMediaSrc
;
RtmpMediaSource
::
RingType
::
RingReader
::
Ptr
_pRtmpReader
;
RtmpMediaSource
::
RingType
::
RingReader
::
Ptr
_pRtmpReader
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论