Rename QtMultimediaKit to QtMultimedia.

There are a few legacy bits left in place so it passes CI, and
then qt5.git etc can be updated.

Change-Id: I6b082e50e6958c72fdabc2974992e16d90dafa3a
Reviewed-on: http://codereview.qt-project.org/5368
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Jonas Rabbe <jonas.rabbe@nokia.com>
This commit is contained in:
Michael Goddard
2011-10-06 14:31:58 +10:00
committed by Qt by Nokia
parent 55bc4f2b46
commit 03f22bcdaf
395 changed files with 1393 additions and 3088 deletions

View File

@@ -0,0 +1,202 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qabstractvideobuffer_p.h"
#include <qvariant.h>
QT_BEGIN_NAMESPACE
/*!
\class QAbstractVideoBuffer
\brief The QAbstractVideoBuffer class is an abstraction for video data.
\since 1.0
\inmodule QtMultimedia
The QVideoFrame class makes use of a QAbstractVideoBuffer internally to reference a buffer of
video data. Creating a subclass of QAbstractVideoBuffer will allow you to construct video
frames from preallocated or static buffers.
The contents of a buffer can be accessed by mapping the buffer to memory using the map()
function which returns a pointer to memory containing the contents of the the video buffer.
The memory returned by map() is released by calling the unmap() function.
The handle() of a buffer may also be used to manipulate its contents using type specific APIs.
The type of a buffer's handle is given by the handleType() function.
\sa QVideoFrame
*/
/*!
\enum QAbstractVideoBuffer::HandleType
Identifies the type of a video buffers handle.
\value NoHandle The buffer has no handle, its data can only be accessed by mapping the buffer.
\value GLTextureHandle The handle of the buffer is an OpenGL texture ID.
\value XvShmImageHandle The handle contains pointer to shared memory XVideo image.
\value CoreImageHandle The handle contains pointer to Mac OS X CIImage.
\value QPixmapHandle The handle of the buffer is a QPixmap.
\value UserHandle Start value for user defined handle types.
\sa handleType()
*/
/*!
\enum QAbstractVideoBuffer::MapMode
Enumerates how a video buffer's data is mapped to memory.
\value NotMapped The video buffer has is not mapped to memory.
\value ReadOnly The mapped memory is populated with data from the video buffer when mapped, but
the content of the mapped memory may be discarded when unmapped.
\value WriteOnly The mapped memory is uninitialized when mapped, and the content will be used to
populate the video buffer when unmapped.
\value ReadWrite The mapped memory is populated with data from the video buffer, and the
video buffer is repopulated with the content of the mapped memory.
\sa mapMode(), map()
*/
/*!
Constructs an abstract video buffer of the given \a type.
*/
QAbstractVideoBuffer::QAbstractVideoBuffer(HandleType type)
: d_ptr(new QAbstractVideoBufferPrivate)
{
Q_D(QAbstractVideoBuffer);
d->handleType = type;
}
/*!
\internal
*/
QAbstractVideoBuffer::QAbstractVideoBuffer(QAbstractVideoBufferPrivate &dd, HandleType type)
: d_ptr(&dd)
{
Q_D(QAbstractVideoBuffer);
d->handleType = type;
}
/*!
Destroys an abstract video buffer.
*/
QAbstractVideoBuffer::~QAbstractVideoBuffer()
{
delete d_ptr;
}
/*!
Returns the type of a video buffer's handle.
\since 1.0
\sa handle()
*/
QAbstractVideoBuffer::HandleType QAbstractVideoBuffer::handleType() const
{
return d_func()->handleType;
}
/*!
\fn QAbstractVideoBuffer::mapMode() const
Returns the mode a video buffer is mapped in.
\since 1.0
\sa map()
*/
/*!
\fn QAbstractVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine)
Maps the contents of a video buffer to memory.
The map \a mode indicates whether the contents of the mapped memory should be read from and/or
written to the buffer. If the map mode includes the QAbstractVideoBuffer::ReadOnly flag the
mapped memory will be populated with the content of the video buffer when mapped. If the map
mode includes the QAbstractVideoBuffer::WriteOnly flag the content of the mapped memory will be
persisted in the buffer when unmapped.
When access to the data is no longer needed be sure to call the unmap() function to release the
mapped memory.
Returns a pointer to the mapped memory region, or a null pointer if the mapping failed. The
size in bytes of the mapped memory region is returned in \a numBytes, and the line stride in \a
bytesPerLine.
When access to the data is no longer needed be sure to unmap() the buffer.
\note Writing to memory that is mapped as read-only is undefined, and may result in changes
to shared data.
\since 1.0
\sa unmap(), mapMode()
*/
/*!
\fn QAbstractVideoBuffer::unmap()
Releases the memory mapped by the map() function
If the \l {QAbstractVideoBuffer::MapMode}{MapMode} included the QAbstractVideoBuffer::WriteOnly
flag this will persist the current content of the mapped memory to the video frame.
\since 1.0
\sa map()
*/
/*!
Returns a type specific handle to the data buffer.
The type of the handle is given by handleType() function.
\since 1.0
\sa handleType()
*/
QVariant QAbstractVideoBuffer::handle() const
{
return QVariant();
}
QT_END_NAMESPACE

View File

@@ -0,0 +1,112 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QABSTRACTVIDEOBUFFER_H
#define QABSTRACTVIDEOBUFFER_H
#include <qtmultimediadefs.h>
#include <qtmedianamespace.h>
#include <QtCore/qmetatype.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Multimedia)
class QVariant;
class QAbstractVideoBufferPrivate;
class Q_MULTIMEDIA_EXPORT QAbstractVideoBuffer
{
public:
enum HandleType
{
NoHandle,
GLTextureHandle,
XvShmImageHandle,
CoreImageHandle,
QPixmapHandle,
UserHandle = 1000
};
enum MapMode
{
NotMapped = 0x00,
ReadOnly = 0x01,
WriteOnly = 0x02,
ReadWrite = ReadOnly | WriteOnly
};
QAbstractVideoBuffer(HandleType type);
virtual ~QAbstractVideoBuffer();
HandleType handleType() const;
virtual MapMode mapMode() const = 0;
virtual uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) = 0;
virtual void unmap() = 0;
virtual QVariant handle() const;
protected:
QAbstractVideoBuffer(QAbstractVideoBufferPrivate &dd, HandleType type);
QAbstractVideoBufferPrivate *d_ptr;
private:
Q_DECLARE_PRIVATE(QAbstractVideoBuffer)
Q_DISABLE_COPY(QAbstractVideoBuffer)
};
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QAbstractVideoBuffer::HandleType)
Q_DECLARE_METATYPE(QAbstractVideoBuffer::MapMode)
QT_END_HEADER
#endif

View File

@@ -0,0 +1,88 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QABSTRACTVIDEOBUFFER_P_H
#define QABSTRACTVIDEOBUFFER_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtCore/qshareddata.h>
#include "qabstractvideobuffer.h"
#include <qtmultimediadefs.h>
#include <qtmedianamespace.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Multimedia)
class QAbstractVideoBufferPrivate
{
public:
QAbstractVideoBufferPrivate()
: handleType(QAbstractVideoBuffer::NoHandle)
{}
virtual ~QAbstractVideoBufferPrivate()
{}
QAbstractVideoBuffer::HandleType handleType;
};
QT_END_NAMESPACE
QT_END_HEADER
#endif

View File

