Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: webrtc/modules/audio_device/dummy/file_audio_device.cc

Issue 2785673002: Remove more CriticalSectionWrappers. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 10
(...skipping 15 matching lines...) Expand all
26 kRecordingFixedSampleRate / 100 * kRecordingNumChannels * 2; 26 kRecordingFixedSampleRate / 100 * kRecordingNumChannels * 2;
27 27
28 FileAudioDevice::FileAudioDevice(const int32_t id, 28 FileAudioDevice::FileAudioDevice(const int32_t id,
29 const char* inputFilename, 29 const char* inputFilename,
30 const char* outputFilename): 30 const char* outputFilename):
31 _ptrAudioBuffer(NULL), 31 _ptrAudioBuffer(NULL),
32 _recordingBuffer(NULL), 32 _recordingBuffer(NULL),
33 _playoutBuffer(NULL), 33 _playoutBuffer(NULL),
34 _recordingFramesLeft(0), 34 _recordingFramesLeft(0),
35 _playoutFramesLeft(0), 35 _playoutFramesLeft(0),
36 _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
37 _recordingBufferSizeIn10MS(0), 36 _recordingBufferSizeIn10MS(0),
38 _recordingFramesIn10MS(0), 37 _recordingFramesIn10MS(0),
39 _playoutFramesIn10MS(0), 38 _playoutFramesIn10MS(0),
40 _playing(false), 39 _playing(false),
41 _recording(false), 40 _recording(false),
42 _lastCallPlayoutMillis(0), 41 _lastCallPlayoutMillis(0),
43 _lastCallRecordMillis(0), 42 _lastCallRecordMillis(0),
44 _outputFile(*FileWrapper::Create()), 43 _outputFile(*FileWrapper::Create()),
45 _inputFile(*FileWrapper::Create()), 44 _inputFile(*FileWrapper::Create()),
46 _outputFilename(outputFilename), 45 _outputFilename(outputFilename),
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 int32_t FileAudioDevice::RecordingIsAvailable(bool& available) { 153 int32_t FileAudioDevice::RecordingIsAvailable(bool& available) {
155 if (_record_index == 0) { 154 if (_record_index == 0) {
156 available = true; 155 available = true;
157 return _record_index; 156 return _record_index;
158 } 157 }
159 available = false; 158 available = false;
160 return -1; 159 return -1;
161 } 160 }
162 161
163 int32_t FileAudioDevice::InitRecording() { 162 int32_t FileAudioDevice::InitRecording() {
164 CriticalSectionScoped lock(&_critSect); 163 rtc::CritScope lock(&_critSect);
165 164
166 if (_recording) { 165 if (_recording) {
167 return -1; 166 return -1;
168 } 167 }
169 168
170 _recordingFramesIn10MS = static_cast<size_t>(kRecordingFixedSampleRate / 100); 169 _recordingFramesIn10MS = static_cast<size_t>(kRecordingFixedSampleRate / 100);
171 170
172 if (_ptrAudioBuffer) { 171 if (_ptrAudioBuffer) {
173 _ptrAudioBuffer->SetRecordingSampleRate(kRecordingFixedSampleRate); 172 _ptrAudioBuffer->SetRecordingSampleRate(kRecordingFixedSampleRate);
174 _ptrAudioBuffer->SetRecordingChannels(kRecordingNumChannels); 173 _ptrAudioBuffer->SetRecordingChannels(kRecordingNumChannels);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 _ptrThreadPlay->Start(); 211 _ptrThreadPlay->Start();
213 _ptrThreadPlay->SetPriority(rtc::kRealtimePriority); 212 _ptrThreadPlay->SetPriority(rtc::kRealtimePriority);
214 213
215 LOG(LS_INFO) << "Started playout capture to output file: " 214 LOG(LS_INFO) << "Started playout capture to output file: "
216 << _outputFilename; 215 << _outputFilename;
217 return 0; 216 return 0;
218 } 217 }
219 218
220 int32_t FileAudioDevice::StopPlayout() { 219 int32_t FileAudioDevice::StopPlayout() {
221 { 220 {
222 CriticalSectionScoped lock(&_critSect); 221 rtc::CritScope lock(&_critSect);
223 _playing = false; 222 _playing = false;
224 } 223 }
225 224
226 // stop playout thread first 225 // stop playout thread first
227 if (_ptrThreadPlay) { 226 if (_ptrThreadPlay) {
228 _ptrThreadPlay->Stop(); 227 _ptrThreadPlay->Stop();
229 _ptrThreadPlay.reset(); 228 _ptrThreadPlay.reset();
230 } 229 }
231 230
232 CriticalSectionScoped lock(&_critSect); 231 rtc::CritScope lock(&_critSect);
233 232
234 _playoutFramesLeft = 0; 233 _playoutFramesLeft = 0;
235 delete [] _playoutBuffer; 234 delete [] _playoutBuffer;
236 _playoutBuffer = NULL; 235 _playoutBuffer = NULL;
237 _outputFile.CloseFile(); 236 _outputFile.CloseFile();
238 237
239 LOG(LS_INFO) << "Stopped playout capture to output file: " 238 LOG(LS_INFO) << "Stopped playout capture to output file: "
240 << _outputFilename; 239 << _outputFilename;
241 return 0; 240 return 0;
242 } 241 }
(...skipping 30 matching lines...) Expand all
273 272
274 LOG(LS_INFO) << "Started recording from input file: " 273 LOG(LS_INFO) << "Started recording from input file: "
275 << _inputFilename; 274 << _inputFilename;
276 275
277 return 0; 276 return 0;
278 } 277 }
279 278
280 279
281 int32_t FileAudioDevice::StopRecording() { 280 int32_t FileAudioDevice::StopRecording() {
282 { 281 {
283 CriticalSectionScoped lock(&_critSect); 282 rtc::CritScope lock(&_critSect);
284 _recording = false; 283 _recording = false;
285 } 284 }
286 285
287 if (_ptrThreadRec) { 286 if (_ptrThreadRec) {
288 _ptrThreadRec->Stop(); 287 _ptrThreadRec->Stop();
289 _ptrThreadRec.reset(); 288 _ptrThreadRec.reset();
290 } 289 }
291 290
292 CriticalSectionScoped lock(&_critSect); 291 rtc::CritScope lock(&_critSect);
293 _recordingFramesLeft = 0; 292 _recordingFramesLeft = 0;
294 if (_recordingBuffer) { 293 if (_recordingBuffer) {
295 delete [] _recordingBuffer; 294 delete [] _recordingBuffer;
296 _recordingBuffer = NULL; 295 _recordingBuffer = NULL;
297 } 296 }
298 _inputFile.CloseFile(); 297 _inputFile.CloseFile();
299 298
300 LOG(LS_INFO) << "Stopped recording from input file: " 299 LOG(LS_INFO) << "Stopped recording from input file: "
301 << _inputFilename; 300 << _inputFilename;
302 return 0; 301 return 0;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 448
450 void FileAudioDevice::ClearPlayoutWarning() {} 449 void FileAudioDevice::ClearPlayoutWarning() {}
451 450
452 void FileAudioDevice::ClearPlayoutError() {} 451 void FileAudioDevice::ClearPlayoutError() {}
453 452
454 void FileAudioDevice::ClearRecordingWarning() {} 453 void FileAudioDevice::ClearRecordingWarning() {}
455 454
456 void FileAudioDevice::ClearRecordingError() {} 455 void FileAudioDevice::ClearRecordingError() {}
457 456
458 void FileAudioDevice::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) { 457 void FileAudioDevice::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
459 CriticalSectionScoped lock(&_critSect); 458 rtc::CritScope lock(&_critSect);
460 459
461 _ptrAudioBuffer = audioBuffer; 460 _ptrAudioBuffer = audioBuffer;
462 461
463 // Inform the AudioBuffer about default settings for this implementation. 462 // Inform the AudioBuffer about default settings for this implementation.
464 // Set all values to zero here since the actual settings will be done by 463 // Set all values to zero here since the actual settings will be done by
465 // InitPlayout and InitRecording later. 464 // InitPlayout and InitRecording later.
466 _ptrAudioBuffer->SetRecordingSampleRate(0); 465 _ptrAudioBuffer->SetRecordingSampleRate(0);
467 _ptrAudioBuffer->SetPlayoutSampleRate(0); 466 _ptrAudioBuffer->SetPlayoutSampleRate(0);
468 _ptrAudioBuffer->SetRecordingChannels(0); 467 _ptrAudioBuffer->SetRecordingChannels(0);
469 _ptrAudioBuffer->SetPlayoutChannels(0); 468 _ptrAudioBuffer->SetPlayoutChannels(0);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 539
541 int64_t deltaTimeMillis = rtc::TimeMillis() - currentTime; 540 int64_t deltaTimeMillis = rtc::TimeMillis() - currentTime;
542 if (deltaTimeMillis < 10) { 541 if (deltaTimeMillis < 10) {
543 SleepMs(10 - deltaTimeMillis); 542 SleepMs(10 - deltaTimeMillis);
544 } 543 }
545 544
546 return true; 545 return true;
547 } 546 }
548 547
549 } // namespace webrtc 548 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/dummy/file_audio_device.h ('k') | webrtc/modules/audio_device/linux/audio_device_alsa_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698