Krita Source Code Documentation
Loading...
Searching...
No Matches
RecorderWriterManager::Private Class Reference

Public Member Functions

bool clearWriterPool ()
 
void enlargeWriterPool ()
 
int findLastIndex (const QString &directory)
 
 Private (RecorderWriterManager *q_ptr, ThreadCounter &rt)
 
void searchForFreeWriter ()
 

Public Attributes

QPointer< KisCanvas2canvas
 
QMutex captureMutex
 
volatile std::atomic_bool enabled = false
 
std::atomic_int freeWriterId = -1
 
volatile std::atomic_bool imageModified = false
 
int interval = 1
 
volatile std::atomic_bool isActivateBlackTool = false
 
volatile std::atomic_bool isForceBlackTool = false
 
QDir outputDir
 
int partIndex = 0
 
RecorderWriterManager *const q
 
ThreadCounterrecorderThreads
 
RecorderWriterSettings settings {}
 
QTimer timer
 
volatile std::atomic_bool toolActivated = false
 
WriterPool writerPool
 

Detailed Description

Definition at line 381 of file recorder_writer.cpp.

Constructor & Destructor Documentation

◆ Private()

RecorderWriterManager::Private::Private ( RecorderWriterManager * q_ptr,
ThreadCounter & rt )
inline

Definition at line 384 of file recorder_writer.cpp.

385 : q(q_ptr)
386 , recorderThreads(rt)
387 {}
RecorderWriterManager *const q

Member Function Documentation

◆ clearWriterPool()

bool RecorderWriterManager::Private::clearWriterPool ( )
inline

Definition at line 432 of file recorder_writer.cpp.

433 {
434 bool result = true;
435 bool alreadyWarn = false;
436 bool alreadyErr = false;
437 for(auto& el: writerPool)
438 {
439 el.thread->quit();
440 el.thread->wait(RecorderConst::waitThreadTimeoutMs);
441 disconnect(q, SIGNAL(startCapturing(int)), el.writer.get(), SLOT(onCaptureImage(int)));
442 disconnect(el.writer.get(), SIGNAL(capturingDone(int, int)), q, SLOT(onCapturingDone(int, int)));
443 if (el.thread->isRunning())
444 {
445 if (!alreadyWarn) {
446 warnResources << "One of the Recorder WriterPool threads has been blocked and has to be terminated. "
447 << "Thread Name: " << el.thread->objectName();
448 alreadyWarn = true;
449 }
450 el.thread->terminate();
451 if (!el.thread->wait(RecorderConst::waitThreadTimeoutMs))
452 {
453 if (!alreadyErr) {
454 errResources << "Something odd has been happen. Krita was unable to stop one of the Recorder WriterPool Threads. "
455 << "Thread Name: " << el.thread->objectName();
456 alreadyErr = true;
457 }
458 result = false;
459 }
460 }
461 }
462
463 writerPool.clear();
464 freeWriterId = -1;
465
466 if (!result)
467 Q_EMIT q->recorderStopWarning();
468
469 return result;
470 }
void startCapturing(int writerId)
void onCapturingDone(int workerId, int status)
#define errResources
Definition kis_debug.h:109
#define warnResources
Definition kis_debug.h:89
constexpr int waitThreadTimeoutMs

References errResources, freeWriterId, RecorderWriterManager::onCapturingDone(), q, RecorderWriterManager::recorderStopWarning(), RecorderWriterManager::startCapturing(), RecorderConst::waitThreadTimeoutMs, warnResources, and writerPool.

◆ enlargeWriterPool()

void RecorderWriterManager::Private::enlargeWriterPool ( )
inline

Definition at line 472 of file recorder_writer.cpp.

473 {
474 writerPool.reserve(recorderThreads.get());
475 while (static_cast<int>(recorderThreads.get()) > writerPool.size()) {
476 auto newWorkerId = writerPool.size();
477 freeWriterId = newWorkerId - 1; // Set the value to the last existing writerEl index ->
478 // The next call of searchForFreeWriter() will than automatically find newWorkerId
479
480 writerPool.append(WriterPoolEl(q, newWorkerId, canvas, settings, outputDir));
481
482 auto writerPtr = writerPool[newWorkerId].writer;
483 auto threadPtr = writerPool[newWorkerId].thread;
484 threadPtr->setObjectName(QString("Krita-Recorder-WriterPool#%1").arg(newWorkerId));
485 connect(q, SIGNAL(startCapturing(int)), writerPtr.get(), SLOT(onCaptureImage(int)));
486 connect(writerPtr.get(), SIGNAL(capturingDone(int, int)), q, SLOT(onCapturingDone(int, int)));
487 writerPtr->moveToThread(threadPtr.get());
488 threadPtr->start(QThread::IdlePriority);
489 }
490 }
RecorderWriterSettings settings
unsigned int get() const