@@ -0,0 +1,340 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
//TESTED_COMPONENT=src/multimedia
#include "qabstractvideosurface.h"
#include "qvideosurfaceformat.h"
#include <QtCore/qvariant.h>
QT_BEGIN_NAMESPACE
Q_DECLARE_METATYPE(QVideoSurfaceFormat)
Q_DECLARE_METATYPE(QAbstractVideoSurface::Error)
/*!
\class QAbstractVideoSurface
\brief The QAbstractVideoSurface class is a base class for video presentation surfaces.
\since 1.0
\inmodule QtMultimedia
A video surface presents a continuous stream of identically formatted frames, where the format
of each frame is compatible with a stream format supplied when starting a presentation.
The QAbstractVideoSurface class defines the standard interface that video producers use to
inter-operate with video presentation surfaces. It is not supposed to be instantiated directly.
Instead, you should subclass it to create new video surfaces.
A list of pixel formats a surface can present is given by the supportedPixelFormats() function,
and the isFormatSupported() function will test if a video surface format is supported. If a
format is not supported the nearestFormat() function may be able to suggest a similar format.
For example, if a surface supports fixed set of resolutions it may suggest the smallest
supported resolution that contains the proposed resolution.
The start() function takes a supported format and enables a video surface. Once started a
surface will begin displaying the frames it receives in the present() function. Surfaces may
hold a reference to the buffer of a presented video frame until a new frame is presented or
streaming is stopped. The stop() function will disable a surface and a release any video
buffers it holds references to.
*/
/*!
\enum QAbstractVideoSurface::Error
This enum describes the errors that may be returned by the error() function.
\value NoError No error occurred.
\value UnsupportedFormatError A video format was not supported.
\value IncorrectFormatError A video frame was not compatible with the format of the surface.
\value StoppedError The surface has not been started.
\value ResourceError The surface could not allocate some resource.
*/
/*!
Constructs a video surface with the given \a parent.
*/
QAbstractVideoSurface::QAbstractVideoSurface(QObject *parent)
: QObject(parent)
{
setProperty("_q_surfaceFormat", QVariant::fromValue(QVideoSurfaceFormat()));
setProperty("_q_active", false);
setProperty("_q_error", QVariant::fromValue(QAbstractVideoSurface::NoError));
setProperty("_q_nativeResolution", QSize());
}
// XXX Qt5
/*!
\internal
This is deprecated.
Since we need to build without access to Qt's private headers we can't reliably inherit
from QObjectPrivate. Binary compatibility means we can't remove this constructor or
add a d pointer to QAbstractVideoSurface.
*/
QAbstractVideoSurface::QAbstractVideoSurface(QAbstractVideoSurfacePrivate &, QObject *parent)
: QObject(parent)
{
}
/*!
Destroys a video surface.
*/
QAbstractVideoSurface::~QAbstractVideoSurface()
{
}
/*!
\fn QAbstractVideoSurface::supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const
Returns a list of pixel formats a video surface can present for a given handle \a type.
The pixel formats returned for the QAbstractVideoBuffer::NoHandle type are valid for any buffer
that can be mapped in read-only mode.
Types that are first in the list can be assumed to be faster to render.
\since 1.0
*/
/*!
Tests a video surface \a format to determine if a surface can accept it.
Returns true if the format is supported by the surface, and false otherwise.
\since 1.0
*/
bool QAbstractVideoSurface::isFormatSupported(const QVideoSurfaceFormat &format) const
{
return supportedPixelFormats(format.handleType()).contains(format.pixelFormat());
}
/*!
Returns a supported video surface format that is similar to \a format.
A similar surface format is one that has the same \l {QVideoSurfaceFormat::pixelFormat()}{pixel
format} and \l {QVideoSurfaceFormat::handleType()}{handle type} but may differ in some of the other
properties. For example, if there are restrictions on the \l {QVideoSurfaceFormat::frameSize()}
{frame sizes} a video surface can accept it may suggest a format with a larger frame size and
a \l {QVideoSurfaceFormat::viewport()}{viewport} the size of the original frame size.
If the format is already supported it will be returned unchanged, or if there is no similar
supported format an invalid format will be returned.
\since 1.0
*/
QVideoSurfaceFormat QAbstractVideoSurface::nearestFormat(const QVideoSurfaceFormat &format) const
{
return isFormatSupported(format)
? format
: QVideoSurfaceFormat();
}
/*!
\fn QAbstractVideoSurface::supportedFormatsChanged()
Signals that the set of formats supported by a video surface has changed.
\since 1.0
\sa supportedPixelFormats(), isFormatSupported()
*/
/*!
Returns the format of a video surface.
\since 1.0
*/
QVideoSurfaceFormat QAbstractVideoSurface::surfaceFormat() const
{
return property("_q_format").value<QVideoSurfaceFormat>();
}
/*!
\fn QAbstractVideoSurface::surfaceFormatChanged(const QVideoSurfaceFormat &format)
Signals that the configured \a format of a video surface has changed.
\since 1.0
\sa surfaceFormat(), start()
*/
/*!
Starts a video surface presenting \a format frames.
Returns true if the surface was started, and false if an error occurred.
\since 1.0
\sa isActive(), stop()
*/
bool QAbstractVideoSurface::start(const QVideoSurfaceFormat &format)
{
bool wasActive = property("_q_active").toBool();
setProperty("_q_active", true);
setProperty("_q_format", QVariant::fromValue(format));
setProperty("_q_error", QVariant::fromValue(NoError));
emit surfaceFormatChanged(format);
if (!wasActive)
emit activeChanged(true);
return true;
}
/*!
Stops a video surface presenting frames and releases any resources acquired in start().
\since 1.0
\sa isActive(), start()
*/
void QAbstractVideoSurface::stop()
{
if (property("_q_active").toBool()) {
setProperty("_q_format", QVariant::fromValue(QVideoSurfaceFormat()));
setProperty("_q_active", false);
emit activeChanged(false);
emit surfaceFormatChanged(surfaceFormat());
}
}
/*!
Indicates whether a video surface has been started.
Returns true if the surface has been started, and false otherwise.
\since 1.0
*/
bool QAbstractVideoSurface::isActive() const
{
return property("_q_active").toBool();
}
/*!
\fn QAbstractVideoSurface::activeChanged(bool active)
Signals that the \a active state of a video surface has changed.
\since 1.0
\sa isActive(), start(), stop()
*/
/*!
\fn QAbstractVideoSurface::present(const QVideoFrame &frame)
Presents a video \a frame.
Returns true if the frame was presented, and false if an error occurred.
Not all surfaces will block until the presentation of a frame has completed. Calling present()
on a non-blocking surface may fail if called before the presentation of a previous frame has
completed. In such cases the surface may not return to a ready state until it has had an
opportunity to process events.
If present() fails for any other reason the surface will immediately enter the stopped state
and an error() value will be set.
A video surface must be in the started state for present() to succeed, and the format of the
video frame must be compatible with the current video surface format.
\since 1.0
\sa error()
*/
/*!
Returns the last error that occurred.
If a surface fails to start(), or stops unexpectedly this function can be called to discover
what error occurred.
\since 1.0
*/
QAbstractVideoSurface::Error QAbstractVideoSurface::error() const
{
return property("_q_error").value<QAbstractVideoSurface::Error>();
}
/*!
Sets the value of error() to \a error.
\since 1.0
*/
void QAbstractVideoSurface::setError(Error error)
{
setProperty("_q_error", QVariant::fromValue(error));
}
/*!
\property QAbstractVideoSurface::nativeResolution
The native resolution of video surface.
This is the resolution of video frames the surface
can render with optimal quality and/or performance.
The native resolution is not always known and can be changed during playback.
\since 1.1
*/
QSize QAbstractVideoSurface::nativeResolution() const
{
return property("_q_nativeResolution").toSize();
}
/*!
Set the video surface native \a resolution.
\since 1.1
*/
void QAbstractVideoSurface::setNativeResolution(const QSize &resolution)
{
const QSize nativeResolution = property("_q_nativeResolution").toSize();
if (nativeResolution != resolution) {
setProperty("_q_nativeResolution", resolution);
emit nativeResolutionChanged(resolution);
}
}
/*!
\fn QAbstractVideoSurface::nativeResolutionChanged(const QSize &resolution);
Signals the native \a resolution of video surface has changed.
\since 1.1
*/
QT_END_NAMESPACE
#include "moc_qabstractvideosurface.cpp"

View File

@@ -0,0 +1,115 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QABSTRACTVIDEOSURFACE_H
#define QABSTRACTVIDEOSURFACE_H
#include <QtCore/qobject.h>
#include <qvideoframe.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Multimedia)
class QRectF;
class QVideoSurfaceFormat;
class QAbstractVideoSurfacePrivate;
class Q_MULTIMEDIA_EXPORT QAbstractVideoSurface : public QObject
{
Q_OBJECT
Q_PROPERTY(QSize nativeResolution READ nativeResolution NOTIFY nativeResolutionChanged)
public:
enum Error
{
NoError,
UnsupportedFormatError,
IncorrectFormatError,
StoppedError,
ResourceError
};
explicit QAbstractVideoSurface(QObject *parent = 0);
~QAbstractVideoSurface();
virtual QList<QVideoFrame::PixelFormat> supportedPixelFormats(
QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const = 0;
virtual bool isFormatSupported(const QVideoSurfaceFormat &format) const;
virtual QVideoSurfaceFormat nearestFormat(const QVideoSurfaceFormat &format) const;
QVideoSurfaceFormat surfaceFormat() const;
QSize nativeResolution() const;
virtual bool start(const QVideoSurfaceFormat &format);
virtual void stop();
bool isActive() const;
virtual bool present(const QVideoFrame &frame) = 0;
Error error() const;
Q_SIGNALS:
void activeChanged(bool active);
void surfaceFormatChanged(const QVideoSurfaceFormat &format);
void supportedFormatsChanged();
void nativeResolutionChanged(const QSize &);
protected:
QAbstractVideoSurface(QAbstractVideoSurfacePrivate &dd, QObject *parent);
void setError(Error error);
void setNativeResolution(const QSize &resolution);
private:
Q_DECLARE_PRIVATE(QAbstractVideoSurface)
};
QT_END_NAMESPACE
QT_END_HEADER
#endif

View File

@@ -0,0 +1,106 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qimagevideobuffer_p.h"
#include "qabstractvideobuffer_p.h"
#include <qimage.h>
#include <qvariant.h>
QT_BEGIN_NAMESPACE
class QImageVideoBufferPrivate : public QAbstractVideoBufferPrivate
{
public:
QImageVideoBufferPrivate()
: mapMode(QAbstractVideoBuffer::NotMapped)
{
}
QAbstractVideoBuffer::MapMode mapMode;
QImage image;
};
QImageVideoBuffer::QImageVideoBuffer(const QImage &image)
: QAbstractVideoBuffer(*new QImageVideoBufferPrivate, NoHandle)
{
Q_D(QImageVideoBuffer);
d->image = image;
}
QImageVideoBuffer::~QImageVideoBuffer()
{
}
QAbstractVideoBuffer::MapMode QImageVideoBuffer::mapMode() const
{
return d_func()->mapMode;
}
uchar *QImageVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine)
{
Q_D(QImageVideoBuffer);
if (d->mapMode == NotMapped && d->image.bits() && mode != NotMapped) {
d->mapMode = mode;
if (numBytes)
*numBytes = d->image.byteCount();
if (bytesPerLine)
*bytesPerLine = d->image.bytesPerLine();
return d->image.bits();
} else {
return 0;
}
}
void QImageVideoBuffer::unmap()
{
Q_D(QImageVideoBuffer);
d->mapMode = NotMapped;
}
QT_END_NAMESPACE

