shithub: treason

ref: 65f3155b4376c0d2368ca32b3e20b578825bc601
dir: treason/stream.c

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

struct Stream {
	Streamops ops;
};

extern Streamops ivfops;

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

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

	for(i = 0; i < nelem(ops); i++){
		failed = 0;
		if((s = ops[i].o->open(filename, info, &failed)) != nil){
			memmove(&s->ops, ops[i].o, sizeof(Streamops));
			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);
}