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"
15
16#include "mythtvexp.h"
17#include "programinfo.h"
18
20class QByteArray;
21class MythSocket;
22class QObject;
23class QEvent;
24
25using FileTimeStampMap = QMap<QString,QDateTime>;
26
27class 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 bool Run(void);
67
68 void AttachSignals(QObject *obj);
69
70 bool event(QEvent *e) override; // QObject
71
72 protected:
73 void run(void) override; // MThread
74
75 public slots:
76 void deleteLater();
77
78 protected:
79 ~PreviewGenerator() override;
80 void TeardownAll(void);
81
82 bool RemotePreviewRun(void);
83 bool LocalPreviewRun(void);
84 bool IsLocal(void) const;
85
86 bool RunReal(void);
87
88 static uint8_t *GetScreenGrab(const ProgramInfo &pginfo,
89 const QString &filename,
90 std::chrono::seconds seektime,
91 long long seekframe,
92 int &bufferlen,
93 int &video_width,
94 int &video_height,
95 float &video_aspect);
96
97 static bool SavePreview(const QString &filename,
98 const unsigned char *data,
99 uint width, uint height, float aspect,
100 int desired_width, int desired_height,
101 const QString &format);
102
103
104 static QString CreateAccessibleFilename(
105 const QString &pathname, const QString &outFileName);
106
107 bool SaveOutFile(const QByteArray &data, const QDateTime &dt);
108
109 protected:
113
115 QObject *m_listener {nullptr};
116 QString m_pathname;
117
119 std::chrono::seconds m_captureTime {-1s};
120 long long m_captureFrame {-1};
122 QSize m_outSize {0,0};
123 QString m_outFormat {"PNG"};
124
125 QString m_token;
126 bool m_gotReply {false};
127 bool m_pixmapOk {false};
128};
129
130#endif // PREVIEW_GENERATOR_H_
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49
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:299
Class for communcating between myth backends and frontends.
Definition: mythsocket.h:26
This class creates a preview image of a recording.
QString GetToken(void) const
void SetOutputSize(const QSize size)
void SetPreviewTimeAsSeconds(std::chrono::seconds seconds)
void SetPreviewTimeAsFrameNumber(long long frame_number)
QWaitCondition m_previewWaitCondition
ProgramInfo m_programInfo
void SetPreviewTime(std::chrono::seconds time, long long frame)
Holds information on recordings and videos.
Definition: programinfo.h:74
unsigned int uint
Definition: compat.h:60
int preview_helper(uint chanid, QDateTime starttime, long long previewFrameNumber, std::chrono::seconds previewSeconds, const QSize previewSize, const QString &infile, const QString &outfile)
#define MTV_PUBLIC
Definition: mythtvexp.h:8
QMap< QString, QDateTime > FileTimeStampMap
Mode
Definition: synaesthesia.h:20