shithub: rtmp

Download patch

ref: daf4e542e31036ad232613f82ca1c5d100a270a2
parent: f68aad9c7e2b465cffecdd033e3a4c6612dfa40c
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Aug 13 07:42:14 EDT 2021

protect against audio overruns

--- a/main.c
+++ b/main.c
@@ -13,6 +13,7 @@
 static RTMP *r;
 static ulong sid;
 static uvlong ns₀;
+static uvlong vms;
 
 static void
 usage(void)
@@ -32,14 +33,20 @@
 	memset(&af, 0, sizeof(af));
 	for(;;){
 		if(adtsread(a, &af) != 0)
-			sysfatal("%r");
-		if(af.sz == 0)
+			goto err;
+		if(af.sz == 0) /* eof */
 			break;
 		ms = (af.ns₀ - ns₀ + af.ns)/1000000ULL;
+
 		if(rtmpdata(r, sid, ms, Taudio, af.buf, af.sz) != 0){
+err:
 			fprint(2, "%r\n");
 			break;
 		}
+
+		/* protect against overruns */
+		if(vms+200 < ms)
+			sleep(100);
 	}
 
 	/* FIXME properly close RTMP connection */
@@ -100,6 +107,7 @@
 			fprint(2, "%r\n");
 			break;
 		}
+		vms = ms;
 	}
 
 	/* FIXME properly close RTMP connection */