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