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, int index)
 
void started ()
 
void stopped ()
 

Public Member Functions

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, bool success)
 
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 97 of file recorder_writer.h.

Constructor & Destructor Documentation

◆ RecorderWriterManager() [1/4]

RecorderWriterManager::RecorderWriterManager ( const RecorderExportSettings & es)
explicit

Definition at line 494 of file recorder_writer.cpp.

495 : d(new Private(this, recorderThreads))
496 , exporterSettings(es)
497{
498 d->timer.setTimerType(Qt::PreciseTimer);
499}
ThreadCounter recorderThreads
const RecorderExportSettings & exporterSettings

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

◆ ~RecorderWriterManager()

RecorderWriterManager::~RecorderWriterManager ( )

Definition at line 501 of file recorder_writer.cpp.

502{
503 delete d;
504}

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

◆ frameWriteFailed

void RecorderWriterManager::frameWriteFailed ( )
signal

◆ lowPerformanceWarning

void RecorderWriterManager::lowPerformanceWarning ( )
signal

◆ onCapturingDone

void RecorderWriterManager::onCapturingDone ( int workerId,
bool success )
privateslot

Definition at line 640 of file recorder_writer.cpp.

641{
642 if (workerId >= d->writerPool.size())
643 return;
644 d->writerPool[workerId].inUse = false;
645 d->writerPool[workerId].thread->setPriority(QThread::IdlePriority);
647 if (!success) {
648 stop();
649 Q_EMIT frameWriteFailed();
650 }
651}
bool stop(bool toggleEnabled=true)

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

◆ onImageModified

void RecorderWriterManager::onImageModified ( )
privateslot

◆ onTimer

void RecorderWriterManager::onTimer ( )
privateslot

Definition at line 603 of file recorder_writer.cpp.

604{
605 if (!d->enabled || !d->canvas)
606 return;
607
608 // take snapshots only if main window is active
609 // else some dialogs like filters may disappear when canvas->image()->lock() is called
610 if (qobject_cast<KisMainWindow*>(QApplication::activeWindow()) == nullptr)
611 return;
612
614 (d->canvas->image()->isIsolatingLayer() || d->canvas->image()->isIsolatingGroup())) {
615 return;
616 }
617
618 if (!d->imageModified)
619 return;
620
621 d->imageModified = false;
622
623 if (!d->canStartCapture())
624 return;
625
627
628 if (d->freeWriterId == -1)
629 {
630 Q_EMIT lowPerformanceWarning();
631 return;
632 }
633
634 d->writerPool[d->freeWriterId].inUse = true;
635 d->writerPool[d->freeWriterId].thread->setPriority(QThread::HighPriority);
638}
void startCapturing(int writerId, int index)

References RecorderWriterManager::Private::canStartCapture(), RecorderWriterManager::Private::canvas, d, RecorderWriterManager::Private::enabled, RecorderWriterManager::Private::freeWriterId, RecorderWriterManager::Private::imageModified, ThreadCounter::incUsedAndNotify(), lowPerformanceWarning(), RecorderWriterManager::Private::partIndex, 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 665 of file recorder_writer.cpp.

666{
667 d->isForceBlackTool = forceBlacklistedTools.contains(toolId);
668 d->isActivateBlackTool = activateBlacklistedTools.contains(toolId);
669}
volatile std::atomic_bool isActivateBlackTool
volatile std::atomic_bool isForceBlackTool

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

◆ onToolPrimaryActionActivated

void RecorderWriterManager::onToolPrimaryActionActivated ( bool activated)
privateslot

Definition at line 671 of file recorder_writer.cpp.

672{
673 d->toolActivated = activated;
674}
volatile std::atomic_bool toolActivated

References 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 506 of file recorder_writer.cpp.

