|
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/QVideoFrame> |
|
45 #include <QtGui/QImage> |
|
46 #include <QtCore/QPointer> |
|
47 |
|
48 class tst_QVideoFrame : public QObject |
|
49 { |
|
50 Q_OBJECT |
|
51 public: |
|
52 tst_QVideoFrame(); |
|
53 ~tst_QVideoFrame(); |
|
54 |
|
55 public slots: |
|
56 void initTestCase(); |
|
57 void cleanupTestCase(); |
|
58 void init(); |
|
59 void cleanup(); |
|
60 |
|
61 private slots: |
|
62 void create_data(); |
|
63 void create(); |
|
64 void createInvalid_data(); |
|
65 void createInvalid(); |
|
66 void createFromBuffer_data(); |
|
67 void createFromBuffer(); |
|
68 void createFromImage_data(); |
|
69 void createFromImage(); |
|
70 void createFromIncompatibleImage(); |
|
71 void createNull(); |
|
72 void destructor(); |
|
73 void copy_data(); |
|
74 void copy(); |
|
75 void assign_data(); |
|
76 void assign(); |
|
77 void map_data(); |
|
78 void map(); |
|
79 void mapImage_data(); |
|
80 void mapImage(); |
|
81 void imageDetach(); |
|
82 }; |
|
83 |
|
84 Q_DECLARE_METATYPE(QImage::Format) |
|
85 Q_DECLARE_METATYPE(QVideoFrame) |
|
86 |
|
87 class QtTestVideoBuffer : public QObject, public QAbstractVideoBuffer |
|
88 { |
|
89 Q_OBJECT |
|
90 public: |
|
91 QtTestVideoBuffer() |
|
92 : QAbstractVideoBuffer(NoHandle) {} |
|
93 explicit QtTestVideoBuffer(QAbstractVideoBuffer::HandleType type) |
|
94 : QAbstractVideoBuffer(type) {} |
|
95 |
|
96 MapMode mapMode() const { return NotMapped; } |
|
97 |
|
98 uchar *map(MapMode, int *, int *) { return 0; } |
|
99 void unmap() {} |
|
100 }; |
|
101 |
|
102 tst_QVideoFrame::tst_QVideoFrame() |
|
103 { |
|
104 } |
|
105 |
|
106 tst_QVideoFrame::~tst_QVideoFrame() |
|
107 { |
|
108 } |
|
109 |
|
110 void tst_QVideoFrame::initTestCase() |
|
111 { |
|
112 } |
|
113 |
|
114 void tst_QVideoFrame::cleanupTestCase() |
|
115 { |
|
116 } |
|
117 |
|
118 void tst_QVideoFrame::init() |
|
119 { |
|
120 } |
|
121 |
|
122 void tst_QVideoFrame::cleanup() |
|
123 { |
|
124 } |
|
125 |
|
126 void tst_QVideoFrame::create_data() |
|
127 { |
|
128 QTest::addColumn<QSize>("size"); |
|
129 QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); |
|
130 QTest::addColumn<int>("bytes"); |
|
131 QTest::addColumn<int>("bytesPerLine"); |
|
132 |
|
133 QTest::newRow("64x64 ARGB32") |
|
134 << QSize(64, 64) |
|
135 << QVideoFrame::Format_ARGB32 |
|
136 << 16384 |
|
137 << 256; |
|
138 QTest::newRow("32x256 YUV420P") |
|
139 << QSize(32, 256) |
|
140 << QVideoFrame::Format_YUV420P |
|
141 << 13288 |
|
142 << 32; |
|
143 } |
|
144 |
|
145 void tst_QVideoFrame::create() |
|
146 { |
|
147 QFETCH(QSize, size); |
|
148 QFETCH(QVideoFrame::PixelFormat, pixelFormat); |
|
149 QFETCH(int, bytes); |
|
150 QFETCH(int, bytesPerLine); |
|
151 |
|
152 QVideoFrame frame(bytes, size, bytesPerLine, pixelFormat); |
|
153 |
|
154 QVERIFY(frame.isValid()); |
|
155 QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); |
|
156 QCOMPARE(frame.pixelFormat(), pixelFormat); |
|
157 QCOMPARE(frame.size(), size); |
|
158 QCOMPARE(frame.width(), size.width()); |
|
159 QCOMPARE(frame.height(), size.height()); |
|
160 QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); |
|
161 QCOMPARE(frame.startTime(), qint64(-1)); |
|
162 QCOMPARE(frame.endTime(), qint64(-1)); |
|
163 } |
|
164 |
|
165 void tst_QVideoFrame::createInvalid_data() |
|
166 { |
|
167 QTest::addColumn<QSize>("size"); |
|
168 QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); |
|
169 QTest::addColumn<int>("bytes"); |
|
170 QTest::addColumn<int>("bytesPerLine"); |
|
171 |
|
172 QTest::newRow("64x64 ARGB32 0 size") |
|
173 << QSize(64, 64) |
|
174 << QVideoFrame::Format_ARGB32 |
|
175 << 0 |
|
176 << 45; |
|
177 QTest::newRow("32x256 YUV420P negative size") |
|
178 << QSize(32, 256) |
|
179 << QVideoFrame::Format_YUV420P |
|
180 << -13288 |
|
181 << 32; |
|
182 } |
|
183 |
|
184 void tst_QVideoFrame::createInvalid() |
|
185 { |
|
186 QFETCH(QSize, size); |
|
187 QFETCH(QVideoFrame::PixelFormat, pixelFormat); |
|
188 QFETCH(int, bytes); |
|
189 QFETCH(int, bytesPerLine); |
|
190 |
|
191 QVideoFrame frame(bytes, size, bytesPerLine, pixelFormat); |
|
192 |
|
193 QVERIFY(!frame.isValid()); |
|
194 QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); |
|
195 QCOMPARE(frame.pixelFormat(), pixelFormat); |
|
196 QCOMPARE(frame.size(), size); |
|
197 QCOMPARE(frame.width(), size.width()); |
|
198 QCOMPARE(frame.height(), size.height()); |
|
199 QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); |
|
200 QCOMPARE(frame.startTime(), qint64(-1)); |
|
201 QCOMPARE(frame.endTime(), qint64(-1)); |
|
202 } |
|
203 |
|
204 void tst_QVideoFrame::createFromBuffer_data() |
|
205 { |
|
206 QTest::addColumn<QAbstractVideoBuffer::HandleType>("handleType"); |
|
207 QTest::addColumn<QSize>("size"); |
|
208 QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); |
|
209 |
|
210 QTest::newRow("64x64 ARGB32 no handle") |
|
211 << QAbstractVideoBuffer::NoHandle |
|
212 << QSize(64, 64) |
|
213 << QVideoFrame::Format_ARGB32; |
|
214 QTest::newRow("64x64 ARGB32 gl handle") |
|
215 << QAbstractVideoBuffer::GLTextureHandle |
|
216 << QSize(64, 64) |
|
217 << QVideoFrame::Format_ARGB32; |
|
218 QTest::newRow("64x64 ARGB32 user handle") |
|
219 << QAbstractVideoBuffer::UserHandle |
|
220 << QSize(64, 64) |
|
221 << QVideoFrame::Format_ARGB32; |
|
222 } |
|
223 |
|
224 void tst_QVideoFrame::createFromBuffer() |
|
225 { |
|
226 QFETCH(QAbstractVideoBuffer::HandleType, handleType); |
|
227 QFETCH(QSize, size); |
|
228 QFETCH(QVideoFrame::PixelFormat, pixelFormat); |
|
229 |
|
230 QVideoFrame frame(new QtTestVideoBuffer(handleType), size, pixelFormat); |
|
231 |
|
232 QVERIFY(frame.isValid()); |
|
233 QCOMPARE(frame.handleType(), handleType); |
|
234 QCOMPARE(frame.pixelFormat(), pixelFormat); |
|
235 QCOMPARE(frame.size(), size); |
|
236 QCOMPARE(frame.width(), size.width()); |
|
237 QCOMPARE(frame.height(), size.height()); |
|
238 QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); |
|
239 QCOMPARE(frame.startTime(), qint64(-1)); |
|
240 QCOMPARE(frame.endTime(), qint64(-1)); |
|
241 } |
|
242 |
|
243 void tst_QVideoFrame::createFromImage_data() |
|
244 { |
|
245 QTest::addColumn<QSize>("size"); |
|
246 QTest::addColumn<QImage::Format>("imageFormat"); |
|
247 QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); |
|
248 |
|
249 QTest::newRow("64x64 RGB32") |
|
250 << QSize(64, 64) |
|
251 << QImage::Format_RGB32 |
|
252 << QVideoFrame::Format_RGB32; |
|
253 QTest::newRow("12x45 RGB16") |
|
254 << QSize(12, 45) |
|
255 << QImage::Format_RGB16 |
|
256 << QVideoFrame::Format_RGB565; |
|
257 QTest::newRow("19x46 ARGB32_Premultiplied") |
|
258 << QSize(19, 46) |
|
259 << QImage::Format_ARGB32_Premultiplied |
|
260 << QVideoFrame::Format_ARGB32_Premultiplied; |
|
261 } |
|
262 |
|
263 void tst_QVideoFrame::createFromImage() |
|
264 { |
|
265 QFETCH(QSize, size); |
|
266 QFETCH(QImage::Format, imageFormat); |
|
267 QFETCH(QVideoFrame::PixelFormat, pixelFormat); |
|
268 |
|
269 const QImage image(size.width(), size.height(), imageFormat); |
|
270 |
|
271 QVideoFrame frame(image); |
|
272 |
|
273 QVERIFY(frame.isValid()); |
|
274 QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); |
|
275 QCOMPARE(frame.pixelFormat(), pixelFormat); |
|
276 QCOMPARE(frame.size(), size); |
|
277 QCOMPARE(frame.width(), size.width()); |
|
278 QCOMPARE(frame.height(), size.height()); |
|
279 QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); |
|
280 QCOMPARE(frame.startTime(), qint64(-1)); |
|
281 QCOMPARE(frame.endTime(), qint64(-1)); |
|
282 } |
|
283 |
|
284 void tst_QVideoFrame::createFromIncompatibleImage() |
|
285 { |
|
286 const QImage image(64, 64, QImage::Format_Mono); |
|
287 |
|
288 QVideoFrame frame(image); |
|
289 |
|
290 QVERIFY(!frame.isValid()); |
|
291 QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); |
|
292 QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_Invalid); |
|
293 QCOMPARE(frame.size(), QSize(64, 64)); |
|
294 QCOMPARE(frame.width(), 64); |
|
295 QCOMPARE(frame.height(), 64); |
|
296 QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); |
|
297 QCOMPARE(frame.startTime(), qint64(-1)); |
|
298 QCOMPARE(frame.endTime(), qint64(-1)); |
|
299 } |
|
300 |
|
301 void tst_QVideoFrame::createNull() |
|
302 { |
|
303 QVideoFrame frame; |
|
304 |
|
305 QVERIFY(!frame.isValid()); |
|
306 QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); |
|
307 QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_Invalid); |
|
308 QCOMPARE(frame.size(), QSize()); |
|
309 QCOMPARE(frame.width(), -1); |
|
310 QCOMPARE(frame.height(), -1); |
|
311 QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); |
|
312 QCOMPARE(frame.startTime(), qint64(-1)); |
|
313 QCOMPARE(frame.endTime(), qint64(-1)); |
|
314 } |
|
315 |
|
316 void tst_QVideoFrame::destructor() |
|
317 { |
|
318 QPointer<QtTestVideoBuffer> buffer = new QtTestVideoBuffer; |
|
319 |
|
320 { |
|
321 QVideoFrame frame(buffer, QSize(4, 1), QVideoFrame::Format_ARGB32); |
|
322 } |
|
323 |
|
324 QVERIFY(buffer.isNull()); |
|
325 } |
|
326 |
|
327 void tst_QVideoFrame::copy_data() |
|
328 { |
|
329 QTest::addColumn<QAbstractVideoBuffer::HandleType>("handleType"); |
|
330 QTest::addColumn<QSize>("size"); |
|
331 QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); |
|
332 QTest::addColumn<QVideoFrame::FieldType>("fieldType"); |
|
333 QTest::addColumn<qint64>("startTime"); |
|
334 QTest::addColumn<qint64>("endTime"); |
|
335 |
|
336 QTest::newRow("64x64 ARGB32") |
|
337 << QAbstractVideoBuffer::GLTextureHandle |
|
338 << QSize(64, 64) |
|
339 << QVideoFrame::Format_ARGB32 |
|
340 << QVideoFrame::TopField |
|
341 << qint64(63641740) |
|
342 << qint64(63641954); |
|
343 QTest::newRow("32x256 YUV420P") |
|
344 << QAbstractVideoBuffer::UserHandle |
|
345 << QSize(32, 256) |
|
346 << QVideoFrame::Format_YUV420P |
|
347 << QVideoFrame::InterlacedFrame |
|
348 << qint64(12345) |
|
349 << qint64(12389); |
|
350 } |
|
351 |
|
352 void tst_QVideoFrame::copy() |
|
353 { |
|
354 QFETCH(QAbstractVideoBuffer::HandleType, handleType); |
|
355 QFETCH(QSize, size); |
|
356 QFETCH(QVideoFrame::PixelFormat, pixelFormat); |
|
357 QFETCH(QVideoFrame::FieldType, fieldType); |
|
358 QFETCH(qint64, startTime); |
|
359 QFETCH(qint64, endTime); |
|
360 |
|
361 QPointer<QtTestVideoBuffer> buffer = new QtTestVideoBuffer(handleType); |
|
362 |
|
363 { |
|
364 QVideoFrame frame(buffer, size, pixelFormat); |
|
365 frame.setFieldType(QVideoFrame::FieldType(fieldType)); |
|
366 frame.setStartTime(startTime); |
|
367 frame.setEndTime(endTime); |
|
368 |
|
369 QVERIFY(frame.isValid()); |
|
370 QCOMPARE(frame.handleType(), handleType); |
|
371 QCOMPARE(frame.pixelFormat(), pixelFormat); |
|
372 QCOMPARE(frame.size(), size); |
|
373 QCOMPARE(frame.width(), size.width()); |
|
374 QCOMPARE(frame.height(), size.height()); |
|
375 QCOMPARE(frame.fieldType(), fieldType); |
|
376 QCOMPARE(frame.startTime(), startTime); |
|
377 QCOMPARE(frame.endTime(), endTime); |
|
378 |
|
379 { |
|
380 QVideoFrame otherFrame(frame); |
|
381 |
|
382 QVERIFY(!buffer.isNull()); |
|
383 |
|
384 QVERIFY(otherFrame.isValid()); |
|
385 QCOMPARE(otherFrame.handleType(), handleType); |
|
386 QCOMPARE(otherFrame.pixelFormat(), pixelFormat); |
|
387 QCOMPARE(otherFrame.size(), size); |
|
388 QCOMPARE(otherFrame.width(), size.width()); |
|
389 QCOMPARE(otherFrame.height(), size.height()); |
|
390 QCOMPARE(otherFrame.fieldType(), fieldType); |
|
391 QCOMPARE(otherFrame.startTime(), startTime); |
|
392 QCOMPARE(otherFrame.endTime(), endTime); |
|
393 |
|
394 otherFrame.setEndTime(-1); |
|
395 |
|
396 QVERIFY(!buffer.isNull()); |
|
397 |
|
398 QVERIFY(otherFrame.isValid()); |
|
399 QCOMPARE(otherFrame.handleType(), handleType); |
|
400 QCOMPARE(otherFrame.pixelFormat(), pixelFormat); |
|
401 QCOMPARE(otherFrame.size(), size); |
|
402 QCOMPARE(otherFrame.width(), size.width()); |
|
403 QCOMPARE(otherFrame.height(), size.height()); |
|
404 QCOMPARE(otherFrame.fieldType(), fieldType); |
|
405 QCOMPARE(otherFrame.startTime(), startTime); |
|
406 QCOMPARE(otherFrame.endTime(), qint64(-1)); |
|
407 } |
|
408 |
|
409 QVERIFY(!buffer.isNull()); |
|
410 |
|
411 QVERIFY(frame.isValid()); |
|
412 QCOMPARE(frame.handleType(), handleType); |
|
413 QCOMPARE(frame.pixelFormat(), pixelFormat); |
|
414 QCOMPARE(frame.size(), size); |
|
415 QCOMPARE(frame.width(), size.width()); |
|
416 QCOMPARE(frame.height(), size.height()); |
|
417 QCOMPARE(frame.fieldType(), fieldType); |
|
418 QCOMPARE(frame.startTime(), startTime); |
|
419 QCOMPARE(frame.endTime(), qint64(-1)); // Explicitly shared. |
|
420 } |
|
421 |
|
422 QVERIFY(buffer.isNull()); |
|
423 } |
|
424 |
|
425 void tst_QVideoFrame::assign_data() |
|
426 { |
|
427 QTest::addColumn<QAbstractVideoBuffer::HandleType>("handleType"); |
|
428 QTest::addColumn<QSize>("size"); |
|
429 QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); |
|
430 QTest::addColumn<QVideoFrame::FieldType>("fieldType"); |
|
431 QTest::addColumn<qint64>("startTime"); |
|
432 QTest::addColumn<qint64>("endTime"); |
|
433 |
|
434 QTest::newRow("64x64 ARGB32") |
|
435 << QAbstractVideoBuffer::GLTextureHandle |
|
436 << QSize(64, 64) |
|
437 << QVideoFrame::Format_ARGB32 |
|
438 << QVideoFrame::TopField |
|
439 << qint64(63641740) |
|
440 << qint64(63641954); |
|
441 QTest::newRow("32x256 YUV420P") |
|
442 << QAbstractVideoBuffer::UserHandle |
|
443 << QSize(32, 256) |
|
444 << QVideoFrame::Format_YUV420P |
|
445 << QVideoFrame::InterlacedFrame |
|
446 << qint64(12345) |
|
447 << qint64(12389); |
|
448 } |
|
449 |
|
450 void tst_QVideoFrame::assign() |
|
451 { |
|
452 QFETCH(QAbstractVideoBuffer::HandleType, handleType); |
|
453 QFETCH(QSize, size); |
|
454 QFETCH(QVideoFrame::PixelFormat, pixelFormat); |
|
455 QFETCH(QVideoFrame::FieldType, fieldType); |
|
456 QFETCH(qint64, startTime); |
|
457 QFETCH(qint64, endTime); |
|
458 |
|
459 QPointer<QtTestVideoBuffer> buffer = new QtTestVideoBuffer(handleType); |
|
460 |
|
461 QVideoFrame frame; |
|
462 { |
|
463 QVideoFrame otherFrame(buffer, size, pixelFormat); |
|
464 otherFrame.setFieldType(fieldType); |
|
465 otherFrame.setStartTime(startTime); |
|
466 otherFrame.setEndTime(endTime); |
|
467 |
|
468 frame = otherFrame; |
|
469 |
|
470 QVERIFY(!buffer.isNull()); |
|
471 |
|
472 QVERIFY(otherFrame.isValid()); |
|
473 QCOMPARE(otherFrame.handleType(), handleType); |
|
474 QCOMPARE(otherFrame.pixelFormat(), pixelFormat); |
|
475 QCOMPARE(otherFrame.size(), size); |
|
476 QCOMPARE(otherFrame.width(), size.width()); |
|
477 QCOMPARE(otherFrame.height(), size.height()); |
|
478 QCOMPARE(otherFrame.fieldType(), fieldType); |
|
479 QCOMPARE(otherFrame.startTime(), startTime); |
|
480 QCOMPARE(otherFrame.endTime(), endTime); |
|
481 |
|
482 otherFrame.setStartTime(-1); |
|
483 |
|
484 QVERIFY(!buffer.isNull()); |
|
485 |
|
486 QVERIFY(otherFrame.isValid()); |
|
487 QCOMPARE(otherFrame.handleType(), handleType); |
|
488 QCOMPARE(otherFrame.pixelFormat(), pixelFormat); |
|
489 QCOMPARE(otherFrame.size(), size); |
|
490 QCOMPARE(otherFrame.width(), size.width()); |
|
491 QCOMPARE(otherFrame.height(), size.height()); |
|
492 QCOMPARE(otherFrame.fieldType(), fieldType); |
|
493 QCOMPARE(otherFrame.startTime(), qint64(-1)); |
|
494 QCOMPARE(otherFrame.endTime(), endTime); |
|
495 } |
|
496 |
|
497 QVERIFY(!buffer.isNull()); |
|
498 |
|
499 QVERIFY(frame.isValid()); |
|
500 QCOMPARE(frame.handleType(), handleType); |
|
501 QCOMPARE(frame.pixelFormat(), pixelFormat); |
|
502 QCOMPARE(frame.size(), size); |
|
503 QCOMPARE(frame.width(), size.width()); |
|
504 QCOMPARE(frame.height(), size.height()); |
|
505 QCOMPARE(frame.fieldType(), fieldType); |
|
506 QCOMPARE(frame.startTime(), qint64(-1)); |
|
507 QCOMPARE(frame.endTime(), endTime); |
|
508 |
|
509 frame = QVideoFrame(); |
|
510 |
|
511 QVERIFY(buffer.isNull()); |
|
512 |
|
513 QVERIFY(!frame.isValid()); |
|
514 QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); |
|
515 QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_Invalid); |
|
516 QCOMPARE(frame.size(), QSize()); |
|
517 QCOMPARE(frame.width(), -1); |
|
518 QCOMPARE(frame.height(), -1); |
|
519 QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); |
|
520 QCOMPARE(frame.startTime(), qint64(-1)); |
|
521 QCOMPARE(frame.endTime(), qint64(-1)); |
|
522 } |
|
523 |
|
524 void tst_QVideoFrame::map_data() |
|
525 { |
|
526 QTest::addColumn<QSize>("size"); |
|
527 QTest::addColumn<int>("numBytes"); |
|
528 QTest::addColumn<int>("bytesPerLine"); |
|
529 QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); |
|
530 QTest::addColumn<QAbstractVideoBuffer::MapMode>("mode"); |
|
531 |
|
532 QTest::newRow("read-only") |
|
533 << QSize(64, 64) |
|
534 << 16384 |
|
535 << 256 |
|
536 << QVideoFrame::Format_ARGB32 |
|
537 << QAbstractVideoBuffer::ReadOnly; |
|
538 |
|
539 QTest::newRow("write-only") |
|
540 << QSize(64, 64) |
|
541 << 16384 |
|
542 << 256 |
|
543 << QVideoFrame::Format_ARGB32 |
|
544 << QAbstractVideoBuffer::WriteOnly; |
|
545 |
|
546 QTest::newRow("read-write") |
|
547 << QSize(64, 64) |
|
548 << 16384 |
|
549 << 256 |
|
550 << QVideoFrame::Format_ARGB32 |
|
551 << QAbstractVideoBuffer::ReadWrite; |
|
552 } |
|
553 |
|
554 void tst_QVideoFrame::map() |
|
555 { |
|
556 QFETCH(QSize, size); |
|
557 QFETCH(int, numBytes); |
|
558 QFETCH(int, bytesPerLine); |
|
559 QFETCH(QVideoFrame::PixelFormat, pixelFormat); |
|
560 QFETCH(QAbstractVideoBuffer::MapMode, mode); |
|
561 |
|
562 QVideoFrame frame(numBytes, size, bytesPerLine, pixelFormat); |
|
563 |
|
564 QVERIFY(!frame.bits()); |
|
565 QCOMPARE(frame.numBytes(), 0); |
|
566 QCOMPARE(frame.bytesPerLine(), 0); |
|
567 QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); |
|
568 |
|
569 QVERIFY(frame.map(mode)); |
|
570 |
|
571 QVERIFY(frame.bits()); |
|
572 QCOMPARE(frame.numBytes(), numBytes); |
|
573 QCOMPARE(frame.bytesPerLine(), bytesPerLine); |
|
574 QCOMPARE(frame.mapMode(), mode); |
|
575 |
|
576 frame.unmap(); |
|
577 |
|
578 QVERIFY(!frame.bits()); |
|
579 QCOMPARE(frame.numBytes(), 0); |
|
580 QCOMPARE(frame.bytesPerLine(), 0); |
|
581 QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); |
|
582 } |
|
583 |
|
584 void tst_QVideoFrame::mapImage_data() |
|
585 { |
|
586 QTest::addColumn<QSize>("size"); |
|
587 QTest::addColumn<QImage::Format>("format"); |
|
588 QTest::addColumn<QAbstractVideoBuffer::MapMode>("mode"); |
|
589 |
|
590 QTest::newRow("read-only") |
|
591 << QSize(64, 64) |
|
592 << QImage::Format_ARGB32 |
|
593 << QAbstractVideoBuffer::ReadOnly; |
|
594 |
|
595 QTest::newRow("write-only") |
|
596 << QSize(15, 106) |
|
597 << QImage::Format_RGB32 |
|
598 << QAbstractVideoBuffer::WriteOnly; |
|
599 |
|
600 QTest::newRow("read-write") |
|
601 << QSize(23, 111) |
|
602 << QImage::Format_RGB16 |
|
603 << QAbstractVideoBuffer::ReadWrite; |
|
604 } |
|
605 |
|
606 void tst_QVideoFrame::mapImage() |
|
607 { |
|
608 QFETCH(QSize, size); |
|
609 QFETCH(QImage::Format, format); |
|
610 QFETCH(QAbstractVideoBuffer::MapMode, mode); |
|
611 |
|
612 QImage image(size.width(), size.height(), format); |
|
613 |
|
614 QVideoFrame frame(image); |
|
615 |
|
616 QVERIFY(!frame.bits()); |
|
617 QCOMPARE(frame.numBytes(), 0); |
|
618 QCOMPARE(frame.bytesPerLine(), 0); |
|
619 QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); |
|
620 |
|
621 QVERIFY(frame.map(mode)); |
|
622 |
|
623 QVERIFY(frame.bits()); |
|
624 QCOMPARE(frame.numBytes(), image.numBytes()); |
|
625 QCOMPARE(frame.bytesPerLine(), image.bytesPerLine()); |
|
626 QCOMPARE(frame.mapMode(), mode); |
|
627 |
|
628 frame.unmap(); |
|
629 |
|
630 QVERIFY(!frame.bits()); |
|
631 QCOMPARE(frame.numBytes(), 0); |
|
632 QCOMPARE(frame.bytesPerLine(), 0); |
|
633 QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); |
|
634 } |
|
635 |
|
636 void tst_QVideoFrame::imageDetach() |
|
637 { |
|
638 const uint red = qRgb(255, 0, 0); |
|
639 const uint blue = qRgb(0, 0, 255); |
|
640 |
|
641 QImage image(8, 8, QImage::Format_RGB32); |
|
642 |
|
643 image.fill(red); |
|
644 QCOMPARE(image.pixel(4, 4), red); |
|
645 |
|
646 QVideoFrame frame(image); |
|
647 |
|
648 QVERIFY(frame.map(QAbstractVideoBuffer::ReadWrite)); |
|
649 |
|
650 QImage frameImage(frame.bits(), 8, 8, frame.bytesPerLine(), QImage::Format_RGB32); |
|
651 |
|
652 QCOMPARE(frameImage.pixel(4, 4), red); |
|
653 |
|
654 frameImage.fill(blue); |
|
655 QCOMPARE(frameImage.pixel(4, 4), blue); |
|
656 |
|
657 // Original image has detached and is therefore unchanged. |
|
658 QCOMPARE(image.pixel(4, 4), red); |
|
659 } |
|
660 |
|
661 QTEST_MAIN(tst_QVideoFrame) |
|
662 |
|
663 #include "tst_qvideoframe.moc" |