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
cb7c72d9
Commit
cb7c72d9
authored
Sep 23, 2019
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修正metadata拼写错误,优化RtmpMediaSource注册机制,修复及时拉流不出画面的bug
parent
8ae9f561
显示空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
79 行增加
和
66 行删除
+79
-66
src/Common/MultiMediaSourceMuxer.h
+1
-1
src/Extension/Factory.cpp
+1
-1
src/Extension/Factory.h
+2
-2
src/Rtmp/Rtmp.cpp
+14
-13
src/Rtmp/Rtmp.h
+24
-24
src/Rtmp/RtmpDemuxer.cpp
+2
-2
src/Rtmp/RtmpDemuxer.h
+3
-3
src/Rtmp/RtmpMediaSource.h
+5
-0
src/Rtmp/RtmpMediaSourceMuxer.h
+2
-2
src/Rtmp/RtmpMuxer.cpp
+12
-12
src/Rtmp/RtmpMuxer.h
+3
-3
src/Rtmp/RtmpPlayerImp.h
+1
-1
src/Rtmp/RtmpSession.cpp
+7
-1
src/Rtmp/RtmpSession.h
+2
-1
没有找到文件。
src/Common/MultiMediaSourceMuxer.h
查看文件 @
cb7c72d9
...
...
@@ -45,7 +45,7 @@ public:
bool
bEnableMp4
=
false
){
if
(
bEanbleRtmp
)
{
_rtmp
=
std
::
make_shared
<
RtmpMediaSourceMuxer
>
(
vhost
,
strApp
,
strId
,
std
::
make_shared
<
TitleMet
e
>
(
dur_sec
));
_rtmp
=
std
::
make_shared
<
RtmpMediaSourceMuxer
>
(
vhost
,
strApp
,
strId
,
std
::
make_shared
<
TitleMet
a
>
(
dur_sec
));
}
if
(
bEanbleRtsp
)
{
_rtsp
=
std
::
make_shared
<
RtspMediaSourceMuxer
>
(
vhost
,
strApp
,
strId
,
std
::
make_shared
<
TitleSdp
>
(
dur_sec
));
...
...
src/Extension/Factory.cpp
查看文件 @
cb7c72d9
...
...
@@ -197,7 +197,7 @@ CodecId Factory::getCodecIdByAmf(const AMFValue &val){
return
CodecInvalid
;
}
}
else
{
WarnL
<<
"Met
e
data不存在相应的Track"
;
WarnL
<<
"Met
a
data不存在相应的Track"
;
}
return
CodecInvalid
;
...
...
src/Extension/Factory.h
查看文件 @
cb7c72d9
...
...
@@ -73,14 +73,14 @@ public:
/**
* 根据amf对象获取响应的Track
* @param amf rtmp met
e
data中的videocodecid或audiocodecid的值
* @param amf rtmp met
a
data中的videocodecid或audiocodecid的值
* @return
*/
static
Track
::
Ptr
getTrackByAmf
(
const
AMFValue
&
amf
);
/**
* 根据amf对象获取相应的CodecId
* @param val rtmp met
e
data中的videocodecid或audiocodecid的值
* @param val rtmp met
a
data中的videocodecid或audiocodecid的值
* @return
*/
static
CodecId
getCodecIdByAmf
(
const
AMFValue
&
val
);
...
...
src/Rtmp/Rtmp.cpp
查看文件 @
cb7c72d9
...
...
@@ -27,35 +27,35 @@
#include "Extension/Factory.h"
namespace
mediakit
{
VideoMet
e
::
VideoMete
(
const
VideoTrack
::
Ptr
&
video
,
int
datarate
){
VideoMet
a
::
VideoMeta
(
const
VideoTrack
::
Ptr
&
video
,
int
datarate
){
if
(
video
->
getVideoWidth
()
>
0
){
_met
e
data
.
set
(
"width"
,
video
->
getVideoWidth
());
_met
a
data
.
set
(
"width"
,
video
->
getVideoWidth
());
}
if
(
video
->
getVideoHeight
()
>
0
){
_met
e
data
.
set
(
"height"
,
video
->
getVideoHeight
());
_met
a
data
.
set
(
"height"
,
video
->
getVideoHeight
());
}
if
(
video
->
getVideoFps
()
>
0
){
_met
e
data
.
set
(
"framerate"
,
video
->
getVideoFps
());
_met
a
data
.
set
(
"framerate"
,
video
->
getVideoFps
());
}
_met
e
data
.
set
(
"videodatarate"
,
datarate
);
_met
a
data
.
set
(
"videodatarate"
,
datarate
);
_codecId
=
video
->
getCodecId
();
_met
e
data
.
set
(
"videocodecid"
,
Factory
::
getAmfByCodecId
(
_codecId
));
_met
a
data
.
set
(
"videocodecid"
,
Factory
::
getAmfByCodecId
(
_codecId
));
}
AudioMet
e
::
AudioMete
(
const
AudioTrack
::
Ptr
&
audio
,
int
datarate
){
_met
e
data
.
set
(
"audiodatarate"
,
datarate
);
AudioMet
a
::
AudioMeta
(
const
AudioTrack
::
Ptr
&
audio
,
int
datarate
){
_met
a
data
.
set
(
"audiodatarate"
,
datarate
);
if
(
audio
->
getAudioSampleRate
()
>
0
){
_met
e
data
.
set
(
"audiosamplerate"
,
audio
->
getAudioSampleRate
());
_met
a
data
.
set
(
"audiosamplerate"
,
audio
->
getAudioSampleRate
());
}
if
(
audio
->
getAudioSampleBit
()
>
0
){
_met
e
data
.
set
(
"audiosamplesize"
,
audio
->
getAudioSampleBit
());
_met
a
data
.
set
(
"audiosamplesize"
,
audio
->
getAudioSampleBit
());
}
if
(
audio
->
getAudioChannel
()
>
0
){
_met
e
data
.
set
(
"audiochannels"
,
audio
->
getAudioChannel
());
_met
e
data
.
set
(
"stereo"
,
audio
->
getAudioChannel
()
>
1
);
_met
a
data
.
set
(
"audiochannels"
,
audio
->
getAudioChannel
());
_met
a
data
.
set
(
"stereo"
,
audio
->
getAudioChannel
()
>
1
);
}
_codecId
=
audio
->
getCodecId
();
_met
e
data
.
set
(
"audiocodecid"
,
Factory
::
getAmfByCodecId
(
_codecId
));
_met
a
data
.
set
(
"audiocodecid"
,
Factory
::
getAmfByCodecId
(
_codecId
));
}
}
//
namespace
mediakit
\ No newline at end of file
src/Rtmp/Rtmp.h
查看文件 @
cb7c72d9
...
...
@@ -298,36 +298,36 @@ public:
/**
* rtmp met
e
data基类,用于描述rtmp格式信息
* rtmp met
a
data基类,用于描述rtmp格式信息
*/
class
Met
e
data
:
public
CodecInfo
{
class
Met
a
data
:
public
CodecInfo
{
public
:
typedef
std
::
shared_ptr
<
Met
e
data
>
Ptr
;
typedef
std
::
shared_ptr
<
Met
a
data
>
Ptr
;
Met
edata
()
:
_mete
data
(
AMF_OBJECT
){}
virtual
~
Met
e
data
(){}
const
AMFValue
&
getMet
e
data
()
const
{
return
_met
e
data
;
Met
adata
()
:
_meta
data
(
AMF_OBJECT
){}
virtual
~
Met
a
data
(){}
const
AMFValue
&
getMet
a
data
()
const
{
return
_met
a
data
;
}
protected
:
AMFValue
_met
e
data
;
AMFValue
_met
a
data
;
};
/**
* met
e
data中除音视频外的其他描述部分
* met
a
data中除音视频外的其他描述部分
*/
class
TitleMet
e
:
public
Mete
data
{
class
TitleMet
a
:
public
Meta
data
{
public
:
typedef
std
::
shared_ptr
<
TitleMet
e
>
Ptr
;
typedef
std
::
shared_ptr
<
TitleMet
a
>
Ptr
;
TitleMet
e
(
float
dur_sec
=
0
,
TitleMet
a
(
float
dur_sec
=
0
,
uint64_t
fileSize
=
0
,
const
map
<
string
,
string
>
&
header
=
map
<
string
,
string
>
()){
_met
e
data
.
set
(
"duration"
,
dur_sec
);
_met
e
data
.
set
(
"fileSize"
,
0
);
_met
e
data
.
set
(
"server"
,
"ZLMediaKit"
);
_met
a
data
.
set
(
"duration"
,
dur_sec
);
_met
a
data
.
set
(
"fileSize"
,
0
);
_met
a
data
.
set
(
"server"
,
"ZLMediaKit"
);
for
(
auto
&
pr
:
header
){
_met
e
data
.
set
(
pr
.
first
,
pr
.
second
);
_met
a
data
.
set
(
pr
.
first
,
pr
.
second
);
}
}
...
...
@@ -348,12 +348,12 @@ public:
}
};
class
VideoMet
e
:
public
Mete
data
{
class
VideoMet
a
:
public
Meta
data
{
public
:
typedef
std
::
shared_ptr
<
VideoMet
e
>
Ptr
;
typedef
std
::
shared_ptr
<
VideoMet
a
>
Ptr
;
VideoMet
e
(
const
VideoTrack
::
Ptr
&
video
,
int
datarate
=
5000
);
virtual
~
VideoMet
e
(){}
VideoMet
a
(
const
VideoTrack
::
Ptr
&
video
,
int
datarate
=
5000
);
virtual
~
VideoMet
a
(){}
/**
* 返回音频或视频类型
...
...
@@ -375,13 +375,13 @@ private:
};
class
AudioMet
e
:
public
Mete
data
{
class
AudioMet
a
:
public
Meta
data
{
public
:
typedef
std
::
shared_ptr
<
AudioMet
e
>
Ptr
;
typedef
std
::
shared_ptr
<
AudioMet
a
>
Ptr
;
AudioMet
e
(
const
AudioTrack
::
Ptr
&
audio
,
int
datarate
=
160
);
AudioMet
a
(
const
AudioTrack
::
Ptr
&
audio
,
int
datarate
=
160
);
virtual
~
AudioMet
e
(){}
virtual
~
AudioMet
a
(){}
/**
* 返回音频或视频类型
...
...
src/Rtmp/RtmpDemuxer.cpp
查看文件 @
cb7c72d9
...
...
@@ -45,8 +45,8 @@ RtmpDemuxer::RtmpDemuxer(const AMFValue &val) {
}
}
int
RtmpDemuxer
::
getTrackCount
(
const
AMFValue
&
met
e
data
)
{
return
(
int
)(
met
edata
[
"videocodecid"
].
type
()
!=
AMF_NULL
)
+
(
int
)(
mete
data
[
"audiocodecid"
].
type
()
!=
AMF_NULL
);
int
RtmpDemuxer
::
getTrackCount
(
const
AMFValue
&
met
a
data
)
{
return
(
int
)(
met
adata
[
"videocodecid"
].
type
()
!=
AMF_NULL
)
+
(
int
)(
meta
data
[
"audiocodecid"
].
type
()
!=
AMF_NULL
);
}
bool
RtmpDemuxer
::
inputRtmp
(
const
RtmpPacket
::
Ptr
&
pkt
)
{
...
...
src/Rtmp/RtmpDemuxer.h
查看文件 @
cb7c72d9
...
...
@@ -49,7 +49,7 @@ public:
RtmpDemuxer
(){}
/**
* 构造rtmp解复用器
* @param val rtmp的met
e
data,可以传入null类型,
* @param val rtmp的met
a
data,可以传入null类型,
* 这样就会在inputRtmp时异步探测媒体编码格式
*/
RtmpDemuxer
(
const
AMFValue
&
val
);
...
...
@@ -58,10 +58,10 @@ public:
/**
*
* 获取rtmp track 数
* @param met
edata rtmp的mete
data
* @param met
adata rtmp的meta
data
* @return
*/
static
int
getTrackCount
(
const
AMFValue
&
met
e
data
);
static
int
getTrackCount
(
const
AMFValue
&
met
a
data
);
/**
* 开始解复用
...
...
src/Rtmp/RtmpMediaSource.h
查看文件 @
cb7c72d9
...
...
@@ -86,6 +86,9 @@ public:
virtual
void
onGetMetaData
(
const
AMFValue
&
metadata
)
{
lock_guard
<
recursive_mutex
>
lock
(
_mtxMap
);
_metadata
=
metadata
;
if
(
_pRing
){
regist
();
}
}
void
onWrite
(
const
RtmpPacket
::
Ptr
&
pkt
,
bool
isKey
=
true
)
override
{
...
...
@@ -107,8 +110,10 @@ public:
strongSelf
->
onReaderChanged
(
size
);
});
onReaderChanged
(
0
);
if
(
_metadata
){
regist
();
}
}
_pRing
->
write
(
pkt
,
pkt
->
isVideoKeyFrame
());
checkNoneReader
();
}
...
...
src/Rtmp/RtmpMediaSourceMuxer.h
查看文件 @
cb7c72d9
...
...
@@ -39,7 +39,7 @@ public:
RtmpMediaSourceMuxer
(
const
string
&
vhost
,
const
string
&
strApp
,
const
string
&
strId
,
const
TitleMet
e
::
Ptr
&
title
=
nullptr
)
:
RtmpMuxer
(
title
){
const
TitleMet
a
::
Ptr
&
title
=
nullptr
)
:
RtmpMuxer
(
title
){
_mediaSouce
=
std
::
make_shared
<
RtmpMediaSource
>
(
vhost
,
strApp
,
strId
);
getRtmpRing
()
->
setDelegate
(
_mediaSouce
);
}
...
...
@@ -53,7 +53,7 @@ public:
}
private
:
void
onAllTrackReady
()
override
{
_mediaSouce
->
onGetMetaData
(
getMet
e
data
());
_mediaSouce
->
onGetMetaData
(
getMet
a
data
());
}
private
:
RtmpMediaSource
::
Ptr
_mediaSouce
;
...
...
src/Rtmp/RtmpMuxer.cpp
查看文件 @
cb7c72d9
...
...
@@ -29,11 +29,11 @@
namespace
mediakit
{
RtmpMuxer
::
RtmpMuxer
(
const
TitleMet
e
::
Ptr
&
title
)
{
RtmpMuxer
::
RtmpMuxer
(
const
TitleMet
a
::
Ptr
&
title
)
{
if
(
!
title
){
_met
edata
=
std
::
make_shared
<
TitleMete
>
()
->
getMete
data
();
_met
adata
=
std
::
make_shared
<
TitleMeta
>
()
->
getMeta
data
();
}
else
{
_met
edata
=
title
->
getMete
data
();
_met
adata
=
title
->
getMeta
data
();
}
_rtmpRing
=
std
::
make_shared
<
RtmpRingInterface
::
RingType
>
();
}
...
...
@@ -45,24 +45,24 @@ void RtmpMuxer::onTrackReady(const Track::Ptr &track) {
if
(
!
encoder
)
{
return
;
}
//根据track生产met
e
data
Met
edata
::
Ptr
metedate
;
//根据track生产met
a
data
Met
adata
::
Ptr
metadata
;
switch
(
track
->
getTrackType
()){
case
TrackVideo
:{
met
edate
=
std
::
make_shared
<
VideoMete
>
(
dynamic_pointer_cast
<
VideoTrack
>
(
track
));
met
adata
=
std
::
make_shared
<
VideoMeta
>
(
dynamic_pointer_cast
<
VideoTrack
>
(
track
));
}
break
;
case
TrackAudio
:{
met
edate
=
std
::
make_shared
<
AudioMete
>
(
dynamic_pointer_cast
<
AudioTrack
>
(
track
));
met
adata
=
std
::
make_shared
<
AudioMeta
>
(
dynamic_pointer_cast
<
AudioTrack
>
(
track
));
}
break
;
default
:
return
;;
}
//添加其met
e
data
met
edate
->
getMete
data
().
object_for_each
([
&
](
const
std
::
string
&
key
,
const
AMFValue
&
value
){
_met
e
data
.
set
(
key
,
value
);
//添加其met
a
data
met
adata
->
getMeta
data
().
object_for_each
([
&
](
const
std
::
string
&
key
,
const
AMFValue
&
value
){
_met
a
data
.
set
(
key
,
value
);
});
//设置Track的代理,这样输入frame至Track时,最终数据将输出到RtmpEncoder中
track
->
addDelegate
(
encoder
);
...
...
@@ -71,13 +71,13 @@ void RtmpMuxer::onTrackReady(const Track::Ptr &track) {
}
const
AMFValue
&
RtmpMuxer
::
getMet
e
data
()
const
{
const
AMFValue
&
RtmpMuxer
::
getMet
a
data
()
const
{
if
(
!
isAllTrackReady
()){
//尚未就绪
static
AMFValue
s_amf
;
return
s_amf
;
}
return
_met
e
data
;
return
_met
a
data
;
}
RtmpRingInterface
::
RingType
::
Ptr
RtmpMuxer
::
getRtmpRing
()
const
{
...
...
src/Rtmp/RtmpMuxer.h
查看文件 @
cb7c72d9
...
...
@@ -41,14 +41,14 @@ public:
/**
* 构造函数
*/
RtmpMuxer
(
const
TitleMet
e
::
Ptr
&
title
);
RtmpMuxer
(
const
TitleMet
a
::
Ptr
&
title
);
virtual
~
RtmpMuxer
(){}
/**
* 获取完整的SDP字符串
* @return SDP字符串
*/
const
AMFValue
&
getMet
e
data
()
const
;
const
AMFValue
&
getMet
a
data
()
const
;
/**
* 获取rtmp环形缓存
...
...
@@ -64,7 +64,7 @@ protected:
void
onTrackReady
(
const
Track
::
Ptr
&
track
)
override
;
private
:
RtmpRingInterface
::
RingType
::
Ptr
_rtmpRing
;
AMFValue
_met
e
data
;
AMFValue
_met
a
data
;
};
...
...
src/Rtmp/RtmpPlayerImp.h
查看文件 @
cb7c72d9
...
...
@@ -75,7 +75,7 @@ private:
_pRtmpMediaSrc
->
onWrite
(
chunkData
);
}
if
(
!
_parser
){
//这个流没有met
e
data
//这个流没有met
a
data
_parser
.
reset
(
new
RtmpDemuxer
());
}
_parser
->
inputRtmp
(
chunkData
);
...
...
src/Rtmp/RtmpSession.cpp
查看文件 @
cb7c72d9
...
...
@@ -431,6 +431,7 @@ void RtmpSession::setMetaData(AMFDecoder &dec) {
}
auto
metadata
=
dec
.
load
<
AMFValue
>
();
//dumpMetadata(metadata);
_metadata_got
=
true
;
_pPublisherSrc
->
onGetMetaData
(
metadata
);
}
...
...
@@ -488,6 +489,11 @@ void RtmpSession::onRtmpChunk(RtmpPacket &chunkData) {
_stamp
[
chunkData
.
typeId
%
2
].
revise
(
0
,
0
,
dts_out
,
dts_out
);
chunkData
.
timeStamp
=
dts_out
;
}
if
(
!
_metadata_got
){
//有些rtmp推流客户端不产生metadata,我们产生一个默认的metadata,目的是为了触发注册操作
_metadata_got
=
true
;
_pPublisherSrc
->
onGetMetaData
(
TitleMeta
().
getMetadata
());
}
_pPublisherSrc
->
onWrite
(
std
::
make_shared
<
RtmpPacket
>
(
std
::
move
(
chunkData
)));
}
break
;
...
...
@@ -553,7 +559,7 @@ void RtmpSession::setSocketFlags(){
void
RtmpSession
::
dumpMetadata
(
const
AMFValue
&
metadata
)
{
if
(
metadata
.
type
()
!=
AMF_OBJECT
&&
metadata
.
type
()
!=
AMF_ECMA_ARRAY
){
WarnL
<<
"invalid met
e
data type:"
<<
metadata
.
type
();
WarnL
<<
"invalid met
a
data type:"
<<
metadata
.
type
();
return
;
}
_StrPrinter
printer
;
...
...
src/Rtmp/RtmpSession.h
查看文件 @
cb7c72d9
...
...
@@ -87,8 +87,9 @@ private:
void
onNoneReader
(
MediaSource
&
sender
)
override
;
void
setSocketFlags
();
string
getStreamId
(
const
string
&
str
);
void
dumpMetadata
(
const
AMFValue
&
met
e
data
);
void
dumpMetadata
(
const
AMFValue
&
met
a
data
);
private
:
bool
_metadata_got
=
false
;
std
::
string
_strTcUrl
;
MediaInfo
_mediaInfo
;
double
_dNowReqID
=
0
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论