~ft/treason

ref: c1156352ba4eceae2ec875fd06fc94c38c92271f treason/stream.h -rw-r--r-- 1.5 KiB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
typedef struct Stream Stream;
typedef struct Streamhdr Streamhdr;
typedef struct Streamframe Streamframe;
typedef struct Streaminfo Streaminfo;
typedef struct Streamops Streamops;
#pragma incomplete Stream

enum {
	Svideo,
	Saudio,
	Ssubtitles,

	/* video */
	FmtAV1 = 0,
	FmtH264,
	FmtVP8,
	FmtVP9,
	/* audio */
	FmtAAC,
	FmtMp3,
	FmtOpus,
	FmtVorbis,
	FmtFlac,
	/* subtitles */
	FmtSrt,

	Numfmt,
};

struct Streamframe {
	uvlong timestamp;
	uvlong dt;
	union {
		struct { /* video/audio */
			u8int *buf;
			int sz;
		};
		struct { /* subtitles */
			char *lines[16];
			int nlines;
		};
	};
};

struct Streamops {
	Stream *(*open)(char *path, int *num, int *failed);
	u8int *(*alloc)(void *aux, int sz);
	void (*close)(Stream *s);
	int (*read)(Stream *s, Streamframe *f);

	void *aux;
};

struct Streaminfo {
	int type;
	int fmt;

	struct {
		uvlong denum, num;
	}timebase;

	union {
		struct {
			int w, h;
		}video;

		struct {
			int nchan;
			int srate;
		}audio;
	};

	char info[128];
};

#define Zt₀ (~0ULL)

struct Stream {
	Streaminfo;
	Streamops ops;

	/* private stuff */
	uvlong timestamp;
	uvlong t₀;
	void *b;
	u8int *buf;
	int bufsz;
	void *aux;
	void (*freeaux)(void *);
};

Stream *Sopen(char *filename, int *num);
void Sclose(Stream *s);
int Sread(Stream *s, Streamframe *f);

int ivfopenb(void *bio, Stream *s, int *failed);
int audopenfd(int fd, Stream *s, int *failed);
int subopenfd(int fd, Stream *s, int *failed);

Stream *subopen(char *path, int *num, int *failed);