|
MythTV
0.26-pre
|
00001 // -*- Mode: c++ -*- 00002 #ifndef _PREVIEW_GENERATOR_QUEUE_H_ 00003 #define _PREVIEW_GENERATOR_QUEUE_H_ 00004 00005 #include <QStringList> 00006 #include <QDateTime> 00007 #include <QMutex> 00008 #include <QMap> 00009 #include <QSet> 00010 00011 #include "previewgenerator.h" 00012 #include "mythtvexp.h" 00013 #include "mthread.h" 00014 00015 class ProgramInfo; 00016 class QSize; 00017 00018 class PreviewGenState 00019 { 00020 public: 00021 PreviewGenState() : 00022 gen(NULL), genStarted(false), 00023 attempts(0), lastBlockTime(0) {} 00024 PreviewGenerator *gen; 00025 bool genStarted; 00026 uint attempts; 00027 uint lastBlockTime; 00028 QDateTime blockRetryUntil; 00029 QSet<QString> tokens; 00030 }; 00031 typedef QMap<QString,PreviewGenState> PreviewMap; 00032 00033 class MTV_PUBLIC PreviewGeneratorQueue : public QObject, public MThread 00034 { 00035 Q_OBJECT 00036 00037 public: 00038 static void CreatePreviewGeneratorQueue( 00039 PreviewGenerator::Mode mode, 00040 uint maxAttempts, uint minBlockSeconds); 00041 static void TeardownPreviewGeneratorQueue(); 00042 00043 static void GetPreviewImage(const ProgramInfo &pginfo, QString token) 00044 { 00045 GetPreviewImage(pginfo, QSize(0,0), "", -1, true, token); 00046 } 00047 static void GetPreviewImage(const ProgramInfo&, const QSize&, 00048 const QString &outputfile, 00049 long long time, bool in_seconds, 00050 QString token); 00051 static void AddListener(QObject*); 00052 static void RemoveListener(QObject*); 00053 00054 private: 00055 PreviewGeneratorQueue(PreviewGenerator::Mode mode, 00056 uint maxAttempts, uint minBlockSeconds); 00057 ~PreviewGeneratorQueue(); 00058 00059 QString GeneratePreviewImage(ProgramInfo &pginfo, const QSize&, 00060 const QString &outputfile, 00061 long long time, bool in_seconds, 00062 QString token); 00063 00064 void GetInfo(const QString &key, uint &queue_depth, uint &preview_tokens); 00065 void SetPreviewGenerator(const QString &key, PreviewGenerator *g); 00066 void IncPreviewGeneratorPriority(const QString &key, QString token); 00067 void UpdatePreviewGeneratorThreads(void); 00068 bool IsGeneratingPreview(const QString &key) const; 00069 uint IncPreviewGeneratorAttempts(const QString &key); 00070 void ClearPreviewGeneratorAttempts(const QString &key); 00071 00072 virtual bool event(QEvent *e); // QObject 00073 00074 void SendEvent(const ProgramInfo &pginfo, 00075 const QString &eventname, 00076 const QString &fn, 00077 const QString &token, 00078 const QString &msg, 00079 const QDateTime &dt); 00080 00081 private: 00082 static PreviewGeneratorQueue *s_pgq; 00083 QSet<QObject*> m_listeners; 00084 00085 mutable QMutex m_lock; 00086 PreviewGenerator::Mode m_mode; 00087 PreviewMap m_previewMap; 00088 QMap<QString,QString> m_tokenToKeyMap; 00089 QStringList m_queue; 00090 uint m_running; 00091 uint m_maxThreads; 00092 uint m_maxAttempts; 00093 uint m_minBlockSeconds; 00094 }; 00095 00096 #endif // _PREVIEW_GENERATOR_QUEUE_H_
1.7.6.1