X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fthread_encode.cpp;h=af7127a0a750f6557a4f7b2f8c69e235eb655b9b;hb=413c93a4586c8366bcf2c94180f4cd746fe49644;hp=cee4bd0efd011c9880c4b36739d6b3115de37292;hpb=cc3d25dfce52494f4371c9d0098ec8f2c0610282;p=x264-launcher%2Fx264-launcher.git diff --git a/src/thread_encode.cpp b/src/thread_encode.cpp index cee4bd0..af7127a 100644 --- a/src/thread_encode.cpp +++ b/src/thread_encode.cpp @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// // Simple x264 Launcher -// Copyright (C) 2004-2014 LoRd_MuldeR +// Copyright (C) 2004-2021 LoRd_MuldeR // // 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,16 +26,19 @@ #include "model_options.h" #include "model_preferences.h" #include "model_sysinfo.h" +#include "model_clipInfo.h" #include "job_object.h" -#include "binaries.h" #include "mediainfo.h" //Encoders #include "encoder_factory.h" //Source -#include "source_avisynth.h" -#include "source_vapoursynth.h" +#include "source_factory.h" + +//MUtils +#include +#include //Qt Framework #include @@ -83,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) @@ -133,15 +136,15 @@ EncodeThread::EncodeThread(const QString &sourceFileName, const QString &outputF switch(MediaInfo::analyze(m_sourceFileName)) { case MediaInfo::FILETYPE_AVISYNTH: - if(m_sysinfo->hasAVSSupport()) + if(m_sysinfo->hasAvisynth()) { - m_pipedSource = new AvisynthSource (m_jobObject, m_options, m_sysinfo, m_preferences, m_status, &m_abort, &m_pause, &m_semaphorePaused, m_sourceFileName); + m_pipedSource = SourceFactory::createSource(SourceFactory::SourceType_AVS, m_jobObject, m_options, m_sysinfo, m_preferences, m_status, &m_abort, &m_pause, &m_semaphorePaused, m_sourceFileName); } break; case MediaInfo::FILETYPE_VAPOURSYNTH: - if(m_sysinfo->hasVPSSupport()) + if(m_sysinfo->hasVapourSynth()) { - m_pipedSource = new VapoursynthSource(m_jobObject, m_options, m_sysinfo, m_preferences, m_status, &m_abort, &m_pause, &m_semaphorePaused, m_sourceFileName); + m_pipedSource = SourceFactory::createSource(SourceFactory::SourceType_VPS, m_jobObject, m_options, m_sysinfo, m_preferences, m_status, &m_abort, &m_pause, &m_semaphorePaused, m_sourceFileName); } break; } @@ -153,9 +156,10 @@ EncodeThread::EncodeThread(const QString &sourceFileName, const QString &outputF EncodeThread::~EncodeThread(void) { - X264_DELETE(m_encoder); - X264_DELETE(m_jobObject); - X264_DELETE(m_options); + MUTILS_DELETE(m_encoder); + MUTILS_DELETE(m_jobObject); + MUTILS_DELETE(m_options); + MUTILS_DELETE(m_pipedSource); } /////////////////////////////////////////////////////////////////////////////// @@ -164,57 +168,21 @@ EncodeThread::~EncodeThread(void) void EncodeThread::run(void) { -#if !defined(_DEBUG) - __try - { - checkedRun(); - } - __except(1) - { - qWarning("STRUCTURED EXCEPTION ERROR IN ENCODE THREAD !!!"); - } -#else - checkedRun(); -#endif - - if(m_jobObject) - { - m_jobObject->terminateJob(42); - X264_DELETE(m_jobObject); - } -} - -void EncodeThread::checkedRun(void) -{ m_progress = 0; m_status = JobStatus_Starting; - try + AbstractThread::run(); + + if (m_exception) { - 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); - } + log(tr("UNHANDLED EXCEPTION ERROR IN THREAD !!!")); + setStatus(JobStatus_Failed); } - catch(...) + + if(m_jobObject) { - x264_fatal_exit(L"Unhandeled exception error in encode thread!"); + m_jobObject->terminateJob(42); + MUTILS_DELETE(m_jobObject); } } @@ -226,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(); @@ -242,7 +210,7 @@ void EncodeThread::encode(void) // ----------------------------------------------------------------------------------- //Print some basic info - log(tr("Simple x264 Launcher (Build #%1), built %2\n").arg(QString::number(x264_version_build()), x264_version_date().toString(Qt::ISODate))); + log(tr("Simple x264 Launcher (Build #%1), built %2\n").arg(QString::number(x264_version_build()), MUtils::Version::app_build_date().toString(Qt::ISODate))); log(tr("Job started at %1, %2.\n").arg(QDate::currentDate().toString(Qt::ISODate), QTime::currentTime().toString( Qt::ISODate))); log(tr("Source file : %1").arg(QDir::toNativeSeparators(m_sourceFileName))); log(tr("Output file : %1").arg(QDir::toNativeSeparators(m_outputFileName))); @@ -250,21 +218,21 @@ void EncodeThread::encode(void) //Print system info log(tr("\n--- SYSTEMINFO ---\n")); log(tr("Binary Path : %1").arg(QDir::toNativeSeparators(m_sysinfo->getAppPath()))); - log(tr("Avisynth : %1").arg(m_sysinfo->hasAVSSupport() ? tr("Yes") : tr("No"))); - log(tr("VapourSynth : %1").arg(m_sysinfo->hasVPSSupport() ? QDir::toNativeSeparators(m_sysinfo->getVPSPath()) : tr("N/A"))); + log(tr("Avisynth : %1").arg(m_sysinfo->hasAvisynth() ? tr("Yes") : tr("No"))); + log(tr("VapourSynth : %1").arg(m_sysinfo->hasVapourSynth() ? tr("Yes") : tr("No"))); //Print encoder settings 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())); + log(tr("Custom : %1").arg(m_options->customEncParams().isEmpty() ? tr("") : m_options->customEncParams())); bool ok = false; - unsigned int frames = 0; + ClipInfo clipInfo; // ----------------------------------------------------------------------------------- // Check Versions @@ -314,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); } @@ -323,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); } @@ -351,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*/ } /////////////////////////////////////////////////////////////////////////////// @@ -359,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)