#include <u.h>#include <libc.h>#include "stream.h" extern Streamops ivfops, mcops, audops; static struct { char *name; Streamops *o;}ops[] = { {"ivf", &ivfops}, {"mc", &mcops}, {"audio", &audops},}; Stream *Sopen(char *filename, int *num){ int i, failed; Stream *s; char *f; *num = 0; for(i = 0; i < nelem(ops); i++){ failed = 0; if((s = ops[i].o->open(filename, num, &failed)) != nil){ f = utfrrune(filename, '/'); if(f == nil) f = filename; else f++; snprint(s->info, sizeof(s->info), "%s [%s]", ops[i].name, f); s->t₀ = Zt₀; return s; } if(failed){ werrstr("%s: %r", ops[i].name); return nil; } } werrstr("unknown format"); return nil;} voidSclose(Stream *s){ if(s == nil || s->type < 0) return; s->ops.close(s); s->type = -1; if(s->freeaux != nil) s->freeaux(s->aux);} intSread(Stream *s, Streamframe *f){ int res; if(s == nil || s->type < 0){ werrstr("invalid stream"); return -1; } if((res = s->ops.read(s, f)) == 0){ if(s->t₀ == Zt₀) s->t₀ = f->timestamp; /* * timestamps going backwards means clock wasn't monotonically * increasing. perhaps nanosec() or nsec() is to blame. * just work around it in any case, instead of hanging without * displaying any frames. */ if(f->timestamp > s->t₀) f->timestamp -= s->t₀; else f->timestamp = 0; } return res;}
#include <u.h>
#include <libc.h>
#include "stream.h"
extern Streamops ivfops, mcops, audops;
static struct {
char *name;
Streamops *o;
}ops[] = {
{"ivf", &ivfops},
{"mc", &mcops},
{"audio", &audops},
};
Stream *
Sopen(char *filename, int *num)
{
int i, failed;
Stream *s;
char *f;
*num = 0;
for(i = 0; i < nelem(ops); i++){
failed = 0;
if((s = ops[i].o->open(filename, num, &failed)) != nil){
f = utfrrune(filename, '/');
if(f == nil)
f = filename;
else
f++;
snprint(s->info, sizeof(s->info), "%s [%s]", ops[i].name, f);
s->t₀ = Zt₀;
return s;
}
if(failed){
werrstr("%s: %r", ops[i].name);
return nil;
}
}
werrstr("unknown format");
return nil;
}
void
Sclose(Stream *s)
{
if(s == nil || s->type < 0)
return;
s->ops.close(s);
s->type = -1;
if(s->freeaux != nil)
s->freeaux(s->aux);
}
int
Sread(Stream *s, Streamframe *f)
{
int res;
if(s == nil || s->type < 0){
werrstr("invalid stream");
return -1;
}
if((res = s->ops.read(s, f)) == 0){
if(s->t₀ == Zt₀)
s->t₀ = f->timestamp;
/*
* timestamps going backwards means clock wasn't monotonically
* increasing. perhaps nanosec() or nsec() is to blame.
* just work around it in any case, instead of hanging without
* displaying any frames.
*/
if(f->timestamp > s->t₀)
f->timestamp -= s->t₀;
else
f->timestamp = 0;
}
return res;
}