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
c1e91620
Commit
c1e91620
authored
Oct 23, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
大规模修改rtsp相关代码
parent
393f123e
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
25 个修改的文件
包含
466 行增加
和
217 行删除
+466
-217
src/Device/Device.cpp
+1
-1
src/Device/Device.h
+2
-1
src/Device/PlayerProxy.cpp
+1
-1
src/MediaFile/MediaReader.h
+1
-1
src/Player/Frame.h
+126
-4
src/Player/Player.cpp
+3
-3
src/Player/Player.h
+3
-3
src/Player/PlayerBase.h
+3
-3
src/Player/Track.h
+6
-30
src/RTP/AACRtpCodec.cpp
+11
-11
src/RTP/AACRtpCodec.h
+23
-6
src/RTP/H264RtpCodec.cpp
+8
-8
src/RTP/H264RtpCodec.h
+18
-2
src/RTP/RtpCodec.cpp
+13
-0
src/RTP/RtpCodec.h
+63
-18
src/Rtmp/RtmpParser.h
+3
-3
src/Rtmp/RtmpToRtspMediaSource.cpp
+1
-1
src/Rtmp/RtmpToRtspMediaSource.h
+1
-1
src/Rtsp/RtpParser.cpp
+2
-2
src/Rtsp/RtpParser.h
+5
-4
src/Rtsp/Rtsp.h
+2
-22
src/Rtsp/RtspEncoder.h
+167
-90
src/Rtsp/RtspMediaSource.h
+1
-0
src/Rtsp/RtspToRtmpMediaSource.cpp
+1
-1
src/Rtsp/RtspToRtmpMediaSource.h
+1
-1
没有找到文件。
src/Device/Device.cpp
查看文件 @
c1e91620
...
...
@@ -278,7 +278,7 @@ void DevChannel::initVideo(const VideoInfo& info) {
void
DevChannel
::
initAudio
(
const
AudioInfo
&
info
)
{
m_audio
.
reset
(
new
AudioInfo
(
info
));
m_pAdtsHeader
=
std
::
make_shared
<
A
dts
Frame
>
();
m_pAdtsHeader
=
std
::
make_shared
<
A
AC
Frame
>
();
m_pAdtsHeader
->
syncword
=
0x0FFF
;
m_pAdtsHeader
->
id
=
0
;
...
...
src/Device/Device.h
查看文件 @
c1e91620
...
...
@@ -35,6 +35,7 @@
#include "RTP/RtpMakerAAC.h"
#include "RTP/RtpMakerH264.h"
#include "Rtsp/RtspToRtmpMediaSource.h"
#include "Rtsp/RtspEncoder.h"
#include "Util/TimeTicker.h"
using
namespace
std
;
...
...
@@ -119,7 +120,7 @@ private:
std
::
shared_ptr
<
VideoInfo
>
m_video
;
std
::
shared_ptr
<
AudioInfo
>
m_audio
;
SmoothTicker
m_aTicker
[
2
];
std
::
shared_ptr
<
A
dts
Frame
>
m_pAdtsHeader
;
std
::
shared_ptr
<
A
AC
Frame
>
m_pAdtsHeader
;
};
...
...
src/Device/PlayerProxy.cpp
查看文件 @
c1e91620
...
...
@@ -97,7 +97,7 @@ void PlayerProxy::play(const char* strUrl) {
strongSelf
->
initMedia
();
}
});
setOnAudioCB
(
[
weakSelf
](
const
A
dts
Frame
&
data
)
{
setOnAudioCB
(
[
weakSelf
](
const
A
AC
Frame
&
data
)
{
auto
strongSelf
=
weakSelf
.
lock
();
if
(
!
strongSelf
){
return
;
...
...
src/MediaFile/MediaReader.h
查看文件 @
c1e91620
...
...
@@ -74,7 +74,7 @@ private:
uint32_t
m_audio_sample_rate
=
0
;
uint32_t
m_audio_num_channels
=
0
;
string
m_strAacCfg
;
A
dts
Frame
m_adts
;
A
AC
Frame
m_adts
;
int
m_iDuration
=
0
;
DevChannel
::
Ptr
m_pChn
;
...
...
src/Player/Frame.h
查看文件 @
c1e91620
...
...
@@ -5,11 +5,43 @@
#ifndef ZLMEDIAKIT_FRAME_H
#define ZLMEDIAKIT_FRAME_H
#include "Util/RingBuffer.h"
#include "Network/Socket.h"
using
namespace
ZL
::
Util
;
using
namespace
ZL
::
Network
;
class
Frame
:
public
Buffer
{
typedef
enum
{
CodecInvalid
=
-
1
,
CodecH264
=
0
,
CodecAAC
=
0x0100
,
CodecMax
}
CodecId
;
typedef
enum
{
TrackInvalid
=
-
1
,
TrackVideo
=
0
,
TrackAudio
,
TrackMax
}
TrackType
;
class
CodecInfo
{
public
:
CodecInfo
(){}
virtual
~
CodecInfo
(){}
/**
* 获取音视频类型
*/
virtual
TrackType
getTrackType
()
const
=
0
;
/**
* 获取编解码器类型
*/
virtual
CodecId
getCodecId
()
const
=
0
;
};
class
Frame
:
public
Buffer
,
public
CodecInfo
{
public
:
typedef
std
::
shared_ptr
<
Frame
>
Ptr
;
virtual
~
Frame
(){}
...
...
@@ -25,6 +57,78 @@ public:
virtual
uint32_t
prefixSize
()
=
0
;
};
/**
* 帧环形缓存接口类
*/
class
FrameRingInterface
{
public
:
typedef
RingBuffer
<
Frame
::
Ptr
>
RingType
;
FrameRingInterface
(){}
virtual
~
FrameRingInterface
(){}
/**
* 获取帧环形缓存
* @return
*/
virtual
RingType
::
Ptr
getFrameRing
()
const
=
0
;
/**
* 设置帧环形缓存
* @param ring
*/
virtual
void
setFrameRing
(
const
RingType
::
Ptr
&
ring
)
=
0
;
/**
* 写入帧数据
* @param frame 帧
* @param key_pos 是否为关键帧
*/
virtual
void
inputFrame
(
const
Frame
::
Ptr
&
frame
,
bool
key_pos
)
=
0
;
};
class
FrameRing
:
public
FrameRingInterface
{
public
:
typedef
std
::
shared_ptr
<
FrameRing
>
Ptr
;
FrameRing
(){
//禁用缓存
_frameRing
=
std
::
make_shared
<
RingType
>
(
1
);
}
virtual
~
FrameRing
(){}
/**
* 获取帧环形缓存
* @return
*/
RingType
::
Ptr
getFrameRing
()
const
override
{
return
_frameRing
;
}
/**
* 设置帧环形缓存
* @param ring
*/
void
setFrameRing
(
const
RingType
::
Ptr
&
ring
)
override
{
_frameRing
=
ring
;
}
/**
* 输入数据帧
* @param frame
* @param key_pos
*/
void
inputFrame
(
const
Frame
::
Ptr
&
frame
,
bool
key_pos
)
override
{
_frameRing
->
write
(
frame
,
key_pos
);
}
protected
:
RingType
::
Ptr
_frameRing
;
};
/**
* 264帧类
*/
class
H264Frame
:
public
Frame
{
public
:
typedef
std
::
shared_ptr
<
H264Frame
>
Ptr
;
...
...
@@ -41,6 +145,14 @@ public:
uint32_t
prefixSize
()
override
{
return
iPrefixSize
;
}
TrackType
getTrackType
()
const
override
{
return
TrackVideo
;
}
CodecId
getCodecId
()
const
override
{
return
CodecH264
;
}
public
:
uint16_t
sequence
;
uint32_t
timeStamp
;
...
...
@@ -49,10 +161,12 @@ public:
uint32_t
iPrefixSize
=
4
;
};
//ADTS 头中相对有用的信息 采样率、声道数、帧长度
class
AdtsFrame
:
public
Frame
{
/**
* aac帧,包含adts头
*/
class
AACFrame
:
public
Frame
{
public
:
typedef
std
::
shared_ptr
<
A
dts
Frame
>
Ptr
;
typedef
std
::
shared_ptr
<
A
AC
Frame
>
Ptr
;
char
*
data
()
const
override
{
return
(
char
*
)
buffer
;
...
...
@@ -66,6 +180,14 @@ public:
uint32_t
prefixSize
()
override
{
return
iPrefixSize
;
}
TrackType
getTrackType
()
const
override
{
return
TrackAudio
;
}
CodecId
getCodecId
()
const
override
{
return
CodecAAC
;
}
public
:
unsigned
int
syncword
;
//12 bslbf 同步字The bit string ‘1111 1111 1111’,说明一个ADTS帧的开始
unsigned
int
id
;
//1 bslbf MPEG 标示符, 设置为1
...
...
src/Player/Player.cpp
查看文件 @
c1e91620
...
...
@@ -32,7 +32,7 @@
using
namespace
ZL
::
Util
;
void
writeAdtsHeader
(
const
A
dts
Frame
&
hed
,
uint8_t
*
pcAdts
)
{
void
writeAdtsHeader
(
const
A
AC
Frame
&
hed
,
uint8_t
*
pcAdts
)
{
pcAdts
[
0
]
=
(
hed
.
syncword
>>
4
&
0xFF
);
//8bit
pcAdts
[
1
]
=
(
hed
.
syncword
<<
4
&
0xF0
);
//4 bit
pcAdts
[
1
]
|=
(
hed
.
id
<<
3
&
0x08
);
//1 bit
...
...
@@ -85,7 +85,7 @@ string makeAdtsConfig(const uint8_t *pcAdts){
audioSpecificConfig
[
1
]
=
(
sampling_frequency_index
<<
7
)
|
(
channel_configuration
<<
3
);
return
string
((
char
*
)
audioSpecificConfig
,
2
);
}
void
makeAdtsHeader
(
const
string
&
strAudioCfg
,
A
dts
Frame
&
adts
)
{
void
makeAdtsHeader
(
const
string
&
strAudioCfg
,
A
AC
Frame
&
adts
)
{
uint8_t
cfg1
=
strAudioCfg
[
0
];
uint8_t
cfg2
=
strAudioCfg
[
1
];
...
...
@@ -113,7 +113,7 @@ void makeAdtsHeader(const string &strAudioCfg,AdtsFrame &adts) {
adts
.
adts_buffer_fullness
=
2047
;
adts
.
no_raw_data_blocks_in_frame
=
0
;
}
void
getAACInfo
(
const
A
dts
Frame
&
adts
,
int
&
iSampleRate
,
int
&
iChannel
){
void
getAACInfo
(
const
A
AC
Frame
&
adts
,
int
&
iSampleRate
,
int
&
iChannel
){
iSampleRate
=
samplingFrequencyTable
[
adts
.
sf_index
];
iChannel
=
adts
.
channel_configuration
;
}
...
...
src/Player/Player.h
查看文件 @
c1e91620
...
...
@@ -40,10 +40,10 @@ unsigned const samplingFrequencyTable[16] = { 96000, 88200,
11025
,
8000
,
7350
,
0
,
0
,
0
};
void
makeAdtsHeader
(
const
string
&
strAudioCfg
,
A
dts
Frame
&
adts
);
void
writeAdtsHeader
(
const
A
dts
Frame
&
adts
,
uint8_t
*
pcAdts
)
;
void
makeAdtsHeader
(
const
string
&
strAudioCfg
,
A
AC
Frame
&
adts
);
void
writeAdtsHeader
(
const
A
AC
Frame
&
adts
,
uint8_t
*
pcAdts
)
;
string
makeAdtsConfig
(
const
uint8_t
*
pcAdts
);
void
getAACInfo
(
const
A
dts
Frame
&
adts
,
int
&
iSampleRate
,
int
&
iChannel
);
void
getAACInfo
(
const
A
AC
Frame
&
adts
,
int
&
iSampleRate
,
int
&
iChannel
);
bool
getAVCInfo
(
const
string
&
strSps
,
int
&
iVideoWidth
,
int
&
iVideoHeight
,
float
&
iVideoFps
);
#endif
/* SRC_PLAYER_PLAYER_H_ */
src/Player/PlayerBase.h
查看文件 @
c1e91620
...
...
@@ -94,7 +94,7 @@ public:
virtual
void
setOnShutdown
(
const
function
<
void
(
const
SockException
&
)
>
&
cb
)
{};
virtual
void
setOnPlayResult
(
const
function
<
void
(
const
SockException
&
ex
)
>
&
cb
)
{};
virtual
void
setOnVideoCB
(
const
function
<
void
(
const
H264Frame
&
frame
)
>
&
cb
)
{};
virtual
void
setOnAudioCB
(
const
function
<
void
(
const
A
dts
Frame
&
frame
)
>
&
cb
)
{};
virtual
void
setOnAudioCB
(
const
function
<
void
(
const
A
AC
Frame
&
frame
)
>
&
cb
)
{};
virtual
float
getProgress
()
const
{
return
0
;};
virtual
void
seekTo
(
float
fProgress
)
{};
...
...
@@ -140,7 +140,7 @@ public:
}
m_onGetVideoCB
=
cb
;
}
void
setOnAudioCB
(
const
function
<
void
(
const
A
dts
Frame
&
frame
)
>
&
cb
)
override
{
void
setOnAudioCB
(
const
function
<
void
(
const
A
AC
Frame
&
frame
)
>
&
cb
)
override
{
if
(
m_parser
)
{
m_parser
->
setOnAudioCB
(
cb
);
}
...
...
@@ -269,7 +269,7 @@ protected:
function
<
void
(
const
SockException
&
ex
)
>
m_playResultCB
;
std
::
shared_ptr
<
Parser
>
m_parser
;
function
<
void
(
const
H264Frame
&
frame
)
>
m_onGetVideoCB
;
function
<
void
(
const
A
dts
Frame
&
frame
)
>
m_onGetAudioCB
;
function
<
void
(
const
A
AC
Frame
&
frame
)
>
m_onGetAudioCB
;
MediaSource
::
Ptr
m_pMediaSrc
;
};
...
...
src/Player/Track.h
查看文件 @
c1e91620
...
...
@@ -14,35 +14,11 @@
using
namespace
std
;
using
namespace
ZL
::
Util
;
class
TrackFormat
{
class
TrackFormat
:
public
FrameRingInterface
,
public
CodecInfo
{
public
:
typedef
std
::
shared_ptr
<
TrackFormat
>
Ptr
;
typedef
RingBuffer
<
Frame
::
Ptr
>
RingType
;
typedef
enum
{
CodecInvalid
=
-
1
,
CodecH264
=
0
,
CodecAAC
=
0x0100
,
CodecMax
}
CodecID
;
TrackFormat
(){
_ring
=
std
::
make_shared
<
RingType
>
();
}
TrackFormat
(){}
virtual
~
TrackFormat
(){}
virtual
TrackType
getTrackType
()
const
=
0
;
virtual
int
getCodecId
()
const
=
0
;
void
writeFrame
(
const
Frame
::
Ptr
&
frame
,
bool
keypos
=
true
){
_ring
->
write
(
frame
,
keypos
);
}
RingType
::
Ptr
&
getRing
()
{
return
_ring
;
}
private
:
RingType
::
Ptr
_ring
;
};
class
VideoTrackFormat
:
public
TrackFormat
{
...
...
@@ -73,8 +49,8 @@ public:
const
string
&
getPps
()
const
{
return
_pps
;
}
int
getCodecId
()
const
override
{
return
TrackFormat
::
CodecH264
;
CodecId
getCodecId
()
const
override
{
return
CodecH264
;
}
private
:
string
_sps
;
...
...
@@ -89,8 +65,8 @@ public:
const
string
&
getAacCfg
()
const
{
return
_cfg
;
}
int
getCodecId
()
const
override
{
return
TrackFormat
::
CodecAAC
;
CodecId
getCodecId
()
const
override
{
return
CodecAAC
;
}
private
:
string
_cfg
;
...
...
src/RTP/AACRtpCodec.cpp
查看文件 @
c1e91620
...
...
@@ -9,16 +9,16 @@ AACRtpEncoder::AACRtpEncoder(uint32_t ui32Ssrc,
uint32_t
ui32SampleRate
,
uint8_t
ui8PlayloadType
,
uint8_t
ui8Interleaved
)
:
Rtp
Info
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
)
{
Rtp
Encoder
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
)
{
}
void
AACRtpEncoder
::
inputFame
(
const
Frame
::
Ptr
&
frame
,
bool
key_pos
)
{
RtpCodec
::
inputFame
(
frame
,
false
);
void
AACRtpEncoder
::
inputF
r
ame
(
const
Frame
::
Ptr
&
frame
,
bool
key_pos
)
{
RtpCodec
::
inputF
r
ame
(
frame
,
false
);
GET_CONFIG_AND_REGISTER
(
uint32_t
,
cycleMS
,
Config
::
Rtp
::
kCycleMS
);
auto
uiStamp
=
frame
->
stamp
();
...
...
@@ -92,7 +92,7 @@ AACRtpDecoder::AACRtpDecoder(uint32_t ui32SampleRate) {
m_sampleRate
=
ui32SampleRate
;
}
A
dts
Frame
::
Ptr
AACRtpDecoder
::
obtainFrame
()
{
A
AC
Frame
::
Ptr
AACRtpDecoder
::
obtainFrame
()
{
//从缓存池重新申请对象,防止覆盖已经写入环形缓存的对象
auto
frame
=
m_framePool
.
obtain
();
frame
->
aac_frame_length
=
7
;
...
...
@@ -104,7 +104,7 @@ void AACRtpDecoder::inputRtp(const RtpPacket::Ptr &rtppack, bool key_pos) {
RtpCodec
::
inputRtp
(
rtppack
,
false
);
int
length
=
rtppack
->
length
-
rtppack
->
offset
;
if
(
m_adts
->
aac_frame_length
+
length
-
4
>
sizeof
(
A
dts
Frame
::
buffer
))
{
if
(
m_adts
->
aac_frame_length
+
length
-
4
>
sizeof
(
A
AC
Frame
::
buffer
))
{
m_adts
->
aac_frame_length
=
7
;
WarnL
<<
"aac负载数据太长"
;
return
;
...
...
@@ -120,9 +120,9 @@ void AACRtpDecoder::inputRtp(const RtpPacket::Ptr &rtppack, bool key_pos) {
}
}
void
AACRtpDecoder
::
onGetAdts
(
const
A
dts
Frame
::
Ptr
&
frame
)
{
void
AACRtpDecoder
::
onGetAdts
(
const
A
AC
Frame
::
Ptr
&
frame
)
{
//写入环形缓存
RtpCodec
::
inputFame
(
frame
,
false
);
RtpCodec
::
inputF
r
ame
(
frame
,
false
);
m_adts
=
obtainFrame
();
}
...
...
src/RTP/AACRtpCodec.h
查看文件 @
c1e91620
...
...
@@ -24,12 +24,20 @@ public:
* @param key_pos 此参数内部强制转换为false,请忽略之
*/
void
inputRtp
(
const
RtpPacket
::
Ptr
&
rtp
,
bool
key_pos
=
false
)
override
;
TrackType
getTrackType
()
const
override
{
return
TrackAudio
;
}
CodecId
getCodecId
()
const
override
{
return
CodecAAC
;
}
private
:
void
onGetAdts
(
const
A
dts
Frame
::
Ptr
&
frame
);
A
dts
Frame
::
Ptr
obtainFrame
();
void
onGetAdts
(
const
A
AC
Frame
::
Ptr
&
frame
);
A
AC
Frame
::
Ptr
obtainFrame
();
private
:
A
dts
Frame
::
Ptr
m_adts
;
ResourcePool
<
A
dts
Frame
>
m_framePool
;
A
AC
Frame
::
Ptr
m_adts
;
ResourcePool
<
A
AC
Frame
>
m_framePool
;
uint32_t
m_sampleRate
;
};
...
...
@@ -37,7 +45,7 @@ private:
/**
* aac adts转rtp类
*/
class
AACRtpEncoder
:
public
Rtp
Info
,
public
RtpCodec
{
class
AACRtpEncoder
:
public
Rtp
Encoder
{
public
:
/**
* @param ui32Ssrc ssrc
...
...
@@ -58,7 +66,16 @@ public:
* @param frame 带dats头的aac数据
* @param key_pos 此参数内部强制转换为false,请忽略之
*/
void
inputFame
(
const
Frame
::
Ptr
&
frame
,
bool
key_pos
=
false
)
override
;
void
inputFrame
(
const
Frame
::
Ptr
&
frame
,
bool
key_pos
=
false
)
override
;
TrackType
getTrackType
()
const
override
{
return
TrackAudio
;
}
CodecId
getCodecId
()
const
override
{
return
CodecAAC
;
}
private
:
void
makeAACRtp
(
const
void
*
pData
,
unsigned
int
uiLen
,
bool
bMark
,
uint32_t
uiStamp
);
private
:
...
...
src/RTP/H264RtpCodec.cpp
查看文件 @
c1e91620
...
...
@@ -97,7 +97,7 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
void
H264RtpDecoder
::
onGetH264
(
const
H264Frame
::
Ptr
&
frame
)
{
//写入环形缓存
RtpCodec
::
inputFame
(
frame
,
frame
->
type
==
5
);
RtpCodec
::
inputF
r
ame
(
frame
,
frame
->
type
==
5
);
m_h264frame
=
obtainFrame
();
}
...
...
@@ -109,15 +109,15 @@ H264RtpEncoder::H264RtpEncoder(uint32_t ui32Ssrc,
uint32_t
ui32SampleRate
,
uint8_t
ui8PlayloadType
,
uint8_t
ui8Interleaved
)
:
Rtp
Info
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
)
{
Rtp
Encoder
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
)
{
}
void
H264RtpEncoder
::
inputFame
(
const
Frame
::
Ptr
&
frame
,
bool
key_pos
)
{
RtpCodec
::
inputFame
(
frame
,
key_pos
);
void
H264RtpEncoder
::
inputF
r
ame
(
const
Frame
::
Ptr
&
frame
,
bool
key_pos
)
{
RtpCodec
::
inputF
r
ame
(
frame
,
key_pos
);
GET_CONFIG_AND_REGISTER
(
uint32_t
,
cycleMS
,
Config
::
Rtp
::
kCycleMS
);
auto
uiStamp
=
frame
->
stamp
();
...
...
src/RTP/H264RtpCodec.h
查看文件 @
c1e91620
...
...
@@ -24,6 +24,14 @@ public:
* @param key_pos 此参数忽略之
*/
void
inputRtp
(
const
RtpPacket
::
Ptr
&
rtp
,
bool
key_pos
=
true
)
override
;
TrackType
getTrackType
()
const
override
{
return
TrackVideo
;
}
CodecId
getCodecId
()
const
override
{
return
CodecH264
;
}
private
:
bool
decodeRtp
(
const
RtpPacket
::
Ptr
&
rtp
);
void
onGetH264
(
const
H264Frame
::
Ptr
&
frame
);
...
...
@@ -36,7 +44,7 @@ private:
/**
* 264 rtp打包类
*/
class
H264RtpEncoder
:
public
Rtp
Info
,
public
RtpCodec
{
class
H264RtpEncoder
:
public
Rtp
Encoder
{
public
:
/**
...
...
@@ -58,7 +66,15 @@ public:
* @param frame 帧数据,必须
* @param key_pos
*/
void
inputFame
(
const
Frame
::
Ptr
&
frame
,
bool
key_pos
)
override
;
void
inputFrame
(
const
Frame
::
Ptr
&
frame
,
bool
key_pos
)
override
;
TrackType
getTrackType
()
const
override
{
return
TrackVideo
;
}
CodecId
getCodecId
()
const
override
{
return
CodecH264
;
}
private
:
void
makeH264Rtp
(
const
void
*
pData
,
unsigned
int
uiLen
,
bool
bMark
,
uint32_t
uiStamp
);
private
:
...
...
src/RTP/RtpCodec.cpp
查看文件 @
c1e91620
...
...
@@ -3,3 +3,16 @@
//
#include "RtpCodec.h"
RtpEncoder
::
RtpEncoder
(
uint32_t
ui32Ssrc
,
uint32_t
ui32MtuSize
,
uint32_t
ui32SampleRate
,
uint8_t
ui8PlayloadType
,
uint8_t
ui8Interleaved
)
:
RtpInfo
(
ui32Ssrc
,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
)
{
}
src/RTP/RtpCodec.h
查看文件 @
c1e91620
...
...
@@ -14,35 +14,55 @@ using namespace std;
using
namespace
ZL
::
Util
;
using
namespace
ZL
::
Player
;
class
Rtp
Codec
{
class
Rtp
Packet
{
public
:
typedef
std
::
shared_ptr
<
RtpCodec
>
Ptr
;
typedef
RingBuffer
<
Frame
::
Ptr
>
FrameRing
;
typedef
RingBuffer
<
RtpPacket
::
Ptr
>
RtpRing
;
typedef
std
::
shared_ptr
<
RtpPacket
>
Ptr
;
uint8_t
interleaved
;
uint8_t
PT
;
bool
mark
;
uint32_t
length
;
uint32_t
timeStamp
;
uint16_t
sequence
;
uint32_t
ssrc
;
uint8_t
payload
[
1560
];
uint8_t
offset
;
TrackType
type
;
};
class
RtpRingInterface
{
public
:
typedef
RingBuffer
<
RtpPacket
::
Ptr
>
RingType
;
RtpRingInterface
(){}
virtual
~
RtpRingInterface
(){}
virtual
RingType
::
Ptr
getRtpRing
()
const
=
0
;
virtual
void
setRtpRing
(
const
RingType
::
Ptr
&
ring
)
=
0
;
virtual
void
inputRtp
(
const
RtpPacket
::
Ptr
&
rtp
,
bool
key_pos
)
=
0
;
};
class
RtpRing
:
public
RtpRingInterface
{
public
:
typedef
std
::
shared_ptr
<
RtpRing
>
Ptr
;
Rtp
Codec
(){
Rtp
Ring
(){
//禁用缓存
_frameRing
=
std
::
make_shared
<
FrameRing
>
(
1
);
_rtpRing
=
std
::
make_shared
<
RtpRing
>
(
1
);
_rtpRing
=
std
::
make_shared
<
RingType
>
(
1
);
}
virtual
~
Rtp
Codec
(){}
virtual
~
Rtp
Ring
(){}
FrameRing
::
Ptr
&
getFrameRing
()
{
return
_frameRing
;
}
RtpRing
::
Ptr
&
getRtpRing
()
{
RingType
::
Ptr
getRtpRing
()
const
override
{
return
_rtpRing
;
}
v
irtual
void
inputFame
(
const
Frame
::
Ptr
&
frame
,
bool
key_pos
)
{
_
frameRing
->
write
(
frame
,
key_pos
)
;
v
oid
setRtpRing
(
const
RingType
::
Ptr
&
ring
)
override
{
_
rtpRing
=
ring
;
}
virtual
void
inputRtp
(
const
RtpPacket
::
Ptr
&
rtp
,
bool
key_pos
){
void
inputRtp
(
const
RtpPacket
::
Ptr
&
rtp
,
bool
key_pos
)
override
{
_rtpRing
->
write
(
rtp
,
key_pos
);
}
private
:
FrameRing
::
Ptr
_frameRing
;
RtpRing
::
Ptr
_rtpRing
;
protected
:
RingType
::
Ptr
_rtpRing
;
};
...
...
@@ -105,6 +125,31 @@ protected:
ResourcePool
<
RtpPacket
>
m_rtpPool
;
};
class
RtpCodec
:
public
RtpRing
,
public
FrameRing
,
public
CodecInfo
{
public
:
typedef
std
::
shared_ptr
<
RtpCodec
>
Ptr
;
RtpCodec
(){}
virtual
~
RtpCodec
(){}
};
class
RtpEncoder
:
public
RtpInfo
,
public
RtpCodec
{
public
:
typedef
std
::
shared_ptr
<
RtpEncoder
>
Ptr
;
/**
* @param ui32Ssrc ssrc
* @param ui32MtuSize mtu大小
* @param ui32SampleRate 采样率,强制为90000
* @param ui8PlayloadType pt类型
* @param ui8Interleaved rtsp interleaved
*/
RtpEncoder
(
uint32_t
ui32Ssrc
,
uint32_t
ui32MtuSize
=
1400
,
uint32_t
ui32SampleRate
=
90000
,
uint8_t
ui8PlayloadType
=
96
,
uint8_t
ui8Interleaved
=
TrackVideo
*
2
);
~
RtpEncoder
()
{}
};
...
...
src/Rtmp/RtmpParser.h
查看文件 @
c1e91620
...
...
@@ -57,7 +57,7 @@ public:
lock_guard
<
recursive_mutex
>
lck
(
m_mtxCB
);
onVideo
=
cb
;
}
void
setOnAudioCB
(
const
function
<
void
(
const
A
dts
Frame
&
frame
)
>
&
cb
)
override
{
void
setOnAudioCB
(
const
function
<
void
(
const
A
AC
Frame
&
frame
)
>
&
cb
)
override
{
lock_guard
<
recursive_mutex
>
lck
(
m_mtxCB
);
onAudio
=
cb
;
}
...
...
@@ -140,7 +140,7 @@ private:
//video
H264Frame
m_h264frame
;
//aduio
A
dts
Frame
m_adts
;
A
AC
Frame
m_adts
;
int
m_iSampleRate
=
44100
;
int
m_iSampleBit
=
16
;
...
...
@@ -158,7 +158,7 @@ private:
float
m_fDuration
=
0
;
mutable
Ticker
m_ticker
;
function
<
void
(
const
H264Frame
&
frame
)
>
onVideo
;
function
<
void
(
const
A
dts
Frame
&
frame
)
>
onAudio
;
function
<
void
(
const
A
AC
Frame
&
frame
)
>
onAudio
;
recursive_mutex
m_mtxCB
;
...
...
src/Rtmp/RtmpToRtspMediaSource.cpp
查看文件 @
c1e91620
...
...
@@ -55,7 +55,7 @@ void RtmpToRtspMediaSource::onGetH264(const H264Frame &frame) {
m_pRtpMaker_h264
->
makeRtp
(
frame
.
data
()
+
4
,
frame
.
size
()
-
4
,
frame
.
timeStamp
);
}
}
inline
void
RtmpToRtspMediaSource
::
onGetAdts
(
const
A
dts
Frame
&
frame
)
{
inline
void
RtmpToRtspMediaSource
::
onGetAdts
(
const
A
AC
Frame
&
frame
)
{
if
(
m_pRecorder
){
m_pRecorder
->
inputAAC
((
char
*
)
frame
.
buffer
,
frame
.
aac_frame_length
,
frame
.
timeStamp
);
}
...
...
src/Rtmp/RtmpToRtspMediaSource.h
查看文件 @
c1e91620
...
...
@@ -94,7 +94,7 @@ private:
bool
m_bEnableHls
;
bool
m_bEnableMp4
;
void
onGetH264
(
const
H264Frame
&
frame
);
void
onGetAdts
(
const
A
dts
Frame
&
frame
);
void
onGetAdts
(
const
A
AC
Frame
&
frame
);
void
makeSDP
();
};
...
...
src/Rtsp/RtpParser.cpp
查看文件 @
c1e91620
...
...
@@ -242,7 +242,7 @@ inline bool RtpParser::inputAudio(const RtpPacket& rtppack,
char
*
frame
=
(
char
*
)
rtppack
.
payload
+
rtppack
.
offset
;
int
length
=
rtppack
.
length
-
rtppack
.
offset
;
if
(
m_adts
.
aac_frame_length
+
length
-
4
>
sizeof
(
A
dts
Frame
::
buffer
))
{
if
(
m_adts
.
aac_frame_length
+
length
-
4
>
sizeof
(
A
AC
Frame
::
buffer
))
{
m_adts
.
aac_frame_length
=
7
;
return
false
;
}
...
...
@@ -302,7 +302,7 @@ inline void RtpParser::onGetH264(H264Frame& frame) {
}
}
inline
void
RtpParser
::
onGetAdts
(
A
dts
Frame
&
frame
)
{
inline
void
RtpParser
::
onGetAdts
(
A
AC
Frame
&
frame
)
{
//frame.timeStamp=ticker1.elapsedTime();
lock_guard
<
recursive_mutex
>
lck
(
m_mtxCB
);
if
(
onAudio
)
{
...
...
src/Rtsp/RtpParser.h
查看文件 @
c1e91620
...
...
@@ -32,6 +32,7 @@
#include "Player/Player.h"
#include "Player/PlayerBase.h"
#include "Util/TimeTicker.h"
#include "RTP/RtpCodec.h"
using
namespace
std
;
using
namespace
ZL
::
Util
;
...
...
@@ -51,7 +52,7 @@ public:
lock_guard
<
recursive_mutex
>
lck
(
m_mtxCB
);
onVideo
=
cb
;
}
void
setOnAudioCB
(
const
function
<
void
(
const
A
dts
Frame
&
frame
)
>
&
cb
)
override
{
void
setOnAudioCB
(
const
function
<
void
(
const
A
AC
Frame
&
frame
)
>
&
cb
)
override
{
lock_guard
<
recursive_mutex
>
lck
(
m_mtxCB
);
onAudio
=
cb
;
}
...
...
@@ -120,11 +121,11 @@ private:
inline
bool
inputAudio
(
const
RtpPacket
&
rtp
,
const
RtspTrack
&
track
);
inline
void
_onGetH264
(
H264Frame
&
frame
);
inline
void
onGetH264
(
H264Frame
&
frame
);
inline
void
onGetAdts
(
A
dts
Frame
&
frame
);
inline
void
onGetAdts
(
A
AC
Frame
&
frame
);
//video
H264Frame
m_h264frame
;
//aduio
A
dts
Frame
m_adts
;
A
AC
Frame
m_adts
;
int
m_iSampleRate
=
44100
;
int
m_iSampleBit
=
16
;
...
...
@@ -142,7 +143,7 @@ private:
bool
m_bParseSpsDelay
=
false
;
function
<
void
(
const
H264Frame
&
frame
)
>
onVideo
;
function
<
void
(
const
A
dts
Frame
&
frame
)
>
onAudio
;
function
<
void
(
const
A
AC
Frame
&
frame
)
>
onAudio
;
recursive_mutex
m_mtxCB
;
};
...
...
src/Rtsp/Rtsp.h
查看文件 @
c1e91620
...
...
@@ -32,22 +32,17 @@
#include <unordered_map>
#include "Common/config.h"
#include "Util/util.h"
#include "Player/Frame.h"
using
namespace
std
;
using
namespace
ZL
::
Util
;
typedef
enum
{
TrackVideo
=
0
,
TrackAudio
,
TrackInvalid
,
TrackMax
}
TrackType
;
class
RtspTrack
{
public
:
uint8_t
PT
;
uint8_t
interleaved
;
TrackType
type
=
(
TrackType
)
-
1
;
TrackType
type
=
TrackInvalid
;
string
trackSdp
;
string
controlSuffix
;
bool
inited
;
...
...
@@ -56,21 +51,6 @@ public:
uint32_t
timeStamp
;
};
class
RtpPacket
{
public
:
typedef
std
::
shared_ptr
<
RtpPacket
>
Ptr
;
uint8_t
interleaved
;
uint8_t
PT
;
bool
mark
;
uint32_t
length
;
uint32_t
timeStamp
;
uint16_t
sequence
;
uint32_t
ssrc
;
uint8_t
payload
[
1560
];
uint8_t
offset
;
TrackType
type
;
};
class
RtcpCounter
{
public
:
uint32_t
pktCnt
=
0
;
...
...
src/Rtsp/Rtsp
Mak
er.h
→
src/Rtsp/Rtsp
Encod
er.h
查看文件 @
c1e91620
差异被折叠。
点击展开。
src/Rtsp/RtspMediaSource.h
查看文件 @
c1e91620
...
...
@@ -35,6 +35,7 @@
#include "Rtsp.h"
#include "Common/config.h"
#include "Common/MediaSource.h"
#include "RTP/RtpCodec.h"
#include "Util/logger.h"
#include "Util/RingBuffer.h"
...
...
src/Rtsp/RtspToRtmpMediaSource.cpp
查看文件 @
c1e91620
...
...
@@ -124,7 +124,7 @@ void RtspToRtmpMediaSource::onGetH264(const H264Frame& frame) {
rtmpPkt
->
typeId
=
MSG_VIDEO
;
m_pRtmpSrc
->
onGetMedia
(
rtmpPkt
);
}
void
RtspToRtmpMediaSource
::
onGetAdts
(
const
A
dts
Frame
&
frame
)
{
void
RtspToRtmpMediaSource
::
onGetAdts
(
const
A
AC
Frame
&
frame
)
{
if
(
m_pRecorder
){
m_pRecorder
->
inputAAC
((
char
*
)
frame
.
buffer
,
frame
.
aac_frame_length
,
frame
.
timeStamp
);
}
...
...
src/Rtsp/RtspToRtmpMediaSource.h
查看文件 @
c1e91620
...
...
@@ -97,7 +97,7 @@ private:
bool
m_bEnableHls
;
bool
m_bEnableMp4
;
void
onGetH264
(
const
H264Frame
&
frame
);
void
onGetAdts
(
const
A
dts
Frame
&
frame
);
void
onGetAdts
(
const
A
AC
Frame
&
frame
);
void
makeVideoConfigPkt
();
void
makeAudioConfigPkt
();
void
makeMetaData
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论