Improved RTMP cross-server compatibility

This commit is contained in:
Thulinma 2019-12-06 13:29:26 +01:00
parent 771fad390a
commit a8c7bc5d27
3 changed files with 14 additions and 6 deletions

View file

@ -250,7 +250,7 @@ std::string &RTMPStream::SendMedia(FLV::Tag &tag){
std::string &RTMPStream::SendCTL(unsigned char type, unsigned int data){
static RTMPStream::Chunk ch;
ch.cs_id = 2;
ch.timestamp = Util::getMS();
ch.timestamp = 0;
ch.msg_type_id = type;
ch.msg_stream_id = 0;
ch.len_left = 0;
@ -265,6 +265,7 @@ std::string &RTMPStream::SendCTL(unsigned char type, unsigned int data){
ch.data.resize(4);
}
*(int *)((char *)ch.data.data()) = htonl(data);
lastsend.erase(2u);
return ch.Pack();
}// SendCTL
@ -272,7 +273,7 @@ std::string &RTMPStream::SendCTL(unsigned char type, unsigned int data){
std::string &RTMPStream::SendCTL(unsigned char type, unsigned int data, unsigned char data2){
static RTMPStream::Chunk ch;
ch.cs_id = 2;
ch.timestamp = Util::getMS();
ch.timestamp = 0;
ch.len = 5;
ch.real_len = 5;
ch.len_left = 0;
@ -281,6 +282,7 @@ std::string &RTMPStream::SendCTL(unsigned char type, unsigned int data, unsigned
ch.data.resize(5);
*(unsigned int *)((char *)ch.data.c_str()) = htonl(data);
ch.data[4] = data2;
lastsend.erase(2u);
return ch.Pack();
}// SendCTL
@ -288,7 +290,7 @@ std::string &RTMPStream::SendCTL(unsigned char type, unsigned int data, unsigned
std::string &RTMPStream::SendUSR(unsigned char type, unsigned int data){
static RTMPStream::Chunk ch;
ch.cs_id = 2;
ch.timestamp = Util::getMS();
ch.timestamp = 0;
ch.len = 6;
ch.real_len = 6;
ch.len_left = 0;
@ -298,6 +300,7 @@ std::string &RTMPStream::SendUSR(unsigned char type, unsigned int data){
*(unsigned int *)(((char *)ch.data.c_str()) + 2) = htonl(data);
ch.data[0] = 0;
ch.data[1] = type;
lastsend.erase(2u);
return ch.Pack();
}// SendUSR
@ -305,7 +308,7 @@ std::string &RTMPStream::SendUSR(unsigned char type, unsigned int data){
std::string &RTMPStream::SendUSR(unsigned char type, unsigned int data, unsigned int data2){
static RTMPStream::Chunk ch;
ch.cs_id = 2;
ch.timestamp = Util::getMS();
ch.timestamp = 0;
ch.len = 10;
ch.real_len = 10;
ch.len_left = 0;
@ -316,6 +319,7 @@ std::string &RTMPStream::SendUSR(unsigned char type, unsigned int data, unsigned
*(unsigned int *)(((char *)ch.data.c_str()) + 6) = htonl(data2);
ch.data[0] = 0;
ch.data[1] = type;
lastsend.erase(2u);
return ch.Pack();
}// SendUSR

View file

@ -13,6 +13,7 @@
namespace Mist{
OutRTMP::OutRTMP(Socket::Connection &conn) : Output(conn){
lastAck = Util::bootSecs();
lastOutTime = 0;
setRtmpOffset = false;
rtmpOffset = 0;
@ -1151,7 +1152,8 @@ namespace Mist{
while (next.Parse(inputBuffer)){
// send ACK if we received a whole window
if ((RTMPStream::rec_cnt - RTMPStream::rec_window_at > RTMPStream::rec_window_size)){
if ((RTMPStream::rec_cnt - RTMPStream::rec_window_at > RTMPStream::rec_window_size) || Util::bootSecs() > lastAck+15){
lastAck = Util::bootSecs();
RTMPStream::rec_window_at = RTMPStream::rec_cnt;
myConn.SendNow(RTMPStream::SendCTL(3, RTMPStream::rec_cnt)); // send ack (msg 3)
}
@ -1203,7 +1205,7 @@ namespace Mist{
break;
case 6:
MEDIUM_MSG("CTRL: UCM PingRequest %" PRIu32, Bit::btohl(next.data.data() + 2));
myConn.SendNow(RTMPStream::SendUSR(7, 1)); // send UCM PingResponse (7)
myConn.SendNow(RTMPStream::SendUSR(7, Bit::btohl(next.data.data() + 2))); // send UCM PingResponse (7)
break;
case 7:
MEDIUM_MSG("CTRL: UCM PingResponse %" PRIu32, Bit::btohl(next.data.data() + 2));
@ -1216,6 +1218,7 @@ namespace Mist{
RTMPStream::rec_window_size = Bit::btohl(next.data.data());
RTMPStream::rec_window_at = RTMPStream::rec_cnt;
myConn.SendNow(RTMPStream::SendCTL(3, RTMPStream::rec_cnt)); // send ack (msg 3)
lastAck = Util::bootSecs();
break;
case 6:
MEDIUM_MSG("CTRL: Set peer bandwidth");

View file

@ -29,6 +29,7 @@ namespace Mist{
void parseAMFCommand(AMF::Object &amfData, int messageType, int streamId);
void sendCommand(AMF::Object &amfReply, int messageType, int streamId);
void startPushOut(const char *args);
uint64_t lastAck;
HTTP::URL pushApp, pushUrl;
uint8_t authAttempts;
};