|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 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 Qt Mobility Components. |
|
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 "qgstreamervideooverlay.h" |
|
43 #include "qvideosurfacegstsink.h" |
|
44 |
|
45 #include <qvideosurfaceformat.h> |
|
46 |
|
47 #include "qx11videosurface.h" |
|
48 |
|
49 #ifndef QT_NO_XVIDEO |
|
50 |
|
51 QGstreamerVideoOverlay::QGstreamerVideoOverlay(QObject *parent) |
|
52 : QVideoWindowControl(parent) |
|
53 , m_surface(new QX11VideoSurface) |
|
54 , m_videoSink(reinterpret_cast<GstElement*>(QVideoSurfaceGstSink::createSink(m_surface))) |
|
55 , m_aspectRatioMode(Qt::KeepAspectRatio) |
|
56 , m_fullScreen(false) |
|
57 { |
|
58 if (m_videoSink) { |
|
59 gst_object_ref(GST_OBJECT(m_videoSink)); //Take ownership |
|
60 gst_object_sink(GST_OBJECT(m_videoSink)); |
|
61 } |
|
62 |
|
63 connect(m_surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat)), |
|
64 this, SLOT(surfaceFormatChanged())); |
|
65 } |
|
66 |
|
67 QGstreamerVideoOverlay::~QGstreamerVideoOverlay() |
|
68 { |
|
69 if (m_videoSink) |
|
70 gst_object_unref(GST_OBJECT(m_videoSink)); |
|
71 |
|
72 delete m_surface; |
|
73 } |
|
74 |
|
75 WId QGstreamerVideoOverlay::winId() const |
|
76 { |
|
77 return m_surface->winId(); |
|
78 } |
|
79 |
|
80 void QGstreamerVideoOverlay::setWinId(WId id) |
|
81 { |
|
82 m_surface->setWinId(id); |
|
83 } |
|
84 |
|
85 QRect QGstreamerVideoOverlay::displayRect() const |
|
86 { |
|
87 return m_displayRect; |
|
88 } |
|
89 |
|
90 void QGstreamerVideoOverlay::setDisplayRect(const QRect &rect) |
|
91 { |
|
92 m_displayRect = rect; |
|
93 |
|
94 setScaledDisplayRect(); |
|
95 } |
|
96 |
|
97 Qt::AspectRatioMode QGstreamerVideoOverlay::aspectRatioMode() const |
|
98 { |
|
99 return m_aspectRatioMode; |
|
100 } |
|
101 |
|
102 void QGstreamerVideoOverlay::setAspectRatioMode(Qt::AspectRatioMode mode) |
|
103 { |
|
104 m_aspectRatioMode = mode; |
|
105 |
|
106 setScaledDisplayRect(); |
|
107 } |
|
108 |
|
109 void QGstreamerVideoOverlay::repaint() |
|
110 { |
|
111 } |
|
112 |
|
113 int QGstreamerVideoOverlay::brightness() const |
|
114 { |
|
115 return m_surface->brightness(); |
|
116 } |
|
117 |
|
118 void QGstreamerVideoOverlay::setBrightness(int brightness) |
|
119 { |
|
120 m_surface->setBrightness(brightness); |
|
121 |
|
122 emit brightnessChanged(m_surface->brightness()); |
|
123 } |
|
124 |
|
125 int QGstreamerVideoOverlay::contrast() const |
|
126 { |
|
127 return m_surface->contrast(); |
|
128 } |
|
129 |
|
130 void QGstreamerVideoOverlay::setContrast(int contrast) |
|
131 { |
|
132 m_surface->setContrast(contrast); |
|
133 |
|
134 emit contrastChanged(m_surface->contrast()); |
|
135 } |
|
136 |
|
137 int QGstreamerVideoOverlay::hue() const |
|
138 { |
|
139 return m_surface->hue(); |
|
140 } |
|
141 |
|
142 void QGstreamerVideoOverlay::setHue(int hue) |
|
143 { |
|
144 m_surface->setHue(hue); |
|
145 |
|
146 emit hueChanged(m_surface->hue()); |
|
147 } |
|
148 |
|
149 int QGstreamerVideoOverlay::saturation() const |
|
150 { |
|
151 return m_surface->saturation(); |
|
152 } |
|
153 |
|
154 void QGstreamerVideoOverlay::setSaturation(int saturation) |
|
155 { |
|
156 m_surface->setSaturation(saturation); |
|
157 |
|
158 emit saturationChanged(m_surface->saturation()); |
|
159 } |
|
160 |
|
161 bool QGstreamerVideoOverlay::isFullScreen() const |
|
162 { |
|
163 return m_fullScreen; |
|
164 } |
|
165 |
|
166 void QGstreamerVideoOverlay::setFullScreen(bool fullScreen) |
|
167 { |
|
168 emit fullScreenChanged(m_fullScreen = fullScreen); |
|
169 } |
|
170 |
|
171 QSize QGstreamerVideoOverlay::nativeSize() const |
|
172 { |
|
173 return m_surface->surfaceFormat().sizeHint(); |
|
174 } |
|
175 |
|
176 QAbstractVideoSurface *QGstreamerVideoOverlay::surface() const |
|
177 { |
|
178 return m_surface; |
|
179 } |
|
180 |
|
181 GstElement *QGstreamerVideoOverlay::videoSink() |
|
182 { |
|
183 return m_videoSink; |
|
184 } |
|
185 |
|
186 void QGstreamerVideoOverlay::surfaceFormatChanged() |
|
187 { |
|
188 setScaledDisplayRect(); |
|
189 |
|
190 emit nativeSizeChanged(); |
|
191 } |
|
192 |
|
193 void QGstreamerVideoOverlay::setScaledDisplayRect() |
|
194 { |
|
195 QRect formatViewport = m_surface->surfaceFormat().viewport(); |
|
196 |
|
197 switch (m_aspectRatioMode) { |
|
198 case Qt::KeepAspectRatio: |
|
199 { |
|
200 QSize size = m_surface->surfaceFormat().sizeHint(); |
|
201 size.scale(m_displayRect.size(), Qt::KeepAspectRatio); |
|
202 |
|
203 QRect rect(QPoint(0, 0), size); |
|
204 rect.moveCenter(m_displayRect.center()); |
|
205 |
|
206 m_surface->setDisplayRect(rect); |
|
207 m_surface->setViewport(formatViewport); |
|
208 } |
|
209 break; |
|
210 case Qt::IgnoreAspectRatio: |
|
211 m_surface->setDisplayRect(m_displayRect); |
|
212 m_surface->setViewport(formatViewport); |
|
213 break; |
|
214 case Qt::KeepAspectRatioByExpanding: |
|
215 { |
|
216 QSize size = m_displayRect.size(); |
|
217 size.scale(m_surface->surfaceFormat().sizeHint(), Qt::KeepAspectRatio); |
|
218 |
|
219 QRect viewport(QPoint(0, 0), size); |
|
220 viewport.moveCenter(formatViewport.center()); |
|
221 m_surface->setDisplayRect(m_displayRect); |
|
222 m_surface->setViewport(viewport); |
|
223 } |
|
224 break; |
|
225 }; |
|
226 } |
|
227 |
|
228 #endif //QT_NO_XVIDEO |