| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 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 [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qvideoframe.h"
|
|---|
| 43 |
|
|---|
| 44 | #include <private/qimagevideobuffer_p.h>
|
|---|
| 45 | #include <private/qmemoryvideobuffer_p.h>
|
|---|
| 46 |
|
|---|
| 47 | #include <qimage.h>
|
|---|
| 48 | #include <qpair.h>
|
|---|
| 49 | #include <qsize.h>
|
|---|
| 50 | #include <qvariant.h>
|
|---|
| 51 | #include <qvector.h>
|
|---|
| 52 |
|
|---|
| 53 | QT_BEGIN_NAMESPACE
|
|---|
| 54 |
|
|---|
| 55 | class QVideoFramePrivate : public QSharedData
|
|---|
| 56 | {
|
|---|
| 57 | public:
|
|---|
| 58 | QVideoFramePrivate()
|
|---|
| 59 | : startTime(-1)
|
|---|
| 60 | , endTime(-1)
|
|---|
| 61 | , data(0)
|
|---|
| 62 | , mappedBytes(0)
|
|---|
| 63 | , bytesPerLine(0)
|
|---|
| 64 | , pixelFormat(QVideoFrame::Format_Invalid)
|
|---|
| 65 | , fieldType(QVideoFrame::ProgressiveFrame)
|
|---|
| 66 | , buffer(0)
|
|---|
| 67 | {
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | QVideoFramePrivate(const QSize &size, QVideoFrame::PixelFormat format)
|
|---|
| 71 | : size(size)
|
|---|
| 72 | , startTime(-1)
|
|---|
| 73 | , endTime(-1)
|
|---|
| 74 | , data(0)
|
|---|
| 75 | , mappedBytes(0)
|
|---|
| 76 | , bytesPerLine(0)
|
|---|
| 77 | , pixelFormat(format)
|
|---|
| 78 | , fieldType(QVideoFrame::ProgressiveFrame)
|
|---|
| 79 | , buffer(0)
|
|---|
| 80 | {
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | ~QVideoFramePrivate()
|
|---|
| 84 | {
|
|---|
| 85 | delete buffer;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | QSize size;
|
|---|
| 89 | qint64 startTime;
|
|---|
| 90 | qint64 endTime;
|
|---|
| 91 | uchar *data;
|
|---|
| 92 | int mappedBytes;
|
|---|
| 93 | int bytesPerLine;
|
|---|
| 94 | QVideoFrame::PixelFormat pixelFormat;
|
|---|
| 95 | QVideoFrame::FieldType fieldType;
|
|---|
| 96 | QAbstractVideoBuffer *buffer;
|
|---|
| 97 |
|
|---|
| 98 | private:
|
|---|
| 99 | Q_DISABLE_COPY(QVideoFramePrivate)
|
|---|
| 100 | };
|
|---|
| 101 |
|
|---|
| 102 | /*!
|
|---|
| 103 | \class QVideoFrame
|
|---|
| 104 | \brief The QVideoFrame class provides a representation of a frame of video data.
|
|---|
| 105 | \preliminary
|
|---|
| 106 | \since 4.6
|
|---|
| 107 |
|
|---|
| 108 | A QVideoFrame encapsulates the data of a video frame, and information about the frame.
|
|---|
| 109 |
|
|---|
| 110 | The contents of a video frame can be mapped to memory using the map() function. While
|
|---|
| 111 | mapped the video data can accessed using the bits() function which returns a pointer to a
|
|---|
| 112 | buffer, the total size of which is given by the mappedBytes(), and the size of each line is given
|
|---|
| 113 | by bytesPerLine(). The return value of the handle() function may be used to access frame data
|
|---|
| 114 | using the internal buffer's native APIs.
|
|---|
| 115 |
|
|---|
| 116 | The video data in a QVideoFrame is encapsulated in a QAbstractVideoBuffer. A QVideoFrame
|
|---|
| 117 | may be constructed from any buffer type by subclassing the QAbstractVideoBuffer class.
|
|---|
| 118 |
|
|---|
| 119 | \note QVideoFrame is explicitly shared, any change made to video frame will also apply to any
|
|---|
| 120 | copies.
|
|---|
| 121 | */
|
|---|
| 122 |
|
|---|
| 123 | /*!
|
|---|
| 124 | \enum QVideoFrame::PixelFormat
|
|---|
| 125 |
|
|---|
| 126 | Enumerates video data types.
|
|---|
| 127 |
|
|---|
| 128 | \value Format_Invalid
|
|---|
| 129 | The frame is invalid.
|
|---|
| 130 |
|
|---|
| 131 | \value Format_ARGB32
|
|---|
| 132 | The frame is stored using a 32-bit ARGB format (0xAARRGGBB). This is equivalent to
|
|---|
| 133 | QImage::Format_ARGB32.
|
|---|
| 134 |
|
|---|
| 135 | \value Format_ARGB32_Premultiplied
|
|---|
| 136 | The frame stored using a premultiplied 32-bit ARGB format (0xAARRGGBB). This is equivalent
|
|---|
| 137 | to QImage::Format_ARGB32_Premultiplied.
|
|---|
| 138 |
|
|---|
| 139 | \value Format_RGB32
|
|---|
| 140 | The frame stored using a 32-bit RGB format (0xffRRGGBB). This is equivalent to
|
|---|
| 141 | QImage::Format_RGB32
|
|---|
| 142 |
|
|---|
| 143 | \value Format_RGB24
|
|---|
| 144 | The frame is stored using a 24-bit RGB format (8-8-8). This is equivalent to
|
|---|
| 145 | QImage::Format_RGB888
|
|---|
| 146 |
|
|---|
| 147 | \value Format_RGB565
|
|---|
| 148 | The frame is stored using a 16-bit RGB format (5-6-5). This is equivalent to
|
|---|
| 149 | QImage::Format_RGB16.
|
|---|
| 150 |
|
|---|
| 151 | \value Format_RGB555
|
|---|
| 152 | The frame is stored using a 16-bit RGB format (5-5-5). This is equivalent to
|
|---|
| 153 | QImage::Format_RGB555.
|
|---|
| 154 |
|
|---|
| 155 | \value Format_ARGB8565_Premultiplied
|
|---|
| 156 | The frame is stored using a 24-bit premultiplied ARGB format (8-6-6-5).
|
|---|
| 157 |
|
|---|
| 158 | \value Format_BGRA32
|
|---|
| 159 | The frame is stored using a 32-bit ARGB format (0xBBGGRRAA).
|
|---|
| 160 |
|
|---|
| 161 | \value Format_BGRA32_Premultiplied
|
|---|
| 162 | The frame is stored using a premultiplied 32bit BGRA format.
|
|---|
| 163 |
|
|---|
| 164 | \value Format_BGR32
|
|---|
| 165 | The frame is stored using a 32-bit BGR format (0xBBGGRRff).
|
|---|
| 166 |
|
|---|
| 167 | \value Format_BGR24
|
|---|
| 168 | The frame is stored using a 24-bit BGR format (0xBBGGRR).
|
|---|
| 169 |
|
|---|
| 170 | \value Format_BGR565
|
|---|
| 171 | The frame is stored using a 16-bit BGR format (5-6-5).
|
|---|
| 172 |
|
|---|
| 173 | \value Format_BGR555
|
|---|
| 174 | The frame is stored using a 16-bit BGR format (5-5-5).
|
|---|
| 175 |
|
|---|
| 176 | \value Format_BGRA5658_Premultiplied
|
|---|
| 177 | The frame is stored using a 24-bit premultiplied BGRA format (5-6-5-8).
|
|---|
| 178 |
|
|---|
| 179 | \value Format_AYUV444
|
|---|
| 180 | The frame is stored using a packed 32-bit AYUV format (0xAAYYUUVV).
|
|---|
| 181 |
|
|---|
| 182 | \value Format_AYUV444_Premultiplied
|
|---|
| 183 | The frame is stored using a packed premultiplied 32-bit AYUV format (0xAAYYUUVV).
|
|---|
| 184 |
|
|---|
| 185 | \value Format_YUV444
|
|---|
| 186 | The frame is stored using a 24-bit packed YUV format (8-8-8).
|
|---|
| 187 |
|
|---|
| 188 | \value Format_YUV420P
|
|---|
| 189 | The frame is stored using an 8-bit per component planar YUV format with the U and V planes
|
|---|
| 190 | horizontally and vertically sub-sampled, i.e. the height and width of the U and V planes are
|
|---|
| 191 | half that of the Y plane.
|
|---|
| 192 |
|
|---|
| 193 | \value Format_YV12
|
|---|
| 194 | The frame is stored using an 8-bit per component planar YVU format with the V and U planes
|
|---|
| 195 | horizontally and vertically sub-sampled, i.e. the height and width of the V and U planes are
|
|---|
| 196 | half that of the Y plane.
|
|---|
| 197 |
|
|---|
| 198 | \value Format_UYVY
|
|---|
| 199 | The frame is stored using an 8-bit per component packed YUV format with the U and V planes
|
|---|
| 200 | horizontally sub-sampled (U-Y-V-Y), i.e. two horizontally adjacent pixels are stored as a 32-bit
|
|---|
| 201 | macropixel which has a Y value for each pixel and common U and V values.
|
|---|
| 202 |
|
|---|
| 203 | \value Format_YUYV
|
|---|
| 204 | The frame is stored using an 8-bit per component packed YUV format with the U and V planes
|
|---|
| 205 | horizontally sub-sampled (Y-U-Y-V), i.e. two horizontally adjacent pixels are stored as a 32-bit
|
|---|
| 206 | macropixel which has a Y value for each pixel and common U and V values.
|
|---|
| 207 |
|
|---|
| 208 | \value Format_NV12
|
|---|
| 209 | The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y)
|
|---|
| 210 | followed by a horizontally and vertically sub-sampled, packed UV plane (U-V).
|
|---|
| 211 |
|
|---|
| 212 | \value Format_NV21
|
|---|
| 213 | The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y)
|
|---|
| 214 | followed by a horizontally and vertically sub-sampled, packed VU plane (V-U).
|
|---|
|
|---|