shithub: treason

Download patch

ref: 978f94bf9b2f384157f14c3ee436206a5d6b6450
parent: 9bbed008d94cd67aacccfcb7128a2510a77a16b2
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Dec 14 09:16:31 EST 2020

display how late the video is, and audio stream information

--- a/main.c
+++ b/main.c
@@ -21,6 +21,7 @@
 static int showinfo;
 static uvlong dispdelay;
 static int framedrop;
+static uvlong late;
 
 static void
 audioproc(void *x)
@@ -53,12 +54,18 @@
 	uvlong x, end, left;
 	Rectangle r, clip;
 
+	x = nanosec();
 	if(lastframe == 0)
-		lastframe = nanosec();
+		lastframe = x;
 
 	end = lastframe + f->dt - dispdelay;
-	if(framedrop && dispdelay > 0 && nanosec() >= end+dispdelay)
-		goto drop;
+	if(dispdelay > 0 && x >= end+dispdelay){
+		late = x - (end+dispdelay);
+		if(framedrop)
+			goto drop;
+	}else{
+		late = 0;
+	}
 
 	lockdisplay(display);
 
@@ -234,14 +241,16 @@
 			case Cframe:
 				snprint(
 					info, sizeof(info),
-					"decode=%zdms yuv→rgb=%zdms display=%zdms total=%zdms %dx%d %s %s",
+					"decode=%-5zd yuv→rgb=%-3zd display=%-3zd total=%-3zd late=%-3zd %dx%d %s %s %s",
 					d->decodetime/1000000ULL,
 					dispdelay/1000000ULL,
 					yuv→rgb/1000000ULL,
 					(d->decodetime + dispdelay + yuv→rgb)/1000000ULL,
+					late/1000000ULL,
 					frame->w, frame->h,
 					d->info,
-					d->s->info
+					d->s->info,
+					saudio ? saudio->info : "no audio"
 				);
 				drawframe(frame);
 				break;
--- a/misc.c
+++ b/misc.c
@@ -25,6 +25,15 @@
 	return i < nelem(fmts) ? i : -1;
 }
 
+char *
+fmt2str(int fmt)
+{
+	if(fmt >= 0 && fmt < nelem(fmts))
+		return fmts[fmt];
+
+	return "???";
+}
+
 uvlong
 nanosec(void)
 {
--- a/misc.h
+++ b/misc.h
@@ -1,4 +1,5 @@
 int str2fmt(char *s);
+char *fmt2str(int fmt);
 uvlong nanosec(void);
 void yuv420_rgb24(
 	int width, int height,
--- a/stream_mc.c
+++ b/stream_mc.c
@@ -38,24 +38,6 @@
 	return pid;
 }
 
-static int
-audfmt(char *fmt)
-{
-	static char *fmts[] = {
-		[FmtAAC] = "aac",
-		[FmtOpus] = "opus",
-		[FmtVorbis] = "vorbis",
-	};
-	int i;
-
-	for(i = 0; i < nelem(fmts); i++){
-		if(fmts[i] != nil && strcmp(fmt, fmts[i]) == 0)
-			return i;
-	}
-
-	return -1;
-}
-
 static void
 freeaux(void *aux)
 {
@@ -113,9 +95,10 @@
 						ns++;
 					}
 				}
-			}else if(naudio < 1 && strcmp(v[1], "audio") == 0 && (s->fmt = audfmt(v[2])) >= 0){
+			}else if(naudio < 1 && strcmp(v[1], "audio") == 0 && (s->fmt = str2fmt(v[2])) >= 0){
 				s->audio.nchan = atoi(v[3]);
 				s->audio.srate = atoi(v[4]);
+				snprint(s->info, sizeof(s->info), "%s (%d %d)", v[2], s->audio.nchan, s->audio.srate);
 				if(mcfs(argv, &sp) > 0 && audopenfd(sp, s, failed) == 0){
 					naudio++;
 					ns++;