• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mcallegari / qlcplus / 19144422256

06 Nov 2025 05:33PM UTC coverage: 34.256% (-0.1%) from 34.358%
19144422256

push

github

mcallegari
Back to 5.1.0 debug

17718 of 51723 relevant lines covered (34.26%)

19528.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/ui/src/videoprovider.cpp
1
/*
2
  Q Light Controller Plus
3
  videoprovider.cpp
4

5
  Copyright (c) Massimo Callegari
6

7
  Licensed under the Apache License, Version 2.0 (the "License");
8
  you may not use this file except in compliance with the License.
9
  You may obtain a copy of the License at
10

11
      http://www.apache.org/licenses/LICENSE-2.0.txt
12

13
  Unless required by applicable law or agreed to in writing, software
14
  distributed under the License is distributed on an "AS IS" BASIS,
15
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
  See the License for the specific language governing permissions and
17
  limitations under the License.
18
*/
19

20
#include <QVersionNumber>
21
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
22
 #include <QMediaMetaData>
23
 #include <QAudioOutput>
24
#endif
25
#include <QApplication>
26
#include <QMediaPlayer>
27
#include <QVideoWidget>
28
#include <QScreen>
29

30
#include "videoprovider.h"
31
#include "qlcfile.h"
32
#include "doc.h"
33

34
VideoProvider::VideoProvider(Doc *doc, QObject *parent)
×
35
    : QObject(parent)
36
    , m_doc(doc)
×
37
{
38
    Q_ASSERT(doc != NULL);
×
39
    connect(m_doc, SIGNAL(functionAdded(quint32)),
×
40
            this, SLOT(slotFunctionAdded(quint32)));
41
    connect(m_doc, SIGNAL(functionRemoved(quint32)),
×
42
            this, SLOT(slotFunctionRemoved(quint32)));
43
}
×
44

45
VideoProvider::~VideoProvider()
×
46
{
47
    m_videoMap.clear();
×
48
}
×
49

50
void VideoProvider::slotFunctionAdded(quint32 id)
×
51
{
52
    Function *func = m_doc->function(id);
×
53
    if (func == NULL)
×
54
        return;
×
55

56
    if (func->type() == Function::VideoType)
×
57
    {
58
        VideoWidget *vWidget = new VideoWidget(qobject_cast<Video *>(func));
×
59
        m_videoMap[id] = vWidget;
×
60
    }
61
}
62

63
void VideoProvider::slotFunctionRemoved(quint32 id)
×
64
{
65
    if (m_videoMap.contains(id))
×
66
    {
67
        VideoWidget *vw = m_videoMap.take(id);
×
68
        delete vw;
×
69
    }
70
}
×
71

72
/*********************************************************************
73
 * VideoWidget class implementation
74
 *********************************************************************/
75

76
VideoWidget::VideoWidget(Video *video, QObject *parent)
×
77
    : QObject(parent)
78
    , m_video(video)
×
79
    , m_videoPlayer(NULL)
×
80
    , m_videoWidget(NULL)
