QTfrontend/net/recorder.cpp
changeset 7280 fd707afbc3a2
parent 7235 baa69bd025d9
child 7376 48b79b3ca592
equal deleted inserted replaced
7278:000e4543f204 7280:fd707afbc3a2
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17  */
    17  */
    18 
    18 
    19 #include <QString>
    19 #include <QString>
    20 #include <QByteArray>
    20 #include <QByteArray>
       
    21 //#include <QMessageBox>
    21 
    22 
    22 #include "recorder.h"
    23 #include "recorder.h"
    23 #include "gameuiconfig.h"
    24 #include "gameuiconfig.h"
    24 #include "hwconsts.h"
    25 #include "hwconsts.h"
    25 #include "game.h"
    26 #include "game.h"
       
    27 #include "libav_iteraction.h"
    26 
    28 
    27 HWRecorder::HWRecorder(GameUIConfig * config) :
    29 HWRecorder::HWRecorder(GameUIConfig * config, const QString &prefix) :
    28     TCPBase(false)
    30     TCPBase(false)
    29 {
    31 {
    30     this->config = config;
    32     this->config = config;
       
    33     this->prefix = prefix;
       
    34     finished = false;
       
    35     name = prefix + "." + LibavIteraction::instance().getExtension(config->AVFormat());
    31 }
    36 }
    32 
    37 
    33 HWRecorder::~HWRecorder()
    38 HWRecorder::~HWRecorder()
    34 {
    39 {
       
    40     emit encodingFinished(finished);
    35 }
    41 }
    36 
    42 
    37 void HWRecorder::onClientDisconnect()
    43 void HWRecorder::onClientDisconnect()
    38 {
    44 {
    39 }
    45 }
    45     while (!readbuffer.isEmpty() && ((bufsize = readbuffer.size()) > 0) &&
    51     while (!readbuffer.isEmpty() && ((bufsize = readbuffer.size()) > 0) &&
    46             ((msglen = readbuffer.data()[0]) < bufsize))
    52             ((msglen = readbuffer.data()[0]) < bufsize))
    47     {
    53     {
    48         QByteArray msg = readbuffer.left(msglen + 1);
    54         QByteArray msg = readbuffer.left(msglen + 1);
    49         readbuffer.remove(0, msglen + 1);
    55         readbuffer.remove(0, msglen + 1);
    50         if (msg.at(1) == '?')
    56         switch (msg.at(1))
       
    57         {
       
    58         case '?':
    51             SendIPC("!");
    59             SendIPC("!");
       
    60             break;
       
    61         case 'p':
       
    62             emit onProgress(float(++curFrame)/numFrames);
       
    63             break;
       
    64         case 'v':
       
    65             finished = true;
       
    66             break;
       
    67         }
    52     }
    68     }
    53 }
    69 }
    54 
    70 
    55 void HWRecorder::EncodeVideo( const QByteArray & record, const QString & prefix )
    71 void HWRecorder::EncodeVideo(const QByteArray & record, int numFrames)
    56 {
    72 {
    57     this->prefix = prefix;
    73     this->numFrames = numFrames;
       
    74     curFrame = 0;
    58 
    75 
    59     toSendBuf = record;
    76     toSendBuf = record;
    60     toSendBuf.replace(QByteArray("\x02TD"), QByteArray("\x02TV"));
    77     toSendBuf.replace(QByteArray("\x02TD"), QByteArray("\x02TV"));
    61     toSendBuf.replace(QByteArray("\x02TL"), QByteArray("\x02TV"));
    78     toSendBuf.replace(QByteArray("\x02TL"), QByteArray("\x02TV"));
    62     toSendBuf.replace(QByteArray("\x02TN"), QByteArray("\x02TV"));
    79     toSendBuf.replace(QByteArray("\x02TN"), QByteArray("\x02TV"));
    71     QStringList arguments;
    88     QStringList arguments;
    72     QRect resolution = config->rec_Resolution();
    89     QRect resolution = config->rec_Resolution();
    73     arguments << cfgdir->absolutePath();
    90     arguments << cfgdir->absolutePath();
    74     arguments << QString::number(resolution.width());
    91     arguments << QString::number(resolution.width());
    75     arguments << QString::number(resolution.height());
    92     arguments << QString::number(resolution.height());
    76     arguments << QString::number(config->bitDepth()); // bpp
    93     arguments << "32"; // bpp
    77     arguments << QString("%1").arg(ipc_port);
    94     arguments << QString("%1").arg(ipc_port);
    78     arguments << "0"; // fullscreen
    95     arguments << "0"; // fullscreen
    79     arguments << "0"; // sound
    96     arguments << "0"; // sound
    80     arguments << "0"; // music
    97     arguments << "0"; // music
    81     arguments << "0"; // sound volume
    98     arguments << "0"; // sound volume
    92     arguments << prefix;
   109     arguments << prefix;
    93     arguments << config->AVFormat();
   110     arguments << config->AVFormat();
    94     arguments << config->videoCodec();
   111     arguments << config->videoCodec();
    95     arguments << "5"; // video quality
   112     arguments << "5"; // video quality
    96     arguments << "medium";
   113     arguments << "medium";
    97     if (config->recordAudio())
   114     arguments << (config->recordAudio()? config->audioCodec() : "no");
    98         arguments << config->audioCodec();
       
    99     else
       
   100         arguments << "no";
       
   101     arguments << "5"; // audio quality
   115     arguments << "5"; // audio quality
   102 
   116 
   103     return arguments;
   117     return arguments;
   104 }
   118 }