Stabiliteitsfixes en in theorie werkende H.264 en AAC, maar je weet maar nooit...

This commit is contained in:
Thulinma 2010-08-24 00:13:52 +02:00 committed by Thulinma
parent a34a9b69cc
commit 94f587563c
10 changed files with 144 additions and 54 deletions

View file

@ -19,6 +19,5 @@ clean:
run-test: $(OUT)
rm -rf ./meh
mkfifo ./meh
cat ./meh &
nc -l -p 1935 -e './Connector_RTMP 2>./meh'
run-cat:
cat < ./meh

View file

@ -10,19 +10,21 @@ void FLV_Readheader(SWUnixSocket & ss){
}
}//FLV_Readheader
void FLV_Dump(){FLV_len = 0;}
bool FLV_GetPacket(SWUnixSocket & ss){
if (FLVbs < 15){FLVbuffer = (char*)realloc(FLVbuffer, 15); FLVbs = 15;}
//if received a whole header, receive a whole packet
//if not, retry header next pass
if (ss.frecv(FLVbuffer, 11, &SWBerr) == 11){
FLV_len = FLVbuffer[3] + 15;
FLV_len += (FLVbuffer[2] << 8);
FLV_len += (FLVbuffer[1] << 16);
if (FLVbs < FLV_len){FLVbuffer = (char*)realloc(FLVbuffer, FLV_len);FLVbs = FLV_len;}
while (ss.frecv(FLVbuffer+11, FLV_len-11, &SWBerr) != FLV_len-11){
//wait
if (FLV_len == 0){
if (ss.frecv(FLVbuffer, 11, &SWBerr) == 11){
FLV_len = FLVbuffer[3] + 15;
FLV_len += (FLVbuffer[2] << 8);
FLV_len += (FLVbuffer[1] << 16);
if (FLVbs < FLV_len){FLVbuffer = (char*)realloc(FLVbuffer, FLV_len);FLVbs = FLV_len;}
}
return true;
}else{
if (ss.frecv(FLVbuffer+11, FLV_len-11, &SWBerr) == FLV_len-11){return true;}
}
return false;
}//FLV_GetPacket

View file

@ -15,6 +15,7 @@
#include "../sockets/SocketW.h"
bool ready4data = false;//set to true when streaming starts
bool inited = false;
bool stopparsing = false;
timeval lastrec;
#include "parsechunks.cpp" //chunkstream parsing
@ -44,9 +45,10 @@ int main(){
fprintf(stderr, "Starting processing...\n");
#endif
while (!feof(stdin)){
select(1, &pollset, 0, 0, &timeout);
//select(1, &pollset, 0, 0, &timeout);
//only parse input from stdin if available or not yet init'ed
if (FD_ISSET(0, &pollset) || !ready4data || (snd_cnt - snd_window_at >= snd_window_size)){parseChunk();fflush(stdout);}// || !ready4data?
//FD_ISSET(0, &pollset) || //NOTE: Polling does not work? WHY?!? WHY DAMN IT?!?
if ((!ready4data || (snd_cnt - snd_window_at >= snd_window_size)) && !stopparsing){parseChunk();fflush(stdout);}
if (ready4data){
if (!inited){
//we are ready, connect the socket!
@ -54,7 +56,7 @@ int main(){
#ifdef DEBUG
fprintf(stderr, "Could not connect to server!\n");
#endif
return 1;
return 0;
}
FLV_Readheader(ss);//read the header, we don't want it
#ifdef DEBUG
@ -69,17 +71,29 @@ int main(){
ts += FLVbuffer[4] * 256*256;
ts += FLVbuffer[5] * 256;
ts += FLVbuffer[6];
if (fts == 0){fts = ts;ftst = getNowMS();}
ts -= fts;
FLVbuffer[7] = ts / (256*256*256);
FLVbuffer[4] = ts / (256*256);
FLVbuffer[5] = ts / 256;
FLVbuffer[6] = ts % 256;
ts += ftst;
if (ts != 0){
if (fts == 0){fts = ts;ftst = getNowMS();}
ts -= fts;
FLVbuffer[7] = ts / (256*256*256);
FLVbuffer[4] = ts / (256*256);
FLVbuffer[5] = ts / 256;
FLVbuffer[6] = ts % 256;
ts += ftst;
}else{
ftst = getNowMS();
FLVbuffer[7] = ftst / (256*256*256);
FLVbuffer[4] = ftst / (256*256);
FLVbuffer[5] = ftst / 256;
FLVbuffer[6] = ftst % 256;
}
SendMedia((unsigned char)FLVbuffer[0], (unsigned char *)FLVbuffer+11, FLV_len-15, ts);
//if (FLVbuffer[0] == 9){
// fprintf(stderr, "first 2 bytes: 0x%hhx 0x%hhx\n", FLVbuffer[11], FLVbuffer[12]);
//}
FLV_Dump();//dump packet and get ready for next
}
if ((SWBerr != SWBaseSocket::ok) && (SWBerr != SWBaseSocket::notReady)){
#ifdef DEBUG
fprintf(stderr, "No more data! :-( (%s)\n", SWBerr.get_error().c_str());
#endif
return 0;//no more input possible! Fail immediately.
}
}
}
@ -89,5 +103,8 @@ int main(){
SendCTL(3, rec_cnt);//send ack (msg 3)
}
}
#ifdef DEBUG
fprintf(stderr, "User disconnected.\n");
#endif
return 0;
}//main

View file

@ -28,7 +28,7 @@ void parseChunk(){
fprintf(stderr, "CTRL: Acknowledgement\n");
#endif
snd_window_at = ntohl(*(int*)next.data);
//maybe better? snd_window_at = snd_cnt;
snd_window_at = snd_cnt;
break;
case 4:{
#ifdef DEBUG
@ -205,6 +205,11 @@ void parseChunk(){
amfreply.getContentP(3)->addContent(AMFType("details", "PLS"));
amfreply.getContentP(3)->addContent(AMFType("clientid", (double)1));
SendChunk(4, 20, 1, amfreply.Pack());
amfreply = AMFType("container", (unsigned char)0xFF);
amfreply.addContent(AMFType("", "|RtmpSampleAccess"));//status reply
amfreply.addContent(AMFType("", (double)1, 0x01));//bool true - audioaccess
amfreply.addContent(AMFType("", (double)1, 0x01));//bool true - videoaccess
SendChunk(4, 20, next.msg_stream_id, amfreply.Pack());
chunk_snd_max = 1024*1024;
SendCTL(1, chunk_snd_max);//send chunk size max (msg 1)
ready4data = true;//start sending video data!
@ -226,8 +231,9 @@ void parseChunk(){
break;
default:
#ifdef DEBUG
fprintf(stderr, "Unknown chunk received!\n");
fprintf(stderr, "Unknown chunk received! Probably protocol corruption, stopping parsing of incoming data.\n", next.msg_type_id);
#endif
stopparsing = true;
break;
}
}//parseChunk