diff options
author | Lars Knoll <lars.knoll@qt.io> | 2021-01-04 12:31:09 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2021-01-22 06:58:14 +0000 |
commit | cfaa21174e72dc00d073f3d6f6ce7f68330afff9 (patch) | |
tree | d925688c02c5e6d9c596ba46be58ff2db6032078 /src/plugins | |
parent | c355d98b045834a494e9fda634388f82c8f625a9 (diff) |
Merge QAbstractPlanarVideoOutput into QAbstractVideoOutput
And while we're at it, sanitize the signature of the virtual
map() method.
Change-Id: I8feb09e1dd6abdd9f480e202568ff84e6c3c08a9
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/plugins')
6 files changed, 56 insertions, 70 deletions
diff --git a/src/plugins/android/src/common/qandroidvideooutput.cpp b/src/plugins/android/src/common/qandroidvideooutput.cpp index 27cea76ad..3c6472482 100644 --- a/src/plugins/android/src/common/qandroidvideooutput.cpp +++ b/src/plugins/android/src/common/qandroidvideooutput.cpp @@ -103,33 +103,31 @@ public: virtual ~AndroidTextureVideoBuffer() {} - MapMode mapMode() const { return m_mapMode; } + MapMode mapMode() const override { return m_mapMode; } - uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) + MapData map(MapMode mode) override { + MapData mapData; if (m_mapMode == NotMapped && mode == ReadOnly && updateFrame()) { m_mapMode = mode; m_image = m_output->m_fbo->toImage(); - if (numBytes) - *numBytes = static_cast<int>(m_image.sizeInBytes()); - - if (bytesPerLine) - *bytesPerLine = m_image.bytesPerLine(); - - return m_image.bits(); - } else { - return 0; + mapData.nBytes = static_cast<int>(m_image.sizeInBytes()); + mapData.nPlanes = 1; + mapData.bytesPerLine[0] = m_image.bytesPerLine(); + mapData.data[0] = m_image.bits(); } + + return mapData; } - void unmap() + void unmap() override { m_image = QImage(); m_mapMode = NotMapped; } - QVariant handle() const + QVariant handle() const override { AndroidTextureVideoBuffer *that = const_cast<AndroidTextureVideoBuffer*>(this); if (!that->updateFrame()) diff --git a/src/plugins/avfoundation/camera/avfcamerarenderercontrol.mm b/src/plugins/avfoundation/camera/avfcamerarenderercontrol.mm index 98cbf3df4..b77aa21ec 100644 --- a/src/plugins/avfoundation/camera/avfcamerarenderercontrol.mm +++ b/src/plugins/avfoundation/camera/avfcamerarenderercontrol.mm @@ -55,16 +55,16 @@ QT_USE_NAMESPACE -class CVImageVideoBuffer : public QAbstractPlanarVideoBuffer +class CVImageVideoBuffer : public QAbstractVideoBuffer { public: CVImageVideoBuffer(CVImageBufferRef buffer, AVFCameraRendererControl *renderer) #ifndef Q_OS_IOS - : QAbstractPlanarVideoBuffer(NoHandle) + : QAbstractVideoBuffer(NoHandle) #else - : QAbstractPlanarVideoBuffer(renderer->supportsTextures() - && CVPixelBufferGetPixelFormatType(buffer) == kCVPixelFormatType_32BGRA - ? GLTextureHandle : NoHandle) + : QAbstractVideoBuffer(renderer->supportsTextures() + && CVPixelBufferGetPixelFormatType(buffer) == kCVPixelFormatType_32BGRA + ? GLTextureHandle : NoHandle) , m_texture(nullptr) , m_renderer(renderer) #endif @@ -89,16 +89,19 @@ public: MapMode mapMode() const { return m_mode; } - int map(QAbstractVideoBuffer::MapMode mode, int *numBytes, int bytesPerLine[4], uchar *data[4]) + MapData map(QAbstractVideoBuffer::MapMode mode) { + MapData mapData; + // We only support RGBA or NV12 (or Apple's version of NV12), // they are either 0 planes or 2. - const size_t nPlanes = CVPixelBufferGetPlaneCount(m_buffer); - Q_ASSERT(nPlanes <= 2); + mapData.nPlanes = CVPixelBufferGetPlaneCount(m_buffer); + Q_ASSERT(mapData.nPlanes <= 2); - if (!nPlanes) { - data[0] = map(mode, numBytes, bytesPerLine); - return data[0] ? 1 : 0; + if (!mapData.nPlanes) { + mapData.data[0] = map(mode, &mapData.nBytes, &mapData.bytesPerLine[0]); + mapData.nPlanes = mapData.data[0] ? 1 : 0; + return mapData; } // For a bi-planar format we have to set the parameters correctly: @@ -107,27 +110,22 @@ public: ? kCVPixelBufferLock_ReadOnly : 0); - if (numBytes) - *numBytes = CVPixelBufferGetDataSize(m_buffer); + mapData.nBytes = CVPixelBufferGetDataSize(m_buffer); - if (bytesPerLine) { - // At the moment we handle only bi-planar format. - bytesPerLine[0] = CVPixelBufferGetBytesPerRowOfPlane(m_buffer, 0); - bytesPerLine[1] = CVPixelBufferGetBytesPerRowOfPlane(m_buffer, 1); - } + // At the moment we handle only bi-planar format. + mapData.bytesPerLine[0] = CVPixelBufferGetBytesPerRowOfPlane(m_buffer, 0); + mapData.bytesPerLine[1] = CVPixelBufferGetBytesPerRowOfPlane(m_buffer, 1); - if (data) { - data[0] = static_cast<uchar*>(CVPixelBufferGetBaseAddressOfPlane(m_buffer, 0)); - data[1] = static_cast<uchar*>(CVPixelBufferGetBaseAddressOfPlane(m_buffer, 1)); - } + mapData.data[0] = static_cast<uchar*>(CVPixelBufferGetBaseAddressOfPlane(m_buffer, 0)); + mapData.data[1] = static_cast<uchar*>(CVPixelBufferGetBaseAddressOfPlane(m_buffer, 1)); m_mode = mode; } - return nPlanes; + return mapData; } - uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) + uchar *map(MapMode mode, qsizetype *numBytes, int *bytesPerLine) { if (mode != NotMapped && m_mode == NotMapped) { CVPixelBufferLockBaseAddress(m_buffer, mode == QAbstractVideoBuffer::ReadOnly diff --git a/src/plugins/avfoundation/mediaplayer/avfvideorenderercontrol.mm b/src/plugins/avfoundation/mediaplayer/avfvideorenderercontrol.mm index 726dc5193..6e5b6a15e 100644 --- a/src/plugins/avfoundation/mediaplayer/avfvideorenderercontrol.mm +++ b/src/plugins/avfoundation/mediaplayer/avfvideorenderercontrol.mm @@ -71,7 +71,7 @@ public: } MapMode mapMode() const { return NotMapped; } - uchar *map(MapMode, int*, int*) { return 0; } + MapData map(MapMode mode) override { return {}; } void unmap() {} QVariant handle() const diff --git a/src/plugins/common/evr/evrd3dpresentengine.cpp b/src/plugins/common/evr/evrd3dpresentengine.cpp index 964504e48..51f8b1a39 100644 --- a/src/plugins/common/evr/evrd3dpresentengine.cpp +++ b/src/plugins/common/evr/evrd3dpresentengine.cpp @@ -90,7 +90,7 @@ public: QVariant handle() const override; MapMode mapMode() const override { return m_mapMode; } - uchar *map(MapMode, int*, int*) override; + MapData map(MapMode mode) override; void unmap() override; private: @@ -101,28 +101,27 @@ private: mutable unsigned int m_textureId = 0; }; -uchar *IMFSampleVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine) +IMFSampleVideoBuffer::MapData IMFSampleVideoBuffer::map(MapMode mode) { if (!m_surface || m_mapMode != NotMapped) - return 0; + return {}; D3DSURFACE_DESC desc; if (FAILED(m_surface->GetDesc(&desc))) - return 0; + return {}; D3DLOCKED_RECT rect; if (FAILED(m_surface->LockRect(&rect, NULL, mode == ReadOnly ? D3DLOCK_READONLY : 0))) - return 0; + return {}; m_mapMode = mode; - if (numBytes) - *numBytes = (int)(rect.Pitch * desc.Height); - - if (bytesPerLine) - *bytesPerLine = (int)rect.Pitch; - - return reinterpret_cast<uchar *>(rect.pBits); + MapData mapData; + mapData.nBytes = (int)(rect.Pitch * desc.Height); + mapData.nPlanes = 1; + mapData.bytesPerLine[0] = (int)rect.Pitch; + mapData.data[0] = reinterpret_cast<uchar *>(rect.pBits); + return mapData; } void IMFSampleVideoBuffer::unmap() diff --git a/src/plugins/qnx/mediaplayer/mmrendererplayervideorenderercontrol.cpp b/src/plugins/qnx/mediaplayer/mmrendererplayervideorenderercontrol.cpp index 3b5715157..68cb47c3c 100644 --- a/src/plugins/qnx/mediaplayer/mmrendererplayervideorenderercontrol.cpp +++ b/src/plugins/qnx/mediaplayer/mmrendererplayervideorenderercontrol.cpp @@ -154,15 +154,8 @@ public: MapMode mapMode() const { return QAbstractVideoBuffer::ReadWrite; } - void unmap() { - - } - uchar *map(MapMode mode, int * numBytes, int * bytesPerLine) { - Q_UNUSED(mode); - Q_UNUSED(numBytes); - Q_UNUSED(bytesPerLine); - return 0; - } + void unmap() {} + MapData map(MapMode mode) override { return {}; } QVariant handle() const { if (!m_handle) { const_cast<QnxTextureBuffer*>(this)->m_handle = m_windowGrabber->getNextTextureId(); diff --git a/src/plugins/wmf/player/mfvideorenderercontrol.cpp b/src/plugins/wmf/player/mfvideorenderercontrol.cpp index 7b121255f..212533009 100644 --- a/src/plugins/wmf/player/mfvideorenderercontrol.cpp +++ b/src/plugins/wmf/player/mfvideorenderercontrol.cpp @@ -74,29 +74,27 @@ namespace m_buffer->Release(); } - uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) + MapData map(MapMode mode) override { + MapData mapData; if (m_mapMode == NotMapped && mode != NotMapped) { BYTE *bytes; DWORD length; HRESULT hr = m_buffer->Lock(&bytes, NULL, &length); if (SUCCEEDED(hr)) { - if (numBytes) - *numBytes = int(length); - - if (bytesPerLine) - *bytesPerLine = m_bytesPerLine; - + mapData.nBytes = qsizetype(length); + mapData.nPlanes = 1; + mapData.bytesPerLine[0] = m_bytesPerLine; + mapData.data[0] = reinterpret_cast<uchar *>(bytes); m_mapMode = mode; - return reinterpret_cast<uchar *>(bytes); } else { qWarning("Faild to lock mf buffer!"); } } - return 0; + return mapData; } - void unmap() + void unmap() override { if (m_mapMode == NotMapped) return; @@ -104,7 +102,7 @@ namespace m_buffer->Unlock(); } - MapMode mapMode() const + MapMode mapMode() const override { return m_mapMode; } |