View File

@@ -0,0 +1,87 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QIMAGEVIDEOBUFFER_P_H
#define QIMAGEVIDEOBUFFER_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <qabstractvideobuffer.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Multimedia)
class QImage;
class QImageVideoBufferPrivate;
class Q_MULTIMEDIA_EXPORT QImageVideoBuffer : public QAbstractVideoBuffer
{
Q_DECLARE_PRIVATE(QImageVideoBuffer)
public:
QImageVideoBuffer(const QImage &image);
~QImageVideoBuffer();
MapMode mapMode() const;
uchar *map(MapMode mode, int *numBytes, int *bytesPerLine);
void unmap();
};
QT_END_NAMESPACE
QT_END_HEADER
#endif

View File

@@ -0,0 +1,132 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qmemoryvideobuffer_p.h"
#include "qabstractvideobuffer_p.h"
#include <qbytearray.h>
QT_BEGIN_NAMESPACE
class QMemoryVideoBufferPrivate : public QAbstractVideoBufferPrivate
{
public:
QMemoryVideoBufferPrivate()
: bytesPerLine(0)
, mapMode(QAbstractVideoBuffer::NotMapped)
{
}
int bytesPerLine;
QAbstractVideoBuffer::MapMode mapMode;
QByteArray data;
};
/*!
\class QMemoryVideoBuffer
\brief The QMemoryVideoBuffer class provides a system memory allocated video data buffer.
\internal
QMemoryVideoBuffer is the default video buffer for allocating system memory. It may be used to
allocate memory for a QVideoFrame without implementing your own QAbstractVideoBuffer.
*/
/*!
Constructs a video buffer with an image stride of \a bytesPerLine from a byte \a array.
*/
QMemoryVideoBuffer::QMemoryVideoBuffer(const QByteArray &array, int bytesPerLine)
: QAbstractVideoBuffer(*new QMemoryVideoBufferPrivate, NoHandle)
{
Q_D(QMemoryVideoBuffer);
d->data = array;
d->bytesPerLine = bytesPerLine;
}
/*!
Destroys a system memory allocated video buffer.
*/
QMemoryVideoBuffer::~QMemoryVideoBuffer()
{
}
/*!
\reimp
\since 1.1
*/
QAbstractVideoBuffer::MapMode QMemoryVideoBuffer::mapMode() const
{
return d_func()->mapMode;
}
/*!
\reimp
\since 1.1
*/
uchar *QMemoryVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine)
{
Q_D(QMemoryVideoBuffer);
if (d->mapMode == NotMapped && d->data.data() && mode != NotMapped) {
d->mapMode = mode;
if (numBytes)
*numBytes = d->data.size();
if (bytesPerLine)
*bytesPerLine = d->bytesPerLine;
return reinterpret_cast<uchar *>(d->data.data());
} else {
return 0;
}
}
/*!
\reimp
\since 1.1
*/
void QMemoryVideoBuffer::unmap()
{
d_func()->mapMode = NotMapped;
}
QT_END_NAMESPACE

View File

@@ -0,0 +1,89 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QMEMORYVIDEOBUFFER_P_H
#define QMEMORYVIDEOBUFFER_P_H
#include <qabstractvideobuffer.h>
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
QT_BEGIN_HEADER
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Multimedia)
class QMemoryVideoBufferPrivate;
class Q_MULTIMEDIA_EXPORT QMemoryVideoBuffer : public QAbstractVideoBuffer
{
Q_DECLARE_PRIVATE(QMemoryVideoBuffer)
public:
QMemoryVideoBuffer(const QByteArray &data, int bytesPerLine);
~QMemoryVideoBuffer();
MapMode mapMode() const;
uchar *map(MapMode mode, int *numBytes, int *bytesPerLine);
void unmap();
};
QT_END_NAMESPACE
QT_END_HEADER
QT_END_HEADER
#endif

View File

