Refactoring naar common bases - also, werkende RTMP streaming! Jammer dat er nog maar 1 frame wordt verwerkt... maar het werkt!
This commit is contained in:
parent
f4c02f33d8
commit
2d0aafc179
27 changed files with 159 additions and 1594 deletions
|
@ -1,4 +1,4 @@
|
|||
SRC = main.cpp
|
||||
SRC = main.cpp ../sockets/sw_base.cpp ../sockets/sw_inet.cpp ../sockets/sw_unix.cpp
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
OUT = Connector_RTMP
|
||||
INCLUDES =
|
||||
|
@ -12,7 +12,7 @@ LIBS =
|
|||
default: $(OUT)
|
||||
.cpp.o:
|
||||
$(CC) $(INCLUDES) $(CCFLAGS) $(LIBS) -c $< -o $@
|
||||
$(OUT): $(OBJ) handshake.cpp chunkstream.cpp amf.cpp
|
||||
$(OUT): $(OBJ)
|
||||
$(CC) $(LIBS) -o $(OUT) $(OBJ)
|
||||
clean:
|
||||
rm -rf $(OBJ) $(OUT) Makefile.bak *~
|
||||
|
|
|
@ -119,6 +119,25 @@ void SendChunk(unsigned int cs_id, unsigned char msg_type_id, unsigned int msg_s
|
|||
free(ch.data);
|
||||
}//SendChunk
|
||||
|
||||
//sends a media chunk
|
||||
void SendMedia(unsigned char msg_type_id, unsigned char * data, int len){
|
||||
if ((msg_type_id != 8) && (msg_type_id != 9)) return;//only parse audio and video
|
||||
chunkpack ch;
|
||||
timeval t;
|
||||
gettimeofday(&t, 0);
|
||||
ch.cs_id = msg_type_id;
|
||||
ch.timestamp = t.tv_sec * 10 + t.tv_usec / 1000000;
|
||||
ch.len = len;
|
||||
ch.real_len = len;
|
||||
ch.len_left = 0;
|
||||
ch.msg_type_id = msg_type_id;
|
||||
ch.msg_stream_id = 10;
|
||||
ch.data = (unsigned char*)malloc(len);
|
||||
memcpy(ch.data, data, len);
|
||||
SendChunk(ch);
|
||||
free(ch.data);
|
||||
}//SendMedia
|
||||
|
||||
//sends a control message
|
||||
void SendCTL(unsigned char type, unsigned int data){
|
||||
chunkpack ch;
|
||||
|
|
|
@ -10,12 +10,18 @@
|
|||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
//for connection to server
|
||||
#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
|
||||
#include "parsechunks.cpp" //chunkstream parsing
|
||||
|
||||
int main(){
|
||||
SWUnixSocket ss;
|
||||
FLV_Pack * FLV = 0;
|
||||
int ssfd = 0;
|
||||
fd_set pollset;
|
||||
struct timeval timeout;
|
||||
//0 timeout - return immediately after select call
|
||||
|
@ -26,14 +32,26 @@ int main(){
|
|||
doHandshake();
|
||||
while (!feof(stdin)){
|
||||
select(1, &pollset, 0, 0, &timeout);
|
||||
if (FD_ISSET(0, &pollset)){
|
||||
//only try to parse a new chunk when one is available :-)
|
||||
std::cerr << "Parsing..." << std::endl;
|
||||
parseChunk();
|
||||
}
|
||||
//only parse input from stdin if available
|
||||
if (FD_ISSET(0, &pollset)){parseChunk();}
|
||||
if (ready4data){
|
||||
//check for packets, send them if needed
|
||||
std::cerr << "Sending crap..." << std::endl;
|
||||
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");
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue