author | Stepan777 <stepik-777@mail.ru> |
Sun, 24 Jun 2012 20:57:02 +0400 | |
changeset 7280 | fd707afbc3a2 |
parent 7235 | baa69bd025d9 |
child 7376 | 48b79b3ca592 |
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> |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
21 |
//#include <QMessageBox> |
7180 | 22 |
|
23 |
#include "recorder.h" |
|
24 |
#include "gameuiconfig.h" |
|
25 |
#include "hwconsts.h" |
|
26 |
#include "game.h" |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
27 |
#include "libav_iteraction.h" |
7180 | 28 |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
29 |
HWRecorder::HWRecorder(GameUIConfig * config, const QString &prefix) : |
7180 | 30 |
TCPBase(false) |
31 |
{ |
|
32 |
this->config = config; |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
33 |
this->prefix = prefix; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
34 |
finished = false; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
35 |
name = prefix + "." + LibavIteraction::instance().getExtension(config->AVFormat()); |
7180 | 36 |
} |
37 |
||
38 |
HWRecorder::~HWRecorder() |
|
39 |
{ |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
40 |
emit encodingFinished(finished); |
7180 | 41 |
} |
42 |
||
43 |
void HWRecorder::onClientDisconnect() |
|
44 |
{ |
|
45 |
} |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
46 |
|
7180 | 47 |
void HWRecorder::onClientRead() |
48 |
{ |
|
49 |
quint8 msglen; |
|
50 |
quint32 bufsize; |
|
51 |
while (!readbuffer.isEmpty() && ((bufsize = readbuffer.size()) > 0) && |
|
52 |
((msglen = readbuffer.data()[0]) < bufsize)) |
|
53 |
{ |
|
54 |
QByteArray msg = readbuffer.left(msglen + 1); |
|
55 |
readbuffer.remove(0, msglen + 1); |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
56 |
switch (msg.at(1)) |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
57 |
{ |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
58 |
case '?': |
7180 | 59 |
SendIPC("!"); |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
60 |
break; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
61 |
case 'p': |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
62 |
emit onProgress(float(++curFrame)/numFrames); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
63 |
break; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
64 |
case 'v': |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
65 |
finished = true; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
66 |
break; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
67 |
} |
7180 | 68 |
} |
69 |
} |
|
70 |
||
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
71 |
void HWRecorder::EncodeVideo(const QByteArray & record, int numFrames) |
7180 | 72 |
{ |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
73 |
this->numFrames = numFrames; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
74 |
curFrame = 0; |
7180 | 75 |
|
76 |
toSendBuf = record; |
|
77 |
toSendBuf.replace(QByteArray("\x02TD"), QByteArray("\x02TV")); |
|
78 |
toSendBuf.replace(QByteArray("\x02TL"), QByteArray("\x02TV")); |
|
79 |
toSendBuf.replace(QByteArray("\x02TN"), QByteArray("\x02TV")); |
|
80 |
toSendBuf.replace(QByteArray("\x02TS"), QByteArray("\x02TV")); |
|
81 |
||
82 |
// run engine |
|
83 |
Start(); |
|
84 |
} |
|
85 |
||
86 |
QStringList HWRecorder::getArguments() |
|
87 |
{ |
|
88 |
QStringList arguments; |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
89 |
QRect resolution = config->rec_Resolution(); |
7180 | 90 |
arguments << cfgdir->absolutePath(); |
91 |
arguments << QString::number(resolution.width()); |
|
92 |
arguments << QString::number(resolution.height()); |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
93 |
arguments << "32"; // bpp |
7180 | 94 |
arguments << QString("%1").arg(ipc_port); |
95 |
arguments << "0"; // fullscreen |
|
96 |
arguments << "0"; // sound |
|
97 |
arguments << "0"; // music |
|
98 |
arguments << "0"; // sound volume |
|
99 |
arguments << QString::number(config->timerInterval()); |
|
100 |
arguments << datadir->absolutePath(); |
|
101 |
arguments << (config->isShowFPSEnabled() ? "1" : "0"); |
|
102 |
arguments << (config->isAltDamageEnabled() ? "1" : "0"); |
|
103 |
arguments << config->netNick().toUtf8().toBase64(); |
|
104 |
arguments << QString::number(config->translateQuality()); |
|
105 |
arguments << QString::number(config->stereoMode()); |
|
106 |
arguments << HWGame::tr("en.txt"); |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
107 |
arguments << QString::number(config->rec_Framerate()); // framerate num |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
108 |
arguments << "1"; // framerate den |
7180 | 109 |
arguments << prefix; |
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
110 |
arguments << config->AVFormat(); |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
111 |
arguments << config->videoCodec(); |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
112 |
arguments << "5"; // video quality |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
113 |
arguments << "medium"; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
114 |
arguments << (config->recordAudio()? config->audioCodec() : "no"); |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
115 |
arguments << "5"; // audio quality |
7180 | 116 |
|
117 |
return arguments; |
|
118 |
} |