43 #include "qgraphicsvideoitem.h" |
43 #include "qgraphicsvideoitem.h" |
44 #include <QtTest/QtTest> |
44 #include <QtTest/QtTest> |
45 #include "qmediaobject.h" |
45 #include "qmediaobject.h" |
46 #include "qmediaservice.h" |
46 #include "qmediaservice.h" |
47 #include "qpaintervideosurface_p.h" |
47 #include "qpaintervideosurface_p.h" |
48 #include "qvideooutputcontrol.h" |
|
49 #include "qvideorenderercontrol.h" |
48 #include "qvideorenderercontrol.h" |
50 |
49 |
51 #include <QtMultimedia/qabstractvideosurface.h> |
50 #include <qabstractvideosurface.h> |
52 #include <QtMultimedia/qvideosurfaceformat.h> |
51 #include <qvideosurfaceformat.h> |
53 |
52 |
54 #include <QtGui/qapplication.h> |
53 #include <QtGui/qapplication.h> |
55 #include <QtGui/qgraphicsscene.h> |
54 #include <QtGui/qgraphicsscene.h> |
56 #include <QtGui/qgraphicsview.h> |
55 #include <QtGui/qgraphicsview.h> |
57 |
56 |
86 }; |
84 }; |
87 |
85 |
88 Q_DECLARE_METATYPE(const uchar *) |
86 Q_DECLARE_METATYPE(const uchar *) |
89 Q_DECLARE_METATYPE(Qt::AspectRatioMode) |
87 Q_DECLARE_METATYPE(Qt::AspectRatioMode) |
90 |
88 |
91 class QtTestOutputControl : public QVideoOutputControl |
|
92 { |
|
93 public: |
|
94 QtTestOutputControl() : m_output(NoOutput) {} |
|
95 |
|
96 QList<Output> availableOutputs() const { return m_outputs; } |
|
97 void setAvailableOutputs(const QList<Output> outputs) { m_outputs = outputs; } |
|
98 |
|
99 Output output() const { return m_output; } |
|
100 virtual void setOutput(Output output) { m_output = output; } |
|
101 |
|
102 private: |
|
103 Output m_output; |
|
104 QList<Output> m_outputs; |
|
105 }; |
|
106 |
|
107 class QtTestRendererControl : public QVideoRendererControl |
89 class QtTestRendererControl : public QVideoRendererControl |
108 { |
90 { |
109 public: |
91 public: |
110 QtTestRendererControl() |
92 QtTestRendererControl() |
111 : m_surface(0) |
93 : m_surface(0) |
122 class QtTestVideoService : public QMediaService |
104 class QtTestVideoService : public QMediaService |
123 { |
105 { |
124 Q_OBJECT |
106 Q_OBJECT |
125 public: |
107 public: |
126 QtTestVideoService( |
108 QtTestVideoService( |
127 QtTestOutputControl *output, |
|
128 QtTestRendererControl *renderer) |
109 QtTestRendererControl *renderer) |
129 : QMediaService(0) |
110 : QMediaService(0) |
130 , outputControl(output) |
111 , rendererRef(0) |
131 , rendererControl(renderer) |
112 , rendererControl(renderer) |
132 { |
113 { |
133 } |
114 } |
134 |
115 |
135 ~QtTestVideoService() |
116 ~QtTestVideoService() |
136 { |
117 { |
137 delete outputControl; |
|
138 delete rendererControl; |
118 delete rendererControl; |
139 } |
119 } |
140 |
120 |
141 QMediaControl *control(const char *name) const |
121 QMediaControl *requestControl(const char *name) |
142 { |
122 { |
143 if (qstrcmp(name, QVideoOutputControl_iid) == 0) |
123 if (qstrcmp(name, QVideoRendererControl_iid) == 0 && rendererControl) { |
144 return outputControl; |
124 rendererRef += 1; |
145 else if (qstrcmp(name, QVideoRendererControl_iid) == 0) |
125 |
146 return rendererControl; |
126 return rendererControl; |
147 else |
127 } else { |
148 return 0; |
128 return 0; |
149 } |
129 } |
150 |
130 } |
151 QtTestOutputControl *outputControl; |
131 |
|
132 void releaseControl(QMediaControl *control) |
|
133 { |
|
134 Q_ASSERT(control); |
|
135 |
|
136 if (control == rendererControl) |
|
137 rendererRef -= 1; |
|
138 } |
|
139 |
|
140 int rendererRef; |
152 QtTestRendererControl *rendererControl; |
141 QtTestRendererControl *rendererControl; |
153 }; |
142 }; |
154 |
143 |
155 class QtTestVideoObject : public QMediaObject |
144 class QtTestVideoObject : public QMediaObject |
156 { |
145 { |
157 Q_OBJECT |
146 Q_OBJECT |
158 public: |
147 public: |
159 QtTestVideoObject(QtTestRendererControl *renderer): |
148 QtTestVideoObject(QtTestRendererControl *renderer) |
160 QMediaObject(0, new QtTestVideoService(new QtTestOutputControl, renderer)) |
149 : QMediaObject(0, new QtTestVideoService(renderer)) |
161 { |
150 { |
162 testService = qobject_cast<QtTestVideoService*>(service()); |
151 testService = qobject_cast<QtTestVideoService*>(service()); |
163 QList<QVideoOutputControl::Output> outputs; |
|
164 |
|
165 if (renderer) |
|
166 outputs.append(QVideoOutputControl::RendererOutput); |
|
167 |
|
168 testService->outputControl->setAvailableOutputs(outputs); |
|
169 } |
152 } |
170 |
153 |
171 QtTestVideoObject(QtTestVideoService *service): |
154 QtTestVideoObject(QtTestVideoService *service): |
172 QMediaObject(0, service), |
155 QMediaObject(0, service), |
173 testService(service) |
156 testService(service) |
248 graphicsScene.addItem(item); |
231 graphicsScene.addItem(item); |
249 QGraphicsView graphicsView(&graphicsScene); |
232 QGraphicsView graphicsView(&graphicsScene); |
250 graphicsView.show(); |
233 graphicsView.show(); |
251 } |
234 } |
252 |
235 |
253 void tst_QGraphicsVideoItem::nullOutputControl() |
236 void tst_QGraphicsVideoItem::noOutputs() |
254 { |
237 { |
255 QtTestVideoObject object(new QtTestVideoService(0, 0)); |
238 QtTestRendererControl *control = 0; |
|
239 QtTestVideoObject object(control); |
256 |
240 |
257 QtTestGraphicsVideoItem *item = new QtTestGraphicsVideoItem; |
241 QtTestGraphicsVideoItem *item = new QtTestGraphicsVideoItem; |
258 item->setMediaObject(&object); |
242 object.bind(item); |
259 |
243 |
260 QVERIFY(item->boundingRect().isEmpty()); |
244 QVERIFY(item->boundingRect().isEmpty()); |
261 |
245 |
262 item->hide(); |
246 item->hide(); |
263 item->show(); |
247 item->show(); |
266 graphicsScene.addItem(item); |
250 graphicsScene.addItem(item); |
267 QGraphicsView graphicsView(&graphicsScene); |
251 QGraphicsView graphicsView(&graphicsScene); |
268 graphicsView.show(); |
252 graphicsView.show(); |
269 } |
253 } |
270 |
254 |
271 void tst_QGraphicsVideoItem::noOutputs() |
|
272 { |
|
273 QtTestRendererControl *control = 0; |
|
274 QtTestVideoObject object(control); |
|
275 |
|
276 QtTestGraphicsVideoItem *item = new QtTestGraphicsVideoItem; |
|
277 item->setMediaObject(&object); |
|
278 |
|
279 QVERIFY(item->boundingRect().isEmpty()); |
|
280 |
|
281 item->hide(); |
|
282 QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput); |
|
283 item->show(); |
|
284 QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput); |
|
285 |
|
286 QGraphicsScene graphicsScene; |
|
287 graphicsScene.addItem(item); |
|
288 QGraphicsView graphicsView(&graphicsScene); |
|
289 graphicsView.show(); |
|
290 } |
|
291 |
|
292 void tst_QGraphicsVideoItem::serviceDestroyed() |
255 void tst_QGraphicsVideoItem::serviceDestroyed() |
293 { |
256 { |
294 QtTestVideoObject object(new QtTestRendererControl); |
257 QtTestVideoObject object(new QtTestRendererControl); |
295 |
258 |
296 QGraphicsVideoItem item; |
259 QGraphicsVideoItem item; |
297 item.setMediaObject(&object); |
260 object.bind(&item); |
|
261 |
|
262 QCOMPARE(object.testService->rendererRef, 1); |
298 |
263 |
299 QtTestVideoService *service = object.testService; |
264 QtTestVideoService *service = object.testService; |
300 object.testService = 0; |
265 object.testService = 0; |
301 |
266 |
302 delete service; |
267 delete service; |
303 |
268 |
304 QCOMPARE(item.mediaObject(), static_cast<QMediaObject *>(&object)); |
269 QCOMPARE(item.mediaObject(), static_cast<QMediaObject *>(&object)); |
305 QVERIFY(item.boundingRect().isEmpty()); |
270 QVERIFY(item.boundingRect().isEmpty()); |
306 } |
271 } |
307 |
272 |
308 void tst_QGraphicsVideoItem::mediaObjectDestroyed() |
273 void tst_QGraphicsVideoItem::mediaObjectDestroyed() |
309 { |
274 { |
310 QtTestVideoObject *object = new QtTestVideoObject(new QtTestRendererControl); |
275 QtTestVideoObject *object = new QtTestVideoObject(new QtTestRendererControl); |
311 |
276 |
312 QGraphicsVideoItem item; |
277 QGraphicsVideoItem item; |
313 item.setMediaObject(object); |
278 object->bind(&item); |
|
279 |
|
280 QCOMPARE(object->testService->rendererRef, 1); |
314 |
281 |
315 delete object; |
282 delete object; |
316 object = 0; |
283 object = 0; |
317 |
284 |
318 QCOMPARE(item.mediaObject(), static_cast<QMediaObject *>(object)); |
285 QCOMPARE(item.mediaObject(), static_cast<QMediaObject *>(object)); |
325 QtTestVideoObject object(new QtTestRendererControl); |
292 QtTestVideoObject object(new QtTestRendererControl); |
326 |
293 |
327 QGraphicsVideoItem item; |
294 QGraphicsVideoItem item; |
328 |
295 |
329 QCOMPARE(item.mediaObject(), nullObject); |
296 QCOMPARE(item.mediaObject(), nullObject); |
330 QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput); |
297 QCOMPARE(object.testService->rendererRef, 0); |
331 |
298 |
332 item.setMediaObject(&object); |
299 object.bind(&item); |
333 QCOMPARE(item.mediaObject(), static_cast<QMediaObject *>(&object)); |
300 QCOMPARE(item.mediaObject(), static_cast<QMediaObject *>(&object)); |
334 QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::RendererOutput); |
301 QCOMPARE(object.testService->rendererRef, 1); |
335 QVERIFY(object.testService->rendererControl->surface() != 0); |
302 QVERIFY(object.testService->rendererControl->surface() != 0); |
336 |
303 |
337 item.setMediaObject(0); |
304 object.unbind(&item); |
338 QCOMPARE(item.mediaObject(), nullObject); |
305 QCOMPARE(item.mediaObject(), nullObject); |
339 |
306 |
340 QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput); |
307 QCOMPARE(object.testService->rendererRef, 0); |
341 |
308 |
342 item.setVisible(false); |
309 item.setVisible(false); |
343 |
310 |
344 item.setMediaObject(&object); |
311 object.bind(&item); |
345 QCOMPARE(item.mediaObject(), static_cast<QMediaObject *>(&object)); |
312 QCOMPARE(item.mediaObject(), static_cast<QMediaObject *>(&object)); |
346 QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput); |
313 QCOMPARE(object.testService->rendererRef, 1); |
347 QVERIFY(object.testService->rendererControl->surface() != 0); |
314 QVERIFY(object.testService->rendererControl->surface() != 0); |
348 } |
315 } |
349 |
316 |
350 void tst_QGraphicsVideoItem::show() |
317 void tst_QGraphicsVideoItem::show() |
351 { |
318 { |
352 QtTestVideoObject object(new QtTestRendererControl); |
319 QtTestVideoObject object(new QtTestRendererControl); |
353 QtTestGraphicsVideoItem *item = new QtTestGraphicsVideoItem; |
320 QtTestGraphicsVideoItem *item = new QtTestGraphicsVideoItem; |
354 item->setMediaObject(&object); |
321 object.bind(item); |
355 |
322 |
356 // Graphics items are visible by default |
323 // Graphics items are visible by default |
357 QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::RendererOutput); |
324 QCOMPARE(object.testService->rendererRef, 1); |
358 QVERIFY(object.testService->rendererControl->surface() != 0); |
325 QVERIFY(object.testService->rendererControl->surface() != 0); |
359 |
326 |
360 item->hide(); |
327 item->hide(); |
361 QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::RendererOutput); |
328 QCOMPARE(object.testService->rendererRef, 1); |
362 |
329 |
363 item->show(); |
330 item->show(); |
364 QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::RendererOutput); |
331 QCOMPARE(object.testService->rendererRef, 1); |
365 QVERIFY(object.testService->rendererControl->surface() != 0); |
332 QVERIFY(object.testService->rendererControl->surface() != 0); |
366 |
333 |
367 QVERIFY(item->boundingRect().isEmpty()); |
334 QVERIFY(item->boundingRect().isEmpty()); |
368 |
335 |
369 QVideoSurfaceFormat format(QSize(320,240),QVideoFrame::Format_RGB32); |
336 QVideoSurfaceFormat format(QSize(320,240),QVideoFrame::Format_RGB32); |
469 QFETCH(QSize, pixelAspectRatio); |
436 QFETCH(QSize, pixelAspectRatio); |
470 QFETCH(QSizeF, nativeSize); |
437 QFETCH(QSizeF, nativeSize); |
471 |
438 |
472 QtTestVideoObject object(new QtTestRendererControl); |
439 QtTestVideoObject object(new QtTestRendererControl); |
473 QGraphicsVideoItem item; |
440 QGraphicsVideoItem item; |
474 item.setMediaObject(&object); |
441 object.bind(&item); |
475 |
442 |
476 QCOMPARE(item.nativeSize(), QSizeF()); |
443 QCOMPARE(item.nativeSize(), QSizeF()); |
477 |
444 |
478 QSignalSpy spy(&item, SIGNAL(nativeSizeChanged(QSizeF))); |
445 QSignalSpy spy(&item, SIGNAL(nativeSizeChanged(QSizeF))); |
479 |
446 |
603 QFETCH(Qt::AspectRatioMode, aspectRatioMode); |
570 QFETCH(Qt::AspectRatioMode, aspectRatioMode); |
604 QFETCH(QRectF, expectedRect); |
571 QFETCH(QRectF, expectedRect); |
605 |
572 |
606 QtTestVideoObject object(new QtTestRendererControl); |
573 QtTestVideoObject object(new QtTestRendererControl); |
607 QGraphicsVideoItem item; |
574 QGraphicsVideoItem item; |
608 item.setMediaObject(&object); |
575 object.bind(&item); |
609 |
576 |
610 item.setOffset(offset); |
577 item.setOffset(offset); |
611 item.setSize(size); |
578 item.setSize(size); |
612 item.setAspectRatioMode(aspectRatioMode); |
579 item.setAspectRatioMode(aspectRatioMode); |
613 |
580 |