×
81
{
82
    Q_ASSERT(video != NULL);
×
83

84
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
85
    m_videoPlayer = new QMediaPlayer(this, QMediaPlayer::VideoSurface);
86
#else
87
    m_videoPlayer = new QMediaPlayer(this);
×
88
    m_audioOutput = new QAudioOutput(this);
×
89
    m_videoPlayer->setAudioOutput(m_audioOutput);
×
90
#endif
91
    m_videoPlayer->moveToThread(QCoreApplication::instance()->thread());
×
92

93
    if (QLCFile::getQtRuntimeVersion() >= 50700 && m_videoWidget == NULL)
×
94
    {
95
        m_videoWidget = new QVideoWidget;
×
96
        m_videoWidget->setStyleSheet("background-color:black;");
×
97
        m_videoPlayer->setVideoOutput(m_videoWidget);
×
98
    }
99

100
    connect(m_videoPlayer, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
×
101
            this, SLOT(slotStatusChanged(QMediaPlayer::MediaStatus)));
102
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
103
    connect(m_videoPlayer, SIGNAL(metaDataChanged(QString,QVariant)),
104
            this, SLOT(slotMetaDataChanged(QString,QVariant)));
105
#else
106
    connect(m_videoPlayer, SIGNAL(metaDataChanged()),
×
107
            this, SLOT(slotMetaDataChanged()));
108
#endif
109
    connect(m_videoPlayer, SIGNAL(durationChanged(qint64)),
×
110
            this, SLOT(slotTotalTimeChanged(qint64)));
111

112
    connect(m_video, SIGNAL(sourceChanged(QString)),
×
113
            this, SLOT(slotSourceUrlChanged(QString)));
114
    connect(m_video, SIGNAL(requestPlayback()),
×
115
            this, SLOT(slotPlaybackVideo()));
116
    connect(m_video, SIGNAL(requestPause(bool)),
×
117
            this, SLOT(slotSetPause(bool)));
118
    connect(m_video, SIGNAL(requestStop()),
×
119
            this, SLOT(slotStopVideo()));
120
    connect(m_video, SIGNAL(requestBrightnessAdjust(int)),
×
121
            this, SLOT(slotBrightnessAdjust(int)));
122

123
    QString sourceURL = m_video->sourceUrl();
×
124
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
125
    if (sourceURL.contains("://"))
126
        m_videoPlayer->setMedia(QUrl(sourceURL));
127
    else
128
        m_videoPlayer->setMedia(QUrl::fromLocalFile(sourceURL));
129
#else
130
    if (sourceURL.contains("://"))
×
131
        m_videoPlayer->setSource(QUrl(sourceURL));
×
132
    else
133
        m_videoPlayer->setSource(QUrl::fromLocalFile(sourceURL));
×
134
#endif
135
    qDebug() << "Video source URL:" << sourceURL;
×
136
}
×
137

138
void VideoWidget::slotSourceUrlChanged(QString url)
×
139
{
140
    qDebug() << "Video source URL changed:" << url;
×
141

142
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
143
    if (url.contains("://"))
144
        m_videoPlayer->setMedia(QUrl(url));
145
    else
146
        m_videoPlayer->setMedia(QUrl::fromLocalFile(url));
147
#else
148
    if (url.contains("://"))
×
149
        m_videoPlayer->setSource(QUrl(url));
×
150
    else
151
        m_videoPlayer->setSource(QUrl::fromLocalFile(url));
×
152
#endif
153
}
×
154

155
void VideoWidget::slotTotalTimeChanged(qint64 duration)
×
156
{
157
    qDebug() << "Video duration: " << duration;
×
158
    m_video->setTotalDuration(duration);
×
159
}
×
160

161
void VideoWidget::slotStatusChanged(QMediaPlayer::MediaStatus status)
×
162
{
163
    qDebug() << Q_FUNC_INFO << status;
×
164
    switch (status)
×
165
    {
166
        case QMediaPlayer::NoMedia:
×
167
        case QMediaPlayer::LoadedMedia:
168
        case QMediaPlayer::BufferingMedia:
169
        case QMediaPlayer::BufferedMedia:
170
            //setStatusInfo(QString());
171
        break;
×
172
        case QMediaPlayer::LoadingMedia:
×
173
            //setStatusInfo(tr("Loading..."));
174
        break;
×
175
        case QMediaPlayer::StalledMedia:
×
176
            //setStatusInfo(tr("Media Stalled"));
177
        break;
×
178
        case QMediaPlayer::EndOfMedia:
×
179
        {
180
            if (m_videoPlayer != NULL)
×
181
                m_videoPlayer->stop();
×
182

183
            if (m_video->runOrder() == Video::Loop)
×
184
            {
185
                m_videoPlayer->play();
×
186
                break;
×
187
            }
188

189
            if (m_videoWidget != NULL)
×
190
                m_videoWidget->hide();
×
191

192
            m_video->stop(functionParent());
×
193
            break;
×
194
        }
195
        default:
×
196
        case QMediaPlayer::InvalidMedia:
197
            //displayErrorMessage();
198
        break;
×
199
    }
200
}
×
201

