forked from erak/glmixer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenderingEncoder.h
165 lines (130 loc) · 3.8 KB
/
RenderingEncoder.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
/*
* RenderingEncoder.h
*
* Created on: Mar 13, 2011
* Author: bh
*
* This file is part of GLMixer.
*
* GLMixer is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GLMixer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GLMixer. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2009, 2012 Bruno Herbelin
*
*/
#ifndef RENDERINGENCODER_H_
#define RENDERINGENCODER_H_
#include <QObject>
#include <QTime>
#include <QString>
/**
* Minimum and Maximum size of the recording buffer
* Expressed in bytes
*/
// 100 MB
#define MIN_RECORDING_BUFFER_SIZE 104857600
// 4 GB
#define MAX_RECORDING_BUFFER_SIZE 4294967296
// 5% of range, approx 200 MB
#define DEFAULT_RECORDING_BUFFER_SIZE 209505485
extern "C" {
#include "video_rec.h"
}
#include "RenderingManager.h"
class EncodingThread: public QThread {
Q_OBJECT
public:
EncodingThread();
~EncodingThread();
void initialize(video_rec_t *recorder, int bufferCount);
void clear();
void stop();
void pictq_push(int timestamp);
unsigned char *pictq_top();
bool pictq_full();
signals:
void encodingFinished();
protected:
// the update function
void run();
// ref to the recorder
video_rec_t *rec;
// execution management
bool _quit;
QMutex *pictq_mutex;
QWaitCondition *pictq_cond;
// picture queue management
unsigned char** pictq;
int pictq_max_count, pictq_size_count, pictq_rindex, pictq_windex;
int *recordingTimeStamp;
};
class RenderingEncoder: public QObject {
Q_OBJECT
friend class EncodingThread;
public:
RenderingEncoder(QObject * parent = 0);
~RenderingEncoder();
void addFrame(unsigned char *data = 0);
// preferences encoding
void setEncodingFormat(encodingformat f);
encodingformat encodingFormat() { return format; }
void setUpdatePeriod(uint ms) { update=ms; }
uint updatePeriod() { return update; }
void setFrameSize(QSize s) { if (!started) framesSize = s; }
// preferences saving mode
void setAutomaticSavingMode(bool on);
bool automaticSavingMode() { return automaticSaving;}
void setAutomaticSavingFolder(QDir d);
QDir automaticSavingFolder() { return savingFolder; }
// status
bool isActive() { return started; }
int getRecodingTime();
bool isRecording() { return started && !paused ; }
// utility
static unsigned long computeBufferSize(int percent);
static int computeBufferPercent(unsigned long bytes);
public slots:
void setActive(bool on);
void setPaused(bool on);
void saveFile(QString suffix, QString filename = QString::null);
void saveFileAs(QString suffix, QString description);
void close();
void setBufferSize(unsigned long bytes);
unsigned long getBufferSize();
signals:
void activated(bool);
void processing(bool);
void status(const QString &, int);
void selectAspectRatio(const standardAspectRatio );
protected:
void timerEvent(QTimerEvent *event);
bool start();
private:
// files location
QString temporaryFileName;
QDir savingFolder, temporaryFolder;
bool automaticSaving;
// state machine
bool started, paused;
QTime timer;
int elapseTimer, skipframecount;
// encoder
QSize framesSize;
EncodingThread *encoder;
uint update, displayupdate;
encodingformat format;
video_rec_t *recorder;
char errormessage[256];
unsigned long bufferSize;
};
#endif /* RENDERINGENCODER_H_ */