From 19c708168573e8189ecc20141b02bd16416b9b8f Mon Sep 17 00:00:00 2001 From: Thulinma Date: Fri, 8 Jun 2012 00:11:25 +0200 Subject: [PATCH] Fixed RTMP desync bug with Windows clients. --- lib/rtmpchunks.cpp | 4 +--- lib/rtmpchunks.h | 1 - src/conn_rtmp.cpp | 13 ++++++------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/rtmpchunks.cpp b/lib/rtmpchunks.cpp index 6aa5f242..51a2e9dd 100644 --- a/lib/rtmpchunks.cpp +++ b/lib/rtmpchunks.cpp @@ -13,7 +13,7 @@ std::string RTMPStream::handshake_out;///< Output for the handshake. unsigned int RTMPStream::getNowMS(){ timeval t; gettimeofday(&t, 0); - return t.tv_sec + t.tv_usec/1000; + return t.tv_sec * 1000 + t.tv_usec/1000; }//RTMPStream::getNowMS @@ -27,7 +27,6 @@ unsigned int RTMPStream::rec_cnt = 0; unsigned int RTMPStream::snd_cnt = 0; timeval RTMPStream::lastrec; -unsigned int RTMPStream::firsttime; /// Holds the last sent chunk for every msg_id. std::map RTMPStream::Chunk::lastsend; @@ -42,7 +41,6 @@ std::string RTMPStream::Chunk::Pack(){ RTMPStream::Chunk prev = lastsend[cs_id]; unsigned int tmpi; unsigned char chtype = 0x00; - //timestamp -= firsttime; if ((prev.msg_type_id > 0) && (prev.cs_id == cs_id)){ if (msg_stream_id == prev.msg_stream_id){ chtype = 0x40;//do not send msg_stream_id diff --git a/lib/rtmpchunks.h b/lib/rtmpchunks.h index ff4eee4a..009cfd29 100644 --- a/lib/rtmpchunks.h +++ b/lib/rtmpchunks.h @@ -30,7 +30,6 @@ namespace RTMPStream{ extern unsigned int snd_cnt; ///< Counter for total data sent, in bytes. extern timeval lastrec; ///< Timestamp of last time data was received. - extern unsigned int firsttime; ///< Timestamp of first time a chunk was sent. /// Holds a single RTMP chunk, either send or receive direction. class Chunk{ diff --git a/src/conn_rtmp.cpp b/src/conn_rtmp.cpp index bc9abc3a..1ca51817 100644 --- a/src/conn_rtmp.cpp +++ b/src/conn_rtmp.cpp @@ -42,9 +42,6 @@ int Connector_RTMP::Connector_RTMP(Socket::Connection conn){ DTSC::Stream Strm; bool stream_inited = false;//true if init data for audio/video was sent - //first timestamp set - RTMPStream::firsttime = RTMPStream::getNowMS(); - RTMPStream::handshake_in.reserve(1537); Socket.read((char*)RTMPStream::handshake_in.c_str(), 1537); RTMPStream::rec_cnt += 1537; @@ -96,22 +93,24 @@ int Connector_RTMP::Connector_RTMP(Socket::Connection conn){ } } if (SS.spool()){ - if (Strm.parsePacket(SS.Received())){ + while (Strm.parsePacket(SS.Received())){ //sent init data if needed if (!stream_inited){ + init_tag.DTSCMetaInit(Strm); + Socket.Send(RTMPStream::SendMedia(init_tag)); if (Strm.metadata.getContentP("audio") && Strm.metadata.getContentP("audio")->getContentP("init")){ init_tag.DTSCAudioInit(Strm); - Socket.write(RTMPStream::SendMedia(init_tag)); + Socket.Send(RTMPStream::SendMedia(init_tag)); } if (Strm.metadata.getContentP("video") && Strm.metadata.getContentP("video")->getContentP("init")){ init_tag.DTSCVideoInit(Strm); - Socket.write(RTMPStream::SendMedia(init_tag)); + Socket.Send(RTMPStream::SendMedia(init_tag)); } stream_inited = true; } //sent a tag tag.DTSCLoader(Strm); - Socket.write(RTMPStream::SendMedia(tag)); + Socket.Send(RTMPStream::SendMedia(tag)); #if DEBUG >= 8 fprintf(stderr, "Sent tag to %i: [%u] %s\n", Socket.getSocket(), tag.tagTime(), tag.tagType().c_str()); #endif