507{
508 // Restart writers if canvas changes
509 bool restart = d->timer.isActive();
510 if (restart) {
511 stop(false);
512 }
513
514 if (d->canvas) {
515 KoToolProxy *proxy = d->canvas->toolProxy();
516 KisToolProxy *kritaProxy = dynamic_cast<KisToolProxy*>(proxy);
517
518 disconnect(proxy, SIGNAL(toolChanged(QString)), this, SLOT(onToolChanged(QString)));
519 disconnect(kritaProxy, SIGNAL(toolPrimaryActionActivated(bool)), this, SLOT(onToolPrimaryActionActivated(bool)));
520 disconnect(d->canvas->image(), SIGNAL(sigImageUpdated(QRect)), this, SLOT(onImageModified()));
521 }
522
523 d->canvas = canvas;
524
525 if (d->canvas) {
526 KoToolProxy *proxy = d->canvas->toolProxy();
527 KisToolProxy *kritaProxy = dynamic_cast<KisToolProxy*>(proxy);
528
529 connect(proxy, SIGNAL(toolChanged(QString)), this, SLOT(onToolChanged(QString)),
530 Qt::DirectConnection); // need to handle it even if our event loop is not running
531 connect(kritaProxy, SIGNAL(toolPrimaryActionActivated(bool)), this, SLOT(onToolPrimaryActionActivated(bool)),
532 Qt::DirectConnection);
533 connect(d->canvas->image(), SIGNAL(sigImageUpdated(QRect)), this, SLOT(onImageModified()),
534 Qt::DirectConnection); // because it spams
535 }
536
537 if (restart) {
538 start(false);
539 }
540}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void start(bool toggleEnabled=true)
void onToolPrimaryActionActivated(bool activated)
void onToolChanged(const QString &toolId)

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

◆ setEnabled()

void RecorderWriterManager::setEnabled ( bool enabled = false)

Definition at line 598 of file recorder_writer.cpp.

599{
600 d->enabled = enabled;
601}

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

◆ setup()

void RecorderWriterManager::setup ( const RecorderWriterSettings & settings)

Definition at line 542 of file recorder_writer.cpp.

543{
544 // Restart writers if setup changes
545 bool restart = d->timer.isActive();
546 if (restart) {
547 stop(false);
548 }
549
550 d->settings = settings;
551 d->outputDir.setPath(settings.outputDirectory);
552
554
555 if (restart) {
556 start(false);
557 }
558}
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 560 of file recorder_writer.cpp.

561{
562 if (d->timer.isActive())
563 return;
564
565 if (!d->canvas)
566 return;
567
568 d->enabled = true;
569 d->imageModified = false;
570
571 connect(&d->timer, SIGNAL (timeout()), this, SLOT (onTimer()));
573 d->interval = static_cast<int>(1000.0/static_cast<double>(exporterSettings.fps));
574 } else {
575 d->interval = static_cast<int>(qMax(d->settings.captureInterval, .1) * 1000.0);
576 }
578 d->timer.start(d->interval);
579 if (toggleEnabled) {
580 Q_EMIT started();
581 }
582}

References RecorderWriterManager::Private::canvas, RecorderWriterSettings::captureInterval, connect(), 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,
int index )
signal

◆ started

void RecorderWriterManager::started ( )
signal

◆ stop()

bool RecorderWriterManager::stop ( bool toggleEnabled = true)

Definition at line 584 of file recorder_writer.cpp.

585{
586 if (!d->timer.isActive())
587 return true;
588
589 d->timer.stop();
590 auto result = d->clearWriterPool();
592 if (toggleEnabled) {
593 Q_EMIT stopped();
594 }
595 return result;
596}
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 141 of file recorder_writer.h.

◆ exporterSettings

const RecorderExportSettings& RecorderWriterManager::exporterSettings
private

Definition at line 142 of file recorder_writer.h.

◆ recorderThreads

ThreadCounter RecorderWriterManager::recorderThreads {}

Definition at line 137 of file recorder_writer.h.

137{};

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