From 0fd6801c3c2e059121d50b9293c41828bbdcc085 Mon Sep 17 00:00:00 2001 From: henrika Date: Mon, 4 Jul 2016 13:01:19 +0200 Subject: [PATCH] clang-format on AudioDeviceBuffer BUG=NONE R=magjed@webrtc.org Review URL: https://codereview.webrtc.org/2119093003 . Cr-Commit-Position: refs/heads/master@{#13377} --- .../audio_device/audio_device_buffer.cc | 587 ++++++++---------- .../audio_device/audio_device_buffer.h | 136 ++-- 2 files changed, 335 insertions(+), 388 deletions(-) diff --git a/webrtc/modules/audio_device/audio_device_buffer.cc b/webrtc/modules/audio_device/audio_device_buffer.cc index 0bc2f5c225..d10a2bd464 100644 --- a/webrtc/modules/audio_device/audio_device_buffer.cc +++ b/webrtc/modules/audio_device/audio_device_buffer.cc @@ -28,166 +28,160 @@ static const int kLogHighDelayIntervalFrames = 500; // 5 seconds. // ctor // ---------------------------------------------------------------------------- -AudioDeviceBuffer::AudioDeviceBuffer() : - _id(-1), - _critSect(*CriticalSectionWrapper::CreateCriticalSection()), - _critSectCb(*CriticalSectionWrapper::CreateCriticalSection()), - _ptrCbAudioTransport(NULL), - _recSampleRate(0), - _playSampleRate(0), - _recChannels(0), - _playChannels(0), - _recChannel(AudioDeviceModule::kChannelBoth), - _recBytesPerSample(0), - _playBytesPerSample(0), - _recSamples(0), - _recSize(0), - _playSamples(0), - _playSize(0), - _recFile(*FileWrapper::Create()), - _playFile(*FileWrapper::Create()), - _currentMicLevel(0), - _newMicLevel(0), - _typingStatus(false), - _playDelayMS(0), - _recDelayMS(0), - _clockDrift(0), - // Set to the interval in order to log on the first occurrence. - high_delay_counter_(kLogHighDelayIntervalFrames) { - // valid ID will be set later by SetId, use -1 for now - WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s created", __FUNCTION__); - memset(_recBuffer, 0, kMaxBufferSizeBytes); - memset(_playBuffer, 0, kMaxBufferSizeBytes); +AudioDeviceBuffer::AudioDeviceBuffer() + : _id(-1), + _critSect(*CriticalSectionWrapper::CreateCriticalSection()), + _critSectCb(*CriticalSectionWrapper::CreateCriticalSection()), + _ptrCbAudioTransport(NULL), + _recSampleRate(0), + _playSampleRate(0), + _recChannels(0), + _playChannels(0), + _recChannel(AudioDeviceModule::kChannelBoth), + _recBytesPerSample(0), + _playBytesPerSample(0), + _recSamples(0), + _recSize(0), + _playSamples(0), + _playSize(0), + _recFile(*FileWrapper::Create()), + _playFile(*FileWrapper::Create()), + _currentMicLevel(0), + _newMicLevel(0), + _typingStatus(false), + _playDelayMS(0), + _recDelayMS(0), + _clockDrift(0), + // Set to the interval in order to log on the first occurrence. + high_delay_counter_(kLogHighDelayIntervalFrames) { + // valid ID will be set later by SetId, use -1 for now + WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s created", + __FUNCTION__); + memset(_recBuffer, 0, kMaxBufferSizeBytes); + memset(_playBuffer, 0, kMaxBufferSizeBytes); } // ---------------------------------------------------------------------------- // dtor // ---------------------------------------------------------------------------- -AudioDeviceBuffer::~AudioDeviceBuffer() -{ - WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", __FUNCTION__); - { - CriticalSectionScoped lock(&_critSect); +AudioDeviceBuffer::~AudioDeviceBuffer() { + WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destroyed", + __FUNCTION__); + { + CriticalSectionScoped lock(&_critSect); - _recFile.Flush(); - _recFile.CloseFile(); - delete &_recFile; + _recFile.Flush(); + _recFile.CloseFile(); + delete &_recFile; - _playFile.Flush(); - _playFile.CloseFile(); - delete &_playFile; - } + _playFile.Flush(); + _playFile.CloseFile(); + delete &_playFile; + } - delete &_critSect; - delete &_critSectCb; + delete &_critSect; + delete &_critSectCb; } // ---------------------------------------------------------------------------- // SetId // ---------------------------------------------------------------------------- -void AudioDeviceBuffer::SetId(uint32_t id) -{ - WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id, "AudioDeviceBuffer::SetId(id=%d)", id); - _id = id; +void AudioDeviceBuffer::SetId(uint32_t id) { + WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, id, + "AudioDeviceBuffer::SetId(id=%d)", id); + _id = id; } // ---------------------------------------------------------------------------- // RegisterAudioCallback // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::RegisterAudioCallback(AudioTransport* audioCallback) -{ - CriticalSectionScoped lock(&_critSectCb); - _ptrCbAudioTransport = audioCallback; +int32_t AudioDeviceBuffer::RegisterAudioCallback( + AudioTransport* audioCallback) { + CriticalSectionScoped lock(&_critSectCb); + _ptrCbAudioTransport = audioCallback; - return 0; + return 0; } // ---------------------------------------------------------------------------- // InitPlayout // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::InitPlayout() -{ - WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); - return 0; +int32_t AudioDeviceBuffer::InitPlayout() { + WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); + return 0; } // ---------------------------------------------------------------------------- // InitRecording // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::InitRecording() -{ - WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); - return 0; +int32_t AudioDeviceBuffer::InitRecording() { + WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); + return 0; } // ---------------------------------------------------------------------------- // SetRecordingSampleRate // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::SetRecordingSampleRate(uint32_t fsHz) -{ - CriticalSectionScoped lock(&_critSect); - _recSampleRate = fsHz; - return 0; +int32_t AudioDeviceBuffer::SetRecordingSampleRate(uint32_t fsHz) { + CriticalSectionScoped lock(&_critSect); + _recSampleRate = fsHz; + return 0; } // ---------------------------------------------------------------------------- // SetPlayoutSampleRate // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::SetPlayoutSampleRate(uint32_t fsHz) -{ - CriticalSectionScoped lock(&_critSect); - _playSampleRate = fsHz; - return 0; +int32_t AudioDeviceBuffer::SetPlayoutSampleRate(uint32_t fsHz) { + CriticalSectionScoped lock(&_critSect); + _playSampleRate = fsHz; + return 0; } // ---------------------------------------------------------------------------- // RecordingSampleRate // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::RecordingSampleRate() const -{ - return _recSampleRate; +int32_t AudioDeviceBuffer::RecordingSampleRate() const { + return _recSampleRate; } // ---------------------------------------------------------------------------- // PlayoutSampleRate // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::PlayoutSampleRate() const -{ - return _playSampleRate; +int32_t AudioDeviceBuffer::PlayoutSampleRate() const { + return _playSampleRate; } // ---------------------------------------------------------------------------- // SetRecordingChannels // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::SetRecordingChannels(size_t channels) -{ - CriticalSectionScoped lock(&_critSect); - _recChannels = channels; - _recBytesPerSample = 2*channels; // 16 bits per sample in mono, 32 bits in stereo - return 0; +int32_t AudioDeviceBuffer::SetRecordingChannels(size_t channels) { + CriticalSectionScoped lock(&_critSect); + _recChannels = channels; + _recBytesPerSample = + 2 * channels; // 16 bits per sample in mono, 32 bits in stereo + return 0; } // ---------------------------------------------------------------------------- // SetPlayoutChannels // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::SetPlayoutChannels(size_t channels) -{ - CriticalSectionScoped lock(&_critSect); - _playChannels = channels; - // 16 bits per sample in mono, 32 bits in stereo - _playBytesPerSample = 2*channels; - return 0; +int32_t AudioDeviceBuffer::SetPlayoutChannels(size_t channels) { + CriticalSectionScoped lock(&_critSect); + _playChannels = channels; + // 16 bits per sample in mono, 32 bits in stereo + _playBytesPerSample = 2 * channels; + return 0; } // ---------------------------------------------------------------------------- @@ -201,88 +195,80 @@ int32_t AudioDeviceBuffer::SetPlayoutChannels(size_t channels) // will be 2 instead of 4 four these cases. // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::SetRecordingChannel(const AudioDeviceModule::ChannelType channel) -{ - CriticalSectionScoped lock(&_critSect); +int32_t AudioDeviceBuffer::SetRecordingChannel( + const AudioDeviceModule::ChannelType channel) { + CriticalSectionScoped lock(&_critSect); - if (_recChannels == 1) - { - return -1; - } + if (_recChannels == 1) { + return -1; + } - if (channel == AudioDeviceModule::kChannelBoth) - { - // two bytes per channel - _recBytesPerSample = 4; - } - else - { - // only utilize one out of two possible channels (left or right) - _recBytesPerSample = 2; - } - _recChannel = channel; + if (channel == AudioDeviceModule::kChannelBoth) { + // two bytes per channel + _recBytesPerSample = 4; + } else { + // only utilize one out of two possible channels (left or right) + _recBytesPerSample = 2; + } + _recChannel = channel; - return 0; + return 0; } // ---------------------------------------------------------------------------- // RecordingChannel // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::RecordingChannel(AudioDeviceModule::ChannelType& channel) const -{ - channel = _recChannel; - return 0; +int32_t AudioDeviceBuffer::RecordingChannel( + AudioDeviceModule::ChannelType& channel) const { + channel = _recChannel; + return 0; } // ---------------------------------------------------------------------------- // RecordingChannels // ---------------------------------------------------------------------------- -size_t AudioDeviceBuffer::RecordingChannels() const -{ - return _recChannels; +size_t AudioDeviceBuffer::RecordingChannels() const { + return _recChannels; } // ---------------------------------------------------------------------------- // PlayoutChannels // ---------------------------------------------------------------------------- -size_t AudioDeviceBuffer::PlayoutChannels() const -{ - return _playChannels; +size_t AudioDeviceBuffer::PlayoutChannels() const { + return _playChannels; } // ---------------------------------------------------------------------------- // SetCurrentMicLevel // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::SetCurrentMicLevel(uint32_t level) -{ - _currentMicLevel = level; - return 0; +int32_t AudioDeviceBuffer::SetCurrentMicLevel(uint32_t level) { + _currentMicLevel = level; + return 0; } -int32_t AudioDeviceBuffer::SetTypingStatus(bool typingStatus) -{ - _typingStatus = typingStatus; - return 0; +int32_t AudioDeviceBuffer::SetTypingStatus(bool typingStatus) { + _typingStatus = typingStatus; + return 0; } // ---------------------------------------------------------------------------- // NewMicLevel // ---------------------------------------------------------------------------- -uint32_t AudioDeviceBuffer::NewMicLevel() const -{ - return _newMicLevel; +uint32_t AudioDeviceBuffer::NewMicLevel() const { + return _newMicLevel; } // ---------------------------------------------------------------------------- // SetVQEData // ---------------------------------------------------------------------------- -void AudioDeviceBuffer::SetVQEData(int playDelayMs, int recDelayMs, +void AudioDeviceBuffer::SetVQEData(int playDelayMs, + int recDelayMs, int clockDrift) { if (high_delay_counter_ < kLogHighDelayIntervalFrames) { ++high_delay_counter_; @@ -304,32 +290,30 @@ void AudioDeviceBuffer::SetVQEData(int playDelayMs, int recDelayMs, // ---------------------------------------------------------------------------- int32_t AudioDeviceBuffer::StartInputFileRecording( - const char fileName[kAdmMaxFileNameSize]) -{ - WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); + const char fileName[kAdmMaxFileNameSize]) { + WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); - CriticalSectionScoped lock(&_critSect); + CriticalSectionScoped lock(&_critSect); - _recFile.Flush(); - _recFile.CloseFile(); + _recFile.Flush(); + _recFile.CloseFile(); - return _recFile.OpenFile(fileName, false) ? 0 : -1; + return _recFile.OpenFile(fileName, false) ? 0 : -1; } // ---------------------------------------------------------------------------- // StopInputFileRecording // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::StopInputFileRecording() -{ - WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); +int32_t AudioDeviceBuffer::StopInputFileRecording() { + WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); - CriticalSectionScoped lock(&_critSect); + CriticalSectionScoped lock(&_critSect); - _recFile.Flush(); - _recFile.CloseFile(); + _recFile.Flush(); + _recFile.CloseFile(); - return 0; + return 0; } // ---------------------------------------------------------------------------- @@ -337,32 +321,30 @@ int32_t AudioDeviceBuffer::StopInputFileRecording() // ---------------------------------------------------------------------------- int32_t AudioDeviceBuffer::StartOutputFileRecording( - const char fileName[kAdmMaxFileNameSize]) -{ - WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); + const char fileName[kAdmMaxFileNameSize]) { + WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); - CriticalSectionScoped lock(&_critSect); + CriticalSectionScoped lock(&_critSect); - _playFile.Flush(); - _playFile.CloseFile(); + _playFile.Flush(); + _playFile.CloseFile(); - return _playFile.OpenFile(fileName, false) ? 0 : -1; + return _playFile.OpenFile(fileName, false) ? 0 : -1; } // ---------------------------------------------------------------------------- // StopOutputFileRecording // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::StopOutputFileRecording() -{ - WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); +int32_t AudioDeviceBuffer::StopOutputFileRecording() { + WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); - CriticalSectionScoped lock(&_critSect); + CriticalSectionScoped lock(&_critSect); - _playFile.Flush(); - _playFile.CloseFile(); + _playFile.Flush(); + _playFile.CloseFile(); - return 0; + return 0; } // ---------------------------------------------------------------------------- @@ -381,202 +363,175 @@ int32_t AudioDeviceBuffer::StopOutputFileRecording() // ---------------------------------------------------------------------------- int32_t AudioDeviceBuffer::SetRecordedBuffer(const void* audioBuffer, - size_t nSamples) -{ - CriticalSectionScoped lock(&_critSect); + size_t nSamples) { + CriticalSectionScoped lock(&_critSect); - if (_recBytesPerSample == 0) - { - assert(false); - return -1; + if (_recBytesPerSample == 0) { + assert(false); + return -1; + } + + _recSamples = nSamples; + _recSize = _recBytesPerSample * nSamples; // {2,4}*nSamples + if (_recSize > kMaxBufferSizeBytes) { + assert(false); + return -1; + } + + if (_recChannel == AudioDeviceModule::kChannelBoth) { + // (default) copy the complete input buffer to the local buffer + memcpy(&_recBuffer[0], audioBuffer, _recSize); + } else { + int16_t* ptr16In = (int16_t*)audioBuffer; + int16_t* ptr16Out = (int16_t*)&_recBuffer[0]; + + if (AudioDeviceModule::kChannelRight == _recChannel) { + ptr16In++; } - _recSamples = nSamples; - _recSize = _recBytesPerSample*nSamples; // {2,4}*nSamples - if (_recSize > kMaxBufferSizeBytes) - { - assert(false); - return -1; + // exctract left or right channel from input buffer to the local buffer + for (size_t i = 0; i < _recSamples; i++) { + *ptr16Out = *ptr16In; + ptr16Out++; + ptr16In++; + ptr16In++; } + } - if (_recChannel == AudioDeviceModule::kChannelBoth) - { - // (default) copy the complete input buffer to the local buffer - memcpy(&_recBuffer[0], audioBuffer, _recSize); - } - else - { - int16_t* ptr16In = (int16_t*)audioBuffer; - int16_t* ptr16Out = (int16_t*)&_recBuffer[0]; + if (_recFile.is_open()) { + // write to binary file in mono or stereo (interleaved) + _recFile.Write(&_recBuffer[0], _recSize); + } - if (AudioDeviceModule::kChannelRight == _recChannel) - { - ptr16In++; - } - - // exctract left or right channel from input buffer to the local buffer - for (size_t i = 0; i < _recSamples; i++) - { - *ptr16Out = *ptr16In; - ptr16Out++; - ptr16In++; - ptr16In++; - } - } - - if (_recFile.is_open()) { - // write to binary file in mono or stereo (interleaved) - _recFile.Write(&_recBuffer[0], _recSize); - } - - return 0; + return 0; } // ---------------------------------------------------------------------------- // DeliverRecordedData // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::DeliverRecordedData() -{ - CriticalSectionScoped lock(&_critSectCb); +int32_t AudioDeviceBuffer::DeliverRecordedData() { + CriticalSectionScoped lock(&_critSectCb); - // Ensure that user has initialized all essential members - if ((_recSampleRate == 0) || - (_recSamples == 0) || - (_recBytesPerSample == 0) || - (_recChannels == 0)) - { - assert(false); - return -1; - } - - if (_ptrCbAudioTransport == NULL) - { - WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "failed to deliver recorded data (AudioTransport does not exist)"); - return 0; - } - - int32_t res(0); - uint32_t newMicLevel(0); - uint32_t totalDelayMS = _playDelayMS +_recDelayMS; - - res = _ptrCbAudioTransport->RecordedDataIsAvailable(&_recBuffer[0], - _recSamples, - _recBytesPerSample, - _recChannels, - _recSampleRate, - totalDelayMS, - _clockDrift, - _currentMicLevel, - _typingStatus, - newMicLevel); - if (res != -1) - { - _newMicLevel = newMicLevel; - } + // Ensure that user has initialized all essential members + if ((_recSampleRate == 0) || (_recSamples == 0) || + (_recBytesPerSample == 0) || (_recChannels == 0)) { + assert(false); + return -1; + } + if (_ptrCbAudioTransport == NULL) { + WEBRTC_TRACE( + kTraceWarning, kTraceAudioDevice, _id, + "failed to deliver recorded data (AudioTransport does not exist)"); return 0; + } + + int32_t res(0); + uint32_t newMicLevel(0); + uint32_t totalDelayMS = _playDelayMS + _recDelayMS; + + res = _ptrCbAudioTransport->RecordedDataIsAvailable( + &_recBuffer[0], _recSamples, _recBytesPerSample, _recChannels, + _recSampleRate, totalDelayMS, _clockDrift, _currentMicLevel, + _typingStatus, newMicLevel); + if (res != -1) { + _newMicLevel = newMicLevel; + } + + return 0; } // ---------------------------------------------------------------------------- // RequestPlayoutData // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::RequestPlayoutData(size_t nSamples) -{ - uint32_t playSampleRate = 0; - size_t playBytesPerSample = 0; - size_t playChannels = 0; - { - CriticalSectionScoped lock(&_critSect); +int32_t AudioDeviceBuffer::RequestPlayoutData(size_t nSamples) { + uint32_t playSampleRate = 0; + size_t playBytesPerSample = 0; + size_t playChannels = 0; + { + CriticalSectionScoped lock(&_critSect); - // Store copies under lock and use copies hereafter to avoid race with - // setter methods. - playSampleRate = _playSampleRate; - playBytesPerSample = _playBytesPerSample; - playChannels = _playChannels; + // Store copies under lock and use copies hereafter to avoid race with + // setter methods. + playSampleRate = _playSampleRate; + playBytesPerSample = _playBytesPerSample; + playChannels = _playChannels; - // Ensure that user has initialized all essential members - if ((playBytesPerSample == 0) || - (playChannels == 0) || - (playSampleRate == 0)) - { - assert(false); - return -1; - } - - _playSamples = nSamples; - _playSize = playBytesPerSample * nSamples; // {2,4}*nSamples - if (_playSize > kMaxBufferSizeBytes) - { - assert(false); - return -1; - } - - if (nSamples != _playSamples) - { - WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "invalid number of samples to be played out (%d)", nSamples); - return -1; - } + // Ensure that user has initialized all essential members + if ((playBytesPerSample == 0) || (playChannels == 0) || + (playSampleRate == 0)) { + assert(false); + return -1; } - size_t nSamplesOut(0); - - CriticalSectionScoped lock(&_critSectCb); - - if (_ptrCbAudioTransport == NULL) - { - WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, "failed to feed data to playout (AudioTransport does not exist)"); - return 0; + _playSamples = nSamples; + _playSize = playBytesPerSample * nSamples; // {2,4}*nSamples + if (_playSize > kMaxBufferSizeBytes) { + assert(false); + return -1; } - if (_ptrCbAudioTransport) - { - uint32_t res(0); - int64_t elapsed_time_ms = -1; - int64_t ntp_time_ms = -1; - res = _ptrCbAudioTransport->NeedMorePlayData(_playSamples, - playBytesPerSample, - playChannels, - playSampleRate, - &_playBuffer[0], - nSamplesOut, - &elapsed_time_ms, - &ntp_time_ms); - if (res != 0) - { - WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, "NeedMorePlayData() failed"); - } + if (nSamples != _playSamples) { + WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, + "invalid number of samples to be played out (%d)", nSamples); + return -1; } + } - return static_cast(nSamplesOut); + size_t nSamplesOut(0); + + CriticalSectionScoped lock(&_critSectCb); + + if (_ptrCbAudioTransport == NULL) { + WEBRTC_TRACE( + kTraceWarning, kTraceAudioDevice, _id, + "failed to feed data to playout (AudioTransport does not exist)"); + return 0; + } + + if (_ptrCbAudioTransport) { + uint32_t res(0); + int64_t elapsed_time_ms = -1; + int64_t ntp_time_ms = -1; + res = _ptrCbAudioTransport->NeedMorePlayData( + _playSamples, playBytesPerSample, playChannels, playSampleRate, + &_playBuffer[0], nSamplesOut, &elapsed_time_ms, &ntp_time_ms); + if (res != 0) { + WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, + "NeedMorePlayData() failed"); + } + } + + return static_cast(nSamplesOut); } // ---------------------------------------------------------------------------- // GetPlayoutData // ---------------------------------------------------------------------------- -int32_t AudioDeviceBuffer::GetPlayoutData(void* audioBuffer) -{ - CriticalSectionScoped lock(&_critSect); +int32_t AudioDeviceBuffer::GetPlayoutData(void* audioBuffer) { + CriticalSectionScoped lock(&_critSect); - if (_playSize > kMaxBufferSizeBytes) - { - WEBRTC_TRACE(kTraceError, kTraceUtility, _id, - "_playSize %" PRIuS " exceeds kMaxBufferSizeBytes in " - "AudioDeviceBuffer::GetPlayoutData", _playSize); - assert(false); - return -1; - } + if (_playSize > kMaxBufferSizeBytes) { + WEBRTC_TRACE(kTraceError, kTraceUtility, _id, + "_playSize %" PRIuS + " exceeds kMaxBufferSizeBytes in " + "AudioDeviceBuffer::GetPlayoutData", + _playSize); + assert(false); + return -1; + } - memcpy(audioBuffer, &_playBuffer[0], _playSize); + memcpy(audioBuffer, &_playBuffer[0], _playSize); - if (_playFile.is_open()) { - // write to binary file in mono or stereo (interleaved) - _playFile.Write(&_playBuffer[0], _playSize); - } + if (_playFile.is_open()) { + // write to binary file in mono or stereo (interleaved) + _playFile.Write(&_playBuffer[0], _playSize); + } - return static_cast(_playSamples); + return static_cast(_playSamples); } } // namespace webrtc diff --git a/webrtc/modules/audio_device/audio_device_buffer.h b/webrtc/modules/audio_device/audio_device_buffer.h index 1095971040..11b49c1100 100644 --- a/webrtc/modules/audio_device/audio_device_buffer.h +++ b/webrtc/modules/audio_device/audio_device_buffer.h @@ -19,103 +19,95 @@ namespace webrtc { class CriticalSectionWrapper; const uint32_t kPulsePeriodMs = 1000; -const size_t kMaxBufferSizeBytes = 3840; // 10ms in stereo @ 96kHz +const size_t kMaxBufferSizeBytes = 3840; // 10ms in stereo @ 96kHz class AudioDeviceObserver; -class AudioDeviceBuffer -{ -public: - AudioDeviceBuffer(); - virtual ~AudioDeviceBuffer(); +class AudioDeviceBuffer { + public: + AudioDeviceBuffer(); + virtual ~AudioDeviceBuffer(); - void SetId(uint32_t id); - int32_t RegisterAudioCallback(AudioTransport* audioCallback); + void SetId(uint32_t id); + int32_t RegisterAudioCallback(AudioTransport* audioCallback); - int32_t InitPlayout(); - int32_t InitRecording(); + int32_t InitPlayout(); + int32_t InitRecording(); - virtual int32_t SetRecordingSampleRate(uint32_t fsHz); - virtual int32_t SetPlayoutSampleRate(uint32_t fsHz); - int32_t RecordingSampleRate() const; - int32_t PlayoutSampleRate() const; + virtual int32_t SetRecordingSampleRate(uint32_t fsHz); + virtual int32_t SetPlayoutSampleRate(uint32_t fsHz); + int32_t RecordingSampleRate() const; + int32_t PlayoutSampleRate() const; - virtual int32_t SetRecordingChannels(size_t channels); - virtual int32_t SetPlayoutChannels(size_t channels); - size_t RecordingChannels() const; - size_t PlayoutChannels() const; - int32_t SetRecordingChannel( - const AudioDeviceModule::ChannelType channel); - int32_t RecordingChannel( - AudioDeviceModule::ChannelType& channel) const; + virtual int32_t SetRecordingChannels(size_t channels); + virtual int32_t SetPlayoutChannels(size_t channels); + size_t RecordingChannels() const; + size_t PlayoutChannels() const; + int32_t SetRecordingChannel(const AudioDeviceModule::ChannelType channel); + int32_t RecordingChannel(AudioDeviceModule::ChannelType& channel) const; - virtual int32_t SetRecordedBuffer(const void* audioBuffer, - size_t nSamples); - int32_t SetCurrentMicLevel(uint32_t level); - virtual void SetVQEData(int playDelayMS, - int recDelayMS, - int clockDrift); - virtual int32_t DeliverRecordedData(); - uint32_t NewMicLevel() const; + virtual int32_t SetRecordedBuffer(const void* audioBuffer, size_t nSamples); + int32_t SetCurrentMicLevel(uint32_t level); + virtual void SetVQEData(int playDelayMS, int recDelayMS, int clockDrift); + virtual int32_t DeliverRecordedData(); + uint32_t NewMicLevel() const; - virtual int32_t RequestPlayoutData(size_t nSamples); - virtual int32_t GetPlayoutData(void* audioBuffer); + virtual int32_t RequestPlayoutData(size_t nSamples); + virtual int32_t GetPlayoutData(void* audioBuffer); - int32_t StartInputFileRecording( - const char fileName[kAdmMaxFileNameSize]); - int32_t StopInputFileRecording(); - int32_t StartOutputFileRecording( - const char fileName[kAdmMaxFileNameSize]); - int32_t StopOutputFileRecording(); + int32_t StartInputFileRecording(const char fileName[kAdmMaxFileNameSize]); + int32_t StopInputFileRecording(); + int32_t StartOutputFileRecording(const char fileName[kAdmMaxFileNameSize]); + int32_t StopOutputFileRecording(); - int32_t SetTypingStatus(bool typingStatus); + int32_t SetTypingStatus(bool typingStatus); -private: - int32_t _id; - CriticalSectionWrapper& _critSect; - CriticalSectionWrapper& _critSectCb; + private: + int32_t _id; + CriticalSectionWrapper& _critSect; + CriticalSectionWrapper& _critSectCb; - AudioTransport* _ptrCbAudioTransport; + AudioTransport* _ptrCbAudioTransport; - uint32_t _recSampleRate; - uint32_t _playSampleRate; + uint32_t _recSampleRate; + uint32_t _playSampleRate; - size_t _recChannels; - size_t _playChannels; + size_t _recChannels; + size_t _playChannels; - // selected recording channel (left/right/both) - AudioDeviceModule::ChannelType _recChannel; + // selected recording channel (left/right/both) + AudioDeviceModule::ChannelType _recChannel; - // 2 or 4 depending on mono or stereo - size_t _recBytesPerSample; - size_t _playBytesPerSample; + // 2 or 4 depending on mono or stereo + size_t _recBytesPerSample; + size_t _playBytesPerSample; - // 10ms in stereo @ 96kHz - int8_t _recBuffer[kMaxBufferSizeBytes]; + // 10ms in stereo @ 96kHz + int8_t _recBuffer[kMaxBufferSizeBytes]; - // one sample <=> 2 or 4 bytes - size_t _recSamples; - size_t _recSize; // in bytes + // one sample <=> 2 or 4 bytes + size_t _recSamples; + size_t _recSize; // in bytes - // 10ms in stereo @ 96kHz - int8_t _playBuffer[kMaxBufferSizeBytes]; + // 10ms in stereo @ 96kHz + int8_t _playBuffer[kMaxBufferSizeBytes]; - // one sample <=> 2 or 4 bytes - size_t _playSamples; - size_t _playSize; // in bytes + // one sample <=> 2 or 4 bytes + size_t _playSamples; + size_t _playSize; // in bytes - FileWrapper& _recFile; - FileWrapper& _playFile; + FileWrapper& _recFile; + FileWrapper& _playFile; - uint32_t _currentMicLevel; - uint32_t _newMicLevel; + uint32_t _currentMicLevel; + uint32_t _newMicLevel; - bool _typingStatus; + bool _typingStatus; - int _playDelayMS; - int _recDelayMS; - int _clockDrift; - int high_delay_counter_; + int _playDelayMS; + int _recDelayMS; + int _clockDrift; + int high_delay_counter_; }; } // namespace webrtc