author | unc0rr |
Thu, 22 Nov 2012 01:19:16 +0400 | |
branch | flibqtfrontend |
changeset 8092 | 08960209db8c |
parent 8069 | bb7671829935 |
child 8363 | 0b4ac686fc44 |
permissions | -rw-r--r-- |
7180 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
|
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 |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
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) : |
7180 | 36 |
TCPBase(false) |
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; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
40 |
finished = false; |
7897 | 41 |
name = prefix + "." + LibavInteraction::instance().getExtension(config->AVFormat()); |
7180 | 42 |
} |
43 |
||
44 |
HWRecorder::~HWRecorder() |
|
45 |
{ |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
46 |
emit encodingFinished(finished); |
7507 | 47 |
if (queue.empty()) |
48 |
numRecorders--; |
|
49 |
else |
|
8092 | 50 |
queue.takeFirst()->start(false); |
7180 | 51 |
} |
52 |
||
53 |
void HWRecorder::onClientDisconnect() |
|
54 |
{ |
|
55 |
} |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
56 |
|
8092 | 57 |
void HWRecorder::onEngineStart() |
58 |
{ |
|
59 |
||
60 |
} |
|
61 |
||
7180 | 62 |
void HWRecorder::onClientRead() |
63 |
{ |
|
8092 | 64 |
/* quint8 msglen; |
7180 | 65 |
quint32 bufsize; |
66 |
while (!readbuffer.isEmpty() && ((bufsize = readbuffer.size()) > 0) && |
|
67 |
((msglen = readbuffer.data()[0]) < bufsize)) |
|
68 |
{ |
|
69 |
QByteArray msg = readbuffer.left(msglen + 1); |
|
70 |
readbuffer.remove(0, msglen + 1); |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
71 |
switch (msg.at(1)) |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
72 |
{ |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
73 |
case '?': |
7180 | 74 |
SendIPC("!"); |
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 '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
|
77 |
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
|
78 |
break; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
79 |
case 'v': |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
80 |
finished = true; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
81 |
break; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
82 |
} |
8092 | 83 |
}*/ |
7180 | 84 |
} |
85 |
||
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
|
86 |
void HWRecorder::EncodeVideo(const QByteArray & record) |
7180 | 87 |
{ |
8092 | 88 |
/*toSendBuf = record; |
7180 | 89 |
toSendBuf.replace(QByteArray("\x02TD"), QByteArray("\x02TV")); |
90 |
toSendBuf.replace(QByteArray("\x02TL"), QByteArray("\x02TV")); |
|
91 |
toSendBuf.replace(QByteArray("\x02TN"), QByteArray("\x02TV")); |
|
92 |
toSendBuf.replace(QByteArray("\x02TS"), QByteArray("\x02TV")); |
|
93 |
||
7507 | 94 |
if (numRecorders < maxRecorders) |
95 |
{ |
|
96 |
numRecorders++; |
|
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7897
diff
changeset
|
97 |
Start(false); // run engine |
7507 | 98 |
} |
99 |
else |
|
8092 | 100 |
queue.push_back(this);*/ |
7180 | 101 |
} |
102 |
||
103 |
QStringList HWRecorder::getArguments() |
|
104 |
{ |
|
105 |
QStringList arguments; |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
106 |
QRect resolution = config->rec_Resolution(); |
7180 | 107 |
arguments << cfgdir->absolutePath(); |
108 |
arguments << QString::number(resolution.width()); |
|
109 |
arguments << QString::number(resolution.height()); |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
110 |
arguments << "32"; // bpp |
8092 | 111 |
//arguments << QString("%1").arg(ipc_port); |
7180 | 112 |
arguments << "0"; // fullscreen |
113 |
arguments << "0"; // sound |
|
114 |
arguments << "0"; // music |
|
115 |
arguments << "0"; // sound volume |
|
116 |
arguments << QString::number(config->timerInterval()); |
|
117 |
arguments << datadir->absolutePath(); |
|
7868 | 118 |
arguments << "0"; // fps |
7180 | 119 |
arguments << (config->isAltDamageEnabled() ? "1" : "0"); |
120 |
arguments << config->netNick().toUtf8().toBase64(); |
|
121 |
arguments << QString::number(config->translateQuality()); |
|
122 |
arguments << QString::number(config->stereoMode()); |
|
123 |
arguments << HWGame::tr("en.txt"); |
|
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
|
124 |
arguments << QString::number(config->rec_Framerate()); // framerate numerator |
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
|
125 |
arguments << "1"; // framerate denominator |
7180 | 126 |
arguments << prefix; |
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
127 |
arguments << config->AVFormat(); |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
128 |
arguments << config->videoCodec(); |
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
|
129 |
// Could use a field to use quality instead. maybe quality could override bitrate - or just pass (and set) both. |
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
|
130 |
// 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
|
131 |
arguments << QString::number(config->rec_Bitrate()*1024); |
7868 | 132 |
arguments << (config->recordAudio() ? config->audioCodec() : "no"); |
7180 | 133 |
|
134 |
return arguments; |
|
135 |
} |