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
2504b05e
Commit
2504b05e
authored
Oct 25, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成rtmp复用器
parent
fd65c4b6
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
242 行增加
和
2 行删除
+242
-2
src/RtmpMuxer/RtmpMetedata.h
+7
-0
src/RtmpMuxer/RtmpMuxer.cpp
+116
-0
src/RtmpMuxer/RtmpMuxer.h
+117
-0
src/RtspMuxer/RtspMuxer.cpp
+1
-1
src/RtspMuxer/RtspMuxer.h
+1
-1
没有找到文件。
src/RtmpMuxer/RtmpMetedata.h
查看文件 @
2504b05e
...
...
@@ -42,6 +42,7 @@ namespace mediakit {
class
Metedata
:
public
CodecInfo
{
public
:
typedef
std
::
shared_ptr
<
Metedata
>
Ptr
;
Metedata
()
:
_metedata
(
AMF_OBJECT
){}
virtual
~
Metedata
(){}
const
AMFValue
&
getMetedata
()
const
{
...
...
@@ -56,6 +57,8 @@ protected:
*/
class
TitleMete
:
public
Metedata
{
public
:
typedef
std
::
shared_ptr
<
TitleMete
>
Ptr
;
TitleMete
(
float
dur_sec
=
0
,
uint64_t
fileSize
=
0
,
const
map
<
string
,
string
>
&
header
=
map
<
string
,
string
>
()){
...
...
@@ -86,6 +89,8 @@ public:
class
VideoMete
:
public
Metedata
{
public
:
typedef
std
::
shared_ptr
<
VideoMete
>
Ptr
;
VideoMete
(
const
VideoTrack
::
Ptr
&
video
,
int
datarate
=
5000
){
_metedata
.
set
(
"width"
,
video
->
getVideoWidth
());
_metedata
.
set
(
"height"
,
video
->
getVideoHeight
());
...
...
@@ -118,6 +123,8 @@ private:
class
AudioMete
:
public
Metedata
{
public
:
typedef
std
::
shared_ptr
<
AudioMete
>
Ptr
;
AudioMete
(
const
AudioTrack
::
Ptr
&
audio
,
int
datarate
=
160
){
_metedata
.
set
(
"audiodatarate"
,
datarate
);
_metedata
.
set
(
"audiosamplerate"
,
audio
->
getAudioSampleRate
());
...
...
src/RtmpMuxer/RtmpMuxer.cpp
0 → 100644
查看文件 @
2504b05e
/*
* MIT License
*
* Copyright (c) 2016 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "RtmpMuxer.h"
namespace
mediakit
{
void
RtmpMuxer
::
addTrack
(
const
Track
::
Ptr
&
track
)
{
//记录该Track
auto
codec_id
=
track
->
getCodecId
();
_track_map
[
codec_id
]
=
track
;
auto
lam
=
[
this
,
track
](){
//异步生成Rtmp编码器
auto
encoder
=
Factory
::
getRtmpCodecByTrack
(
track
);
if
(
!
encoder
)
{
return
;
}
//根据track生产sdp
Metedata
::
Ptr
metedate
;
switch
(
track
->
getTrackType
()){
case
TrackVideo
:{
metedate
=
std
::
make_shared
<
VideoMete
>
(
dynamic_pointer_cast
<
VideoTrack
>
(
track
));
}
break
;
case
TrackAudio
:{
metedate
=
std
::
make_shared
<
AudioMete
>
(
dynamic_pointer_cast
<
AudioTrack
>
(
track
));
}
break
;
default
:
return
;;
}
//添加其metedata
metedate
->
getMetedata
().
object_for_each
([
&
](
const
std
::
string
&
key
,
const
AMFValue
&
value
){
_metedata
.
set
(
key
,
value
);
});
//设置Track的代理,这样输入frame至Track时,最终数据将输出到RtmpEncoder中
track
->
setDelegate
(
encoder
);
//Rtmp编码器共用同一个环形缓存
encoder
->
setRtmpRing
(
_rtmpRing
);
};
if
(
track
->
ready
()){
lam
();
}
else
{
_trackReadyCallback
[
codec_id
]
=
lam
;
}
}
const
AMFValue
&
RtmpMuxer
::
getMetedata
()
const
{
if
(
!
_trackReadyCallback
.
empty
()){
//尚未就绪
static
AMFValue
s_amf
;
return
s_amf
;
}
return
_metedata
;
}
void
RtmpMuxer
::
inputFrame
(
const
Frame
::
Ptr
&
frame
)
{
auto
codec_id
=
frame
->
getCodecId
();
auto
it
=
_track_map
.
find
(
codec_id
);
if
(
it
==
_track_map
.
end
())
{
return
;
}
//Track是否准备好
auto
ready
=
it
->
second
->
ready
();
//inputFrame可能使Track变成就绪状态
it
->
second
->
inputFrame
(
frame
);
if
(
!
ready
&&
it
->
second
->
ready
()){
//Track由未就绪状态装换成就绪状态,我们就生成sdp以及Rtmp编码器
auto
it_callback
=
_trackReadyCallback
.
find
(
codec_id
);
if
(
it_callback
!=
_trackReadyCallback
.
end
()){
it_callback
->
second
();
_trackReadyCallback
.
erase
(
it_callback
);
}
}
}
bool
RtmpMuxer
::
inputRtmp
(
const
RtmpPacket
::
Ptr
&
rtmp
,
bool
key_pos
)
{
_rtmpRing
->
write
(
rtmp
,
key_pos
);
return
key_pos
;
}
RtmpRingInterface
::
RingType
::
Ptr
RtmpMuxer
::
getRtmpRing
()
const
{
return
_rtmpRing
;
}
}
\ No newline at end of file
src/RtmpMuxer/RtmpMuxer.h
0 → 100644
查看文件 @
2504b05e
/*
* MIT License
*
* Copyright (c) 2016 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef ZLMEDIAKIT_RTMPMUXER_H
#define ZLMEDIAKIT_RTMPMUXER_H
#include "RtmpMetedata.h"
namespace
mediakit
{
class
RtmpMuxer
{
public
:
/**
* 构造函数
*/
RtmpMuxer
(
const
TitleMete
::
Ptr
&
title
=
std
::
make_shared
<
TitleMete
>
())
:
_metedata
(
AMF_OBJECT
){
_metedata
=
title
->
getMetedata
();
_rtmpRing
=
std
::
make_shared
<
RtmpRingInterface
::
RingType
>
();
}
virtual
~
RtmpMuxer
(){}
/**
* 添加音视频媒体
* @param track 媒体描述
*/
void
addTrack
(
const
Track
::
Ptr
&
track
)
;
/**
* 获取完整的SDP字符串
* @return SDP字符串
*/
const
AMFValue
&
getMetedata
()
const
;
/**
* 写入帧数据然后打包rtmp
* @param frame 帧数据
*/
void
inputFrame
(
const
Frame
::
Ptr
&
frame
)
;
/**
* 也可以在外部打包好rtmp然后再写入
* @param rtmp rtmp包
* @param key_pos 是否为关键帧
*/
bool
inputRtmp
(
const
RtmpPacket
::
Ptr
&
rtmp
,
bool
key_pos
=
true
);
/**
* 获取rtmp环形缓存
* @return
*/
RtmpRingInterface
::
RingType
::
Ptr
getRtmpRing
()
const
;
private
:
map
<
int
,
Track
::
Ptr
>
_track_map
;
map
<
int
,
function
<
void
()
>
>
_trackReadyCallback
;
RtmpRingInterface
::
RingType
::
Ptr
_rtmpRing
;
AMFValue
_metedata
;
};
}
/* namespace mediakit */
#endif //ZLMEDIAKIT_RTMPMUXER_H
src/RtspMuxer/RtspMuxer.cpp
查看文件 @
2504b05e
...
...
@@ -93,7 +93,7 @@ void RtspMuxer::inputFrame(const Frame::Ptr &frame) {
bool
RtspMuxer
::
inputRtp
(
const
RtpPacket
::
Ptr
&
rtp
,
bool
key_pos
)
{
_rtpRing
->
write
(
rtp
,
key_pos
);
return
true
;
return
key_pos
;
}
RtpRingInterface
::
RingType
::
Ptr
RtspMuxer
::
getRtpRing
()
const
{
...
...
src/RtspMuxer/RtspMuxer.h
查看文件 @
2504b05e
...
...
@@ -45,7 +45,7 @@ public:
virtual
~
RtspMuxer
(){}
/**
* 添加音视频
或title
媒体
* 添加音视频媒体
* @param track 媒体描述
* @param ssrc 媒体rtp ssrc
* @param mtu 媒体rtp mtu
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论