diff --git a/Connector_RTMP/main.cpp b/Connector_RTMP/main.cpp index 6fe57bfe..8d50081d 100644 --- a/Connector_RTMP/main.cpp +++ b/Connector_RTMP/main.cpp @@ -53,6 +53,7 @@ int Connector_RTMP::Connector_RTMP(DDV::Socket conn){ while (RTMPStream::handshake_in.size() < 1537){ Socket.read(RTMPStream::handshake_in); } + RTMPStream::rec_cnt += 1537; if (RTMPStream::doHandshake()){ Socket.write(RTMPStream::handshake_out); Socket.read((char*)RTMPStream::handshake_in.c_str(), 1536); @@ -161,7 +162,8 @@ void Connector_RTMP::parseChunk(){ static AMF::Object amfdata("empty", AMF::AMF0_DDV_CONTAINER); static AMF::Object amfelem("empty", AMF::AMF0_DDV_CONTAINER); if (!Connector_RTMP::Socket.read(inbuffer)){return;} //try to get more data - + + fprintf(stderr, "Current buffer is %i long.\n", inbuffer.size()); while (next.Parse(inbuffer)){ //send ACK if we received a whole window @@ -172,6 +174,9 @@ void Connector_RTMP::parseChunk(){ switch (next.msg_type_id){ case 0://does not exist + #if DEBUG >= 2 + fprintf(stderr, "UNKN: Received a zero-type message. This is an error.\n"); + #endif break;//happens when connection breaks unexpectedly case 1://set chunk size RTMPStream::chunk_rec_max = ntohl(*(int*)next.data.c_str()); @@ -387,7 +392,7 @@ void Connector_RTMP::parseChunk(){ // amfreply.addContent(AMFType("", (double)1, 0x01));//bool true - audioaccess // amfreply.addContent(AMFType("", (double)1, 0x01));//bool true - videoaccess // SendChunk(4, 20, next.msg_stream_id, amfreply.Pack()); - RTMPStream::chunk_snd_max = 1024*1024; + RTMPStream::chunk_snd_max = 65536;//1024*1024; Socket.write(RTMPStream::SendCTL(1, RTMPStream::chunk_snd_max));//send chunk size max (msg 1) Connector_RTMP::ready4data = true;//start sending video data! parsed = true; diff --git a/util/rtmpchunks.cpp b/util/rtmpchunks.cpp index d297b5e5..eca2f9fb 100644 --- a/util/rtmpchunks.cpp +++ b/util/rtmpchunks.cpp @@ -249,15 +249,17 @@ std::string RTMPStream::SendUSR(unsigned char type, unsigned int data, unsigned bool RTMPStream::Chunk::Parse(std::string & indata){ gettimeofday(&RTMPStream::lastrec, 0); unsigned int i = 0; - if (indata.size() < 3) return false;//need at least 3 bytes to continue + if (indata.size() < 1) return false;//need at least a byte unsigned char chunktype = indata[i++]; //read the chunkstream ID properly switch (chunktype & 0x3F){ case 0: + if (indata.size() < 2) return false;//need at least 2 bytes to continue cs_id = indata[i++] + 64; break; case 1: + if (indata.size() < 3) return false;//need at least 3 bytes to continue cs_id = indata[i++] + 64; cs_id += indata[i++] * 256; break; @@ -265,7 +267,7 @@ bool RTMPStream::Chunk::Parse(std::string & indata){ cs_id = chunktype & 0x3F; break; } - + RTMPStream::Chunk prev = lastrecv[cs_id]; //process the rest of the header, for each chunk type @@ -336,7 +338,7 @@ bool RTMPStream::Chunk::Parse(std::string & indata){ timestamp += indata[i++]*256; timestamp += indata[i++]; } - + //read data if length > 0, and allocate it if (real_len > 0){ if (prev.len_left > 0){ @@ -352,7 +354,7 @@ bool RTMPStream::Chunk::Parse(std::string & indata){ if (len_left == 0){ return true; }else{ - return false; + return Parse(indata); } }else{ data = "";