Qt 4.8
qvideosurfaceformat.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtMultimedia module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qvideosurfaceformat.h"
43 
44 #include <qdebug.h>
45 #include <qmetatype.h>
46 #include <qpair.h>
47 #include <qvariant.h>
48 #include <qvector.h>
49 
51 
53 {
54 public:
56  : pixelFormat(QVideoFrame::Format_Invalid)
57  , handleType(QAbstractVideoBuffer::NoHandle)
59  , pixelAspectRatio(1, 1)
60  , ycbcrColorSpace(QVideoSurfaceFormat::YCbCr_Undefined)
61  , frameRate(0.0)
62  {
63  }
64 
66  const QSize &size,
69  : pixelFormat(format)
70  , handleType(type)
72  , frameSize(size)
73  , pixelAspectRatio(1, 1)
74  , ycbcrColorSpace(QVideoSurfaceFormat::YCbCr_Undefined)
75  , viewport(QPoint(0, 0), size)
76  , frameRate(0.0)
77  {
78  }
79 
81  : QSharedData(other)
82  , pixelFormat(other.pixelFormat)
83  , handleType(other.handleType)
85  , frameSize(other.frameSize)
88  , viewport(other.viewport)
89  , frameRate(other.frameRate)
92  {
93  }
94 
95  bool operator ==(const QVideoSurfaceFormatPrivate &other) const
96  {
97  if (pixelFormat == other.pixelFormat
98  && handleType == other.handleType
100  && frameSize == other.frameSize
102  && viewport == other.viewport
104  && ycbcrColorSpace == other.ycbcrColorSpace
105  && propertyNames.count() == other.propertyNames.count()) {
106  for (int i = 0; i < propertyNames.count(); ++i) {
107  int j = other.propertyNames.indexOf(propertyNames.at(i));
108 
109  if (j == -1 || propertyValues.at(i) != other.propertyValues.at(j))
110  return false;
111  }
112  return true;
113  } else {
114  return false;
115  }
116  }
117 
118  inline static bool frameRatesEqual(qreal r1, qreal r2)
119  {
120  return qAbs(r1 - r2) <= 0.00001 * qMin(qAbs(r1), qAbs(r2));
121  }
122 
133 };
134 
214 {
215 }
216 
224  : d(new QVideoSurfaceFormatPrivate(size, format, type))
225 {
226 }
227 
233  : d(other.d)
234 {
235 }
236 
242 {
243  d = other.d;
244 
245  return *this;
246 }
247 
253 {
254 }
255 
263 {
265 }
266 
272 {
273  return d == other.d || *d == *other.d;
274 }
275 
281 {
282  return d != other.d && !(*d == *other.d);
283 }
284 
290 {
291  return d->pixelFormat;
292 }
293 
304 {
305  return d->handleType;
306 }
307 
315 {
316  return d->frameSize;
317 }
318 
326 {
327  return d->frameSize.width();
328 }
329 
335 {
336  return d->frameSize.height();
337 }
338 
346 {
347  d->frameSize = size;
348  d->viewport = QRect(QPoint(0, 0), size);
349 }
350 
362 void QVideoSurfaceFormat::setFrameSize(int width, int height)
363 {
364  d->frameSize = QSize(width, height);
365  d->viewport = QRect(0, 0, width, height);
366 }
367 
377 {
378  return d->viewport;
379 }
380 
386 {
387  d->viewport = viewport;
388 }
389 
395 {
396  return d->scanLineDirection;
397 }
398 
404 {
406 }
407 
413 {
414  return d->frameRate;
415 }
416 
422 {
423  d->frameRate = rate;
424 }
425 
431 {
432  return d->pixelAspectRatio;
433 }
434 
440 {
442 }
443 
453 void QVideoSurfaceFormat::setPixelAspectRatio(int horizontal, int vertical)
454 {
455  d->pixelAspectRatio = QSize(horizontal, vertical);
456 }
457 
463 {
464  return d->ycbcrColorSpace;
465 }
466 
473 {
474  d->ycbcrColorSpace = space;
475 }
476 
484 {
485  QSize size = d->viewport.size();
486 
487  if (d->pixelAspectRatio.height() != 0)
489 
490  return size;
491 }
492 
498 {
499  return (QList<QByteArray>()
500  << "handleType"
501  << "pixelFormat"
502  << "frameSize"
503  << "frameWidth"
504  << "viewport"
505  << "scanLineDirection"
506  << "frameRate"
507  << "pixelAspectRatio"
508  << "sizeHint"
509  << "yCbCrColorSpace")
510  + d->propertyNames;
511 }
512 
518 {
519  if (qstrcmp(name, "handleType") == 0) {
521  } else if (qstrcmp(name, "pixelFormat") == 0) {
523  } else if (qstrcmp(name, "handleType") == 0) {
525  } else if (qstrcmp(name, "frameSize") == 0) {
526  return d->frameSize;
527  } else if (qstrcmp(name, "frameWidth") == 0) {
528  return d->frameSize.width();
529  } else if (qstrcmp(name, "frameHeight") == 0) {
530  return d->frameSize.height();
531  } else if (qstrcmp(name, "viewport") == 0) {
532  return d->viewport;
533  } else if (qstrcmp(name, "scanLineDirection") == 0) {
535  } else if (qstrcmp(name, "frameRate") == 0) {
537  } else if (qstrcmp(name, "pixelAspectRatio") == 0) {
539  } else if (qstrcmp(name, "sizeHint") == 0) {
540  return sizeHint();
541  } else if (qstrcmp(name, "yCbCrColorSpace") == 0) {
543  } else {
544  int id = 0;
545  for (; id < d->propertyNames.count() && d->propertyNames.at(id) != name; ++id) {}
546 
547  return id < d->propertyValues.count()
548  ? d->propertyValues.at(id)
549  : QVariant();
550  }
551 }
552 
557 void QVideoSurfaceFormat::setProperty(const char *name, const QVariant &value)
558 {
559  if (qstrcmp(name, "handleType") == 0) {
560  // read only.
561  } else if (qstrcmp(name, "pixelFormat") == 0) {
562  // read only.
563  } else if (qstrcmp(name, "frameSize") == 0) {
564  if (value.canConvert<QSize>()) {
565  d->frameSize = qvariant_cast<QSize>(value);
566  d->viewport = QRect(QPoint(0, 0), d->frameSize);
567  }
568  } else if (qstrcmp(name, "frameWidth") == 0) {
569  // read only.
570  } else if (qstrcmp(name, "frameHeight") == 0) {
571  // read only.
572  } else if (qstrcmp(name, "viewport") == 0) {
573  if (value.canConvert<QRect>())
574  d->viewport = qvariant_cast<QRect>(value);
575  } else if (qstrcmp(name, "scanLineDirection") == 0) {
576  if (value.canConvert<Direction>())
577  d->scanLineDirection = qvariant_cast<Direction>(value);
578  } else if (qstrcmp(name, "frameRate") == 0) {
579  if (value.canConvert<qreal>())
580  d->frameRate = qvariant_cast<qreal>(value);
581  } else if (qstrcmp(name, "pixelAspectRatio") == 0) {
582  if (value.canConvert<QSize>())
583  d->pixelAspectRatio = qvariant_cast<QSize>(value);
584  } else if (qstrcmp(name, "sizeHint") == 0) {
585  // read only.
586  } else if (qstrcmp(name, "yCbCrColorSpace") == 0) {
587  if (value.canConvert<YCbCrColorSpace>())
588  d->ycbcrColorSpace = qvariant_cast<YCbCrColorSpace>(value);
589  } else {
590  int id = 0;
591  for (; id < d->propertyNames.count() && d->propertyNames.at(id) != name; ++id) {}
592 
593  if (id < d->propertyValues.count()) {
594  if (value.isNull()) {
595  d->propertyNames.removeAt(id);
597  } else {
598  d->propertyValues[id] = value;
599  }
600  } else if (!value.isNull()) {
602  d->propertyValues.append(value);
603  }
604  }
605 }
606 
607 
608 #ifndef QT_NO_DEBUG_STREAM
610 {
612  switch (f.pixelFormat()) {
614  typeName = QLatin1String("Format_Invalid");
615  break;
617  typeName = QLatin1String("Format_ARGB32");
618  break;
620  typeName = QLatin1String("Format_ARGB32_Premultiplied");
621  break;
623  typeName = QLatin1String("Format_RGB32");
624  break;
626  typeName = QLatin1String("Format_RGB24");
627  break;
629  typeName = QLatin1String("Format_RGB565");
630  break;
632  typeName = QLatin1String("Format_RGB555");
633  break;
635  typeName = QLatin1String("Format_ARGB8565_Premultiplied");
636  break;
638  typeName = QLatin1String("Format_BGRA32");
639  break;
641  typeName = QLatin1String("Format_BGRA32_Premultiplied");
642  break;
644  typeName = QLatin1String("Format_BGR32");
645  break;
647  typeName = QLatin1String("Format_BGR24");
648  break;
650  typeName = QLatin1String("Format_BGR565");
651  break;
653  typeName = QLatin1String("Format_BGR555");
654  break;
656  typeName = QLatin1String("Format_BGRA5658_Premultiplied");
657  break;
659  typeName = QLatin1String("Format_AYUV444");
660  break;
662  typeName = QLatin1String("Format_AYUV444_Premultiplied");
663  break;
665  typeName = QLatin1String("Format_YUV444");
666  break;
668  typeName = QLatin1String("Format_YUV420P");
669  break;
671  typeName = QLatin1String("Format_YV12");
672  break;
674  typeName = QLatin1String("Format_UYVY");
675  break;
677  typeName = QLatin1String("Format_YUYV");
678  break;
680  typeName = QLatin1String("Format_NV12");
681  break;
683  typeName = QLatin1String("Format_NV21");
684  break;
686  typeName = QLatin1String("Format_IMC1");
687  break;
689  typeName = QLatin1String("Format_IMC2");
690  break;
692  typeName = QLatin1String("Format_IMC3");
693  break;
695  typeName = QLatin1String("Format_IMC4");
696  break;
698  typeName = QLatin1String("Format_Y8");
699  break;
701  typeName = QLatin1String("Format_Y16");
702  default:
703  typeName = QString(QLatin1String("UserType(%1)" )).arg(int(f.pixelFormat()));
704  }
705 
706  dbg.nospace() << "QVideoSurfaceFormat(" << typeName;
707  dbg.nospace() << ", " << f.frameSize();
708  dbg.nospace() << ", viewport=" << f.viewport();
709  dbg.nospace() << ", pixelAspectRatio=" << f.pixelAspectRatio();
710  dbg.nospace() << ")";
711 
712  foreach(const QByteArray& propertyName, f.propertyNames())
713  dbg << "\n " << propertyName.data() << " = " << f.property(propertyName.data());
714 
715  return dbg.space();
716 }
717 #endif
718 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
double d
Definition: qnumeric_p.h:62
QSize sizeHint() const
Returns a suggested size in pixels for the video stream.
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void setYCbCrColorSpace(YCbCrColorSpace colorSpace)
Sets the Y&#39;CbCr color space of a video stream.
QVideoSurfaceFormat::Direction scanLineDirection
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QSharedDataPointer< QVideoSurfaceFormatPrivate > d
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
The QVideoSurfaceFormat class specifies the stream format of a video presentation surface...
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QSize frameSize() const
Returns the size of frames in a video stream.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QVideoSurfaceFormatPrivate(const QVideoSurfaceFormatPrivate &other)
The QVideoFrame class provides a representation of a frame of video data.
Definition: qvideoframe.h:61
HandleType
Identifies the type of a video buffers handle.
QVideoFrame::PixelFormat pixelFormat
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
YCbCrColorSpace yCbCrColorSpace() const
Returns the Y&#39;CbCr color space of a video stream.
int frameWidth() const
Returns the width of frames in a video stream.
static double ratio(Bigint *a, Bigint *b)
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
void setViewport(const QRect &viewport)
Sets the viewport of a video stream to viewport.
int width() const
Returns the width.
Definition: qsize.h:126
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
PixelFormat
Enumerates video data types.
Definition: qvideoframe.h:72
QDebug operator<<(QDebug dbg, const QVideoSurfaceFormat &f)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
int frameHeight() const
Returns the height of frame in a video stream.
QSize pixelAspectRatio() const
Returns a video stream&#39;s pixel aspect ratio.
QVideoSurfaceFormat::YCbCrColorSpace ycbcrColorSpace
QVideoSurfaceFormat & operator=(const QVideoSurfaceFormat &format)
Assigns the values of other to a video stream description.
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
bool isValid() const
Identifies if a video surface format has a valid pixel format and frame size.
QVideoSurfaceFormat()
Constructs a null video stream format.
const char * typeName
Definition: qmetatype.cpp:239
const char * name
bool operator==(const QVideoSurfaceFormatPrivate &other) const
bool operator!=(const QVideoSurfaceFormat &format) const
Returns true if other is different to a video format, and false if they are the same.
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void setFrameRate(qreal rate)
Sets the frame rate of a video stream in frames per second.
void setPixelAspectRatio(const QSize &ratio)
Sets a video stream&#39;s pixel aspect ratio.
bool operator==(const QVideoSurfaceFormat &format) const
Returns true if other is the same as a video format, and false if they are the different.
static bool frameRatesEqual(qreal r1, qreal r2)
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
QAbstractVideoBuffer::HandleType handleType() const
Returns the type of handle the surface uses to present the frame data.
Direction scanLineDirection() const
Returns the direction of scan lines.
void setProperty(const char *name, const QVariant &value)
Sets the video format&#39;s name property to value.
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
QAbstractVideoBuffer::HandleType handleType
The QSharedData class is a base class for shared data objects.
Definition: qshareddata.h:56
~QVideoSurfaceFormat()
Destroys a video stream description.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QAbstractVideoBuffer class is an abstraction for video data.
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Direction
Enumerates the layout direction of video scan lines.
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
void setScanLineDirection(Direction direction)
Sets the direction of scan lines.
QVideoSurfaceFormatPrivate(const QSize &size, QVideoFrame::PixelFormat format, QAbstractVideoBuffer::HandleType type)
QVideoFrame::PixelFormat pixelFormat() const
Returns the pixel format of frames in a video stream.
qreal frameRate() const
Returns the frame rate of a video stream in frames per second.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QList< QByteArray > propertyNames() const
Returns a list of video format dynamic property names.
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
void setFrameSize(const QSize &size)
Sets the size of frames in a video stream to size.
QVariant property(const char *name) const
Returns the value of the video format&#39;s name property.
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
YCbCrColorSpace
Enumerates the Y&#39;CbCr color space of video frames.
QRect viewport() const
Returns the viewport of a video stream.
Qt::LayoutDirection direction
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480