-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdarmstadt.h
219 lines (190 loc) · 4.59 KB
/
darmstadt.h
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// ~> DARMSTADT <~ - low-overhead full-hardware screen capture.
// so many things have occurred since...
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <signal.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <dirent.h>
#include <pthread.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <drm.h>
#include <va/va_drm.h>
#include <va/va_drmcommon.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <stdexcept>
#include <string>
#include <deque>
#include <queue>
#include <mutex>
#ifdef HAVE_JACK
#include <jack/jack.h>
#endif
#include <pulse/error.h>
#include <pulse/simple.h>
#include "ta-log.h"
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/channel_layout.h>
#include <libavutil/hwcontext.h>
#include <libavutil/hwcontext_vaapi.h>
}
#define DEVICE_PATH "/dev/dri/card1"
#define DARM_VERSION "v4.0pre1"
#define DARM_RINGBUF_SIZE 134217728
#define S(x) std::string(x)
typedef std::string string;
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define CLAMP(x,xMin,xMax) (MIN(MAX((x),(xMin)),(xMax)))
bool operator ==(const struct timespec& l, const struct timespec& r);
bool operator >(const struct timespec& l, const struct timespec& r);
bool operator <(const struct timespec& l, const struct timespec& r);
struct timespec operator +(const struct timespec& l, const struct timespec& r);
struct timespec operator -(const struct timespec& l, const struct timespec& r);
struct timespec operator +(const struct timespec& l, const long& r);
struct timespec operator -(const struct timespec& l, const long& r);
struct timespec mkts(time_t sec, long nsec);
struct timespec stots(string s);
string tstos(struct timespec ts);
struct timespec curTime(clockid_t clockSource);
string strFormat(const char* format, ...);
enum SyncMethod {
syncVBlank=0,
syncTimer
};
enum ScaleMethod {
scaleFit=0,
scaleFill,
scaleOrig
};
enum EncodeSpeeds {
encPerformance=0,
encBalanced,
encQuality
};
enum AudioType {
audioTypeNone=0,
audioTypeJACK,
audioTypePulse,
audioTypeALSA
};
enum Vendor {
VendorIntel=0,
VendorAMD,
VendorNVIDIA, // ?!?!
VendorOther=255
};
struct Device {
string path, busID, name;
Vendor vendor;
};
struct Param {
string shortName;
string name;
string valName;
string desc;
bool value;
bool (*func)(string);
Param(string sn, string n, bool v, bool (*f)(string), string vn, string d): shortName(sn), name(n), valName(vn), desc(d), value(v), func(f) {}
};
struct Category {
string name;
string cmdName;
Category(string n, string c): name(n), cmdName(c) {}
};
struct AudioPacket {
struct timespec time;
// 1024 samples. up to 8 channels.
float data[8192];
};
class AudioEngine {
public:
bool wantBlank;
// read an audio packet. returns NULL if there aren't any.
virtual AudioPacket* read();
virtual int sampleRate();
virtual int channels();
virtual bool start();
virtual bool init(string devName);
virtual const char* engineName();
};
#ifdef HAVE_JACK
class JACKAudioEngine: public AudioEngine {
jack_client_t* ac;
jack_port_t* ai[8];
jack_status_t as;
int chan;
string name;
string devName;
int collPos;
AudioPacket ap;
std::queue<AudioPacket*> apqueue;
public:
AudioPacket* read();
int process(jack_nframes_t count);
int sampleRate();
int channels();
bool start();
bool init(string dn);
const char* engineName();
};
#endif
class PulseAudioEngine: public AudioEngine {
pa_simple* ac;
pa_sample_spec asf;
int as;
pthread_t tid;
AudioPacket ap;
string devName;
std::queue<AudioPacket*> apqueue;
public:
AudioPacket* read();
void* thr();
int sampleRate();
int channels();
bool start();
bool init(string dn);
const char* engineName();
};
enum CacheCommands {
cWrite=0,
cSeek,
cRead // ???
};
struct CacheCommand {
CacheCommands cmd;
unsigned char* buf;
ssize_t size;
int whence;
CacheCommand(CacheCommands c, unsigned char* b, int s, int w): cmd(c), buf(b), size(s), whence(w) {}
CacheCommand() {}
};
class WriteCache {
int o;
bool running, shallStop, busy;
pthread_t tid;
std::deque<CacheCommand> cqueue;
std::mutex m;
unsigned char* ringBuf;
ssize_t ringBufSize;
ssize_t ringBufPosR, ringBufPosW;
public:
void* run();
int write(unsigned char* buf, ssize_t len);
int seek(ssize_t pos, int whence);
ssize_t queueSize();
bool flush();
void setFile(int f);
bool enable(ssize_t ringSize);
bool disable();
WriteCache();
};
extern bool quit;