From dca157228ef30e8ef8176c60443dd502a7bef8fe Mon Sep 17 00:00:00 2001 From: Thulinma Date: Sat, 30 Dec 2017 00:44:58 +0100 Subject: [PATCH] Fixed RTMP implementation to match 2012 spec update and not 2009 original spec --- lib/rtmpchunks.cpp | 2 +- src/output/output_rtmp.cpp | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/rtmpchunks.cpp b/lib/rtmpchunks.cpp index c1d9582f..dc1bedb5 100644 --- a/lib/rtmpchunks.cpp +++ b/lib/rtmpchunks.cpp @@ -455,7 +455,7 @@ bool RTMPStream::Chunk::Parse(Socket::Buffer & buffer) { DEBUG_MSG(DLVL_DONTEVEN, "Parsing RTMP chunk result: len_left=%d, real_len=%d", len_left, real_len); //read extended timestamp, if necessary - if (ts_header == 0x00ffffff && headertype != 0xC0) { + if (ts_header == 0x00ffffff) { if (!buffer.available(i + 4)) { return false; } //can't read timestamp diff --git a/src/output/output_rtmp.cpp b/src/output/output_rtmp.cpp index 2de5e217..fc46a3c3 100644 --- a/src/output/output_rtmp.cpp +++ b/src/output/output_rtmp.cpp @@ -349,30 +349,40 @@ namespace Mist { //send the header myConn.setBlocking(true); myConn.SendNow(rtmpheader, header_len); + RTMPStream::snd_cnt += header_len; //update the sent data counter //set the header's first byte to the "continue" type chunk, for later use rtmpheader[0] = 0xC4; + if (timestamp >= 0x00ffffff){ + rtmpheader[1] = timestamp & 0xff; + rtmpheader[2] = (timestamp >> 8) & 0xff; + rtmpheader[3] = (timestamp >> 16) & 0xff; + rtmpheader[4] = (timestamp >> 24) & 0xff; + } //sent actual data - never send more than chunk_snd_max at a time //interleave blocks of max chunk_snd_max bytes with 0xC4 bytes to indicate continue unsigned int len_sent = 0; - unsigned int steps = 0; while (len_sent < data_len){ unsigned int to_send = std::min(data_len - len_sent, RTMPStream::chunk_snd_max); if (!len_sent){ myConn.SendNow(dataheader, dheader_len); + RTMPStream::snd_cnt += dheader_len; //update the sent data counter to_send -= dheader_len; len_sent += dheader_len; } myConn.SendNow(tmpData+len_sent-dheader_len, to_send); len_sent += to_send; if (len_sent < data_len){ - myConn.SendNow(rtmpheader, 1); - ++steps; + if (timestamp >= 0x00ffffff){ + myConn.SendNow(rtmpheader, 5); + RTMPStream::snd_cnt += 5; //update the sent data counter + }else{ + myConn.SendNow(rtmpheader, 1); + RTMPStream::snd_cnt += 1; //update the sent data counter + } } } myConn.setBlocking(false); - //update the sent data counter - RTMPStream::snd_cnt += header_len + data_len + steps; } void OutRTMP::sendHeader(){