/
NuppelVideoRecorder.h
278 lines (211 loc) · 6.12 KB
/
NuppelVideoRecorder.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#ifndef NUPPELVIDEORECORDER
#define NUPPELVIDEORECORDER
#include <qstring.h>
#include <qmap.h>
#include <vector>
#include <sys/time.h>
#include <time.h>
#include <pthread.h>
#ifdef MMX
#undef MMX
#define MMXBLAH
#endif
#include <lame/lame.h>
#ifdef MMXBLAH
#define MMX
#endif
#include "recorderbase.h"
#include "commercial_skip.h"
#include "minilzo.h"
#include "format.h"
extern "C" {
#include "../libavcodec/avcodec.h"
#include "filter.h"
}
using namespace std;
struct video_audio;
struct VBIData;
struct cc;
class RTjpeg;
class RingBuffer;
class ChannelBase;
class FilterManager;
class FilterChain;
class NuppelVideoRecorder : public RecorderBase
{
public:
NuppelVideoRecorder(ChannelBase *channel);
~NuppelVideoRecorder();
void SetOption(const QString &name, int value);
void SetOption(const QString &name, const QString &value)
{ RecorderBase::SetOption(name, value); }
void SetOptionsFromProfile(RecordingProfile *profile,
const QString &videodev,
const QString &audiodev,
const QString &vbidev, int ispip);
void Initialize(void);
void StartRecording(void);
void StopRecording(void);
void Pause(bool clear = true);
void Unpause(void);
bool GetPause(void);
void WaitForPause(void);
bool IsRecording(void);
bool IsErrored(void);
long long GetFramesWritten(void);
bool Open(void);
int GetVideoFd(void);
void Reset(void);
void SetVideoFilters(QString &filters);
long long GetKeyframePosition(long long desired);
void GetBlankFrameMap(QMap<long long, int> &blank_frame_map);
// reencode stuff
void StreamAllocate(void);
void WriteHeader(void);
void WriteSeekTable(void);
void WriteKeyFrameAdjustTable(QPtrList<struct kfatable_entry> *kfa_table);
void UpdateSeekTable(int frame_num, bool update_db, long offset = 0);
bool SetupAVCodec(void);
void SetupRTjpeg(void);
int AudioInit(bool skipdevice = false);
void WriteVideo(VideoFrame *frame, bool skipsync = false,
bool forcekey = false);
void WriteAudio(unsigned char *buf, int fnum, int timecode);
void WriteText(unsigned char *buf, int len, int timecode, int pagenr);
protected:
static void *WriteThread(void *param);
static void *AudioThread(void *param);
static void *VbiThread(void *param);
void doWriteThread(void);
void doAudioThread(void);
void doVbiThread(void);
private:
inline void NuppelVideoRecorder::WriteFrameheader(rtframeheader *fh);
void InitBuffers(void);
void InitFilters(void);
void ResizeVideoBuffers(void);
int MJPEGInit(void);
int SpawnChildren(void);
void KillChildren(void);
void BufferIt(unsigned char *buf, int len = -1);
int CreateNuppelFile(void);
void DoV4L2(void);
void DoMJPEG(void);
void FormatTeletextSubtitles(struct VBIData *vbidata);
void FormatCC(struct cc *cc);
void FormatCCField(struct cc *cc, int tc, int field);
QChar CharCC(int code);
void ResetCC(struct cc *cc, int mode);
void BufferCC(struct cc *cc, int mode, int len, int clr);
int NewRowCC(struct cc *cc, int mode, int len);
bool encoding;
int fd; // v4l input file handle
signed char *strm;
long dropped;
unsigned int lf, tf;
int M1, M2, Q;
int w, h;
int pip_mode;
int pid, pid2;
int inputchannel;
int compression;
int compressaudio;
unsigned long long audiobytes;
int audio_channels;
int audio_bits;
int audio_bytes_per_sample;
int audio_samplerate; // rate we request from sounddevice
int effectivedsp; // actual measured rate
int quiet;
int rawmode;
int usebttv;
CommDetect *commDetect;
int mp3quality;
char *mp3buf;
int mp3buf_size;
lame_global_flags *gf;
QMap<long long, int> blank_frames;
RTjpeg *rtjc;
#define OUT_LEN (1024*1024 + 1024*1024 / 64 + 16 + 3)
lzo_byte out[OUT_LEN];
#define HEAP_ALLOC(var,size) \
long __LZO_MMODEL var [ ((size) + (sizeof(long) - 1)) / sizeof(long) ]
HEAP_ALLOC(wrkmem, LZO1X_1_MEM_COMPRESS);
vector<struct vidbuffertype *> videobuffer;
vector<struct audbuffertype *> audiobuffer;
vector<struct txtbuffertype *> textbuffer;
int act_video_encode;
int act_video_buffer;
int act_audio_encode;
int act_audio_buffer;
long long act_audio_sample;
int act_text_encode;
int act_text_buffer;
int video_buffer_count;
int audio_buffer_count;
int text_buffer_count;
long video_buffer_size;
long audio_buffer_size;
long text_buffer_size;
struct timeval stm;
struct timezone tzone;
bool childrenLive;
pthread_t write_tid;
pthread_t audio_tid;
pthread_t vbi_tid;
bool recording;
bool errored;
int keyframedist;
vector<struct seektable_entry> *seektable;
QMap<long long, long long> positionMap;
QMap<long long, long long> positionMapDelta;
long long extendeddataOffset;
long long framesWritten;
bool livetv;
bool paused;
bool pausewritethread;
bool actuallypaused;
bool audiopaused;
bool mainpaused;
double framerate_multiplier;
double height_multiplier;
int last_block;
int firsttc;
long int oldtc;
int startnum;
int frameofgop;
int lasttimecode;
int audio_behind;
bool useavcodec;
AVCodec *mpa_codec;
AVCodecContext *mpa_ctx;
AVFrame mpa_picture;
int targetbitrate;
int scalebitrate;
int maxquality;
int minquality;
int qualdiff;
int mp4opts;
int mb_decision;
QString videoFilterList;
FilterChain *videoFilters;
FilterManager *FiltMan;
VideoFrameType inpixfmt;
PixelFormat picture_format;
int w_out;
int h_out;
bool hardware_encode;
int hmjpg_quality;
int hmjpg_hdecimation;
int hmjpg_vdecimation;
int hmjpg_maxw;
bool cleartimeonpause;
bool usingv4l2;
int channelfd;
long long prev_bframe_save_pos;
ChannelBase *channelObj;
bool skip_btaudio;
bool correct_bttv;
int volume;
};
#endif