@@ -0,0 +1,776 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qvideoframe.h"
#include "qimagevideobuffer_p.h"
#include "qmemoryvideobuffer_p.h"
#include <qimage.h>
#include <qpair.h>
#include <qsize.h>
#include <qvariant.h>
#include <qvector.h>
QT_BEGIN_NAMESPACE
namespace
{
class QVideoFramePrivateRegisterMetaTypes
{
public:
QVideoFramePrivateRegisterMetaTypes()
{
qRegisterMetaType<QVideoFrame::PixelFormat>("QVideoFrame::PixelFormat");
}
} _registerMetaTypes;
}
class QVideoFramePrivate : public QSharedData
{
public:
QVideoFramePrivate()
: startTime(-1)
, endTime(-1)
, data(0)
, mappedBytes(0)
, bytesPerLine(0)
, pixelFormat(QVideoFrame::Format_Invalid)
, fieldType(QVideoFrame::ProgressiveFrame)
, buffer(0)
{
}
QVideoFramePrivate(const QSize &size, QVideoFrame::PixelFormat format)
: size(size)
, startTime(-1)
, endTime(-1)
, data(0)
, mappedBytes(0)
, bytesPerLine(0)
, pixelFormat(format)
, fieldType(QVideoFrame::ProgressiveFrame)
, buffer(0)
{
}
~QVideoFramePrivate()
{
delete buffer;
}
QSize size;
qint64 startTime;
qint64 endTime;
uchar *data;
int mappedBytes;
int bytesPerLine;
QVideoFrame::PixelFormat pixelFormat;
QVideoFrame::FieldType fieldType;
QAbstractVideoBuffer *buffer;
private:
Q_DISABLE_COPY(QVideoFramePrivate)
};
/*!
\class QVideoFrame
\brief The QVideoFrame class provides a representation of a frame of video data.
\since 1.0
\inmodule QtMultimedia
A QVideoFrame encapsulates the data of a video frame, and information about the frame.
The contents of a video frame can be mapped to memory using the map() function. While
mapped, the video data can accessed using the bits() function, which returns a pointer to a
buffer. The total size of this buffer is given by the mappedBytes() function, and the size of each line is given
by bytesPerLine(). The return value of the handle() function may be used to access frame data
using the internal buffer's native APIs.
The video data in a QVideoFrame is encapsulated in a QAbstractVideoBuffer. A QVideoFrame
may be constructed from any buffer type by subclassing the QAbstractVideoBuffer class.
\note QVideoFrame is explicitly shared, any change made to video frame will also apply to any
copies.
*/
/*!
\enum QVideoFrame::PixelFormat
Enumerates video data types.
\value Format_Invalid
The frame is invalid.
\value Format_ARGB32
The frame is stored using a 32-bit ARGB format (0xAARRGGBB). This is equivalent to
QImage::Format_ARGB32.
\value Format_ARGB32_Premultiplied
The frame stored using a premultiplied 32-bit ARGB format (0xAARRGGBB). This is equivalent
to QImage::Format_ARGB32_Premultiplied.
\value Format_RGB32
The frame stored using a 32-bit RGB format (0xffRRGGBB). This is equivalent to
QImage::Format_RGB32
\value Format_RGB24
The frame is stored using a 24-bit RGB format (8-8-8). This is equivalent to
QImage::Format_RGB888
\value Format_RGB565
The frame is stored using a 16-bit RGB format (5-6-5). This is equivalent to
QImage::Format_RGB16.
\value Format_RGB555
The frame is stored using a 16-bit RGB format (5-5-5). This is equivalent to
QImage::Format_RGB555.
\value Format_ARGB8565_Premultiplied
The frame is stored using a 24-bit premultiplied ARGB format (8-6-6-5).
\value Format_BGRA32
The frame is stored using a 32-bit ARGB format (0xBBGGRRAA).
\value Format_BGRA32_Premultiplied
The frame is stored using a premultiplied 32bit BGRA format.
\value Format_BGR32
The frame is stored using a 32-bit BGR format (0xBBGGRRff).
\value Format_BGR24
The frame is stored using a 24-bit BGR format (0xBBGGRR).
\value Format_BGR565
The frame is stored using a 16-bit BGR format (5-6-5).
\value Format_BGR555
The frame is stored using a 16-bit BGR format (5-5-5).
\value Format_BGRA5658_Premultiplied
The frame is stored using a 24-bit premultiplied BGRA format (5-6-5-8).
\value Format_AYUV444
The frame is stored using a packed 32-bit AYUV format (0xAAYYUUVV).
\value Format_AYUV444_Premultiplied
The frame is stored using a packed premultiplied 32-bit AYUV format (0xAAYYUUVV).
\value Format_YUV444
The frame is stored using a 24-bit packed YUV format (8-8-8).
\value Format_YUV420P
The frame is stored using an 8-bit per component planar YUV format with the U and V planes
horizontally and vertically sub-sampled, i.e. the height and width of the U and V planes are
half that of the Y plane.
\value Format_YV12
The frame is stored using an 8-bit per component planar YVU format with the V and U planes
horizontally and vertically sub-sampled, i.e. the height and width of the V and U planes are
half that of the Y plane.
\value Format_UYVY
The frame is stored using an 8-bit per component packed YUV format with the U and V planes
horizontally sub-sampled (U-Y-V-Y), i.e. two horizontally adjacent pixels are stored as a 32-bit
macropixel which has a Y value for each pixel and common U and V values.
\value Format_YUYV
The frame is stored using an 8-bit per component packed YUV format with the U and V planes
horizontally sub-sampled (Y-U-Y-V), i.e. two horizontally adjacent pixels are stored as a 32-bit
macropixel which has a Y value for each pixel and common U and V values.
\value Format_NV12
The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y)
followed by a horizontally and vertically sub-sampled, packed UV plane (U-V).
\value Format_NV21
The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y)
followed by a horizontally and vertically sub-sampled, packed VU plane (V-U).
\value Format_IMC1
The frame is stored using an 8-bit per component planar YUV format with the U and V planes
horizontally and vertically sub-sampled. This is similar to the Format_YUV420P type, except
that the bytes per line of the U and V planes are padded out to the same stride as the Y plane.
\value Format_IMC2
The frame is stored using an 8-bit per component planar YUV format with the U and V planes
horizontally and vertically sub-sampled. This is similar to the Format_YUV420P type, except
that the lines of the U and V planes are interleaved, i.e. each line of U data is followed by a
line of V data creating a single line of the same stride as the Y data.
\value Format_IMC3
The frame is stored using an 8-bit per component planar YVU format with the V and U planes
horizontally and vertically sub-sampled. This is similar to the Format_YV12 type, except that
the bytes per line of the V and U planes are padded out to the same stride as the Y plane.
\value Format_IMC4
The frame is stored using an 8-bit per component planar YVU format with the V and U planes
horizontally and vertically sub-sampled. This is similar to the Format_YV12 type, except that
the lines of the V and U planes are interleaved, i.e. each line of V data is followed by a line
of U data creating a single line of the same stride as the Y data.
\value Format_Y8
The frame is stored using an 8-bit greyscale format.
\value Format_Y16
The frame is stored using a 16-bit linear greyscale format. Little endian.
\value Format_Jpeg
The frame is stored in compressed Jpeg format.
\value Format_CameraRaw
The frame is stored using a device specific camera raw format.
\value Format_AdobeDng
The frame is stored using raw Adobe Digital Negative (DNG) format.
\value Format_User
Start value for user defined pixel formats.
*/
/*!
\enum QVideoFrame::FieldType
Specifies the field an interlaced video frame belongs to.
\value ProgressiveFrame The frame is not interlaced.
\value TopField The frame contains a top field.
\value BottomField The frame contains a bottom field.
\value InterlacedFrame The frame contains a merged top and bottom field.
*/
/*!
Constructs a null video frame.
*/
QVideoFrame::QVideoFrame()
: d(new QVideoFramePrivate)
{
}
/*!
Constructs a video frame from a \a buffer with the given pixel \a format and \a size in pixels.
\note This doesn't increment the reference count of the video buffer.
\since 1.0
*/
QVideoFrame::QVideoFrame(
QAbstractVideoBuffer *buffer, const QSize &size, PixelFormat format)
: d(new QVideoFramePrivate(size, format))
{
d->buffer = buffer;
}
/*!
Constructs a video frame of the given pixel \a format and \a size in pixels.
The \a bytesPerLine (stride) is the length of each scan line in bytes, and \a bytes is the total
number of bytes that must be allocated for the frame.
\since 1.0
*/
QVideoFrame::QVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format)
: d(new QVideoFramePrivate(size, format))
{
if (bytes > 0) {
QByteArray data;
data.resize(bytes);
// Check the memory was successfully allocated.
if (!data.isEmpty())
d->buffer = new QMemoryVideoBuffer(data, bytesPerLine);
}
}
/*!
Constructs a video frame from an \a image.
\note This will construct an invalid video frame if there is no frame type equivalent to the
image format.
\since 1.0
\sa pixelFormatFromImageFormat()
*/
QVideoFrame::QVideoFrame(const QImage &image)
: d(new QVideoFramePrivate(
image.size(), pixelFormatFromImageFormat(image.format())))
{
if (d->pixelFormat != Format_Invalid)
d->buffer = new QImageVideoBuffer(image);
}
/*!
Constructs a copy of \a other.
\since 1.0
*/
QVideoFrame::QVideoFrame(const QVideoFrame &other)
: d(other.d)
{
}
/*!
Assigns the contents of \a other to a video frame.
\since 1.0
*/
QVideoFrame &QVideoFrame::operator =(const QVideoFrame &other)
{
d = other.d;
return *this;
}
/*!
Destroys a video frame.
*/
QVideoFrame::~QVideoFrame()
{
}
/*!
Identifies whether a video frame is valid.
An invalid frame has no video buffer associated with it.
Returns true if the frame is valid, and false if it is not.
\since 1.0
*/
bool QVideoFrame::isValid() const
{
return d->buffer != 0;
}
/*!
Returns the color format of a video frame.
\since 1.0
*/
QVideoFrame::PixelFormat QVideoFrame::pixelFormat() const
{
return d->pixelFormat;
}
/*!
Returns the type of a video frame's handle.
\since 1.0
*/
QAbstractVideoBuffer::HandleType QVideoFrame::handleType() const
{
return d->buffer ? d->buffer->handleType() : QAbstractVideoBuffer::NoHandle;
}
/*!
Returns the dimensions of a video frame.
\since 1.0
*/
QSize QVideoFrame::size() const
{
return d->size;
}
/*!
Returns the width of a video frame.
\since 1.0
*/
int QVideoFrame::width() const
{
return d->size.width();
}
/*!
Returns the height of a video frame.
\since 1.0
*/
int QVideoFrame::height() const
{
return d->size.height();
}
/*!
Returns the field an interlaced video frame belongs to.
If the video is not interlaced this will return WholeFrame.
\since 1.0
*/
QVideoFrame::FieldType QVideoFrame::fieldType() const
{
return d->fieldType;
}
/*!
Sets the \a field an interlaced video frame belongs to.
\since 1.0
*/
void QVideoFrame::setFieldType(QVideoFrame::FieldType field)
{
d->fieldType = field;
}
/*!
Identifies if a video frame's contents are currently mapped to system memory.
This is a convenience function which checks that the \l {QAbstractVideoBuffer::MapMode}{MapMode}
of the frame is not equal to QAbstractVideoBuffer::NotMapped.
Returns true if the contents of the video frame are mapped to system memory, and false
otherwise.
\since 1.0
\sa mapMode(), QAbstractVideoBuffer::MapMode
*/
bool QVideoFrame::isMapped() const
{
return d->buffer != 0 && d->buffer->mapMode() != QAbstractVideoBuffer::NotMapped;
}
/*!
Identifies if the mapped contents of a video frame will be persisted when the frame is unmapped.
This is a convenience function which checks if the \l {QAbstractVideoBuffer::MapMode}{MapMode}
contains the QAbstractVideoBuffer::WriteOnly flag.
Returns true if the video frame will be updated when unmapped, and false otherwise.
\note The result of altering the data of a frame that is mapped in read-only mode is undefined.
Depending on the buffer implementation the changes may be persisted, or worse alter a shared
buffer.
\since 1.0
\sa mapMode(), QAbstractVideoBuffer::MapMode
*/
bool QVideoFrame::isWritable() const
{
return d->buffer != 0 && (d->buffer->mapMode() & QAbstractVideoBuffer::WriteOnly);
}
/*!
Identifies if the mapped contents of a video frame were read from the frame when it was mapped.
This is a convenience function which checks if the \l {QAbstractVideoBuffer::MapMode}{MapMode}
contains the QAbstractVideoBuffer::WriteOnly flag.
Returns true if the contents of the mapped memory were read from the video frame, and false
otherwise.
\since 1.0
\sa mapMode(), QAbstractVideoBuffer::MapMode
*/
bool QVideoFrame::isReadable() const
{
return d->buffer != 0 && (d->buffer->mapMode() & QAbstractVideoBuffer::ReadOnly);
}
/*!
Returns the mode a video frame was mapped to system memory in.
\since 1.0
\sa map(), QAbstractVideoBuffer::MapMode
*/
QAbstractVideoBuffer::MapMode QVideoFrame::mapMode() const
{
return d->buffer != 0 ? d->buffer->mapMode() : QAbstractVideoBuffer::NotMapped;
}
/*!
Maps the contents of a video frame to memory.
The map \a mode indicates whether the contents of the mapped memory should be read from and/or
written to the frame. If the map mode includes the QAbstractVideoBuffer::ReadOnly flag the
mapped memory will be populated with the content of the video frame when mapped. If the map
mode inclues the QAbstractVideoBuffer::WriteOnly flag the content of the mapped memory will be
persisted in the frame when unmapped.
While mapped the contents of a video frame can be accessed directly through the pointer returned
by the bits() function.
When access to the data is no longer needed be sure to call the unmap() function to release the
mapped memory and possibly update the video frame contents.
Returns true if the buffer was mapped to memory in the given \a mode and false otherwise.
\since 1.0
\sa unmap(), mapMode(), bits()
*/
bool QVideoFrame::map(QAbstractVideoBuffer::MapMode mode)
{
if (d->buffer != 0 && d->data == 0) {
Q_ASSERT(d->bytesPerLine == 0);
Q_ASSERT(d->mappedBytes == 0);
d->data = d->buffer->map(mode, &d->mappedBytes, &d->bytesPerLine);
return d->data != 0;
}
return false;
}
/*!
Releases the memory mapped by the map() function.
If the \l {QAbstractVideoBuffer::MapMode}{MapMode} included the QAbstractVideoBuffer::WriteOnly
flag this will persist the current content of the mapped memory to the video frame.
\since 1.0
\sa map()
*/
void QVideoFrame::unmap()
{
if (d->data != 0) {
d->mappedBytes = 0;
d->bytesPerLine = 0;
d->data = 0;
d->buffer->unmap();
}
}
/*!
Returns the number of bytes in a scan line.
\note This is the bytes per line of the first plane only. The bytes per line of subsequent
planes should be calculated as per the frame type.
This value is only valid while the frame data is \l {map()}{mapped}.
\since 1.0
\sa bits(), map(), mappedBytes()
*/
int QVideoFrame::bytesPerLine() const
{
return d->bytesPerLine;
}
/*!
Returns a pointer to the start of the frame data buffer.
This value is only valid while the frame data is \l {map()}{mapped}.
Changes made to data accessed via this pointer (when mapped with write access)
are only guaranteed to have been persisted when unmap() is called.
\since 1.0
\sa map(), mappedBytes(), bytesPerLine()
*/
uchar *QVideoFrame::bits()
{
return d->data;
}
/*!
Returns a pointer to the start of the frame data buffer.
This value is only valid while the frame data is \l {map()}{mapped}.
If the buffer was not mapped with read access, the contents of this
buffer will initially be uninitialized.
\since 1.0
\sa map(), mappedBytes(), bytesPerLine()
*/
const uchar *QVideoFrame::bits() const
{
return d->data;
}
/*!
Returns the number of bytes occupied by the mapped frame data.
This value is only valid while the frame data is \l {map()}{mapped}.
\since 1.0
\sa map()
*/
int QVideoFrame::mappedBytes() const
{
return d->mappedBytes;
}
/*!
Returns a type specific handle to a video frame's buffer.
For an OpenGL texture this would be the texture ID.
\since 1.0
\sa QAbstractVideoBuffer::handle()
*/
QVariant QVideoFrame::handle() const
{
return d->buffer != 0 ? d->buffer->handle() : QVariant();
}
/*!
Returns the presentation time when the frame should be displayed.
\since 1.0
*/
qint64 QVideoFrame::startTime() const
{
return d->startTime;
}
/*!
Sets the presentation \a time when the frame should be displayed.
\since 1.0
*/
void QVideoFrame::setStartTime(qint64 time)
{
d->startTime = time;
}
/*!
Returns the presentation time when a frame should stop being displayed.
\since 1.0
*/
qint64 QVideoFrame::endTime() const
{
return d->endTime;
}
/*!
Sets the presentation \a time when a frame should stop being displayed.
\since 1.0
*/
void QVideoFrame::setEndTime(qint64 time)
{
d->endTime = time;
}
/*!
Returns a video pixel format equivalent to an image \a format. If there is no equivalent
format QVideoFrame::InvalidType is returned instead.
\since 1.0
*/
QVideoFrame::PixelFormat QVideoFrame::pixelFormatFromImageFormat(QImage::Format format)
{
switch (format) {
case QImage::Format_Invalid:
case QImage::Format_Mono:
case QImage::Format_MonoLSB:
case QImage::Format_Indexed8:
return Format_Invalid;
case QImage::Format_RGB32:
return Format_RGB32;
case QImage::Format_ARGB32:
return Format_ARGB32;
case QImage::Format_ARGB32_Premultiplied:
return Format_ARGB32_Premultiplied;
case QImage::Format_RGB16:
return Format_RGB565;
case QImage::Format_ARGB8565_Premultiplied:
return Format_ARGB8565_Premultiplied;
case QImage::Format_RGB666:
case QImage::Format_ARGB6666_Premultiplied:
return Format_Invalid;
case QImage::Format_RGB555:
return Format_RGB555;
case QImage::Format_ARGB8555_Premultiplied:
return Format_Invalid;
case QImage::Format_RGB888:
return Format_RGB24;
case QImage::Format_RGB444:
case QImage::Format_ARGB4444_Premultiplied:
return Format_Invalid;
case QImage::NImageFormats:
return Format_Invalid;
}
return Format_Invalid;
}
/*!
Returns an image format equivalent to a video frame pixel \a format. If there is no equivalent
format QImage::Format_Invalid is returned instead.
\since 1.0
*/
QImage::Format QVideoFrame::imageFormatFromPixelFormat(PixelFormat format)
{
switch (format) {
case Format_Invalid:
return QImage::Format_Invalid;
case Format_ARGB32:
return QImage::Format_ARGB32;
case Format_ARGB32_Premultiplied:
return QImage::Format_ARGB32_Premultiplied;
case Format_RGB32:
return QImage::Format_RGB32;
case Format_RGB24:
return QImage::Format_RGB888;
case Format_RGB565:
return QImage::Format_RGB16;
case Format_RGB555:
return QImage::Format_RGB555;
case Format_ARGB8565_Premultiplied:
return QImage::Format_ARGB8565_Premultiplied;
case Format_BGRA32:
case Format_BGRA32_Premultiplied:
case Format_BGR32:
case Format_BGR24:
return QImage::Format_Invalid;
case Format_BGR565:
case Format_BGR555:
case Format_BGRA5658_Premultiplied:
case Format_AYUV444:
case Format_AYUV444_Premultiplied:
case Format_YUV444:
case Format_YUV420P:
case Format_YV12:
case Format_UYVY:
case Format_YUYV:
case Format_NV12:
case Format_NV21:
case Format_IMC1:
case Format_IMC2:
case Format_IMC3:
case Format_IMC4:
case Format_Y8:
case Format_Y16:
case Format_Jpeg:
case Format_CameraRaw:
case Format_AdobeDng:
return QImage::Format_Invalid;
case Format_User:
return QImage::Format_Invalid;
}
return QImage::Format_Invalid;
}
QT_END_NAMESPACE

