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

#include <recorder_writer.h>

+ Inheritance diagram for RecorderWriterManager:

Classes

class  Private
 

Signals

void frameWriteFailed ()
 
void lowPerformanceWarning ()
 
void recorderStopWarning ()
 
void startCapturing (int writerId)
 
void started ()
 
void stopped ()
 

Public Member Functions

bool canStartCapture () const
 
QMutex * captureMutex ()
 
int incrementAndGetIndex ()
 
RecorderWriterManageroperator= (const RecorderWriterManager &)=delete
 
RecorderWriterManageroperator= (RecorderWriterManager &&)=delete
 
 RecorderWriterManager ()=delete
 
 RecorderWriterManager (const RecorderExportSettings &es)
 
 RecorderWriterManager (const RecorderWriterManager &)=delete
 
 RecorderWriterManager (RecorderWriterManager &&)=delete
 
void setCanvas (QPointer< KisCanvas2 > canvas)
 
void setEnabled (bool enabled)
 
void setup (const RecorderWriterSettings &settings)
 
void start (bool toggleEnabled=true)
 
bool stop (bool toggleEnabled=true)
 
 ~RecorderWriterManager ()
 

Public Attributes

ThreadCounter recorderThreads {}
 

Private Slots

void onCapturingDone (int workerId, int status)
 
void onImageModified ()
 
void onTimer ()
 
void onToolChanged (const QString &toolId)
 
void onToolPrimaryActionActivated (bool activated)
 

Private Attributes

Private *const d
 
const RecorderExportSettingsexporterSettings
 

Detailed Description

Definition at line 104 of file recorder_writer.h.

Constructor & Destructor Documentation

◆ RecorderWriterManager() [1/4]

RecorderWriterManager::RecorderWriterManager ( const RecorderExportSettings & es)
explicit

Definition at line 505 of file recorder_writer.cpp.

506 : d(new Private(this, recorderThreads))
507 , exporterSettings(es)
508{
509 d->timer.setTimerType(Qt::PreciseTimer);
510}
ThreadCounter recorderThreads
const RecorderExportSettings & exporterSettings

References d, and RecorderWriterManager::Private::timer.

◆ ~RecorderWriterManager()

RecorderWriterManager::~RecorderWriterManager ( )

Definition at line 512 of file recorder_writer.cpp.

513{
514 delete d;
515}

References d.

◆ RecorderWriterManager() [2/4]

RecorderWriterManager::RecorderWriterManager ( )
delete

◆ RecorderWriterManager() [3/4]

RecorderWriterManager::RecorderWriterManager ( const RecorderWriterManager & )
delete

◆ RecorderWriterManager() [4/4]

RecorderWriterManager::RecorderWriterManager ( RecorderWriterManager && )
delete

Member Function Documentation

◆ canStartCapture()

bool RecorderWriterManager::canStartCapture ( ) const

Definition at line 614 of file recorder_writer.cpp.

615{
616 if (d->isForceBlackTool)
617 return false;
619 return false;
620 return true;
621}
volatile std::atomic_bool toolActivated
volatile std::atomic_bool isActivateBlackTool
volatile std::atomic_bool isForceBlackTool

References d, RecorderWriterManager::Private::isActivateBlackTool, RecorderWriterManager::Private::isForceBlackTool, and RecorderWriterManager::Private::toolActivated.

◆ captureMutex()

QMutex * RecorderWriterManager::captureMutex ( )

Definition at line 628 of file recorder_writer.cpp.

629{
630 return &d->captureMutex;
631}

References RecorderWriterManager::Private::captureMutex, and d.

◆ frameWriteFailed

void RecorderWriterManager::frameWriteFailed ( )
signal

◆ incrementAndGetIndex()

int RecorderWriterManager::incrementAndGetIndex ( )

Definition at line 623 of file recorder_writer.cpp.

624{
625 return ++d->partIndex;
626}

References d, and RecorderWriterManager::Private::partIndex.

◆ lowPerformanceWarning

void RecorderWriterManager::lowPerformanceWarning ( )
signal

◆ onCapturingDone

void RecorderWriterManager::onCapturingDone ( int workerId,
int status )
privateslot

Definition at line 670 of file recorder_writer.cpp.

671{
672 if (workerId >= d->writerPool.size())
673 return;
674 d->writerPool[workerId].inUse = false;
675 d->writerPool[workerId].thread->setPriority(QThread::IdlePriority);
677 if (status == RecorderWriter::STATUS_ERROR) {
678 stop();
679 Q_EMIT frameWriteFailed();
680 }
681}
bool stop(bool toggleEnabled=true)
static constexpr int STATUS_ERROR

