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

Public Member Functions

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

Public Attributes

QPointer< KisCanvas2canvas
 
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 362 of file recorder_writer.cpp.

Constructor & Destructor Documentation

◆ Private()

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

Definition at line 365 of file recorder_writer.cpp.

366 : q(q_ptr)
367 , recorderThreads(rt)
368 {}
RecorderWriterManager *const q

Member Function Documentation

◆ canStartCapture()

bool RecorderWriterManager::Private::canStartCapture ( )
inline

Definition at line 484 of file recorder_writer.cpp.

485 {
487 return false;
489 return false;
490 return true;
491 }
volatile std::atomic_bool toolActivated
volatile std::atomic_bool isActivateBlackTool
volatile std::atomic_bool isForceBlackTool

References isActivateBlackTool, isForceBlackTool, and toolActivated.

◆ clearWriterPool()

bool RecorderWriterManager::Private::clearWriterPool ( )
inline

Definition at line 412 of file recorder_writer.cpp.

413 {
414 bool result = true;
415 bool alreadyWarn = false;
416 bool alreadyErr = false;
417 for(auto& el: writerPool)
418 {
419 el.thread->quit();
420 el.thread->wait(RecorderConst::waitThreadTimeoutMs);
421 disconnect(q, SIGNAL(startCapturing(int, int)), el.writer.get(), SLOT(onCaptureImage(int, int)));
422 disconnect(el.writer.get(), SIGNAL(capturingDone(int, bool)), q, SLOT(onCapturingDone(int, bool)));
423 if (el.thread->isRunning())
424 {
425 if (!alreadyWarn) {
426 warnResources << "One of the Recorder WriterPool threads has been blocked and has to be terminated. "
427 << "Thread Name: " << el.thread->objectName();
428 alreadyWarn = true;
429 }
430 el.thread->terminate();
431 if (!el.thread->wait(RecorderConst::waitThreadTimeoutMs))
432 {
433 if (!alreadyErr) {
434 errResources << "Something odd has been happen. Krita was unable to stop one of the Recorder WriterPool Threads. "
435 << "Thread Name: " << el.thread->objectName();
436 alreadyErr = true;
437 }
438 result = false;
439 }
440 }
441 }
442
443 writerPool.clear();
444 freeWriterId = -1;
445
446 if (!result)
447 Q_EMIT q->recorderStopWarning();
448
449 return result;
450 }
void onCapturingDone(int workerId, bool success)
void startCapturing(int writerId, int index)
#define errResources
Definition kis_debug.h:105
#define warnResources
Definition kis_debug.h:85
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 452 of file recorder_writer.cpp.

453 {
454 writerPool.reserve(recorderThreads.get());
455 while (static_cast<int>(recorderThreads.get()) > writerPool.size()) {
456 auto newWorkerId = writerPool.size();
457 freeWriterId = newWorkerId - 1; // Set the value to the last existing writerEl index ->
458 // The next call of searchForFreeWriter() will than automatically find newWorkerId
459
460 writerPool.append(WriterPoolEl(q, newWorkerId, canvas, settings, outputDir));
461
462 auto writerPtr = writerPool[newWorkerId].writer;
463 auto threadPtr = writerPool[newWorkerId].thread;
464 threadPtr->setObjectName(QString("Krita-Recorder-WriterPool#%1").arg(newWorkerId));
465 connect(q, SIGNAL(startCapturing(int, int)), writerPtr.get(), SLOT(onCaptureImage(int, int)));
466 connect(writerPtr.get(), SIGNAL(capturingDone(int, bool)), q, SLOT(onCapturingDone(int, bool)));
467 writerPtr->moveToThread(threadPtr.get());
468 threadPtr->start(QThread::IdlePriority);
469 }
470 }
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
RecorderWriterSettings settings
unsigned int get() const

References canvas, connect(), 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 386 of file recorder_writer.cpp.

387 {
388 QElapsedTimer dbgTimer;
389 dbgTimer.start();
390
391 QDirIterator dirIterator(directory);
393 const QRegularExpression &snapshotFilePattern = RecorderConst::snapshotFilePatternFor(extension);
394
395 int recordIndex = -1;
396 while (dirIterator.hasNext()) {
397 dirIterator.next();
398
399 const QString &fileName = dirIterator.fileName();
400 const QRegularExpressionMatch &match = snapshotFilePattern.match(fileName);
401 if (match.hasMatch()) {
402 int index = match.captured(1).toInt();
403 if (recordIndex < index)
404 recordIndex = index;
405 }
406 }
407 dbgTools << "findLastPartNumber for" << directory << ": " << dbgTimer.elapsed() << "ms";
408
409 return recordIndex;
410 }
#define dbgTools
Definition kis_debug.h:48
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 472 of file recorder_writer.cpp.

473 {
474 auto j = freeWriterId + 1;
475 for(auto i = 0; i < writerPool.size(); i++, j++)
476 {
477 freeWriterId = j % writerPool.size();
478 if (writerPool[freeWriterId].thread->isRunning() && !writerPool[freeWriterId].inUse)
479 return;
480 }
481 freeWriterId = -1;
482 }

References freeWriterId, and writerPool.

Member Data Documentation

◆ canvas

QPointer<KisCanvas2> RecorderWriterManager::Private::canvas

Definition at line 380 of file recorder_writer.cpp.

◆ enabled

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

Definition at line 372 of file recorder_writer.cpp.

◆ freeWriterId

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

Definition at line 378 of file recorder_writer.cpp.

◆ imageModified

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

Definition at line 373 of file recorder_writer.cpp.

◆ interval

int RecorderWriterManager::Private::interval = 1

Definition at line 379 of file recorder_writer.cpp.

◆ isActivateBlackTool

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

Definition at line 375 of file recorder_writer.cpp.

◆ isForceBlackTool

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

Definition at line 374 of file recorder_writer.cpp.

◆ outputDir

QDir RecorderWriterManager::Private::outputDir

Definition at line 384 of file recorder_writer.cpp.

◆ partIndex

int RecorderWriterManager::Private::partIndex = 0

Definition at line 377 of file recorder_writer.cpp.

◆ q

RecorderWriterManager* const RecorderWriterManager::Private::q

Definition at line 370 of file recorder_writer.cpp.

◆ recorderThreads

ThreadCounter& RecorderWriterManager::Private::recorderThreads

Definition at line 371 of file recorder_writer.cpp.

◆ settings

RecorderWriterSettings RecorderWriterManager::Private::settings {}

Definition at line 383 of file recorder_writer.cpp.

383{};

◆ timer

QTimer RecorderWriterManager::Private::timer

Definition at line 381 of file recorder_writer.cpp.

◆ toolActivated

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

Definition at line 376 of file recorder_writer.cpp.

◆ writerPool

WriterPool RecorderWriterManager::Private::writerPool

Definition at line 382 of file recorder_writer.cpp.


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