Gearbox updates, FLV parser rewrite, buffer fixes...
This commit is contained in:
parent
de701fc58e
commit
82d5ed69a2
2 changed files with 102 additions and 59 deletions
|
@ -1,3 +1,5 @@
|
|||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
#include "../sockets/SocketW.h"
|
||||
#include <string>
|
||||
|
@ -47,17 +49,17 @@ int main( int argc, char * argv[] ) {
|
|||
unsigned char packtype;
|
||||
bool gotVideoInfo = false;
|
||||
bool gotAudioInfo = false;
|
||||
while(std::cin.good() && std::cout.good()) {
|
||||
loopcount ++;
|
||||
|
||||
//set stdin to be nonblocking
|
||||
int flags = fcntl(0, F_GETFL, 0);
|
||||
flags |= O_NONBLOCK;
|
||||
fcntl(0, F_SETFL, flags);
|
||||
|
||||
while(!feof(stdin) && !ferror(stdin) && !All_Hell_Broke_Loose){
|
||||
//invalidate the current buffer
|
||||
ringbuf[current_buffer]->number = -1;
|
||||
if (std::cin.peek() == 'F') {
|
||||
//new FLV file, read the file header again.
|
||||
FLV_Readheader();
|
||||
} else {
|
||||
if (!FLV_GetPacket(ringbuf[current_buffer]->FLV)){
|
||||
break;//wrong packet? something bust be broken. End program!
|
||||
}
|
||||
if (FLV_GetPacket(ringbuf[current_buffer]->FLV)){
|
||||
loopcount ++;
|
||||
packtype = ringbuf[current_buffer]->FLV->data[0];
|
||||
//store metadata, if available
|
||||
if (packtype == 0x12){
|
||||
|
@ -98,35 +100,39 @@ int main( int argc, char * argv[] ) {
|
|||
if (packtype == 0x09){
|
||||
if (((ringbuf[current_buffer]->FLV->data[11] & 0xf0) >> 4) == 1){lastproper = current_buffer;}
|
||||
}
|
||||
incoming = listener.accept(&BError);
|
||||
if (incoming){
|
||||
connectionList.push_back(user(incoming));
|
||||
//send the FLV header
|
||||
connectionList.back().MyBuffer = lastproper;
|
||||
connectionList.back().MyBuffer_num = -1;
|
||||
//TODO: Do this more nicely?
|
||||
if (connectionList.back().Conn->send(FLVHeader,13,&BError) != 13){
|
||||
connectionList.back().disconnect("failed to receive the header!");
|
||||
}else{
|
||||
if (connectionList.back().Conn->send(metabuffer,metabuflen,&BError) != metabuflen){
|
||||
connectionList.back().disconnect("failed to receive metadata!");
|
||||
}
|
||||
}
|
||||
if (BError != SWBaseSocket::ok){
|
||||
connectionList.back().disconnect("Socket error: " + BError.get_error());
|
||||
//keep track of buffers
|
||||
current_buffer++;
|
||||
current_buffer %= buffers;
|
||||
ringbuf[current_buffer]->number = loopcount;
|
||||
}
|
||||
|
||||
//check for new connections, accept them if there are any
|
||||
incoming = listener.accept(&BError);
|
||||
if (incoming){
|
||||
connectionList.push_back(user(incoming));
|
||||
//send the FLV header
|
||||
connectionList.back().MyBuffer = lastproper;
|
||||
connectionList.back().MyBuffer_num = -1;
|
||||
//TODO: Do this more nicely?
|
||||
if (connectionList.back().Conn->send(FLVHeader,13,&BError) != 13){
|
||||
connectionList.back().disconnect("failed to receive the header!");
|
||||
}else{
|
||||
if (connectionList.back().Conn->send(metabuffer,metabuflen,&BError) != metabuflen){
|
||||
connectionList.back().disconnect("failed to receive metadata!");
|
||||
}
|
||||
}
|
||||
ringbuf[current_buffer]->number = loopcount;
|
||||
//send all connections what they need, if and when they need it
|
||||
if (BError != SWBaseSocket::ok){
|
||||
connectionList.back().disconnect("Socket error: " + BError.get_error());
|
||||
}
|
||||
}
|
||||
//send all connections what they need, if and when they need it
|
||||
if (connectionList.size() > 0){
|
||||
for (connIt = connectionList.begin(); connIt != connectionList.end(); connIt++){
|
||||
if (!(*connIt).is_connected){connectionList.erase(connIt);break;}
|
||||
(*connIt).Send(ringbuf, buffers);
|
||||
}
|
||||
//keep track of buffers
|
||||
current_buffer++;
|
||||
current_buffer %= buffers;
|
||||
}
|
||||
}
|
||||
}//main loop
|
||||
|
||||
// disconnect listener
|
||||
std::cout << "Reached EOF of input" << std::endl;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue