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 "previewgenerator.h"
12 #include "mythtvexp.h"
13 #include "mthread.h"
14 
15 class ProgramInfo;
16 class QSize;
17 
23 {
24  public:
26  gen(nullptr), genStarted(false),
27  attempts(0), lastBlockTime(0) {}
28 
31 
33  bool genStarted;
34 
38 
42 
45  QDateTime blockRetryUntil;
46 
49  QSet<QString> tokens;
50 };
51 typedef QMap<QString,PreviewGenState> PreviewMap;
52 
69 class MTV_PUBLIC PreviewGeneratorQueue : public QObject, public MThread
70 {
71  Q_OBJECT
72 
73  public:
74  static void CreatePreviewGeneratorQueue(
76  uint maxAttempts, uint minBlockSeconds);
77  static void TeardownPreviewGeneratorQueue();
78 
90  static void GetPreviewImage(const ProgramInfo &pginfo, QString token)
91  {
92  GetPreviewImage(pginfo, QSize(0,0), "", -1, true, token);
93  }
94  static void GetPreviewImage(const ProgramInfo&, const QSize&,
95  const QString &outputfile,
96  long long time, bool in_seconds,
97  QString token);
98  static void AddListener(QObject*);
99  static void RemoveListener(QObject*);
100 
101  private:
103  uint maxAttempts, uint minBlockSeconds);
105 
106  QString GeneratePreviewImage(ProgramInfo &pginfo, const QSize&,
107  const QString &outputfile,
108  long long time, bool in_seconds,
109  QString token);
110 
111  void GetInfo(const QString &key, uint &queue_depth, uint &preview_tokens);
112  void SetPreviewGenerator(const QString &key, PreviewGenerator *g);
113  void IncPreviewGeneratorPriority(const QString &key, QString token);
114  void UpdatePreviewGeneratorThreads(void);
115  bool IsGeneratingPreview(const QString &key) const;
116  uint IncPreviewGeneratorAttempts(const QString &key);
117  void ClearPreviewGeneratorAttempts(const QString &key);
118 
119  bool event(QEvent *e) override; // QObject
120 
121  void SendEvent(const ProgramInfo &pginfo,
122  const QString &eventname,
123  const QString &fn,
124  const QString &token,
125  const QString &msg,
126  const QDateTime &dt);
127 
128  private:
134  QSet<QObject*> m_listeners;
136  mutable QMutex m_lock;
143  QMap<QString,QString> m_tokenToKeyMap;
146  QStringList m_queue;
159 };
160 
161 #endif // _PREVIEW_GENERATOR_QUEUE_H_
static int SendEvent(const MythUtilCommandLineParser &cmdline)
PreviewGenerator::Mode m_mode
uint m_minBlockSeconds
How long after a failed preview generation attempt will the code ignore subsequent requests.
QStringList m_queue
The queue of previews to be generated.
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
PreviewGenerator * gen
A pointer to the generator that this state object describes.
This class holds all the state information related to a specific preview generator.
uint lastBlockTime
The amount of time (in seconds) that this generator was blocked before it could start.
uint attempts
How many attempts have been made to generate a preview for this file.
QSet< QString > tokens
The full set of tokens for all callers that have requested this preview.
unsigned int uint
Definition: compat.h:140
This class creates a preview image of a recording.
QDateTime blockRetryUntil
Any request to generate an image will be ignored until after this time.
Holds information on recordings and videos.
Definition: programinfo.h:66
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
QMap< QString, QString > m_tokenToKeyMap
A mapping from requestor tokens to internal keys.
#define MTV_PUBLIC
Definition: mythtvexp.h:15
static void GetPreviewImage(const ProgramInfo &pginfo, QString token)
Submit a request for the generation of a preview image.
QSet< QObject * > m_listeners
The set of all listeners that want messages when a preview request is queued or finishes.
bool genStarted
The preview generator for this file is currently running.
QMutex m_lock
The thread interlock for this data structure.
PreviewMap m_previewMap
A mapping from the generated preview name to the state information on the progress of generating the ...
uint m_running
The number of threads currently generating previews.
static PreviewGeneratorQueue * s_pgq
The singleton queue.
QMap< QString, PreviewGenState > PreviewMap
uint m_maxAttempts
How many times total will the code attempt to generate a preview for a specific file,...
uint m_maxThreads
The maximum number of threads that may concurrently generate previews.
This class implements a queue of preview generation requests.
unsigned char g
Definition: ParseText.cpp:340