1 /*
2 SPDX-FileCopyrightText: 2010 Nokia Corporation and/or its subsidiary(-ies). <qt-info@nokia.com>
3 SPDX-FileCopyrightText: 2011-2013 Collabora Ltd. <info@collabora.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only
6 */
7
8 #include "qtquick2videosinkdelegate.h"
9 #include "../painters/videonode.h"
10
QtQuick2VideoSinkDelegate(GstElement * sink,QObject * parent)11 QtQuick2VideoSinkDelegate::QtQuick2VideoSinkDelegate(GstElement *sink, QObject *parent)
12 : BaseDelegate(sink, parent)
13 {
14 }
15
updateNode(QSGNode * node,const QRectF & targetArea)16 QSGNode* QtQuick2VideoSinkDelegate::updateNode(QSGNode *node, const QRectF & targetArea)
17 {
18 GST_TRACE_OBJECT(m_sink, "updateNode called");
19 bool sgnodeFormatChanged = false;
20
21 VideoNode *vnode = dynamic_cast<VideoNode*>(node);
22 if (!vnode) {
23 GST_INFO_OBJECT(m_sink, "creating new VideoNode");
24 vnode = new VideoNode;
25 m_formatDirty = true;
26 }
27
28 if (!m_buffer) {
29 if (vnode->materialType() != VideoNode::MaterialTypeSolidBlack) {
30 vnode->setMaterialTypeSolidBlack();
31 sgnodeFormatChanged = true;
32 }
33 if (sgnodeFormatChanged || targetArea != m_areas.targetArea || !vnode->geometry()) {
34 m_areas.targetArea = targetArea;
35 vnode->updateGeometry(m_areas);
36 }
37 } else {
38 //change format before geometry, so that we change QSGGeometry as well
39 if (m_formatDirty) {
40 vnode->changeFormat(m_bufferFormat);
41 sgnodeFormatChanged = true;
42 }
43
44 //recalculate the video area if needed
45 QReadLocker forceAspectRatioLocker(&m_forceAspectRatioLock);
46 if (sgnodeFormatChanged || targetArea != m_areas.targetArea || m_forceAspectRatioDirty) {
47 m_forceAspectRatioDirty = false;
48
49 QReadLocker pixelAspectRatioLocker(&m_pixelAspectRatioLock);
50 Qt::AspectRatioMode aspectRatioMode = m_forceAspectRatio ?
51 Qt::KeepAspectRatio : Qt::IgnoreAspectRatio;
52 m_areas.calculate(targetArea, m_bufferFormat.frameSize(),
53 m_bufferFormat.pixelAspectRatio(), m_pixelAspectRatio,
54 aspectRatioMode);
55 pixelAspectRatioLocker.unlock();
56
57 GST_LOG_OBJECT(m_sink,
58 "Recalculated paint areas: "
59 "Frame size: " QSIZE_FORMAT ", "
60 "target area: " QRECTF_FORMAT ", "
61 "video area: " QRECTF_FORMAT ", "
62 "black1: " QRECTF_FORMAT ", "
63 "black2: " QRECTF_FORMAT,
64 QSIZE_FORMAT_ARGS(m_bufferFormat.frameSize()),
65 QRECTF_FORMAT_ARGS(m_areas.targetArea),
66 QRECTF_FORMAT_ARGS(m_areas.videoArea),
67 QRECTF_FORMAT_ARGS(m_areas.blackArea1),
68 QRECTF_FORMAT_ARGS(m_areas.blackArea2)
69 );
70
71 vnode->updateGeometry(m_areas);
72 }
73 forceAspectRatioLocker.unlock();
74
75 if (m_formatDirty) {
76 m_formatDirty = false;
77
78 //make sure to update the colors after changing material
79 m_colorsDirty = true;
80 }
81
82 QReadLocker colorsLocker(&m_colorsLock);
83 if (m_colorsDirty) {
84 vnode->updateColors(m_brightness, m_contrast, m_hue, m_saturation);
85 m_colorsDirty = false;
86 }
87 colorsLocker.unlock();
88
89 vnode->setCurrentFrame(m_buffer);
90 }
91
92 return vnode;
93 }
94