ref: 03ea1099fb54ca5a57a302b68d1519f9dee80a83
parent: 489f4a7962adf0243e6a1f81a97b564823970b80
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Aug 5 08:48:28 EDT 2021
rework closing
--- a/main.c
+++ b/main.c
@@ -19,7 +19,7 @@
void
threadmain(int argc, char **argv)
{
- Biobuf *a, *v;
+ Biobuf *a, v;
u64int ns;
ulong sid;
IVFrame f;
@@ -41,7 +41,7 @@
if(argc != 1)
usage();
- if((v = Bfdopen(0, OREAD)) == nil || ivfopen(v, &ivf) != 0)
+ if(Binit(&v, 0, OREAD) != 0 || ivfopen(&v, &ivf) != 0)
sysfatal("%r");
if(strcmp(ivf.type, "AVC1") != 0)
sysfatal("not H.264");
@@ -58,14 +58,20 @@
memset(&f, 0, sizeof(f));
for(;;){
- if(ivfread(v, &f) != 0)
+ if(ivfread(&v, &f) != 0)
sysfatal("%r");
if(f.sz == 0)
break;
ns = ivfns(&ivf, f.ts)/1000000ULL;
- if(rtmpdata(r, sid, ns, Tvideo, f.buf, f.sz) != 0)
- sysfatal("%r");
+ if(rtmpdata(r, sid, ns, Tvideo, f.buf, f.sz) != 0){
+ fprint(2, "%r\n");
+ break;
+ }
}
+
+ if(a != nil)
+ Bterm(a);
+ rtmpclose(r);
threadexitsall(nil);
}
--- a/rtmp.c
+++ b/rtmp.c
@@ -404,23 +404,6 @@
return -1;
}
-static void
-rtmpfree(RTMP *r)
-{
- free(r->i.b);
- free(r->o.b);
- free(r->tcurl);
- free(r->app);
- free(r->inst);
- free(r->path);
- if(r->c != nil){
- sendp(r->c, "done");
- chanfree(r->c);
- }
- Bterm(r);
- free(r);
-}
-
static int
pong(RTMP *r, s32int n)
{
@@ -621,7 +604,7 @@
qunlock(r);
}
- rtmpfree(r);
+ chanclose(r->c);
threadexitsall(res == 0 ? nil : "error");
}
@@ -994,7 +977,22 @@
return 0;
}
-RTMP *
+static void
+rtmpfree(RTMP *r)
+{
+ free(r->i.b);
+ free(r->o.b);
+ free(r->tcurl);
+ free(r->app);
+ free(r->inst);
+ free(r->path);
+ if(r->c != nil)
+ chanfree(r->c);
+ Bterm(r);
+ free(r);
+}
+
+RTMP *
rtmpdial(char *url)
{
char *s, *e, *p, *app, *inst, *path;
@@ -1098,5 +1096,6 @@
if(r->fd >= 0)
close(r->fd);
if(r->c != nil)
- chanclose(r->c);
+ recvp(r->c);
+ rtmpfree(r);
}