ref: e95674db1eb82210f12fb429cc848613e24e704f
parent: dad1582627ca77f86f0a6c64d9503a36cab8f00c
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Thu Jul 29 09:43:53 EDT 2021
[Aa]mf0 → [Aa]₀
--- a/amf0.c
+++ b/amf0.c
@@ -24,13 +24,13 @@
}while(0)
u8int *
-amf0null(u8int *p, u8int *e)
+a₀null(u8int *p, u8int *e)
{
- return amf0byte(p, e, Anull);
+ return a₀byte(p, e, Anull);
}
u8int *
-amf0bool(u8int *p, u8int *e, int v)
+a₀bool(u8int *p, u8int *e, int v)
{
atleast("bool", 2);
*p++ = Abool;
@@ -39,7 +39,7 @@
}
u8int *
-amf0byte(u8int *p, u8int *e, u8int byte)
+a₀byte(u8int *p, u8int *e, u8int byte)
{
atleast("byte", 1);
*p++ = byte;
@@ -47,7 +47,7 @@
}
u8int *
-amf0i16(u8int *p, u8int *e, s16int i)
+a₀i16(u8int *p, u8int *e, s16int i)
{
atleast("i16", 2);
*p++ = i >> 8;
@@ -56,7 +56,7 @@
}
u8int *
-amf0i24(u8int *p, u8int *e, s32int i)
+a₀i24(u8int *p, u8int *e, s32int i)
{
atleast("i24", 3);
*p++ = i >> 16;
@@ -66,7 +66,7 @@
}
u8int *
-amf0i32(u8int *p, u8int *e, s32int i)
+a₀i32(u8int *p, u8int *e, s32int i)
{
atleast("i32", 4);
*p++ = i >> 24;
@@ -77,7 +77,7 @@
}
u8int *
-amf0num(u8int *p, u8int *e, double v)
+a₀num(u8int *p, u8int *e, double v)
{
union {
double v;
@@ -100,7 +100,7 @@
}
u8int *
-amf0str(u8int *p, u8int *e, char *s)
+a₀str(u8int *p, u8int *e, char *s)
{
int n;
@@ -108,34 +108,34 @@
if(n <= 0xffff){
atleast("str", 1+2+n);
*p++ = Astr;
- return (u8int*)memmove(amf0i16(p, e, n), s, n) + n;
+ return (u8int*)memmove(a₀i16(p, e, n), s, n) + n;
}
atleast("lstr", 1+4+n);
*p++ = Alstr;
- return (u8int*)memmove(amf0i32(p, e, n), s, n) + n;
+ return (u8int*)memmove(a₀i32(p, e, n), s, n) + n;
}
u8int *
-amf0arr(u8int *p, u8int *e)
+a₀arr(u8int *p, u8int *e)
{
- return amf0byte(p, e, Aarr);
+ return a₀byte(p, e, Aarr);
}
u8int *
-amf0obj(u8int *p, u8int *e)
+a₀obj(u8int *p, u8int *e)
{
- return amf0byte(p, e, Aobj);
+ return a₀byte(p, e, Aobj);
}
u8int *
-amf0end(u8int *p, u8int *e)
+a₀end(u8int *p, u8int *e)
{
- return amf0i24(p, e, Aend);
+ return a₀i24(p, e, Aend);
}
static u8int *
-amf0kv(u8int *p, u8int *e, char *name)
+a₀kv(u8int *p, u8int *e, char *name)
{
int n;
@@ -144,31 +144,31 @@
return nil;
}
atleast("kv", 2+n);
- p = amf0i16(p, e, n);
+ p = a₀i16(p, e, n);
return (u8int*)memmove(p, name, n) + n;
}
u8int *
-amf0kvbool(u8int *p, u8int *e, char *name, int v)
+a₀kvbool(u8int *p, u8int *e, char *name, int v)
{
- return amf0bool(amf0kv(p, e, name), e, v);
+ return a₀bool(a₀kv(p, e, name), e, v);
}
u8int *
-amf0kvnum(u8int *p, u8int *e, char *name, double v)
+a₀kvnum(u8int *p, u8int *e, char *name, double v)
{
- return amf0num(amf0kv(p, e, name), e, v);
+ return a₀num(a₀kv(p, e, name), e, v);
}
u8int *
-amf0kvstr(u8int *p, u8int *e, char *name, char *v)
+a₀kvstr(u8int *p, u8int *e, char *name, char *v)
{
- return amf0str(amf0kv(p, e, name), e, v);
+ return a₀str(a₀kv(p, e, name), e, v);
}
u8int *
-amf0byteget(u8int *p, u8int *e, u8int *byte)
+a₀byteget(u8int *p, u8int *e, u8int *byte)
{
atleast("byte", 1);
*byte = *p;
@@ -176,7 +176,7 @@
}
u8int *
-amf0i16get(u8int *p, u8int *e, s16int *i)
+a₀i16get(u8int *p, u8int *e, s16int *i)
{
atleast("i16", 2);
*i = p[0]<<8 | p[1];
@@ -184,7 +184,7 @@
}
u8int *
-amf0i24get(u8int *p, u8int *e, s32int *i)
+a₀i24get(u8int *p, u8int *e, s32int *i)
{
atleast("i24", 3);
*i = p[0]<<16 | p[1]<<8 | p[2];
@@ -192,7 +192,7 @@
}
u8int *
-amf0i32get(u8int *p, u8int *e, s32int *i)
+a₀i32get(u8int *p, u8int *e, s32int *i)
{
atleast("i32", 4);
*i = p[0]<<24 | p[1]<<16 | p[2]<<8 | p[3];
@@ -200,7 +200,7 @@
}
u8int *
-amf0i32leget(u8int *p, u8int *e, s32int *i)
+a₀i32leget(u8int *p, u8int *e, s32int *i)
{
atleast("i32le", 4);
*i = p[0] | p[1]<<8 | p[2]<<16 | p[3]<<24;
@@ -208,7 +208,7 @@
}
void
-amf0free(Amf0 *a)
+a₀free(A₀ *a)
{
int i;
@@ -222,18 +222,18 @@
case Tobj:
for(i = 0; i < a->obj.n; i++){
free(a->obj.k[i]);
- amf0free(a->obj.v[i]);
+ a₀free(a->obj.v[i]);
}
break;
case Tarr:
for(i = 0; i < a->arr.n; i++)
- amf0free(a->arr.v[i]);
+ a₀free(a->arr.v[i]);
case Tnull:
case Tnum:
case Tbool:
break;
default:
- sysfatal("unknown amf0 type %d", a->type);
+ sysfatal("unknown a₀ type %d", a->type);
}
free(a);
@@ -240,7 +240,7 @@
}
u8int *
-amf0parse(Amf0 **amf0, u8int *p, u8int *e)
+a₀parse(A₀ **a₀, u8int *p, u8int *e)
{
s16int s16;
union {
@@ -248,9 +248,9 @@
u64int u;
}x;
int n;
- Amf0 *a;
+ A₀ *a;
- *amf0 = nil;
+ *a₀ = nil;
atleast("type", 1);
a = ecalloc(1, sizeof(*a));
a->type = -1;
@@ -272,11 +272,11 @@
a->type = Tbool;
break;
case Alstr:
- if((p = amf0i32get(p, e, &n)) == nil)
+ if((p = a₀i32get(p, e, &n)) == nil)
return nil;
if(0){
case Astr:
- if((p = amf0i16get(p, e, &s16)) == nil)
+ if((p = a₀i16get(p, e, &s16)) == nil)
return nil;
n = s16;
}
@@ -288,7 +288,7 @@
case Aobj:
atleast("obj", 3); /* Aend should be there anyway */
for(a->obj.n = 0;;){
- if((p = amf0i16get(p, e, &s16)) == nil)
+ if((p = a₀i16get(p, e, &s16)) == nil)
break;
if(s16 == 0){
atleast("obj end?", 1);
@@ -307,7 +307,7 @@
a->obj.v = erealloc(a->obj.v, sizeof(*a->obj.v)*a->obj.n);
a->obj.k[a->obj.n-1] = estrndup(p, n);
p += n;
- if((p = amf0parse(&a->obj.v[a->obj.n-1], p, e)) == nil){
+ if((p = a₀parse(&a->obj.v[a->obj.n-1], p, e)) == nil){
werrstr("obj val: %r");
break;
}
@@ -315,16 +315,16 @@
a->type = Tobj;
break;
case Aarr:
- if((p = amf0i32get(p, e, &a->arr.n)) == nil)
+ if((p = a₀i32get(p, e, &a->arr.n)) == nil)
break;
a->arr.v = emalloc(sizeof(*a->arr.v)*a->arr.n);
for(n = 0; n < a->arr.n; n++){
- if((p = amf0parse(&a->arr.v[n], p, e)) == nil){
+ if((p = a₀parse(&a->arr.v[n], p, e)) == nil){
werrstr("arr el: %r");
break;
}
}
- if((p = amf0i24get(p, e, &n)) == nil || n != Aend){
+ if((p = a₀i24get(p, e, &n)) == nil || n != Aend){
p = nil;
werrstr("array doesn't end with Aend");
}
@@ -341,20 +341,20 @@
}
if(p == nil)
- amf0free(a);
+ a₀free(a);
else
- *amf0 = a;
+ *a₀ = a;
return p;
}
int
-amf0fmt(Fmt *f)
+a₀fmt(Fmt *f)
{
- Amf0 *a;
+ A₀ *a;
int i;
- a = va_arg(f->args, Amf0*);
+ a = va_arg(f->args, A₀*);
switch(a->type){
case Tstr:
@@ -382,7 +382,7 @@
fmtprint(f, "null");
break;
default:
- sysfatal("unknown amf0 type %d", a->type);
+ sysfatal("unknown a₀ type %d", a->type);
}
return 0;
--- a/amf0.h
+++ b/amf0.h
@@ -7,9 +7,9 @@
Tobj,
};
-typedef struct Amf0 Amf0;
+typedef struct A₀ A₀;
-struct Amf0 {
+struct A₀ {
int type;
union {
char *str;
@@ -16,40 +16,40 @@
double num;
u8int bool;
struct {
- Amf0 **v;
+ A₀ **v;
int n;
}arr;
struct {
char **k;
- Amf0 **v;
+ A₀ **v;
int n;
}obj;
};
};
-u8int *amf0null(u8int *p, u8int *e);
-u8int *amf0i16(u8int *p, u8int *e, s16int i);
-u8int *amf0bool(u8int *p, u8int *e, int v);
-u8int *amf0byte(u8int *p, u8int *e, u8int byte);
-u8int *amf0i24(u8int *p, u8int *e, s32int i);
-u8int *amf0i32(u8int *p, u8int *e, s32int i);
-u8int *amf0num(u8int *p, u8int *e, double v);
-u8int *amf0str(u8int *p, u8int *e, char *s);
-u8int *amf0arr(u8int *p, u8int *e);
-u8int *amf0obj(u8int *p, u8int *e);
-u8int *amf0end(u8int *p, u8int *e);
-u8int *amf0kvnum(u8int *p, u8int *e, char *name, double v);
-u8int *amf0kvstr(u8int *p, u8int *e, char *name, char *v);
-u8int *amf0kvbool(u8int *p, u8int *e, char *name, int v);
+u8int *a₀null(u8int *p, u8int *e);
+u8int *a₀i16(u8int *p, u8int *e, s16int i);
+u8int *a₀bool(u8int *p, u8int *e, int v);
+u8int *a₀byte(u8int *p, u8int *e, u8int byte);
+u8int *a₀i24(u8int *p, u8int *e, s32int i);
+u8int *a₀i32(u8int *p, u8int *e, s32int i);
+u8int *a₀num(u8int *p, u8int *e, double v);
+u8int *a₀str(u8int *p, u8int *e, char *s);
+u8int *a₀arr(u8int *p, u8int *e);
+u8int *a₀obj(u8int *p, u8int *e);
+u8int *a₀end(u8int *p, u8int *e);
+u8int *a₀kvnum(u8int *p, u8int *e, char *name, double v);
+u8int *a₀kvstr(u8int *p, u8int *e, char *name, char *v);
+u8int *a₀kvbool(u8int *p, u8int *e, char *name, int v);
-u8int *amf0byteget(u8int *p, u8int *e, u8int *byte);
-u8int *amf0i16get(u8int *p, u8int *e, s16int *i);
-u8int *amf0i24get(u8int *p, u8int *e, s32int *i);
-u8int *amf0i32get(u8int *p, u8int *e, s32int *i);
-u8int *amf0i32leget(u8int *p, u8int *e, s32int *i);
+u8int *a₀byteget(u8int *p, u8int *e, u8int *byte);
+u8int *a₀i16get(u8int *p, u8int *e, s16int *i);
+u8int *a₀i24get(u8int *p, u8int *e, s32int *i);
+u8int *a₀i32get(u8int *p, u8int *e, s32int *i);
+u8int *a₀i32leget(u8int *p, u8int *e, s32int *i);
-u8int *amf0parse(Amf0 **a, u8int *p, u8int *e);
-void amf0free(Amf0 *a);
+u8int *a₀parse(A₀ **a, u8int *p, u8int *e);
+void a₀free(A₀ *a);
-#pragma varargck type "A" Amf0*
-int amf0fmt(Fmt *f);
+#pragma varargck type "A" A₀*
+int a₀fmt(Fmt *f);
--- a/flv.c
+++ b/flv.c
@@ -27,25 +27,25 @@
p0 = p;
*p++ = Fvideo;
psz = p;
- p = amf0i24(p, e, 0); /* sz set later */
- p = amf0i24(p, e, ts);
+ p = a₀i24(p, e, 0); /* sz set later */
+ p = a₀i24(p, e, ts);
*p++ = ts>>24;
- p = amf0i24(p, e, stream);
+ p = a₀i24(p, e, stream);
d = p;
- p = amf0str(p, e, "onMetaData");
- p = amf0arr(p, e);
- p = amf0i32(p, e, audio ? 5 : 4);
- p = amf0kvnum(p, e, "duration", 0.0);
- p = amf0kvnum(p, e, "width", w);
- p = amf0kvnum(p, e, "height", h);
- p = amf0kvnum(p, e, "videocodecid", EncH264);
+ p = a₀str(p, e, "onMetaData");
+ p = a₀arr(p, e);
+ p = a₀i32(p, e, audio ? 5 : 4);
+ p = a₀kvnum(p, e, "duration", 0.0);
+ p = a₀kvnum(p, e, "width", w);
+ p = a₀kvnum(p, e, "height", h);
+ p = a₀kvnum(p, e, "videocodecid", EncH264);
if(audio)
- p = amf0kvnum(p, e, "audiocodecid", EncAAC);
- p = amf0end(p, e);
- amf0i24(psz, e, p-d);
+ p = a₀kvnum(p, e, "audiocodecid", EncAAC);
+ p = a₀end(p, e);
+ a₀i24(psz, e, p-d);
- return amf0i32(p, e, p-p0);
+ return a₀i32(p, e, p-p0);
}
u8int *
@@ -61,10 +61,10 @@
p0 = p;
*p++ = type;
psz = p;
- p = amf0i24(p, e, 0); /* size to be set later */
- p = amf0i24(p, e, dts);
+ p = a₀i24(p, e, 0); /* size to be set later */
+ p = a₀i24(p, e, dts);
*p++ = dts >> 24;
- p = amf0i24(p, e, stream);
+ p = a₀i24(p, e, stream);
d = p;
if(type == Faudio){
@@ -75,12 +75,12 @@
*p++ = ((fl & FlKey) ? 0x10 : 0x20) | EncH264;
*p++ = (fl & FlHdr) ? 0 : 1;
pts = ((fl & FlHdr) || pts < dts) ? 0 : (pts - dts);
- p = amf0i24(p, e, pts);
+ p = a₀i24(p, e, pts);
if((fl & FlHdr) == 0)
- p = amf0i32(p, e, sz);
+ p = a₀i32(p, e, sz);
}
p = (u8int*)memmove(p, data, sz) + sz;
- amf0i24(psz, e, p-d);
+ a₀i24(psz, e, p-d);
- return amf0i32(p, e, p-p0);
+ return a₀i32(p, e, p-p0);
}
--- a/rtmp.c
+++ b/rtmp.c
@@ -72,7 +72,7 @@
#pragma varargck type "M" Message*
struct Command {
- void (*cb)(RTMP *r, int ok, Amf0 *a[NumCb], void *aux);
+ void (*cb)(RTMP *r, int ok, A₀ *a[NumCb], void *aux);
void *aux;
int tid;
@@ -114,18 +114,18 @@
u8int biobuf[Biobufsz];
};
-#define putnull() do{ r->p = amf0null(r->p, r->e); }while(0)
-#define puti16(i) do{ r->p = amf0i16(r->p, r->e, i); }while(0)
-#define puti24(i) do{ r->p = amf0i24(r->p, r->e, i); }while(0)
-#define puti32(i) do{ r->p = amf0i32(r->p, r->e, i); }while(0)
-#define putnum(v) do{ r->p = amf0num(r->p, r->e, v); }while(0)
-#define putstr(s) do{ r->p = amf0str(r->p, r->e, s); }while(0)
-#define putarr() do{ r->p = amf0arr(r->p, r->e); }while(0)
-#define putobj() do{ r->p = amf0obj(r->p, r->e); }while(0)
-#define putend() do{ r->p = amf0end(r->p, r->e); }while(0)
-#define putkvnum(name, v) do{ r->p = amf0kvnum(r->p, r->e, name, v); }while(0)
-#define putkvstr(name, s) do{ r->p = amf0kvstr(r->p, r->e, name, s); }while(0)
-#define putkvbool(name, s) do{ r->p = amf0kvbool(r->p, r->e, name, s); }while(0)
+#define putnull() do{ r->p = a₀null(r->p, r->e); }while(0)
+#define puti16(i) do{ r->p = a₀i16(r->p, r->e, i); }while(0)
+#define puti24(i) do{ r->p = a₀i24(r->p, r->e, i); }while(0)
+#define puti32(i) do{ r->p = a₀i32(r->p, r->e, i); }while(0)
+#define putnum(v) do{ r->p = a₀num(r->p, r->e, v); }while(0)
+#define putstr(s) do{ r->p = a₀str(r->p, r->e, s); }while(0)
+#define putarr() do{ r->p = a₀arr(r->p, r->e); }while(0)
+#define putobj() do{ r->p = a₀obj(r->p, r->e); }while(0)
+#define putend() do{ r->p = a₀end(r->p, r->e); }while(0)
+#define putkvnum(name, v) do{ r->p = a₀kvnum(r->p, r->e, name, v); }while(0)
+#define putkvstr(name, s) do{ r->p = a₀kvstr(r->p, r->e, name, s); }while(0)
+#define putkvbool(name, s) do{ r->p = a₀kvbool(r->p, r->e, name, s); }while(0)
#define putcommand(name, cb_) do { \
putstr(name); \
@@ -240,13 +240,13 @@
ts = 0;
len = 0;
if(hsz >= szs[Type2]){
- h = amf0i24get(h, e, (s32int*)&ts); /* FIXME proper timestamps? */
+ h = a₀i24get(h, e, (s32int*)&ts); /* FIXME proper timestamps? */
if(hsz >= szs[Type1]){
- h = amf0i24get(h, e, &len);
- h = amf0byteget(h, e, &byte);
+ h = a₀i24get(h, e, &len);
+ h = a₀byteget(h, e, &byte);
r->msg.type = byte;
if(hsz >= szs[Type0])
- h = amf0i32leget(h, e, &msid);
+ h = a₀i32leget(h, e, &msid);
}
}
@@ -253,7 +253,7 @@
if(ts == 0xffffff){ /* exntended timestamp */
if(readn(r->i, h, 4) != 4)
goto err;
- h = amf0i32get(h, h+4, (s32int*)&ts);
+ h = a₀i32get(h, h+4, (s32int*)&ts);
}
/* FIXME do all consecutive chunks use Type3? */
@@ -302,12 +302,12 @@
hsz = szs[r->msg.fmt];
e = h + hsz;
if(hsz >= szs[Type2]){
- h = amf0i24(h, e, 0); /* FIXME put actual timestamps? */
+ h = a₀i24(h, e, 0); /* FIXME put actual timestamps? */
if(hsz >= szs[Type1]){
- h = amf0i24(h, e, r->msg.sz);
- h = amf0byte(h, e, r->msg.type);
+ h = a₀i24(h, e, r->msg.sz);
+ h = a₀byte(h, e, r->msg.type);
if(hsz >= szs[Type0])
- h = amf0i32(h, e, r->msg.sid);
+ h = a₀i32(h, e, r->msg.sid);
}
}
assert(h != nil);
@@ -333,17 +333,17 @@
if(debug){
fprint(2, "← %M", &r->msg);
if(r->msg.type == AMF0Command){
- Amf0 *a;
+ A₀ *a;
u8int *s, *e;
fprint(2, ":");
s = r->msg.data;
e = s + r->msg.sz;
for(; s != nil && s != e;){
- if((s = amf0parse(&a, s, e)) != nil)
+ if((s = a₀parse(&a, s, e)) != nil)
fprint(2, " %A", a);
else
fprint(2, " %r");
- amf0free(a);
+ a₀free(a);
}
}
fprint(2, "\n");
@@ -406,7 +406,7 @@
loop(void *aux)
{
int res, n, ok;
- Amf0 *a[NumCb];
+ A₀ *a[NumCb];
u8int *s, *e;
s16int s16;
Message *m;
@@ -419,7 +419,7 @@
memset(a, 0, sizeof(a));
for(;;){
for(n = 0; n < nelem(a); n++)
- amf0free(a[n]);
+ a₀free(a[n]);
memset(a, 0, sizeof(a));
qlock(r);
@@ -428,7 +428,7 @@
if(debug)
fprint(2, "rtmp loop: %r\n");
for(n = 0; n < nelem(a); n++)
- amf0free(a[n]);
+ a₀free(a[n]);
break;
}
@@ -443,7 +443,7 @@
c = nil;
ok = 1;
for(n = 0; n < NumCb; n++){
- if((s = amf0parse(&a[n], s, e)) == nil)
+ if((s = a₀parse(&a[n], s, e)) == nil)
goto err;
switch(n){
case CbCommand:
@@ -481,7 +481,7 @@
break;
case SetChunkSize:
- if(amf0i32get(s, e, &r->chunkin) == nil)
+ if(a₀i32get(s, e, &r->chunkin) == nil)
goto err;
if(r->chunkin < 2){
werrstr("invalid chunk size: %d", r->chunkin);
@@ -492,9 +492,9 @@
break;
case UserControl:
- if((s = amf0i16get(s, e, &s16)) == nil)
+ if((s = a₀i16get(s, e, &s16)) == nil)
goto err;
- if(amf0i32get(s, e, &n) == nil)
+ if(a₀i32get(s, e, &n) == nil)
n = -1;
switch(s16){
case CtlStreamBegin:
@@ -518,7 +518,7 @@
break;
case WindowAckSize:
- if(amf0i32get(s, e, &r->winacksz) == nil)
+ if(a₀i32get(s, e, &r->winacksz) == nil)
goto err;
if(debug)
fprint(2, ": %d\n", r->winacksz);
@@ -525,7 +525,7 @@
break;
case SetBandwidth:
- if((s = amf0i32get(s, e, &r->bw)) == nil || amf0byteget(s, e, &r->bwlimit) == nil)
+ if((s = a₀i32get(s, e, &r->bw)) == nil || a₀byteget(s, e, &r->bwlimit) == nil)
goto err;
if(debug)
fprint(2, ": %d (%s)\n", r->bw, r->bwlimit < nelem(bwlimit2s) ? bwlimit2s[r->bwlimit] : "???");
@@ -594,7 +594,7 @@
}
static void
-streamcreated(RTMP *, int ok, Amf0 *a[NumCb], void *aux)
+streamcreated(RTMP *, int ok, A₀ *a[NumCb], void *aux)
{
Channel *sid;
@@ -638,7 +638,7 @@
}
static void
-connected(RTMP *r, int ok, Amf0 *a[NumCb], void *)
+connected(RTMP *r, int ok, A₀ *a[NumCb], void *)
{
if(strcmp(a[CbCommand]->str, "_result") != 0)
sendp(r->c, smprint("expected '_result', got %#q", a[CbCommand]->str));
@@ -698,7 +698,7 @@
int f, port, ctl;
RTMP *r;
- fmtinstall('A', amf0fmt);
+ fmtinstall('A', a₀fmt);
fmtinstall('T', msgtypefmt);
fmtinstall('M', msgfmt);
quotefmtinstall();