202
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
203
void VideoWidget::slotMetaDataChanged(QString key, QVariant data)
204
{
205
    if (m_video == NULL)
206
        return;
207

208
    qDebug() << Q_FUNC_INFO << "Got meta data:" << key;
209
    if (key == "Resolution")
210
        m_video->setResolution(data.toSize());
211
    else if (key == "VideoCodec")
212
        m_video->setVideoCodec(data.toString());
213
    else if (key == "AudioCodec")
214
        m_video->setAudioCodec(data.toString());
215
}
216
#else
217
void VideoWidget::slotMetaDataChanged()
×
218
{
219
    if (m_video == NULL)
×
220
        return;
×
221

222
    QMediaMetaData md = m_videoPlayer->metaData();
×
223
    foreach (QMediaMetaData::Key k, md.keys())
×
224
    {
225
        qDebug() << "[Metadata]" << md.metaDataKeyToString(k) << ":" << md.stringValue(k);
×
226
        switch (k)
×
227
        {
228
            case QMediaMetaData::Resolution:
×
229
                m_video->setResolution(md.value(k).toSize());
×
230
            break;
×
231
            case QMediaMetaData::VideoCodec:
×
232
                m_video->setVideoCodec(md.stringValue(k));
×
233
            break;
×
234
            case QMediaMetaData::AudioCodec:
×
235
                m_video->setAudioCodec(md.stringValue(k));
×
236
            break;
×
237
            default:
×
238
            break;
×
239
        }
240
    }
×
241
}
×
242
#endif
243

244
void VideoWidget::slotPlaybackVideo()
×
245
{
246
    int screen = m_video->screen();
×
247
    QList<QScreen*> screens = QGuiApplication::screens();
×
248
    QScreen *scr = screens.count() > screen ? screens.at(screen) : screens.first();
×
249
    QRect rect = scr->availableGeometry();
×
250

251
    if (QLCFile::getQtRuntimeVersion() < 50700 && m_videoWidget == NULL)
×
252
    {
253
        m_videoWidget = new QVideoWidget;
×
254
        m_videoWidget->setStyleSheet("background-color:black;");
×
255
        m_videoPlayer->setVideoOutput(m_videoWidget);
×
256
    }
257

258
    m_videoWidget->setWindowFlags(m_videoWidget->windowFlags() | Qt::WindowStaysOnTopHint);
×
259

260
    if (m_video->fullscreen() == false)
×
261
    {
262
        QSize resolution = m_video->resolution();
×
263
        m_videoWidget->setFullScreen(false);
×
264
        if (resolution.isEmpty())
×
265
            m_videoWidget->setGeometry(0, 50, 640, 480);
×
266
        else
267
            m_videoWidget->setGeometry(0, 50, resolution.width(), resolution.height());
×
268
        m_videoWidget->move(rect.topLeft());
×
269
    }
270
    else
271
    {
272
#if defined(WIN32) || defined(Q_OS_WIN)
273
        m_videoWidget->setFullScreen(true);
274
        m_videoWidget->setGeometry(rect);
275
#else
276
        m_videoWidget->setGeometry(rect);
×
277
        m_videoWidget->setFullScreen(true);
×
278
#endif
279
    }
280

281
    if (m_videoPlayer->isSeekable())
×
282
        m_videoPlayer->setPosition(m_video->elapsed());
×
283
    else
284
        m_videoPlayer->setPosition(0);
×
285

286
    m_videoWidget->show();
×
287
    m_videoPlayer->play();
×
288
}
×
289

290
void VideoWidget::slotSetPause(bool enable)
×
291
{
292
    if (enable)
×
293
        m_videoPlayer->pause();
×
294
    else
295
        m_videoPlayer->play();
×
296
}
×
297

298
void VideoWidget::slotStopVideo()
×
299
{
300
    if (m_videoPlayer != NULL)
×
301
        m_videoPlayer->stop();
×
302

303
    if (m_videoWidget != NULL)
×
304
    {
305
        if (m_video->fullscreen())
×
306
            m_videoWidget->setFullScreen(false);
×
307
        m_videoWidget->hide();
×
308
    }
309

310
    m_video->stop(functionParent());
×
311
}
×
312

313
void VideoWidget::slotBrightnessAdjust(int value)
×
314
{
315
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
316
    if (m_videoWidget != NULL)
317
        m_videoWidget->setBrightness(value);
318
    if (m_videoPlayer)
319
        m_videoPlayer->setVolume(value + 100);
320
#else
321
    if (m_audioOutput)
×
322
        m_audioOutput->setVolume(value + 100);
×
323
#endif
324
}
×
325

326
int VideoWidget::getScreenCount()
×
327
{
328
    int screenCount = QGuiApplication::screens().count();
×
329

330
    return screenCount;
×
331
}
332

333
FunctionParent VideoWidget::functionParent() const
×
334
{
335
    return FunctionParent::master();
×
336
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc