|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "audioencodercontrol.h" |
|
43 #include "audiocapturesession.h" |
|
44 |
|
45 #include <qaudioformat.h> |
|
46 |
|
47 #include <QtCore/qdebug.h> |
|
48 |
|
49 AudioEncoderControl::AudioEncoderControl(QObject *parent) |
|
50 :QAudioEncoderControl(parent) |
|
51 { |
|
52 m_session = qobject_cast<AudioCaptureSession*>(parent); |
|
53 |
|
54 QT_PREPEND_NAMESPACE(QAudioFormat) fmt; |
|
55 fmt.setSampleSize(8); |
|
56 fmt.setChannels(1); |
|
57 fmt.setFrequency(8000); |
|
58 fmt.setSampleType(QT_PREPEND_NAMESPACE(QAudioFormat)::SignedInt); |
|
59 fmt.setCodec("audio/pcm"); |
|
60 fmt.setByteOrder(QAudioFormat::LittleEndian); |
|
61 m_session->setFormat(fmt); |
|
62 |
|
63 m_settings.setEncodingMode(QtMultimediaKit::ConstantQualityEncoding); |
|
64 m_settings.setCodec("audio/pcm"); |
|
65 m_settings.setBitRate(8000); |
|
66 m_settings.setChannelCount(1); |
|
67 m_settings.setSampleRate(8000); |
|
68 m_settings.setQuality(QtMultimediaKit::LowQuality); |
|
69 } |
|
70 |
|
71 AudioEncoderControl::~AudioEncoderControl() |
|
72 { |
|
73 } |
|
74 |
|
75 QStringList AudioEncoderControl::supportedAudioCodecs() const |
|
76 { |
|
77 QStringList list; |
|
78 if (m_session->supportedContainers().size() > 0) |
|
79 list.append("audio/pcm"); |
|
80 |
|
81 return list; |
|
82 } |
|
83 |
|
84 QString AudioEncoderControl::codecDescription(const QString &codecName) const |
|
85 { |
|
86 if (codecName.contains(QLatin1String("audio/pcm"))) |
|
87 return QString(tr("PCM audio data")); |
|
88 |
|
89 return QString(); |
|
90 } |
|
91 |
|
92 QStringList AudioEncoderControl::supportedEncodingOptions(const QString &codec) const |
|
93 { |
|
94 Q_UNUSED(codec) |
|
95 |
|
96 QStringList list; |
|
97 return list; |
|
98 } |
|
99 |
|
100 QVariant AudioEncoderControl::encodingOption(const QString &codec, const QString &name) const |
|
101 { |
|
102 Q_UNUSED(codec) |
|
103 Q_UNUSED(name) |
|
104 |
|
105 return QVariant(); |
|
106 } |
|
107 |
|
108 void AudioEncoderControl::setEncodingOption( |
|
109 const QString &codec, const QString &name, const QVariant &value) |
|
110 { |
|
111 Q_UNUSED(value) |
|
112 Q_UNUSED(codec) |
|
113 Q_UNUSED(name) |
|
114 } |
|
115 |
|
116 QList<int> AudioEncoderControl::supportedSampleRates(const QAudioEncoderSettings &, bool *continuous) const |
|
117 { |
|
118 if (continuous) |
|
119 *continuous = false; |
|
120 |
|
121 return m_session->deviceInfo()->supportedFrequencies(); |
|
122 } |
|
123 |
|
124 QAudioEncoderSettings AudioEncoderControl::audioSettings() const |
|
125 { |
|
126 return m_settings; |
|
127 } |
|
128 |
|
129 void AudioEncoderControl::setAudioSettings(const QAudioEncoderSettings &settings) |
|
130 { |
|
131 QAudioFormat fmt = m_session->format(); |
|
132 |
|
133 if (settings.encodingMode() == QtMultimediaKit::ConstantQualityEncoding) { |
|
134 if (settings.quality() == QtMultimediaKit::LowQuality) { |
|
135 fmt.setSampleSize(8); |
|
136 fmt.setChannels(1); |
|
137 fmt.setFrequency(8000); |
|
138 fmt.setSampleType(QAudioFormat::UnSignedInt); |
|
139 |
|
140 } else if (settings.quality() == QtMultimediaKit::NormalQuality) { |
|
141 fmt.setSampleSize(16); |
|
142 fmt.setChannels(1); |
|
143 fmt.setFrequency(22050); |
|
144 fmt.setSampleType(QAudioFormat::SignedInt); |
|
145 |
|
146 } else { |
|
147 fmt.setSampleSize(16); |
|
148 fmt.setChannels(1); |
|
149 fmt.setFrequency(44100); |
|
150 fmt.setSampleType(QAudioFormat::SignedInt); |
|
151 } |
|
152 |
|
153 } else { |
|
154 fmt.setChannels(settings.channelCount()); |
|
155 fmt.setFrequency(settings.sampleRate()); |
|
156 if (settings.sampleRate() == 8000 && settings.bitRate() == 8000) { |
|
157 fmt.setSampleType(QAudioFormat::UnSignedInt); |
|
158 fmt.setSampleSize(8); |
|
159 } else { |
|
160 fmt.setSampleSize(16); |
|
161 fmt.setSampleType(QAudioFormat::SignedInt); |
|
162 } |
|
163 } |
|
164 fmt.setCodec("audio/pcm"); |
|
165 |
|
166 m_session->setFormat(fmt); |
|
167 m_settings = settings; |
|
168 } |