shithub: qoistream

Download patch

ref: 68a4d1cef5db92f15102ec14ae327430150e8d56
parent: 55134acef2cf72c82556521348d2917939faee1b
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Wed Jul 19 20:00:26 EDT 2023

qoisend: fix fps

--- a/qoisend.c
+++ b/qoisend.c
@@ -12,6 +12,7 @@
 };
 
 #define Nsec 1000000000ULL
+#define Nmsec 1000000ULL
 
 typedef struct Img Img;
 typedef union Pix Pix;
@@ -71,11 +72,11 @@
 	end = start + ns;
 	ns = start;
 	do{
-		if(end - ns > 85*Nsec)
+		if(end - ns > 85*Nmsec)
 			sleep(80);
-		else if (end - ns > 25*Nsec)
+		else if (end - ns > 25*Nmsec)
 			sleep(20);
-		else if (end - ns > 1*Nsec)
+		else if (end - ns > 1*Nmsec)
 			sleep(1);
 		else
 			break;
@@ -256,10 +257,9 @@
 	proccreate(encthread, nil, mainstacksize);
 
 	f₀ = nanosec();
-	for(nframes = 0;; nframes++){
+	for(nframes = 0;;){
 		fstart = nanosec();
-		if((img = imgread(in)) == nil)
-			continue;
+		while((img = imgread(in)) == nil);
 		if(sendp(frame, img) != 1)
 			break;
 		if(one){
@@ -267,6 +267,7 @@
 			recvul(done);
 		}
 		fend = nanosec();
+		nframes++;
 
 		if(debug && nframes > 0 && (nframes % fps) == 0){
 			fprint(2, "avg fps: %llud\n", nframes/((fend - f₀)/Nsec));