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"
16
17#include "mythtvexp.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 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 uint8_t *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:
110
112 QObject *m_listener {nullptr};
113 QString m_pathname;
114
116 std::chrono::seconds m_captureTime {-1s};
117 long long m_captureFrame {-1};
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: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:315
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:68
unsigned int uint
Definition: freesurround.h:24
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:15
QMap< QString, QDateTime > FileTimeStampMap
Mode
Definition: synaesthesia.h:23