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
92ea9567
Commit
92ea9567
authored
Oct 24, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加工厂类 统一管理
parent
68fc3bdc
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
138 行增加
和
134 行删除
+138
-134
src/Common/Factory.cpp
+56
-6
src/Common/Factory.h
+57
-0
src/Player/Track.h
+0
-5
src/RTP/RtpCodec.cpp
+0
-35
src/RTP/RtpCodec.h
+0
-25
src/Rtsp/RtpParser.cpp
+5
-4
src/Rtsp/RtspSdp.cpp
+18
-34
src/Rtsp/RtspSdp.h
+2
-25
没有找到文件。
src/
Player/Track
.cpp
→
src/
Common/Factory
.cpp
查看文件 @
92ea9567
//
// Created by xzl on 2018/10/2
1
.
// Created by xzl on 2018/10/2
4
.
//
#include "Track.h"
#include "Util/util.h"
#include "Util/base64.h"
#include "Factory.h"
Sdp
::
Ptr
Factory
::
getSdpByTrack
(
const
Track
::
Ptr
&
track
)
{
switch
(
track
->
getCodecId
()){
case
CodecH264
:{
H264Track
::
Ptr
h264Track
=
dynamic_pointer_cast
<
H264Track
>
(
track
);
if
(
!
h264Track
){
return
nullptr
;
}
return
std
::
make_shared
<
H264Sdp
>
(
h264Track
->
getSps
(),
h264Track
->
getPps
());
}
case
CodecAAC
:{
AACTrack
::
Ptr
aacTrack
=
dynamic_pointer_cast
<
AACTrack
>
(
track
);
if
(
!
aacTrack
){
return
nullptr
;
}
return
std
::
make_shared
<
AACSdp
>
(
aacTrack
->
getAacCfg
(),
aacTrack
->
getAudioSampleRate
());
}
default
:
return
nullptr
;
}
}
using
namespace
ZL
::
Util
;
Track
::
Ptr
Track
::
getTrackBySdp
(
const
string
&
sdp
)
{
Track
::
Ptr
Factory
::
getTrackBySdp
(
const
string
&
sdp
)
{
if
(
strcasestr
(
sdp
.
data
(),
"mpeg4-generic"
)
!=
nullptr
)
{
string
aac_cfg_str
=
FindField
(
sdp
.
c_str
(),
"config="
,
"
\r\n
"
);
if
(
aac_cfg_str
.
size
()
!=
4
)
{
...
...
@@ -51,3 +71,33 @@ Track::Ptr Track::getTrackBySdp(const string &sdp) {
return
nullptr
;
}
RtpCodec
::
Ptr
Factory
::
getRtpEncoderById
(
CodecId
codecId
,
uint32_t
ui32Ssrc
,
uint32_t
ui32MtuSize
,
uint32_t
ui32SampleRate
,
uint8_t
ui8PlayloadType
,
uint8_t
ui8Interleaved
)
{
switch
(
codecId
){
case
CodecH264
:
return
std
::
make_shared
<
H264RtpEncoder
>
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
);
case
CodecAAC
:
return
std
::
make_shared
<
AACRtpEncoder
>
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
);
default
:
return
nullptr
;
}
}
RtpCodec
::
Ptr
Factory
::
getRtpDecoderById
(
CodecId
codecId
,
uint32_t
ui32SampleRate
)
{
switch
(
codecId
){
case
CodecH264
:
return
std
::
make_shared
<
H264RtpDecoder
>
();
case
CodecAAC
:
return
std
::
make_shared
<
AACRtpDecoder
>
(
ui32SampleRate
);
default
:
return
nullptr
;
}
}
src/Common/Factory.h
0 → 100644
查看文件 @
92ea9567
//
// Created by xzl on 2018/10/24.
//
#ifndef ZLMEDIAKIT_FACTORY_H
#define ZLMEDIAKIT_FACTORY_H
#include <string>
#include "Player/Track.h"
#include "Rtsp/RtspSdp.h"
using
namespace
std
;
using
namespace
ZL
::
Rtsp
;
class
Factory
{
public
:
/**
* 根据sdp生成Track对象
*/
static
Track
::
Ptr
getTrackBySdp
(
const
string
&
sdp
);
/**
* 根据Track生成SDP对象
* @param track 媒体信息
* @return 返回sdp对象
*/
static
Sdp
::
Ptr
getSdpByTrack
(
const
Track
::
Ptr
&
track
);
/**
* 根据CodecId生成Rtp打包器
* @param codecId
* @param ui32Ssrc
* @param ui32MtuSize
* @param ui32SampleRate
* @param ui8PlayloadType
* @param ui8Interleaved
* @return
*/
static
RtpCodec
::
Ptr
getRtpEncoderById
(
CodecId
codecId
,
uint32_t
ui32Ssrc
,
uint32_t
ui32MtuSize
,
uint32_t
ui32SampleRate
,
uint8_t
ui8PlayloadType
,
uint8_t
ui8Interleaved
);
/**
* 根据CodecId生成Rtp解包器
* @param codecId
* @param ui32SampleRate
* @return
*/
static
RtpCodec
::
Ptr
getRtpDecoderById
(
CodecId
codecId
,
uint32_t
ui32SampleRate
);
};
#endif //ZLMEDIAKIT_FACTORY_H
src/Player/Track.h
查看文件 @
92ea9567
...
...
@@ -20,11 +20,6 @@ public:
typedef
std
::
shared_ptr
<
Track
>
Ptr
;
Track
(){}
virtual
~
Track
(){}
/**
* 根据sdp生成Track对象
*/
static
Ptr
getTrackBySdp
(
const
string
&
sdp
);
};
class
VideoTrack
:
public
Track
{
...
...
src/RTP/RtpCodec.cpp
deleted
100644 → 0
查看文件 @
68fc3bdc
//
// Created by xzl on 2018/10/18.
//
#include "RtpCodec.h"
#include "AACRtpCodec.h"
#include "H264RtpCodec.h"
RtpCodec
::
Ptr
RtpCodec
::
getRtpEncoderById
(
CodecId
codecId
,
uint32_t
ui32Ssrc
,
uint32_t
ui32MtuSize
,
uint32_t
ui32SampleRate
,
uint8_t
ui8PlayloadType
,
uint8_t
ui8Interleaved
)
{
switch
(
codecId
){
case
CodecH264
:
return
std
::
make_shared
<
H264RtpEncoder
>
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
);
case
CodecAAC
:
return
std
::
make_shared
<
AACRtpEncoder
>
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
);
default
:
return
nullptr
;
}
}
RtpCodec
::
Ptr
RtpCodec
::
getRtpDecoderById
(
CodecId
codecId
,
uint32_t
ui32SampleRate
)
{
switch
(
codecId
){
case
CodecH264
:
return
std
::
make_shared
<
H264RtpDecoder
>
();
case
CodecAAC
:
return
std
::
make_shared
<
AACRtpDecoder
>
(
ui32SampleRate
);
default
:
return
nullptr
;
}
}
src/RTP/RtpCodec.h
查看文件 @
92ea9567
...
...
@@ -161,31 +161,6 @@ public:
typedef
std
::
shared_ptr
<
RtpCodec
>
Ptr
;
RtpCodec
(){}
virtual
~
RtpCodec
(){}
/**
* 根据CodecId生成Rtp打包器
* @param codecId
* @param ui32Ssrc
* @param ui32MtuSize
* @param ui32SampleRate
* @param ui8PlayloadType
* @param ui8Interleaved
* @return
*/
static
Ptr
getRtpEncoderById
(
CodecId
codecId
,
uint32_t
ui32Ssrc
,
uint32_t
ui32MtuSize
,
uint32_t
ui32SampleRate
,
uint8_t
ui8PlayloadType
,
uint8_t
ui8Interleaved
);
/**
* 根据CodecId生成Rtp解包器
* @param codecId
* @param ui32SampleRate
* @return
*/
static
Ptr
getRtpDecoderById
(
CodecId
codecId
,
uint32_t
ui32SampleRate
);
};
...
...
src/Rtsp/RtpParser.cpp
查看文件 @
92ea9567
...
...
@@ -29,6 +29,7 @@
#include "RtpParser.h"
#include "Util/base64.h"
#include "H264/SPSParser.h"
#include "Common/Factory.h"
using
namespace
std
;
...
...
@@ -97,10 +98,10 @@ inline bool RtpParser::inputAudio(const RtpPacket::Ptr &rtp) {
inline
void
RtpParser
::
onGetAudioTrack
(
const
RtspTrack
&
audio
)
{
//生成Track对象
_audioTrack
=
dynamic_pointer_cast
<
AudioTrack
>
(
Track
::
getTrackBySdp
(
audio
.
trackSdp
));
_audioTrack
=
dynamic_pointer_cast
<
AudioTrack
>
(
Factory
::
getTrackBySdp
(
audio
.
trackSdp
));
if
(
_audioTrack
){
//生成RtpCodec对象以便解码rtp
_audioRtpDecoder
=
RtpCodec
::
getRtpDecoderById
(
_audioTrack
->
getCodecId
(),
_audioTrack
->
getAudioSampleRate
());
_audioRtpDecoder
=
Factory
::
getRtpDecoderById
(
_audioTrack
->
getCodecId
(),
_audioTrack
->
getAudioSampleRate
());
if
(
_audioRtpDecoder
){
//设置rtp解码器代理,生成的frame写入该Track
_audioRtpDecoder
->
setDelegate
(
_audioTrack
);
...
...
@@ -110,10 +111,10 @@ inline void RtpParser::onGetAudioTrack(const RtspTrack& audio) {
inline
void
RtpParser
::
onGetVideoTrack
(
const
RtspTrack
&
video
)
{
//生成Track对象
_videoTrack
=
dynamic_pointer_cast
<
VideoTrack
>
(
Track
::
getTrackBySdp
(
video
.
trackSdp
));
_videoTrack
=
dynamic_pointer_cast
<
VideoTrack
>
(
Factory
::
getTrackBySdp
(
video
.
trackSdp
));
if
(
_videoTrack
){
//生成RtpCodec对象以便解码rtp
_videoRtpDecoder
=
RtpCodec
::
getRtpDecoderById
(
_videoTrack
->
getCodecId
(),
90000
);
_videoRtpDecoder
=
Factory
::
getRtpDecoderById
(
_videoTrack
->
getCodecId
(),
90000
);
if
(
_videoRtpDecoder
){
//设置rtp解码器代理,生成的frame写入该Track
_videoRtpDecoder
->
setDelegate
(
_videoTrack
);
...
...
src/Rtsp/RtspSdp.cpp
查看文件 @
92ea9567
//
// Created by xzl on 2018/10/23.
//
#include "RtspSdp.h"
namespace
ZL
{
namespace
Rtsp
{
Sdp
::
Ptr
Sdp
::
getSdpByTrack
(
const
Track
::
Ptr
&
track
)
{
switch
(
track
->
getCodecId
()){
case
CodecH264
:{
H264Track
::
Ptr
h264Track
=
dynamic_pointer_cast
<
H264Track
>
(
track
);
if
(
!
h264Track
){
return
nullptr
;
}
return
std
::
make_shared
<
H264Sdp
>
(
h264Track
->
getSps
(),
h264Track
->
getPps
());
}
#
include
"RtspSdp.h"
#include "Common/Factory.h"
void
Sdp
::
createRtpEncoder
(
uint32_t
ssrc
,
int
mtu
)
{
_encoder
=
Factory
::
getRtpEncoderById
(
getCodecId
(),
ssrc
,
mtu
,
_sample_rate
,
_playload_type
,
getTrackType
()
*
2
);
}
case
CodecAAC
:{
AACTrack
::
Ptr
aacTrack
=
dynamic_pointer_cast
<
AACTrack
>
(
track
);
if
(
!
aacTrack
){
return
nullptr
;
}
return
std
::
make_shared
<
AACSdp
>
(
aacTrack
->
getAacCfg
(),
aacTrack
->
getAudioSampleRate
());
void
RtspMaker
::
addTrack
(
const
Track
::
Ptr
&
track
,
uint32_t
ssrc
,
int
mtu
)
{
if
(
track
->
getCodecId
()
==
CodecInvalid
)
{
addTrack
(
std
::
make_shared
<
TitleSdp
>
(),
ssrc
,
mtu
);
}
else
{
Sdp
::
Ptr
sdp
=
Factory
::
getSdpByTrack
(
track
);
if
(
sdp
)
{
addTrack
(
sdp
,
ssrc
,
mtu
);
}
default
:
return
nullptr
;
}
}
}
}
src/Rtsp/RtspSdp.h
查看文件 @
92ea9567
...
...
@@ -30,13 +30,6 @@ public:
_playload_type
=
playload_type
;
}
/**
* 根据Track生成SDP对象
* @param track 媒体信息
* @return 返回sdp对象
*/
static
Ptr
getSdpByTrack
(
const
Track
::
Ptr
&
track
);
virtual
~
Sdp
(){}
/**
...
...
@@ -115,14 +108,7 @@ public:
* @param ssrc 打包器ssrc,可以为0
* @param mtu mtu大小,一般小于1500字节,推荐1400
*/
virtual
void
createRtpEncoder
(
uint32_t
ssrc
,
int
mtu
)
{
_encoder
=
RtpCodec
::
getRtpEncoderById
(
getCodecId
(),
ssrc
,
mtu
,
_sample_rate
,
_playload_type
,
getTrackType
()
*
2
);
}
virtual
void
createRtpEncoder
(
uint32_t
ssrc
,
int
mtu
);
private
:
RtpCodec
::
Ptr
_encoder
;
uint8_t
_playload_type
;
...
...
@@ -311,16 +297,7 @@ public:
* @param ssrc 媒体rtp ssrc
* @param mtu 媒体rtp mtu
*/
void
addTrack
(
const
Track
::
Ptr
&
track
,
uint32_t
ssrc
=
0
,
int
mtu
=
1400
)
{
if
(
track
->
getCodecId
()
==
CodecInvalid
){
addTrack
(
std
::
make_shared
<
TitleSdp
>
(),
ssrc
,
mtu
);
}
else
{
Sdp
::
Ptr
sdp
=
Sdp
::
getSdpByTrack
(
track
);
if
(
sdp
){
addTrack
(
sdp
,
ssrc
,
mtu
);
}
}
}
void
addTrack
(
const
Track
::
Ptr
&
track
,
uint32_t
ssrc
=
0
,
int
mtu
=
1400
)
;
/**
* 获取完整的SDP字符串
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论