Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
framegenerator.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
5
6#include <private/qplatformmediaintegration_p.h>
7
9
10void VideoGenerator::setPattern(ImagePattern pattern)
11{
12 m_pattern = pattern;
13}
14
16{
17 m_maxFrameCount = count;
18}
19
20void VideoGenerator::setSize(QSize size)
21{
22 m_size = size;
23}
24
25void VideoGenerator::setPixelFormat(QVideoFrameFormat::PixelFormat pixelFormat)
26{
27 m_pixelFormat = pixelFormat;
28}
29
30void VideoGenerator::setFrameRate(double rate)
31{
32 m_frameRate = rate;
33}
34
35void VideoGenerator::setPeriod(std::chrono::microseconds period)
36{
37 m_period = period;
38}
39
40void VideoGenerator::setPresentationRotation(QtVideo::Rotation rotation)
41{
42 m_presentationRotation = rotation;
43}
44
46{
47 m_presentationMirrored = mirror;
48}
49void VideoGenerator::setEndTimeReporting(bool endTimeIsReported)
50{
51 m_endTimeIsReported = endTimeIsReported;
52}
53
54void VideoGenerator::setColors(std::array<QColor, 5> newColors)
55{
56 m_colors = newColors;
57}
58
60{
61 m_emitEmptyFrameOnStop = true;
62}
63
64static void fillColoredSquares(QImage& image)
65{
66 QList<QColor> colors = { Qt::red, Qt::green, Qt::blue, Qt::yellow };
67 const int width = image.width();
68 const int height = image.height();
69
70 for (int j = 0; j < height; ++j) {
71 for (int i = 0; i < width; ++i) {
72 const int colorX = i < width / 2 ? 0 : 1;
73 const int colorY = j < height / 2 ? 0 : 1;
74 const int colorIndex = colorX + 2 * colorY;
75 image.setPixel(i, j, colors[colorIndex].rgb());
76 }
77 }
78}
79
81{
82 using namespace std::chrono;
83
84 QImage image(m_size, QImage::Format_ARGB32);
85 switch (m_pattern) {
86 case ImagePattern::SingleColor:
87 image.fill(m_colors[m_frameIndex % m_colors.size()]);
88 break;
89 case ImagePattern::ColoredSquares:
90 fillColoredSquares(image);
91 break;
92 }
93
94 QVideoFrame rgbFrame(image);
95 QVideoFrameFormat outputFormat { m_size, m_pixelFormat };
96 QVideoFrame frame =
97 QPlatformMediaIntegration::instance()->convertVideoFrame(rgbFrame, outputFormat);
98
99 if (m_frameRate)
100 frame.setStreamFrameRate(*m_frameRate);
101
102 if (m_period) {
103 frame.setStartTime(m_period->count() * m_frameIndex);
104 if (m_endTimeIsReported)
105 frame.setEndTime(m_period->count() * (m_frameIndex + 1));
106 }
107
108 if (m_presentationRotation)
109 frame.setRotation(*m_presentationRotation);
110
111 if (m_presentationMirrored)
112 frame.setMirrored(*m_presentationMirrored);
113
114 return frame;
115}
116
117void VideoGenerator::nextFrame()
118{
119 if (m_frameIndex == m_maxFrameCount) {
120 emit done();
121 if (m_emitEmptyFrameOnStop)
122 emit frameCreated({});
123 return;
124 }
125
126 const QVideoFrame frame = createFrame();
127 emit frameCreated(frame);
128 ++m_frameIndex;
129}
130
131QT_END_NAMESPACE
132
133#include "moc_framegenerator_p.cpp"
void setEndTimeReporting(bool endTimeIsReported)
QVideoFrame createFrame()
void setSize(QSize size)
void emitEmptyFrameOnStop()
void setPresentationMirrored(bool mirror)
void setColors(std::array< QColor, 5 > colors)
void setFrameCount(int count)
void setPeriod(std::chrono::microseconds period)
void setFrameRate(double rate)
void setPresentationRotation(QtVideo::Rotation rotation)
void setPixelFormat(QVideoFrameFormat::PixelFormat pixelFormat)
static void fillColoredSquares(QImage &image)
Combined button and popup list for selecting options.