shithub: treason

ref: 19cbe98daef0d058a0387f03cc36e44f9169e04b
dir: /stream.c/

View raw version
#include <u.h>
#include <libc.h>
#include "stream.h"

extern Streamops ivfops;
extern Streamops mcops;

static struct {
	char *name;
	Streamops *o;
}ops[] = {
	{"mc", &mcops},
	{"ivf", &ivfops},
};

Stream *
Sopen(char *filename, int *num)
{
	int i, failed;
	Stream *s;

	*num = 0;
	for(i = 0; i < nelem(ops); i++){
		failed = 0;
		if((s = ops[i].o->open(filename, num, &failed)) != nil)
			return s;
		if(failed){
			werrstr("%s: %r", ops[i].name);
			return nil;
		}
	}

	werrstr("unknown format");

	return nil;
}

void
Sclose(Stream *s)
{
	s->ops.close(s);
}

int
Sread(Stream *s, Streamframe *f)
{
	return s->ops.read(s, f);
}

vlong
Soffset(Stream *s)
{
	return s->ops.offset(s);
}