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)
10 : QObject(parent),
11 q(parent)
12{
13}
14
15void QPlatformAudioDecoder::error(int error, const QString &errorString)
16{
17 if (error == m_error && errorString == m_errorString)
18 return;
19 m_error = QAudioDecoder::Error(error);
20 m_errorString = errorString;
21
22 if (m_error != QAudioDecoder::NoError) {
23 setIsDecoding(false);
24 emit q->error(error: m_error);
25 }
26}
27
28void QPlatformAudioDecoder::bufferAvailableChanged(bool available)
29{
30 if (m_bufferAvailable == available)
31 return;
32 m_bufferAvailable = available;
33
34 if (QThread::currentThread() != q->thread())
35 QMetaObject::invokeMethod(obj: q, member: "bufferAvailableChanged", c: Qt::QueuedConnection, Q_ARG(bool, available));
36 else
37 emit q->bufferAvailableChanged(available);
38}
39
40void QPlatformAudioDecoder::bufferReady()
41{
42 if (QThread::currentThread() != q->thread())
43 QMetaObject::invokeMethod(obj: q, member: "bufferReady", c: Qt::QueuedConnection);
44 else
45 emit q->bufferReady();
46}
47
48void QPlatformAudioDecoder::sourceChanged()
49{
50 emit q->sourceChanged();
51}
52
53void QPlatformAudioDecoder::formatChanged(const QAudioFormat &format)
54{
55 emit q->formatChanged(format);
56}
57
58void QPlatformAudioDecoder::finished()
59{
60 durationChanged(duration: -1);
61 setIsDecoding(false);
62 emit q->finished();
63}
64
65void QPlatformAudioDecoder::positionChanged(qint64 position)
66{
67 if (m_position == position)
68 return;
69 m_position = position;
70 emit q->positionChanged(position);
71}
72
73void QPlatformAudioDecoder::durationChanged(qint64 duration)
74{
75 if (m_duration == duration)
76 return;
77 m_duration = duration;
78 emit q->durationChanged(duration);
79}
80
81QT_END_NAMESPACE
82
83#include "moc_qplatformaudiodecoder_p.cpp"
84

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