View File

@@ -0,0 +1,174 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QVIDEOFRAME_H
#define QVIDEOFRAME_H
#include <QtCore/qmetatype.h>
#include <QtCore/qshareddata.h>
#include <QtGui/qimage.h>
#include <qabstractvideobuffer.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Multimedia)
class QSize;
class QVariant;
class QVideoFramePrivate;
class Q_MULTIMEDIA_EXPORT QVideoFrame
{
public:
enum FieldType
{
ProgressiveFrame,
TopField,
BottomField,
InterlacedFrame
};
enum PixelFormat
{
Format_Invalid,
Format_ARGB32,
Format_ARGB32_Premultiplied,
Format_RGB32,
Format_RGB24,
Format_RGB565,
Format_RGB555,
Format_ARGB8565_Premultiplied,
Format_BGRA32,
Format_BGRA32_Premultiplied,
Format_BGR32,
Format_BGR24,
Format_BGR565,
Format_BGR555,
Format_BGRA5658_Premultiplied,
Format_AYUV444,
Format_AYUV444_Premultiplied,
Format_YUV444,
Format_YUV420P,
Format_YV12,
Format_UYVY,
Format_YUYV,
Format_NV12,
Format_NV21,
Format_IMC1,
Format_IMC2,
Format_IMC3,
Format_IMC4,
Format_Y8,
Format_Y16,
Format_Jpeg,
Format_CameraRaw,
Format_AdobeDng,
Format_User = 1000
};
QVideoFrame();
QVideoFrame(QAbstractVideoBuffer *buffer, const QSize &size, PixelFormat format);
QVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format);
QVideoFrame(const QImage &image);
QVideoFrame(const QVideoFrame &other);
~QVideoFrame();
QVideoFrame &operator =(const QVideoFrame &other);
bool isValid() const;
PixelFormat pixelFormat() const;
QAbstractVideoBuffer::HandleType handleType() const;
QSize size() const;
int width() const;
int height() const;
FieldType fieldType() const;
void setFieldType(FieldType);
bool isMapped() const;
bool isReadable() const;
bool isWritable() const;
QAbstractVideoBuffer::MapMode mapMode() const;
bool map(QAbstractVideoBuffer::MapMode mode);
void unmap();
int bytesPerLine() const;
uchar *bits();
const uchar *bits() const;
int mappedBytes() const;
QVariant handle() const;
qint64 startTime() const;
void setStartTime(qint64 time);
qint64 endTime() const;
void setEndTime(qint64 time);
static PixelFormat pixelFormatFromImageFormat(QImage::Format format);
static QImage::Format imageFormatFromPixelFormat(PixelFormat format);
private:
QExplicitlySharedDataPointer<QVideoFramePrivate> d;
};
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QVideoFrame::FieldType)
Q_DECLARE_METATYPE(QVideoFrame::PixelFormat)
QT_END_HEADER
#endif

