author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtMultimedia module 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 "qabstractvideosurface_p.h" |
|
43 |
||
44 |
QT_BEGIN_NAMESPACE |
|
45 |
||
46 |
/*! |
|
47 |
\class QAbstractVideoSurface |
|
48 |
\brief The QAbstractVideoSurface class is a base class for video presentation surfaces. |
|
49 |
\since 4.6 |
|
50 |
||
51 |
The QAbstractVideoSurface class defines the standard interface that video producers use to |
|
52 |
inter-operate with video presentation surfaces. It is not supposed to be instantiated directly. |
|
53 |
Instead, you should subclass it to create new video surfaces. |
|
54 |
||
55 |
A video surface presents a continuous stream of identically formatted frames, where the format |
|
56 |
of each frame is compatible with a stream format supplied when starting a presentation. |
|
57 |
||
58 |
A list of pixel formats a surface can present is given by the supportedPixelFormats() function, |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
59 |
and the isFormatSupported() function will test if a video surface format is supported. If a |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
60 |
format is not supported the nearestFormat() function may be able to suggest a similar format. |
0 | 61 |
For example if a surface supports fixed set of resolutions it may suggest the smallest |
62 |
supported resolution that contains the proposed resolution. |
|
63 |
||
64 |
The start() function takes a supported format and enables a video surface. Once started a |
|
65 |
surface will begin displaying the frames it receives in the present() function. Surfaces may |
|
66 |
hold a reference to the buffer of a presented video frame until a new frame is presented or |
|
67 |
streaming is stopped. The stop() function will disable a surface and a release any video |
|
68 |
buffers it holds references to. |
|
69 |
*/ |
|
70 |
||
71 |
/*! |
|
72 |
\enum QAbstractVideoSurface::Error |
|
73 |
This enum describes the errors that may be returned by the error() function. |
|
74 |
||
75 |
\value NoError No error occurred. |
|
76 |
\value UnsupportedFormatError A video format was not supported. |
|
77 |
\value IncorrectFormatError A video frame was not compatible with the format of the surface. |
|
78 |
\value StoppedError The surface has not been started. |
|
79 |
\value ResourceError The surface could not allocate some resource. |
|
80 |
*/ |
|
81 |
||
82 |
/*! |
|
83 |
Constructs a video surface with the given \a parent. |
|
84 |
*/ |
|
85 |
||
86 |
QAbstractVideoSurface::QAbstractVideoSurface(QObject *parent) |
|
87 |
: QObject(*new QAbstractVideoSurfacePrivate, parent) |
|
88 |
{ |
|
89 |
} |
|
90 |
||
91 |
/*! |
|
92 |
\internal |
|
93 |
*/ |
|
94 |
||
95 |
QAbstractVideoSurface::QAbstractVideoSurface(QAbstractVideoSurfacePrivate &dd, QObject *parent) |
|
96 |
: QObject(dd, parent) |
|
97 |
{ |
|
98 |
} |
|
99 |
||
100 |
/*! |
|
101 |
Destroys a video surface. |
|
102 |
*/ |
|
103 |
||
104 |
QAbstractVideoSurface::~QAbstractVideoSurface() |
|
105 |
{ |
|
106 |
} |
|
107 |
||
108 |
/*! |
|
109 |
\fn QAbstractVideoSurface::supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const |
|
110 |
||
111 |
Returns a list of pixel formats a video surface can present for a given handle \a type. |
|
112 |
||
113 |
The pixel formats returned for the QAbstractVideoBuffer::NoHandle type are valid for any buffer |
|
114 |
that can be mapped in read-only mode. |
|
115 |
||
116 |
Types that are first in the list can be assumed to be faster to render. |
|
117 |
*/ |
|
118 |
||
119 |
/*! |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
120 |
Tests a video surface \a format to determine if a surface can accept it. |
0 | 121 |
|
122 |
Returns true if the format is supported by the surface, and false otherwise. |
|
123 |
*/ |
|
124 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
125 |
bool QAbstractVideoSurface::isFormatSupported(const QVideoSurfaceFormat &format) const |
0 | 126 |
{ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
return supportedPixelFormats(format.handleType()).contains(format.pixelFormat()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
Returns a supported video surface format that is similar to \a format. |
0 | 132 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
A similar surface format is one that has the same \l {QVideoSurfaceFormat::pixelFormat()}{pixel |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
134 |
format} and \l {QVideoSurfaceFormat::handleType()}{handle type} but differs in some of the other |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
properties. For example if there are restrictions on the \l {QVideoSurfaceFormat::frameSize()} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
136 |
{frame sizes} a video surface can accept it may suggest a format with a larger frame size and |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
137 |
a \l {QVideoSurfaceFormat::viewport()}{viewport} the size of the original frame size. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
139 |
If the format is already supported it will be returned unchanged, or if there is no similar |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
140 |
supported format an invalid format will be returned. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
142 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
143 |
QVideoSurfaceFormat QAbstractVideoSurface::nearestFormat(const QVideoSurfaceFormat &format) const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
144 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
145 |
return isFormatSupported(format) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
? format |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
: QVideoSurfaceFormat(); |
0 | 148 |
} |
149 |
||
150 |
/*! |
|
151 |
\fn QAbstractVideoSurface::supportedFormatsChanged() |
|
152 |
||
153 |
Signals that the set of formats supported by a video surface has changed. |
|
154 |
||
155 |
\sa supportedPixelFormats(), isFormatSupported() |
|
156 |
*/ |
|
157 |
||
158 |
/*! |
|
159 |
Returns the format of a video surface. |
|
160 |
*/ |
|
161 |
||
162 |
QVideoSurfaceFormat QAbstractVideoSurface::surfaceFormat() const |
|
163 |
{ |
|
164 |
return d_func()->format; |
|
165 |
} |
|
166 |
||
167 |
/*! |
|
168 |
\fn QAbstractVideoSurface::surfaceFormatChanged(const QVideoSurfaceFormat &format) |
|
169 |
||
170 |
Signals that the configured \a format of a video surface has changed. |
|
171 |
||
172 |
\sa surfaceFormat(), start() |
|
173 |
*/ |
|
174 |
||
175 |
/*! |
|
176 |
Starts a video surface presenting \a format frames. |
|
177 |
||
178 |
Returns true if the surface was started, and false if an error occurred. |
|
179 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
\sa isActive(), stop() |
0 | 181 |
*/ |
182 |
||
183 |
bool QAbstractVideoSurface::start(const QVideoSurfaceFormat &format) |
|
184 |
{ |
|
185 |
Q_D(QAbstractVideoSurface); |
|
186 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
187 |
bool wasActive = d->active; |
0 | 188 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
d->active = true; |
0 | 190 |
d->format = format; |
191 |
d->error = NoError; |
|
192 |
||
193 |
emit surfaceFormatChanged(d->format); |
|
194 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
195 |
if (!wasActive) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
196 |
emit activeChanged(true); |
0 | 197 |
|
198 |
return true; |
|
199 |
} |
|
200 |
||
201 |
/*! |
|
202 |
Stops a video surface presenting frames and releases any resources acquired in start(). |
|
203 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
204 |
\sa isActive(), start() |
0 | 205 |
*/ |
206 |
||
207 |
void QAbstractVideoSurface::stop() |
|
208 |
{ |
|
209 |
Q_D(QAbstractVideoSurface); |
|
210 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
211 |
if (d->active) { |
0 | 212 |
d->format = QVideoSurfaceFormat(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
213 |
d->active = false; |
0 | 214 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
215 |
emit activeChanged(false); |
0 | 216 |
emit surfaceFormatChanged(d->format); |
217 |
} |
|
218 |
} |
|
219 |
||
220 |
/*! |
|
221 |
Indicates whether a video surface has been started. |
|
222 |
||
223 |
Returns true if the surface has been started, and false otherwise. |
|
224 |
*/ |
|
225 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
226 |
bool QAbstractVideoSurface::isActive() const |
0 | 227 |
{ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
228 |
return d_func()->active; |
0 | 229 |
} |
230 |
||
231 |
/*! |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
232 |
\fn QAbstractVideoSurface::activeChanged(bool active) |
0 | 233 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
234 |
Signals that the \a active state of a video surface has changed. |
0 | 235 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
236 |
\sa isActive(), start(), stop() |
0 | 237 |
*/ |
238 |
||
239 |
/*! |
|
240 |
\fn QAbstractVideoSurface::present(const QVideoFrame &frame) |
|
241 |
||
242 |
Presents a video \a frame. |
|
243 |
||
244 |
Returns true if the frame was presented, and false if an error occurred. |
|
245 |
||
246 |
Not all surfaces will block until the presentation of a frame has completed. Calling present() |
|
247 |
on a non-blocking surface may fail if called before the presentation of a previous frame has |
|
248 |
completed. In such cases the surface may not return to a ready state until it's had an |
|
249 |
opportunity to process events. |
|
250 |
||
251 |
If present() fails for any other reason the surface will immediately enter the stopped state |
|
252 |
and an error() value will be set. |
|
253 |
||
254 |
A video surface must be in the started state for present() to succeed, and the format of the |
|
255 |
video frame must be compatible with the current video surface format. |
|
256 |
||
257 |
\sa error() |
|
258 |
*/ |
|
259 |
||
260 |
/*! |
|
261 |
Returns the last error that occurred. |
|
262 |
||
263 |
If a surface fails to start(), or stops unexpectedly this function can be called to discover |
|
264 |
what error occurred. |
|
265 |
*/ |
|
266 |
||
267 |
QAbstractVideoSurface::Error QAbstractVideoSurface::error() const |
|
268 |
{ |
|
269 |
return d_func()->error; |
|
270 |
} |
|
271 |
||
272 |
/*! |
|
273 |
Sets the value of error() to \a error. |
|
274 |
*/ |
|
275 |
||
276 |
void QAbstractVideoSurface::setError(Error error) |
|
277 |
{ |
|
278 |
Q_D(QAbstractVideoSurface); |
|
279 |
||
280 |
d->error = error; |
|
281 |
} |
|
282 |
||
283 |
QT_END_NAMESPACE |