OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 #include "webrtc/base/logging.h" |
10 #include "webrtc/base/platform_thread.h" | 11 #include "webrtc/base/platform_thread.h" |
11 #include "webrtc/modules/audio_device/dummy/file_audio_device.h" | 12 #include "webrtc/modules/audio_device/dummy/file_audio_device.h" |
12 #include "webrtc/system_wrappers/include/sleep.h" | 13 #include "webrtc/system_wrappers/include/sleep.h" |
13 | 14 |
14 namespace webrtc { | 15 namespace webrtc { |
15 | 16 |
16 const int kRecordingFixedSampleRate = 48000; | 17 const int kRecordingFixedSampleRate = 48000; |
17 const size_t kRecordingNumChannels = 2; | 18 const size_t kRecordingNumChannels = 2; |
18 const int kPlayoutFixedSampleRate = 48000; | 19 const int kPlayoutFixedSampleRate = 48000; |
19 const size_t kPlayoutNumChannels = 2; | 20 const size_t kPlayoutNumChannels = 2; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 _playoutBuffer = new int8_t[kPlayoutBufferSize]; | 192 _playoutBuffer = new int8_t[kPlayoutBufferSize]; |
192 } | 193 } |
193 if (!_playoutBuffer) { | 194 if (!_playoutBuffer) { |
194 _playing = false; | 195 _playing = false; |
195 return -1; | 196 return -1; |
196 } | 197 } |
197 | 198 |
198 // PLAYOUT | 199 // PLAYOUT |
199 if (!_outputFilename.empty() && | 200 if (!_outputFilename.empty() && |
200 !_outputFile.OpenFile(_outputFilename.c_str(), false)) { | 201 !_outputFile.OpenFile(_outputFilename.c_str(), false)) { |
201 printf("Failed to open playout file %s!\n", _outputFilename.c_str()); | 202 LOG(LS_ERROR) << "Failed to open playout file: " << _outputFilename; |
202 _playing = false; | 203 _playing = false; |
203 delete [] _playoutBuffer; | 204 delete [] _playoutBuffer; |
204 _playoutBuffer = NULL; | 205 _playoutBuffer = NULL; |
205 return -1; | 206 return -1; |
206 } | 207 } |
207 | 208 |
208 _ptrThreadPlay.reset(new rtc::PlatformThread( | 209 _ptrThreadPlay.reset(new rtc::PlatformThread( |
209 PlayThreadFunc, this, "webrtc_audio_module_play_thread")); | 210 PlayThreadFunc, this, "webrtc_audio_module_play_thread")); |
210 _ptrThreadPlay->Start(); | 211 _ptrThreadPlay->Start(); |
211 _ptrThreadPlay->SetPriority(rtc::kRealtimePriority); | 212 _ptrThreadPlay->SetPriority(rtc::kRealtimePriority); |
| 213 |
| 214 LOG(LS_INFO) << "Started playout capture to output file: " |
| 215 << _outputFilename; |
212 return 0; | 216 return 0; |
213 } | 217 } |
214 | 218 |
215 int32_t FileAudioDevice::StopPlayout() { | 219 int32_t FileAudioDevice::StopPlayout() { |
216 { | 220 { |
217 CriticalSectionScoped lock(&_critSect); | 221 CriticalSectionScoped lock(&_critSect); |
218 _playing = false; | 222 _playing = false; |
219 } | 223 } |
220 | 224 |
221 // stop playout thread first | 225 // stop playout thread first |
222 if (_ptrThreadPlay) { | 226 if (_ptrThreadPlay) { |
223 _ptrThreadPlay->Stop(); | 227 _ptrThreadPlay->Stop(); |
224 _ptrThreadPlay.reset(); | 228 _ptrThreadPlay.reset(); |
225 } | 229 } |
226 | 230 |
227 CriticalSectionScoped lock(&_critSect); | 231 CriticalSectionScoped lock(&_critSect); |
228 | 232 |
229 _playoutFramesLeft = 0; | 233 _playoutFramesLeft = 0; |
230 delete [] _playoutBuffer; | 234 delete [] _playoutBuffer; |
231 _playoutBuffer = NULL; | 235 _playoutBuffer = NULL; |
232 _outputFile.CloseFile(); | 236 _outputFile.CloseFile(); |
| 237 |
| 238 LOG(LS_INFO) << "Stopped playout capture to output file: " |
| 239 << _outputFilename; |
233 return 0; | 240 return 0; |
234 } | 241 } |
235 | 242 |
236 bool FileAudioDevice::Playing() const { | 243 bool FileAudioDevice::Playing() const { |
237 return true; | 244 return true; |
238 } | 245 } |
239 | 246 |
240 int32_t FileAudioDevice::StartRecording() { | 247 int32_t FileAudioDevice::StartRecording() { |
241 _recording = true; | 248 _recording = true; |
242 | 249 |
243 // Make sure we only create the buffer once. | 250 // Make sure we only create the buffer once. |
244 _recordingBufferSizeIn10MS = _recordingFramesIn10MS * | 251 _recordingBufferSizeIn10MS = _recordingFramesIn10MS * |
245 kRecordingNumChannels * | 252 kRecordingNumChannels * |
246 2; | 253 2; |
247 if (!_recordingBuffer) { | 254 if (!_recordingBuffer) { |
248 _recordingBuffer = new int8_t[_recordingBufferSizeIn10MS]; | 255 _recordingBuffer = new int8_t[_recordingBufferSizeIn10MS]; |
249 } | 256 } |
250 | 257 |
251 if (!_inputFilename.empty() && | 258 if (!_inputFilename.empty() && |
252 !_inputFile.OpenFile(_inputFilename.c_str(), true)) { | 259 !_inputFile.OpenFile(_inputFilename.c_str(), true)) { |
253 printf("Failed to open audio input file %s!\n", | 260 LOG(LS_ERROR) << "Failed to open audio input file: " << _inputFilename; |
254 _inputFilename.c_str()); | |
255 _recording = false; | 261 _recording = false; |
256 delete[] _recordingBuffer; | 262 delete[] _recordingBuffer; |
257 _recordingBuffer = NULL; | 263 _recordingBuffer = NULL; |
258 return -1; | 264 return -1; |
259 } | 265 } |
260 | 266 |
261 _ptrThreadRec.reset(new rtc::PlatformThread( | 267 _ptrThreadRec.reset(new rtc::PlatformThread( |
262 RecThreadFunc, this, "webrtc_audio_module_capture_thread")); | 268 RecThreadFunc, this, "webrtc_audio_module_capture_thread")); |
263 | 269 |
264 _ptrThreadRec->Start(); | 270 _ptrThreadRec->Start(); |
265 _ptrThreadRec->SetPriority(rtc::kRealtimePriority); | 271 _ptrThreadRec->SetPriority(rtc::kRealtimePriority); |
266 | 272 |
| 273 LOG(LS_INFO) << "Started recording from input file: " |
| 274 << _inputFilename; |
| 275 |
267 return 0; | 276 return 0; |
268 } | 277 } |
269 | 278 |
270 | 279 |
271 int32_t FileAudioDevice::StopRecording() { | 280 int32_t FileAudioDevice::StopRecording() { |
272 { | 281 { |
273 CriticalSectionScoped lock(&_critSect); | 282 CriticalSectionScoped lock(&_critSect); |
274 _recording = false; | 283 _recording = false; |
275 } | 284 } |
276 | 285 |
277 if (_ptrThreadRec) { | 286 if (_ptrThreadRec) { |
278 _ptrThreadRec->Stop(); | 287 _ptrThreadRec->Stop(); |
279 _ptrThreadRec.reset(); | 288 _ptrThreadRec.reset(); |
280 } | 289 } |
281 | 290 |
282 CriticalSectionScoped lock(&_critSect); | 291 CriticalSectionScoped lock(&_critSect); |
283 _recordingFramesLeft = 0; | 292 _recordingFramesLeft = 0; |
284 if (_recordingBuffer) { | 293 if (_recordingBuffer) { |
285 delete [] _recordingBuffer; | 294 delete [] _recordingBuffer; |
286 _recordingBuffer = NULL; | 295 _recordingBuffer = NULL; |
287 } | 296 } |
| 297 _inputFile.CloseFile(); |
| 298 |
| 299 LOG(LS_INFO) << "Stopped recording from input file: " |
| 300 << _inputFilename; |
288 return 0; | 301 return 0; |
289 } | 302 } |
290 | 303 |
291 bool FileAudioDevice::Recording() const { | 304 bool FileAudioDevice::Recording() const { |
292 return _recording; | 305 return _recording; |
293 } | 306 } |
294 | 307 |
295 int32_t FileAudioDevice::SetAGC(bool enable) { return -1; } | 308 int32_t FileAudioDevice::SetAGC(bool enable) { return -1; } |
296 | 309 |
297 bool FileAudioDevice::AGC() const { return false; } | 310 bool FileAudioDevice::AGC() const { return false; } |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 | 539 |
527 uint64_t deltaTimeMillis = _clock->CurrentNtpInMilliseconds() - currentTime; | 540 uint64_t deltaTimeMillis = _clock->CurrentNtpInMilliseconds() - currentTime; |
528 if(deltaTimeMillis < 10) { | 541 if(deltaTimeMillis < 10) { |
529 SleepMs(10 - deltaTimeMillis); | 542 SleepMs(10 - deltaTimeMillis); |
530 } | 543 } |
531 | 544 |
532 return true; | 545 return true; |
533 } | 546 } |
534 | 547 |
535 } // namespace webrtc | 548 } // namespace webrtc |
OLD | NEW |