| 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 | |
| 7 | QT_BEGIN_NAMESPACE | 
| 8 | |
| 9 | QPlatformAudioDecoder::QPlatformAudioDecoder(QAudioDecoder *parent) : q(parent) { } | 
| 10 | |
| 11 | QPlatformAudioDecoder::~QPlatformAudioDecoder() = default; | 
| 12 | |
| 13 | void 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 | |
| 26 | void QPlatformAudioDecoder::bufferAvailableChanged(bool available) | 
| 27 | { | 
| 28 | if (m_bufferAvailable == available) | 
| 29 | return; | 
| 30 | m_bufferAvailable = available; | 
| 31 | |
| 32 | if (!q->thread()->isCurrentThread()) | 
| 33 |         QMetaObject::invokeMethod(obj: q, member: "bufferAvailableChanged", c: Qt::QueuedConnection, Q_ARG(bool, available));  | 
| 34 | else | 
| 35 | emit q->bufferAvailableChanged(available); | 
| 36 | } | 
| 37 | |
| 38 | void QPlatformAudioDecoder::bufferReady() | 
| 39 | { | 
| 40 | if (!q->thread()->isCurrentThread()) | 
| 41 |         QMetaObject::invokeMethod(obj: q, member: "bufferReady", c: Qt::QueuedConnection);  | 
| 42 | else | 
| 43 | emit q->bufferReady(); | 
| 44 | } | 
| 45 | |
| 46 | void QPlatformAudioDecoder::sourceChanged() | 
| 47 | { | 
| 48 | emit q->sourceChanged(); | 
| 49 | } | 
| 50 | |
| 51 | void QPlatformAudioDecoder::formatChanged(const QAudioFormat &format) | 
| 52 | { | 
| 53 | emit q->formatChanged(format); | 
| 54 | } | 
| 55 | |
| 56 | void QPlatformAudioDecoder::finished() | 
| 57 | { | 
| 58 | durationChanged(duration: -1); | 
| 59 | setIsDecoding(false); | 
| 60 | emit q->finished(); | 
| 61 | } | 
| 62 | |
| 63 | void QPlatformAudioDecoder::positionChanged(qint64 position) | 
| 64 | { | 
| 65 | if (m_position == position) | 
| 66 | return; | 
| 67 | m_position = position; | 
| 68 | emit q->positionChanged(position); | 
| 69 | } | 
| 70 | |
| 71 | void QPlatformAudioDecoder::durationChanged(qint64 duration) | 
| 72 | { | 
| 73 | if (m_duration == duration) | 
| 74 | return; | 
| 75 | m_duration = duration; | 
| 76 | emit q->durationChanged(duration); | 
| 77 | } | 
| 78 | |
| 79 | QT_END_NAMESPACE | 
| 80 | |
| 81 | #include "moc_qplatformaudiodecoder_p.cpp" | 
| 82 | 
