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< KisCanvas2 > canvas
 
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
 
ThreadCounter & recorderThreads
 
RecorderWriterSettings settings {}
 
QTimer timer
 
volatile std::atomic_bool toolActivated = false
 
WriterPool writerPool
 

Detailed Description

Definition at line 350 of file recorder_writer.cpp.

Constructor & Destructor Documentation

◆ Private()

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

Definition at line 353 of file recorder_writer.cpp.

354 : q(q_ptr)
355 , recorderThreads(rt)
356 {}
RecorderWriterManager *const q

Member Function Documentation

◆ canStartCapture()

bool RecorderWriterManager::Private::canStartCapture ( )
inline

Definition at line 487 of file recorder_writer.cpp.

488 {
490 return false;
492 return false;
493 return true;
494 }
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 400 of file recorder_writer.cpp.

401 {
402 bool result = true;
403 bool alreadyWarn = false;
404 bool alreadyErr = false;
405
406 for (auto &el : writerPool) {
407 if (el.inUse && !el.writer->isActive()) {
408 // There's a pending job, but the writer didn't recieve the signal yet
409
410 // Wait until all the jobs processes
411 canvas->image()->waitForDone();
412
413 // Make sure the signals are delivered
414 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
415
416 //we can exit the loop, all the signals have been delivered and we don't need to check further
417 break;
418 }
419 }
420
421 for (auto &el : writerPool) {
422 el.thread->quit();
423 el.thread->wait(RecorderConst::waitThreadTimeoutMs);
424 disconnect(q, SIGNAL(startCapturing(int, int, KisPaintDeviceSP)), el.writer.get(), SLOT(onCaptureImage(int, int, KisPaintDeviceSP)));
425 disconnect(el.writer.get(), SIGNAL(capturingDone(int, bool)), q, SLOT(onCapturingDone(int, bool)));
426 if (el.thread->isRunning())
427 {
428 if (!alreadyWarn) {
429 warnResources << "One of the Recorder WriterPool threads has been blocked and has to be terminated. "
430 << "Thread Name: " << el.thread->objectName();
431 alreadyWarn = true;
432 }
433 el.thread->terminate();
434 if (!el.thread->wait(RecorderConst::waitThreadTimeoutMs))
435 {
436 if (!alreadyErr) {
437 errResources << "Something odd has been happen. Krita was unable to stop one of the Recorder WriterPool Threads. "
438 << "Thread Name: " << el.thread->objectName();
439 alreadyErr = true;
440 }
441 result = false;
442 }
443 }
444 }
445
446 writerPool.clear();
447 freeWriterId = -1;
448
449 if (!result)
450 Q_EMIT q->recorderStopWarning();
451
452 return result;
453 }
void onCapturingDone(int workerId, bool success)
void startCapturing(int writerId, int index, KisPaintDeviceSP device)
#define errResources
Definition kis_debug.h:113
#define warnResources
Definition kis_debug.h:92
constexpr int waitThreadTimeoutMs

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

◆ enlargeWriterPool()

void RecorderWriterManager::Private::enlargeWriterPool ( )
inline

Definition at line 455 of file recorder_writer.cpp.

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

375 {
376 QElapsedTimer dbgTimer;
377 dbgTimer.start();
378
379 QDirIterator dirIterator(directory);
381 const QRegularExpression &snapshotFilePattern = RecorderConst::snapshotFilePatternFor(extension);
382
383 int recordIndex = -1;
384 while (dirIterator.hasNext()) {
385 dirIterator.next();
386
387 const QString &fileName = dirIterator.fileName();
388 const QRegularExpressionMatch &match = snapshotFilePattern.match(fileName);
389 if (match.hasMatch()) {
390 int index = match.captured(1).toInt();
391 if (recordIndex < index)
392 recordIndex = index;
393 }
394 }
395 dbgTools << "findLastPartNumber for" << directory << ": " << dbgTimer.elapsed() << "ms";
396
397 return recordIndex;
398 }
#define dbgTools
Definition kis_debug.h:52
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 475 of file recorder_writer.cpp.

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

References freeWriterId, and writerPool.

Member Data Documentation

◆ canvas

QPointer<KisCanvas2> RecorderWriterManager::Private::canvas

Definition at line 368 of file recorder_writer.cpp.

◆ enabled

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

Definition at line 360 of file recorder_writer.cpp.

◆ freeWriterId

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

Definition at line 366 of file recorder_writer.cpp.

◆ imageModified

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

Definition at line 361 of file recorder_writer.cpp.

◆ interval

int RecorderWriterManager::Private::interval = 1

Definition at line 367 of file recorder_writer.cpp.

◆ isActivateBlackTool

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

Definition at line 363 of file recorder_writer.cpp.

◆ isForceBlackTool

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

Definition at line 362 of file recorder_writer.cpp.

◆ outputDir

QDir RecorderWriterManager::Private::outputDir

Definition at line 372 of file recorder_writer.cpp.

◆ partIndex

int RecorderWriterManager::Private::partIndex = 0

Definition at line 365 of file recorder_writer.cpp.

◆ q

RecorderWriterManager* const RecorderWriterManager::Private::q

Definition at line 358 of file recorder_writer.cpp.

◆ recorderThreads

ThreadCounter& RecorderWriterManager::Private::recorderThreads

Definition at line 359 of file recorder_writer.cpp.

◆ settings

RecorderWriterSettings RecorderWriterManager::Private::settings {}

Definition at line 371 of file recorder_writer.cpp.

371{};

◆ timer

QTimer RecorderWriterManager::Private::timer

Definition at line 369 of file recorder_writer.cpp.

◆ toolActivated

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

Definition at line 364 of file recorder_writer.cpp.

◆ writerPool

WriterPool RecorderWriterManager::Private::writerPool

Definition at line 370 of file recorder_writer.cpp.


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