diff options
author | axis <qt-info@nokia.com> | 2009-11-06 14:50:21 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2009-11-06 14:50:21 (GMT) |
commit | d1aa89647824cbaf9af4fc943d4514018973ddc1 (patch) | |
tree | e8e13c32613a896311117fc39c45fe8b6f27144d /src/multimedia/video | |
parent | 351ba8b9ca4f0db176c9e3553d105be0ef35c844 (diff) | |
parent | daf5f511ee813fc4fffba64bed558d0413270388 (diff) | |
download | Qt-d1aa89647824cbaf9af4fc943d4514018973ddc1.zip Qt-d1aa89647824cbaf9af4fc943d4514018973ddc1.tar.gz Qt-d1aa89647824cbaf9af4fc943d4514018973ddc1.tar.bz2 |
Merge branch '4.6' of git@scm.dev.nokia.troll.no:qt/qt
Diffstat (limited to 'src/multimedia/video')
-rw-r--r-- | src/multimedia/video/qabstractvideosurface.cpp | 60 | ||||
-rw-r--r-- | src/multimedia/video/qabstractvideosurface.h | 8 | ||||
-rw-r--r-- | src/multimedia/video/qabstractvideosurface_p.h | 5 | ||||
-rw-r--r-- | src/multimedia/video/qvideoframe.cpp | 34 | ||||
-rw-r--r-- | src/multimedia/video/qvideoframe.h | 6 | ||||
-rw-r--r-- | src/multimedia/video/qvideosurfaceformat.cpp | 68 | ||||
-rw-r--r-- | src/multimedia/video/qvideosurfaceformat.h | 18 |
7 files changed, 96 insertions, 103 deletions
diff --git a/src/multimedia/video/qabstractvideosurface.cpp b/src/multimedia/video/qabstractvideosurface.cpp index a4f51a2..33dc815 100644 --- a/src/multimedia/video/qabstractvideosurface.cpp +++ b/src/multimedia/video/qabstractvideosurface.cpp @@ -57,8 +57,8 @@ QT_BEGIN_NAMESPACE of each frame is compatible with a stream format supplied when starting a presentation. A list of pixel formats a surface can present is given by the supportedPixelFormats() function, - and the isFormatSupported() function will test if a complete video format is supported. In - some cases when a format is not supported; isFormatSupported() may suggest a similar format. + 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. @@ -118,21 +118,37 @@ QAbstractVideoSurface::~QAbstractVideoSurface() */ /*! - Tests a video \a format to determine if a surface can accept it. If the format isn't supported - the surface may suggest a \a similar format that is supported. + 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. */ -bool QAbstractVideoSurface::isFormatSupported( - const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const +bool QAbstractVideoSurface::isFormatSupported(const QVideoSurfaceFormat &format) const { - Q_UNUSED(similar); - 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 differs 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. +*/ + +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. @@ -162,23 +178,23 @@ QVideoSurfaceFormat QAbstractVideoSurface::surfaceFormat() const Returns true if the surface was started, and false if an error occurred. - \sa isStarted(), stop() + \sa isActive(), stop() */ bool QAbstractVideoSurface::start(const QVideoSurfaceFormat &format) { Q_D(QAbstractVideoSurface); - bool wasStarted = d->started; + bool wasActive = d->active; - d->started = true; + d->active = true; d->format = format; d->error = NoError; emit surfaceFormatChanged(d->format); - if (!wasStarted) - emit startedChanged(true); + if (!wasActive) + emit activeChanged(true); return true; } @@ -186,18 +202,18 @@ bool QAbstractVideoSurface::start(const QVideoSurfaceFormat &format) /*! Stops a video surface presenting frames and releases any resources acquired in start(). - \sa isStarted(), start() + \sa isActive(), start() */ void QAbstractVideoSurface::stop() { Q_D(QAbstractVideoSurface); - if (d->started) { + if (d->active) { d->format = QVideoSurfaceFormat(); - d->started = false; + d->active = false; - emit startedChanged(false); + emit activeChanged(false); emit surfaceFormatChanged(d->format); } } @@ -208,17 +224,17 @@ void QAbstractVideoSurface::stop() Returns true if the surface has been started, and false otherwise. */ -bool QAbstractVideoSurface::isStarted() const +bool QAbstractVideoSurface::isActive() const { - return d_func()->started; + return d_func()->active; } /*! - \fn QAbstractVideoSurface::startedChanged(bool started) + \fn QAbstractVideoSurface::activeChanged(bool active) - Signals that the \a started state of a video surface has changed. + Signals that the \a active state of a video surface has changed. - \sa isStarted(), start(), stop() + \sa isActive(), start(), stop() */ /*! diff --git a/src/multimedia/video/qabstractvideosurface.h b/src/multimedia/video/qabstractvideosurface.h index 3823eeb..58d06f1 100644 --- a/src/multimedia/video/qabstractvideosurface.h +++ b/src/multimedia/video/qabstractvideosurface.h @@ -75,22 +75,22 @@ public: virtual QList<QVideoFrame::PixelFormat> supportedPixelFormats( QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const = 0; - virtual bool isFormatSupported( - const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar = 0) const; + virtual bool isFormatSupported(const QVideoSurfaceFormat &format) const; + virtual QVideoSurfaceFormat nearestFormat(const QVideoSurfaceFormat &format) const; QVideoSurfaceFormat surfaceFormat() const; virtual bool start(const QVideoSurfaceFormat &format); virtual void stop(); - bool isStarted() const; + bool isActive() const; virtual bool present(const QVideoFrame &frame) = 0; Error error() const; Q_SIGNALS: - void startedChanged(bool started); + void activeChanged(bool active); void surfaceFormatChanged(const QVideoSurfaceFormat &format); void supportedFormatsChanged(); diff --git a/src/multimedia/video/qabstractvideosurface_p.h b/src/multimedia/video/qabstractvideosurface_p.h index 3142b78..8675fac 100644 --- a/src/multimedia/video/qabstractvideosurface_p.h +++ b/src/multimedia/video/qabstractvideosurface_p.h @@ -64,14 +64,13 @@ class QAbstractVideoSurfacePrivate : public QObjectPrivate public: QAbstractVideoSurfacePrivate() : error(QAbstractVideoSurface::NoError) - , started(false) + , active(false) { } mutable QAbstractVideoSurface::Error error; QVideoSurfaceFormat format; - bool started; - + bool active; }; QT_END_NAMESPACE diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp index c884da0..ae38e82 100644 --- a/src/multimedia/video/qvideoframe.cpp +++ b/src/multimedia/video/qvideoframe.cpp @@ -59,7 +59,7 @@ public: : startTime(-1) , endTime(-1) , data(0) - , numBytes(0) + , mappedBytes(0) , bytesPerLine(0) , pixelFormat(QVideoFrame::Format_Invalid) , fieldType(QVideoFrame::ProgressiveFrame) @@ -72,7 +72,7 @@ public: , startTime(-1) , endTime(-1) , data(0) - , numBytes(0) + , mappedBytes(0) , bytesPerLine(0) , pixelFormat(format) , fieldType(QVideoFrame::ProgressiveFrame) @@ -89,7 +89,7 @@ public: qint64 startTime; qint64 endTime; uchar *data; - int numBytes; + int mappedBytes; int bytesPerLine; QVideoFrame::PixelFormat pixelFormat; QVideoFrame::FieldType fieldType; @@ -109,7 +109,7 @@ private: 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 which is given by the numBytes(), and the size of each line is given + buffer, the total size of which is given by the mappedBytes(), 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. @@ -304,12 +304,12 @@ QVideoFrame::QVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFo \note This will construct an invalid video frame if there is no frame type equivalent to the image format. - \sa equivalentPixelFormat() + \sa pixelFormatFromImageFormat() */ QVideoFrame::QVideoFrame(const QImage &image) : d(new QVideoFramePrivate( - image.size(), equivalentPixelFormat(image.format()))) + image.size(), pixelFormatFromImageFormat(image.format()))) { if (d->pixelFormat != Format_Invalid) d->buffer = new QImageVideoBuffer(image); @@ -510,9 +510,9 @@ bool QVideoFrame::map(QAbstractVideoBuffer::MapMode mode) { if (d->buffer != 0 && d->data == 0) { Q_ASSERT(d->bytesPerLine == 0); - Q_ASSERT(d->numBytes == 0); + Q_ASSERT(d->mappedBytes == 0); - d->data = d->buffer->map(mode, &d->numBytes, &d->bytesPerLine); + d->data = d->buffer->map(mode, &d->mappedBytes, &d->bytesPerLine); return d->data != 0; } @@ -532,7 +532,7 @@ bool QVideoFrame::map(QAbstractVideoBuffer::MapMode mode) void QVideoFrame::unmap() { if (d->data != 0) { - d->numBytes = 0; + d->mappedBytes = 0; d->bytesPerLine = 0; d->data = 0; @@ -548,7 +548,7 @@ void QVideoFrame::unmap() This value is only valid while the frame data is \l {map()}{mapped}. - \sa bits(), map(), numBytes() + \sa bits(), map(), mappedBytes() */ int QVideoFrame::bytesPerLine() const @@ -561,7 +561,7 @@ int QVideoFrame::bytesPerLine() const This value is only valid while the frame data is \l {map()}{mapped}. - \sa map(), numBytes(), bytesPerLine() + \sa map(), mappedBytes(), bytesPerLine() */ uchar *QVideoFrame::bits() @@ -574,7 +574,7 @@ uchar *QVideoFrame::bits() This value is only valid while the frame data is \l {map()}{mapped}. - \sa map(), numBytes(), bytesPerLine() + \sa map(), mappedBytes(), bytesPerLine() */ const uchar *QVideoFrame::bits() const @@ -583,16 +583,16 @@ const uchar *QVideoFrame::bits() const } /*! - Returns the number of bytes occupied by the frame 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}. \sa map() */ -int QVideoFrame::numBytes() const +int QVideoFrame::mappedBytes() const { - return d->numBytes; + return d->mappedBytes; } /*! @@ -649,7 +649,7 @@ void QVideoFrame::setEndTime(qint64 time) format QVideoFrame::InvalidType is returned instead. */ -QVideoFrame::PixelFormat QVideoFrame::equivalentPixelFormat(QImage::Format format) +QVideoFrame::PixelFormat QVideoFrame::pixelFormatFromImageFormat(QImage::Format format) { switch (format) { case QImage::Format_Invalid: @@ -689,7 +689,7 @@ QVideoFrame::PixelFormat QVideoFrame::equivalentPixelFormat(QImage::Format forma format QImage::Format_Invalid is returned instead. */ -QImage::Format QVideoFrame::equivalentImageFormat(PixelFormat format) +QImage::Format QVideoFrame::imageFormatFromPixelFormat(PixelFormat format) { switch (format) { case Format_Invalid: diff --git a/src/multimedia/video/qvideoframe.h b/src/multimedia/video/qvideoframe.h index e1b46a8..d08008b 100644 --- a/src/multimedia/video/qvideoframe.h +++ b/src/multimedia/video/qvideoframe.h @@ -141,7 +141,7 @@ public: uchar *bits(); const uchar *bits() const; - int numBytes() const; + int mappedBytes() const; QVariant handle() const; @@ -151,8 +151,8 @@ public: qint64 endTime() const; void setEndTime(qint64 time); - static PixelFormat equivalentPixelFormat(QImage::Format format); - static QImage::Format equivalentImageFormat(PixelFormat format); + static PixelFormat pixelFormatFromImageFormat(QImage::Format format); + static QImage::Format imageFormatFromPixelFormat(PixelFormat format); private: QExplicitlySharedDataPointer<QVideoFramePrivate> d; diff --git a/src/multimedia/video/qvideosurfaceformat.cpp b/src/multimedia/video/qvideosurfaceformat.cpp index e6ef8f3..c898e3a 100644 --- a/src/multimedia/video/qvideosurfaceformat.cpp +++ b/src/multimedia/video/qvideosurfaceformat.cpp @@ -57,7 +57,7 @@ public: , handleType(QAbstractVideoBuffer::NoHandle) , scanLineDirection(QVideoSurfaceFormat::TopToBottom) , pixelAspectRatio(1, 1) - , yuvColorSpace(QVideoSurfaceFormat::YCbCr_Undefined) + , ycbcrColorSpace(QVideoSurfaceFormat::YCbCr_Undefined) , frameRate(0.0) { } @@ -71,7 +71,7 @@ public: , scanLineDirection(QVideoSurfaceFormat::TopToBottom) , frameSize(size) , pixelAspectRatio(1, 1) - , yuvColorSpace(QVideoSurfaceFormat::YCbCr_Undefined) + , ycbcrColorSpace(QVideoSurfaceFormat::YCbCr_Undefined) , viewport(QPoint(0, 0), size) , frameRate(0.0) { @@ -84,7 +84,7 @@ public: , scanLineDirection(other.scanLineDirection) , frameSize(other.frameSize) , pixelAspectRatio(other.pixelAspectRatio) - , yuvColorSpace(other.yuvColorSpace) + , ycbcrColorSpace(other.ycbcrColorSpace) , viewport(other.viewport) , frameRate(other.frameRate) , propertyNames(other.propertyNames) @@ -101,7 +101,7 @@ public: && pixelAspectRatio == other.pixelAspectRatio && viewport == other.viewport && frameRatesEqual(frameRate, other.frameRate) - && yuvColorSpace == other.yuvColorSpace + && ycbcrColorSpace == other.ycbcrColorSpace && propertyNames.count() == other.propertyNames.count()) { for (int i = 0; i < propertyNames.count(); ++i) { int j = other.propertyNames.indexOf(propertyNames.at(i)); @@ -125,7 +125,7 @@ public: QVideoSurfaceFormat::Direction scanLineDirection; QSize frameSize; QSize pixelAspectRatio; - QVideoSurfaceFormat::YuvColorSpace yuvColorSpace; + QVideoSurfaceFormat::YCbCrColorSpace ycbcrColorSpace; QRect viewport; qreal frameRate; QList<QByteArray> propertyNames; @@ -168,19 +168,10 @@ public: \value BottomToTop Scan lines are arranged from the bottom of the frame to the top. */ -/*! - \enum QVideoSurfaceFormat::ViewportMode - - Enumerates the methods for updating the stream viewport when the frame size is changed. - - \value ResetViewport The viewport is reset to cover an entire frame. - \value KeepViewport The viewport is kept within the bounds the frame. -*/ - /*! - \enum QVideoSurfaceFormat::YuvColorSpace + \enum QVideoSurfaceFormat::YCbCrColorSpace - Enumerates the YUV color space of video frames. + Enumerates the Y'CbCr color space of video frames. \value YCbCr_Undefined No color space is specified. @@ -340,21 +331,13 @@ int QVideoSurfaceFormat::frameHeight() const /*! Sets the size of frames in a video stream to \a size. - The viewport \a mode indicates how the view port should be updated. + This will reset the viewport() to fill the entire frame. */ -void QVideoSurfaceFormat::setFrameSize(const QSize &size, ViewportMode mode) +void QVideoSurfaceFormat::setFrameSize(const QSize &size) { d->frameSize = size; - - switch (mode) { - case ResetViewport: - d->viewport = QRect(QPoint(0, 0), size); - break; - case KeepViewport: - d->viewport = QRect(QPoint(0, 0), size).intersected(d->viewport); - break; - } + d->viewport = QRect(QPoint(0, 0), size); } /*! @@ -362,12 +345,13 @@ void QVideoSurfaceFormat::setFrameSize(const QSize &size, ViewportMode mode) Sets the \a width and \a height of frames in a video stream. - The viewport \a mode indicates how the view port should be updated. + This will reset the viewport() to fill the entire frame. */ -void QVideoSurfaceFormat::setFrameSize(int width, int height, ViewportMode mode) +void QVideoSurfaceFormat::setFrameSize(int width, int height) { - setFrameSize(QSize(width, height), mode); + d->frameSize = QSize(width, height); + d->viewport = QRect(0, 0, width, height); } /*! @@ -458,22 +442,22 @@ void QVideoSurfaceFormat::setPixelAspectRatio(int horizontal, int vertical) } /*! - Returns a YUV color space of a video stream. + Returns the Y'CbCr color space of a video stream. */ -QVideoSurfaceFormat::YuvColorSpace QVideoSurfaceFormat::yuvColorSpace() const +QVideoSurfaceFormat::YCbCrColorSpace QVideoSurfaceFormat::yCbCrColorSpace() const { - return d->yuvColorSpace; + return d->ycbcrColorSpace; } /*! - Sets a YUV color \a space of a video stream. + Sets the Y'CbCr color \a space of a video stream. It is only used with raw YUV frame types. */ -void QVideoSurfaceFormat::setYuvColorSpace(QVideoSurfaceFormat::YuvColorSpace space) +void QVideoSurfaceFormat::setYCbCrColorSpace(QVideoSurfaceFormat::YCbCrColorSpace space) { - d->yuvColorSpace = space; + d->ycbcrColorSpace = space; } /*! @@ -508,7 +492,7 @@ QList<QByteArray> QVideoSurfaceFormat::propertyNames() const << "frameRate" << "pixelAspectRatio" << "sizeHint" - << "yuvColorSpace") + << "yCbCrColorSpace") + d->propertyNames; } @@ -540,8 +524,8 @@ QVariant QVideoSurfaceFormat::property(const char *name) const return qVariantFromValue(d->pixelAspectRatio); } else if (qstrcmp(name, "sizeHint") == 0) { return sizeHint(); - } else if (qstrcmp(name, "yuvColorSpace") == 0) { - return qVariantFromValue(d->yuvColorSpace); + } 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) {} @@ -585,9 +569,9 @@ void QVideoSurfaceFormat::setProperty(const char *name, const QVariant &value) d->pixelAspectRatio = qvariant_cast<QSize>(value); } else if (qstrcmp(name, "sizeHint") == 0) { // read only. - } else if (qstrcmp(name, "yuvColorSpace") == 0) { - if (qVariantCanConvert<YuvColorSpace>(value)) - d->yuvColorSpace = qvariant_cast<YuvColorSpace>(value); + } 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) {} diff --git a/src/multimedia/video/qvideosurfaceformat.h b/src/multimedia/video/qvideosurfaceformat.h index 1f4a5cb..ee60244 100644 --- a/src/multimedia/video/qvideosurfaceformat.h +++ b/src/multimedia/video/qvideosurfaceformat.h @@ -68,13 +68,7 @@ public: BottomToTop }; - enum ViewportMode - { - ResetViewport, - KeepViewport - }; - - enum YuvColorSpace + enum YCbCrColorSpace { YCbCr_Undefined, YCbCr_BT601, @@ -106,8 +100,8 @@ public: QAbstractVideoBuffer::HandleType handleType() const; QSize frameSize() const; - void setFrameSize(const QSize &size, ViewportMode mode = ResetViewport); - void setFrameSize(int width, int height, ViewportMode mode = ResetViewport); + void setFrameSize(const QSize &size); + void setFrameSize(int width, int height); int frameWidth() const; int frameHeight() const; @@ -125,8 +119,8 @@ public: void setPixelAspectRatio(const QSize &ratio); void setPixelAspectRatio(int width, int height); - YuvColorSpace yuvColorSpace() const; - void setYuvColorSpace(YuvColorSpace colorSpace); + YCbCrColorSpace yCbCrColorSpace() const; + void setYCbCrColorSpace(YCbCrColorSpace colorSpace); QSize sizeHint() const; @@ -145,7 +139,7 @@ Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QVideoSurfaceFormat &); QT_END_NAMESPACE Q_DECLARE_METATYPE(QVideoSurfaceFormat::Direction) -Q_DECLARE_METATYPE(QVideoSurfaceFormat::YuvColorSpace) +Q_DECLARE_METATYPE(QVideoSurfaceFormat::YCbCrColorSpace) QT_END_HEADER |