QTfrontend/net/recorder.cpp
branchui-scaling
changeset 15304 c4fd2813b127
parent 13389 24b531dcebe7
parent 14650 8ffa0c27f434
equal deleted inserted replaced
13390:0135e64c6c66 15304:c4fd2813b127
    21 
    21 
    22 #include "recorder.h"
    22 #include "recorder.h"
    23 #include "gameuiconfig.h"
    23 #include "gameuiconfig.h"
    24 #include "hwconsts.h"
    24 #include "hwconsts.h"
    25 #include "game.h"
    25 #include "game.h"
       
    26 #include "util/MessageDialog.h"
    26 #include "LibavInteraction.h"
    27 #include "LibavInteraction.h"
    27 
    28 
    28 // Encoding is memory expensive process, so we need to limit maximum number
    29 // Encoding is memory expensive process, so we need to limit maximum number
    29 // of simultaneous encoders.
    30 // of simultaneous encoders.
    30 static const int maxRecorders = 3;
    31 static const int maxRecorders = 3;
    31 static int numRecorders = 0;
    32 static int numRecorders = 0;
    32 
    33 
    33 static QList<HWRecorder*> queue;
    34 static QList<HWRecorder*> queue;
    34 
    35 
    35 HWRecorder::HWRecorder(GameUIConfig * config, const QString &prefix) :
    36 HWRecorder::HWRecorder(GameUIConfig * config, const QString &prefix) :
    36     TCPBase(false)
    37     TCPBase(false, !config->language().isEmpty())
    37 {
    38 {
    38     this->config = config;
    39     this->config = config;
    39     this->prefix = prefix;
    40     this->prefix = prefix;
    40     item = 0;
    41     item = 0;
    41     finished = false;
    42     finished = false;
       
    43     aborted = false;
    42     name = prefix + "." + LibavInteraction::instance().getExtension(config->AVFormat());
    44     name = prefix + "." + LibavInteraction::instance().getExtension(config->AVFormat());
    43 }
    45 }
    44 
    46 
    45 HWRecorder::~HWRecorder()
    47 HWRecorder::~HWRecorder()
    46 {
    48 {
    73             emit onProgress((quint8(msg.at(2))*256.0 + quint8(msg.at(3)))*0.0001);
    75             emit onProgress((quint8(msg.at(2))*256.0 + quint8(msg.at(3)))*0.0001);
    74             break;
    76             break;
    75         case 'v':
    77         case 'v':
    76             finished = true;
    78             finished = true;
    77             break;
    79             break;
       
    80         case 'E':
       
    81             int size = msg.size();
       
    82             emit ErrorMessage(
       
    83                 tr("A fatal ERROR occured while processing the video recording! "
       
    84                 "The video could not be saved.\n\n"
       
    85                 "As a workaround, you could try to reset the Hedgewars video recorder settings to the defaults.\n\n"
       
    86                 "To report this error, please click the 'Feedback' button in the main menu!\n\n"
       
    87                 "Last engine message:\n%1")
       
    88                 .arg(QString::fromUtf8(msg.mid(2).left(size - 4))));
       
    89             return;
    78         }
    90         }
    79     }
    91     }
    80 }
    92 }
    81 
    93 
    82 void HWRecorder::EncodeVideo(const QByteArray & record)
    94 void HWRecorder::EncodeVideo(const QByteArray & record)
   138     arguments << config->AVFormat();
   150     arguments << config->AVFormat();
   139     arguments << config->videoCodec();
   151     arguments << config->videoCodec();
   140 // Could use a field to use quality instead. maybe quality could override bitrate - or just pass (and set) both.
   152 // Could use a field to use quality instead. maybe quality could override bitrate - or just pass (and set) both.
   141 // The library does support using both at once after all.
   153 // The library does support using both at once after all.
   142     arguments << QString::number(config->rec_Bitrate()*1024);
   154     arguments << QString::number(config->rec_Bitrate()*1024);
   143     arguments << (config->recordAudio() ? config->audioCodec() : "no");
   155     if (config->recordAudio() && (config->isSoundEnabled() || config->isMusicEnabled()))
       
   156         arguments << config->audioCodec();
       
   157     else
       
   158         arguments << "no";
   144     arguments << "--chat-size";
   159     arguments << "--chat-size";
   145     arguments << QString::number(config->chatSize());
   160     arguments << QString::number(config->chatSize());
   146 
   161 
   147     return arguments;
   162     return arguments;
   148 }
   163 }
   149 
   164 
   150 bool HWRecorder::simultaneousRun()
   165 bool HWRecorder::simultaneousRun()
   151 {
   166 {
   152     return true;
   167     return true;
   153 }
   168 }
       
   169 
       
   170 void HWRecorder::abort()
       
   171 {
       
   172     queue.removeOne(this);
       
   173     aborted = true;
       
   174     deleteLater();
       
   175 }