Alles werkend - maar echte flash clients zijn het daar niet meer eens, raar genoeg...
This commit is contained in:
parent
2d0aafc179
commit
e8246efc91
8 changed files with 234 additions and 99 deletions
|
@ -14,45 +14,52 @@
|
|||
#include "../sockets/SocketW.h"
|
||||
bool ready4data = false;//set to true when streaming starts
|
||||
bool inited = false;
|
||||
#include "../util/flv.cpp" //FLV format parser
|
||||
#include "handshake.cpp" //handshaking
|
||||
timeval lastrec;
|
||||
|
||||
#include "parsechunks.cpp" //chunkstream parsing
|
||||
#include "handshake.cpp" //handshaking
|
||||
#include "flv_sock.cpp" //FLV parsing with SocketW
|
||||
|
||||
int main(){
|
||||
SWUnixSocket ss;
|
||||
FLV_Pack * FLV = 0;
|
||||
int ssfd = 0;
|
||||
fd_set pollset;
|
||||
struct timeval timeout;
|
||||
struct timeval now;
|
||||
//0 timeout - return immediately after select call
|
||||
timeout.tv_sec = 1; timeout.tv_usec = 0;
|
||||
FD_ZERO(&pollset);//clear the polling set
|
||||
FD_SET(0, &pollset);//add stdin to polling set
|
||||
|
||||
fprintf(stderr, "Doing handshake...\n");
|
||||
doHandshake();
|
||||
fprintf(stderr, "Starting processing...\n");
|
||||
while (!feof(stdin)){
|
||||
select(1, &pollset, 0, 0, &timeout);
|
||||
//only parse input from stdin if available
|
||||
if (FD_ISSET(0, &pollset)){parseChunk();}
|
||||
//only parse input from stdin if available or not yet init'ed
|
||||
if (FD_ISSET(0, &pollset) || !ready4data){parseChunk();fflush(stdout);}// || !ready4data?
|
||||
if (ready4data){
|
||||
if (!inited){
|
||||
//we are ready, connect the socket!
|
||||
ss.connect("../shared_socket");
|
||||
ssfd = ss.get_fd(0);
|
||||
if (ssfd > 0){FD_SET(ssfd, &pollset);}else{return 1;}
|
||||
FLV_Readheader(ssfd);//read the header, we don't want it
|
||||
fprintf(stderr, "Header read\n");
|
||||
if (!ss.connect("../shared_socket")){
|
||||
fprintf(stderr, "Could not connect to server!\n");
|
||||
return 1;
|
||||
}
|
||||
FLV_Readheader(ss);//read the header, we don't want it
|
||||
fprintf(stderr, "Header read, starting to send video data...\n");
|
||||
inited = true;
|
||||
}
|
||||
//only deal with FLV packets if we have any to receive
|
||||
if (FD_ISSET(ssfd, &pollset)){
|
||||
fprintf(stderr, "Getting packet...\n");
|
||||
FLV_GetPacket(FLV, ssfd);//read a full packet
|
||||
fprintf(stderr, "Sending a type %hhx packet...\n", (unsigned char)FLV->data[0]);
|
||||
SendMedia((unsigned char)FLV->data[0], (unsigned char *)FLV->data+11, FLV->len-15);
|
||||
fprintf(stderr, "Packet sent.\n");
|
||||
//only send data if previous data has been ACK'ed...
|
||||
if (snd_cnt - snd_window_at < snd_window_size){
|
||||
if (FLV_GetPacket(ss)){//able to read a full packet?
|
||||
SendMedia((unsigned char)FLVbuffer[0], (unsigned char *)FLVbuffer+11, FLV_len-15);
|
||||
}
|
||||
}
|
||||
}
|
||||
//send ACK if we received a whole window
|
||||
if (rec_cnt - rec_window_at > rec_window_size){
|
||||
rec_window_at = rec_cnt;
|
||||
SendCTL(3, rec_cnt);//send ack (msg 3)
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}//main
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue