81 , ActiveState |
82 , ActiveState |
82 , IdleState |
83 , IdleState |
83 , SuspendedState |
84 , SuspendedState |
84 }; |
85 }; |
85 |
86 |
86 /* |
87 /** |
87 * Helper class for querying DevSound codec / format support |
88 * Wrapper around DevSound instance |
88 */ |
89 */ |
89 class DevSoundCapabilities { |
90 class DevSoundWrapper |
|
91 : public QObject |
|
92 , public MDevSoundObserver |
|
93 { |
|
94 Q_OBJECT |
|
95 |
90 public: |
96 public: |
91 DevSoundCapabilities(CMMFDevSound &devsound, QAudio::Mode mode); |
97 DevSoundWrapper(QAudio::Mode mode, QObject *parent = 0); |
92 ~DevSoundCapabilities(); |
98 ~DevSoundWrapper(); |
93 |
99 |
94 const RArray<TFourCC>& fourCC() const { return m_fourCC; } |
100 public: |
95 const TMMFCapabilities& caps() const { return m_caps; } |
101 // List of supported codecs; can be called once object is constructed |
|
102 const QList<QString>& supportedCodecs() const; |
|
103 |
|
104 // Asynchronous initialization function; emits devsoundInitializeComplete |
|
105 void initialize(const QString& codec); |
|
106 |
|
107 // Capabilities, for selected codec. Can be called once initialize has returned |
|
108 // successfully. |
|
109 const QList<int>& supportedFrequencies() const; |
|
110 const QList<int>& supportedChannels() const; |
|
111 const QList<int>& supportedSampleSizes() const; |
|
112 const QList<QAudioFormat::Endian>& supportedByteOrders() const; |
|
113 const QList<QAudioFormat::SampleType>& supportedSampleTypes() const; |
|
114 |
|
115 bool isFormatSupported(const QAudioFormat &format) const; |
|
116 |
|
117 int samplesProcessed() const; |
|
118 bool setFormat(const QAudioFormat &format); |
|
119 bool start(); |
|
120 void pause(); |
|
121 void stop(); |
|
122 void bufferProcessed(); |
|
123 |
|
124 public: |
|
125 // MDevSoundObserver |
|
126 void InitializeComplete(TInt aError); |
|
127 void ToneFinished(TInt aError); |
|
128 void BufferToBeFilled(CMMFBuffer *aBuffer); |
|
129 void PlayError(TInt aError); |
|
130 void BufferToBeEmptied(CMMFBuffer *aBuffer); |
|
131 void RecordError(TInt aError); |
|
132 void ConvertError(TInt aError); |
|
133 void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg); |
|
134 |
|
135 signals: |
|
136 void initializeComplete(int error); |
|
137 void bufferToBeProcessed(CMMFBuffer *buffer); |
|
138 void processingError(int error); |
96 |
139 |
97 private: |
140 private: |
98 void constructL(CMMFDevSound &devsound, QAudio::Mode mode); |
141 void getSupportedCodecs(); |
|
142 void populateCapabilities(); |
99 |
143 |
100 private: |
144 private: |
101 RArray<TFourCC> m_fourCC; |
145 const QAudio::Mode m_mode; |
102 TMMFCapabilities m_caps; |
146 TMMFState m_nativeMode; |
|
147 |
|
148 enum State { |
|
149 StateIdle, |
|
150 StateInitializing, |
|
151 StateInitialized |
|
152 } m_state; |
|
153 |
|
154 CMMFDevSound* m_devsound; |
|
155 TFourCC m_fourcc; |
|
156 |
|
157 QList<QString> m_supportedCodecs; |
|
158 QList<int> m_supportedFrequencies; |
|
159 QList<int> m_supportedChannels; |
|
160 QList<int> m_supportedSampleSizes; |
|
161 QList<QAudioFormat::Endian> m_supportedByteOrders; |
|
162 QList<QAudioFormat::SampleType> m_supportedSampleTypes; |
|
163 |
103 }; |
164 }; |
|
165 |
104 |
166 |
105 namespace Utils { |
167 namespace Utils { |
106 |
168 |
107 /** |
169 /** |
108 * Convert native audio capabilities to QAudio lists. |
|
109 */ |
|
110 void capabilitiesNativeToQt(const DevSoundCapabilities &caps, |
|
111 QList<int> &frequencies, |
|
112 QList<int> &channels, |
|
113 QList<int> &sampleSizes, |
|
114 QList<QAudioFormat::Endian> &byteOrders, |
|
115 QList<QAudioFormat::SampleType> &sampleTypes); |
|
116 |
|
117 /** |
|
118 * Check whether format is supported. |
|
119 */ |
|
120 bool isFormatSupported(const QAudioFormat &format, |
|
121 const DevSoundCapabilities &caps); |
|
122 |
|
123 /** |
|
124 * Convert QAudioFormat to native format types. |
|
125 * |
|
126 * Note that, despite the name, DevSound uses TMMFCapabilities to specify |
|
127 * single formats as well as capabilities. |
|
128 * |
|
129 * Note that this function does not modify outputFormat.iBufferSize. |
|
130 */ |
|
131 bool formatQtToNative(const QAudioFormat &inputFormat, |
|
132 TUint32 &outputFourCC, |
|
133 TMMFCapabilities &outputFormat); |
|
134 |
|
135 /** |
|
136 * Convert internal states to QAudio states. |
170 * Convert internal states to QAudio states. |
137 */ |
171 */ |
138 QAudio::State stateNativeToQt(State nativeState, |
172 QAudio::State stateNativeToQt(State nativeState); |
139 QAudio::State initializingState); |
|
140 |
173 |
141 /** |
174 /** |
142 * Convert data length to number of samples. |
175 * Convert data length to number of samples. |
143 */ |
176 */ |
144 qint64 bytesToSamples(const QAudioFormat &format, qint64 length); |
177 qint64 bytesToSamples(const QAudioFormat &format, qint64 length); |