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
23c2de9a
Commit
23c2de9a
authored
Sep 19, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初步完成一些类的抽象
parent
fab283da
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
218 行增加
和
33 行删除
+218
-33
src/Player/PlayerBase.h
+102
-5
src/Rtsp/Rtsp.h
+3
-2
src/Rtsp/RtspMaker.h
+113
-26
没有找到文件。
src/Player/PlayerBase.h
查看文件 @
23c2de9a
...
...
@@ -35,6 +35,7 @@
#include "Network/Socket.h"
#include "Util/mini.h"
#include "Common/MediaSource.h"
#include "Util/RingBuffer.h"
using
namespace
std
;
using
namespace
ZL
::
Util
;
...
...
@@ -44,6 +45,100 @@ using namespace ZL::Network;
namespace
ZL
{
namespace
Player
{
class
TrackFrame
:
public
Buffer
{
public
:
typedef
std
::
shared_ptr
<
TrackFrame
>
Ptr
;
virtual
~
TrackFrame
(){}
virtual
uint32_t
stamp
()
=
0
;
};
class
TrackFormat
{
public
:
typedef
std
::
shared_ptr
<
TrackFormat
>
Ptr
;
typedef
RingBuffer
<
TrackFrame
::
Ptr
>
RingType
;
typedef
RingType
::
RingReader
::
Ptr
ReaderType
;
typedef
enum
{
VideoCodecInvalid
=
-
1
,
VideoCodecH264
=
0
,
VideoCodecMax
}
VideoCodecID
;
typedef
enum
{
AudioCodecInvalid
=
-
1
,
AudioCodecAAC
=
0
,
AudioCodecMax
}
AudioCodecID
;
TrackFormat
(){
_ring
=
std
::
make_shared
<
RingType
>
();
}
virtual
~
TrackFormat
(){}
virtual
TrackType
getTrackType
()
const
=
0
;
virtual
int
getCodecId
()
const
=
0
;
ReaderType
attachReader
(
bool
useBuffer
=
false
){
return
_ring
->
attach
(
useBuffer
);
}
void
writeFrame
(
const
TrackFrame
::
Ptr
&
frame
,
bool
keypos
=
true
){
_ring
->
write
(
frame
,
keypos
);
}
private
:
RingType
::
Ptr
_ring
;
};
class
VideoTrackFormat
:
public
TrackFormat
{
public
:
TrackType
getTrackType
()
const
override
{
return
TrackVideo
;};
virtual
int
getVideoHeight
()
const
=
0
;
virtual
int
getVideoWidth
()
const
=
0
;
virtual
float
getVideoFps
()
const
=
0
;
};
class
AudioTrackFormat
:
public
TrackFormat
{
public
:
TrackType
getTrackType
()
const
override
{
return
TrackAudio
;};
virtual
int
getAudioSampleRate
()
const
=
0
;
virtual
int
getAudioSampleBit
()
const
=
0
;
virtual
int
getAudioChannel
()
const
=
0
;
};
class
H264TrackFormat
:
public
VideoTrackFormat
{
public
:
H264TrackFormat
(
const
string
&
sps
,
const
string
&
pps
){
_sps
=
sps
;
_pps
=
pps
;
}
const
string
&
getSps
()
const
{
return
_sps
;
}
const
string
&
getPps
()
const
{
return
_pps
;
}
int
getCodecId
()
const
override
{
return
TrackFormat
::
VideoCodecH264
;
}
private
:
string
_sps
;
string
_pps
;
};
class
AACTrackFormat
:
public
AudioTrackFormat
{
public
:
AACTrackFormat
(
const
string
&
aac_cfg
){
_cfg
=
aac_cfg
;
}
const
string
&
getAacCfg
()
const
{
return
_cfg
;
}
int
getCodecId
()
const
override
{
return
TrackFormat
::
AudioCodecAAC
;
}
private
:
string
_cfg
;
};
class
MediaFormat
{
public
:
virtual
~
MediaFormat
(){};
...
...
@@ -58,11 +153,6 @@ public:
virtual
const
string
&
getPps
()
const
{
static
string
null
;
return
null
;
};
virtual
const
string
&
getSps
()
const
{
static
string
null
;
return
null
;
};
virtual
const
string
&
getAudioCfg
()
const
{
static
string
null
;
return
null
;
};
virtual
bool
containAudio
()
const
{
return
false
;
};
virtual
bool
containVideo
()
const
{
return
false
;
};
virtual
float
getDuration
()
const
{
return
0
;};
};
class
PlayerBase
:
public
MediaFormat
,
public
mINI
{
...
...
@@ -105,6 +195,13 @@ public:
virtual
bool
isInited
()
const
{
return
true
;
};
//TrackVideo = 0, TrackAudio = 1
virtual
float
getRtpLossRate
(
int
trackType
)
const
{
return
0
;
};
virtual
float
getDuration
()
const
{
return
0
;};
virtual
bool
containAudio
()
const
{
return
false
;
};
virtual
bool
containVideo
()
const
{
return
false
;
};
virtual
int
getTrackCount
()
const
{
return
0
;};
virtual
TrackFormat
::
Ptr
getTrack
(
int
index
)
const
{
return
nullptr
;};
protected
:
virtual
void
onShutdown
(
const
SockException
&
ex
)
{};
virtual
void
onPlayResult
(
const
SockException
&
ex
)
{};
...
...
src/Rtsp/Rtsp.h
查看文件 @
23c2de9a
...
...
@@ -37,9 +37,10 @@ using namespace std;
using
namespace
ZL
::
Util
;
typedef
enum
{
TrackInvalid
=
-
1
,
TrackVideo
=
0
,
TrackAudio
TrackAudio
,
TrackInvalid
,
TrackMax
}
TrackType
;
class
RtspTrack
{
...
...
src/Rtsp/RtspMaker.h
查看文件 @
23c2de9a
...
...
@@ -18,17 +18,47 @@ using namespace ZL::Rtsp;
namespace
ZL
{
namespace
Rtsp
{
/**
* sdp基类
*/
class
Sdp
{
public
:
typedef
std
::
shared_ptr
<
Sdp
>
Ptr
;
virtual
~
Sdp
(){}
virtual
string
getSdp
()
{
return
""
;};
virtual
TrackType
getTrackType
()
{
return
TrackInvalid
;};
virtual
RtpMaker
::
Ptr
createRtpMaker
(
const
RtpMaker
::
onGetRTP
&
cb
,
uint32_t
ui32Ssrc
,
int
iMtuSize
)
{
return
nullptr
;};
/**
* 获取sdp字符串
* @return
*/
virtual
string
getSdp
()
const
{
return
""
;};
/**
* 获取track类型
* @return
*/
virtual
TrackType
getTrackType
()
const
{
return
TrackInvalid
;};
/**
* 获取rtp生成器
* @param cb 回调lambad
* @param ui32Ssrc rtp ssrc
* @param iMtuSize rtp mtu
* @return
*/
virtual
RtpMaker
::
Ptr
createRtpMaker
(
const
RtpMaker
::
onGetRTP
&
cb
,
uint32_t
ui32Ssrc
,
int
iMtuSize
)
const
{
return
nullptr
;};
};
/**
* sdp中除音视频外的其他描述部分
*/
class
SdpTitle
:
public
Sdp
{
public
:
/**
* 构造title类型sdp
* @param dur_sec rtsp点播时长,0代表直播,单位秒
* @param header 自定义sdp描述
* @param version sdp版本
*/
SdpTitle
(
float
dur_sec
=
0
,
const
map
<
string
,
string
>
&
header
=
map
<
string
,
string
>
(),
int
version
=
0
){
...
...
@@ -53,7 +83,7 @@ public:
}
_printer
<<
"a=control:*
\r\n
"
;
}
string
getSdp
()
override
{
string
getSdp
()
const
override
{
return
_printer
;
}
...
...
@@ -61,8 +91,21 @@ private:
_StrPrinter
_printer
;
};
/**
* h264类型sdp
*/
class
SdpH264
:
public
Sdp
{
public
:
/**
*
* @param sps 264 sps,带0x00000001头
* @param pps 264 pps,带0x00000001头
* @param sample_rate 时间戳采样率,视频默认90000
* @param playload_type rtp playload type 默认96
* @param track_id trackID 默认为TrackVideo
* @param bitrate 比特率
*/
SdpH264
(
const
string
&
sps
,
const
string
&
pps
,
int
sample_rate
=
90000
,
...
...
@@ -100,15 +143,15 @@ public:
_printer
<<
"a=control:trackID="
<<
track_id
<<
"
\r\n
"
;
}
string
getSdp
()
override
{
string
getSdp
()
const
override
{
return
_printer
;
}
TrackType
getTrackType
()
override
{
TrackType
getTrackType
()
const
override
{
return
TrackVideo
;
};
RtpMaker
::
Ptr
createRtpMaker
(
const
RtpMaker
::
onGetRTP
&
cb
,
uint32_t
ui32Ssrc
,
int
iMtuSize
)
override
{
RtpMaker
::
Ptr
createRtpMaker
(
const
RtpMaker
::
onGetRTP
&
cb
,
uint32_t
ui32Ssrc
,
int
iMtuSize
)
const
override
{
return
std
::
make_shared
<
RtpMaker_H264
>
(
cb
,
ui32Ssrc
,
iMtuSize
,
_sample_rate
,
_playload_type
,
_track_id
*
2
);
};
...
...
@@ -121,8 +164,20 @@ private:
};
/**
* aac类型SDP
*/
class
SdpAAC
:
public
Sdp
{
public
:
/**
* 构造aac sdp
* @param aac_cfg aac两个字节的配置描述
* @param sample_rate 音频采样率
* @param playload_type rtp playload type 默认96
* @param track_id trackID 默认为TrackVideo
* @param bitrate 比特率
*/
SdpAAC
(
const
string
&
aac_cfg
,
int
sample_rate
,
int
playload_type
=
98
,
...
...
@@ -145,15 +200,15 @@ public:
_printer
<<
"a=control:trackID="
<<
track_id
<<
"
\r\n
"
;
}
string
getSdp
()
override
{
string
getSdp
()
const
override
{
return
_printer
;
}
TrackType
getTrackType
()
override
{
TrackType
getTrackType
()
const
override
{
return
TrackAudio
;
};
RtpMaker
::
Ptr
createRtpMaker
(
const
RtpMaker
::
onGetRTP
&
cb
,
uint32_t
ui32Ssrc
,
int
iMtuSize
)
override
{
RtpMaker
::
Ptr
createRtpMaker
(
const
RtpMaker
::
onGetRTP
&
cb
,
uint32_t
ui32Ssrc
,
int
iMtuSize
)
const
override
{
return
std
::
make_shared
<
RtpMaker_AAC
>
(
cb
,
ui32Ssrc
,
iMtuSize
,
_sample_rate
,
_playload_type
,
_track_id
*
2
);
};
private
:
...
...
@@ -163,34 +218,67 @@ private:
int
_track_id
;
};
/**
* rtsp生成器
*/
class
RtspMaker
{
public
:
RtspMaker
(
const
RtpMaker
::
onGetRTP
&
callback
)
:
_vec_rtp_maker
(
8
){
/**
* 构成函数
* @param callback rtp回调lambad
*/
RtspMaker
(
const
RtpMaker
::
onGetRTP
&
callback
)
:
_vec_rtp_maker
(
TrackMax
){
_callback
=
callback
;
}
template
<
typename
First
,
typename
...
Others
>
void
addTrack
(
First
&&
first
,
Others
&&
...
others
){
addTrack
(
std
::
forward
<
First
>
(
first
));
addTrack
(
std
::
forward
<
Others
>
(
others
)...);
}
template
<
typename
First
>
void
addTrack
(
First
&&
first
){
_printer
<<
first
->
getSdp
();
if
(
first
->
getTrackType
()
>=
0
){
auto
rtpMaker
=
first
->
createRtpMaker
(
_callback
,
0
,
1400
);
_vec_rtp_maker
[
first
->
getTrackType
()]
=
rtpMaker
;
/**
* 添加音视频track
* @param sdp 媒体描述
* @param ssrc 媒体rtp ssrc
* @param mtu 媒体rtp mtu
* @return 成功与否
*/
bool
addTrack
(
const
Sdp
&
sdp
,
uint32_t
ssrc
=
0
,
int
mtu
=
1400
){
auto
type
=
sdp
.
getTrackType
();
if
(
type
<
0
||
type
>=
_vec_rtp_maker
.
size
()){
return
false
;
}
if
(
_vec_rtp_maker
[
type
]){
return
false
;
}
if
(
ssrc
==
0
){
ssrc
=
((
uint64_t
)
&
sdp
)
&
0xFFFFFFFF
;
}
auto
rtpMaker
=
sdp
.
createRtpMaker
(
_callback
,
ssrc
,
mtu
);
_vec_rtp_maker
[
sdp
.
getTrackType
()]
=
rtpMaker
;
_printer
<<
sdp
.
getSdp
();
return
true
;
}
virtual
~
RtspMaker
()
{};
/**
* 获取完整的SDP字符串
* @return SDP字符串
*/
string
getSdp
()
{
return
_printer
;
}
/**
* 打包RTP数据包
* @param type 媒体类型
* @param pcData 媒体数据
* @param iDataLen 媒体数据长度
* @param uiStamp 媒体时间戳,单位毫秒
* @return 是否成功
*/
bool
makeRtp
(
TrackType
type
,
const
char
*
pcData
,
int
iDataLen
,
uint32_t
uiStamp
){
if
(
type
<
0
||
type
>
_vec_rtp_maker
.
size
()){
if
(
type
<
0
||
type
>
=
_vec_rtp_maker
.
size
()){
return
false
;
}
auto
track
=
_vec_rtp_maker
[
type
];
...
...
@@ -205,7 +293,6 @@ private:
vector
<
RtpMaker
::
Ptr
>
_vec_rtp_maker
;
_StrPrinter
_printer
;
RtpMaker
::
onGetRTP
_callback
;
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论