mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 12:37:09 +08:00
修正rtmp绝对时间戳的bug
This commit is contained in:
parent
e7837a19ad
commit
c2d5f5abed
@ -210,7 +210,7 @@ void RtmpProtocol::startClientSession(const function<void()> &callBack) {
|
|||||||
//发送 C0C1
|
//发送 C0C1
|
||||||
char handshake_head = HANDSHAKE_PLAINTEXT;
|
char handshake_head = HANDSHAKE_PLAINTEXT;
|
||||||
onSendRawData(&handshake_head, 1);
|
onSendRawData(&handshake_head, 1);
|
||||||
RtmpHandshake c1(::time(NULL));
|
RtmpHandshake c1(0);
|
||||||
onSendRawData((char *) (&c1), sizeof(c1));
|
onSendRawData((char *) (&c1), sizeof(c1));
|
||||||
m_nextHandle = [this,callBack]() {
|
m_nextHandle = [this,callBack]() {
|
||||||
//等待 S0+S1+S2
|
//等待 S0+S1+S2
|
||||||
@ -388,7 +388,7 @@ void RtmpProtocol::send_complex_S0S1S2(int schemeType,const string &digest){
|
|||||||
char handshake_head = HANDSHAKE_PLAINTEXT;
|
char handshake_head = HANDSHAKE_PLAINTEXT;
|
||||||
onSendRawData(&handshake_head, 1);
|
onSendRawData(&handshake_head, 1);
|
||||||
//S1
|
//S1
|
||||||
RtmpHandshake s1(time(NULL));
|
RtmpHandshake s1(0);
|
||||||
memcpy(s1.zero,"\x04\x05\x00\x01",4);
|
memcpy(s1.zero,"\x04\x05\x00\x01",4);
|
||||||
char *digestPos;
|
char *digestPos;
|
||||||
if(schemeType == 0){
|
if(schemeType == 0){
|
||||||
|
@ -342,7 +342,20 @@ void RtmpSession::onCmd_seek(AMFDecoder &dec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RtmpSession::onSendMedia(const RtmpPacket& pkt) {
|
void RtmpSession::onSendMedia(const RtmpPacket& pkt) {
|
||||||
sendRtmp(pkt.typeId, pkt.streamId, pkt.strBuf, pkt.timeStamp, pkt.chunkId);
|
auto modifiedStamp = pkt.timeStamp;
|
||||||
|
auto &firstStamp = m_aui32FirstStamp[pkt.typeId % 2];
|
||||||
|
if(!firstStamp){
|
||||||
|
firstStamp = modifiedStamp;
|
||||||
|
}
|
||||||
|
if(modifiedStamp >= firstStamp){
|
||||||
|
//计算时间戳增量
|
||||||
|
modifiedStamp -= firstStamp;
|
||||||
|
}else{
|
||||||
|
//发生回环,重新计算时间戳增量
|
||||||
|
CLEAR_ARR(m_aui32FirstStamp);
|
||||||
|
modifiedStamp = 0;
|
||||||
|
}
|
||||||
|
sendRtmp(pkt.typeId, pkt.streamId, pkt.strBuf, modifiedStamp, pkt.chunkId);
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace Rtmp */
|
} /* namespace Rtmp */
|
||||||
|
@ -46,6 +46,7 @@ private:
|
|||||||
std::shared_ptr<RtmpMediaSource> m_pPublisherSrc;
|
std::shared_ptr<RtmpMediaSource> m_pPublisherSrc;
|
||||||
bool m_bPublisherSrcRegisted = false;
|
bool m_bPublisherSrcRegisted = false;
|
||||||
std::weak_ptr<RtmpMediaSource> m_pPlayerSrc;
|
std::weak_ptr<RtmpMediaSource> m_pPlayerSrc;
|
||||||
|
uint32_t m_aui32FirstStamp[2] = {0};
|
||||||
|
|
||||||
void onProcessCmd(AMFDecoder &dec);
|
void onProcessCmd(AMFDecoder &dec);
|
||||||
void onCmd_connect(AMFDecoder &dec);
|
void onCmd_connect(AMFDecoder &dec);
|
||||||
|
@ -118,20 +118,7 @@ void RtspToRtmpMediaSource::onGetH264(const H264Frame& frame) {
|
|||||||
m_rtmpPkt.bodySize = m_rtmpPkt.strBuf.size();
|
m_rtmpPkt.bodySize = m_rtmpPkt.strBuf.size();
|
||||||
m_rtmpPkt.chunkId = CHUNK_MEDIA;
|
m_rtmpPkt.chunkId = CHUNK_MEDIA;
|
||||||
m_rtmpPkt.streamId = STREAM_MEDIA;
|
m_rtmpPkt.streamId = STREAM_MEDIA;
|
||||||
|
m_rtmpPkt.timeStamp = frame.timeStamp;
|
||||||
if(!m_aui32FirstStamp[0]){
|
|
||||||
//记录首次时间戳
|
|
||||||
m_aui32FirstStamp[0] = frame.timeStamp;
|
|
||||||
}
|
|
||||||
if(frame.timeStamp >= m_aui32FirstStamp[0]){
|
|
||||||
//计算时间戳增量
|
|
||||||
m_rtmpPkt.timeStamp = frame.timeStamp - m_aui32FirstStamp[0];
|
|
||||||
}else{
|
|
||||||
//发生回环,重新计算时间戳增量
|
|
||||||
CLEAR_ARR(m_aui32FirstStamp);
|
|
||||||
m_rtmpPkt.timeStamp = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_rtmpPkt.typeId = MSG_VIDEO;
|
m_rtmpPkt.typeId = MSG_VIDEO;
|
||||||
m_pRtmpSrc->onGetMedia(m_rtmpPkt);
|
m_pRtmpSrc->onGetMedia(m_rtmpPkt);
|
||||||
}
|
}
|
||||||
@ -150,20 +137,7 @@ void RtspToRtmpMediaSource::onGetAdts(const AdtsFrame& frame) {
|
|||||||
m_rtmpPkt.bodySize = m_rtmpPkt.strBuf.size();
|
m_rtmpPkt.bodySize = m_rtmpPkt.strBuf.size();
|
||||||
m_rtmpPkt.chunkId = CHUNK_MEDIA;
|
m_rtmpPkt.chunkId = CHUNK_MEDIA;
|
||||||
m_rtmpPkt.streamId = STREAM_MEDIA;
|
m_rtmpPkt.streamId = STREAM_MEDIA;
|
||||||
|
m_rtmpPkt.timeStamp = frame.timeStamp;
|
||||||
if(!m_aui32FirstStamp[1]){
|
|
||||||
//记录首次时间戳
|
|
||||||
m_aui32FirstStamp[1] = frame.timeStamp;
|
|
||||||
}
|
|
||||||
if(frame.timeStamp >= m_aui32FirstStamp[1]){
|
|
||||||
//计算时间戳增量
|
|
||||||
m_rtmpPkt.timeStamp = frame.timeStamp - m_aui32FirstStamp[1];
|
|
||||||
}else{
|
|
||||||
//发生回环,重新计算时间戳增量
|
|
||||||
CLEAR_ARR(m_aui32FirstStamp);
|
|
||||||
m_rtmpPkt.timeStamp = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_rtmpPkt.typeId = MSG_AUDIO;
|
m_rtmpPkt.typeId = MSG_AUDIO;
|
||||||
m_pRtmpSrc->onGetMedia(m_rtmpPkt);
|
m_pRtmpSrc->onGetMedia(m_rtmpPkt);
|
||||||
}
|
}
|
||||||
|
@ -84,8 +84,6 @@ private:
|
|||||||
RtmpMediaSource::Ptr m_pRtmpSrc;
|
RtmpMediaSource::Ptr m_pRtmpSrc;
|
||||||
RtmpPacket m_rtmpPkt;
|
RtmpPacket m_rtmpPkt;
|
||||||
uint8_t m_ui8AudioFlags = 0;
|
uint8_t m_ui8AudioFlags = 0;
|
||||||
//首次时间戳,m_aui32FirstStamp[0]:视频,m_aui32FirstStamp[1]:音频
|
|
||||||
uint32_t m_aui32FirstStamp[2] = {0,0};
|
|
||||||
MediaRecorder::Ptr m_pRecorder;
|
MediaRecorder::Ptr m_pRecorder;
|
||||||
bool m_bEnableFile = true;
|
bool m_bEnableFile = true;
|
||||||
void onGetH264(const H264Frame &frame);
|
void onGetH264(const H264Frame &frame);
|
||||||
|
Loading…
Reference in New Issue
Block a user