werkende negotiation, klaar om daadwerklijk video/audio te versturen\!
This commit is contained in:
parent
4f0f71716f
commit
f4c02f33d8
4 changed files with 174 additions and 52 deletions
|
@ -9,11 +9,6 @@ void parseChunk(){
|
|||
static AMFType amfelem("empty", (unsigned char)0xFF);
|
||||
static int tmpint;
|
||||
next = getWholeChunk();
|
||||
if (next.cs_id == 2 && next.msg_stream_id == 0){
|
||||
fprintf(stderr, "Received protocol message. (cs_id 2, stream id 0)\nContents:\n");
|
||||
fwrite(next.data, 1, next.real_len, stderr);
|
||||
fflush(stderr);
|
||||
}
|
||||
switch (next.msg_type_id){
|
||||
case 0://does not exist
|
||||
break;//happens when connection breaks unexpectedly
|
||||
|
@ -30,11 +25,12 @@ void parseChunk(){
|
|||
snd_window_at = ntohl(*(int*)next.data);
|
||||
//maybe better? snd_window_at = snd_cnt;
|
||||
break;
|
||||
case 4:
|
||||
fprintf(stderr, "CTRL: User control message\n");
|
||||
case 4:{
|
||||
short int ucmtype = ntohs(*(short int*)next.data);
|
||||
fprintf(stderr, "CTRL: User control message %hi\n", ucmtype);
|
||||
//2 bytes event type, rest = event data
|
||||
//TODO: process this
|
||||
break;
|
||||
//we don't need to process this
|
||||
} break;
|
||||
case 5://window size of other end
|
||||
fprintf(stderr, "CTRL: Window size\n");
|
||||
rec_window_size = ntohl(*(int*)next.data);
|
||||
|
@ -66,10 +62,10 @@ void parseChunk(){
|
|||
case 19:
|
||||
fprintf(stderr, "Received AFM0 shared object\n");
|
||||
break;
|
||||
case 20:
|
||||
case 20:{//AMF0 command message
|
||||
amfdata = parseAMF(next.data, next.real_len);
|
||||
fprintf(stderr, "Received AFM0 command message:\n");
|
||||
amfdata.Print();
|
||||
fprintf(stderr, "Received AFM0 command message: %s\n", amfdata.getContentP(0)->Str());
|
||||
if (amfdata.getContentP(0)->StrValue() == "connect"){
|
||||
tmpint = amfdata.getContentP(2)->getContentP("videoCodecs")->NumValue();
|
||||
if (tmpint & 0x04){fprintf(stderr, "Sorensen video support detected\n");}
|
||||
|
@ -77,16 +73,38 @@ void parseChunk(){
|
|||
tmpint = amfdata.getContentP(2)->getContentP("audioCodecs")->NumValue();
|
||||
if (tmpint & 0x04){fprintf(stderr, "MP3 audio support detected\n");}
|
||||
if (tmpint & 0x400){fprintf(stderr, "AAC video support detected\n");}
|
||||
//send a _result reply
|
||||
AMFType amfreply("container", (unsigned char)0xFF);
|
||||
amfreply.addContent(AMFType("", "_result"));//result success
|
||||
amfreply.addContent(amfdata.getContent(1));//same transaction ID
|
||||
amfreply.addContent(AMFType("", (double)0, 0x05));//null - properties (none?)
|
||||
amfreply.addContent(AMFType(""));//info
|
||||
amfreply.getContentP(3)->addContent(AMFType("level", "status"));
|
||||
amfreply.getContentP(3)->addContent(AMFType("code", "NetConnection.Connect.Sucess"));
|
||||
amfreply.getContentP(3)->addContent(AMFType("description", "Connection succeeded."));
|
||||
SendChunk(3, 20, next.msg_stream_id, amfreply.Pack());
|
||||
SendCTL(5, snd_window_size);//send window acknowledgement size (msg 5)
|
||||
SendCTL(5, rec_window_size, 1);//send peer bandwidth (msg 6)
|
||||
SendUSR(0, 10);//send UCM StreamBegin (0), stream 10 (we use this number)
|
||||
//send AFM0 (20) {_result, 1, {properties}, {info}}
|
||||
}else{
|
||||
//call, close, createStream
|
||||
//TODO: play (&& play2?)
|
||||
//fprintf(stderr, "Ignored AFM0 command.\n");
|
||||
}
|
||||
break;
|
||||
}//connect
|
||||
if (amfdata.getContentP(0)->StrValue() == "createStream"){
|
||||
//send a _result reply
|
||||
AMFType amfreply("container", (unsigned char)0xFF);
|
||||
amfreply.addContent(AMFType("", "_result"));//result success
|
||||
amfreply.addContent(amfdata.getContent(1));//same transaction ID
|
||||
amfreply.addContent(AMFType("", (double)0, 0x05));//null - command info
|
||||
amfreply.addContent(AMFType("", (double)10));//stream ID - we use 10
|
||||
SendChunk(3, 20, next.msg_stream_id, amfreply.Pack());
|
||||
}//createStream
|
||||
if ((amfdata.getContentP(0)->StrValue() == "play") || (amfdata.getContentP(0)->StrValue() == "play2")){
|
||||
//send a status reply
|
||||
AMFType amfreply("container", (unsigned char)0xFF);
|
||||
amfreply.addContent(AMFType("", "onStatus"));//status reply
|
||||
amfreply.addContent(AMFType("", "NetStream.Play.Start"));//result success
|
||||
SendChunk(3, 20, next.msg_stream_id, amfreply.Pack());
|
||||
ready4data = true;//start sending video data!
|
||||
}//createStream
|
||||
} break;
|
||||
case 22:
|
||||
fprintf(stderr, "Received aggregate message\n");
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue