修正rtmp绝对时间戳的bug

This commit is contained in:
xiongziliang 2017-05-17 11:52:59 +08:00
parent e7837a19ad
commit c2d5f5abed
5 changed files with 19 additions and 33 deletions

View File

@ -210,7 +210,7 @@ void RtmpProtocol::startClientSession(const function<void()> &callBack) {
//发送 C0C1
char handshake_head = HANDSHAKE_PLAINTEXT;
onSendRawData(&handshake_head, 1);
RtmpHandshake c1(::time(NULL));
RtmpHandshake c1(0);
onSendRawData((char *) (&c1), sizeof(c1));
m_nextHandle = [this,callBack]() {
//等待 S0+S1+S2
@ -388,7 +388,7 @@ void RtmpProtocol::send_complex_S0S1S2(int schemeType,const string &digest){
char handshake_head = HANDSHAKE_PLAINTEXT;
onSendRawData(&handshake_head, 1);
//S1
RtmpHandshake s1(time(NULL));
RtmpHandshake s1(0);
memcpy(s1.zero,"\x04\x05\x00\x01",4);
char *digestPos;
if(schemeType == 0){

View File

@ -342,7 +342,20 @@ void RtmpSession::onCmd_seek(AMFDecoder &dec) {
}
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 */

View File

@ -46,6 +46,7 @@ private:
std::shared_ptr<RtmpMediaSource> m_pPublisherSrc;
bool m_bPublisherSrcRegisted = false;
std::weak_ptr<RtmpMediaSource> m_pPlayerSrc;
uint32_t m_aui32FirstStamp[2] = {0};
void onProcessCmd(AMFDecoder &dec);
void onCmd_connect(AMFDecoder &dec);

View File

@ -118,20 +118,7 @@ void RtspToRtmpMediaSource::onGetH264(const H264Frame& frame) {
m_rtmpPkt.bodySize = m_rtmpPkt.strBuf.size();
m_rtmpPkt.chunkId = CHUNK_MEDIA;
m_rtmpPkt.streamId = STREAM_MEDIA;
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.timeStamp = frame.timeStamp;
m_rtmpPkt.typeId = MSG_VIDEO;
m_pRtmpSrc->onGetMedia(m_rtmpPkt);
}
@ -150,20 +137,7 @@ void RtspToRtmpMediaSource::onGetAdts(const AdtsFrame& frame) {
m_rtmpPkt.bodySize = m_rtmpPkt.strBuf.size();
m_rtmpPkt.chunkId = CHUNK_MEDIA;
m_rtmpPkt.streamId = STREAM_MEDIA;
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.timeStamp = frame.timeStamp;
m_rtmpPkt.typeId = MSG_AUDIO;
m_pRtmpSrc->onGetMedia(m_rtmpPkt);
}

View File

@ -84,8 +84,6 @@ private:
RtmpMediaSource::Ptr m_pRtmpSrc;
RtmpPacket m_rtmpPkt;
uint8_t m_ui8AudioFlags = 0;
//首次时间戳m_aui32FirstStamp[0]:视频m_aui32FirstStamp[1]:音频
uint32_t m_aui32FirstStamp[2] = {0,0};
MediaRecorder::Ptr m_pRecorder;
bool m_bEnableFile = true;
void onGetH264(const H264Frame &frame);