ref: b93aad5650ddf5cd776a0e7c827eaeae750b251c
dir: /adts.c/
#include <u.h>
#include <libc.h>
#include <bio.h>
#include "adts.h"
#include "util.h"
int
adtsread(Biobuf *b, ADTSFrame *f)
{
u8int h[7];
if(Bread(b, h, 7) != 7)
goto err;
if(h[0] != 0xff || (h[1]&0xf0) != 0xf0){
werrstr("bad sync word");
goto err;
}
f->sz = h[4]<<3 | h[5]>>5;
if(f->sz < 7){
werrstr("frame too small (%d bytes)", f->sz);
goto err;
}
if(f->sz > f->bufsz){
f->bufsz = f->sz*2;
f->buf = erealloc(f->buf, f->bufsz);
}
memmove(f->buf, h, 7);
if(Bread(b, f->buf+7, f->sz-7) != f->sz-7)
goto err;
return 0;
err:
werrstr("adtsread: %r");
return -1;
}