Avoid the render lock in AudioProcessingImpl::ProcessStream
It seems unnecessary to lock it if not actually reinitializing. Bug: webrtc:10205 Change-Id: Ib3292e1d640a92a7df77400aebe9583cf877f824 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/115460 Commit-Queue: Oskar Sundbom <ossu@webrtc.org> Reviewed-by: Per Åhgren <peah@webrtc.org> Cr-Commit-Position: refs/heads/master@{#28060}
This commit is contained in:

committed by
Commit Bot

parent
a0e9943ca6
commit
4b27648d8b
@ -486,22 +486,8 @@ int AudioProcessingImpl::Initialize(const ProcessingConfig& processing_config) {
|
|||||||
|
|
||||||
int AudioProcessingImpl::MaybeInitializeRender(
|
int AudioProcessingImpl::MaybeInitializeRender(
|
||||||
const ProcessingConfig& processing_config) {
|
const ProcessingConfig& processing_config) {
|
||||||
return MaybeInitialize(processing_config, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
int AudioProcessingImpl::MaybeInitializeCapture(
|
|
||||||
const ProcessingConfig& processing_config,
|
|
||||||
bool force_initialization) {
|
|
||||||
return MaybeInitialize(processing_config, force_initialization);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calls InitializeLocked() if any of the audio parameters have changed from
|
|
||||||
// their current values (needs to be called while holding the crit_render_lock).
|
|
||||||
int AudioProcessingImpl::MaybeInitialize(
|
|
||||||
const ProcessingConfig& processing_config,
|
|
||||||
bool force_initialization) {
|
|
||||||
// Called from both threads. Thread check is therefore not possible.
|
// Called from both threads. Thread check is therefore not possible.
|
||||||
if (processing_config == formats_.api_format && !force_initialization) {
|
if (processing_config == formats_.api_format) {
|
||||||
return kNoError;
|
return kNoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -938,15 +924,23 @@ int AudioProcessingImpl::ProcessStream(const float* const* src,
|
|||||||
reinitialization_required = UpdateActiveSubmoduleStates();
|
reinitialization_required = UpdateActiveSubmoduleStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
processing_config.input_stream() = input_config;
|
if (processing_config.input_stream() != input_config) {
|
||||||
processing_config.output_stream() = output_config;
|
processing_config.input_stream() = input_config;
|
||||||
|
reinitialization_required = true;
|
||||||
{
|
|
||||||
// Do conditional reinitialization.
|
|
||||||
rtc::CritScope cs_render(&crit_render_);
|
|
||||||
RETURN_ON_ERR(
|
|
||||||
MaybeInitializeCapture(processing_config, reinitialization_required));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (processing_config.output_stream() != output_config) {
|
||||||
|
processing_config.output_stream() = output_config;
|
||||||
|
reinitialization_required = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reinitialization_required) {
|
||||||
|
// Reinitialize.
|
||||||
|
rtc::CritScope cs_render(&crit_render_);
|
||||||
|
rtc::CritScope cs_capture(&crit_capture_);
|
||||||
|
RETURN_ON_ERR(InitializeLocked(processing_config));
|
||||||
|
}
|
||||||
|
|
||||||
rtc::CritScope cs_capture(&crit_capture_);
|
rtc::CritScope cs_capture(&crit_capture_);
|
||||||
RTC_DCHECK_EQ(processing_config.input_stream().num_frames(),
|
RTC_DCHECK_EQ(processing_config.input_stream().num_frames(),
|
||||||
formats_.api_format.input_stream().num_frames());
|
formats_.api_format.input_stream().num_frames());
|
||||||
@ -1216,17 +1210,29 @@ int AudioProcessingImpl::ProcessStream(AudioFrame* frame) {
|
|||||||
|
|
||||||
reinitialization_required = UpdateActiveSubmoduleStates();
|
reinitialization_required = UpdateActiveSubmoduleStates();
|
||||||
}
|
}
|
||||||
processing_config.input_stream().set_sample_rate_hz(frame->sample_rate_hz_);
|
|
||||||
processing_config.input_stream().set_num_channels(frame->num_channels_);
|
|
||||||
processing_config.output_stream().set_sample_rate_hz(frame->sample_rate_hz_);
|
|
||||||
processing_config.output_stream().set_num_channels(frame->num_channels_);
|
|
||||||
|
|
||||||
{
|
reinitialization_required =
|
||||||
// Do conditional reinitialization.
|
reinitialization_required ||
|
||||||
|
processing_config.input_stream().sample_rate_hz() !=
|
||||||
|
frame->sample_rate_hz_ ||
|
||||||
|
processing_config.input_stream().num_channels() != frame->num_channels_ ||
|
||||||
|
processing_config.output_stream().sample_rate_hz() !=
|
||||||
|
frame->sample_rate_hz_ ||
|
||||||
|
processing_config.output_stream().num_channels() != frame->num_channels_;
|
||||||
|
|
||||||
|
if (reinitialization_required) {
|
||||||
|
processing_config.input_stream().set_sample_rate_hz(frame->sample_rate_hz_);
|
||||||
|
processing_config.input_stream().set_num_channels(frame->num_channels_);
|
||||||
|
processing_config.output_stream().set_sample_rate_hz(
|
||||||
|
frame->sample_rate_hz_);
|
||||||
|
processing_config.output_stream().set_num_channels(frame->num_channels_);
|
||||||
|
|
||||||
|
// Reinitialize.
|
||||||
rtc::CritScope cs_render(&crit_render_);
|
rtc::CritScope cs_render(&crit_render_);
|
||||||
RETURN_ON_ERR(
|
rtc::CritScope cs_capture(&crit_capture_);
|
||||||
MaybeInitializeCapture(processing_config, reinitialization_required));
|
RETURN_ON_ERR(InitializeLocked(processing_config));
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::CritScope cs_capture(&crit_capture_);
|
rtc::CritScope cs_capture(&crit_capture_);
|
||||||
if (frame->samples_per_channel_ !=
|
if (frame->samples_per_channel_ !=
|
||||||
formats_.api_format.input_stream().num_frames()) {
|
formats_.api_format.input_stream().num_frames()) {
|
||||||
|
@ -221,16 +221,9 @@ class AudioProcessingImpl : public AudioProcessing {
|
|||||||
// that the capture thread blocks the render thread.
|
// that the capture thread blocks the render thread.
|
||||||
// The struct is modified in a single-threaded manner by holding both the
|
// The struct is modified in a single-threaded manner by holding both the
|
||||||
// render and capture locks.
|
// render and capture locks.
|
||||||
int MaybeInitialize(const ProcessingConfig& config, bool force_initialization)
|
|
||||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
|
|
||||||
|
|
||||||
int MaybeInitializeRender(const ProcessingConfig& processing_config)
|
int MaybeInitializeRender(const ProcessingConfig& processing_config)
|
||||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
|
||||||
|
|
||||||
int MaybeInitializeCapture(const ProcessingConfig& processing_config,
|
|
||||||
bool force_initialization)
|
|
||||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_);
|
|
||||||
|
|
||||||
// Method for updating the state keeping track of the active submodules.
|
// Method for updating the state keeping track of the active submodules.
|
||||||
// Returns a bool indicating whether the state has changed.
|
// Returns a bool indicating whether the state has changed.
|
||||||
bool UpdateActiveSubmoduleStates()
|
bool UpdateActiveSubmoduleStates()
|
||||||
|
Reference in New Issue
Block a user