QTfrontend/net/recorder.cpp
author Stepan777 <stepik-777@mail.ru>
Fri, 08 Jun 2012 02:52:35 +0400
changeset 7198 5debd5fe526e
parent 7180 53ffc8853008
child 7235 baa69bd025d9
permissions -rw-r--r--
1. Add IFDEFs for video recording 2. Options for video recording were hardcoded in engine, now they are hardcoded in frontend and passed to engine thru command line (later it will be possible to change them in frontend)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     1
/*
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     4
 *
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     8
 *
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    12
 * GNU General Public License for more details.
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    13
 *
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    17
 */
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    18
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    19
#include <QString>
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    20
#include <QByteArray>
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    21
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    22
#include "recorder.h"
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    23
#include "gameuiconfig.h"
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    24
#include "hwconsts.h"
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    25
#include "game.h"
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    26
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    27
HWRecorder::HWRecorder(GameUIConfig * config) :
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    28
    TCPBase(false)
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    29
{
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    30
    this->config = config;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    31
}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    32
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    33
HWRecorder::~HWRecorder()
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    34
{
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    35
}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    36
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    37
void HWRecorder::onClientDisconnect()
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    38
{
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    39
}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    40
     
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    41
void HWRecorder::onClientRead()
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    42
{
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    43
    quint8 msglen;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    44
    quint32 bufsize;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    45
    while (!readbuffer.isEmpty() && ((bufsize = readbuffer.size()) > 0) &&
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    46
            ((msglen = readbuffer.data()[0]) < bufsize))
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    47
    {
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    48
        QByteArray msg = readbuffer.left(msglen + 1);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    49
        readbuffer.remove(0, msglen + 1);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    50
        if (msg.at(1) == '?')
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    51
            SendIPC("!");
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    52
    }
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    53
}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    54
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    55
void HWRecorder::EncodeVideo( const QByteArray & record, const QString & prefix )
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    56
{
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    57
    this->prefix = prefix;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    58
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    59
    toSendBuf = record;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    60
    toSendBuf.replace(QByteArray("\x02TD"), QByteArray("\x02TV"));
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    61
    toSendBuf.replace(QByteArray("\x02TL"), QByteArray("\x02TV"));
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    62
    toSendBuf.replace(QByteArray("\x02TN"), QByteArray("\x02TV"));
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    63
    toSendBuf.replace(QByteArray("\x02TS"), QByteArray("\x02TV"));
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    64
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    65
    // run engine
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    66
    Start();
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    67
}
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    68
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    69
QStringList HWRecorder::getArguments()
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    70
{
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    71
    QStringList arguments;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    72
    QRect resolution = config->vid_Resolution();
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    73
    arguments << cfgdir->absolutePath();
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    74
    arguments << QString::number(resolution.width());
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    75
    arguments << QString::number(resolution.height());
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    76
    arguments << QString::number(config->bitDepth()); // bpp
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    77
    arguments << QString("%1").arg(ipc_port);
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    78
    arguments << "0"; // fullscreen
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    79
    arguments << "0"; // sound
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    80
    arguments << "0"; // music
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    81
    arguments << "0"; // sound volume
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    82
    arguments << QString::number(config->timerInterval());
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    83
    arguments << datadir->absolutePath();
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    84
    arguments << (config->isShowFPSEnabled() ? "1" : "0");
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    85
    arguments << (config->isAltDamageEnabled() ? "1" : "0");
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    86
    arguments << config->netNick().toUtf8().toBase64();
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    87
    arguments << QString::number(config->translateQuality());
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    88
    arguments << QString::number(config->stereoMode());
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    89
    arguments << HWGame::tr("en.txt");
7198
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    90
    arguments << "30"; // framerate num
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    91
    arguments << "1";  // framerate den
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    92
    arguments << prefix;
7198
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    93
    arguments << "mp4";
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    94
    arguments << "mpeg4"; // arguments << "libx264";
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    95
    arguments << "5"; // video quality
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    96
    arguments << "medium";
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    97
    arguments << "libmp3lame";
5debd5fe526e 1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents: 7180
diff changeset
    98
    arguments << "5"; // audio quality
7180
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
    99
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   100
    return arguments;
53ffc8853008 here it is
Stepan777 <stepik-777@mail.ru>
parents:
diff changeset
   101
}