1 | // Copyright (C) 2024 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef FRAMEGENERATOR_H |
5 | #define FRAMEGENERATOR_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtCore/qobject.h> |
19 | #include <QtCore/qlist.h> |
20 | #include <QtMultimedia/qvideoframe.h> |
21 | #include <QtMultimedia/qaudiobuffer.h> |
22 | #include <private/audiogenerationutils_p.h> |
23 | |
24 | #include <functional> |
25 | #include <chrono> |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | enum class ImagePattern |
30 | { |
31 | SingleColor, // Image filled with a single color |
32 | ColoredSquares // Colored squares, [red, green; blue, yellow] |
33 | }; |
34 | |
35 | class VideoGenerator : public QObject |
36 | { |
37 | Q_OBJECT |
38 | public: |
39 | void setPattern(ImagePattern pattern); |
40 | void setFrameCount(int count); |
41 | void setSize(QSize size); |
42 | void setPixelFormat(QVideoFrameFormat::PixelFormat pixelFormat); |
43 | void setFrameRate(double rate); |
44 | void setPeriod(std::chrono::milliseconds period); |
45 | void setPresentationRotation(QtVideo::Rotation rotation); |
46 | void setPresentationMirrored(bool mirror); |
47 | void emitEmptyFrameOnStop(); |
48 | QVideoFrame createFrame(); |
49 | |
50 | signals: |
51 | void done(); |
52 | void frameCreated(const QVideoFrame &frame); |
53 | |
54 | public slots: |
55 | void nextFrame(); |
56 | |
57 | private: |
58 | QList<QColor> colors = { Qt::red, Qt::green, Qt::blue, Qt::black, Qt::white }; |
59 | ImagePattern m_pattern = ImagePattern::SingleColor; |
60 | QSize m_size{ 640, 480 }; |
61 | QVideoFrameFormat::PixelFormat m_pixelFormat = QVideoFrameFormat::Format_BGRA8888; |
62 | std::optional<int> m_maxFrameCount; |
63 | int m_frameIndex = 0; |
64 | std::optional<double> m_frameRate; |
65 | std::optional<std::chrono::milliseconds> m_period; |
66 | std::optional<QtVideo::Rotation> m_presentationRotation; |
67 | std::optional<bool> m_presentationMirrored; |
68 | bool m_emitEmptyFrameOnStop = false; |
69 | }; |
70 | |
71 | QT_END_NAMESPACE |
72 | |
73 | #endif |
74 | |