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
28 CbStatus,28 CbStatus,
29 NumCbA,29 NumCbA,
30 30
31 CtlStreamBegin = 0,
32 CtlStreamEnd,
33 CtlStreamDry,
34 CtlStreamRecorded,
35 CtlPing = 6,
36 CtlBufferEmpty = 31,
37 CtlBufferReady,
38
31 PktChunkSz = 1,39 PktChunkSz = 1,
32 PktBytesReadReport = 3,40 PktBytesReadReport = 3,
33 PktControl = 4,41 PktControl = 4,
@@ -105,7 +113,7 @@ struct RTMP { · 71 unmodified lines
105 putobj(); \113 putobj(); \
106}while(0)114}while(0)
107 115
108static szs[] = {116static int szs[] = {
109 [SzTiny] = 1,117 [SzTiny] = 1,
110 [SzSmall] = 4,118 [SzSmall] = 4,
111 [SzMedium] = 8,119 [SzMedium] = 8,
@@ -128,6 +136,16 @@ static char *pktype2s[] = { · 16 unmodified lines
128 [PktFlashVideo] = "FlashVideo",136 [PktFlashVideo] = "FlashVideo",
129};137};
130 138
139static 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
131extern int debug;149extern int debug;
132 150
133#pragma varargck type "T" int151#pragma varargck type "T" int
@@ -156,9 +174,13 @@ pkfmt(Fmt *f) · 22 unmodified lines
156 p = va_arg(f->args, Packet*);174 p = va_arg(f->args, Packet*);
157 175
158 fmtprint(f, "type=%T chan=%d ts=%ud sz=%d", p->type, p->chan, p->ts, p->sz);176 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
159 if(p->type == PktInvoke){181 if(p->type == PktInvoke){
160 fmtprint(f, ":");182 fmtprint(f, ":");
161 for(s = p->data, e = s + p->sz; s != nil && s != e;){183 for(; s != nil && s != e;){
162 if((s = amfparse(&a, s, e)) != nil)184 if((s = amfparse(&a, s, e)) != nil)
163 fmtprint(f, " %A", a);185 fmtprint(f, " %A", a);
164 else186 else
@@ -414,6 +436,7 @@ loop(void *aux) · 249 unmodified lines
414 int res, n, ok;436 int res, n, ok;
415 Amf *a[NumCbA];437 Amf *a[NumCbA];
416 u8int *s, *e;438 u8int *s, *e;
439 s16int s16;
417 Packet *p;440 Packet *p;
418 Invoke *i;441 Invoke *i;
419 RTMP *r;442 RTMP *r;
@@ -435,12 +458,13 @@ loop(void *aux) · 15 unmodified lines
435 break;458 break;
436 }459 }
437 460
461 s = r->pk.data;
462 e = s + r->pk.sz;
463
438 switch(p->type){464 switch(p->type){
439 case PktInvoke:465 case PktInvoke:
440 i = nil;466 i = nil;
441 ok = 0;467 ok = 0;
442 s = r->pk.data;
443 e = s + r->pk.sz;
444 for(n = 0; n < NumCbA; n++){468 for(n = 0; n < NumCbA; n++){
445 if((s = amfparse(&a[n], s, e)) == nil)469 if((s = amfparse(&a[n], s, e)) == nil)
446 goto err;470 goto err;
@@ -483,7 +507,7 @@ loop(void *aux) · 36 unmodified lines
483 break;507 break;
484 508
485 case PktChunkSz:509 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)
487 goto err;511 goto err;
488 if(r->chunk < 2){512 if(r->chunk < 2){
489 werrstr("invalid chunk size: %d", r->chunk);513 werrstr("invalid chunk size: %d", r->chunk);
@@ -492,8 +516,35 @@ loop(void *aux) · 2 unmodified lines
492 if(debug)516 if(debug)
493 fprint(2, "new chunk size: %d bytes\n", r->chunk);517 fprint(2, "new chunk size: %d bytes\n", r->chunk);
494 break;518 break;
519
495 case PktBytesReadReport:520 case PktBytesReadReport:
496 case PktControl:521 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
497 case PktServerBW:548 case PktServerBW:
498 case PktClientBW:549 case PktClientBW:
499 case PktAudio:550 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