| 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 | \preliminary | 
|---|
| 52 | \since 4.6 | 
|---|
| 53 |  | 
|---|
| 54 | The QVideoFrame class makes use of a QAbstractVideoBuffer internally to reference a buffer of | 
|---|
| 55 | video data.  Creating a subclass of QAbstractVideoBuffer will allow you to construct video | 
|---|
| 56 | frames from preallocated or static buffers. | 
|---|
| 57 |  | 
|---|
| 58 | The contents of a buffer can be accessed by mapping the buffer to memory using the map() | 
|---|
| 59 | function which returns a pointer to memory containing the contents of the the video buffer. | 
|---|
| 60 | The memory returned by map() is released by calling the unmap() function. | 
|---|
| 61 |  | 
|---|
| 62 | The handle() of a buffer may also be used to manipulate it's contents using type specific APIs. | 
|---|
| 63 | The type of a buffer's handle is given by the handleType() function. | 
|---|
| 64 |  | 
|---|
| 65 | \sa QVideoFrame | 
|---|
| 66 | */ | 
|---|
| 67 |  | 
|---|
| 68 | /*! | 
|---|
| 69 | \enum QAbstractVideoBuffer::HandleType | 
|---|
| 70 |  | 
|---|
| 71 | Identifies the type of a video buffers handle. | 
|---|
| 72 |  | 
|---|
| 73 | \value NoHandle The buffer has no handle, its data can only be accessed by mapping the buffer. | 
|---|
| 74 | \value GLTextureHandle The handle of the buffer is an OpenGL texture ID. | 
|---|
| 75 | \value UserHandle Start value for user defined handle types. | 
|---|
| 76 |  | 
|---|
| 77 | \sa handleType() | 
|---|
| 78 | */ | 
|---|
| 79 |  | 
|---|
| 80 | /*! | 
|---|
| 81 | \enum QAbstractVideoBuffer::MapMode | 
|---|
| 82 |  | 
|---|
| 83 | Enumerates how a video buffer's data is mapped to memory. | 
|---|
| 84 |  | 
|---|
| 85 | \value NotMapped The video buffer has is not mapped to memory. | 
|---|
| 86 | \value ReadOnly The mapped memory is populated with data from the video buffer when mapped, but | 
|---|
| 87 | the content of the mapped memory may be discarded when unmapped. | 
|---|
| 88 | \value WriteOnly The mapped memory in unitialized when mapped, and the content will be used to | 
|---|
| 89 | populate the video buffer when unmapped. | 
|---|
| 90 | \value ReadWrite The mapped memory is populated with data from the video buffer, and the | 
|---|
| 91 | video buffer is repopulated with the content of the mapped memory. | 
|---|
| 92 |  | 
|---|
| 93 | \sa mapMode(), map() | 
|---|
| 94 | */ | 
|---|
| 95 |  | 
|---|
| 96 | /*! | 
|---|
| 97 | Constructs an abstract video buffer of the given \a type. | 
|---|
| 98 | */ | 
|---|
| 99 |  | 
|---|
| 100 | QAbstractVideoBuffer::QAbstractVideoBuffer(HandleType type) | 
|---|
| 101 | : d_ptr(new QAbstractVideoBufferPrivate) | 
|---|
| 102 | { | 
|---|
| 103 | Q_D(QAbstractVideoBuffer); | 
|---|
| 104 |  | 
|---|
| 105 | d->handleType = type; | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|
| 108 | /*! | 
|---|
| 109 | \internal | 
|---|
| 110 | */ | 
|---|
| 111 |  | 
|---|
| 112 | QAbstractVideoBuffer::QAbstractVideoBuffer(QAbstractVideoBufferPrivate &dd, HandleType type) | 
|---|
| 113 | : d_ptr(&dd) | 
|---|
| 114 | { | 
|---|
| 115 | Q_D(QAbstractVideoBuffer); | 
|---|
| 116 |  | 
|---|
| 117 | d->handleType = type; | 
|---|
| 118 | } | 
|---|
| 119 |  | 
|---|
| 120 | /*! | 
|---|
| 121 | Destroys an abstract video buffer. | 
|---|
| 122 | */ | 
|---|
| 123 |  | 
|---|
| 124 | QAbstractVideoBuffer::~QAbstractVideoBuffer() | 
|---|
| 125 | { | 
|---|
| 126 | delete d_ptr; | 
|---|
| 127 | } | 
|---|
| 128 |  | 
|---|
| 129 | /*! | 
|---|
| 130 | Returns the type of a video buffer's handle. | 
|---|
| 131 |  | 
|---|
| 132 | \sa handle() | 
|---|
| 133 | */ | 
|---|
| 134 |  | 
|---|
| 135 | QAbstractVideoBuffer::HandleType QAbstractVideoBuffer::handleType() const | 
|---|
| 136 | { | 
|---|
| 137 | return d_func()->handleType; | 
|---|
| 138 | } | 
|---|
| 139 |  | 
|---|
| 140 | /*! | 
|---|
| 141 | \fn QAbstractVideoBuffer::mapMode() const | 
|---|
| 142 |  | 
|---|
| 143 | Returns the mode a video buffer is mapped in. | 
|---|
| 144 |  | 
|---|
| 145 | \sa map() | 
|---|
| 146 | */ | 
|---|
| 147 |  | 
|---|
| 148 | /*! | 
|---|
| 149 | \fn QAbstractVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine) | 
|---|
| 150 |  | 
|---|
| 151 | Maps the contents of a video buffer to memory. | 
|---|
| 152 |  | 
|---|
| 153 | The map \a mode indicates whether the contents of the mapped memory should be read from and/or | 
|---|
| 154 | written to the buffer.  If the map mode includes the QAbstractVideoBuffer::ReadOnly flag the | 
|---|
| 155 | mapped memory will be populated with the content of the video buffer when mapped.  If the map | 
|---|
| 156 | mode includes the QAbstractVideoBuffer::WriteOnly flag the content of the mapped memory will be | 
|---|
| 157 | persisted in the buffer when unmapped. | 
|---|
| 158 |  | 
|---|
| 159 | When access to the data is no longer needed be sure to call the unmap() function to release the | 
|---|
| 160 | mapped memory. | 
|---|
| 161 |  | 
|---|
| 162 | Returns a pointer to the mapped memory region, or a null pointer if the mapping failed.  The | 
|---|
| 163 | size in bytes of the mapped memory region is returned in \a numBytes, and the line stride in \a | 
|---|
| 164 | bytesPerLine. | 
|---|
| 165 |  | 
|---|
| 166 | When access to the data is no longer needed be sure to unmap() the buffer. | 
|---|
| 167 |  | 
|---|
| 168 | \note Writing to memory that is mapped as read-only is undefined, and may result in changes | 
|---|
| 169 | to shared data. | 
|---|
| 170 |  | 
|---|
| 171 | \sa unmap(), mapMode() | 
|---|
| 172 | */ | 
|---|
| 173 |  | 
|---|
| 174 | /*! | 
|---|
| 175 | \fn QAbstractVideoBuffer::unmap() | 
|---|
| 176 |  | 
|---|
| 177 | Releases the memory mapped by the map() function | 
|---|
| 178 |  | 
|---|
| 179 | If the \l {QAbstractVideoBuffer::MapMode}{MapMode} included the QAbstractVideoBuffer::WriteOnly | 
|---|
| 180 | flag this will persist the current content of the mapped memory to the video frame. | 
|---|
| 181 |  | 
|---|
| 182 | \sa map() | 
|---|
| 183 | */ | 
|---|
| 184 |  | 
|---|
| 185 | /*! | 
|---|
| 186 | Returns a type specific handle to the data buffer. | 
|---|
| 187 |  | 
|---|
| 188 | The type of the handle is given by handleType() function. | 
|---|
| 189 |  | 
|---|
| 190 | \sa handleType() | 
|---|
| 191 | */ | 
|---|
| 192 |  | 
|---|
| 193 | QVariant QAbstractVideoBuffer::handle() const | 
|---|
| 194 | { | 
|---|
| 195 | return QVariant(); | 
|---|
| 196 | } | 
|---|
| 197 |  | 
|---|
| 198 |  | 
|---|
| 199 | QT_END_NAMESPACE | 
|---|