shithub: rtmp

Download patch

ref: eb0b032482a8c6ebb356d61c40c453d38318f93a
parent: 02a850608753ed9c743dfd6992ad56e4c4ea3d53
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Thu Jul 29 05:36:20 EDT 2021

move msg pretty-printing elsewhere

--- a/rtmp.c
+++ b/rtmp.c
@@ -163,6 +163,12 @@
 	[CtlPingResponse] = "PingResponse",
 };
 
+static char *bwlimit2s[] = {
+	[LimitHard] = "hard",
+	[LimitSoft] = "soft",
+	[LimitDynamic] = "dynamic",
+};
+
 extern int debug;
 
 static void
@@ -264,9 +270,6 @@
 		}
 	}
 
-	if(debug)
-		fprint(2, "→ %M\n", &r->msg);
-
 	return 0;
 
 err:
@@ -317,10 +320,27 @@
 		}
 	}
 
-	Bflush(r);
+	if(Bflush(r) < 0)
+		goto err;
 
-	if(debug)
-		fprint(2, "← %M\n", &r->msg);
+	if(debug){
+		fprint(2, "← %M", &r->msg);
+		if(r->msg.type == AMF0Command){
+			Amf0 *a;
+			u8int *s, *e;
+			fprint(2, ":");
+			s = r->msg.data;
+			e = s + r->msg.sz;
+			for(; s != nil && s != e;){
+				if((s = amf0parse(&a, s, e)) != nil)
+					fprint(2, " %A", a);
+				else
+					fprint(2, " %r");
+				amf0free(a);
+			}
+		}
+		fprint(2, "\n");
+	}
 
 	if(r->msg.type == AMF0Command){
 		c = emalloc(sizeof(*c));
@@ -383,6 +403,9 @@
 		s = r->msg.data;
 		e = s + r->msg.sz;
 
+		if(debug)
+			fprint(2, "→ %M", &r->msg);
+
 		switch(m->type){
 		case AMF0Command:
 			c = nil;
@@ -413,6 +436,8 @@
 					break;
 				}
 			}
+			if(debug)
+				fprint(2, " tid=%A: %A %A %A", a[CbTransID], a[CbCommand], a[CbObject], a[CbResponse]);
 			if(c->prev != nil)
 				c->prev->next = c->next;
 			if(c->next != nil)
@@ -431,7 +456,7 @@
 				goto err;
 			}
 			if(debug)
-				fprint(2, "new chunk size: %d bytes\n", r->chunk);
+				fprint(2, ": %d", r->chunk);
 			break;
 
 		case UserControl:
@@ -451,11 +476,11 @@
 					USED(n);
 				}
 				if(debug)
-					fprint(2, "control message: %s %d\n", ctl2s[s16], n);
+					fprint(2, ": %s %d", ctl2s[s16], n);
 				break;
 			default:
 				if(debug)
-					fprint(2, "unknown control message %d (value %d)\n", s16, n);
+					fprint(2, ": ?%d? %d", s16, n);
 				break;
 			}
 			break;
@@ -463,11 +488,15 @@
 		case WindowAckSize:
 			if(amf0i32get(s, e, &r->winacksz) == nil)
 				goto err;
+			if(debug)
+				fprint(2, ": %d", r->winacksz);
 			break;
 
 		case SetBandwidth:
 			if((s = amf0i32get(s, e, &r->bw)) == nil || amf0byteget(s, e, &r->bwlimit) == nil)
 				goto err;
+			if(debug)
+				fprint(2, ": %d (%s)", r->bw, r->bwlimit < nelem(bwlimit2s) ? bwlimit2s[r->bwlimit] : "???");
 			break;
 
 		/* FIXME */
@@ -484,12 +513,15 @@
 		case AMF3SharedObject:
 		case AMF3Command:
 			if(debug)
-				fprint(2, "AMF3 message, ignoring\n");
+				fprint(2, ": ignored");
 			break;
 err:
 			res = -1;
 			break;
 		}
+
+		if(debug)
+			fprint(2, "\n");
 	}
 
 	rtmpfree(r);
@@ -567,27 +599,10 @@
 static int
 msgfmt(Fmt *f)
 {
-	u8int *s, *e;
 	Message *m;
-	Amf0 *a;
 
 	m = va_arg(f->args, Message*);
-
 	fmtprint(f, "type=%T cs=%d ts=%ud sz=%d", m->type, m->cs, m->ts, m->sz);
-
-	s = m->data;
-	e = s + m->sz;
-
-	if(m->type == AMF0Command){
-		fmtprint(f, ":");
-		for(; s != nil && s != e;){
-			if((s = amf0parse(&a, s, e)) != nil)
-				fmtprint(f, " %A", a);
-			else
-				fmtprint(f, " %r");
-			amf0free(a);
-		}
-	}
 
 	return 0;
 }