1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qplatformaudiodecoder_p.h"
5#include "qthread.h"
6
7QT_BEGIN_NAMESPACE
8
9QPlatformAudioDecoder::QPlatformAudioDecoder(QAudioDecoder *parent) : q(parent) { }
10
11QPlatformAudioDecoder::~QPlatformAudioDecoder() = default;
12
13void QPlatformAudioDecoder::error(int error, const QString &errorString)
14{
15 if (error == m_error && errorString == m_errorString)
16 return;
17 m_error = QAudioDecoder::Error(error);
18 m_errorString = errorString;
19
20 if (m_error != QAudioDecoder::NoError) {
21 setIsDecoding(false);
22 emit q->error(error: m_error);
23 }
24}
25
26void QPlatformAudioDecoder::bufferAvailableChanged(bool available)
27{
28 if (m_bufferAvailable == available)
29 return;
30 m_bufferAvailable = available;
31
32 if (QThread::currentThread() != q->thread())
33 QMetaObject::invokeMethod(obj: q, member: "bufferAvailableChanged", c: Qt::QueuedConnection, Q_ARG(bool, available));
34 else
35 emit q->bufferAvailableChanged(available);
36}
37
38void QPlatformAudioDecoder::bufferReady()
39{
40 if (QThread::currentThread() != q->thread())
41 QMetaObject::invokeMethod(obj: q, member: "bufferReady", c: Qt::QueuedConnection);
42 else
43 emit q->bufferReady();
44}
45
46void QPlatformAudioDecoder::sourceChanged()
47{
48 emit q->sourceChanged();
49}
50
51void QPlatformAudioDecoder::formatChanged(const QAudioFormat &format)
52{
53 emit q->formatChanged(format);
54}
55
56void QPlatformAudioDecoder::finished()
57{
58 durationChanged(duration: -1);
59 setIsDecoding(false);
60 emit q->finished();
61}
62
63void QPlatformAudioDecoder::positionChanged(qint64 position)
64{
65 if (m_position == position)
66 return;
67 m_position = position;
68 emit q->positionChanged(position);
69}
70
71void QPlatformAudioDecoder::durationChanged(qint64 duration)
72{
73 if (m_duration == duration)
74 return;
75 m_duration = duration;
76 emit q->durationChanged(duration);
77}
78
79QT_END_NAMESPACE
80
81#include "moc_qplatformaudiodecoder_p.cpp"
82

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtmultimedia/src/multimedia/platform/qplatformaudiodecoder.cpp