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:
25  PreviewGenState() = default;
26 
28  PreviewGenerator *m_gen {nullptr};
29 
31  bool m_genStarted {false};
32 
36 
40 
43  QDateTime m_blockRetryUntil;
44 
47  QSet<QString> m_tokens;
48 };
49 typedef QMap<QString,PreviewGenState> PreviewMap;
50 
67 class MTV_PUBLIC PreviewGeneratorQueue : public QObject, public MThread
68 {
69  Q_OBJECT
70 
71  public:
72  static void CreatePreviewGeneratorQueue(
74  uint maxAttempts, uint minBlockSeconds);
75  static void TeardownPreviewGeneratorQueue();
76 
88  static void GetPreviewImage(const ProgramInfo &pginfo, const QString& token)
89  {
90  GetPreviewImage(pginfo, QSize(0,0), "", -1, true, token);
91  }
92  static void GetPreviewImage(const ProgramInfo&, const QSize&,
93  const QString &outputfile,
94  long long time, bool in_seconds,
95  const QString& token);
96  static void AddListener(QObject*);
97  static void RemoveListener(QObject*);
98 
99  private:
101  uint maxAttempts, uint minBlockSeconds);
103 
104  QString GeneratePreviewImage(ProgramInfo &pginfo, const QSize&,
105  const QString &outputfile,
106  long long time, bool in_seconds,
107  const QString& token);
108 
109  void GetInfo(const QString &key, uint &queue_depth, uint &token_cnt);
110  void SetPreviewGenerator(const QString &key, PreviewGenerator *g);
111  void IncPreviewGeneratorPriority(const QString &key, const QString& token);
112  void UpdatePreviewGeneratorThreads(void);
113  bool IsGeneratingPreview(const QString &key) const;
114  uint IncPreviewGeneratorAttempts(const QString &key);
115  void ClearPreviewGeneratorAttempts(const QString &key);
116 
117  bool event(QEvent *e) override; // QObject
118 
119  void SendEvent(const ProgramInfo &pginfo,
120  const QString &eventname,
121  const QString &filename,
122  const QString &token,
123  const QString &msg,
124  const QDateTime &dt);
125 
126  private:
132  QSet<QObject*> m_listeners;
134  mutable QMutex m_lock;
141  QMap<QString,QString> m_tokenToKeyMap;
144  QStringList m_queue;
146  uint m_running {0};
149  uint m_maxThreads {2};
157 };
158 
159 #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
static void GetPreviewImage(const ProgramInfo &pginfo, const QString &token)
Submit a request for the generation of a preview image.
This class holds all the state information related to a specific preview generator.
uint m_lastBlockTime
The amount of time (in seconds) that this generator was blocked before it could start.
uint m_attempts
How many attempts have been made to generate a preview for this file.
unsigned int uint
Definition: compat.h:140
bool m_genStarted
The preview generator for this file is currently running.
This class creates a preview image of a recording.
Holds information on recordings and videos.
Definition: programinfo.h:66
QMap< QString, QString > m_tokenToKeyMap
A mapping from requestor tokens to internal keys.
#define MTV_PUBLIC
Definition: mythtvexp.h:15
PreviewGenerator * m_gen
A pointer to the generator that this state object describes.
QSet< QObject * > m_listeners
The set of all listeners that want messages when a preview request is queued or finishes.
PreviewGenState()=default
QDateTime m_blockRetryUntil
Any request to generate an image will be ignored until after this time.
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 ...
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,...
QSet< QString > m_tokens
The full set of tokens for all callers that have requested this preview.
This class implements a queue of preview generation requests.
unsigned char g
Definition: ParseText.cpp:329