Fixed several FLV-related server bugs.
This commit is contained in:
parent
32880330fd
commit
5fb7e235b5
3 changed files with 54 additions and 26 deletions
|
@ -362,7 +362,7 @@ namespace Buffer{
|
||||||
if (tmp != ""){
|
if (tmp != ""){
|
||||||
if (tmp[0] == 'P'){
|
if (tmp[0] == 'P'){
|
||||||
std::cout << "Push attempt from IP " << tmp.substr(2) << std::endl;
|
std::cout << "Push attempt from IP " << tmp.substr(2) << std::endl;
|
||||||
if (tmp.substr(2) == waiting_ip){
|
if (tmp.substr(2) == waiting_ip || tmp.substr(2) == "::ffff:"+waiting_ip){
|
||||||
if (!ip_input.connected()){
|
if (!ip_input.connected()){
|
||||||
std::cout << "Push accepted!" << std::endl;
|
std::cout << "Push accepted!" << std::endl;
|
||||||
ip_input = (*usersIt).S;
|
ip_input = (*usersIt).S;
|
||||||
|
@ -372,7 +372,7 @@ namespace Buffer{
|
||||||
(*usersIt).Disconnect("Push denied - push already in progress!");
|
(*usersIt).Disconnect("Push denied - push already in progress!");
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
(*usersIt).Disconnect("Push denied - invalid IP address!");
|
(*usersIt).Disconnect("Push denied - invalid IP address ("+waiting_ip+"!="+tmp.substr(2)+")!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tmp[0] == 'S'){
|
if (tmp[0] == 'S'){
|
||||||
|
@ -399,7 +399,7 @@ namespace Buffer{
|
||||||
|
|
||||||
// disconnect listener
|
// disconnect listener
|
||||||
if (FLV::Parse_Error){
|
if (FLV::Parse_Error){
|
||||||
std::cout << "FLV parse error" << std::endl;
|
std::cout << "FLV parse error:" << FLV::Error_Str << std::endl;
|
||||||
}else{
|
}else{
|
||||||
std::cout << "Reached EOF of input" << std::endl;
|
std::cout << "Reached EOF of input" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -241,21 +241,31 @@ void Connector_RTMP::parseChunk(){
|
||||||
Socket.write(RTMPStream::SendCTL(5, RTMPStream::snd_window_size));//send window acknowledgement size (msg 5)
|
Socket.write(RTMPStream::SendCTL(5, RTMPStream::snd_window_size));//send window acknowledgement size (msg 5)
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
#if DEBUG >= 4
|
|
||||||
fprintf(stderr, "Received audio data\n");
|
|
||||||
#endif
|
|
||||||
F.ChunkLoader(next);
|
F.ChunkLoader(next);
|
||||||
if (SS.connected()){
|
if (SS.connected()){
|
||||||
|
#if DEBUG >= 4
|
||||||
|
fprintf(stderr, "A");
|
||||||
|
#endif
|
||||||
SS.write(std::string(F.data, F.len));
|
SS.write(std::string(F.data, F.len));
|
||||||
|
}else{
|
||||||
|
#if DEBUG >= 4
|
||||||
|
fprintf(stderr, "Received useless audio data\n");
|
||||||
|
#endif
|
||||||
|
Socket.close();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
#if DEBUG >= 4
|
|
||||||
fprintf(stderr, "Received video data\n");
|
|
||||||
#endif
|
|
||||||
F.ChunkLoader(next);
|
F.ChunkLoader(next);
|
||||||
if (SS.connected()){
|
if (SS.connected()){
|
||||||
|
#if DEBUG >= 4
|
||||||
|
fprintf(stderr, "V");
|
||||||
|
#endif
|
||||||
SS.write(std::string(F.data, F.len));
|
SS.write(std::string(F.data, F.len));
|
||||||
|
}else{
|
||||||
|
#if DEBUG >= 4
|
||||||
|
fprintf(stderr, "Received useless video data\n");
|
||||||
|
#endif
|
||||||
|
Socket.close();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 15:
|
case 15:
|
||||||
|
@ -348,6 +358,9 @@ void Connector_RTMP::parseChunk(){
|
||||||
Socket.write(RTMPStream::SendUSR(0, 1));//send UCM StreamBegin (0), stream 1
|
Socket.write(RTMPStream::SendUSR(0, 1));//send UCM StreamBegin (0), stream 1
|
||||||
parsed3 = true;
|
parsed3 = true;
|
||||||
}//createStream
|
}//createStream
|
||||||
|
if ((amfdata.getContentP(0)->StrValue() == "closeStream") || (amfdata.getContentP(0)->StrValue() == "deleteStream")){
|
||||||
|
if (SS.connected()){SS.close();}
|
||||||
|
}
|
||||||
if ((amfdata.getContentP(0)->StrValue() == "getStreamLength") || (amfdata.getContentP(0)->StrValue() == "getMovLen")){
|
if ((amfdata.getContentP(0)->StrValue() == "getStreamLength") || (amfdata.getContentP(0)->StrValue() == "getMovLen")){
|
||||||
//send a _result reply
|
//send a _result reply
|
||||||
AMF::Object amfreply("container", AMF::AMF0_DDV_CONTAINER);
|
AMF::Object amfreply("container", AMF::AMF0_DDV_CONTAINER);
|
||||||
|
@ -569,6 +582,9 @@ void Connector_RTMP::parseChunk(){
|
||||||
Socket.write(RTMPStream::SendUSR(0, 1));//send UCM StreamBegin (0), stream 1
|
Socket.write(RTMPStream::SendUSR(0, 1));//send UCM StreamBegin (0), stream 1
|
||||||
parsed = true;
|
parsed = true;
|
||||||
}//createStream
|
}//createStream
|
||||||
|
if ((amfdata.getContentP(0)->StrValue() == "closeStream") || (amfdata.getContentP(0)->StrValue() == "deleteStream")){
|
||||||
|
if (SS.connected()){SS.close();}
|
||||||
|
}
|
||||||
if ((amfdata.getContentP(0)->StrValue() == "getStreamLength") || (amfdata.getContentP(0)->StrValue() == "getMovLen")){
|
if ((amfdata.getContentP(0)->StrValue() == "getStreamLength") || (amfdata.getContentP(0)->StrValue() == "getMovLen")){
|
||||||
//send a _result reply
|
//send a _result reply
|
||||||
AMF::Object amfreply("container", AMF::AMF0_DDV_CONTAINER);
|
AMF::Object amfreply("container", AMF::AMF0_DDV_CONTAINER);
|
||||||
|
|
|
@ -320,7 +320,14 @@ bool FLV::Tag::MemLoader(char * D, unsigned int S, unsigned int & P){
|
||||||
len += (data[2] << 8);
|
len += (data[2] << 8);
|
||||||
len += (data[1] << 16);
|
len += (data[1] << 16);
|
||||||
if (buf < len){data = (char*)realloc(data, len); buf = len;}
|
if (buf < len){data = (char*)realloc(data, len); buf = len;}
|
||||||
if (data[0] > 0x12){FLV::Parse_Error = true; Error_Str = "Invalid Tag received."; return false;}
|
if (data[0] > 0x12){
|
||||||
|
data[0] += 32;
|
||||||
|
FLV::Parse_Error = true;
|
||||||
|
Error_Str = "Invalid Tag received (";
|
||||||
|
Error_Str += data[0];
|
||||||
|
Error_Str += ").";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -347,20 +354,11 @@ bool FLV::Tag::MemLoader(char * D, unsigned int S, unsigned int & P){
|
||||||
/// \param sock Socket to read from.
|
/// \param sock Socket to read from.
|
||||||
/// \return True if count bytes are read succesfully, false otherwise.
|
/// \return True if count bytes are read succesfully, false otherwise.
|
||||||
bool FLV::Tag::SockReadUntil(char * buffer, unsigned int count, unsigned int & sofar, Socket::Connection & sock){
|
bool FLV::Tag::SockReadUntil(char * buffer, unsigned int count, unsigned int & sofar, Socket::Connection & sock){
|
||||||
if (sofar == count){return true;}
|
if (sofar >= count){return true;}
|
||||||
if (!sock.read(buffer + sofar,count-sofar)){
|
int r = 0;
|
||||||
if (errno != EWOULDBLOCK){
|
r = sock.iread(buffer + sofar,count-sofar);
|
||||||
FLV::Parse_Error = true;
|
sofar += r;
|
||||||
Error_Str = "Error reading from socket.";
|
if (sofar >= count){return true;}
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
sofar += count-sofar;
|
|
||||||
if (sofar == count){return true;}
|
|
||||||
if (sofar > count){
|
|
||||||
FLV::Parse_Error = true;
|
|
||||||
Error_Str = "Socket buffer overflow.";
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}//Tag::SockReadUntil
|
}//Tag::SockReadUntil
|
||||||
|
|
||||||
|
@ -387,7 +385,14 @@ bool FLV::Tag::SockLoader(Socket::Connection sock){
|
||||||
len += (data[2] << 8);
|
len += (data[2] << 8);
|
||||||
len += (data[1] << 16);
|
len += (data[1] << 16);
|
||||||
if (buf < len){data = (char*)realloc(data, len); buf = len;}
|
if (buf < len){data = (char*)realloc(data, len); buf = len;}
|
||||||
if (data[0] > 0x12){FLV::Parse_Error = true; Error_Str = "Invalid Tag received."; return false;}
|
if (data[0] > 0x12){
|
||||||
|
data[0] += 32;
|
||||||
|
FLV::Parse_Error = true;
|
||||||
|
Error_Str = "Invalid Tag received (";
|
||||||
|
Error_Str += data[0];
|
||||||
|
Error_Str += ").";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -459,7 +464,14 @@ bool FLV::Tag::FileLoader(FILE * f){
|
||||||
len += (data[2] << 8);
|
len += (data[2] << 8);
|
||||||
len += (data[1] << 16);
|
len += (data[1] << 16);
|
||||||
if (buf < len){data = (char*)realloc(data, len); buf = len;}
|
if (buf < len){data = (char*)realloc(data, len); buf = len;}
|
||||||
if (data[0] > 0x12){FLV::Parse_Error = true; Error_Str = "Invalid Tag received."; return false;}
|
if (data[0] > 0x12){
|
||||||
|
data[0] += 32;
|
||||||
|
FLV::Parse_Error = true;
|
||||||
|
Error_Str = "Invalid Tag received (";
|
||||||
|
Error_Str += data[0];
|
||||||
|
Error_Str += ").";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue