QAbstractVideoSurface Class

The QAbstractVideoSurface class is a base class for video presentation surfaces. 更多...

头文件: #include <QAbstractVideoSurface>
qmake: QT += multimedia
基类: QObject

公有类型

enum Error { NoError, UnsupportedFormatError, IncorrectFormatError, StoppedError, ResourceError }

属性

公有函数

QAbstractVideoSurface(QObject *parent = Q_NULLPTR)
~QAbstractVideoSurface()
Error error() const
bool isActive() const
virtual bool isFormatSupported(const QVideoSurfaceFormat &format) const
QSize nativeResolution() const
virtual QVideoSurfaceFormat nearestFormat(const QVideoSurfaceFormat &format) const
virtual bool present(const QVideoFrame &frame) = 0
virtual bool start(const QVideoSurfaceFormat &format)
virtual void stop()
virtual QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType type = QAbstractVideoBuffer::NoHandle) const = 0
QVideoSurfaceFormat surfaceFormat() const
  • 32 个公有函数继承自 QObject

信号

void activeChanged(bool active)
void nativeResolutionChanged(const QSize &resolution)
void supportedFormatsChanged()
void surfaceFormatChanged(const QVideoSurfaceFormat &format)

受保护的函数

void setError(Error error)
void setNativeResolution(const QSize &resolution)
  • 9 个受保护的函数继承自 QObject

其他继承的成员

  • 1 个公有槽函数继承自 QObject
  • 1 个公有变量继承自 QObject
  • 10 个静态公有成员继承自 QObject
  • 2 个受保护的变量继承自 QObject

详细描述

QAbstractVideoSurface定义标准接口, 用于显示视频.

QAbstractVideoSurface 定义标准接口, 用于显示视频. 你可以子类化QAbstractVideoSurface, 接收来自 解码器摄像头 等视频帧, 并执行自己的处理流程.

一个视频界面显示一组连续的视频流, 视频流的格式采用 QVideoFrame 定义,每一帧的格式与开始播放是提供的流格式兼容. 每一帧可以具有时间戳信息, 定义何时显示视频帧.

视频界面的视频帧像素格式可以调用 supportedPixelFormats() 函数查询, isFormatSupported() 函数检查视频流格式是否支持.如果不支持某种格式, nearestFormat() 函数返回相近的建议格式. 例如, 如果视频界面支持一组固定的分辨率, nearestFormat()函数返回支持的最小分辨率.

start() 函数采用支持格式启用视频播放. 开始播放后, 视频界面开始显示, 并在 present() 函数接收视频帧. 视频界面可能持有视频帧缓存的引用, 直到新的帧数据到达, 停止流传输, 时间戳结束. stop() 函数停止视频渲染, 并释放视频缓冲区.

实现QAstractVideoSurface的子类

自定义子类时, 仅需要实现少数几个函数, 分为两类:

  • 视频格式相关函数
  • 视频渲染相关函数

对于格式相关函数, 你必须描述你支持的像素格式 (包括 nearestFormat() 函数). 对于渲染相关函数, 你必须实现 present() 函数, start() 函数, stop() 函数.

注意: 你必须在重载 start() 和 stop() 函数中调用基类的start()和stop().

成员类型

enum QAbstractVideoSurface::Error

This enum describes the errors that may be returned by the error() function.

ConstantValueDescription
QAbstractVideoSurface::NoError0No error occurred.
QAbstractVideoSurface::UnsupportedFormatError1A video format was not supported.
QAbstractVideoSurface::IncorrectFormatError2A video frame was not compatible with the format of the surface.
QAbstractVideoSurface::StoppedError3The surface has not been started.
QAbstractVideoSurface::ResourceError4The surface could not allocate some resource.

属性

nativeResolution : const QSize

The native resolution of video surface. This is the resolution of video frames the surface can render with optimal quality and/or performance.

The native resolution is not always known and can be changed during playback.

访问函数:

QSize nativeResolution() const

Notifier signal:

