History

parse control packets

Sigrid Solveig Haflínudóttir committed 5 years ago

Commit 0ce01d61 parent 3acc9f11 file · +56 −5Browse files

Unified · Split

rtmp.c+56−5
@@ -28,6 +28,14 @@ enum { · 27 unmodified lines
2828 CbStatus,
2929 NumCbA,
3030
31+ CtlStreamBegin = 0,
32+ CtlStreamEnd,
33+ CtlStreamDry,
34+ CtlStreamRecorded,
35+ CtlPing = 6,
36+ CtlBufferEmpty = 31,
37+ CtlBufferReady,
38+
3139 PktChunkSz = 1,
3240 PktBytesReadReport = 3,
3341 PktControl = 4,
@@ -105,7 +113,7 @@ struct RTMP { · 71 unmodified lines
105113 putobj(); \
106114 }while(0)
107115
108−static szs[] = {
116+static int szs[] = {
109117 [SzTiny] = 1,
110118 [SzSmall] = 4,
111119 [SzMedium] = 8,
@@ -128,6 +136,16 @@ static char *pktype2s[] = { · 16 unmodified lines
128136 [PktFlashVideo] = "FlashVideo",
129137 };
130138
139+static char *ctl2s[] = {
140+ [CtlStreamBegin] = "StreamBegin",
141+ [CtlStreamEnd] = "StreamEnd",
142+ [CtlStreamDry] = "StreamDry",
143+ [CtlStreamRecorded] = "StreamRecorded",
144+ [CtlPing] = "Ping",
145+ [CtlBufferEmpty] = "BufferEmpty",
146+ [CtlBufferReady] = "BufferReady",
147+};
148+
131149 extern int debug;
132150
133151 #pragma varargck type "T" int
@@ -156,9 +174,13 @@ pkfmt(Fmt *f) · 22 unmodified lines
156174 p = va_arg(f->args, Packet*);
157175
158176 fmtprint(f, "type=%T chan=%d ts=%ud sz=%d", p->type, p->chan, p->ts, p->sz);
177+
178+ s = p->data;
179+ e = s + p->sz;
180+
159181 if(p->type == PktInvoke){
160182 fmtprint(f, ":");
161− for(s = p->data, e = s + p->sz; s != nil && s != e;){
183+ for(; s != nil && s != e;){
162184 if((s = amfparse(&a, s, e)) != nil)
163185 fmtprint(f, " %A", a);
164186 else
@@ -414,6 +436,7 @@ loop(void *aux) · 249 unmodified lines
414436 int res, n, ok;
415437 Amf *a[NumCbA];
416438 u8int *s, *e;
439+ s16int s16;
417440 Packet *p;
418441 Invoke *i;
419442 RTMP *r;
@@ -435,12 +458,13 @@ loop(void *aux) · 15 unmodified lines
435458 break;
436459 }
437460
461+ s = r->pk.data;
462+ e = s + r->pk.sz;
463+
438464 switch(p->type){
439465 case PktInvoke:
440466 i = nil;
441467 ok = 0;
442− s = r->pk.data;
443− e = s + r->pk.sz;
444468 for(n = 0; n < NumCbA; n++){
445469 if((s = amfparse(&a[n], s, e)) == nil)
446470 goto err;
@@ -483,7 +507,7 @@ loop(void *aux) · 36 unmodified lines
483507 break;
484508
485509 case PktChunkSz:
486− if(amfi32get(r->pk.data, r->pk.data+r->pk.sz, &r->chunk) == nil)
510+ if(amfi32get(s, e, &r->chunk) == nil)
487511 goto err;
488512 if(r->chunk < 2){
489513 werrstr("invalid chunk size: %d", r->chunk);
@@ -492,8 +516,35 @@ loop(void *aux) · 2 unmodified lines
492516 if(debug)
493517 fprint(2, "new chunk size: %d bytes\n", r->chunk);
494518 break;
519+
495520 case PktBytesReadReport:
496521 case PktControl:
522+ if((s = amfi16get(s, e, &s16)) == nil)
523+ goto err;
524+ if((s = amfi32get(s, e, &n)) == nil)
525+ n = -1;
526+ switch(s16){
527+ case CtlStreamBegin:
528+ case CtlStreamEnd:
529+ case CtlStreamDry:
530+ case CtlStreamRecorded:
531+ case CtlBufferEmpty:
532+ case CtlBufferReady:
533+ if(0){
534+ case CtlPing:
535+ /* FIXME pong */
536+ USED(n);
537+ }
538+ if(debug)
539+ fprint(2, "control packet: %s %d\n", ctl2s[s16], n);
540+ break;
541+ default:
542+ if(debug)
543+ fprint(2, "unknown control packet %d (value %d)\n", s16, n);
544+ break;
545+ }
546+ break;
547+
497548 case PktServerBW:
498549 case PktClientBW:
499550 case PktAudio:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t