OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 _playIsInitialized(false), | 47 _playIsInitialized(false), |
48 _startRec(false), | 48 _startRec(false), |
49 _stopRec(false), | 49 _stopRec(false), |
50 _startPlay(false), | 50 _startPlay(false), |
51 _stopPlay(false), | 51 _stopPlay(false), |
52 _AGC(false), | 52 _AGC(false), |
53 update_speaker_volume_at_startup_(false), | 53 update_speaker_volume_at_startup_(false), |
54 _sndCardPlayDelay(0), | 54 _sndCardPlayDelay(0), |
55 _sndCardRecDelay(0), | 55 _sndCardRecDelay(0), |
56 _writeErrors(0), | 56 _writeErrors(0), |
57 _playWarning(0), | |
58 _playError(0), | |
59 _recWarning(0), | |
60 _recError(0), | |
61 _deviceIndex(-1), | 57 _deviceIndex(-1), |
62 _numPlayDevices(0), | 58 _numPlayDevices(0), |
63 _numRecDevices(0), | 59 _numRecDevices(0), |
64 _playDeviceName(NULL), | 60 _playDeviceName(NULL), |
65 _recDeviceName(NULL), | 61 _recDeviceName(NULL), |
66 _playDisplayDeviceName(NULL), | 62 _playDisplayDeviceName(NULL), |
67 _recDisplayDeviceName(NULL), | 63 _recDisplayDeviceName(NULL), |
68 _playBuffer(NULL), | 64 _playBuffer(NULL), |
69 _playbackBufferSize(0), | 65 _playbackBufferSize(0), |
70 _playbackBufferUnused(0), | 66 _playbackBufferUnused(0), |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 149 |
154 // Initialize PulseAudio | 150 // Initialize PulseAudio |
155 if (InitPulseAudio() < 0) { | 151 if (InitPulseAudio() < 0) { |
156 LOG(LS_ERROR) << "failed to initialize PulseAudio"; | 152 LOG(LS_ERROR) << "failed to initialize PulseAudio"; |
157 if (TerminatePulseAudio() < 0) { | 153 if (TerminatePulseAudio() < 0) { |
158 LOG(LS_ERROR) << "failed to terminate PulseAudio"; | 154 LOG(LS_ERROR) << "failed to terminate PulseAudio"; |
159 } | 155 } |
160 return InitStatus::OTHER_ERROR; | 156 return InitStatus::OTHER_ERROR; |
161 } | 157 } |
162 | 158 |
163 _playWarning = 0; | |
164 _playError = 0; | |
165 _recWarning = 0; | |
166 _recError = 0; | |
167 | |
168 // Get X display handle for typing detection | 159 // Get X display handle for typing detection |
169 _XDisplay = XOpenDisplay(NULL); | 160 _XDisplay = XOpenDisplay(NULL); |
170 if (!_XDisplay) { | 161 if (!_XDisplay) { |
171 LOG(LS_WARNING) | 162 LOG(LS_WARNING) |
172 << "failed to open X display, typing detection will not work"; | 163 << "failed to open X display, typing detection will not work"; |
173 } | 164 } |
174 | 165 |
175 // RECORDING | 166 // RECORDING |
176 _ptrThreadRec.reset(new rtc::PlatformThread( | 167 _ptrThreadRec.reset(new rtc::PlatformThread( |
177 RecThreadFunc, this, "webrtc_audio_module_rec_thread")); | 168 RecThreadFunc, this, "webrtc_audio_module_rec_thread")); |
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1276 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1286 delayMS = (uint16_t)_sndCardRecDelay; | 1277 delayMS = (uint16_t)_sndCardRecDelay; |
1287 return 0; | 1278 return 0; |
1288 } | 1279 } |
1289 | 1280 |
1290 bool AudioDeviceLinuxPulse::Playing() const { | 1281 bool AudioDeviceLinuxPulse::Playing() const { |
1291 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 1282 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1292 return (_playing); | 1283 return (_playing); |
1293 } | 1284 } |
1294 | 1285 |
1295 bool AudioDeviceLinuxPulse::PlayoutWarning() const { | |
1296 rtc::CritScope lock(&_critSect); | |
1297 return (_playWarning > 0); | |
1298 } | |
1299 | |
1300 bool AudioDeviceLinuxPulse::PlayoutError() const { | |
1301 rtc::CritScope lock(&_critSect); | |
1302 return (_playError > 0); | |
1303 } | |
1304 | |
1305 bool AudioDeviceLinuxPulse::RecordingWarning() const { | |
1306 rtc::CritScope lock(&_critSect); | |
1307 return (_recWarning > 0); | |
1308 } | |
1309 | |
1310 bool AudioDeviceLinuxPulse::RecordingError() const { | |
1311 rtc::CritScope lock(&_critSect); | |
1312 return (_recError > 0); | |
1313 } | |
1314 | |
1315 void AudioDeviceLinuxPulse::ClearPlayoutWarning() { | |
1316 rtc::CritScope lock(&_critSect); | |
1317 _playWarning = 0; | |
1318 } | |
1319 | |
1320 void AudioDeviceLinuxPulse::ClearPlayoutError() { | |
1321 rtc::CritScope lock(&_critSect); | |
1322 _playError = 0; | |
1323 } | |
1324 | |
1325 void AudioDeviceLinuxPulse::ClearRecordingWarning() { | |
1326 rtc::CritScope lock(&_critSect); | |
1327 _recWarning = 0; | |
1328 } | |
1329 | |
1330 void AudioDeviceLinuxPulse::ClearRecordingError() { | |
1331 rtc::CritScope lock(&_critSect); | |
1332 _recError = 0; | |
1333 } | |
1334 | |
1335 // ============================================================================ | 1286 // ============================================================================ |
1336 // Private Methods | 1287 // Private Methods |
1337 // ============================================================================ | 1288 // ============================================================================ |
1338 | 1289 |
1339 void AudioDeviceLinuxPulse::PaContextStateCallback(pa_context* c, void* pThis) { | 1290 void AudioDeviceLinuxPulse::PaContextStateCallback(pa_context* c, void* pThis) { |
1340 static_cast<AudioDeviceLinuxPulse*>(pThis)->PaContextStateCallbackHandler(c); | 1291 static_cast<AudioDeviceLinuxPulse*>(pThis)->PaContextStateCallbackHandler(c); |
1341 } | 1292 } |
1342 | 1293 |
1343 // ---------------------------------------------------------------------------- | 1294 // ---------------------------------------------------------------------------- |
1344 // PaSinkInfoCallback | 1295 // PaSinkInfoCallback |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2184 if (_tempBufferSpace < write) { | 2135 if (_tempBufferSpace < write) { |
2185 write = _tempBufferSpace; | 2136 write = _tempBufferSpace; |
2186 } | 2137 } |
2187 | 2138 |
2188 PaLock(); | 2139 PaLock(); |
2189 if (LATE(pa_stream_write)( | 2140 if (LATE(pa_stream_write)( |
2190 _playStream, (void*)&_playBuffer[_playbackBufferUnused], write, | 2141 _playStream, (void*)&_playBuffer[_playbackBufferUnused], write, |
2191 NULL, (int64_t)0, PA_SEEK_RELATIVE) != PA_OK) { | 2142 NULL, (int64_t)0, PA_SEEK_RELATIVE) != PA_OK) { |
2192 _writeErrors++; | 2143 _writeErrors++; |
2193 if (_writeErrors > 10) { | 2144 if (_writeErrors > 10) { |
2194 if (_playError == 1) { | 2145 LOG(LS_ERROR) << "Playout error: _writeErrors=" |
2195 LOG(LS_WARNING) << "pending playout error exists"; | |
2196 } | |
2197 // Triggers callback from module process thread. | |
2198 _playError = 1; | |
2199 LOG(LS_ERROR) << "kPlayoutError message posted: _writeErrors=" | |
2200 << _writeErrors | 2146 << _writeErrors |
2201 << ", error=" << LATE(pa_context_errno)(_paContext); | 2147 << ", error=" << LATE(pa_context_errno)(_paContext); |
2202 _writeErrors = 0; | 2148 _writeErrors = 0; |
2203 } | 2149 } |
2204 } | 2150 } |
2205 PaUnLock(); | 2151 PaUnLock(); |
2206 | 2152 |
2207 _playbackBufferUnused += write; | 2153 _playbackBufferUnused += write; |
2208 _tempBufferSpace -= write; | 2154 _tempBufferSpace -= write; |
2209 } | 2155 } |
(...skipping 23 matching lines...) Expand all Loading... |
2233 if (_tempBufferSpace < write) { | 2179 if (_tempBufferSpace < write) { |
2234 write = _tempBufferSpace; | 2180 write = _tempBufferSpace; |
2235 } | 2181 } |
2236 | 2182 |
2237 LOG(LS_VERBOSE) << "will write"; | 2183 LOG(LS_VERBOSE) << "will write"; |
2238 PaLock(); | 2184 PaLock(); |
2239 if (LATE(pa_stream_write)(_playStream, (void*)&_playBuffer[0], write, | 2185 if (LATE(pa_stream_write)(_playStream, (void*)&_playBuffer[0], write, |
2240 NULL, (int64_t)0, PA_SEEK_RELATIVE) != PA_OK) { | 2186 NULL, (int64_t)0, PA_SEEK_RELATIVE) != PA_OK) { |
2241 _writeErrors++; | 2187 _writeErrors++; |
2242 if (_writeErrors > 10) { | 2188 if (_writeErrors > 10) { |
2243 if (_playError == 1) { | 2189 LOG(LS_ERROR) << "Playout error: _writeErrors=" |
2244 LOG(LS_WARNING) << "pending playout error exists"; | |
2245 } | |
2246 // Triggers callback from module process thread. | |
2247 _playError = 1; | |
2248 LOG(LS_ERROR) << "kPlayoutError message posted: _writeErrors=" | |
2249 << _writeErrors | 2190 << _writeErrors |
2250 << ", error=" << LATE(pa_context_errno)(_paContext); | 2191 << ", error=" << LATE(pa_context_errno)(_paContext); |
2251 _writeErrors = 0; | 2192 _writeErrors = 0; |
2252 } | 2193 } |
2253 } | 2194 } |
2254 PaUnLock(); | 2195 PaUnLock(); |
2255 | 2196 |
2256 _playbackBufferUnused = write; | 2197 _playbackBufferUnused = write; |
2257 } | 2198 } |
2258 | 2199 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2351 if (LATE(pa_stream_readable_size)(_recStream) <= 0) { | 2292 if (LATE(pa_stream_readable_size)(_recStream) <= 0) { |
2352 // Then that was all the data | 2293 // Then that was all the data |
2353 break; | 2294 break; |
2354 } | 2295 } |
2355 | 2296 |
2356 // Else more data. | 2297 // Else more data. |
2357 const void* sampleData; | 2298 const void* sampleData; |
2358 size_t sampleDataSize; | 2299 size_t sampleDataSize; |
2359 | 2300 |
2360 if (LATE(pa_stream_peek)(_recStream, &sampleData, &sampleDataSize) != 0) { | 2301 if (LATE(pa_stream_peek)(_recStream, &sampleData, &sampleDataSize) != 0) { |
2361 _recError = 1; // triggers callback from module process thread | 2302 LOG(LS_ERROR) << "RECORD_ERROR, error = " |
2362 LOG(LS_ERROR) << "RECORD_ERROR message posted, error = " | |
2363 << LATE(pa_context_errno)(_paContext); | 2303 << LATE(pa_context_errno)(_paContext); |
2364 break; | 2304 break; |
2365 } | 2305 } |
2366 | 2306 |
2367 _sndCardRecDelay = (uint32_t)(LatencyUsecs(_recStream) / 1000); | 2307 _sndCardRecDelay = (uint32_t)(LatencyUsecs(_recStream) / 1000); |
2368 | 2308 |
2369 // Drop lock for sigslot dispatch, which could take a while. | 2309 // Drop lock for sigslot dispatch, which could take a while. |
2370 PaUnLock(); | 2310 PaUnLock(); |
2371 // Read data and provide it to VoiceEngine | 2311 // Read data and provide it to VoiceEngine |
2372 if (ReadRecordedData(sampleData, sampleDataSize) == -1) { | 2312 if (ReadRecordedData(sampleData, sampleDataSize) == -1) { |
(...skipping 25 matching lines...) Expand all Loading... |
2398 | 2338 |
2399 // A bit change in keymap means a key is pressed | 2339 // A bit change in keymap means a key is pressed |
2400 for (i = 0; i < sizeof(szKey); i++) | 2340 for (i = 0; i < sizeof(szKey); i++) |
2401 state |= (szKey[i] ^ _oldKeyState[i]) & szKey[i]; | 2341 state |= (szKey[i] ^ _oldKeyState[i]) & szKey[i]; |
2402 | 2342 |
2403 // Save old state | 2343 // Save old state |
2404 memcpy((char*)_oldKeyState, (char*)szKey, sizeof(_oldKeyState)); | 2344 memcpy((char*)_oldKeyState, (char*)szKey, sizeof(_oldKeyState)); |
2405 return (state != 0); | 2345 return (state != 0); |
2406 } | 2346 } |
2407 } // namespace webrtc | 2347 } // namespace webrtc |
OLD | NEW |