void nativeResolutionChanged(const QSize &resolution)

成员函数

QAbstractVideoSurface::QAbstractVideoSurface(QObject *parent = Q_NULLPTR)

Constructs a video surface with the given parent.

QAbstractVideoSurface::~QAbstractVideoSurface()

Destroys a video surface.

[signal] void QAbstractVideoSurface::activeChanged(bool active)

Signals that the active state of a video surface has changed.

参见 isActive(), start(), and stop().

Error QAbstractVideoSurface::error() const

Returns the last error that occurred.

If a surface fails to start(), or stops unexpectedly this function can be called to discover what error occurred.

参见 setError().

bool QAbstractVideoSurface::isActive() const

Indicates whether a video surface has been started.

Returns true if the surface has been started, and false otherwise.

[virtual] bool QAbstractVideoSurface::isFormatSupported(const QVideoSurfaceFormat &format) const

Tests a video surface format to determine if a surface can accept it.

Returns true if the format is supported by the surface, and false otherwise.

[signal] void QAbstractVideoSurface::nativeResolutionChanged(const QSize &resolution)

Signals the native resolution of video surface has changed.

Note: Notifier signal for property nativeResolution.

[virtual] QVideoSurfaceFormat QAbstractVideoSurface::nearestFormat(const QVideoSurfaceFormat &format) const

Returns a supported video surface format that is similar to format.

A similar surface format is one that has the same pixel format and handle type but may differ in some of the other properties. For example, if there are restrictions on the frame sizes a video surface can accept it may suggest a format with a larger frame size and a 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.

[pure virtual] bool QAbstractVideoSurface::present(const QVideoFrame &frame)

Presents a video frame.

Returns true if the frame was presented, and false if an error occurred.

Not all surfaces will block until the presentation of a frame has completed. Calling present() on a non-blocking surface may fail if called before the presentation of a previous frame has completed. In such cases the surface may not return to a ready state until it has had an opportunity to process events.

If present() fails for any other reason the surface should immediately enter the stopped state and an error() value will be set.

A video surface must be in the started state for present() to succeed, and the format of the video frame must be compatible with the current video surface format.

参见 error().

[protected] void QAbstractVideoSurface::setError(Error error)

Sets the value of error() to error.

This can be called by implementors of this interface to communicate what the most recent error was.

参见 error().

[protected] void QAbstractVideoSurface::setNativeResolution(const QSize &resolution)

Set the video surface native resolution.

This function can be called by implementors of this interface to specify to frame producers what the native resolution of this surface is.

参见 nativeResolution().

[virtual] bool QAbstractVideoSurface::start(const QVideoSurfaceFormat &format)

Starts a video surface presenting format frames.

Returns true if the surface was started, and false if an error occurred.

Note: You must call the base class implementation of start() at the end of your implementation.

参见 isActive() and stop().

[virtual] void QAbstractVideoSurface::stop()

Stops a video surface presenting frames and releases any resources acquired in start().

Note: You must call the base class implementation of stop() at the start of your implementation.

参见 isActive() and start().

[signal] void QAbstractVideoSurface::supportedFormatsChanged()

Signals that the set of formats supported by a video surface has changed.

参见 supportedPixelFormats() and isFormatSupported().

[pure virtual] QList<QVideoFrame::PixelFormat> QAbstractVideoSurface::supportedPixelFormats(QAbstractVideoBuffer::HandleType type = QAbstractVideoBuffer::NoHandle) const

Returns a list of pixel formats a video surface can present for a given handle type.

The pixel formats returned for the QAbstractVideoBuffer::NoHandle type are valid for any buffer that can be mapped in read-only mode.

Types that are first in the list can be assumed to be faster to render.

QVideoSurfaceFormat QAbstractVideoSurface::surfaceFormat() const

Returns the format of a video surface.

[signal] void QAbstractVideoSurface::surfaceFormatChanged(const QVideoSurfaceFormat &format)

Signals that the configured format of a video surface has changed.

参见 surfaceFormat() and start().