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

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

Issue 2685783014: Replace NULL with nullptr in all C++ files. (Closed)
Patch Set: Fixing android. Created 3 years, 10 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
11 #include "webrtc/base/checks.h" 11 #include "webrtc/base/checks.h"
12 #include "webrtc/base/logging.h" 12 #include "webrtc/base/logging.h"
13 #include "webrtc/base/platform_thread.h" 13 #include "webrtc/base/platform_thread.h"
14 #include "webrtc/modules/audio_device/dummy/file_audio_device.h" 14 #include "webrtc/modules/audio_device/dummy/file_audio_device.h"
15 #include "webrtc/system_wrappers/include/sleep.h" 15 #include "webrtc/system_wrappers/include/sleep.h"
16 16
17 namespace webrtc { 17 namespace webrtc {
18 18
19 const int kRecordingFixedSampleRate = 48000; 19 const int kRecordingFixedSampleRate = 48000;
20 const size_t kRecordingNumChannels = 2; 20 const size_t kRecordingNumChannels = 2;
21 const int kPlayoutFixedSampleRate = 48000; 21 const int kPlayoutFixedSampleRate = 48000;
22 const size_t kPlayoutNumChannels = 2; 22 const size_t kPlayoutNumChannels = 2;
23 const size_t kPlayoutBufferSize = 23 const size_t kPlayoutBufferSize =
24 kPlayoutFixedSampleRate / 100 * kPlayoutNumChannels * 2; 24 kPlayoutFixedSampleRate / 100 * kPlayoutNumChannels * 2;
25 const size_t kRecordingBufferSize = 25 const size_t kRecordingBufferSize =
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(nullptr),
32 _recordingBuffer(NULL), 32 _recordingBuffer(nullptr),
33 _playoutBuffer(NULL), 33 _playoutBuffer(nullptr),
34 _recordingFramesLeft(0), 34 _recordingFramesLeft(0),
35 _playoutFramesLeft(0), 35 _playoutFramesLeft(0),
36 _critSect(*CriticalSectionWrapper::CreateCriticalSection()), 36 _critSect(*CriticalSectionWrapper::CreateCriticalSection()),
37 _recordingBufferSizeIn10MS(0), 37 _recordingBufferSizeIn10MS(0),
38 _recordingFramesIn10MS(0), 38 _recordingFramesIn10MS(0),
39 _playoutFramesIn10MS(0), 39 _playoutFramesIn10MS(0),
40 _playing(false), 40 _playing(false),
41 _recording(false), 41 _recording(false),
42 _lastCallPlayoutMillis(0), 42 _lastCallPlayoutMillis(0),
43 _lastCallRecordMillis(0), 43 _lastCallRecordMillis(0),
44 _outputFile(*FileWrapper::Create()), 44 _outputFile(*FileWrapper::Create()),
45 _inputFile(*FileWrapper::Create()), 45 _inputFile(*FileWrapper::Create()),
46 _outputFilename(outputFilename), 46 _outputFilename(outputFilename),
47 _inputFilename(inputFilename) { 47 _inputFilename(inputFilename) {}
48 }
49 48
50 FileAudioDevice::~FileAudioDevice() { 49 FileAudioDevice::~FileAudioDevice() {
51 delete &_outputFile; 50 delete &_outputFile;
52 delete &_inputFile; 51 delete &_inputFile;
53 } 52 }
54 53
55 int32_t FileAudioDevice::ActiveAudioLayer( 54 int32_t FileAudioDevice::ActiveAudioLayer(
56 AudioDeviceModule::AudioLayer& audioLayer) const { 55 AudioDeviceModule::AudioLayer& audioLayer) const {
57 return -1; 56 return -1;
58 } 57 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 _playing = false; 195 _playing = false;
197 return -1; 196 return -1;
198 } 197 }
199 198
200 // PLAYOUT 199 // PLAYOUT
201 if (!_outputFilename.empty() && 200 if (!_outputFilename.empty() &&
202 !_outputFile.OpenFile(_outputFilename.c_str(), false)) { 201 !_outputFile.OpenFile(_outputFilename.c_str(), false)) {
203 LOG(LS_ERROR) << "Failed to open playout file: " << _outputFilename; 202 LOG(LS_ERROR) << "Failed to open playout file: " << _outputFilename;
204 _playing = false; 203 _playing = false;
205 delete [] _playoutBuffer; 204 delete [] _playoutBuffer;
206 _playoutBuffer = NULL; 205 _playoutBuffer = nullptr;
207 return -1; 206 return -1;
208 } 207 }
209 208
210 _ptrThreadPlay.reset(new rtc::PlatformThread( 209 _ptrThreadPlay.reset(new rtc::PlatformThread(
211 PlayThreadFunc, this, "webrtc_audio_module_play_thread")); 210 PlayThreadFunc, this, "webrtc_audio_module_play_thread"));
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 CriticalSectionScoped 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 CriticalSectionScoped lock(&_critSect);
233 232
234 _playoutFramesLeft = 0; 233 _playoutFramesLeft = 0;
235 delete [] _playoutBuffer; 234 delete [] _playoutBuffer;
236 _playoutBuffer = NULL; 235 _playoutBuffer = nullptr;
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 }
243 242
244 bool FileAudioDevice::Playing() const { 243 bool FileAudioDevice::Playing() const {
245 return true; 244 return true;
246 } 245 }
247 246
248 int32_t FileAudioDevice::StartRecording() { 247 int32_t FileAudioDevice::StartRecording() {
249 _recording = true; 248 _recording = true;
250 249
251 // Make sure we only create the buffer once. 250 // Make sure we only create the buffer once.
252 _recordingBufferSizeIn10MS = _recordingFramesIn10MS * 251 _recordingBufferSizeIn10MS = _recordingFramesIn10MS *
253 kRecordingNumChannels * 252 kRecordingNumChannels *
254 2; 253 2;
255 if (!_recordingBuffer) { 254 if (!_recordingBuffer) {
256 _recordingBuffer = new int8_t[_recordingBufferSizeIn10MS]; 255 _recordingBuffer = new int8_t[_recordingBufferSizeIn10MS];
257 } 256 }
258 257
259 if (!_inputFilename.empty() && 258 if (!_inputFilename.empty() &&
260 !_inputFile.OpenFile(_inputFilename.c_str(), true)) { 259 !_inputFile.OpenFile(_inputFilename.c_str(), true)) {
261 LOG(LS_ERROR) << "Failed to open audio input file: " << _inputFilename; 260 LOG(LS_ERROR) << "Failed to open audio input file: " << _inputFilename;
262 _recording = false; 261 _recording = false;
263 delete[] _recordingBuffer; 262 delete[] _recordingBuffer;
264 _recordingBuffer = NULL; 263 _recordingBuffer = nullptr;
265 return -1; 264 return -1;
266 } 265 }
267 266
268 _ptrThreadRec.reset(new rtc::PlatformThread( 267 _ptrThreadRec.reset(new rtc::PlatformThread(
269 RecThreadFunc, this, "webrtc_audio_module_capture_thread")); 268 RecThreadFunc, this, "webrtc_audio_module_capture_thread"));
270 269
271 _ptrThreadRec->Start(); 270 _ptrThreadRec->Start();
272 _ptrThreadRec->SetPriority(rtc::kRealtimePriority); 271 _ptrThreadRec->SetPriority(rtc::kRealtimePriority);
273 272
274 LOG(LS_INFO) << "Started recording from input file: " 273 LOG(LS_INFO) << "Started recording from input file: "
(...skipping 11 matching lines...) Expand all
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 CriticalSectionScoped 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 = nullptr;
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;
303 } 302 }
304 303
305 bool FileAudioDevice::Recording() const { 304 bool FileAudioDevice::Recording() const {
306 return _recording; 305 return _recording;
(...skipping 233 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

Powered by Google App Engine
This is Rietveld 408576698