View File

@@ -0,0 +1,707 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qvideosurfaceformat.h"
#include <qdebug.h>
#include <qmetatype.h>
#include <qpair.h>
#include <qvariant.h>
#include <qvector.h>
QT_BEGIN_NAMESPACE
class QVideoSurfaceFormatPrivate : public QSharedData
{
public:
QVideoSurfaceFormatPrivate()
: pixelFormat(QVideoFrame::Format_Invalid)
, handleType(QAbstractVideoBuffer::NoHandle)
, scanLineDirection(QVideoSurfaceFormat::TopToBottom)
, pixelAspectRatio(1, 1)
, ycbcrColorSpace(QVideoSurfaceFormat::YCbCr_Undefined)
, frameRate(0.0)
{
}
QVideoSurfaceFormatPrivate(
const QSize &size,
QVideoFrame::PixelFormat format,
QAbstractVideoBuffer::HandleType type)
: pixelFormat(format)
, handleType(type)
, scanLineDirection(QVideoSurfaceFormat::TopToBottom)
, frameSize(size)
, pixelAspectRatio(1, 1)
, ycbcrColorSpace(QVideoSurfaceFormat::YCbCr_Undefined)
, viewport(QPoint(0, 0), size)
, frameRate(0.0)
{
}
QVideoSurfaceFormatPrivate(const QVideoSurfaceFormatPrivate &other)
: QSharedData(other)
, pixelFormat(other.pixelFormat)
, handleType(other.handleType)
, scanLineDirection(other.scanLineDirection)
, frameSize(other.frameSize)
, pixelAspectRatio(other.pixelAspectRatio)
, ycbcrColorSpace(other.ycbcrColorSpace)
, viewport(other.viewport)
, frameRate(other.frameRate)
, propertyNames(other.propertyNames)
, propertyValues(other.propertyValues)
{
}
bool operator ==(const QVideoSurfaceFormatPrivate &other) const
{
if (pixelFormat == other.pixelFormat
&& handleType == other.handleType
&& scanLineDirection == other.scanLineDirection
&& frameSize == other.frameSize
&& pixelAspectRatio == other.pixelAspectRatio
&& viewport == other.viewport
&& frameRatesEqual(frameRate, other.frameRate)
&& ycbcrColorSpace == other.ycbcrColorSpace
&& propertyNames.count() == other.propertyNames.count()) {
for (int i = 0; i < propertyNames.count(); ++i) {
int j = other.propertyNames.indexOf(propertyNames.at(i));
if (j == -1 || propertyValues.at(i) != other.propertyValues.at(j))
return false;
}
return true;
} else {
return false;
}
}
inline static bool frameRatesEqual(qreal r1, qreal r2)
{
return qAbs(r1 - r2) <= 0.00001 * qMin(qAbs(r1), qAbs(r2));
}
QVideoFrame::PixelFormat pixelFormat;
QAbstractVideoBuffer::HandleType handleType;
QVideoSurfaceFormat::Direction scanLineDirection;
QSize frameSize;
QSize pixelAspectRatio;
QVideoSurfaceFormat::YCbCrColorSpace ycbcrColorSpace;
QRect viewport;
qreal frameRate;
QList<QByteArray> propertyNames;
QList<QVariant> propertyValues;
};
/*!
\class QVideoSurfaceFormat
\brief The QVideoSurfaceFormat class specifies the stream format of a video presentation
surface.
\since 1.0
\inmodule QtMultimedia
A video surface presents a stream of video frames. The surface's format describes the type of
the frames and determines how they should be presented.
The core properties of a video stream required to setup a video surface are the pixel format
given by pixelFormat(), and the frame dimensions given by frameSize().
If the surface is to present frames using a frame's handle a surface format will also include
a handle type which is given by the handleType() function.
The region of a frame that is actually displayed on a video surface is given by the viewport().
A stream may have a viewport less than the entire region of a frame to allow for videos smaller
than the nearest optimal size of a video frame. For example the width of a frame may be
extended so that the start of each scan line is eight byte aligned.
Other common properties are the pixelAspectRatio(), scanLineDirection(), and frameRate().
Additionally a stream may have some additional type specific properties which are listed by the
dynamicPropertyNames() function and can be accessed using the property(), and setProperty()
functions.
*/
/*!
\enum QVideoSurfaceFormat::Direction
Enumerates the layout direction of video scan lines.
\value TopToBottom Scan lines are arranged from the top of the frame to the bottom.
\value BottomToTop Scan lines are arranged from the bottom of the frame to the top.
*/
/*!
\enum QVideoSurfaceFormat::YCbCrColorSpace
Enumerates the Y'CbCr color space of video frames.
\value YCbCr_Undefined
No color space is specified.
\value YCbCr_BT601
A Y'CbCr color space defined by ITU-R recommendation BT.601
with Y value range from 16 to 235, and Cb/Cr range from 16 to 240.
Used in standard definition video.
\value YCbCr_BT709
A Y'CbCr color space defined by ITU-R BT.709 with the same values range as YCbCr_BT601. Used
for HDTV.
\value YCbCr_xvYCC601
The BT.601 color space with the value range extended to 0 to 255.
It is backward compatibile with BT.601 and uses values outside BT.601 range to represent a
wider range of colors.
\value YCbCr_xvYCC709
The BT.709 color space with the value range extended to 0 to 255.
\value YCbCr_JPEG
The full range Y'CbCr color space used in JPEG files.
*/
/*!
Constructs a null video stream format.
*/
QVideoSurfaceFormat::QVideoSurfaceFormat()
: d(new QVideoSurfaceFormatPrivate)
{
}
/*!
Contructs a description of stream which receives stream of \a type buffers with given frame
\a size and pixel \a format.
\since 1.0
*/
QVideoSurfaceFormat::QVideoSurfaceFormat(
const QSize& size, QVideoFrame::PixelFormat format, QAbstractVideoBuffer::HandleType type)
: d(new QVideoSurfaceFormatPrivate(size, format, type))
{
}
/*!
Constructs a copy of \a other.
\since 1.0
*/
QVideoSurfaceFormat::QVideoSurfaceFormat(const QVideoSurfaceFormat &other)
: d(other.d)
{
}
/*!
Assigns the values of \a other to this object.
\since 1.0
*/
QVideoSurfaceFormat &QVideoSurfaceFormat::operator =(const QVideoSurfaceFormat &other)
{
d = other.d;
return *this;
}
/*!
Destroys a video stream description.
*/
QVideoSurfaceFormat::~QVideoSurfaceFormat()
{
}
/*!
Identifies if a video surface format has a valid pixel format and frame size.
Returns true if the format is valid, and false otherwise.
\since 1.0
*/
bool QVideoSurfaceFormat::isValid() const
{
return d->pixelFormat != QVideoFrame::Format_Invalid && d->frameSize.isValid();
}
/*!
Returns true if \a other is the same as this video format, and false if they are different.
\since 1.0
*/
bool QVideoSurfaceFormat::operator ==(const QVideoSurfaceFormat &other) const
{
return d == other.d || *d == *other.d;
}
/*!
Returns true if \a other is different to a video format, and false if they are the same.
\since 1.0
*/
bool QVideoSurfaceFormat::operator !=(const QVideoSurfaceFormat &other) const
{
return d != other.d && !(*d == *other.d);
}
/*!
Returns the pixel format of frames in a video stream.
\since 1.0
*/
QVideoFrame::PixelFormat QVideoSurfaceFormat::pixelFormat() const
{
return d->pixelFormat;
}
/*!
Returns the type of handle the surface uses to present the frame data.
If the handle type is QAbstractVideoBuffer::NoHandle buffers with any handle type are valid
provided they can be \l {QAbstractVideoBuffer::map()}{mapped} with the
QAbstractVideoBuffer::ReadOnly flag. If the handleType() is not QAbstractVideoBuffer::NoHandle
then the handle type of the buffer must be the same as that of the surface format.
\since 1.0
*/
QAbstractVideoBuffer::HandleType QVideoSurfaceFormat::handleType() const
{
return d->handleType;
}
/*!
Returns the dimensions of frames in a video stream.
\sa frameWidth(), frameHeight()
\since 1.0
*/
QSize QVideoSurfaceFormat::frameSize() const
{
return d->frameSize;
}
/*!
Returns the width of frames in a video stream.
\sa frameSize(), frameHeight()
\since 1.0
*/
int QVideoSurfaceFormat::frameWidth() const
{
return d->frameSize.width();
}
/*!
Returns the height of frame in a video stream.
\since 1.0
*/
int QVideoSurfaceFormat::frameHeight() const
{
return d->frameSize.height();
}
/*!
Sets the size of frames in a video stream to \a size.
This will reset the viewport() to fill the entire frame.
\since 1.0
*/
void QVideoSurfaceFormat::setFrameSize(const QSize &size)
{
d->frameSize = size;
d->viewport = QRect(QPoint(0, 0), size);
}
/*!
\overload
Sets the \a width and \a height of frames in a video stream.
This will reset the viewport() to fill the entire frame.
\since 1.0
*/
void QVideoSurfaceFormat::setFrameSize(int width, int height)
{
d->frameSize = QSize(width, height);
d->viewport = QRect(0, 0, width, height);
}
/*!
Returns the viewport of a video stream.
The viewport is the region of a video frame that is actually displayed.
By default the viewport covers an entire frame.
\since 1.0
*/
QRect QVideoSurfaceFormat::viewport() const
{
return d->viewport;
}
/*!
Sets the viewport of a video stream to \a viewport.
\since 1.0
*/
void QVideoSurfaceFormat::setViewport(const QRect &viewport)
{
d->viewport = viewport;
}
/*!
Returns the direction of scan lines.
\since 1.0
*/
QVideoSurfaceFormat::Direction QVideoSurfaceFormat::scanLineDirection() const
{
return d->scanLineDirection;
}
/*!
Sets the \a direction of scan lines.
\since 1.0
*/
void QVideoSurfaceFormat::setScanLineDirection(Direction direction)
{
d->scanLineDirection = direction;
}
/*!
Returns the frame rate of a video stream in frames per second.
\since 1.0
*/
qreal QVideoSurfaceFormat::frameRate() const
{
return d->frameRate;
}
/*!
Sets the frame \a rate of a video stream in frames per second.
\since 1.0
*/
void QVideoSurfaceFormat::setFrameRate(qreal rate)
{
d->frameRate = rate;
}
/*!
Returns a video stream's pixel aspect ratio.
\since 1.0
*/
QSize QVideoSurfaceFormat::pixelAspectRatio() const
{
return d->pixelAspectRatio;
}
/*!
Sets a video stream's pixel aspect \a ratio.
\since 1.0
*/
void QVideoSurfaceFormat::setPixelAspectRatio(const QSize &ratio)
{
d->pixelAspectRatio = ratio;
}
/*!
\overload
Sets the \a horizontal and \a vertical elements of a video stream's pixel aspect ratio.
\since 1.0
*/
void QVideoSurfaceFormat::setPixelAspectRatio(int horizontal, int vertical)
{
d->pixelAspectRatio = QSize(horizontal, vertical);
}
/*!
Returns the Y'CbCr color space of a video stream.
\since 1.0
*/
QVideoSurfaceFormat::YCbCrColorSpace QVideoSurfaceFormat::yCbCrColorSpace() const
{
return d->ycbcrColorSpace;
}
/*!
Sets the Y'CbCr color \a space of a video stream.
It is only used with raw YUV frame types.
\since 1.0
*/
void QVideoSurfaceFormat::setYCbCrColorSpace(QVideoSurfaceFormat::YCbCrColorSpace space)
{
d->ycbcrColorSpace = space;
}
/*!
Returns a suggested size in pixels for the video stream.
This is the size of the viewport scaled according to the pixel aspect ratio.
\since 1.0
*/
QSize QVideoSurfaceFormat::sizeHint() const
{
QSize size = d->viewport.size();
if (d->pixelAspectRatio.height() != 0)
size.setWidth(size.width() * d->pixelAspectRatio.width() / d->pixelAspectRatio.height());
return size;
}
/*!
Returns a list of video format dynamic property names.
\since 1.0
*/
QList<QByteArray> QVideoSurfaceFormat::propertyNames() const
{
return (QList<QByteArray>()
<< "handleType"
<< "pixelFormat"
<< "frameSize"
<< "frameWidth"
<< "viewport"
<< "scanLineDirection"
<< "frameRate"
<< "pixelAspectRatio"
<< "sizeHint"
<< "yCbCrColorSpace")
+ d->propertyNames;
}
/*!
Returns the value of the video format's \a name property.
\since 1.0
*/
QVariant QVideoSurfaceFormat::property(const char *name) const
{
if (qstrcmp(name, "handleType") == 0) {
return qVariantFromValue(d->handleType);
} else if (qstrcmp(name, "pixelFormat") == 0) {
return qVariantFromValue(d->pixelFormat);
} else if (qstrcmp(name, "handleType") == 0) {
return qVariantFromValue(d->handleType);
} else if (qstrcmp(name, "frameSize") == 0) {
return d->frameSize;
} else if (qstrcmp(name, "frameWidth") == 0) {
return d->frameSize.width();
} else if (qstrcmp(name, "frameHeight") == 0) {
return d->frameSize.height();
} else if (qstrcmp(name, "viewport") == 0) {
return d->viewport;
} else if (qstrcmp(name, "scanLineDirection") == 0) {
return qVariantFromValue(d->scanLineDirection);
} else if (qstrcmp(name, "frameRate") == 0) {
return qVariantFromValue(d->frameRate);
} else if (qstrcmp(name, "pixelAspectRatio") == 0) {
return qVariantFromValue(d->pixelAspectRatio);
} else if (qstrcmp(name, "sizeHint") == 0) {
return sizeHint();
} else if (qstrcmp(name, "yCbCrColorSpace") == 0) {
return qVariantFromValue(d->ycbcrColorSpace);
} else {
int id = 0;
for (; id < d->propertyNames.count() && d->propertyNames.at(id) != name; ++id) {}
return id < d->propertyValues.count()
? d->propertyValues.at(id)
: QVariant();
}
}
/*!
Sets the video format's \a name property to \a value.
Trying to set a read only property will be ignored.
\since 1.0
*/
void QVideoSurfaceFormat::setProperty(const char *name, const QVariant &value)
{
if (qstrcmp(name, "handleType") == 0) {
// read only.
} else if (qstrcmp(name, "pixelFormat") == 0) {
// read only.
} else if (qstrcmp(name, "frameSize") == 0) {
if (qVariantCanConvert<QSize>(value)) {
d->frameSize = qvariant_cast<QSize>(value);
d->viewport = QRect(QPoint(0, 0), d->frameSize);
}
} else if (qstrcmp(name, "frameWidth") == 0) {
// read only.
} else if (qstrcmp(name, "frameHeight") == 0) {
// read only.
} else if (qstrcmp(name, "viewport") == 0) {
if (qVariantCanConvert<QRect>(value))
d->viewport = qvariant_cast<QRect>(value);
} else if (qstrcmp(name, "scanLineDirection") == 0) {
if (qVariantCanConvert<Direction>(value))
d->scanLineDirection = qvariant_cast<Direction>(value);
} else if (qstrcmp(name, "frameRate") == 0) {
if (qVariantCanConvert<qreal>(value))
d->frameRate = qvariant_cast<qreal>(value);
} else if (qstrcmp(name, "pixelAspectRatio") == 0) {
if (qVariantCanConvert<QSize>(value))
d->pixelAspectRatio = qvariant_cast<QSize>(value);
} else if (qstrcmp(name, "sizeHint") == 0) {
// read only.
} else if (qstrcmp(name, "yCbCrColorSpace") == 0) {
if (qVariantCanConvert<YCbCrColorSpace>(value))
d->ycbcrColorSpace = qvariant_cast<YCbCrColorSpace>(value);
} else {
int id = 0;
for (; id < d->propertyNames.count() && d->propertyNames.at(id) != name; ++id) {}
if (id < d->propertyValues.count()) {
if (value.isNull()) {
d->propertyNames.removeAt(id);
d->propertyValues.removeAt(id);
} else {
d->propertyValues[id] = value;
}
} else if (!value.isNull()) {
d->propertyNames.append(QByteArray(name));
d->propertyValues.append(value);
}
}
}
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QVideoSurfaceFormat &f)
{
QString typeName;
switch (f.pixelFormat()) {
case QVideoFrame::Format_Invalid:
typeName = QLatin1String("Format_Invalid");
break;
case QVideoFrame::Format_ARGB32:
typeName = QLatin1String("Format_ARGB32");
break;
case QVideoFrame::Format_ARGB32_Premultiplied:
typeName = QLatin1String("Format_ARGB32_Premultiplied");
break;
case QVideoFrame::Format_RGB32:
typeName = QLatin1String("Format_RGB32");
break;
case QVideoFrame::Format_RGB24:
typeName = QLatin1String("Format_RGB24");
break;
case QVideoFrame::Format_RGB565:
typeName = QLatin1String("Format_RGB565");
break;
case QVideoFrame::Format_RGB555:
typeName = QLatin1String("Format_RGB555");
break;
case QVideoFrame::Format_ARGB8565_Premultiplied:
typeName = QLatin1String("Format_ARGB8565_Premultiplied");
break;
case QVideoFrame::Format_BGRA32:
typeName = QLatin1String("Format_BGRA32");
break;
case QVideoFrame::Format_BGRA32_Premultiplied:
typeName = QLatin1String("Format_BGRA32_Premultiplied");
break;
case QVideoFrame::Format_BGR32:
typeName = QLatin1String("Format_BGR32");
break;
case QVideoFrame::Format_BGR24:
typeName = QLatin1String("Format_BGR24");
break;
case QVideoFrame::Format_BGR565:
typeName = QLatin1String("Format_BGR565");
break;
case QVideoFrame::Format_BGR555:
typeName = QLatin1String("Format_BGR555");
break;
case QVideoFrame::Format_BGRA5658_Premultiplied:
typeName = QLatin1String("Format_BGRA5658_Premultiplied");
break;
case QVideoFrame::Format_AYUV444:
typeName = QLatin1String("Format_AYUV444");
break;
case QVideoFrame::Format_AYUV444_Premultiplied:
typeName = QLatin1String("Format_AYUV444_Premultiplied");
break;
case QVideoFrame::Format_YUV444:
typeName = QLatin1String("Format_YUV444");
break;
case QVideoFrame::Format_YUV420P:
typeName = QLatin1String("Format_YUV420P");
break;
case QVideoFrame::Format_YV12:
typeName = QLatin1String("Format_YV12");
break;
case QVideoFrame::Format_UYVY:
typeName = QLatin1String("Format_UYVY");
break;
case QVideoFrame::Format_YUYV:
typeName = QLatin1String("Format_YUYV");
break;
case QVideoFrame::Format_NV12:
typeName = QLatin1String("Format_NV12");
break;
case QVideoFrame::Format_NV21:
typeName = QLatin1String("Format_NV21");
break;
case QVideoFrame::Format_IMC1:
typeName = QLatin1String("Format_IMC1");
break;
case QVideoFrame::Format_IMC2:
typeName = QLatin1String("Format_IMC2");
break;
case QVideoFrame::Format_IMC3:
typeName = QLatin1String("Format_IMC3");
break;
case QVideoFrame::Format_IMC4:
typeName = QLatin1String("Format_IMC4");
break;
case QVideoFrame::Format_Y8:
typeName = QLatin1String("Format_Y8");
break;
case QVideoFrame::Format_Y16:
typeName = QLatin1String("Format_Y16");
break;
default:
typeName = QString(QLatin1String("UserType(%1)" )).arg(int(f.pixelFormat()));
}
dbg.nospace() << "QVideoSurfaceFormat(" << typeName;
dbg.nospace() << ", " << f.frameSize();
dbg.nospace() << ", viewport=" << f.viewport();
dbg.nospace() << ", pixelAspectRatio=" << f.pixelAspectRatio();
dbg.nospace() << ")";
foreach(const QByteArray& propertyName, f.propertyNames())
dbg << "\n " << propertyName.data() << " = " << f.property(propertyName.data());
return dbg.space();
}
#endif
QT_END_NAMESPACE

