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

Side by Side Diff: webrtc/modules/audio_device/audio_device_buffer.cc

Issue 1228823003: Update audio code to use size_t more correctly, webrtc/modules/audio_device/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Review comments Created 5 years, 4 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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/modules/audio_device/audio_device_buffer.h" 11 #include "webrtc/modules/audio_device/audio_device_buffer.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 #include <string.h> 14 #include <string.h>
15 15
16 #include "webrtc/base/format_macros.h"
16 #include "webrtc/modules/audio_device/audio_device_config.h" 17 #include "webrtc/modules/audio_device/audio_device_config.h"
17 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" 18 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
18 #include "webrtc/system_wrappers/interface/logging.h" 19 #include "webrtc/system_wrappers/interface/logging.h"
19 #include "webrtc/system_wrappers/interface/trace.h" 20 #include "webrtc/system_wrappers/interface/trace.h"
20 21
21 namespace webrtc { 22 namespace webrtc {
22 23
23 static const int kHighDelayThresholdMs = 300; 24 static const int kHighDelayThresholdMs = 300;
24 static const int kLogHighDelayIntervalFrames = 500; // 5 seconds. 25 static const int kLogHighDelayIntervalFrames = 500; // 5 seconds.
25 26
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 // This method can also parse out left or right channel from a stereo 374 // This method can also parse out left or right channel from a stereo
374 // input signal, i.e., emulate mono. 375 // input signal, i.e., emulate mono.
375 // 376 //
376 // Examples: 377 // Examples:
377 // 378 //
378 // 16-bit,48kHz mono, 10ms => nSamples=480 => _recSize=2*480=960 bytes 379 // 16-bit,48kHz mono, 10ms => nSamples=480 => _recSize=2*480=960 bytes
379 // 16-bit,48kHz stereo,10ms => nSamples=480 => _recSize=4*480=1920 bytes 380 // 16-bit,48kHz stereo,10ms => nSamples=480 => _recSize=4*480=1920 bytes
380 // ---------------------------------------------------------------------------- 381 // ----------------------------------------------------------------------------
381 382
382 int32_t AudioDeviceBuffer::SetRecordedBuffer(const void* audioBuffer, 383 int32_t AudioDeviceBuffer::SetRecordedBuffer(const void* audioBuffer,
383 uint32_t nSamples) 384 size_t nSamples)
384 { 385 {
385 CriticalSectionScoped lock(&_critSect); 386 CriticalSectionScoped lock(&_critSect);
386 387
387 if (_recBytesPerSample == 0) 388 if (_recBytesPerSample == 0)
388 { 389 {
389 assert(false); 390 assert(false);
390 return -1; 391 return -1;
391 } 392 }
392 393
393 _recSamples = nSamples; 394 _recSamples = nSamples;
(...skipping 13 matching lines...) Expand all
407 { 408 {
408 int16_t* ptr16In = (int16_t*)audioBuffer; 409 int16_t* ptr16In = (int16_t*)audioBuffer;
409 int16_t* ptr16Out = (int16_t*)&_recBuffer[0]; 410 int16_t* ptr16Out = (int16_t*)&_recBuffer[0];
410 411
411 if (AudioDeviceModule::kChannelRight == _recChannel) 412 if (AudioDeviceModule::kChannelRight == _recChannel)
412 { 413 {
413 ptr16In++; 414 ptr16In++;
414 } 415 }
415 416
416 // exctract left or right channel from input buffer to the local buffer 417 // exctract left or right channel from input buffer to the local buffer
417 for (uint32_t i = 0; i < _recSamples; i++) 418 for (size_t i = 0; i < _recSamples; i++)
418 { 419 {
419 *ptr16Out = *ptr16In; 420 *ptr16Out = *ptr16In;
420 ptr16Out++; 421 ptr16Out++;
421 ptr16In++; 422 ptr16In++;
422 ptr16In++; 423 ptr16In++;
423 } 424 }
424 } 425 }
425 426
426 if (_recFile.Open()) 427 if (_recFile.Open())
427 { 428 {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 _newMicLevel = newMicLevel; 476 _newMicLevel = newMicLevel;
476 } 477 }
477 478
478 return 0; 479 return 0;
479 } 480 }
480 481
481 // ---------------------------------------------------------------------------- 482 // ----------------------------------------------------------------------------
482 // RequestPlayoutData 483 // RequestPlayoutData
483 // ---------------------------------------------------------------------------- 484 // ----------------------------------------------------------------------------
484 485
485 int32_t AudioDeviceBuffer::RequestPlayoutData(uint32_t nSamples) 486 int32_t AudioDeviceBuffer::RequestPlayoutData(size_t nSamples)
486 { 487 {
487 uint32_t playSampleRate = 0; 488 uint32_t playSampleRate = 0;
488 uint8_t playBytesPerSample = 0; 489 size_t playBytesPerSample = 0;
489 uint8_t playChannels = 0; 490 uint8_t playChannels = 0;
490 { 491 {
491 CriticalSectionScoped lock(&_critSect); 492 CriticalSectionScoped lock(&_critSect);
492 493
493 // Store copies under lock and use copies hereafter to avoid race with 494 // Store copies under lock and use copies hereafter to avoid race with
494 // setter methods. 495 // setter methods.
495 playSampleRate = _playSampleRate; 496 playSampleRate = _playSampleRate;
496 playBytesPerSample = _playBytesPerSample; 497 playBytesPerSample = _playBytesPerSample;
497 playChannels = _playChannels; 498 playChannels = _playChannels;
498 499
(...skipping 14 matching lines...) Expand all
513 return -1; 514 return -1;
514 } 515 }
515 516
516 if (nSamples != _playSamples) 517 if (nSamples != _playSamples)
517 { 518 {
518 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "invalid number of samples to be played out (%d)", nSamples); 519 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "invalid number of samples to be played out (%d)", nSamples);
519 return -1; 520 return -1;
520 } 521 }
521 } 522 }
522 523
523 uint32_t nSamplesOut(0); 524 size_t nSamplesOut(0);
524 525
525 CriticalSectionScoped lock(&_critSectCb); 526 CriticalSectionScoped lock(&_critSectCb);
526 527
527 if (_ptrCbAudioTransport == NULL) 528 if (_ptrCbAudioTransport == NULL)
528 { 529 {
529 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "failed to feed data to playout (AudioTransport does not exist)"); 530 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "failed to feed data to playout (AudioTransport does not exist)");
530 return 0; 531 return 0;
531 } 532 }
532 533
533 if (_ptrCbAudioTransport) 534 if (_ptrCbAudioTransport)
(...skipping 22 matching lines...) Expand all
556 // GetPlayoutData 557 // GetPlayoutData
557 // ---------------------------------------------------------------------------- 558 // ----------------------------------------------------------------------------
558 559
559 int32_t AudioDeviceBuffer::GetPlayoutData(void* audioBuffer) 560 int32_t AudioDeviceBuffer::GetPlayoutData(void* audioBuffer)
560 { 561 {
561 CriticalSectionScoped lock(&_critSect); 562 CriticalSectionScoped lock(&_critSect);
562 563
563 if (_playSize > kMaxBufferSizeBytes) 564 if (_playSize > kMaxBufferSizeBytes)
564 { 565 {
565 WEBRTC_TRACE(kTraceError, kTraceUtility, _id, 566 WEBRTC_TRACE(kTraceError, kTraceUtility, _id,
566 "_playSize %i exceeds kMaxBufferSizeBytes in " 567 "_playSize %" PRIuS " exceeds kMaxBufferSizeBytes in "
567 "AudioDeviceBuffer::GetPlayoutData", _playSize); 568 "AudioDeviceBuffer::GetPlayoutData", _playSize);
568 assert(false); 569 assert(false);
569 return -1; 570 return -1;
570 } 571 }
571 572
572 memcpy(audioBuffer, &_playBuffer[0], _playSize); 573 memcpy(audioBuffer, &_playBuffer[0], _playSize);
573 574
574 if (_playFile.Open()) 575 if (_playFile.Open())
575 { 576 {
576 // write to binary file in mono or stereo (interleaved) 577 // write to binary file in mono or stereo (interleaved)
577 _playFile.Write(&_playBuffer[0], _playSize); 578 _playFile.Write(&_playBuffer[0], _playSize);
578 } 579 }
579 580
580 return static_cast<int32_t>(_playSamples); 581 return static_cast<int32_t>(_playSamples);
581 } 582 }
582 583
583 } // namespace webrtc 584 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/audio_device_buffer.h ('k') | webrtc/modules/audio_device/dummy/file_audio_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698