References d, ThreadCounter::decUsedAndNotify(), frameWriteFailed(), recorderThreads, RecorderWriter::STATUS_ERROR, stop(), and RecorderWriterManager::Private::writerPool.

◆ onImageModified

void RecorderWriterManager::onImageModified ( )
privateslot

Definition at line 683 of file recorder_writer.cpp.

684{
685 if (!d->enabled || !canStartCapture() )
686 return;
687
689 (d->canvas->image()->isIsolatingLayer() || d->canvas->image()->isIsolatingGroup()))
690 return;
691
692 d->imageModified = true;
693}
volatile std::atomic_bool imageModified
RecorderWriterSettings settings
volatile std::atomic_bool enabled

References canStartCapture(), RecorderWriterManager::Private::canvas, d, RecorderWriterManager::Private::enabled, RecorderWriterManager::Private::imageModified, RecorderWriterSettings::recordIsolateLayerMode, and RecorderWriterManager::Private::settings.

◆ onTimer

void RecorderWriterManager::onTimer ( )
privateslot

Definition at line 633 of file recorder_writer.cpp.

634{
635 if (!d->enabled || !d->canvas)
636 return;
637
638 // take snapshots only if main window is active
639 // else some dialogs like filters may disappear when canvas->image()->lock() is called
640 if (qobject_cast<KisMainWindow*>(QApplication::activeWindow()) == nullptr)
641 return;
642
644 (d->canvas->image()->isIsolatingLayer() || d->canvas->image()->isIsolatingGroup())) {
645 return;
646 }
647
648 if (!d->imageModified)
649 return;
650
651 d->imageModified = false;
652
653 if (!canStartCapture())
654 return;
655
657
658 if (d->freeWriterId == -1)
659 {
660 Q_EMIT lowPerformanceWarning();
661 return;
662 }
663
664 d->writerPool[d->freeWriterId].inUse = true;
665 d->writerPool[d->freeWriterId].thread->setPriority(QThread::HighPriority);
668}
void startCapturing(int writerId)

References canStartCapture(), RecorderWriterManager::Private::canvas, d, RecorderWriterManager::Private::enabled, RecorderWriterManager::Private::freeWriterId, RecorderWriterManager::Private::imageModified, ThreadCounter::incUsedAndNotify(), lowPerformanceWarning(), recorderThreads, RecorderWriterSettings::recordIsolateLayerMode, RecorderWriterManager::Private::searchForFreeWriter(), RecorderWriterManager::Private::settings, startCapturing(), and RecorderWriterManager::Private::writerPool.

◆ onToolChanged

void RecorderWriterManager::onToolChanged ( const QString & toolId)
privateslot

Definition at line 695 of file recorder_writer.cpp.

696{
697 QMutexLocker lock(&d->captureMutex);
698 d->isForceBlackTool = forceBlacklistedTools.contains(toolId);
699 d->isActivateBlackTool = activateBlacklistedTools.contains(toolId);
700}

References RecorderWriterManager::Private::captureMutex, d, RecorderWriterManager::Private::isActivateBlackTool, and RecorderWriterManager::Private::isForceBlackTool.

◆ onToolPrimaryActionActivated

void RecorderWriterManager::onToolPrimaryActionActivated ( bool activated)
privateslot

Definition at line 702 of file recorder_writer.cpp.

703{
704 QMutexLocker lock(&d->captureMutex);
705 d->toolActivated = activated;
706}

References RecorderWriterManager::Private::captureMutex, d, and RecorderWriterManager::Private::toolActivated.

◆ operator=() [1/2]

RecorderWriterManager & RecorderWriterManager::operator= ( const RecorderWriterManager & )
delete

◆ operator=() [2/2]

RecorderWriterManager & RecorderWriterManager::operator= ( RecorderWriterManager && )
delete

◆ recorderStopWarning

void RecorderWriterManager::recorderStopWarning ( )
signal

◆ setCanvas()

void RecorderWriterManager::setCanvas ( QPointer< KisCanvas2 > canvas)

Definition at line 517 of file recorder_writer.cpp.

