shithub: rtmp

Download patch

ref: d70eab81a43d6d7e4d6fc7a9b6fb040db8438551
parent: 51261f3745a0dc575946599e03fcb22b122fb2f6
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Thu Jul 29 07:31:02 EDT 2021

set out chunk size to 4096 after connecting

--- a/rtmp.c
+++ b/rtmp.c
@@ -13,7 +13,8 @@
 enum {
 	Port = 1935,
 	CSsz = 1536,
-	Chunk = 128,
+	ChunkDefault = 128,
+	ChunkDesired = 4096,
 
 	Type0 = 0,
 	Type1,
@@ -384,6 +385,19 @@
 	return rtmpsend(r);
 }
 
+static int
+setchunksz(RTMP *r, int sz)
+{
+	int n;
+
+	newmsg(r, SetChunkSize, Type0, CSUserCtl);
+	puti32(sz);
+	n = rtmpsend(r);
+	r->chunkout = sz;
+
+	return n;
+}
+
 static void
 loop(void *aux)
 {
@@ -449,7 +463,7 @@
 				}
 			}
 			if(debug)
-				fprint(2, " tid=%A: %A %A %A", a[CbTransID], a[CbCommand], a[CbObject], a[CbResponse]);
+				fprint(2, " tid=%A: %A %A %A\n", a[CbTransID], a[CbCommand], a[CbObject], a[CbResponse]);
 			if(c->prev != nil)
 				c->prev->next = c->next;
 			if(c->next != nil)
@@ -468,7 +482,7 @@
 				goto err;
 			}
 			if(debug)
-				fprint(2, ": %d", r->chunkin);
+				fprint(2, ": %d\n", r->chunkin);
 			break;
 
 		case UserControl:
@@ -488,11 +502,11 @@
 						goto err;
 				}
 				if(debug)
-					fprint(2, ": %s %d", ctl2s[s16], n);
+					fprint(2, ": %s %d\n", ctl2s[s16], n);
 				break;
 			default:
 				if(debug)
-					fprint(2, ": ?%d? %d", s16, n);
+					fprint(2, ": ?%d? %d\n", s16, n);
 				break;
 			}
 			break;
@@ -501,7 +515,7 @@
 			if(amf0i32get(s, e, &r->winacksz) == nil)
 				goto err;
 			if(debug)
-				fprint(2, ": %d", r->winacksz);
+				fprint(2, ": %d\n", r->winacksz);
 			break;
 
 		case SetBandwidth:
@@ -508,7 +522,7 @@
 			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] : "???");
+				fprint(2, ": %d (%s)\n", r->bw, r->bwlimit < nelem(bwlimit2s) ? bwlimit2s[r->bwlimit] : "???");
 			break;
 
 		/* FIXME */
@@ -525,15 +539,12 @@
 		case AMF3SharedObject:
 		case AMF3Command:
 			if(debug)
-				fprint(2, ": ignored");
+				fprint(2, ": ignored\n");
 			break;
 err:
 			res = -1;
 			break;
 		}
-
-		if(debug)
-			fprint(2, "\n");
 	}
 
 	rtmpfree(r);
@@ -577,8 +588,11 @@
 {
 	if(strcmp(a[CbCommand]->str, "_result") != 0)
 		sendp(r->c, smprint("expected '_result', got %#q", a[CbCommand]->str));
-	else
+	else{
 		sendp(r->c, ok ? nil : smprint("%A", a[CbResponse]));
+		if(ok)
+			setchunksz(r, ChunkDesired);
+	}
 }
 
 static int
@@ -685,8 +699,8 @@
 
 	r = ecalloc(1, sizeof(*r));
 	r->i = f;
-	r->chunkin = Chunk;
-	r->chunkout = Chunk;
+	r->chunkin = ChunkDefault;
+	r->chunkout = ChunkDefault;
 	r->tcurl = url;
 	url = nil;
 	r->c = chancreate(sizeof(void*), 0);