View File

@@ -0,0 +1,148 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QVIDEOSURFACEFORMAT_H
#define QVIDEOSURFACEFORMAT_H
#include <QtCore/qlist.h>
#include <QtCore/qpair.h>
#include <QtCore/qshareddata.h>
#include <QtCore/qsize.h>
#include <QtGui/qimage.h>
#include <qvideoframe.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Multimedia)
class QDebug;
class QVideoSurfaceFormatPrivate;
class Q_MULTIMEDIA_EXPORT QVideoSurfaceFormat
{
public:
enum Direction
{
TopToBottom,
BottomToTop
};
enum YCbCrColorSpace
{
YCbCr_Undefined,
YCbCr_BT601,
YCbCr_BT709,
YCbCr_xvYCC601,
YCbCr_xvYCC709,
YCbCr_JPEG,
#ifndef qdoc
YCbCr_CustomMatrix
#endif
};
QVideoSurfaceFormat();
QVideoSurfaceFormat(
const QSize &size,
QVideoFrame::PixelFormat pixelFormat,
QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle);
QVideoSurfaceFormat(const QVideoSurfaceFormat &format);
~QVideoSurfaceFormat();
QVideoSurfaceFormat &operator =(const QVideoSurfaceFormat &format);
bool operator ==(const QVideoSurfaceFormat &format) const;
bool operator !=(const QVideoSurfaceFormat &format) const;
bool isValid() const;
QVideoFrame::PixelFormat pixelFormat() const;
QAbstractVideoBuffer::HandleType handleType() const;
QSize frameSize() const;
void setFrameSize(const QSize &size);
void setFrameSize(int width, int height);
int frameWidth() const;
int frameHeight() const;
QRect viewport() const;
void setViewport(const QRect &viewport);
Direction scanLineDirection() const;
void setScanLineDirection(Direction direction);
qreal frameRate() const;
void setFrameRate(qreal rate);
QSize pixelAspectRatio() const;
void setPixelAspectRatio(const QSize &ratio);
void setPixelAspectRatio(int width, int height);
YCbCrColorSpace yCbCrColorSpace() const;
void setYCbCrColorSpace(YCbCrColorSpace colorSpace);
QSize sizeHint() const;
QList<QByteArray> propertyNames() const;
QVariant property(const char *name) const;
void setProperty(const char *name, const QVariant &value);
private:
QSharedDataPointer<QVideoSurfaceFormatPrivate> d;
};
#ifndef QT_NO_DEBUG_STREAM
Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QVideoSurfaceFormat &);
#endif
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QVideoSurfaceFormat::Direction)
Q_DECLARE_METATYPE(QVideoSurfaceFormat::YCbCrColorSpace)
QT_END_HEADER
#endif

View File

@@ -0,0 +1,22 @@
INCLUDEPATH += video
PUBLIC_HEADERS += \
video/qabstractvideobuffer.h \
video/qabstractvideosurface.h \
video/qvideoframe.h \
video/qvideosurfaceformat.h
PRIVATE_HEADERS += \
video/qabstractvideobuffer_p.h \
video/qimagevideobuffer_p.h \
video/qmemoryvideobuffer_p.h
SOURCES += \
video/qabstractvideobuffer.cpp \
video/qabstractvideosurface.cpp \
video/qimagevideobuffer.cpp \
video/qmemoryvideobuffer.cpp \
video/qvideoframe.cpp \
video/qvideosurfaceformat.cpp