| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtMultimedia module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 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 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at qt-info@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qabstractvideobuffer_p.h"
|
|---|
| 43 |
|
|---|
| 44 | #include <qvariant.h>
|
|---|
| 45 |
|
|---|
| 46 | QT_BEGIN_NAMESPACE
|
|---|
| 47 |
|
|---|
| 48 | /*!
|
|---|
| 49 | \class QAbstractVideoBuffer
|
|---|
| 50 | \brief The QAbstractVideoBuffer class is an abstraction for video data.
|
|---|
| 51 | \since 4.6
|
|---|
| 52 |
|
|---|
| 53 | The QVideoFrame class makes use of a QAbstractVideoBuffer internally to reference a buffer of
|
|---|
| 54 | video data. Creating a subclass of QAbstractVideoBuffer will allow you to construct video
|
|---|
| 55 | frames from preallocated or static buffers.
|
|---|
| 56 |
|
|---|
| 57 | The contents of a buffer can be accessed by mapping the buffer to memory using the map()
|
|---|
| 58 | function which returns a pointer to memory containing the contents of the the video buffer.
|
|---|
| 59 | The memory returned by map() is released by calling the unmap() function.
|
|---|
| 60 |
|
|---|
| 61 | The handle() of a buffer may also be used to manipulate it's contents using type specific APIs.
|
|---|
| 62 | The type of a buffer's handle is given by the handleType() function.
|
|---|
| 63 |
|
|---|
| 64 | \sa QVideoFrame
|
|---|
| 65 | */
|
|---|
| 66 |
|
|---|
| 67 | /*!
|
|---|
| 68 | \enum QAbstractVideoBuffer::HandleType
|
|---|
| 69 |
|
|---|
| 70 | Identifies the type of a video buffers handle.
|
|---|
| 71 |
|
|---|
| 72 | \value NoHandle The buffer has no handle, its data can only be accessed by mapping the buffer.
|
|---|
| 73 | \value GLTextureHandle The handle of the buffer is an OpenGL texture ID.
|
|---|
| 74 | \value UserHandle Start value for user defined handle types.
|
|---|
| 75 |
|
|---|
| 76 | \sa handleType()
|
|---|
| 77 | */
|
|---|
| 78 |
|
|---|
| 79 | /*!
|
|---|
| 80 | \enum QAbstractVideoBuffer::MapMode
|
|---|
| 81 |
|
|---|
| 82 | Enumerates how a video buffer's data is mapped to memory.
|
|---|
| 83 |
|
|---|
| 84 | \value NotMapped The video buffer has is not mapped to memory.
|
|---|
| 85 | \value ReadOnly The mapped memory is populated with data from the video buffer when mapped, but
|
|---|
| 86 | the content of the mapped memory may be discarded when unmapped.
|
|---|
| 87 | \value WriteOnly The mapped memory in unitialized when mapped, and the content will be used to
|
|---|
| 88 | populate the video buffer when unmapped.
|
|---|
| 89 | \value ReadWrite The mapped memory is populated with data from the video buffer, and the
|
|---|
| 90 | video buffer is repopulated with the content of the mapped memory.
|
|---|
| 91 |
|
|---|
| 92 | \sa mapMode(), map()
|
|---|
| 93 | */
|
|---|
| 94 |
|
|---|
| 95 | /*!
|
|---|
| 96 | Constructs an abstract video buffer of the given \a type.
|
|---|
| 97 | */
|
|---|
| 98 |
|
|---|
| 99 | QAbstractVideoBuffer::QAbstractVideoBuffer(HandleType type)
|
|---|
| 100 | : d_ptr(new QAbstractVideoBufferPrivate)
|
|---|
| 101 | {
|
|---|
| 102 | Q_D(QAbstractVideoBuffer);
|
|---|
| 103 |
|
|---|
| 104 | d->handleType = type;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | /*!
|
|---|
| 108 | \internal
|
|---|
| 109 | */
|
|---|
| 110 |
|
|---|
| 111 | QAbstractVideoBuffer::QAbstractVideoBuffer(QAbstractVideoBufferPrivate &dd, HandleType type)
|
|---|
| 112 | : d_ptr(&dd)
|
|---|
| 113 | {
|
|---|
| 114 | Q_D(QAbstractVideoBuffer);
|
|---|
| 115 |
|
|---|
| 116 | d->handleType = type;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | /*!
|
|---|
| 120 | Destroys an abstract video buffer.
|
|---|
| 121 | */
|
|---|
| 122 |
|
|---|
| 123 | QAbstractVideoBuffer::~QAbstractVideoBuffer()
|
|---|
| 124 | {
|
|---|
| 125 | delete d_ptr;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | /*!
|
|---|
| 129 | Returns the type of a video buffer's handle.
|
|---|
| 130 |
|
|---|
| 131 | \sa handle()
|
|---|
| 132 | */
|
|---|
| 133 |
|
|---|
| 134 | QAbstractVideoBuffer::HandleType QAbstractVideoBuffer::handleType() const
|
|---|
| 135 | {
|
|---|
| 136 | return d_func()->handleType;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | /*!
|
|---|
| 140 | \fn QAbstractVideoBuffer::mapMode() const
|
|---|
| 141 |
|
|---|
| 142 | Returns the mode a video buffer is mapped in.
|
|---|
| 143 |
|
|---|
| 144 | \sa map()
|
|---|
| 145 | */
|
|---|
| 146 |
|
|---|
| 147 | /*!
|
|---|
| 148 | \fn QAbstractVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine)
|
|---|
| 149 |
|
|---|
| 150 | Maps the contents of a video buffer to memory.
|
|---|
| 151 |
|
|---|
| 152 | The map \a mode indicates whether the contents of the mapped memory should be read from and/or
|
|---|
| 153 | written to the buffer. If the map mode includes the QAbstractVideoBuffer::ReadOnly flag the
|
|---|
| 154 | mapped memory will be populated with the content of the video buffer when mapped. If the map
|
|---|
| 155 | mode includes the QAbstractVideoBuffer::WriteOnly flag the content of the mapped memory will be
|
|---|
| 156 | persisted in the buffer when unmapped.
|
|---|
| 157 |
|
|---|
| 158 | When access to the data is no longer needed be sure to call the unmap() function to release the
|
|---|
| 159 | mapped memory.
|
|---|
| 160 |
|
|---|
| 161 | Returns a pointer to the mapped memory region, or a null pointer if the mapping failed. The
|
|---|
| 162 | size in bytes of the mapped memory region is returned in \a numBytes, and the line stride in \a
|
|---|
| 163 | bytesPerLine.
|
|---|
| 164 |
|
|---|
| 165 | When access to the data is no longer needed be sure to unmap() the buffer.
|
|---|
| 166 |
|
|---|
| 167 | \note Writing to memory that is mapped as read-only is undefined, and may result in changes
|
|---|
| 168 | to shared data.
|
|---|
| 169 |
|
|---|
| 170 | \sa unmap(), mapMode()
|
|---|
| 171 | */
|
|---|
| 172 |
|
|---|
| 173 | /*!
|
|---|
| 174 | \fn QAbstractVideoBuffer::unmap()
|
|---|
| 175 |
|
|---|
| 176 | Releases the memory mapped by the map() function
|
|---|
| 177 |
|
|---|
| 178 | If the \l {QAbstractVideoBuffer::MapMode}{MapMode} included the QAbstractVideoBuffer::WriteOnly
|
|---|
| 179 | flag this will persist the current content of the mapped memory to the video frame.
|
|---|
| 180 |
|
|---|
| 181 | \sa map()
|
|---|
| 182 | */
|
|---|
| 183 |
|
|---|
| 184 | /*!
|
|---|
| 185 | Returns a type specific handle to the data buffer.
|
|---|
| 186 |
|
|---|
| 187 | The type of the handle is given by handleType() function.
|
|---|
| 188 |
|
|---|
| 189 | \sa handleType()
|
|---|
| 190 | */
|
|---|
| 191 |
|
|---|
| 192 | QVariant QAbstractVideoBuffer::handle() const
|
|---|
| 193 | {
|
|---|
| 194 | return QVariant();
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 | QT_END_NAMESPACE
|
|---|