Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsamplecache_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 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#ifndef QSAMPLECACHE_P_H
5#define QSAMPLECACHE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qobject.h>
19#include <QtCore/qthread.h>
20#include <QtCore/qurl.h>
21#include <QtCore/qmutex.h>
22#include <QtCore/qmap.h>
23#include <QtCore/qset.h>
24#include <qaudioformat.h>
25#include <qnetworkreply.h>
26#include <private/qglobal_p.h>
27
29
30class QIODevice;
32class QSampleCache;
33class QWaveDecoder;
34
35// Lives in application thread
36class Q_MULTIMEDIA_EXPORT QSample : public QObject
37{
39public:
40 friend class QSampleCache;
48
49 State state() const;
50 // These are not (currently) locked because they are only meant to be called after these
51 // variables are updated to their final states
52 const QByteArray& data() const { Q_ASSERT(state() == Ready); return m_soundData; }
53 const QAudioFormat& format() const { Q_ASSERT(state() == Ready); return m_audioFormat; }
54 void release();
55
57 void error();
58 void ready();
59
60protected:
61 QSample(const QUrl& url, QSampleCache *parent);
62
63private Q_SLOTS:
64 void load();
65 void loadingError(QNetworkReply::NetworkError);
66 void decoderError();
67 void readSample();
68 void decoderReady();
69
70private:
71 void onReady();
72 void cleanup();
73 void addRef();
74 void loadIfNecessary();
75 QSample();
76 ~QSample();
77
78 mutable QMutex m_mutex;
79 QSampleCache *m_parent;
80 QByteArray m_soundData;
81 QAudioFormat m_audioFormat;
82 QIODevice *m_stream;
83 QWaveDecoder *m_waveDecoder;
84 QUrl m_url;
85 qint64 m_sampleReadLength;
86 State m_state;
87 int m_ref;
88};
89
90class Q_MULTIMEDIA_EXPORT QSampleCache : public QObject
91{
93public:
94 friend class QSample;
95
96 QSampleCache(QObject *parent = nullptr);
98
99 QSample* requestSample(const QUrl& url);
100 void setCapacity(qint64 capacity);
101
102 bool isLoading() const;
103 bool isCached(const QUrl& url) const;
104
105private:
106 QMap<QUrl, QSample*> m_samples;
107 QSet<QSample*> m_staleSamples;
108 QNetworkAccessManager *m_networkAccessManager;
109 mutable QRecursiveMutex m_mutex;
110 qint64 m_capacity;
111 qint64 m_usage;
112 QThread m_loadingThread;
113
114 QNetworkAccessManager& networkAccessManager();
115 void refresh(qint64 usageChange);
116 bool notifyUnreferencedSample(QSample* sample);
117 void removeUnreferencedSample(QSample* sample);
118 void unloadSample(QSample* sample);
119
120 void loadingRelease();
121 int m_loadingRefCount;
122 QMutex m_loadingMutex;
123};
124
126
127#endif // QSAMPLECACHE_P_H
The QAudioFormat class stores audio stream parameter information.
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore \reentrant
Definition qiodevice.h:34
\inmodule QtCore
Definition qmutex.h:281
The QNetworkAccessManager class allows the application to send network requests and receive replies.
NetworkError
Indicates all possible error conditions found during the processing of the request.
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore
Definition qmutex.h:309
QSampleCache(QObject *parent=nullptr)
const QByteArray & data() const
void ready()
void error()
const QAudioFormat & format() const
\inmodule QtCore
Definition qurl.h:94
p1 load("image.bmp")
else opt state
[0]
Combined button and popup list for selecting options.
NSUInteger capacity
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
long long qint64
Definition qtypes.h:60
QUrl url("example.com")
[constructor-url-reference]
sem release()