~ft/mcfs

abd3c14c70b91a3f4f6111c59248ab00c95a95bb — Sigrid Solveig Haflínudóttir 3 years ago f2ea43a
matroska: ogg: set Theora granule position according to the spec
2 files changed, 17 insertions(+), 3 deletions(-)

M ogg.c
M packet.h
M ogg.c => ogg.c +14 -1
@@ 13,6 13,14 @@ packet(Biobuf *out, Packetctx *ctx, int htype, Packet *p, int np, uvlong granule
	u32int crc;
	int psz, i, n, ntot, ip;

	if(ctx->frid == 0 && ctx->fmt == FmtTheora && np > 0 && p->sz > 41){
		if(memcmp(p->data, "\x80theora", 7) != 0){
			werrstr("invalid Theora packet");
			return -1;
		}
		ctx->kfgshift = ((p->data[40]<<8 | p->data[41]) >> 5) & 0x1f;
	}

	h[5] = htype;
	h[6] = granule;
	h[7] = granule >> 8;


@@ 131,7 139,12 @@ oggpacket(Biobuf *out, Packetctx *ctx, Packet *p, int np, uvlong ts, int key)
	}

	if(ctx->fmt == FmtTheora){
		gr = 0;
		ctx->nonkey++; /* FIXME VREV 1 vs 0 diff here, to make it work with 0 */
		if(key){
			ctx->key += ctx->nonkey;
			ctx->nonkey = 0;
		}
		gr = (uvlong)ctx->key<<ctx->kfgshift | ctx->nonkey;
	}else{
		gr = (ts * 48) / 1000000;
	}

M packet.h => packet.h +3 -2
@@ 30,8 30,6 @@ struct Packetctx {
	u32int trackuid;
	u32int fmt;

	int key;

	struct {
		int width;
		int height;


@@ 50,6 48,9 @@ struct Packetctx {
		int n;
	}ps[16];
	int nps;
	int key;
	int nonkey;
	int kfgshift;
};

int aacpacket(Biobuf *out, Packetctx *ctx, Packet *p, int np, uvlong ts, int key);