MythTV  master
previewgenerator.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 #ifndef PREVIEW_GENERATOR_H_
3 #define PREVIEW_GENERATOR_H_
4 
5 #include <QWaitCondition>
6 #include <QDateTime>
7 #include <QString>
8 #include <QMutex>
9 #include <QSize>
10 #include <QMap>
11 #include <QSet>
12 
13 #include "programinfo.h"
14 #include "mythtvexp.h"
15 #include "mthread.h"
16 #include "mythdate.h"
17 
18 class PreviewGenerator;
19 class QByteArray;
20 class MythSocket;
21 class QObject;
22 class QEvent;
23 
24 typedef QMap<QString,QDateTime> FileTimeStampMap;
25 
26 class MTV_PUBLIC PreviewGenerator : public QObject, public MThread
27 {
28  friend int preview_helper(uint chanid,
29  QDateTime starttime,
30  long long previewFrameNumber,
31  long long previewSeconds,
32  const QSize &previewSize,
33  const QString &infile,
34  const QString &outfile);
35 
36  Q_OBJECT
37 
38  public:
39  typedef enum Mode
40  {
41  kNone = 0x0,
42  kLocal = 0x1,
43  kRemote = 0x2,
44  kLocalAndRemote = 0x3,
45  kForceLocal = 0x5,
46  kModeMask = 0x7,
47  } Mode;
48 
49  public:
50  PreviewGenerator(const ProgramInfo *pginfo,
51  const QString &token,
52  Mode mode = kLocal);
53 
54  void SetPreviewTime(long long time, bool in_seconds)
55  { m_captureTime = time; m_timeInSeconds = in_seconds; }
56  void SetPreviewTimeAsSeconds(long long seconds_in)
57  { SetPreviewTime(seconds_in, true); }
58  void SetPreviewTimeAsFrameNumber(long long frame_number)
59  { SetPreviewTime(frame_number, false); }
60  void SetOutputFilename(const QString&);
61  void SetOutputSize(const QSize &size) { m_outSize = size; }
62 
63  QString GetToken(void) const { return m_token; }
64 
65  void run(void) override; // MThread
66  bool Run(void);
67 
68  void AttachSignals(QObject*);
69 
70  public slots:
71  void deleteLater();
72 
73  protected:
74  virtual ~PreviewGenerator();
75  void TeardownAll(void);
76 
77  bool RemotePreviewRun(void);
78  bool LocalPreviewRun(void);
79  bool IsLocal(void) const;
80 
81  bool RunReal(void);
82 
83  static char *GetScreenGrab(const ProgramInfo &pginfo,
84  const QString &filename,
85  long long seektime,
86  bool time_in_secs,
87  int &bufferlen,
88  int &video_width,
89  int &video_height,
90  float &video_aspect);
91 
92  static bool SavePreview(const QString &filename,
93  const unsigned char *data,
94  uint width, uint height, float aspect,
95  int desired_width, int desired_height,
96  const QString &format);
97 
98 
99  static QString CreateAccessibleFilename(
100  const QString &pathname, const QString &outFileName);
101 
102  bool event(QEvent *e) override; // QObject
103  bool SaveOutFile(const QByteArray &data, const QDateTime &dt);
104 
105  protected:
106  QWaitCondition m_previewWaitCondition;
109 
111  QObject *m_listener {nullptr};
112  QString m_pathname;
113 
115  bool m_timeInSeconds {true};
117  long long m_captureTime {-1};
118  QString m_outFileName;
119  QSize m_outSize {0,0};
120  QString m_outFormat {"PNG"};
121 
122  QString m_token;
123  bool m_gotReply {false};
124  bool m_pixmapOk {false};
125 };
126 
127 #endif // PREVIEW_GENERATOR_H_
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
unsigned int slots[4]
Definition: element.c:38
virtual void run(void)
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: mthread.cpp:318
QWaitCondition m_previewWaitCondition
QMap< QString, QDateTime > FileTimeStampMap
unsigned int uint
Definition: compat.h:140
ProgramInfo m_programInfo
This class creates a preview image of a recording.
QString GetToken(void) const
Holds information on recordings and videos.
Definition: programinfo.h:66
#define MTV_PUBLIC
Definition: mythtvexp.h:15
void SetPreviewTimeAsFrameNumber(long long frame_number)
void SetOutputSize(const QSize &size)
void SetPreviewTimeAsSeconds(long long seconds_in)
int preview_helper(uint chanid, QDateTime starttime, long long previewFrameNumber, long long previewSeconds, const QSize &previewSize, const QString &infile, const QString &outfile)
void SetPreviewTime(long long time, bool in_seconds)
Class for communcating between myth backends and frontends.
Definition: mythsocket.h:26