ref: e3323cec8ab6bb99f1aff62ed2987feb786b8bbd
parent: adf3227845db11bde5f89abc0ca54864c4f8747d
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Fri Aug 13 08:26:51 EDT 2021
use a function to convert timestamps
--- a/main.c
+++ b/main.c
@@ -22,6 +22,15 @@
threadexitsall("usage");
}
+static uvlong
+ns2ms(uvlong z, uvlong ns)
+{
+ if(z != 0 && z != Zns₀)
+ ns = z - ns₀ + ns;
+
+ return ns / 1000000ULL;
+}
+
static void
audio(void *aux)
{
@@ -37,7 +46,7 @@
goto err;
if(af.sz == 0) /* eof */
break;
- ms = ((af.ns₀ != Zns₀ ? af.ns₀-ns₀ : 0) + af.ns)/1000000ULL;
+ ms = ns2ms(af.ns₀, af.ns);
if(rtmpdata(r, sid, ms, Taudio, af.buf, af.sz) != 0){
err:
@@ -103,7 +112,7 @@
sysfatal("%r");
if(vf.sz == 0)
break;
- ms = ((ivf.ns₀ != Zns₀ ? ivf.ns₀-ns₀ : 0) + vf.ns)/1000000ULL;
+ ms = ns2ms(ivf.ns₀, vf.ns);
if(rtmpdata(r, sid, ms, Tvideo, vf.buf, vf.sz) != 0){
fprint(2, "%r\n");
break;