QAbstractVideoBuffer Class

The QAbstractVideoBuffer class is an abstraction for video data. More...

Header: #include <QAbstractVideoBuffer>
qmake: QT += multimedia
Inherited By:

QAbstractPlanarVideoBuffer

Public Types

enum HandleType { NoHandle, GLTextureHandle, XvShmImageHandle, CoreImageHandle, QPixmapHandle, …, GLTextureRectangleHandle }
enum MapMode { NotMapped, ReadOnly, WriteOnly, ReadWrite }

Public Functions

QAbstractVideoBuffer(QAbstractVideoBuffer::HandleType type)
virtual ~QAbstractVideoBuffer()
virtual QVariant handle() const
QAbstractVideoBuffer::HandleType handleType() const
virtual uchar *map(QAbstractVideoBuffer::MapMode mode, int *numBytes, int *bytesPerLine) = 0
virtual QAbstractVideoBuffer::MapMode mapMode() const = 0
int mapPlanes(QAbstractVideoBuffer::MapMode mode, int *numBytes, int[4] bytesPerLine = 4, uchar *[4] data = 4)
virtual void release()
virtual void unmap() = 0

Detailed Description

The QVideoFrame class makes use of a QAbstractVideoBuffer internally to reference a buffer of video data. Quite often video data buffers may reside in video memory rather than system memory, and this class provides an abstraction of the location.

In addition, creating a subclass of QAbstractVideoBuffer will allow you to construct video frames from preallocated or static buffers, in cases where the QVideoFrame constructors taking a QByteArray or a QImage do not suffice. This may be necessary when implementing a new hardware accelerated video system, for example.

The contents of a buffer can be accessed by mapping the buffer to memory using the map() function, which returns a pointer to memory containing the contents of the video buffer. The memory returned by map() is released by calling the unmap() function.

The handle() of a buffer may also be used to manipulate its contents using type specific APIs. The type of a buffer's handle is given by the handleType() function.

See also QVideoFrame.

Member Type Documentation

enum QAbstractVideoBuffer::HandleType

Identifies the type of a video buffers handle.

ConstantValueDescription
QAbstractVideoBuffer::NoHandle0The buffer has no handle, its data can only be accessed by mapping the buffer.
QAbstractVideoBuffer::GLTextureHandle1The handle of the buffer is an OpenGL texture ID of an undefined and platform dependent target type.
QAbstractVideoBuffer::XvShmImageHandle2The handle contains pointer to shared memory XVideo image.
QAbstractVideoBuffer::CoreImageHandle3The handle contains pointer to macOS CIImage.
QAbstractVideoBuffer::QPixmapHandle4The handle of the buffer is a QPixmap.
QAbstractVideoBuffer::EGLImageHandle5The handle of the buffer is an EGLImageKHR.
QAbstractVideoBuffer::UserHandle1000Start value for user defined handle types.
QAbstractVideoBuffer::GLTextureRectangleHandle6The handle of the buffer is an OpenGL texture ID of target type GL_TEXTURE_RECTANGLE.

See also handleType().

enum QAbstractVideoBuffer::MapMode

Enumerates how a video buffer's data is mapped to system memory.

ConstantValueDescription
QAbstractVideoBuffer::NotMapped0x00The video buffer is not mapped to memory.
QAbstractVideoBuffer::ReadOnly0x01The mapped memory is populated with data from the video buffer when mapped, but the content of the mapped memory may be discarded when unmapped.
QAbstractVideoBuffer::WriteOnly0x02The mapped memory is uninitialized when mapped, but the possibly modified content will be used to populate the video buffer when unmapped.
QAbstractVideoBuffer::ReadWriteReadOnly | WriteOnlyThe mapped memory is populated with data from the video buffer, and the video buffer is repopulated with the content of the mapped memory when it is unmapped.

See also mapMode() and map().

Member Function Documentation

QAbstractVideoBuffer::QAbstractVideoBuffer(QAbstractVideoBuffer::HandleType type)

Constructs an abstract video buffer of the given type.

[virtual] QAbstractVideoBuffer::~QAbstractVideoBuffer()

Destroys an abstract video buffer.

[virtual] QVariant QAbstractVideoBuffer::handle() const

Returns a type specific handle to the data buffer.

The type of the handle is given by handleType() function.

See also handleType().

QAbstractVideoBuffer::HandleType QAbstractVideoBuffer::handleType() const

Returns the type of a video buffer's handle.

See also handle().

[pure virtual] uchar *QAbstractVideoBuffer::map(QAbstractVideoBuffer::MapMode mode, int *numBytes, int *bytesPerLine)

Maps the contents of a video buffer to memory.

In some cases the video buffer might be stored in video memory or otherwise inaccessible memory, so it is necessary to map the buffer before accessing the pixel data. This may involve copying the contents around, so avoid mapping and unmapping unless required.

The map mode indicates whether the contents of the mapped memory should be read from and/or written to the buffer. If the map mode includes the QAbstractVideoBuffer::ReadOnly flag the mapped memory will be populated with the content of the buffer when initially mapped. If the map mode includes the QAbstractVideoBuffer::WriteOnly flag the content of the possibly modified mapped memory will be written back to the buffer when unmapped.

When access to the data is no longer needed be sure to call the unmap() function to release the mapped memory and possibly update the buffer contents.

Returns a pointer to the mapped memory region, or a null pointer if the mapping failed. The size in bytes of the mapped memory region is returned in numBytes, and the line stride in bytesPerLine.

Note: Writing to memory that is mapped as read-only is undefined, and may result in changes to shared data or crashes.

See also unmap() and mapMode().

[pure virtual] QAbstractVideoBuffer::MapMode QAbstractVideoBuffer::mapMode() const

Returns the mode a video buffer is mapped in.

See also map().

int QAbstractVideoBuffer::mapPlanes(QAbstractVideoBuffer::MapMode mode, int *numBytes, int[4] bytesPerLine = 4, uchar *[4] data = 4)

Independently maps the planes of a video buffer to memory.

The map mode indicates whether the contents of the mapped memory should be read from and/or written to the buffer. If the map mode includes the QAbstractVideoBuffer::ReadOnly flag the mapped memory will be populated with the content of the buffer when initially mapped. If the map mode includes the QAbstractVideoBuffer::WriteOnly flag the content of the possibly modified mapped memory will be written back to the buffer when unmapped.

When access to the data is no longer needed be sure to call the unmap() function to release the mapped memory and possibly update the buffer contents.

Returns the number of planes in the mapped video data. For each plane the line stride of that plane will be returned in bytesPerLine, and a pointer to the plane data will be returned in data. The accumulative size of the mapped data is returned in numBytes.

Not all buffer implementations will map more than the first plane, if this returns a single plane for a planar format the additional planes will have to be calculated from the line stride of the first plane and the frame height. Mapping a buffer with QVideoFrame will do this for you.

To implement this function create a derivative of QAbstractPlanarVideoBuffer and implement its map function instance instead.

This function was introduced in Qt 5.4.

[virtual] void QAbstractVideoBuffer::release()

Releases the video buffer.

QVideoFrame calls QAbstractVideoBuffer::release when the buffer is not used any more and can be destroyed or returned to the buffer pool.

The default implementation deletes the buffer instance.

[pure virtual] void QAbstractVideoBuffer::unmap()

Releases the memory mapped by the map() function.

If the MapMode included the QAbstractVideoBuffer::WriteOnly flag this will write the current content of the mapped memory back to the video frame.

See also map().