MythTV master
previewgeneratorqueue.h
Go to the documentation of this file.
1// -*- Mode: c++ -*-
2#ifndef PREVIEW_GENERATOR_QUEUE_H
3#define PREVIEW_GENERATOR_QUEUE_H
4
5#include <QStringList>
6#include <QDateTime>
7#include <QMutex>
8#include <QMap>
9#include <QSet>
10
11#include "libmythbase/mthread.h"
12
13#include "previewgenerator.h"
14#include "mythtvexp.h"
15
16class ProgramInfo;
17class QSize;
18
24{
25 public:
26 PreviewGenState() = default;
27
30
32 bool m_genStarted {false};
33
37
40 std::chrono::seconds m_lastBlockTime {0s};
41
45
48 QSet<QString> m_tokens;
49};
50using PreviewMap = QMap<QString,PreviewGenState>;
51
68class MTV_PUBLIC PreviewGeneratorQueue : public QObject, public MThread
69{
70 Q_OBJECT
71
72 public:
73 static void CreatePreviewGeneratorQueue(
75 uint maxAttempts, std::chrono::seconds minBlockSeconds);
76 static void TeardownPreviewGeneratorQueue();
77
89 static void GetPreviewImage(const ProgramInfo &pginfo, const QString& token)
90 {
91 GetPreviewImage(pginfo, QSize(0,0), "", -1s, -1, token);
92 }
93 static void GetPreviewImage(const ProgramInfo &pginfo, QSize outputsize,
94 const QString &outputfile,
95 std::chrono::seconds time, long long frame,
96 const QString& token);
97 static void AddListener(QObject *listener);
98 static void RemoveListener(QObject *listener);
99
100 private:
102 uint maxAttempts, std::chrono::seconds minBlockSeconds);
103 ~PreviewGeneratorQueue() override;
104
105 QString GeneratePreviewImage(ProgramInfo &pginfo, QSize size,
106 const QString &outputfile,
107 std::chrono::seconds time, long long frame,
108 const QString& token);
109
110 void GetInfo(const QString &key, uint &queue_depth, uint &token_cnt);
111 void SetPreviewGenerator(const QString &key, PreviewGenerator *g);
112 void IncPreviewGeneratorPriority(const QString &key, const QString& token);
113 void UpdatePreviewGeneratorThreads(void);
114 bool IsGeneratingPreview(const QString &key) const;
115 uint IncPreviewGeneratorAttempts(const QString &key);
116 void ClearPreviewGeneratorAttempts(const QString &key);
117
118 bool event(QEvent *e) override; // QObject
119
120 void SendEvent(const ProgramInfo &pginfo,
121 const QString &eventname,
122 const QString &filename,
123 const QString &token,
124 const QString &msg,
125 const QDateTime &dt);
126
127 private:
133 QSet<QObject*> m_listeners;
135 mutable QMutex m_lock;
142 QMap<QString,QString> m_tokenToKeyMap;
145 QStringList m_queue;
147 uint m_running {0};
150 uint m_maxThreads {2};
157 std::chrono::seconds m_minBlockSeconds;
158};
159
160#endif // PREVIEW_GENERATOR_QUEUE_H
static int SendEvent(const MythUtilCommandLineParser &cmdline)
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49
This class holds all the state information related to a specific preview generator.
uint m_attempts
How many attempts have been made to generate a preview for this file.
bool m_genStarted
The preview generator for this file is currently running.
PreviewGenState()=default
QDateTime m_blockRetryUntil
Any request to generate an image will be ignored until after this time.
std::chrono::seconds m_lastBlockTime
The amount of time (in seconds) that this generator was blocked before it could start.
QSet< QString > m_tokens
The full set of tokens for all callers that have requested this preview.
PreviewGenerator * m_gen
A pointer to the generator that this state object describes.
This class implements a queue of preview generation requests.
uint m_maxAttempts
How many times total will the code attempt to generate a preview for a specific file,...
QMap< QString, QString > m_tokenToKeyMap
A mapping from requestor tokens to internal keys.
QSet< QObject * > m_listeners
The set of all listeners that want messages when a preview request is queued or finishes.
std::chrono::seconds m_minBlockSeconds
How long after a failed preview generation attempt will the code ignore subsequent requests.
static PreviewGeneratorQueue * s_pgq
The singleton queue.
QStringList m_queue
The queue of previews to be generated.
PreviewGenerator::Mode m_mode
static void GetPreviewImage(const ProgramInfo &pginfo, const QString &token)
Submit a request for the generation of a preview image.
PreviewMap m_previewMap
A mapping from the generated preview name to the state information on the progress of generating the ...
QMutex m_lock
The thread interlock for this data structure.
This class creates a preview image of a recording.
Holds information on recordings and videos.
Definition: programinfo.h:68
unsigned int uint
Definition: freesurround.h:24
#define MTV_PUBLIC
Definition: mythtvexp.h:15
QMap< QString, PreviewGenState > PreviewMap