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 "libmythbase/mthread.h"
14 #include "libmythbase/mythdate.h"
16 
17 #include "mythtvexp.h"
18 
19 class PreviewGenerator;
20 class QByteArray;
21 class MythSocket;
22 class QObject;
23 class QEvent;
24 
25 using FileTimeStampMap = QMap<QString,QDateTime>;
26 
27 class MTV_PUBLIC PreviewGenerator : public QObject, public MThread
28 {
29  friend int preview_helper(uint chanid,
30  QDateTime starttime,
31  long long previewFrameNumber,
32  std::chrono::seconds previewSeconds,
33  QSize previewSize,
34  const QString &infile,
35  const QString &outfile);
36 
37  Q_OBJECT
38 
39  public:
40  enum Mode : std::uint8_t
41  {
42  kNone = 0x0,
43  kLocal = 0x1,
44  kRemote = 0x2,
45  kLocalAndRemote = 0x3,
46  kForceLocal = 0x5,
47  kModeMask = 0x7,
48  };
49 
50  public:
51  PreviewGenerator(const ProgramInfo *pginfo,
52  QString token,
53  Mode mode = kLocal);
54 
55  void SetPreviewTime(std::chrono::seconds time, long long frame)
56  { m_captureTime = time; m_captureFrame = frame; }
57  void SetPreviewTimeAsSeconds(std::chrono::seconds seconds)
58  { SetPreviewTime(seconds, -1); }
59  void SetPreviewTimeAsFrameNumber(long long frame_number)
60  { SetPreviewTime(-1s, frame_number); }
61  void SetOutputFilename(const QString &fileName);
62  void SetOutputSize(const QSize size) { m_outSize = size; }
63 
64  QString GetToken(void) const { return m_token; }
65 
66  void run(void) override; // MThread
67  bool Run(void);
68 
69  void AttachSignals(QObject *obj);
70 
71  public slots:
72  void deleteLater();
73 
74  protected:
75  ~PreviewGenerator() override;
76  void TeardownAll(void);
77 
78  bool RemotePreviewRun(void);
79  bool LocalPreviewRun(void);
80  bool IsLocal(void) const;
81 
82  bool RunReal(void);
83 
84  static char *GetScreenGrab(const ProgramInfo &pginfo,
85  const QString &filename,
86  std::chrono::seconds seektime,
87  long long seekframe,
88  int &bufferlen,
89  int &video_width,
90  int &video_height,
91  float &video_aspect);
92 
93  static bool SavePreview(const QString &filename,
94  const unsigned char *data,
95  uint width, uint height, float aspect,
96  int desired_width, int desired_height,
97  const QString &format);
98 
99 
100  static QString CreateAccessibleFilename(
101  const QString &pathname, const QString &outFileName);
102 
103  bool event(QEvent *e) override; // QObject
104  bool SaveOutFile(const QByteArray &data, const QDateTime &dt);
105 
106  protected:
107  QWaitCondition m_previewWaitCondition;
110 
112  QObject *m_listener {nullptr};
113  QString m_pathname;
114 
116  std::chrono::seconds m_captureTime {-1s};
117  long long m_captureFrame {-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_
PreviewGenerator::SetOutputSize
void SetOutputSize(const QSize size)
Definition: previewgenerator.h:62
PreviewGenerator::SetPreviewTime
void SetPreviewTime(std::chrono::seconds time, long long frame)
Definition: previewgenerator.h:55
PreviewGenerator::SetPreviewTimeAsSeconds
void SetPreviewTimeAsSeconds(std::chrono::seconds seconds)
Definition: previewgenerator.h:57
PreviewGenerator::m_token
QString m_token
Definition: previewgenerator.h:122
PreviewGenerator::SetPreviewTimeAsFrameNumber
void SetPreviewTimeAsFrameNumber(long long frame_number)
Definition: previewgenerator.h:59
mythtvexp.h
PreviewGenerator
This class creates a preview image of a recording.
Definition: previewgenerator.h:27
PreviewGenerator::m_pathname
QString m_pathname
Definition: previewgenerator.h:113
MythSocket
Class for communcating between myth backends and frontends.
Definition: mythsocket.h:25
mythdate.h
programinfo.h
preview_helper
int preview_helper(uint chanid, QDateTime starttime, long long previewFrameNumber, std::chrono::seconds previewSeconds, const QSize previewSize, const QString &infile, const QString &outfile)
Definition: mythpreviewgen.cpp:66
FileTimeStampMap
QMap< QString, QDateTime > FileTimeStampMap
Definition: previewgenerator.h:25
MThread::run
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:315
PreviewGenerator::m_previewWaitCondition
QWaitCondition m_previewWaitCondition
Definition: previewgenerator.h:107
PreviewGenerator::Mode
Mode
Definition: previewgenerator.h:40
PreviewGenerator::m_programInfo
ProgramInfo m_programInfo
Definition: previewgenerator.h:109
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
PreviewGenerator::m_outFileName
QString m_outFileName
Definition: previewgenerator.h:118
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
PreviewGenerator::GetToken
QString GetToken(void) const
Definition: previewgenerator.h:64
PreviewGenerator::m_mode
Mode m_mode
Definition: previewgenerator.h:111
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
mthread.h
build_compdb.filename
filename
Definition: build_compdb.py:21
Mode
Mode
Definition: synaesthesia.h:23
PreviewGenerator::m_previewLock
QMutex m_previewLock
Definition: previewgenerator.h:108
uint
unsigned int uint
Definition: freesurround.h:24