6#include <private/qvideooutputorientationhandler_p.h>
7#include <QtMultimedia/qmediaplayer.h>
8#include <QtMultimedia/qmediacapturesession.h>
9#include <private/qfactoryloader_p.h>
10#include <QtCore/qloggingcategory.h>
12#include <QtQuick/QQuickWindow>
13#include <private/qquickwindow_p.h>
14#include <private/qmultimediautils_p.h>
16#include <QtCore/qrunnable.h>
24inline bool qIsDefaultAspect(
int o)
26 return (
o % 180) == 0;
32inline int qNormalizedOrientation(
int o)
109 qRegisterMetaType<QVideoFrameFormat>();
164 m_geometryDirty =
true;
170void QQuickVideoOutput::_q_newFrame(
QSize size)
176 if (m_nativeSize !=
size) {
179 m_geometryDirty =
true;
189void QQuickVideoOutput::_q_updateGeometry()
194 if (!m_geometryDirty && m_lastRect == absoluteRect)
197 QRectF oldContentRect(m_contentRect);
199 m_geometryDirty =
false;
200 m_lastRect = absoluteRect;
202 const auto fill = m_aspectRatioMode;
206 m_contentRect =
rect;
208 m_contentRect =
rect;
219 if (m_contentRect != oldContentRect)
241 return m_orientation;
256 if ((m_orientation % 360) == (
orientation % 360)) {
262 m_geometryDirty =
true;
266 bool oldAspect = qIsDefaultAspect(m_orientation);
271 if (oldAspect != newAspect) {
300 return m_contentRect;
327 if (!qIsDefaultAspect(m_orientation + m_frameOrientation))
353void QQuickVideoOutput::_q_invalidateSceneGraph()
355 invalidateSceneGraph();
358void QQuickVideoOutput::_q_sceneGraphInitialized()
366 invalidateSceneGraph();
369void QQuickVideoOutput::invalidateSceneGraph()
376void QQuickVideoOutput::initRhiForSink()
388 if (changeData.window == m_window)
392 m_window = changeData.window;
404QSize QQuickVideoOutput::nativeSize()
const
409void QQuickVideoOutput::updateGeometry()
418 if (nativeSize().isEmpty()) {
419 m_renderedRect =
rect;
420 m_sourceTextureRect = normalizedViewport;
422 m_renderedRect =
rect;
423 m_sourceTextureRect = normalizedViewport;
425 m_sourceTextureRect = normalizedViewport;
428 m_renderedRect =
rect;
435 const qreal relativeWidth =
rect.width() / contentWidth;
436 const qreal relativeHeight =
rect.height() / contentHeight;
439 const qreal totalOffsetLeft = normalizedViewport.x() + relativeOffsetLeft * normalizedViewport.width();
440 const qreal totalOffsetTop = normalizedViewport.y() + relativeOffsetTop * normalizedViewport.height();
441 const qreal totalWidth = normalizedViewport.width() * relativeWidth;
442 const qreal totalHeight = normalizedViewport.height() * relativeHeight;
444 if (qIsDefaultAspect(
orientation() + m_frameOrientation)) {
445 m_sourceTextureRect =
QRectF(totalOffsetLeft, totalOffsetTop,
446 totalWidth, totalHeight);
448 m_sourceTextureRect =
QRectF(totalOffsetTop, totalOffsetLeft,
449 totalHeight, totalWidth);
455 m_sourceTextureRect.
setTop(m_sourceTextureRect.
bottom());
461 m_sourceTextureRect.
setLeft(m_sourceTextureRect.
right());
476 if (m_frameChanged) {
477 if (videoNode && videoNode->pixelFormat() != m_frame.
pixelFormat()) {
478 qCDebug(qLcVideo) <<
"updatePaintNode: deleting old video node because frame format changed";
484 qCDebug(qLcVideo) <<
"updatePaintNode: no frames yet";
485 m_frameChanged =
false;
494 qCDebug(qLcVideo) <<
"updatePaintNode: Video node created. Handle type:" << m_frame.
handleType();
499 m_frameChanged =
false;
504 if (m_frameChanged) {
505 videoNode->setCurrentFrame(m_frame);
507 updateHdr(videoNode);
510 m_frameChanged =
false;
515 videoNode->setTexturedRectGeometry(m_renderedRect, m_sourceTextureRect,
521void QQuickVideoOutput::updateHdr(
QSGVideoNode *videoNode)
523 auto *videoOutputWindow =
window();
524 if (!videoOutputWindow)
527 auto *swapChain = videoOutputWindow->swapChain();
533 auto *recreateSwapChainJob =
QRunnable::create([swapChain, requiredSwapChainFormat]() {
534 swapChain->destroy();
535 swapChain->setFormat(requiredSwapChainFormat);
536 swapChain->createOrResize();
542 videoOutputWindow->scheduleRenderJob(recreateSwapChainJob, QQuickWindow::AfterSwapStage);
545 videoNode->setSurfaceFormat(swapChain->format());
546 videoNode->setHdrInfo(swapChain->hdrInfo());
549QRectF QQuickVideoOutput::adjustedViewport()
const
558 m_videoFormat =
frame.surfaceFormat();
560 m_frameOrientation =
static_cast<int>(
frame.rotation());
561 m_frameChanged =
true;
566#include "moc_qquickvideooutput_p.cpp"
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
\inmodule QtCore\reentrant
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
void setFlag(Flag flag, bool enabled=true)
Enables the specified flag for this item if enabled is true; if enabled is false, the flag is disable...
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
qreal x
\qmlproperty real QtQuick::Item::x \qmlproperty real QtQuick::Item::y \qmlproperty real QtQuick::Item...
qreal y
Defines the item's y position relative to its parent.
QQuickWindow * window() const
Returns the window in which this item is rendered.
qreal width
This property holds the width of this item.
void setImplicitHeight(qreal)
qreal height
This property holds the height of this item.
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
void setImplicitWidth(qreal)
void update()
Schedules a call to updatePaintNode() for this item.
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void fillModeChanged(QQuickVideoOutput::FillMode)
void contentRectChanged()
void orientationChanged()
void itemChange(ItemChange change, const ItemChangeData &changeData) override
Called when change occurs for this item.
QQuickVideoOutput(QQuickItem *parent=0)
void releaseResources() override
This function is called when an item should release graphics resources which are not already managed ...
QSGNode * updatePaintNode(QSGNode *, UpdatePaintNodeData *) override
Called on the render thread when it is time to sync the state of the item with the scene graph.
void setFillMode(FillMode mode)
static QQuickWindowPrivate * get(QQuickWindow *c)
void sceneGraphInitialized()
\qmlsignal QtQuick::Window::frameSwapped()
void sceneGraphInvalidated()
\qmlsignal QtQuick::Window::sceneGraphInitialized()
\inmodule QtCore\reentrant
constexpr void moveCenter(const QPointF &p) noexcept
Moves the rectangle, leaving the center point at the given position.
constexpr qreal bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
constexpr void setBottom(qreal pos) noexcept
Sets the bottom edge of the rectangle to the given finite y coordinate.
constexpr void setRight(qreal pos) noexcept
Sets the right edge of the rectangle to the given finite x coordinate.
constexpr void setLeft(qreal pos) noexcept
Sets the left edge of the rectangle to the given finite x coordinate.
constexpr qreal height() const noexcept
Returns the height of the rectangle.
constexpr qreal width() const noexcept
Returns the width of the rectangle.
constexpr void setTop(qreal pos) noexcept
Sets the top edge of the rectangle to the given finite y coordinate.
constexpr qreal left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr qreal top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr qreal right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
constexpr QSize size() const noexcept
Returns the size of the rectangle.
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
static QRunnable * create(Callable &&functionToRun)
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
void transpose() noexcept
Swaps the width and height values.
The QVideoFrame class represents a frame of video data.
QVideoFrame::HandleType handleType() const
Returns the type of a video frame's handle.
QVideoFrameFormat surfaceFormat() const
Returns the surface format of this video frame.
QVideoFrameFormat::PixelFormat pixelFormat() const
Returns the pixel format of this video frame.
bool isValid() const
Identifies whether a video frame is valid.
The QVideoSink class represents a generic sink for video data.
void videoFrameChanged(const QVideoFrame &frame) QT6_ONLY(const)
Signals when the video frame changes.
Combined button and popup list for selecting options.
@ KeepAspectRatioByExpanding
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble top
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
static constexpr QSize frameSize(const T &frame)
QImage scaled(const QImage &image)
[0]
myObject disconnect()
[26]
view viewport() -> scroll(dx, dy, deviceRect)