1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtMultimedia module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include <QtCore/QCoreApplication>
|
---|
43 | #include "qaudiodeviceinfo_symbian_p.h"
|
---|
44 | #include "qaudio_symbian_p.h"
|
---|
45 |
|
---|
46 | QT_BEGIN_NAMESPACE
|
---|
47 |
|
---|
48 | QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray device,
|
---|
49 | QAudio::Mode mode)
|
---|
50 | : m_deviceName(QLatin1String(device))
|
---|
51 | , m_mode(mode)
|
---|
52 | , m_updated(false)
|
---|
53 | {
|
---|
54 |
|
---|
55 | }
|
---|
56 |
|
---|
57 | QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal()
|
---|
58 | {
|
---|
59 |
|
---|
60 | }
|
---|
61 |
|
---|
62 | QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const
|
---|
63 | {
|
---|
64 | QAudioFormat format;
|
---|
65 | switch (m_mode) {
|
---|
66 | case QAudio::AudioOutput:
|
---|
67 | format.setFrequency(44100);
|
---|
68 | format.setChannels(2);
|
---|
69 | format.setSampleSize(16);
|
---|
70 | format.setByteOrder(QAudioFormat::LittleEndian);
|
---|
71 | format.setSampleType(QAudioFormat::SignedInt);
|
---|
72 | format.setCodec(QLatin1String("audio/pcm"));
|
---|
73 | break;
|
---|
74 |
|
---|
75 | case QAudio::AudioInput:
|
---|
76 | format.setFrequency(8000);
|
---|
77 | format.setChannels(1);
|
---|
78 | format.setSampleSize(16);
|
---|
79 | format.setByteOrder(QAudioFormat::LittleEndian);
|
---|
80 | format.setSampleType(QAudioFormat::SignedInt);
|
---|
81 | format.setCodec(QLatin1String("audio/pcm"));
|
---|
82 | break;
|
---|
83 |
|
---|
84 | default:
|
---|
85 | Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid mode");
|
---|
86 | }
|
---|
87 |
|
---|
88 | if (!isFormatSupported(format)) {
|
---|
89 | format = QAudioFormat();
|
---|
90 | format.setCodec(QLatin1String("audio/pcm"));
|
---|
91 | if (m_capabilities.contains(format.codec())) {
|
---|
92 | const Capabilities &codecCaps = m_capabilities[format.codec()];
|
---|
93 | if (codecCaps.m_frequencies.size())
|
---|
94 | format.setFrequency(codecCaps.m_frequencies[0]);
|
---|
95 | if (codecCaps.m_channels.size())
|
---|
96 | format.setChannels(codecCaps.m_channels[0]);
|
---|
97 | if (codecCaps.m_sampleSizes.size())
|
---|
98 | format.setSampleSize(codecCaps.m_sampleSizes[0]);
|
---|
99 | if (codecCaps.m_byteOrders.size())
|
---|
100 | format.setByteOrder(codecCaps.m_byteOrders[0]);
|
---|
101 | if (codecCaps.m_sampleTypes.size())
|
---|
102 | format.setSampleType(codecCaps.m_sampleTypes[0]);
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | return format;
|
---|
107 | }
|
---|
108 |
|
---|
109 | bool QAudioDeviceInfoInternal::isFormatSupported(
|
---|
110 | const QAudioFormat &format) const
|
---|
111 | {
|
---|
112 | getSupportedFormats();
|
---|
113 | bool supported = false;
|
---|
114 | if (m_capabilities.contains(format.codec())) {
|
---|
115 | const Capabilities &codecCaps = m_capabilities[format.codec()];
|
---|
116 | supported = codecCaps.m_frequencies.contains(format.frequency())
|
---|
117 | && codecCaps.m_channels.contains(format.channels())
|
---|
118 | && codecCaps.m_sampleSizes.contains(format.sampleSize())
|
---|
119 | && codecCaps.m_byteOrders.contains(format.byteOrder())
|
---|
120 | && codecCaps.m_sampleTypes.contains(format.sampleType());
|
---|
121 | }
|
---|
122 | return supported;
|
---|
123 | }
|
---|
124 |
|
---|
125 | QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat &format) const
|
---|
126 | {
|
---|
127 | if (isFormatSupported(format))
|
---|
128 | return format;
|
---|
129 | else
|
---|
130 | return preferredFormat();
|
---|
131 | }
|
---|
132 |
|
---|
133 | QString QAudioDeviceInfoInternal::deviceName() const
|
---|
134 | {
|
---|
135 | return m_deviceName;
|
---|
136 | }
|
---|
137 |
|
---|
138 | QStringList QAudioDeviceInfoInternal::codecList()
|
---|
139 | {
|
---|
140 | getSupportedFormats();
|
---|
141 | return m_capabilities.keys();
|
---|
142 | }
|
---|
143 |
|
---|
144 | QList<int> QAudioDeviceInfoInternal::frequencyList()
|
---|
145 | {
|
---|
146 | getSupportedFormats();
|
---|
147 | return m_unionCapabilities.m_frequencies;
|
---|
148 | }
|
---|
149 |
|
---|
150 | QList<int> QAudioDeviceInfoInternal::channelsList()
|
---|
151 | {
|
---|
152 | getSupportedFormats();
|
---|
153 | return m_unionCapabilities.m_channels;
|
---|
154 | }
|
---|
155 |
|
---|
156 | QList<int> QAudioDeviceInfoInternal::sampleSizeList()
|
---|
157 | {
|
---|
158 | getSupportedFormats();
|
---|
159 | return m_unionCapabilities.m_sampleSizes;
|
---|
160 | }
|
---|
161 |
|
---|
162 | QList<QAudioFormat::Endian> QAudioDeviceInfoInternal::byteOrderList()
|
---|
163 | {
|
---|
164 | getSupportedFormats();
|
---|
165 | return m_unionCapabilities.m_byteOrders;
|
---|
166 | }
|
---|
167 |
|
---|
168 | QList<QAudioFormat::SampleType> QAudioDeviceInfoInternal::sampleTypeList()
|
---|
169 | {
|
---|
170 | getSupportedFormats();
|
---|
171 | return m_unionCapabilities.m_sampleTypes;
|
---|
172 | }
|
---|
173 |
|
---|
174 | QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
|
---|
175 | {
|
---|
176 | return QByteArray("default");
|
---|
177 | }
|
---|
178 |
|
---|
179 | QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
|
---|
180 | {
|
---|
181 | return QByteArray("default");
|
---|
182 | }
|
---|
183 |
|
---|
184 | QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode)
|
---|
185 | {
|
---|
186 | QList<QByteArray> result;
|
---|
187 | result += QByteArray("default");
|
---|
188 | return result;
|
---|
189 | }
|
---|
190 |
|
---|
191 | void QAudioDeviceInfoInternal::devsoundInitializeComplete(int err)
|
---|
192 | {
|
---|
193 | m_intializationResult = err;
|
---|
194 | m_initializing = false;
|
---|
195 | }
|
---|
196 |
|
---|
197 | // Helper function
|
---|
198 | template<typename T>
|
---|
199 | void appendUnique(QList<T> &left, const QList<T> &right)
|
---|
200 | {
|
---|
201 | foreach (const T &value, right)
|
---|
202 | if (!left.contains(value))
|
---|
203 | left += value;
|
---|
204 | }
|
---|
205 |
|
---|
206 | void QAudioDeviceInfoInternal::getSupportedFormats() const
|
---|
207 | {
|
---|
208 | if (!m_updated) {
|
---|
209 | QScopedPointer<SymbianAudio::DevSoundWrapper> devsound(new SymbianAudio::DevSoundWrapper(m_mode));
|
---|
210 | connect(devsound.data(), SIGNAL(initializeComplete(int)),
|
---|
211 | this, SLOT(devsoundInitializeComplete(int)));
|
---|
212 |
|
---|
213 | foreach (const QString& codec, devsound->supportedCodecs()) {
|
---|
214 | m_initializing = true;
|
---|
215 | devsound->initialize(codec);
|
---|
216 | while (m_initializing)
|
---|
217 | QCoreApplication::instance()->processEvents(QEventLoop::WaitForMoreEvents);
|
---|
218 | if (KErrNone == m_intializationResult) {
|
---|
219 | m_capabilities[codec].m_frequencies = devsound->supportedFrequencies();
|
---|
220 | appendUnique(m_unionCapabilities.m_frequencies, devsound->supportedFrequencies());
|
---|
221 |
|
---|
222 | m_capabilities[codec].m_channels = devsound->supportedChannels();
|
---|
223 | appendUnique(m_unionCapabilities.m_channels, devsound->supportedChannels());
|
---|
224 |
|
---|
225 | m_capabilities[codec].m_sampleSizes = devsound->supportedSampleSizes();
|
---|
226 | appendUnique(m_unionCapabilities.m_sampleSizes, devsound->supportedSampleSizes());
|
---|
227 |
|
---|
228 | m_capabilities[codec].m_byteOrders = devsound->supportedByteOrders();
|
---|
229 | appendUnique(m_unionCapabilities.m_byteOrders, devsound->supportedByteOrders());
|
---|
230 |
|
---|
231 | m_capabilities[codec].m_sampleTypes = devsound->supportedSampleTypes();
|
---|
232 | appendUnique(m_unionCapabilities.m_sampleTypes, devsound->supportedSampleTypes());
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | m_updated = true;
|
---|
237 | }
|
---|
238 | }
|
---|
239 |
|
---|
240 | QT_END_NAMESPACE
|
---|