mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-16 15:20:42 +01:00
Remove one acquisition of capture lock in APM AudioFrame API
This brings the two ProcessStream functions closer in implementation. Additionally, the error checking that is currently done in the period of not holding the lock seems cheaper than releasing and reacquiring the capture lock. Bug: webrtc:11235 Change-Id: Ib4afc68afb419fcabbb8cf08a3a2e61d2c12acda Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/163021 Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Sam Zackrisson <saza@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30140}
This commit is contained in:
parent
2bd85ab039
commit
308bc646e0
1 changed files with 28 additions and 27 deletions
|
@ -843,9 +843,13 @@ int AudioProcessingImpl::ProcessStream(const float* const* src,
|
|||
ProcessingConfig processing_config;
|
||||
bool reinitialization_required = false;
|
||||
{
|
||||
// Acquire the capture lock in order to safely call the function
|
||||
// that retrieves the render side data. This function accesses apm
|
||||
// getters that need the capture lock held when being called.
|
||||
// Acquire the capture lock in order to:
|
||||
// - Safely call the function that retrieves the render side data. This
|
||||
// function accesses APM getters that need the capture lock held when
|
||||
// being called.
|
||||
// - Access api_format. The lock is released immediately due to the
|
||||
// conditional reinitialization.
|
||||
|
||||
rtc::CritScope cs_capture(&crit_capture_);
|
||||
EmptyQueuedRenderAudio();
|
||||
|
||||
|
@ -1101,32 +1105,30 @@ void AudioProcessingImpl::EmptyQueuedRenderAudio() {
|
|||
|
||||
int AudioProcessingImpl::ProcessStream(AudioFrame* frame) {
|
||||
TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_AudioFrame");
|
||||
{
|
||||
// Acquire the capture lock in order to safely call the function
|
||||
// that retrieves the render side data. This function accesses APM
|
||||
// getters that need the capture lock held when being called.
|
||||
rtc::CritScope cs_capture(&crit_capture_);
|
||||
EmptyQueuedRenderAudio();
|
||||
}
|
||||
|
||||
if (!frame) {
|
||||
return kNullPointerError;
|
||||
}
|
||||
// Must be a native rate.
|
||||
if (frame->sample_rate_hz_ != kSampleRate8kHz &&
|
||||
frame->sample_rate_hz_ != kSampleRate16kHz &&
|
||||
frame->sample_rate_hz_ != kSampleRate32kHz &&
|
||||
frame->sample_rate_hz_ != kSampleRate48kHz) {
|
||||
return kBadSampleRateError;
|
||||
}
|
||||
|
||||
ProcessingConfig processing_config;
|
||||
bool reinitialization_required = false;
|
||||
{
|
||||
// Aquire lock for the access of api_format.
|
||||
// The lock is released immediately due to the conditional
|
||||
// reinitialization.
|
||||
// Acquire the capture lock in order to:
|
||||
// - Safely call the function that retrieves the render side data. This
|
||||
// function accesses APM getters that need the capture lock held when
|
||||
// being called.
|
||||
// - Access api_format. The lock is released immediately due to the
|
||||
// conditional reinitialization.
|
||||
rtc::CritScope cs_capture(&crit_capture_);
|
||||
EmptyQueuedRenderAudio();
|
||||
|
||||
if (!frame) {
|
||||
return kNullPointerError;
|
||||
}
|
||||
// Must be a native rate.
|
||||
if (frame->sample_rate_hz_ != kSampleRate8kHz &&
|
||||
frame->sample_rate_hz_ != kSampleRate16kHz &&
|
||||
frame->sample_rate_hz_ != kSampleRate32kHz &&
|
||||
frame->sample_rate_hz_ != kSampleRate48kHz) {
|
||||
return kBadSampleRateError;
|
||||
}
|
||||
|
||||
// TODO(ajm): The input and output rates and channels are currently
|
||||
// constrained to be identical in the int16 interface.
|
||||
processing_config = formats_.api_format;
|
||||
|
@ -1198,9 +1200,8 @@ int AudioProcessingImpl::ProcessCaptureStreamLocked() {
|
|||
// Ensure that not both the AEC and AECM are active at the same time.
|
||||
// TODO(peah): Simplify once the public API Enable functions for these
|
||||
// are moved to APM.
|
||||
RTC_DCHECK_LE(!!submodules_.echo_controller +
|
||||
!!submodules_.echo_control_mobile,
|
||||
1);
|
||||
RTC_DCHECK_LE(
|
||||
!!submodules_.echo_controller + !!submodules_.echo_control_mobile, 1);
|
||||
|
||||
AudioBuffer* capture_buffer = capture_.capture_audio.get(); // For brevity.
|
||||
AudioBuffer* linear_aec_buffer = capture_.linear_aec_output.get();
|
||||
|
|
Loading…
Reference in a new issue