0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include <QtTest/QtTest>
|
|
43 |
|
|
44 |
#include <QtMultimedia/QAbstractVideoSurface>
|
|
45 |
#include <QtMultimedia/QVideoSurfaceFormat>
|
|
46 |
|
|
47 |
class tst_QAbstractVideoSurface : public QObject
|
|
48 |
{
|
|
49 |
Q_OBJECT
|
|
50 |
public:
|
|
51 |
tst_QAbstractVideoSurface();
|
|
52 |
~tst_QAbstractVideoSurface();
|
|
53 |
|
|
54 |
public slots:
|
|
55 |
void initTestCase();
|
|
56 |
void cleanupTestCase();
|
|
57 |
void init();
|
|
58 |
void cleanup();
|
|
59 |
|
|
60 |
private slots:
|
|
61 |
void setError();
|
|
62 |
void isFormatSupported_data();
|
|
63 |
void isFormatSupported();
|
|
64 |
void start_data();
|
|
65 |
void start();
|
|
66 |
};
|
|
67 |
|
|
68 |
typedef QMap<QAbstractVideoBuffer::HandleType, QVideoFrame::PixelFormat> SupportedFormatMap;
|
|
69 |
|
|
70 |
Q_DECLARE_METATYPE(SupportedFormatMap)
|
|
71 |
Q_DECLARE_METATYPE(QVideoSurfaceFormat)
|
|
72 |
Q_DECLARE_METATYPE(QAbstractVideoSurface::Error);
|
|
73 |
|
|
74 |
class QtTestVideoSurface : public QAbstractVideoSurface
|
|
75 |
{
|
|
76 |
Q_OBJECT
|
|
77 |
public:
|
|
78 |
explicit QtTestVideoSurface(QObject *parent = 0) : QAbstractVideoSurface(parent) {}
|
|
79 |
explicit QtTestVideoSurface(SupportedFormatMap formats, QObject *parent = 0)
|
|
80 |
: QAbstractVideoSurface(parent), supportedFormats(formats) {}
|
|
81 |
|
|
82 |
QList<QVideoFrame::PixelFormat> supportedPixelFormats(
|
|
83 |
QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const
|
|
84 |
{
|
|
85 |
return supportedFormats.values(handleType);
|
|
86 |
}
|
|
87 |
|
|
88 |
bool present(const QVideoFrame &) { return false; }
|
|
89 |
|
|
90 |
using QAbstractVideoSurface::setError;
|
|
91 |
|
|
92 |
private:
|
|
93 |
SupportedFormatMap supportedFormats;
|
|
94 |
};
|
|
95 |
|
|
96 |
tst_QAbstractVideoSurface::tst_QAbstractVideoSurface()
|
|
97 |
{
|
|
98 |
}
|
|
99 |
|
|
100 |
tst_QAbstractVideoSurface::~tst_QAbstractVideoSurface()
|
|
101 |
{
|
|
102 |
}
|
|
103 |
|
|
104 |
void tst_QAbstractVideoSurface::initTestCase()
|
|
105 |
{
|
|
106 |
}
|
|
107 |
|
|
108 |
void tst_QAbstractVideoSurface::cleanupTestCase()
|
|
109 |
{
|
|
110 |
}
|
|
111 |
|
|
112 |
void tst_QAbstractVideoSurface::init()
|
|
113 |
{
|
|
114 |
}
|
|
115 |
|
|
116 |
void tst_QAbstractVideoSurface::cleanup()
|
|
117 |
{
|
|
118 |
}
|
|
119 |
|
|
120 |
void tst_QAbstractVideoSurface::setError()
|
|
121 |
{
|
|
122 |
qRegisterMetaType<QAbstractVideoSurface::Error>();
|
|
123 |
|
|
124 |
QtTestVideoSurface surface;
|
|
125 |
|
|
126 |
QCOMPARE(surface.error(), QAbstractVideoSurface::NoError);
|
|
127 |
|
|
128 |
surface.setError(QAbstractVideoSurface::StoppedError);
|
|
129 |
QCOMPARE(surface.error(), QAbstractVideoSurface::StoppedError);
|
|
130 |
|
|
131 |
surface.setError(QAbstractVideoSurface::ResourceError);
|
|
132 |
QCOMPARE(surface.error(), QAbstractVideoSurface::ResourceError);
|
|
133 |
|
|
134 |
surface.setError(QAbstractVideoSurface::NoError);
|
|
135 |
QCOMPARE(surface.error(), QAbstractVideoSurface::NoError);
|
|
136 |
}
|
|
137 |
|
|
138 |
void tst_QAbstractVideoSurface::isFormatSupported_data()
|
|
139 |
{
|
|
140 |
QTest::addColumn<SupportedFormatMap>("supportedFormats");
|
|
141 |
QTest::addColumn<QVideoSurfaceFormat>("format");
|
|
142 |
QTest::addColumn<bool>("supported");
|
|
143 |
|
|
144 |
SupportedFormatMap formats;
|
|
145 |
|
|
146 |
QTest::newRow("no formats: rgb32")
|
|
147 |
<< formats
|
|
148 |
<< QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_RGB32)
|
|
149 |
<< false;
|
|
150 |
QTest::newRow("no formats: yv12")
|
|
151 |
<< formats
|
|
152 |
<< QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_YV12)
|
|
153 |
<< false;
|
|
154 |
QTest::newRow("no formats: rgb32 gl")
|
|
155 |
<< formats
|
|
156 |
<< QVideoSurfaceFormat(
|
|
157 |
QSize(800, 600),
|
|
158 |
QVideoFrame::Format_RGB32,
|
|
159 |
QAbstractVideoBuffer::GLTextureHandle)
|
|
160 |
<< false;
|
|
161 |
QTest::newRow("no formats: rgb24 gl")
|
|
162 |
<< formats
|
|
163 |
<< QVideoSurfaceFormat(
|
|
164 |
QSize(800, 600),
|
|
165 |
QVideoFrame::Format_RGB24,
|
|
166 |
QAbstractVideoBuffer::GLTextureHandle)
|
|
167 |
<< false;
|
|
168 |
|
|
169 |
formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_RGB32);
|
|
170 |
formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_RGB24);
|
|
171 |
formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_YUV444);
|
|
172 |
formats.insertMulti(QAbstractVideoBuffer::GLTextureHandle, QVideoFrame::Format_RGB32);
|
|
173 |
|
|
174 |
QTest::newRow("supported: rgb32")
|
|
175 |
<< formats
|
|
176 |
<< QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_RGB32)
|
|
177 |
<< true;
|
|
178 |
QTest::newRow("supported: rgb24")
|
|
179 |
<< formats
|
|
180 |
<< QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_RGB24)
|
|
181 |
<< true;
|
|
182 |
QTest::newRow("unsupported: yv12")
|
|
183 |
<< formats
|
|
184 |
<< QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_YV12)
|
|
185 |
<< false;
|
|
186 |
QTest::newRow("supported: rgb32 gl")
|
|
187 |
<< formats
|
|
188 |
<< QVideoSurfaceFormat(
|
|
189 |
QSize(800, 600),
|
|
190 |
QVideoFrame::Format_RGB32,
|
|
191 |
QAbstractVideoBuffer::GLTextureHandle)
|
|
192 |
<< true;
|
|
193 |
QTest::newRow("unsupported: rgb24 gl")
|
|
194 |
<< formats
|
|
195 |
<< QVideoSurfaceFormat(
|
|
196 |
QSize(800, 600),
|
|
197 |
QVideoFrame::Format_RGB24,
|
|
198 |
QAbstractVideoBuffer::GLTextureHandle)
|
|
199 |
<< false;
|
|
200 |
QTest::newRow("unsupported: yv12 gl")
|
|
201 |
<< formats
|
|
202 |
<< QVideoSurfaceFormat(
|
|
203 |
QSize(800, 600),
|
|
204 |
QVideoFrame::Format_YV12,
|
|
205 |
QAbstractVideoBuffer::GLTextureHandle)
|
|
206 |
<< false;
|
|
207 |
|
|
208 |
formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_YV12);
|
|
209 |
formats.insertMulti(QAbstractVideoBuffer::GLTextureHandle, QVideoFrame::Format_RGB24);
|
|
210 |
|
|
211 |
QTest::newRow("supported: yv12")
|
|
212 |
<< formats
|
|
213 |
<< QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_YV12)
|
|
214 |
<< true;
|
|
215 |
QTest::newRow("supported: rgb24 gl")
|
|
216 |
<< formats
|
|
217 |
<< QVideoSurfaceFormat(
|
|
218 |
QSize(800, 600),
|
|
219 |
QVideoFrame::Format_RGB24,
|
|
220 |
QAbstractVideoBuffer::GLTextureHandle)
|
|
221 |
<< true;
|
|
222 |
}
|
|
223 |
|
|
224 |
void tst_QAbstractVideoSurface::isFormatSupported()
|
|
225 |
{
|
|
226 |
QFETCH(SupportedFormatMap, supportedFormats);
|
|
227 |
QFETCH(QVideoSurfaceFormat, format);
|
|
228 |
QFETCH(bool, supported);
|
|
229 |
|
|
230 |
QtTestVideoSurface surface(supportedFormats);
|
|
231 |
|
|
232 |
QCOMPARE(surface.isFormatSupported(format), supported);
|
|
233 |
}
|
|
234 |
|
|
235 |
void tst_QAbstractVideoSurface::start_data()
|
|
236 |
{
|
|
237 |
QTest::addColumn<QVideoSurfaceFormat>("format");
|
|
238 |
|
|
239 |
QTest::newRow("rgb32") << QVideoSurfaceFormat(
|
|
240 |
QSize(800, 600),
|
|
241 |
QVideoFrame::Format_RGB32);
|
|
242 |
QTest::newRow("yv12") << QVideoSurfaceFormat(
|
|
243 |
QSize(800, 600),
|
|
244 |
QVideoFrame::Format_YV12);
|
|
245 |
QTest::newRow("rgb32 gl") << QVideoSurfaceFormat(
|
|
246 |
QSize(800, 600),
|
|
247 |
QVideoFrame::Format_RGB32,
|
|
248 |
QAbstractVideoBuffer::GLTextureHandle);
|
|
249 |
}
|
|
250 |
|
|
251 |
void tst_QAbstractVideoSurface::start()
|
|
252 |
{
|
|
253 |
QFETCH(QVideoSurfaceFormat, format);
|
|
254 |
|
|
255 |
QtTestVideoSurface surface;
|
|
256 |
surface.setError(QAbstractVideoSurface::ResourceError);
|
|
257 |
|
|
258 |
QSignalSpy formatSpy(&surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat)));
|
|
259 |
QSignalSpy startedSpy(&surface, SIGNAL(startedChanged(bool)));
|
|
260 |
|
|
261 |
QVERIFY(!surface.isStarted());
|
|
262 |
QCOMPARE(surface.surfaceFormat(), QVideoSurfaceFormat());
|
|
263 |
|
|
264 |
QVERIFY(surface.start(format));
|
|
265 |
|
|
266 |
QVERIFY(surface.isStarted());
|
|
267 |
QCOMPARE(surface.surfaceFormat(), format);
|
|
268 |
|
|
269 |
QCOMPARE(formatSpy.count(), 1);
|
|
270 |
QCOMPARE(qvariant_cast<QVideoSurfaceFormat>(formatSpy.at(0).at(0)), format);
|
|
271 |
|
|
272 |
QCOMPARE(startedSpy.count(), 1);
|
|
273 |
QCOMPARE(startedSpy.at(0).at(0).toBool(), true);
|
|
274 |
|
|
275 |
// error() is reset on a successful start.
|
|
276 |
QCOMPARE(surface.error(), QAbstractVideoSurface::NoError);
|
|
277 |
|
|
278 |
surface.stop();
|
|
279 |
|
|
280 |
QVERIFY(!surface.isStarted());
|
|
281 |
QCOMPARE(surface.surfaceFormat(), QVideoSurfaceFormat());
|
|
282 |
|
|
283 |
QCOMPARE(formatSpy.count(), 2);
|
|
284 |
QCOMPARE(qvariant_cast<QVideoSurfaceFormat>(formatSpy.at(1).at(0)), QVideoSurfaceFormat());
|
|
285 |
|
|
286 |
QCOMPARE(startedSpy.count(), 2);
|
|
287 |
QCOMPARE(startedSpy.at(1).at(0).toBool(), false);
|
|
288 |
}
|
|
289 |
|
|
290 |
QTEST_MAIN(tst_QAbstractVideoSurface)
|
|
291 |
|
|
292 |
#include "tst_qabstractvideosurface.moc"
|