OSDN Git Service

Implemented experimental dark mode, based on QDarkStyleSheet.
[x264-launcher/x264-launcher.git] / src / thread_encode.cpp
index 82c439f..31964d6 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // Simple x264 Launcher
-// Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2020 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@
 #include "model_options.h"
 #include "model_preferences.h"
 #include "model_sysinfo.h"
+#include "model_clipInfo.h"
 #include "job_object.h"
 #include "mediainfo.h"
 
@@ -85,13 +86,13 @@ private:
                log("\nPROCESS ABORTED BY USER !!!"); \
                setStatus(JobStatus_Aborted); \
                if(QFileInfo(m_outputFileName).exists() && (QFileInfo(m_outputFileName).size() == 0)) QFile::remove(m_outputFileName); \
-               return; \
+               return 0; \
        } \
        else if(!(OK_FLAG)) \
        { \
                setStatus(JobStatus_Failed); \
                if(QFileInfo(m_outputFileName).exists() && (QFileInfo(m_outputFileName).size() == 0)) QFile::remove(m_outputFileName); \
-               return; \
+               return 0; \
        } \
 } \
 while(0)
@@ -167,18 +168,16 @@ EncodeThread::~EncodeThread(void)
 
 void EncodeThread::run(void)
 {
-#if !defined(_DEBUG)
-       __try
-       {
-               checkedRun();
-       }
-       __except(1)
+       m_progress = 0;
+       m_status = JobStatus_Starting;
+
+       AbstractThread::run();
+
+       if (m_exception)
        {
-               qWarning("STRUCTURED EXCEPTION ERROR IN ENCODE THREAD !!!");
+               log(tr("UNHANDLED EXCEPTION ERROR IN THREAD !!!"));
+               setStatus(JobStatus_Failed);
        }
-#else
-       checkedRun();
-#endif
 
        if(m_jobObject)
        {
@@ -187,40 +186,6 @@ void EncodeThread::run(void)
        }
 }
 
-void EncodeThread::checkedRun(void)
-{
-       m_progress = 0;
-       m_status = JobStatus_Starting;
-
-       try
-       {
-               try
-               {
-                       ExecutionStateHandler executionStateHandler;
-                       encode();
-               }
-               catch(const std::exception &e)
-               {
-                       log(tr("EXCEPTION ERROR IN THREAD: ").append(QString::fromLatin1(e.what())));
-                       setStatus(JobStatus_Failed);
-               }
-               catch(char *msg)
-               {
-                       log(tr("EXCEPTION ERROR IN THREAD: ").append(QString::fromLatin1(msg)));
-                       setStatus(JobStatus_Failed);
-               }
-               catch(...)
-               {
-                       log(tr("UNHANDLED EXCEPTION ERROR IN THREAD !!!"));
-                       setStatus(JobStatus_Failed);
-               }
-       }
-       catch(...)
-       {
-               MUtils::OS::fatal_exit(L"Unhandeled exception error in encode thread!");
-       }
-}
-
 void EncodeThread::start(Priority priority)
 {
        qDebug("Thread starting...");
@@ -229,14 +194,14 @@ void EncodeThread::start(Priority priority)
        m_pause = false;
 
        while(m_semaphorePaused.tryAcquire(1, 0));
-       QThread::start(priority);
+       AbstractThread::start(priority);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 // Encode functions
 ///////////////////////////////////////////////////////////////////////////////
 
-void EncodeThread::encode(void)
+int EncodeThread::threadMain(void)
 {
        QDateTime startTime = QDateTime::currentDateTime();
 
@@ -260,14 +225,14 @@ void EncodeThread::encode(void)
        log(tr("\n--- SETTINGS ---\n"));
        log(tr("Encoder : %1").arg(m_encoder->getName()));
        log(tr("Source  : %1").arg(m_pipedSource ? m_pipedSource->getName() : tr("Native")));
-       log(tr("RC Mode : %1").arg(OptionsModel::rcMode2String(m_options->rcMode())));
+       log(tr("RC Mode : %1").arg(m_encoder->getEncoderInfo().rcModeToString(m_options->rcMode())));
        log(tr("Preset  : %1").arg(m_options->preset()));
        log(tr("Tuning  : %1").arg(m_options->tune()));
        log(tr("Profile : %1").arg(m_options->profile()));
        log(tr("Custom  : %1").arg(m_options->customEncParams().isEmpty() ? tr("<None>") : m_options->customEncParams()));
        
        bool ok = false;
-       unsigned int frames = 0;
+       ClipInfo clipInfo;
        
        // -----------------------------------------------------------------------------------
        // Check Versions
@@ -317,7 +282,7 @@ void EncodeThread::encode(void)
        if(m_pipedSource)
        {
                log(tr("\n--- GET SOURCE INFO ---\n"));
-               ok = m_pipedSource->checkSourceProperties(frames);
+               ok = m_pipedSource->checkSourceProperties(clipInfo);
                CHECK_STATUS(m_abort, ok);
        }
 
@@ -326,22 +291,22 @@ void EncodeThread::encode(void)
        // -----------------------------------------------------------------------------------
 
        //Run encoding passes
-       if(m_options->rcMode() == OptionsModel::RCMode_2Pass)
+       if(m_encoder->getEncoderInfo().rcModeToType(m_options->rcMode()) == AbstractEncoderInfo::RC_TYPE_MULTIPASS)
        {
                const QString passLogFile = getPasslogFile(m_outputFileName);
                
                log(tr("\n--- ENCODING PASS #1 ---\n"));
-               ok = m_encoder->runEncodingPass(m_pipedSource, m_outputFileName, frames, 1, passLogFile);
+               ok = m_encoder->runEncodingPass(m_pipedSource, m_outputFileName, clipInfo, 1, passLogFile);
                CHECK_STATUS(m_abort, ok);
 
                log(tr("\n--- ENCODING PASS #2 ---\n"));
-               ok = m_encoder->runEncodingPass(m_pipedSource, m_outputFileName, frames, 2, passLogFile);
+               ok = m_encoder->runEncodingPass(m_pipedSource, m_outputFileName, clipInfo, 2, passLogFile);
                CHECK_STATUS(m_abort, ok);
        }
        else
        {
                log(tr("\n--- ENCODING VIDEO ---\n"));
-               ok = m_encoder->runEncodingPass(m_pipedSource, m_outputFileName, frames);
+               ok = m_encoder->runEncodingPass(m_pipedSource, m_outputFileName, clipInfo);
                CHECK_STATUS(m_abort, ok);
        }
 
@@ -354,6 +319,8 @@ void EncodeThread::encode(void)
        int timePassed = startTime.secsTo(QDateTime::currentDateTime());
        log(tr("Job finished at %1, %2. Process took %3 minutes, %4 seconds.").arg(QDate::currentDate().toString(Qt::ISODate), QTime::currentTime().toString(Qt::ISODate), QString::number(timePassed / 60), QString::number(timePassed % 60)));
        setStatus(JobStatus_Completed);
+
+       return 1; /*completed*/
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -362,7 +329,7 @@ void EncodeThread::encode(void)
 
 void EncodeThread::log(const QString &text)
 {
-       emit messageLogged(m_jobId, text);
+       emit messageLogged(m_jobId, QDateTime::currentMSecsSinceEpoch(), text);
 }
 
 void EncodeThread::setStatus(const JobStatus &newStatus)