author | Wuzzy <Wuzzy2@mail.ru> |
Wed, 16 Jan 2019 00:37:26 +0100 | |
changeset 14604 | b86e6e4f3c58 |
parent 13649 | 1b536e268519 |
child 14634 | 8ffa0c27f434 |
permissions | -rw-r--r-- |
7180 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
7180 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
9998
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
7180 | 17 |
*/ |
18 |
||
19 |
#include <QString> |
|
20 |
#include <QByteArray> |
|
21 |
||
22 |
#include "recorder.h" |
|
23 |
#include "gameuiconfig.h" |
|
24 |
#include "hwconsts.h" |
|
25 |
#include "game.h" |
|
7897 | 26 |
#include "LibavInteraction.h" |
7180 | 27 |
|
7507 | 28 |
// Encoding is memory expensive process, so we need to limit maximum number |
29 |
// of simultaneous encoders. |
|
30 |
static const int maxRecorders = 3; |
|
31 |
static int numRecorders = 0; |
|
32 |
||
33 |
static QList<HWRecorder*> queue; |
|
34 |
||
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
35 |
HWRecorder::HWRecorder(GameUIConfig * config, const QString &prefix) : |
14604
b86e6e4f3c58
Make game engine load the user's locale correctly (bug 688)
Wuzzy <Wuzzy2@mail.ru>
parents:
13649
diff
changeset
|
36 |
TCPBase(false, !config->language().isEmpty()) |
7180 | 37 |
{ |
38 |
this->config = config; |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
39 |
this->prefix = prefix; |
10248 | 40 |
item = 0; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
41 |
finished = false; |
13649
1b536e268519
Fix frontend crash when rapidly aborting many active video encodings. Fixes bug 595
Wuzzy <Wuzzy2@mail.ru>
parents:
13497
diff
changeset
|
42 |
aborted = false; |
7897 | 43 |
name = prefix + "." + LibavInteraction::instance().getExtension(config->AVFormat()); |
7180 | 44 |
} |
45 |
||
46 |
HWRecorder::~HWRecorder() |
|
47 |
{ |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
48 |
emit encodingFinished(finished); |
7507 | 49 |
if (queue.empty()) |
50 |
numRecorders--; |
|
51 |
else |
|
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7897
diff
changeset
|
52 |
queue.takeFirst()->Start(false); |
7180 | 53 |
} |
54 |
||
55 |
void HWRecorder::onClientDisconnect() |
|
56 |
{ |
|
57 |
} |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
58 |
|
7180 | 59 |
void HWRecorder::onClientRead() |
60 |
{ |
|
61 |
quint8 msglen; |
|
62 |
quint32 bufsize; |
|
63 |
while (!readbuffer.isEmpty() && ((bufsize = readbuffer.size()) > 0) && |
|
64 |
((msglen = readbuffer.data()[0]) < bufsize)) |
|
65 |
{ |
|
66 |
QByteArray msg = readbuffer.left(msglen + 1); |
|
67 |
readbuffer.remove(0, msglen + 1); |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
68 |
switch (msg.at(1)) |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
69 |
{ |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
70 |
case '?': |
7180 | 71 |
SendIPC("!"); |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
72 |
break; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
73 |
case 'p': |
7376
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7280
diff
changeset
|
74 |
emit onProgress((quint8(msg.at(2))*256.0 + quint8(msg.at(3)))*0.0001); |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
75 |
break; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
76 |
case 'v': |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
77 |
finished = true; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
78 |
break; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
79 |
} |
7180 | 80 |
} |
81 |
} |
|
82 |
||
7376
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7280
diff
changeset
|
83 |
void HWRecorder::EncodeVideo(const QByteArray & record) |
7180 | 84 |
{ |
85 |
toSendBuf = record; |
|
86 |
toSendBuf.replace(QByteArray("\x02TD"), QByteArray("\x02TV")); |
|
87 |
toSendBuf.replace(QByteArray("\x02TL"), QByteArray("\x02TV")); |
|
88 |
toSendBuf.replace(QByteArray("\x02TN"), QByteArray("\x02TV")); |
|
89 |
toSendBuf.replace(QByteArray("\x02TS"), QByteArray("\x02TV")); |
|
90 |
||
7507 | 91 |
if (numRecorders < maxRecorders) |
92 |
{ |
|
93 |
numRecorders++; |
|
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7897
diff
changeset
|
94 |
Start(false); // run engine |
7507 | 95 |
} |
96 |
else |
|
97 |
queue.push_back(this); |
|
7180 | 98 |
} |
99 |
||
100 |
QStringList HWRecorder::getArguments() |
|
101 |
{ |
|
102 |
QStringList arguments; |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
103 |
QRect resolution = config->rec_Resolution(); |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
104 |
QString nick = config->netNick().toUtf8().toBase64(); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
105 |
|
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
106 |
arguments << "--internal"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
107 |
arguments << "--port"; |
7180 | 108 |
arguments << QString("%1").arg(ipc_port); |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
109 |
arguments << "--prefix"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
110 |
arguments << datadir->absolutePath(); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
111 |
arguments << "--user-prefix"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
112 |
arguments << cfgdir->absolutePath(); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
113 |
arguments << "--locale"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
114 |
arguments << HWGame::tr("en.txt"); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
115 |
arguments << "--frame-interval"; |
7180 | 116 |
arguments << QString::number(config->timerInterval()); |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
117 |
arguments << "--width"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
118 |
arguments << QString::number(resolution.width()); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
119 |
arguments << "--height"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
120 |
arguments << QString::number(resolution.height()); |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
121 |
arguments << "--nosound"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
122 |
arguments << "--raw-quality"; |
7180 | 123 |
arguments << QString::number(config->translateQuality()); |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
124 |
arguments << "--stereo"; |
7180 | 125 |
arguments << QString::number(config->stereoMode()); |
8325
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
126 |
arguments << "--nomusic"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
127 |
arguments << "--volume"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
128 |
arguments << "0"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
129 |
if (config->isAltDamageEnabled()) |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
130 |
arguments << "--altdmg"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
131 |
if (!nick.isEmpty()) { |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
132 |
arguments << "--nick"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
133 |
arguments << nick; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
134 |
} |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
135 |
arguments << "--recorder"; |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
136 |
arguments << QString::number(config->rec_Framerate()); //cVideoFramerateNum |
ecd51650d5d8
GCI2012: Change Argument Passing Between Frontend and Engine
RowanD
parents:
8069
diff
changeset
|
137 |
arguments << "1"; //cVideoFramerateDen |
7180 | 138 |
arguments << prefix; |
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
139 |
arguments << config->AVFormat(); |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
140 |
arguments << config->videoCodec(); |
8434 | 141 |
// Could use a field to use quality instead. maybe quality could override bitrate - or just pass (and set) both. |
7633
d4251e519062
Allow adjusting bitrate so that I can get a somewhat usable webm video. The audio is still tinny and unlistenable. Configuration option for that might be helpful, or just adjusting defaults in the wrapper.
nemo
parents:
7507
diff
changeset
|
142 |
// The library does support using both at once after all. |
d4251e519062
Allow adjusting bitrate so that I can get a somewhat usable webm video. The audio is still tinny and unlistenable. Configuration option for that might be helpful, or just adjusting defaults in the wrapper.
nemo
parents:
7507
diff
changeset
|
143 |
arguments << QString::number(config->rec_Bitrate()*1024); |
13497
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
144 |
if (config->recordAudio() && (config->isSoundEnabled() || config->isMusicEnabled())) |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
145 |
arguments << config->audioCodec(); |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
146 |
else |
c7df0d96da81
Fix video recorder not working if sound disabled (fixes bug 200)
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
147 |
arguments << "no"; |
7180 | 148 |
|
149 |
return arguments; |
|
150 |
} |
|
9800
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9080
diff
changeset
|
151 |
|
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9080
diff
changeset
|
152 |
bool HWRecorder::simultaneousRun() |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9080
diff
changeset
|
153 |
{ |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9080
diff
changeset
|
154 |
return true; |
169fbb968bb3
No idea what this is doing, seems to allow recorder instance to not block further engine starts while it is doing its job.
unc0rr
parents:
9080
diff
changeset
|
155 |
} |
13649
1b536e268519
Fix frontend crash when rapidly aborting many active video encodings. Fixes bug 595
Wuzzy <Wuzzy2@mail.ru>
parents:
13497
diff
changeset
|
156 |
|
1b536e268519
Fix frontend crash when rapidly aborting many active video encodings. Fixes bug 595
Wuzzy <Wuzzy2@mail.ru>
parents:
13497
diff
changeset
|
157 |
void HWRecorder::abort() |
1b536e268519
Fix frontend crash when rapidly aborting many active video encodings. Fixes bug 595
Wuzzy <Wuzzy2@mail.ru>
parents:
13497
diff
changeset
|
158 |
{ |
1b536e268519
Fix frontend crash when rapidly aborting many active video encodings. Fixes bug 595
Wuzzy <Wuzzy2@mail.ru>
parents:
13497
diff
changeset
|
159 |
queue.removeOne(this); |
1b536e268519
Fix frontend crash when rapidly aborting many active video encodings. Fixes bug 595
Wuzzy <Wuzzy2@mail.ru>
parents:
13497
diff
changeset
|
160 |
aborted = true; |
1b536e268519
Fix frontend crash when rapidly aborting many active video encodings. Fixes bug 595
Wuzzy <Wuzzy2@mail.ru>
parents:
13497
diff
changeset
|
161 |
deleteLater(); |
1b536e268519
Fix frontend crash when rapidly aborting many active video encodings. Fixes bug 595
Wuzzy <Wuzzy2@mail.ru>
parents:
13497
diff
changeset
|
162 |
} |