ref: 55fd4285c635d6e55c6fa440cd523c264be5bf4a
parent: c5cb931f107d750192ca2c0a2b9d270acec68905
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Sun Aug 8 12:28:00 EDT 2021
put audio reading into a separate proc
--- a/README.md
+++ b/README.md
@@ -17,3 +17,5 @@
this (change according to your preferences):
video/hj264 -f 10 /dev/screen | video/rtmp -a <{audio/aacenc </dev/audio} rtmp://....
+
+Audio loopback isn't ready yet.
--- a/main.c
+++ b/main.c
@@ -10,6 +10,9 @@
int mainstacksize = 65536;
int debug = 0;
+static RTMP *r;
+static ulong sid;
+
static void
usage(void)
{
@@ -17,16 +20,39 @@
threadexitsall("usage");
}
+static void
+audio(void *aux)
+{
+ ADTSFrame af;
+ Biobuf *a;
+ u64int ms;
+
+ a = aux;
+ memset(&af, 0, sizeof(af));
+ for(;;){
+ if(adtsread(a, &af) != 0)
+ sysfatal("%r");
+ if(af.sz == 0)
+ break;
+ ms = af.ns/1000000ULL;
+ if(rtmpdata(r, sid, ms, Taudio, af.buf, af.sz) != 0){
+ fprint(2, "%r\n");
+ break;
+ }
+ }
+
+ /* FIXME properly close RTMP connection */
+
+ threadexitsall(nil);
+}
+
void
threadmain(int argc, char **argv)
{
- u64int ms, until;
Biobuf *a, v;
- ADTSFrame af;
IVFrame vf;
- ulong sid;
+ u64int ms;
IVF ivf;
- RTMP *r;
a = nil;
ARGBEGIN{
@@ -58,7 +84,9 @@
sysfatal("%r");
}
- memset(&af, 0, sizeof(af));
+ if(a != nil)
+ proccreate(audio, a, mainstacksize);
+
memset(&vf, 0, sizeof(vf));
for(;;){
if(ivfread(&v, &vf) != 0)
@@ -70,27 +98,9 @@
fprint(2, "%r\n");
break;
}
-
- /* FIXME obviously this has to run in a separate frame (same for video, actually) */
- if(a == nil)
- continue;
- until = ms + 250; /* provide audio enough to cover + 250 ms over video */
- do{
- if(adtsread(a, &af) != 0)
- sysfatal("%r");
- if(af.sz == 0)
- break;
- ms = af.ns/1000000ULL;
- if(rtmpdata(r, sid, ms, Taudio, af.buf, af.sz) != 0){
- fprint(2, "%r\n");
- break;
- }
- }while(ms < until);
}
- if(a != nil)
- Bterm(a);
- rtmpclose(r);
+ /* FIXME properly close RTMP connection */
threadexitsall(nil);
}