Fixed RTMP desync bug with Windows clients.

This commit is contained in:
Thulinma 2012-06-08 00:11:25 +02:00
parent ae057d3e78
commit 19c7081685
3 changed files with 7 additions and 11 deletions

View file

@ -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<unsigned int, RTMPStream::Chunk> 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

View file

@ -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{

View file

@ -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