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
8f8eda93
Commit
8f8eda93
authored
Oct 26, 2018
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
时间戳统一使用毫秒
parent
e816c56f
显示空白字符变更
内嵌
并排
正在显示
24 个修改的文件
包含
190 行增加
和
100 行删除
+190
-100
src/Common/Factory.cpp
+2
-2
src/Common/Factory.h
+1
-1
src/Common/MultiMediaSourceMuxer.h
+14
-0
src/Player/PlayerBase.h
+63
-1
src/Rtmp/RtmpPlayer.cpp
+15
-15
src/Rtmp/RtmpPlayer.h
+5
-5
src/Rtmp/RtmpPlayerImp.h
+2
-2
src/Rtmp/RtmpSession.cpp
+1
-1
src/RtmpMuxer/RtmpMediaSourceMuxer.h
+3
-0
src/Rtsp/Rtsp.h
+1
-0
src/Rtsp/RtspMediaSource.h
+8
-1
src/Rtsp/RtspPlayer.cpp
+26
-25
src/Rtsp/RtspPlayer.h
+10
-8
src/Rtsp/RtspPlayerImp.h
+2
-2
src/Rtsp/RtspSession.cpp
+7
-3
src/Rtsp/RtspToRtmpMediaSource.h
+0
-7
src/RtspMuxer/AACRtpCodec.cpp
+6
-8
src/RtspMuxer/AACRtpCodec.h
+1
-5
src/RtspMuxer/H264RtpCodec.cpp
+7
-6
src/RtspMuxer/RtpCodec.h
+1
-0
src/RtspMuxer/RtpMakerAAC.cpp
+4
-3
src/RtspMuxer/RtpMakerH264.cpp
+3
-3
src/RtspMuxer/RtspDemuxer.cpp
+2
-2
src/RtspMuxer/RtspMediaSourceMuxer.h
+6
-0
没有找到文件。
src/Common/Factory.cpp
查看文件 @
8f8eda93
...
...
@@ -184,12 +184,12 @@ RtpCodec::Ptr Factory::getRtpEncoderById(CodecId codecId,
}
}
RtpCodec
::
Ptr
Factory
::
getRtpDecoderById
(
CodecId
codecId
,
uint32_t
ui32SampleRate
)
{
RtpCodec
::
Ptr
Factory
::
getRtpDecoderById
(
CodecId
codecId
)
{
switch
(
codecId
){
case
CodecH264
:
return
std
::
make_shared
<
H264RtpDecoder
>
();
case
CodecAAC
:
return
std
::
make_shared
<
AACRtpDecoder
>
(
ui32SampleRate
);
return
std
::
make_shared
<
AACRtpDecoder
>
();
default
:
WarnL
<<
"暂不支持该CodecId:"
<<
codecId
;
return
nullptr
;
...
...
src/Common/Factory.h
查看文件 @
8f8eda93
...
...
@@ -86,7 +86,7 @@ public:
* @param ui32SampleRate
* @return
*/
static
RtpCodec
::
Ptr
getRtpDecoderById
(
CodecId
codecId
,
uint32_t
ui32SampleRate
);
static
RtpCodec
::
Ptr
getRtpDecoderById
(
CodecId
codecId
);
////////////////////////////////rtmp相关//////////////////////////////////
...
...
src/Common/MultiMediaSourceMuxer.h
查看文件 @
8f8eda93
...
...
@@ -32,6 +32,8 @@
class
MultiMediaSourceMuxer
{
public
:
typedef
std
::
shared_ptr
<
MultiMediaSourceMuxer
>
Ptr
;
MultiMediaSourceMuxer
(
const
string
&
vhost
,
const
string
&
strApp
,
const
string
&
strId
,
...
...
@@ -68,6 +70,18 @@ public:
_rtmp
->
setListener
(
listener
);
_rtsp
->
setListener
(
listener
);
}
/**
* 返回总的消费者个数
* @return
*/
int
readerCount
()
const
{
return
_rtsp
->
readerCount
()
+
_rtmp
->
readerCount
();
}
void
updateTimeStamp
(
uint32_t
stamp
){
_rtsp
->
updateTimeStamp
(
stamp
);
}
private
:
RtmpMediaSourceMuxer
::
Ptr
_rtmp
;
RtspMediaSourceMuxer
::
Ptr
_rtsp
;
...
...
src/Player/PlayerBase.h
查看文件 @
8f8eda93
...
...
@@ -46,9 +46,29 @@ class DemuxerBase {
public
:
typedef
std
::
shared_ptr
<
DemuxerBase
>
Ptr
;
/**
* 获取节目总时长,单位秒
* @return
*/
virtual
float
getDuration
()
const
{
return
0
;}
/**
* 是否初始化完毕,完毕后方可调用getTrack方法
* @return
*/
virtual
bool
isInited
()
const
{
return
true
;
}
/**
* 获取全部的Track
* @return
*/
virtual
vector
<
Track
::
Ptr
>
getTracks
()
const
{
return
vector
<
Track
::
Ptr
>
();}
/**
* 获取特定Track
* @param type
* @return
*/
virtual
Track
::
Ptr
getTrack
(
TrackType
type
)
const
{
auto
tracks
=
getTracks
();
for
(
auto
&
track
:
tracks
){
...
...
@@ -85,18 +105,60 @@ public:
PlayerBase
(){}
virtual
~
PlayerBase
(){}
/**
* 开始播放
* @param strUrl 视频url,支持rtsp/rtmp
*/
virtual
void
play
(
const
char
*
strUrl
)
{}
/**
* 暂停或恢复
* @param bPause
*/
virtual
void
pause
(
bool
bPause
)
{}
/**
* 中断播放
*/
virtual
void
teardown
()
{}
/**
* 设置异常中断回调
* @param cb
*/
virtual
void
setOnShutdown
(
const
function
<
void
(
const
SockException
&
)
>
&
cb
)
{}
/**
* 设置播放结果回调
* @param cb
*/
virtual
void
setOnPlayResult
(
const
function
<
void
(
const
SockException
&
ex
)
>
&
cb
)
{}
/**
* 获取播放进度,取值 0.0 ~ 1.0
* @return
*/
virtual
float
getProgress
()
const
{
return
0
;}
/**
* 拖动进度条
* @param fProgress 进度,取值 0.0 ~ 1.0
*/
virtual
void
seekTo
(
float
fProgress
)
{}
/**
* 设置一个MediaSource,直接生产rtsp/rtmp代理
* @param src
*/
virtual
void
setMediaSouce
(
const
MediaSource
::
Ptr
&
src
)
{}
virtual
float
getRtpLossRate
(
TrackType
trackType
)
const
{
return
0
;
}
/**
* 获取丢包率,只支持rtsp
* @param trackType 音频或视频,TrackInvalid时为总丢包率
* @return
*/
virtual
float
getPacketLossRate
(
TrackType
trackType
)
const
{
return
0
;
}
protected
:
virtual
void
onShutdown
(
const
SockException
&
ex
)
{}
virtual
void
onPlayResult
(
const
SockException
&
ex
)
{}
...
...
src/Rtmp/RtmpPlayer.cpp
查看文件 @
8f8eda93
...
...
@@ -66,9 +66,9 @@ void RtmpPlayer::teardown() {
_pBeatTimer
.
reset
();
_pPlayTimer
.
reset
();
_pMediaTimer
.
reset
();
_
f
SeekTo
=
0
;
CLEAR_ARR
(
_a
d
FistStamp
);
CLEAR_ARR
(
_a
d
NowStamp
);
_
i
SeekTo
=
0
;
CLEAR_ARR
(
_a
i
FistStamp
);
CLEAR_ARR
(
_a
i
NowStamp
);
reset
();
shutdown
();
}
...
...
@@ -310,7 +310,7 @@ void RtmpPlayer::onRtmpChunk(RtmpPacket &chunkData) {
case
MSG_VIDEO
:
{
auto
idx
=
chunkData
.
typeId
%
2
;
if
(
_aNowStampTicker
[
idx
].
elapsedTime
()
>
500
)
{
_a
d
NowStamp
[
idx
]
=
chunkData
.
timeStamp
;
_a
i
NowStamp
[
idx
]
=
chunkData
.
timeStamp
;
}
_onMediaData
(
std
::
make_shared
<
RtmpPacket
>
(
chunkData
));
}
...
...
@@ -321,30 +321,30 @@ void RtmpPlayer::onRtmpChunk(RtmpPacket &chunkData) {
}
}
float
RtmpPlayer
::
getProgressTime
()
const
{
double
iTime
[
2
]
=
{
0
,
0
};
uint32_t
RtmpPlayer
::
getProgressMilliSecond
()
const
{
uint32_t
iTime
[
2
]
=
{
0
,
0
};
for
(
auto
i
=
0
;
i
<
2
;
i
++
){
iTime
[
i
]
=
(
_adNowStamp
[
i
]
-
_adFistStamp
[
i
])
/
1000.0
;
iTime
[
i
]
=
_aiNowStamp
[
i
]
-
_aiFistStamp
[
i
]
;
}
return
_
f
SeekTo
+
MAX
(
iTime
[
0
],
iTime
[
1
]);
return
_
i
SeekTo
+
MAX
(
iTime
[
0
],
iTime
[
1
]);
}
void
RtmpPlayer
::
seekTo
Time
(
float
fTime
){
void
RtmpPlayer
::
seekTo
MilliSecond
(
uint32_t
seekMS
){
if
(
_bPaused
)
{
pause
(
false
);
}
AMFEncoder
enc
;
enc
<<
"seek"
<<
++
_iReqID
<<
nullptr
<<
fTime
*
1000
.0
;
enc
<<
"seek"
<<
++
_iReqID
<<
nullptr
<<
seekMS
*
1
.0
;
sendRequest
(
MSG_CMD
,
enc
.
data
());
addOnStatusCB
([
this
,
fTime
](
AMFValue
&
val
)
{
addOnStatusCB
([
this
,
seekMS
](
AMFValue
&
val
)
{
//TraceL << "seek result";
_aNowStampTicker
[
0
].
resetTime
();
_aNowStampTicker
[
1
].
resetTime
();
float
iTimeInc
=
fTime
-
getProgressTime
();
auto
iTimeInc
=
seekMS
-
getProgressMilliSecond
();
for
(
auto
i
=
0
;
i
<
2
;
i
++
){
_a
dFistStamp
[
i
]
=
_adNowStamp
[
i
]
+
iTimeInc
*
1000.0
;
_a
dNowStamp
[
i
]
=
_ad
FistStamp
[
i
];
_a
iFistStamp
[
i
]
=
_aiNowStamp
[
i
]
+
iTimeInc
;
_a
iNowStamp
[
i
]
=
_ai
FistStamp
[
i
];
}
_
fSeekTo
=
fTime
;
_
iSeekTo
=
seekMS
;
});
}
...
...
src/Rtmp/RtmpPlayer.h
查看文件 @
8f8eda93
...
...
@@ -55,8 +55,8 @@ public:
protected
:
virtual
bool
onCheckMeta
(
AMFValue
&
val
)
=
0
;
virtual
void
onMediaData
(
const
RtmpPacket
::
Ptr
&
chunkData
)
=
0
;
float
getProgressTime
()
const
;
void
seekTo
Time
(
float
fTime
);
uint32_t
getProgressMilliSecond
()
const
;
void
seekTo
MilliSecond
(
uint32_t
ms
);
private
:
void
_onShutdown
(
const
SockException
&
ex
)
{
WarnL
<<
ex
.
getErrCode
()
<<
" "
<<
ex
.
what
();
...
...
@@ -145,9 +145,9 @@ private:
std
::
shared_ptr
<
Timer
>
_pBeatTimer
;
//播放进度控制
float
_f
SeekTo
=
0
;
double
_ad
FistStamp
[
2
]
=
{
0
,
0
};
double
_ad
NowStamp
[
2
]
=
{
0
,
0
};
uint32_t
_i
SeekTo
=
0
;
uint32_t
_ai
FistStamp
[
2
]
=
{
0
,
0
};
uint32_t
_ai
NowStamp
[
2
]
=
{
0
,
0
};
Ticker
_aNowStampTicker
[
2
];
};
...
...
src/Rtmp/RtmpPlayerImp.h
查看文件 @
8f8eda93
...
...
@@ -49,13 +49,13 @@ public:
};
float
getProgress
()
const
override
{
if
(
getDuration
()
>
0
){
return
getProgress
Time
()
/
getDuration
(
);
return
getProgress
MilliSecond
()
/
(
getDuration
()
*
1000
);
}
return
PlayerBase
::
getProgress
();
};
void
seekTo
(
float
fProgress
)
override
{
fProgress
=
MAX
(
float
(
0
),
MIN
(
fProgress
,
float
(
1
.
0
)));
seekTo
Time
(
fProgress
*
getDuration
()
);
seekTo
MilliSecond
(
fProgress
*
getDuration
()
*
1000
);
};
private
:
//派生类回调函数
...
...
src/Rtmp/RtmpSession.cpp
查看文件 @
8f8eda93
...
...
@@ -521,7 +521,7 @@ void RtmpSession::onRtmpChunk(RtmpPacket &chunkData) {
void
RtmpSession
::
onCmd_seek
(
AMFDecoder
&
dec
)
{
dec
.
load
<
AMFValue
>
();
/* NULL */
auto
milliSeconds
=
dec
.
load
<
AMFValue
>
().
as_number
();
InfoL
<<
"rtmp seekTo
:"
<<
milliSeconds
/
1000.0
;
InfoL
<<
"rtmp seekTo
(ms):"
<<
milliSeconds
;
auto
stongSrc
=
_pPlayerSrc
.
lock
();
if
(
stongSrc
)
{
stongSrc
->
seekTo
(
milliSeconds
);
...
...
src/RtmpMuxer/RtmpMediaSourceMuxer.h
查看文件 @
8f8eda93
...
...
@@ -48,6 +48,9 @@ public:
void
setListener
(
const
std
::
weak_ptr
<
MediaSourceEvent
>
&
listener
){
_mediaSouce
->
setListener
(
listener
);
}
int
readerCount
()
const
{
return
_mediaSouce
->
getRing
()
->
readerCount
();
}
private
:
void
onInited
()
override
{
_mediaSouce
->
onGetMetaData
(
getMetedata
());
...
...
src/Rtsp/Rtsp.h
查看文件 @
8f8eda93
...
...
@@ -69,6 +69,7 @@ public:
bool
_inited
=
false
;
uint32_t
_ssrc
=
0
;
uint16_t
_seq
=
0
;
//时间戳,单位毫秒
uint32_t
_time_stamp
=
0
;
};
class
SdpAttr
{
...
...
src/Rtsp/RtspMediaSource.h
查看文件 @
8f8eda93
...
...
@@ -84,7 +84,7 @@ public:
}
return
track
->
_seq
;
}
virtual
uint32_t
getTime
s
tamp
(
TrackType
trackType
)
{
virtual
uint32_t
getTime
S
tamp
(
TrackType
trackType
)
{
auto
track
=
_sdpAttr
.
getTrack
(
trackType
);
if
(
!
track
){
return
0
;
...
...
@@ -92,6 +92,13 @@ public:
return
track
->
_time_stamp
;
}
void
updateTimeStamp
(
uint32_t
uiStamp
)
{
auto
tracks
=
_sdpAttr
.
getAvailableTrack
();
for
(
auto
&
track
:
tracks
)
{
track
->
_time_stamp
=
uiStamp
;
}
}
virtual
void
onGetSDP
(
const
string
&
sdp
)
{
//派生类设置该媒体源媒体描述信息
_strSdp
=
sdp
;
...
...
src/Rtsp/RtspPlayer.cpp
查看文件 @
8f8eda93
...
...
@@ -91,9 +91,9 @@ void RtspPlayer::teardown(){
_pBeatTimer
.
reset
();
_pPlayTimer
.
reset
();
_pRtpTimer
.
reset
();
_
f
SeekTo
=
0
;
CLEAR_ARR
(
_a
d
FistStamp
);
CLEAR_ARR
(
_a
d
NowStamp
);
_
i
SeekTo
=
0
;
CLEAR_ARR
(
_a
i
FistStamp
);
CLEAR_ARR
(
_a
i
NowStamp
);
}
void
RtspPlayer
::
play
(
const
char
*
strUrl
){
...
...
@@ -430,17 +430,17 @@ bool RtspPlayer::sendDescribe() {
}
bool
RtspPlayer
::
sendPause
(
bool
bPause
,
float
fTime
){
bool
RtspPlayer
::
sendPause
(
bool
bPause
,
uint32_t
seekMS
){
if
(
!
bPause
){
//修改时间轴
_aNowStampTicker
[
0
].
resetTime
();
_aNowStampTicker
[
1
].
resetTime
();
float
iTimeInc
=
fTime
-
getProgressTime
();
auto
iTimeInc
=
seekMS
-
getProgressMilliSecond
();
for
(
unsigned
int
i
=
0
;
i
<
_aTrackInfo
.
size
()
;
i
++
){
_a
dFistStamp
[
i
]
=
_adNowStamp
[
i
]
+
iTimeInc
*
_aTrackInfo
[
i
]
->
_samplerate
;
_a
dNowStamp
[
i
]
=
_ad
FistStamp
[
i
];
_a
iFistStamp
[
i
]
=
_aiNowStamp
[
i
]
+
iTimeInc
;
_a
iNowStamp
[
i
]
=
_ai
FistStamp
[
i
];
}
_
fSeekTo
=
fTime
;
_
iSeekTo
=
seekMS
;
}
//开启或暂停rtsp
...
...
@@ -448,12 +448,12 @@ bool RtspPlayer::sendPause(bool bPause,float fTime){
StrCaseMap
header
;
char
buf
[
8
];
sprintf
(
buf
,
"%.2f"
,
fTime
);
sprintf
(
buf
,
"%.2f"
,
seekMS
/
1000.0
);
header
[
"Range"
]
=
StrPrinter
<<
"npt="
<<
buf
<<
"-"
;
return
sendRtspRequest
(
bPause
?
"PAUSE"
:
"PLAY"
,
_strContentBase
,
header
);
}
void
RtspPlayer
::
pause
(
bool
bPause
)
{
sendPause
(
bPause
,
getProgressTime
());
sendPause
(
bPause
,
getProgressMilliSecond
());
}
void
RtspPlayer
::
handleResPAUSE
(
const
Parser
&
parser
,
bool
bPause
)
{
...
...
@@ -471,8 +471,8 @@ void RtspPlayer::handleResPAUSE(const Parser& parser, bool bPause) {
if
(
strStart
==
"now"
)
{
strStart
=
"0"
;
}
_
fSeekTo
=
atof
(
strStart
.
data
());
DebugL
<<
"
Range:"
<<
_fSeekTo
<<
" "
<<
strStart
;
_
iSeekTo
=
1000
*
atof
(
strStart
.
data
());
DebugL
<<
"
seekTo(ms):"
<<
_iSeekTo
;
}
auto
strRtpInfo
=
parser
[
"RTP-Info"
];
if
(
strRtpInfo
.
size
())
{
...
...
@@ -482,10 +482,10 @@ void RtspPlayer::handleResPAUSE(const Parser& parser, bool bPause) {
strTrack
.
append
(
";"
);
auto
strControlSuffix
=
strTrack
.
substr
(
1
+
strTrack
.
rfind
(
'/'
),
strTrack
.
find
(
';'
)
-
strTrack
.
rfind
(
'/'
)
-
1
);
auto
strRtpTime
=
FindField
(
strTrack
.
data
(),
"rtptime="
,
";"
);
auto
i
I
dx
=
getTrackIndexByControlSuffix
(
strControlSuffix
);
_a
dFistStamp
[
iIdx
]
=
atoll
(
strRtpTime
.
data
())
;
_a
dNowStamp
[
iIdx
]
=
_adFistStamp
[
iI
dx
];
DebugL
<<
"rtptime:"
<<
strControlSuffix
<<
" "
<<
strRtpTime
;
auto
idx
=
getTrackIndexByControlSuffix
(
strControlSuffix
);
_a
iFistStamp
[
idx
]
=
atoll
(
strRtpTime
.
data
())
*
1000
/
_aTrackInfo
[
idx
]
->
_samplerate
;
_a
iNowStamp
[
idx
]
=
_aiFistStamp
[
i
dx
];
DebugL
<<
"rtptime
(ms)
:"
<<
strControlSuffix
<<
" "
<<
strRtpTime
;
}
}
onPlayResult_l
(
SockException
(
Err_success
,
"rtsp play success"
));
...
...
@@ -595,7 +595,8 @@ bool RtspPlayer::handleOneRtp(int iTrackidx, unsigned char *pucData, unsigned in
rtppt
.
sequence
=
ntohs
(
rtppt
.
sequence
);
//时间戳
memcpy
(
&
rtppt
.
timeStamp
,
pucData
+
4
,
4
);
//内存对齐
rtppt
.
timeStamp
=
ntohl
(
rtppt
.
timeStamp
);
//时间戳转换成毫秒
rtppt
.
timeStamp
=
ntohl
(
rtppt
.
timeStamp
)
*
1000
/
track
->
_samplerate
;
//ssrc
memcpy
(
&
rtppt
.
ssrc
,
pucData
+
8
,
4
);
//内存对齐
rtppt
.
ssrc
=
ntohl
(
rtppt
.
ssrc
);
...
...
@@ -679,12 +680,12 @@ void RtspPlayer::onRecvRTP_l(const RtpPacket::Ptr &rtppt, int trackidx){
_aui16NowSeq
[
trackidx
]
=
rtppt
->
sequence
;
if
(
_aNowStampTicker
[
trackidx
].
elapsedTime
()
>
500
)
{
_a
d
NowStamp
[
trackidx
]
=
rtppt
->
timeStamp
;
_a
i
NowStamp
[
trackidx
]
=
rtppt
->
timeStamp
;
}
onRecvRTP_l
(
rtppt
,
_aTrackInfo
[
trackidx
]);
}
float
RtspPlayer
::
get
Rtp
LossRate
(
TrackType
type
)
const
{
float
RtspPlayer
::
get
Packet
LossRate
(
TrackType
type
)
const
{
int
iTrackIdx
=
getTrackIndexByTrackType
(
type
);
if
(
iTrackIdx
==
-
1
){
uint64_t
totalRecv
=
0
;
...
...
@@ -706,15 +707,15 @@ float RtspPlayer::getRtpLossRate(TrackType type) const{
return
1.0
-
(
double
)
_aui64RtpRecv
[
iTrackIdx
]
/
(
_aui16NowSeq
[
iTrackIdx
]
-
_aui16FirstSeq
[
iTrackIdx
]
+
1
);
}
float
RtspPlayer
::
getProgressTime
()
const
{
double
iTime
[
2
]
=
{
0
,
0
};
uint32_t
RtspPlayer
::
getProgressMilliSecond
()
const
{
uint32_t
iTime
[
2
]
=
{
0
,
0
};
for
(
unsigned
int
i
=
0
;
i
<
_aTrackInfo
.
size
()
;
i
++
){
iTime
[
i
]
=
(
_adNowStamp
[
i
]
-
_adFistStamp
[
i
])
/
_aTrackInfo
[
i
]
->
_samplerate
;
iTime
[
i
]
=
_aiNowStamp
[
i
]
-
_aiFistStamp
[
i
]
;
}
return
_
f
SeekTo
+
MAX
(
iTime
[
0
],
iTime
[
1
]);
return
_
i
SeekTo
+
MAX
(
iTime
[
0
],
iTime
[
1
]);
}
void
RtspPlayer
::
seekTo
Time
(
float
fTime
)
{
sendPause
(
false
,
fTime
);
void
RtspPlayer
::
seekTo
MilliSecond
(
uint32_t
ms
)
{
sendPause
(
false
,
ms
);
}
bool
RtspPlayer
::
sendRtspRequest
(
const
string
&
cmd
,
const
string
&
url
,
const
StrCaseMap
&
header_const
)
{
...
...
src/Rtsp/RtspPlayer.h
查看文件 @
8f8eda93
...
...
@@ -55,13 +55,13 @@ public:
void
play
(
const
char
*
strUrl
)
override
;
void
pause
(
bool
bPause
)
override
;
void
teardown
()
override
;
float
get
Rtp
LossRate
(
TrackType
type
)
const
override
;
float
get
Packet
LossRate
(
TrackType
type
)
const
override
;
protected
:
//派生类回调函数
virtual
bool
onCheckSDP
(
const
string
&
strSdp
,
const
SdpAttr
&
sdpAttr
)
=
0
;
virtual
void
onRecvRTP
(
const
RtpPacket
::
Ptr
&
pRtppt
,
const
SdpTrack
::
Ptr
&
track
)
=
0
;
float
getProgressTime
()
const
;
void
seekTo
Time
(
float
fTime
);
uint32_t
getProgressMilliSecond
()
const
;
void
seekTo
MilliSecond
(
uint32_t
ms
);
private
:
void
onShutdown_l
(
const
SockException
&
ex
);
void
onRecvRTP_l
(
const
RtpPacket
::
Ptr
&
pRtppt
,
int
iTrackidx
);
...
...
@@ -91,7 +91,7 @@ private:
//发送SETUP命令
bool
sendSetup
(
unsigned
int
uiTrackIndex
);
bool
sendPause
(
bool
bPause
,
float
fTime
);
bool
sendPause
(
bool
bPause
,
uint32_t
ms
);
bool
sendOptions
();
bool
sendDescribe
();
bool
sendRtspRequest
(
const
string
&
cmd
,
const
string
&
url
,
const
StrCaseMap
&
header
=
StrCaseMap
());
...
...
@@ -131,10 +131,12 @@ private:
//心跳定时器
std
::
shared_ptr
<
Timer
>
_pBeatTimer
;
//播放进度控制
float
_fSeekTo
=
0
;
double
_adFistStamp
[
2
]
=
{
0
,
0
};
double
_adNowStamp
[
2
]
=
{
0
,
0
};
//播放进度控制,单位毫秒
uint32_t
_iSeekTo
=
0
;
//单位毫秒
uint32_t
_aiFistStamp
[
2
]
=
{
0
,
0
};
uint32_t
_aiNowStamp
[
2
]
=
{
0
,
0
};
Ticker
_aNowStampTicker
[
2
];
};
...
...
src/Rtsp/RtspPlayerImp.h
查看文件 @
8f8eda93
...
...
@@ -51,14 +51,14 @@ public:
};
float
getProgress
()
const
override
{
if
(
getDuration
()
>
0
){
return
getProgress
Time
()
/
getDuration
(
);
return
getProgress
MilliSecond
()
/
(
getDuration
()
*
1000
);
}
return
PlayerBase
::
getProgress
();
};
void
seekTo
(
float
fProgress
)
override
{
fProgress
=
MAX
(
float
(
0
),
MIN
(
fProgress
,
float
(
1
.
0
)));
seekTo
Time
(
fProgress
*
getDuration
()
);
seekTo
MilliSecond
(
fProgress
*
getDuration
()
*
1000
);
};
private
:
//派生类回调函数
...
...
src/Rtsp/RtspSession.cpp
查看文件 @
8f8eda93
...
...
@@ -735,7 +735,7 @@ bool RtspSession::handleReq_Play() {
for
(
auto
&
track
:
_aTrackInfo
){
track
->
_ssrc
=
pMediaSrc
->
getSsrc
(
track
->
_type
);
track
->
_seq
=
pMediaSrc
->
getSeqence
(
track
->
_type
);
track
->
_time_stamp
=
pMediaSrc
->
getTime
s
tamp
(
track
->
_type
);
track
->
_time_stamp
=
pMediaSrc
->
getTime
S
tamp
(
track
->
_type
);
}
}
_bFirstPlay
=
false
;
...
...
@@ -754,7 +754,11 @@ bool RtspSession::handleReq_Play() {
shutdown
();
return
;
}
iLen
+=
sprintf
(
_pcBuf
+
iLen
,
"url=%s/%s;seq=%d;rtptime=%u,"
,
_strUrl
.
data
(),
track
->
_control_surffix
.
data
(),
track
->
_seq
,
track
->
_time_stamp
);
iLen
+=
sprintf
(
_pcBuf
+
iLen
,
"url=%s/%s;seq=%d;rtptime=%u,"
,
_strUrl
.
data
(),
track
->
_control_surffix
.
data
(),
track
->
_seq
,
track
->
_time_stamp
*
track
->
_samplerate
/
1000
);
}
iLen
-=
1
;
...
...
@@ -906,7 +910,7 @@ inline bool RtspSession::findStream() {
for
(
auto
&
track
:
_aTrackInfo
){
track
->
_ssrc
=
pMediaSrc
->
getSsrc
(
track
->
_type
);
track
->
_seq
=
pMediaSrc
->
getSeqence
(
track
->
_type
);
track
->
_time_stamp
=
pMediaSrc
->
getTime
s
tamp
(
track
->
_type
);
track
->
_time_stamp
=
pMediaSrc
->
getTime
S
tamp
(
track
->
_type
);
}
return
true
;
}
...
...
src/Rtsp/RtspToRtmpMediaSource.h
查看文件 @
8f8eda93
...
...
@@ -72,13 +72,6 @@ public:
return
getRing
()
->
readerCount
()
+
(
_pRtmpSrc
?
_pRtmpSrc
->
getRing
()
->
readerCount
()
:
0
);
}
void
updateTimeStamp
(
uint32_t
uiStamp
)
{
auto
tracks
=
_sdpAttr
.
getAvailableTrack
();
for
(
auto
&
track
:
tracks
)
{
track
->
_time_stamp
=
uiStamp
*
(
track
->
_samplerate
/
1000
.
0
);
}
}
protected
:
void
onGetH264
(
const
H264Frame
&
frame
);
void
onGetAAC
(
const
AACFrame
&
frame
);
...
...
src/RtspMuxer/AACRtpCodec.cpp
查看文件 @
8f8eda93
...
...
@@ -36,8 +36,7 @@ AACRtpEncoder::AACRtpEncoder(uint32_t ui32Ssrc,
ui32MtuSize
,
ui32SampleRate
,
ui8PlayloadType
,
ui8Interleaved
),
AACRtpDecoder
(
ui32SampleRate
){
ui8Interleaved
){
}
void
AACRtpEncoder
::
inputFrame
(
const
Frame
::
Ptr
&
frame
)
{
...
...
@@ -74,8 +73,7 @@ void AACRtpEncoder::inputFrame(const Frame::Ptr &frame) {
void
AACRtpEncoder
::
makeAACRtp
(
const
void
*
pData
,
unsigned
int
uiLen
,
bool
bMark
,
uint32_t
uiStamp
)
{
uint16_t
u16RtpLen
=
uiLen
+
12
;
_ui32TimeStamp
=
(
_ui32SampleRate
/
1000
)
*
uiStamp
;
uint32_t
ts
=
htonl
(
_ui32TimeStamp
);
uint32_t
ts
=
htonl
((
_ui32SampleRate
/
1000
)
*
uiStamp
);
uint16_t
sq
=
htons
(
_ui16Sequence
);
uint32_t
sc
=
htonl
(
_ui32Ssrc
);
auto
pRtppkt
=
ResourcePoolHelper
<
RtpPacket
>::
obtainObj
();
...
...
@@ -99,19 +97,19 @@ void AACRtpEncoder::makeAACRtp(const void *pData, unsigned int uiLen, bool bMark
rtppkt
.
mark
=
bMark
;
rtppkt
.
length
=
uiLen
+
16
;
rtppkt
.
sequence
=
_ui16Sequence
;
rtppkt
.
timeStamp
=
_ui32Time
Stamp
;
rtppkt
.
timeStamp
=
ui
Stamp
;
rtppkt
.
ssrc
=
_ui32Ssrc
;
rtppkt
.
type
=
TrackAudio
;
rtppkt
.
offset
=
16
;
RtpCodec
::
inputRtp
(
pRtppkt
,
false
);
_ui16Sequence
++
;
_ui32TimeStamp
=
uiStamp
;
}
/////////////////////////////////////////////////////////////////////////////////////
AACRtpDecoder
::
AACRtpDecoder
(
uint32_t
ui32SampleRate
)
{
AACRtpDecoder
::
AACRtpDecoder
()
{
_adts
=
obtainFrame
();
_sampleRate
=
ui32SampleRate
;
}
AACFrame
::
Ptr
AACRtpDecoder
::
obtainFrame
()
{
...
...
@@ -135,7 +133,7 @@ bool AACRtpDecoder::inputRtp(const RtpPacket::Ptr &rtppack, bool key_pos) {
_adts
->
aac_frame_length
+=
(
length
-
4
);
if
(
rtppack
->
mark
==
true
)
{
_adts
->
sequence
=
rtppack
->
sequence
;
_adts
->
timeStamp
=
rtppack
->
timeStamp
*
(
1000.0
/
_sampleRate
)
;
_adts
->
timeStamp
=
rtppack
->
timeStamp
;
writeAdtsHeader
(
*
_adts
,
_adts
->
buffer
);
onGetAAC
(
_adts
);
}
...
...
src/RtspMuxer/AACRtpCodec.h
查看文件 @
8f8eda93
...
...
@@ -37,10 +37,7 @@ class AACRtpDecoder : public RtpCodec , public ResourcePoolHelper<AACFrame> {
public
:
typedef
std
::
shared_ptr
<
AACRtpDecoder
>
Ptr
;
/**
* @param ui32SampleRate 采样率,用于时间戳转换用
*/
AACRtpDecoder
(
uint32_t
ui32SampleRate
);
AACRtpDecoder
();
~
AACRtpDecoder
()
{}
/**
...
...
@@ -62,7 +59,6 @@ private:
AACFrame
::
Ptr
obtainFrame
();
private
:
AACFrame
::
Ptr
_adts
;
uint32_t
_sampleRate
;
};
...
...
src/RtspMuxer/H264RtpCodec.cpp
查看文件 @
8f8eda93
...
...
@@ -101,7 +101,7 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
_h264frame
->
buffer
.
assign
(
"\x0\x0\x0\x1"
,
4
);
_h264frame
->
buffer
.
append
((
char
*
)
frame
,
length
);
_h264frame
->
type
=
nal
.
type
;
_h264frame
->
timeStamp
=
rtppack
->
timeStamp
/
90
;
_h264frame
->
timeStamp
=
rtppack
->
timeStamp
;
_h264frame
->
sequence
=
rtppack
->
sequence
;
auto
isIDR
=
_h264frame
->
type
==
5
;
onGetH264
(
_h264frame
);
...
...
@@ -119,7 +119,7 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
_h264frame
->
buffer
.
push_back
(
tmp
);
_h264frame
->
buffer
.
append
((
char
*
)
frame
+
2
,
length
-
2
);
_h264frame
->
type
=
fu
.
type
;
_h264frame
->
timeStamp
=
rtppack
->
timeStamp
/
90
;
_h264frame
->
timeStamp
=
rtppack
->
timeStamp
;
_h264frame
->
sequence
=
rtppack
->
sequence
;
return
(
_h264frame
->
type
==
5
);
//i frame
}
...
...
@@ -133,7 +133,7 @@ bool H264RtpDecoder::decodeRtp(const RtpPacket::Ptr &rtppack) {
if
(
fu
.
E
==
1
)
{
//FU-A end
_h264frame
->
buffer
.
append
((
char
*
)
frame
+
2
,
length
-
2
);
_h264frame
->
timeStamp
=
rtppack
->
timeStamp
/
90
;
_h264frame
->
timeStamp
=
rtppack
->
timeStamp
;
auto
isIDR
=
_h264frame
->
type
==
5
;
onGetH264
(
_h264frame
);
return
isIDR
;
...
...
@@ -227,8 +227,7 @@ void H264RtpEncoder::inputFrame(const Frame::Ptr &frame) {
void
H264RtpEncoder
::
makeH264Rtp
(
const
void
*
data
,
unsigned
int
len
,
bool
mark
,
uint32_t
uiStamp
)
{
uint16_t
ui16RtpLen
=
len
+
12
;
_ui32TimeStamp
=
(
_ui32SampleRate
/
1000
)
*
uiStamp
;
uint32_t
ts
=
htonl
(
_ui32TimeStamp
);
uint32_t
ts
=
htonl
((
_ui32SampleRate
/
1000
)
*
uiStamp
);
uint16_t
sq
=
htons
(
_ui16Sequence
);
uint32_t
sc
=
htonl
(
_ui32Ssrc
);
...
...
@@ -252,7 +251,7 @@ void H264RtpEncoder::makeH264Rtp(const void* data, unsigned int len, bool mark,
rtppkt
->
mark
=
mark
;
rtppkt
->
length
=
len
+
16
;
rtppkt
->
sequence
=
_ui16Sequence
;
rtppkt
->
timeStamp
=
_ui32Time
Stamp
;
rtppkt
->
timeStamp
=
ui
Stamp
;
rtppkt
->
ssrc
=
_ui32Ssrc
;
rtppkt
->
type
=
TrackVideo
;
rtppkt
->
offset
=
16
;
...
...
@@ -260,6 +259,7 @@ void H264RtpEncoder::makeH264Rtp(const void* data, unsigned int len, bool mark,
uint8_t
type
=
((
uint8_t
*
)
(
data
))[
0
]
&
0x1F
;
RtpCodec
::
inputRtp
(
rtppkt
,
type
==
5
);
_ui16Sequence
++
;
_ui32TimeStamp
=
uiStamp
;
}
}
//
namespace
mediakit
\ No newline at end of file
src/RtspMuxer/RtpCodec.h
查看文件 @
8f8eda93
...
...
@@ -42,6 +42,7 @@ public:
uint8_t
PT
;
bool
mark
;
uint32_t
length
;
//时间戳,单位毫秒
uint32_t
timeStamp
;
uint16_t
sequence
;
uint32_t
ssrc
;
...
...
src/RtspMuxer/RtpMakerAAC.cpp
查看文件 @
8f8eda93
...
...
@@ -62,8 +62,7 @@ void RtpMaker_AAC::makeRtp(const char *pcData, int iLen, uint32_t uiStamp) {
inline
void
RtpMaker_AAC
::
makeAACRtp
(
const
void
*
pData
,
unsigned
int
uiLen
,
bool
bMark
,
uint32_t
uiStamp
)
{
uint16_t
u16RtpLen
=
uiLen
+
12
;
_ui32TimeStamp
=
(
_ui32SampleRate
/
1000
)
*
uiStamp
;
uint32_t
ts
=
htonl
(
_ui32TimeStamp
);
uint32_t
ts
=
htonl
((
_ui32SampleRate
/
1000
)
*
uiStamp
);
uint16_t
sq
=
htons
(
_ui16Sequence
);
uint32_t
sc
=
htonl
(
_ui32Ssrc
);
auto
pRtppkt
=
obtainPkt
();
...
...
@@ -87,13 +86,14 @@ inline void RtpMaker_AAC::makeAACRtp(const void *pData, unsigned int uiLen, bool
rtppkt
.
mark
=
bMark
;
rtppkt
.
length
=
uiLen
+
16
;
rtppkt
.
sequence
=
_ui16Sequence
;
rtppkt
.
timeStamp
=
_ui32Time
Stamp
;
rtppkt
.
timeStamp
=
ui
Stamp
;
rtppkt
.
ssrc
=
_ui32Ssrc
;
rtppkt
.
type
=
TrackAudio
;
rtppkt
.
offset
=
16
;
onMakeRtp
(
pRtppkt
,
false
);
_ui16Sequence
++
;
_ui32TimeStamp
=
uiStamp
;
}
}
//
namespace
mediakit
\ No newline at end of file
src/RtspMuxer/RtpMakerH264.cpp
查看文件 @
8f8eda93
...
...
@@ -78,8 +78,7 @@ void RtpMaker_H264::makeRtp(const char* pcData, int iLen, uint32_t uiStamp) {
inline
void
RtpMaker_H264
::
makeH264Rtp
(
const
void
*
data
,
unsigned
int
len
,
bool
mark
,
uint32_t
uiStamp
)
{
uint16_t
ui16RtpLen
=
len
+
12
;
_ui32TimeStamp
=
(
_ui32SampleRate
/
1000
)
*
uiStamp
;
uint32_t
ts
=
htonl
(
_ui32TimeStamp
);
uint32_t
ts
=
htonl
((
_ui32SampleRate
/
1000
)
*
uiStamp
);
uint16_t
sq
=
htons
(
_ui16Sequence
);
uint32_t
sc
=
htonl
(
_ui32Ssrc
);
...
...
@@ -104,7 +103,7 @@ inline void RtpMaker_H264::makeH264Rtp(const void* data, unsigned int len, bool
rtppkt
.
mark
=
mark
;
rtppkt
.
length
=
len
+
16
;
rtppkt
.
sequence
=
_ui16Sequence
;
rtppkt
.
timeStamp
=
_ui32Time
Stamp
;
rtppkt
.
timeStamp
=
ui
Stamp
;
rtppkt
.
ssrc
=
_ui32Ssrc
;
rtppkt
.
type
=
TrackVideo
;
rtppkt
.
offset
=
16
;
...
...
@@ -112,6 +111,7 @@ inline void RtpMaker_H264::makeH264Rtp(const void* data, unsigned int len, bool
uint8_t
type
=
((
uint8_t
*
)
(
data
))[
0
]
&
0x1F
;
onMakeRtp
(
pRtppkt
,
type
==
5
);
_ui16Sequence
++
;
_ui32TimeStamp
=
uiStamp
;
//InfoL<<timeStamp<<" "<<time<<" "<<sampleRate;
}
...
...
src/RtspMuxer/RtspDemuxer.cpp
查看文件 @
8f8eda93
...
...
@@ -105,7 +105,7 @@ void RtspDemuxer::makeAudioTrack(const SdpTrack::Ptr &audio) {
_audioTrack
=
dynamic_pointer_cast
<
AudioTrack
>
(
Factory
::
getTrackBySdp
(
audio
));
if
(
_audioTrack
){
//生成RtpCodec对象以便解码rtp
_audioRtpDecoder
=
Factory
::
getRtpDecoderById
(
_audioTrack
->
getCodecId
()
,
_audioTrack
->
getAudioSampleRate
()
);
_audioRtpDecoder
=
Factory
::
getRtpDecoderById
(
_audioTrack
->
getCodecId
());
if
(
_audioRtpDecoder
){
//设置rtp解码器代理,生成的frame写入该Track
_audioRtpDecoder
->
setDelegate
(
_audioTrack
);
...
...
@@ -121,7 +121,7 @@ void RtspDemuxer::makeVideoTrack(const SdpTrack::Ptr &video) {
_videoTrack
=
dynamic_pointer_cast
<
VideoTrack
>
(
Factory
::
getTrackBySdp
(
video
));
if
(
_videoTrack
){
//生成RtpCodec对象以便解码rtp
_videoRtpDecoder
=
Factory
::
getRtpDecoderById
(
_videoTrack
->
getCodecId
()
,
90000
);
_videoRtpDecoder
=
Factory
::
getRtpDecoderById
(
_videoTrack
->
getCodecId
());
if
(
_videoRtpDecoder
){
//设置rtp解码器代理,生成的frame写入该Track
_videoRtpDecoder
->
setDelegate
(
_videoTrack
);
...
...
src/RtspMuxer/RtspMediaSourceMuxer.h
查看文件 @
8f8eda93
...
...
@@ -48,6 +48,12 @@ public:
void
setListener
(
const
std
::
weak_ptr
<
MediaSourceEvent
>
&
listener
){
_mediaSouce
->
setListener
(
listener
);
}
int
readerCount
()
const
{
return
_mediaSouce
->
getRing
()
->
readerCount
();
}
void
updateTimeStamp
(
uint32_t
stamp
){
_mediaSouce
->
updateTimeStamp
(
stamp
);
}
private
:
void
onInited
()
override
{
_mediaSouce
->
onGetSDP
(
getSdp
());
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论