518{
519 // Restart writers if canvas changes
520 bool restart = d->timer.isActive();
521 if (restart) {
522 stop(false);
523 }
524
525 if (d->canvas) {
526 KoToolProxy *proxy = d->canvas->toolProxy();
527 KisToolProxy *kritaProxy = dynamic_cast<KisToolProxy*>(proxy);
528
529 disconnect(proxy, SIGNAL(toolChanged(QString)), this, SLOT(onToolChanged(QString)));
530 disconnect(kritaProxy, SIGNAL(toolPrimaryActionActivated(bool)), this, SLOT(onToolPrimaryActionActivated(bool)));
531 disconnect(d->canvas->image(), SIGNAL(sigImageUpdated(QRect)), this, SLOT(onImageModified()));
532 }
533
534 d->canvas = canvas;
535
536 if (d->canvas) {
537 KoToolProxy *proxy = d->canvas->toolProxy();
538 KisToolProxy *kritaProxy = dynamic_cast<KisToolProxy*>(proxy);
539
540 connect(proxy, SIGNAL(toolChanged(QString)), this, SLOT(onToolChanged(QString)),
541 Qt::DirectConnection); // need to handle it even if our event loop is not running
542 connect(kritaProxy, SIGNAL(toolPrimaryActionActivated(bool)), this, SLOT(onToolPrimaryActionActivated(bool)),
543 Qt::DirectConnection);
544 connect(d->canvas->image(), SIGNAL(sigImageUpdated(QRect)), this, SLOT(onImageModified()),
545 Qt::DirectConnection); // because it spams
546 }
547
548 if (restart) {
549 start(false);
550 }
551}
void start(bool toggleEnabled=true)
void onToolPrimaryActionActivated(bool activated)
void onToolChanged(const QString &toolId)

References RecorderWriterManager::Private::canvas, d, onImageModified(), onToolChanged(), onToolPrimaryActionActivated(), start(), stop(), and RecorderWriterManager::Private::timer.

◆ setEnabled()

void RecorderWriterManager::setEnabled ( bool enabled = false)

Definition at line 609 of file recorder_writer.cpp.

610{
611 d->enabled = enabled;
612}

References d, and RecorderWriterManager::Private::enabled.

◆ setup()

void RecorderWriterManager::setup ( const RecorderWriterSettings & settings)

Definition at line 553 of file recorder_writer.cpp.

554{
555 // Restart writers if setup changes
556 bool restart = d->timer.isActive();
557 if (restart) {
558 stop(false);
559 }
560
561 d->settings = settings;
562 d->outputDir.setPath(settings.outputDirectory);
563
565
566 if (restart) {
567 start(false);
568 }
569}
int findLastIndex(const QString &directory)

References d, RecorderWriterManager::Private::findLastIndex(), RecorderWriterManager::Private::outputDir, RecorderWriterSettings::outputDirectory, RecorderWriterManager::Private::partIndex, RecorderWriterManager::Private::settings, start(), stop(), and RecorderWriterManager::Private::timer.

◆ start()

void RecorderWriterManager::start ( bool toggleEnabled = true)

Definition at line 571 of file recorder_writer.cpp.

572{
573 if (d->timer.isActive())
574 return;
575
576 if (!d->canvas)
577 return;
578
579 d->enabled = true;
580 d->imageModified = false;
581
582 connect(&d->timer, SIGNAL (timeout()), this, SLOT (onTimer()));
584 d->interval = static_cast<int>(1000.0/static_cast<double>(exporterSettings.fps));
585 } else {
586 d->interval = static_cast<int>(qMax(d->settings.captureInterval, .1) * 1000.0);
587 }
589 d->timer.start(d->interval);
590 if (toggleEnabled) {
591 Q_EMIT started();
592 }
593}

References RecorderWriterManager::Private::canvas, RecorderWriterSettings::captureInterval, d, RecorderWriterManager::Private::enabled, RecorderWriterManager::Private::enlargeWriterPool(), exporterSettings, RecorderExportSettings::fps, RecorderWriterManager::Private::imageModified, RecorderWriterManager::Private::interval, onTimer(), RecorderWriterSettings::realTimeCaptureMode, RecorderWriterManager::Private::settings, started(), and RecorderWriterManager::Private::timer.

◆ startCapturing

void RecorderWriterManager::startCapturing ( int writerId)
signal

◆ started

void RecorderWriterManager::started ( )
signal

◆ stop()

bool RecorderWriterManager::stop ( bool toggleEnabled = true)

Definition at line 595 of file recorder_writer.cpp.

596{
597 if (!d->timer.isActive())
598 return true;
599
600 d->timer.stop();
601 auto result = d->clearWriterPool();
603 if (toggleEnabled) {
604 Q_EMIT stopped();
605 }
606 return result;
607}
bool setUsed(int value)

References RecorderWriterManager::Private::clearWriterPool(), d, recorderThreads, ThreadCounter::setUsed(), stopped(), and RecorderWriterManager::Private::timer.

◆ stopped

void RecorderWriterManager::stopped ( )
signal

Member Data Documentation

◆ d

Private* const RecorderWriterManager::d
private

Definition at line 162 of file recorder_writer.h.

◆ exporterSettings

const RecorderExportSettings& RecorderWriterManager::exporterSettings
private

Definition at line 163 of file recorder_writer.h.

◆ recorderThreads

ThreadCounter RecorderWriterManager::recorderThreads {}

Definition at line 158 of file recorder_writer.h.

158{};

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