~ft/treason

ref: c1156352ba4eceae2ec875fd06fc94c38c92271f treason/decoder.c -rw-r--r-- 1015 bytes
c1156352 — Sigrid Solveig Haflínudóttir info: mixed up dispdelay and yuv→rgb, fix it 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <u.h>
#include <libc.h>
#include <thread.h>
#include "stream.h"
#include "decoder.h"
#include "frame.h"

extern Decoderops av1ops, h264ops, vpxops;

static struct {
	char *name;
	Decoderops *o;
	int fmt;
}ops[] = {
	{"AV1", &av1ops, FmtAV1},
	{"H264", &h264ops, FmtH264},
	{"VP8", &vpxops, FmtVP8},
	{"VP9", &vpxops, FmtVP9},
};

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*), 8);
	d->finished = chancreate(sizeof(void*), 0);

	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;
			snprint(d->info, sizeof(d->info), "%s", ops[i].name);
			break;
		}
	}

	assert(i < nelem(ops));

	return d;
err:
	return nil;
}

void
Dclose(Decoder *d)
{
	d->ops->close(d);
	chanclose(d->frames);
	recvp(d->finished);
	free(d);
}