1/****************************************************************************
2**
3** Copyright (C) 2016 Research In Motion
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qdeclarativevideooutput_window_p.h"
41#include "qdeclarativevideooutput_p.h"
42#include <QtQuick/qquickwindow.h>
43#include <QtMultimedia/qmediaservice.h>
44#include <QtMultimedia/qvideowindowcontrol.h>
45
46QT_BEGIN_NAMESPACE
47
48QDeclarativeVideoWindowBackend::QDeclarativeVideoWindowBackend(QDeclarativeVideoOutput *parent)
49 : QDeclarativeVideoBackend(parent),
50 m_visible(true)
51{
52}
53
54QDeclarativeVideoWindowBackend::~QDeclarativeVideoWindowBackend()
55{
56 releaseSource();
57 releaseControl();
58}
59
60bool QDeclarativeVideoWindowBackend::init(QMediaService *service)
61{
62 if (QMediaControl *control = service->requestControl(QVideoWindowControl_iid)) {
63 if ((m_videoWindowControl = qobject_cast<QVideoWindowControl *>(object: control))) {
64 if (q->window())
65 m_videoWindowControl->setWinId(q->window()->winId());
66 m_service = service;
67 QObject::connect(sender: m_videoWindowControl.data(), SIGNAL(nativeSizeChanged()),
68 receiver: q, SLOT(_q_updateNativeSize()));
69 return true;
70 }
71 }
72 return false;
73}
74
75void QDeclarativeVideoWindowBackend::itemChange(QQuickItem::ItemChange change,
76 const QQuickItem::ItemChangeData &changeData)
77{
78 if (!m_videoWindowControl)
79 return;
80
81 switch (change) {
82 case QQuickItem::ItemVisibleHasChanged:
83 m_visible = changeData.boolValue;
84 updateGeometry();
85 break;
86 case QQuickItem::ItemSceneChange:
87 if (changeData.window)
88 m_videoWindowControl->setWinId(changeData.window->winId());
89 else
90 m_videoWindowControl->setWinId(0);
91 break;
92 default: break;
93 }
94}
95
96void QDeclarativeVideoWindowBackend::releaseSource()
97{
98}
99
100void QDeclarativeVideoWindowBackend::releaseControl()
101{
102 if (m_videoWindowControl) {
103 m_videoWindowControl->setWinId(0);
104 if (m_service)
105 m_service->releaseControl(control: m_videoWindowControl);
106 m_videoWindowControl = 0;
107 }
108}
109
110QSize QDeclarativeVideoWindowBackend::nativeSize() const
111{
112 return m_videoWindowControl->nativeSize();
113}
114
115void QDeclarativeVideoWindowBackend::updateGeometry()
116{
117 switch (q->fillMode()) {
118 case QDeclarativeVideoOutput::PreserveAspectFit:
119 m_videoWindowControl->setAspectRatioMode(Qt::KeepAspectRatio); break;
120 case QDeclarativeVideoOutput::PreserveAspectCrop:
121 m_videoWindowControl->setAspectRatioMode(Qt::KeepAspectRatioByExpanding); break;
122 case QDeclarativeVideoOutput::Stretch:
123 m_videoWindowControl->setAspectRatioMode(Qt::IgnoreAspectRatio); break;
124 };
125
126 const QRectF canvasRect = q->mapRectToScene(rect: QRectF(0, 0, q->width(), q->height()));
127 m_videoWindowControl->setDisplayRect(m_visible ? canvasRect.toAlignedRect() : QRect());
128}
129
130QSGNode *QDeclarativeVideoWindowBackend::updatePaintNode(QSGNode *oldNode,
131 QQuickItem::UpdatePaintNodeData *data)
132{
133 Q_UNUSED(oldNode);
134 Q_UNUSED(data);
135 m_videoWindowControl->repaint();
136 return 0;
137}
138
139QAbstractVideoSurface *QDeclarativeVideoWindowBackend::videoSurface() const
140{
141 return 0;
142}
143
144QRectF QDeclarativeVideoWindowBackend::adjustedViewport() const
145{
146 // No viewport supported by QVideoWindowControl, so make the viewport the same size
147 // as the source
148 return QRectF(QPointF(0, 0), nativeSize());
149}
150
151QT_END_NAMESPACE
152

source code of qtmultimedia/src/qtmultimediaquicktools/qdeclarativevideooutput_window.cpp