References canvas, freeWriterId, ThreadCounter::get(), RecorderWriterManager::onCapturingDone(), outputDir, q, recorderThreads, settings, RecorderWriterManager::startCapturing(), and writerPool.

◆ findLastIndex()

int RecorderWriterManager::Private::findLastIndex ( const QString & directory)
inline

Definition at line 406 of file recorder_writer.cpp.

407 {
408 QElapsedTimer dbgTimer;
409 dbgTimer.start();
410
411 QDirIterator dirIterator(directory);
413 const QRegularExpression &snapshotFilePattern = RecorderConst::snapshotFilePatternFor(extension);
414
415 int recordIndex = -1;
416 while (dirIterator.hasNext()) {
417 dirIterator.next();
418
419 const QString &fileName = dirIterator.fileName();
420 const QRegularExpressionMatch &match = snapshotFilePattern.match(fileName);
421 if (match.hasMatch()) {
422 int index = match.captured(1).toInt();
423 if (recordIndex < index)
424 recordIndex = index;
425 }
426 }
427 dbgTools << "findLastPartNumber for" << directory << ": " << dbgTimer.elapsed() << "ms";
428
429 return recordIndex;
430 }
#define dbgTools
Definition kis_debug.h:51
QRegularExpression snapshotFilePatternFor(const QString &extension)
QLatin1String fileExtension(RecorderFormat format)

References dbgTools, RecorderFormatInfo::fileExtension(), RecorderWriterSettings::format, settings, and RecorderConst::snapshotFilePatternFor().

◆ searchForFreeWriter()

void RecorderWriterManager::Private::searchForFreeWriter ( )
inline

Definition at line 492 of file recorder_writer.cpp.

493 {
494 auto j = freeWriterId + 1;
495 for(auto i = 0; i < writerPool.size(); i++, j++)
496 {
497 freeWriterId = j % writerPool.size();
498 if (writerPool[freeWriterId].thread->isRunning() && !writerPool[freeWriterId].inUse)
499 return;
500 }
501 freeWriterId = -1;
502 }

References freeWriterId, and writerPool.

Member Data Documentation

◆ canvas

QPointer<KisCanvas2> RecorderWriterManager::Private::canvas

Definition at line 399 of file recorder_writer.cpp.

◆ captureMutex

QMutex RecorderWriterManager::Private::captureMutex

Definition at line 404 of file recorder_writer.cpp.

◆ enabled

volatile std::atomic_bool RecorderWriterManager::Private::enabled = false

Definition at line 391 of file recorder_writer.cpp.

◆ freeWriterId

std::atomic_int RecorderWriterManager::Private::freeWriterId = -1

Definition at line 397 of file recorder_writer.cpp.

◆ imageModified

volatile std::atomic_bool RecorderWriterManager::Private::imageModified = false

Definition at line 392 of file recorder_writer.cpp.

◆ interval

int RecorderWriterManager::Private::interval = 1

Definition at line 398 of file recorder_writer.cpp.

◆ isActivateBlackTool

volatile std::atomic_bool RecorderWriterManager::Private::isActivateBlackTool = false

Definition at line 394 of file recorder_writer.cpp.

◆ isForceBlackTool

volatile std::atomic_bool RecorderWriterManager::Private::isForceBlackTool = false

Definition at line 393 of file recorder_writer.cpp.

◆ outputDir

QDir RecorderWriterManager::Private::outputDir

Definition at line 403 of file recorder_writer.cpp.

◆ partIndex

int RecorderWriterManager::Private::partIndex = 0

Definition at line 396 of file recorder_writer.cpp.

◆ q

RecorderWriterManager* const RecorderWriterManager::Private::q

Definition at line 389 of file recorder_writer.cpp.

◆ recorderThreads

ThreadCounter& RecorderWriterManager::Private::recorderThreads

Definition at line 390 of file recorder_writer.cpp.

◆ settings

RecorderWriterSettings RecorderWriterManager::Private::settings {}

Definition at line 402 of file recorder_writer.cpp.

402{};

◆ timer

QTimer RecorderWriterManager::Private::timer

Definition at line 400 of file recorder_writer.cpp.

◆ toolActivated

volatile std::atomic_bool RecorderWriterManager::Private::toolActivated = false

Definition at line 395 of file recorder_writer.cpp.

◆ writerPool

WriterPool RecorderWriterManager::Private::writerPool

Definition at line 401 of file recorder_writer.cpp.


The documentation for this class was generated from the following file: