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