| 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 <iostream> | 10 #include <iostream> |
| 11 #include "webrtc/modules/audio_device/dummy/file_audio_device.h" | 11 #include "webrtc/modules/audio_device/dummy/file_audio_device.h" |
| 12 #include "webrtc/system_wrappers/interface/sleep.h" | 12 #include "webrtc/system_wrappers/interface/sleep.h" |
| 13 #include "webrtc/system_wrappers/interface/thread_wrapper.h" | 13 #include "webrtc/system_wrappers/interface/thread_wrapper.h" |
| 14 | 14 |
| 15 namespace webrtc { | 15 namespace webrtc { |
| 16 | 16 |
| 17 int kRecordingFixedSampleRate = 48000; | 17 int kRecordingFixedSampleRate = 48000; |
| 18 int kRecordingNumChannels = 2; | 18 size_t kRecordingNumChannels = 2; |
| 19 int kPlayoutFixedSampleRate = 48000; | 19 int kPlayoutFixedSampleRate = 48000; |
| 20 int kPlayoutNumChannels = 2; | 20 size_t kPlayoutNumChannels = 2; |
| 21 int kPlayoutBufferSize = kPlayoutFixedSampleRate / 100 | 21 size_t kPlayoutBufferSize = |
| 22 * kPlayoutNumChannels * 2; | 22 kPlayoutFixedSampleRate / 100 * kPlayoutNumChannels * 2; |
| 23 int kRecordingBufferSize = kRecordingFixedSampleRate / 100 | 23 size_t kRecordingBufferSize = |
| 24 * kRecordingNumChannels * 2; | 24 kRecordingFixedSampleRate / 100 * kRecordingNumChannels * 2; |
| 25 | 25 |
| 26 FileAudioDevice::FileAudioDevice(const int32_t id, | 26 FileAudioDevice::FileAudioDevice(const int32_t id, |
| 27 const char* inputFilename, | 27 const char* inputFilename, |
| 28 const char* outputFilename): | 28 const char* outputFilename): |
| 29 _ptrAudioBuffer(NULL), | 29 _ptrAudioBuffer(NULL), |
| 30 _recordingBuffer(NULL), | 30 _recordingBuffer(NULL), |
| 31 _playoutBuffer(NULL), | 31 _playoutBuffer(NULL), |
| 32 _recordingFramesLeft(0), | 32 _recordingFramesLeft(0), |
| 33 _playoutFramesLeft(0), | 33 _playoutFramesLeft(0), |
| 34 _critSect(*CriticalSectionWrapper::CreateCriticalSection()), | 34 _critSect(*CriticalSectionWrapper::CreateCriticalSection()), |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 int32_t FileAudioDevice::StartPlayout() { | 188 int32_t FileAudioDevice::StartPlayout() { |
| 189 if (_playing) { | 189 if (_playing) { |
| 190 return 0; | 190 return 0; |
| 191 } | 191 } |
| 192 | 192 |
| 193 _playoutFramesIn10MS = static_cast<size_t>(kPlayoutFixedSampleRate / 100); | 193 _playoutFramesIn10MS = static_cast<size_t>(kPlayoutFixedSampleRate / 100); |
| 194 _playing = true; | 194 _playing = true; |
| 195 _playoutFramesLeft = 0; | 195 _playoutFramesLeft = 0; |
| 196 | 196 |
| 197 if (!_playoutBuffer) { | 197 if (!_playoutBuffer) { |
| 198 _playoutBuffer = new int8_t[2 * | 198 _playoutBuffer = new int8_t[kPlayoutBufferSize]; |
| 199 kPlayoutNumChannels * | |
| 200 kPlayoutFixedSampleRate/100]; | |
| 201 } | 199 } |
| 202 if (!_playoutBuffer) { | 200 if (!_playoutBuffer) { |
| 203 _playing = false; | 201 _playing = false; |
| 204 return -1; | 202 return -1; |
| 205 } | 203 } |
| 206 | 204 |
| 207 // PLAYOUT | 205 // PLAYOUT |
| 208 if (!_outputFilename.empty() && _outputFile.OpenFile( | 206 if (!_outputFilename.empty() && _outputFile.OpenFile( |
| 209 _outputFilename.c_str(), false, false, false) == -1) { | 207 _outputFilename.c_str(), false, false, false) == -1) { |
| 210 printf("Failed to open playout file %s!\n", _outputFilename.c_str()); | 208 printf("Failed to open playout file %s!\n", _outputFilename.c_str()); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 _critSect.Enter(); | 540 _critSect.Enter(); |
| 543 } | 541 } |
| 544 } | 542 } |
| 545 | 543 |
| 546 _critSect.Leave(); | 544 _critSect.Leave(); |
| 547 SleepMs(10 - (_clock->CurrentNtpInMilliseconds() - currentTime)); | 545 SleepMs(10 - (_clock->CurrentNtpInMilliseconds() - currentTime)); |
| 548 return true; | 546 return true; |
| 549 } | 547 } |
| 550 | 548 |
| 551 } // namespace webrtc | 549 } // namespace webrtc |
| OLD | NEW |