*evil scientist laughter* ITS ALIVE! ITS ALIVE!
This commit is contained in:
parent
c8bc0fbafe
commit
66a66b155c
5 changed files with 26 additions and 23 deletions
|
@ -230,16 +230,16 @@ namespace Buffer{
|
||||||
users.back().MyBuffer = lastproper;
|
users.back().MyBuffer = lastproper;
|
||||||
users.back().MyBuffer_num = -1;
|
users.back().MyBuffer_num = -1;
|
||||||
/// \todo Do this more nicely?
|
/// \todo Do this more nicely?
|
||||||
if (!incoming.write(FLV::Header, 13)){
|
if (!users.back().S.write(FLV::Header, 13)){
|
||||||
users.back().Disconnect("failed to receive the header!");
|
users.back().Disconnect("failed to receive the header!");
|
||||||
}else{
|
}else{
|
||||||
if (!incoming.write(metadata.data, metadata.len)){
|
if (!users.back().S.write(metadata.data, metadata.len)){
|
||||||
users.back().Disconnect("failed to receive metadata!");
|
users.back().Disconnect("failed to receive metadata!");
|
||||||
}
|
}
|
||||||
if (!incoming.write(video_init.data, video_init.len)){
|
if (!users.back().S.write(video_init.data, video_init.len)){
|
||||||
users.back().Disconnect("failed to receive video init!");
|
users.back().Disconnect("failed to receive video init!");
|
||||||
}
|
}
|
||||||
if (!incoming.write(audio_init.data, audio_init.len)){
|
if (!users.back().S.write(audio_init.data, audio_init.len)){
|
||||||
users.back().Disconnect("failed to receive audio init!");
|
users.back().Disconnect("failed to receive audio init!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,7 +337,7 @@ namespace Connector_HTTP{
|
||||||
conn.close();
|
conn.close();
|
||||||
if (inited) ss.close();
|
if (inited) ss.close();
|
||||||
#if DEBUG >= 1
|
#if DEBUG >= 1
|
||||||
if (FLV::Parse_Error){fprintf(stderr, "FLV Parser Error\n");}
|
if (FLV::Parse_Error){fprintf(stderr, "FLV Parser Error: %s\n", FLV::Error_Str.c_str());}
|
||||||
fprintf(stderr, "User %i disconnected.\n", conn.getSocket());
|
fprintf(stderr, "User %i disconnected.\n", conn.getSocket());
|
||||||
if (inited){
|
if (inited){
|
||||||
fprintf(stderr, "Status was: inited\n");
|
fprintf(stderr, "Status was: inited\n");
|
||||||
|
|
|
@ -121,9 +121,10 @@ bool DDV::Socket::write(const void * buffer, int len){
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}else{
|
||||||
sofar += r;
|
sofar += r;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}//DDv::Socket::write
|
}//DDv::Socket::write
|
||||||
|
|
||||||
|
@ -151,9 +152,10 @@ bool DDV::Socket::read(void * buffer, int len){
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}else{
|
||||||
sofar += r;
|
sofar += r;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}//DDV::Socket::read
|
}//DDV::Socket::read
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ void FLV::Tag::tagTime(unsigned int T){
|
||||||
/// The buffer length is initialized to 0, and later automatically
|
/// The buffer length is initialized to 0, and later automatically
|
||||||
/// increased if neccesary.
|
/// increased if neccesary.
|
||||||
FLV::Tag::Tag(){
|
FLV::Tag::Tag(){
|
||||||
len = 0; buf = 0; data = 0; isKeyframe = false;
|
len = 0; buf = 0; data = 0; isKeyframe = false; done = true; sofar = 0;
|
||||||
}//empty constructor
|
}//empty constructor
|
||||||
|
|
||||||
/// Copy constructor, copies the contents of an existing tag.
|
/// Copy constructor, copies the contents of an existing tag.
|
||||||
|
@ -151,6 +151,8 @@ FLV::Tag::Tag(){
|
||||||
/// that is being copied, and later automaticallt increased if
|
/// that is being copied, and later automaticallt increased if
|
||||||
/// neccesary.
|
/// neccesary.
|
||||||
FLV::Tag::Tag(const Tag& O){
|
FLV::Tag::Tag(const Tag& O){
|
||||||
|
done = true;
|
||||||
|
sofar = 0;
|
||||||
buf = O.len;
|
buf = O.len;
|
||||||
len = buf;
|
len = buf;
|
||||||
if (len > 0){
|
if (len > 0){
|
||||||
|
@ -166,14 +168,18 @@ FLV::Tag::Tag(const Tag& O){
|
||||||
/// This operator checks for self-assignment.
|
/// This operator checks for self-assignment.
|
||||||
FLV::Tag & FLV::Tag::operator= (const FLV::Tag& O){
|
FLV::Tag & FLV::Tag::operator= (const FLV::Tag& O){
|
||||||
if (this != &O){//no self-assignment
|
if (this != &O){//no self-assignment
|
||||||
if (data != 0){free(data);}
|
len = O.len;
|
||||||
buf = O.len;
|
|
||||||
len = buf;
|
|
||||||
if (len > 0){
|
if (len > 0){
|
||||||
|
if (!data){
|
||||||
data = (char*)malloc(len);
|
data = (char*)malloc(len);
|
||||||
memcpy(data, O.data, len);
|
buf = len;
|
||||||
}else{
|
}else{
|
||||||
data = 0;
|
if (buf < len){
|
||||||
|
data = (char*)realloc(data, len);
|
||||||
|
buf = len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
memcpy(data, O.data, len);
|
||||||
}
|
}
|
||||||
isKeyframe = O.isKeyframe;
|
isKeyframe = O.isKeyframe;
|
||||||
}
|
}
|
||||||
|
@ -211,8 +217,6 @@ bool FLV::Tag::MemReadUntil(char * buffer, unsigned int count, unsigned int & so
|
||||||
/// \param P The current position in the data buffer. Will be updated to reflect new position.
|
/// \param P The current position in the data buffer. Will be updated to reflect new position.
|
||||||
/// \return True if a whole tag is succesfully read, false otherwise.
|
/// \return True if a whole tag is succesfully read, false otherwise.
|
||||||
bool FLV::Tag::MemLoader(char * D, unsigned int S, unsigned int & P){
|
bool FLV::Tag::MemLoader(char * D, unsigned int S, unsigned int & P){
|
||||||
static bool done = true;
|
|
||||||
static unsigned int sofar = 0;
|
|
||||||
if (buf < 15){data = (char*)realloc(data, 15); buf = 15;}
|
if (buf < 15){data = (char*)realloc(data, 15); buf = 15;}
|
||||||
if (done){
|
if (done){
|
||||||
//read a header
|
//read a header
|
||||||
|
@ -259,15 +263,14 @@ bool FLV::Tag::MemLoader(char * D, unsigned int S, unsigned int & P){
|
||||||
/// \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, DDV::Socket & sock){
|
bool FLV::Tag::SockReadUntil(char * buffer, unsigned int count, unsigned int & sofar, DDV::Socket & sock){
|
||||||
if (sofar == count){return true;}
|
if (sofar == count){return true;}
|
||||||
int r = sock.read(buffer + sofar,count-sofar);
|
if (!sock.read(buffer + sofar,count-sofar)){
|
||||||
if (r < 0){
|
|
||||||
if (errno != EWOULDBLOCK){
|
if (errno != EWOULDBLOCK){
|
||||||
FLV::Parse_Error = true;
|
FLV::Parse_Error = true;
|
||||||
Error_Str = "Error reading from socket.";
|
Error_Str = "Error reading from socket.";
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sofar += r;
|
sofar += count-sofar;
|
||||||
if (sofar == count){return true;}
|
if (sofar == count){return true;}
|
||||||
if (sofar > count){
|
if (sofar > count){
|
||||||
FLV::Parse_Error = true;
|
FLV::Parse_Error = true;
|
||||||
|
@ -282,8 +285,6 @@ bool FLV::Tag::SockReadUntil(char * buffer, unsigned int count, unsigned int & s
|
||||||
/// \param sock The socket to read from.
|
/// \param sock The socket to read from.
|
||||||
/// \return True if a whole tag is succesfully read, false otherwise.
|
/// \return True if a whole tag is succesfully read, false otherwise.
|
||||||
bool FLV::Tag::SockLoader(DDV::Socket sock){
|
bool FLV::Tag::SockLoader(DDV::Socket sock){
|
||||||
static bool done = true;
|
|
||||||
static unsigned int sofar = 0;
|
|
||||||
if (buf < 15){data = (char*)realloc(data, 15); buf = 15;}
|
if (buf < 15){data = (char*)realloc(data, 15); buf = 15;}
|
||||||
if (done){
|
if (done){
|
||||||
if (SockReadUntil(data, 11, sofar, sock)){
|
if (SockReadUntil(data, 11, sofar, sock)){
|
||||||
|
@ -354,8 +355,6 @@ bool FLV::Tag::FileLoader(FILE * f){
|
||||||
int preflags = fcntl(fileno(f), F_GETFL, 0);
|
int preflags = fcntl(fileno(f), F_GETFL, 0);
|
||||||
int postflags = preflags | O_NONBLOCK;
|
int postflags = preflags | O_NONBLOCK;
|
||||||
fcntl(fileno(f), F_SETFL, postflags);
|
fcntl(fileno(f), F_SETFL, postflags);
|
||||||
static bool done = true;
|
|
||||||
static unsigned int sofar = 0;
|
|
||||||
if (buf < 15){data = (char*)realloc(data, 15); buf = 15;}
|
if (buf < 15){data = (char*)realloc(data, 15); buf = 15;}
|
||||||
|
|
||||||
if (done){
|
if (done){
|
||||||
|
|
|
@ -35,6 +35,8 @@ namespace FLV {
|
||||||
bool FileLoader(FILE * f);
|
bool FileLoader(FILE * f);
|
||||||
protected:
|
protected:
|
||||||
int buf; ///< Maximum length of buffer space.
|
int buf; ///< Maximum length of buffer space.
|
||||||
|
bool done; ///< Body reading done?
|
||||||
|
unsigned int sofar; ///< How many bytes are read sofar?
|
||||||
//loader helper functions
|
//loader helper functions
|
||||||
bool MemReadUntil(char * buffer, unsigned int count, unsigned int & sofar, char * D, unsigned int S, unsigned int & P);
|
bool MemReadUntil(char * buffer, unsigned int count, unsigned int & sofar, char * D, unsigned int S, unsigned int & P);
|
||||||
bool SockReadUntil(char * buffer, unsigned int count, unsigned int & sofar, DDV::Socket & sock);
|
bool SockReadUntil(char * buffer, unsigned int count, unsigned int & sofar, DDV::Socket & sock);
|
||||||
|
|
Loading…
Add table
Reference in a new issue