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

mcallegari / qlcplus / 6683238402

29 Oct 2023 12:10PM UTC coverage: 28.07%. Remained the same
6683238402

push

github

mcallegari
engine: fix build

15385 of 54809 relevant lines covered (28.07%)

20267.63 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
#endif
24
#include <QApplication>
25
#include <QMediaPlayer>
26
#include <QVideoWidget>
27
#include <QScreen>
28

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

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

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

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

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

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

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

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

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

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

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

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

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

135
void VideoWidget::slotSourceUrlChanged(QString url)
×
136
{
137
    qDebug() << "Video source URL changed:" << url;
×
138

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

152
void VideoWidget::slotTotalTimeChanged(qint64 duration)
×
153
{
154
    qDebug() << "Video duration: " << duration;
×
155
    m_video->setTotalDuration(duration);
×
156
}
×
157

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

180
            if (m_video->runOrder() == Video::Loop)
×
181
            {
182
                m_videoPlayer->play();
×
183
                break;
×
184
            }
185

186
            if (m_videoWidget != NULL)
×
187
                m_videoWidget->hide();
×
188

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

199
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
200
void VideoWidget::slotMetaDataChanged(QString key, QVariant data)
×
201
{
202
    if (m_video == NULL)
×
203
        return;
×
204

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

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

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

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

255
    m_videoWidget->setWindowFlags(m_videoWidget->windowFlags() | Qt::WindowStaysOnTopHint);
×
256

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

278
    if (m_videoPlayer->isSeekable())
×
279
        m_videoPlayer->setPosition(m_video->elapsed());
×
280
    else
281
        m_videoPlayer->setPosition(0);
×
282

283
    m_videoWidget->show();
×
284
    m_videoPlayer->play();
×
285
}
×
286

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

295
void VideoWidget::slotStopVideo()
×
296
{
297
    if (m_videoPlayer != NULL)
×
298
        m_videoPlayer->stop();
×
299

300
    if (m_videoWidget != NULL)
×
301
    {
302
        if (m_video->fullscreen())
×
303
            m_videoWidget->setFullScreen(false);
×
304
        m_videoWidget->hide();
×
305
    }
306

307
    m_video->stop(functionParent());
×
308
}
×
309

310
void VideoWidget::slotBrightnessAdjust(int value)
×
311
{
312
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
313
    if (m_videoWidget != NULL)
×
314
        m_videoWidget->setBrightness(value);
×
315
#else
316
    Q_UNUSED(value)
317
#endif
318
}
×
319

320
int VideoWidget::getScreenCount()
×
321
{
322
    int screenCount = QGuiApplication::screens().count();
×
323

324
    return screenCount;
×
325
}
326

327
FunctionParent VideoWidget::functionParent() const
×
328
{
329
    return FunctionParent::master();
×
330
}
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