From 14fa673df615d21e2d4ebe8afa2d5a0a8129641f Mon Sep 17 00:00:00 2001 From: Thulinma Date: Wed, 3 Oct 2018 23:55:16 +0200 Subject: [PATCH] Switched extended RTMP timestamps from big endian to little endian, to match most current-day implementations. --- lib/rtmpchunks.cpp | 18 +++++++++--------- src/output/output_rtmp.cpp | 14 +++++++------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/rtmpchunks.cpp b/lib/rtmpchunks.cpp index dc1bedb5..8a08caee 100644 --- a/lib/rtmpchunks.cpp +++ b/lib/rtmpchunks.cpp @@ -145,10 +145,10 @@ std::string & RTMPStream::Chunk::Pack() { } //support for 0x00ffffff timestamps if (ntime) { - output += (unsigned char)(ntime & 0xff); - output += (unsigned char)((ntime >> 8) & 0xff); - output += (unsigned char)((ntime >> 16) & 0xff); output += (unsigned char)((ntime >> 24) & 0xff); + output += (unsigned char)((ntime >> 16) & 0xff); + output += (unsigned char)((ntime >> 8) & 0xff); + output += (unsigned char)(ntime & 0xff); } len_left = 0; while (len_left < len) { @@ -172,10 +172,10 @@ std::string & RTMPStream::Chunk::Pack() { } } if (ntime) { - output += (unsigned char)(ntime & 0xff); - output += (unsigned char)((ntime >> 8) & 0xff); - output += (unsigned char)((ntime >> 16) & 0xff); output += (unsigned char)((ntime >> 24) & 0xff); + output += (unsigned char)((ntime >> 16) & 0xff); + output += (unsigned char)((ntime >> 8) & 0xff); + output += (unsigned char)(ntime & 0xff); } } } @@ -460,10 +460,10 @@ bool RTMPStream::Chunk::Parse(Socket::Buffer & buffer) { return false; } //can't read timestamp indata = buffer.copy(i + 4); - timestamp = indata[i++ ]; - timestamp += indata[i++ ] * 256; - timestamp += indata[i++ ] * 256 * 256; timestamp += indata[i++ ] * 256 * 256 * 256; + timestamp += indata[i++ ] * 256 * 256; + timestamp += indata[i++ ] * 256; + timestamp = indata[i++ ]; ts_delta = timestamp; DEBUG_MSG(DLVL_DONTEVEN, "Extended timestamp: %u", timestamp); } diff --git a/src/output/output_rtmp.cpp b/src/output/output_rtmp.cpp index 9f9f6d2f..141653ba 100644 --- a/src/output/output_rtmp.cpp +++ b/src/output/output_rtmp.cpp @@ -332,10 +332,10 @@ namespace Mist { rtmpheader[1] = 0xff; rtmpheader[2] = 0xff; rtmpheader[3] = 0xff; - rtmpheader[header_len++] = timestamp & 0xff; - rtmpheader[header_len++] = (timestamp >> 8) & 0xff; - rtmpheader[header_len++] = (timestamp >> 16) & 0xff; rtmpheader[header_len++] = (timestamp >> 24) & 0xff; + rtmpheader[header_len++] = (timestamp >> 16) & 0xff; + rtmpheader[header_len++] = (timestamp >> 8) & 0xff; + rtmpheader[header_len++] = timestamp & 0xff; }else{ //regular timestamp rtmpheader[1] = (timestamp >> 16) & 0xff; @@ -350,10 +350,10 @@ namespace Mist { //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; + rtmpheader[1] = (timestamp >> 24) & 0xff; + rtmpheader[2] = (timestamp >> 16) & 0xff; + rtmpheader[3] = (timestamp >> 8) & 0xff; + rtmpheader[4] = timestamp & 0xff; } //sent actual data - never send more than chunk_snd_max at a time