ref: 3f03592d6961c9f33b681b3269803739766b0c4b
dir: /decoder.c/
#include <u.h> #include <libc.h> #include <thread.h> #include "stream.h" #include "decoder.h" #include "frame.h" extern Decoderops av1ops; static struct { char *name; Decoderops *o; int fmt; }ops[] = { {"AV1", &av1ops, FmtAV1}, }; Decoder * Dopen(Stream *s) { Decoder *d; int i; if((d = calloc(1, sizeof(*d))) == nil) return nil; d->timebase = (double)s->timebase.num/(double)s->timebase.denum; d->s = s; d->frames = chancreate(sizeof(Frame*), 4); d->finished = chancreate(sizeof(void*), 1); d->stop = chancreate(sizeof(void*), 1); for(i = 0; i < nelem(ops); i++){ if(ops[i].fmt == s->fmt){ if(ops[i].o->open(d) < 0){ werrstr("%s: %r", ops[i].name); goto err; } d->ops = ops[i].o; break; } } assert(i < nelem(ops)); return d; err: return nil; } void Dclose(Decoder *d) { d->ops->close(d); chanclose(d->frames); sendp(d->stop, nil); recvp(d->finished); chanclose(d->stop); chanclose(d->finished); free(d); }