Delete rtc_base/atomic_ops.h
Bug: webrtc:9305 Change-Id: I3e8b0db03b84b5361d63db31ee23e6db3deabfe4 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/266497 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#37348}
This commit is contained in:
parent
3e8a797b2e
commit
7a66900683
@ -159,7 +159,6 @@ rtc_library("rtc_simulcast_encoder_adapter") {
|
|||||||
"../common_video",
|
"../common_video",
|
||||||
"../modules/video_coding:video_codec_interface",
|
"../modules/video_coding:video_codec_interface",
|
||||||
"../modules/video_coding:video_coding_utility",
|
"../modules/video_coding:video_coding_utility",
|
||||||
"../rtc_base:atomicops",
|
|
||||||
"../rtc_base:checks",
|
"../rtc_base:checks",
|
||||||
"../rtc_base:logging",
|
"../rtc_base:logging",
|
||||||
"../rtc_base/experiments:encoder_info_settings",
|
"../rtc_base/experiments:encoder_info_settings",
|
||||||
|
|||||||
@ -30,7 +30,6 @@
|
|||||||
#include "media/base/video_common.h"
|
#include "media/base/video_common.h"
|
||||||
#include "modules/video_coding/include/video_error_codes.h"
|
#include "modules/video_coding/include/video_error_codes.h"
|
||||||
#include "modules/video_coding/utility/simulcast_rate_allocator.h"
|
#include "modules/video_coding/utility/simulcast_rate_allocator.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/experiments/rate_control_settings.h"
|
#include "rtc_base/experiments/rate_control_settings.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
@ -294,7 +293,7 @@ int SimulcastEncoderAdapter::Release() {
|
|||||||
// It's legal to move the encoder to another queue now.
|
// It's legal to move the encoder to another queue now.
|
||||||
encoder_queue_.Detach();
|
encoder_queue_.Detach();
|
||||||
|
|
||||||
rtc::AtomicOps::ReleaseStore(&inited_, 0);
|
inited_.store(0);
|
||||||
|
|
||||||
return WEBRTC_VIDEO_CODEC_OK;
|
return WEBRTC_VIDEO_CODEC_OK;
|
||||||
}
|
}
|
||||||
@ -368,7 +367,7 @@ int SimulcastEncoderAdapter::InitEncode(
|
|||||||
bypass_mode_ = true;
|
bypass_mode_ = true;
|
||||||
|
|
||||||
DestroyStoredEncoders();
|
DestroyStoredEncoders();
|
||||||
rtc::AtomicOps::ReleaseStore(&inited_, 1);
|
inited_.store(1);
|
||||||
return WEBRTC_VIDEO_CODEC_OK;
|
return WEBRTC_VIDEO_CODEC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,7 +423,7 @@ int SimulcastEncoderAdapter::InitEncode(
|
|||||||
// To save memory, don't store encoders that we don't use.
|
// To save memory, don't store encoders that we don't use.
|
||||||
DestroyStoredEncoders();
|
DestroyStoredEncoders();
|
||||||
|
|
||||||
rtc::AtomicOps::ReleaseStore(&inited_, 1);
|
inited_.store(1);
|
||||||
return WEBRTC_VIDEO_CODEC_OK;
|
return WEBRTC_VIDEO_CODEC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -678,7 +677,7 @@ void SimulcastEncoderAdapter::OnDroppedFrame(size_t stream_idx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SimulcastEncoderAdapter::Initialized() const {
|
bool SimulcastEncoderAdapter::Initialized() const {
|
||||||
return rtc::AtomicOps::AcquireLoad(&inited_) == 1;
|
return inited_.load() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulcastEncoderAdapter::DestroyStoredEncoders() {
|
void SimulcastEncoderAdapter::DestroyStoredEncoders() {
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
#ifndef MEDIA_ENGINE_SIMULCAST_ENCODER_ADAPTER_H_
|
#ifndef MEDIA_ENGINE_SIMULCAST_ENCODER_ADAPTER_H_
|
||||||
#define MEDIA_ENGINE_SIMULCAST_ENCODER_ADAPTER_H_
|
#define MEDIA_ENGINE_SIMULCAST_ENCODER_ADAPTER_H_
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
@ -27,7 +28,6 @@
|
|||||||
#include "api/video_codecs/video_encoder_factory.h"
|
#include "api/video_codecs/video_encoder_factory.h"
|
||||||
#include "common_video/framerate_controller.h"
|
#include "common_video/framerate_controller.h"
|
||||||
#include "modules/video_coding/include/video_codec_interface.h"
|
#include "modules/video_coding/include/video_codec_interface.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/experiments/encoder_info_settings.h"
|
#include "rtc_base/experiments/encoder_info_settings.h"
|
||||||
#include "rtc_base/system/no_unique_address.h"
|
#include "rtc_base/system/no_unique_address.h"
|
||||||
#include "rtc_base/system/rtc_export.h"
|
#include "rtc_base/system/rtc_export.h"
|
||||||
@ -167,7 +167,7 @@ class RTC_EXPORT SimulcastEncoderAdapter : public VideoEncoder {
|
|||||||
|
|
||||||
void OverrideFromFieldTrial(VideoEncoder::EncoderInfo* info) const;
|
void OverrideFromFieldTrial(VideoEncoder::EncoderInfo* info) const;
|
||||||
|
|
||||||
volatile int inited_; // Accessed atomically.
|
std::atomic<int> inited_;
|
||||||
VideoEncoderFactory* const primary_encoder_factory_;
|
VideoEncoderFactory* const primary_encoder_factory_;
|
||||||
VideoEncoderFactory* const fallback_encoder_factory_;
|
VideoEncoderFactory* const fallback_encoder_factory_;
|
||||||
const SdpVideoFormat video_format_;
|
const SdpVideoFormat video_format_;
|
||||||
|
|||||||
@ -128,7 +128,6 @@ rtc_library("gain_controller2") {
|
|||||||
":audio_buffer",
|
":audio_buffer",
|
||||||
":audio_frame_view",
|
":audio_frame_view",
|
||||||
"../../common_audio",
|
"../../common_audio",
|
||||||
"../../rtc_base:atomicops",
|
|
||||||
"../../rtc_base:checks",
|
"../../rtc_base:checks",
|
||||||
"../../rtc_base:logging",
|
"../../rtc_base:logging",
|
||||||
"../../rtc_base:stringutils",
|
"../../rtc_base:stringutils",
|
||||||
@ -177,7 +176,6 @@ rtc_library("audio_processing") {
|
|||||||
"../../audio/utility:audio_frame_operations",
|
"../../audio/utility:audio_frame_operations",
|
||||||
"../../common_audio:common_audio_c",
|
"../../common_audio:common_audio_c",
|
||||||
"../../common_audio/third_party/ooura:fft_size_256",
|
"../../common_audio/third_party/ooura:fft_size_256",
|
||||||
"../../rtc_base:atomicops",
|
|
||||||
"../../rtc_base:checks",
|
"../../rtc_base:checks",
|
||||||
"../../rtc_base:event_tracer",
|
"../../rtc_base:event_tracer",
|
||||||
"../../rtc_base:gtest_prod",
|
"../../rtc_base:gtest_prod",
|
||||||
@ -244,7 +242,6 @@ rtc_library("residual_echo_detector") {
|
|||||||
":api",
|
":api",
|
||||||
":apm_logging",
|
":apm_logging",
|
||||||
"../../api:array_view",
|
"../../api:array_view",
|
||||||
"../../rtc_base:atomicops",
|
|
||||||
"../../rtc_base:checks",
|
"../../rtc_base:checks",
|
||||||
"../../rtc_base:logging",
|
"../../rtc_base:logging",
|
||||||
"../../system_wrappers:metrics",
|
"../../system_wrappers:metrics",
|
||||||
@ -488,7 +485,6 @@ if (rtc_include_tests) {
|
|||||||
":audio_processing",
|
":audio_processing",
|
||||||
":audioproc_test_utils",
|
":audioproc_test_utils",
|
||||||
"../../api:array_view",
|
"../../api:array_view",
|
||||||
"../../rtc_base:atomicops",
|
|
||||||
"../../rtc_base:platform_thread",
|
"../../rtc_base:platform_thread",
|
||||||
"../../rtc_base:protobuf_utils",
|
"../../rtc_base:protobuf_utils",
|
||||||
"../../rtc_base:random",
|
"../../rtc_base:random",
|
||||||
|
|||||||
@ -144,7 +144,6 @@ rtc_library("aec3") {
|
|||||||
"../../../api/audio:aec3_config",
|
"../../../api/audio:aec3_config",
|
||||||
"../../../api/audio:echo_control",
|
"../../../api/audio:echo_control",
|
||||||
"../../../common_audio:common_audio_c",
|
"../../../common_audio:common_audio_c",
|
||||||
"../../../rtc_base:atomicops",
|
|
||||||
"../../../rtc_base:checks",
|
"../../../rtc_base:checks",
|
||||||
"../../../rtc_base:logging",
|
"../../../rtc_base:logging",
|
||||||
"../../../rtc_base:macromagic",
|
"../../../rtc_base:macromagic",
|
||||||
|
|||||||
@ -20,7 +20,6 @@
|
|||||||
#include "api/array_view.h"
|
#include "api/array_view.h"
|
||||||
#include "modules/audio_processing/aec3/aec3_common.h"
|
#include "modules/audio_processing/aec3/aec3_common.h"
|
||||||
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "system_wrappers/include/field_trial.h"
|
#include "system_wrappers/include/field_trial.h"
|
||||||
|
|
||||||
@ -97,7 +96,7 @@ void ComputeAvgRenderReverb(
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int AecState::instance_count_ = 0;
|
std::atomic<int> AecState::instance_count_(0);
|
||||||
|
|
||||||
void AecState::GetResidualEchoScaling(
|
void AecState::GetResidualEchoScaling(
|
||||||
rtc::ArrayView<float> residual_scaling) const {
|
rtc::ArrayView<float> residual_scaling) const {
|
||||||
@ -115,8 +114,7 @@ void AecState::GetResidualEchoScaling(
|
|||||||
|
|
||||||
AecState::AecState(const EchoCanceller3Config& config,
|
AecState::AecState(const EchoCanceller3Config& config,
|
||||||
size_t num_capture_channels)
|
size_t num_capture_channels)
|
||||||
: data_dumper_(
|
: data_dumper_(new ApmDataDumper(instance_count_.fetch_add(1) + 1)),
|
||||||
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))),
|
|
||||||
config_(config),
|
config_(config),
|
||||||
num_capture_channels_(num_capture_channels),
|
num_capture_channels_(num_capture_channels),
|
||||||
deactivate_initial_state_reset_at_echo_path_change_(
|
deactivate_initial_state_reset_at_echo_path_change_(
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -154,7 +155,7 @@ class AecState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int instance_count_;
|
static std::atomic<int> instance_count_;
|
||||||
std::unique_ptr<ApmDataDumper> data_dumper_;
|
std::unique_ptr<ApmDataDumper> data_dumper_;
|
||||||
const EchoCanceller3Config config_;
|
const EchoCanceller3Config config_;
|
||||||
const size_t num_capture_channels_;
|
const size_t num_capture_channels_;
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -26,7 +27,6 @@
|
|||||||
#include "modules/audio_processing/aec3/render_delay_buffer.h"
|
#include "modules/audio_processing/aec3/render_delay_buffer.h"
|
||||||
#include "modules/audio_processing/aec3/render_delay_controller.h"
|
#include "modules/audio_processing/aec3/render_delay_controller.h"
|
||||||
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ class BlockProcessorImpl final : public BlockProcessor {
|
|||||||
void SetCaptureOutputUsage(bool capture_output_used) override;
|
void SetCaptureOutputUsage(bool capture_output_used) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int instance_count_;
|
static std::atomic<int> instance_count_;
|
||||||
std::unique_ptr<ApmDataDumper> data_dumper_;
|
std::unique_ptr<ApmDataDumper> data_dumper_;
|
||||||
const EchoCanceller3Config config_;
|
const EchoCanceller3Config config_;
|
||||||
bool capture_properly_started_ = false;
|
bool capture_properly_started_ = false;
|
||||||
@ -79,7 +79,7 @@ class BlockProcessorImpl final : public BlockProcessor {
|
|||||||
absl::optional<DelayEstimate> estimated_delay_;
|
absl::optional<DelayEstimate> estimated_delay_;
|
||||||
};
|
};
|
||||||
|
|
||||||
int BlockProcessorImpl::instance_count_ = 0;
|
std::atomic<int> BlockProcessorImpl::instance_count_(0);
|
||||||
|
|
||||||
BlockProcessorImpl::BlockProcessorImpl(
|
BlockProcessorImpl::BlockProcessorImpl(
|
||||||
const EchoCanceller3Config& config,
|
const EchoCanceller3Config& config,
|
||||||
@ -89,8 +89,7 @@ BlockProcessorImpl::BlockProcessorImpl(
|
|||||||
std::unique_ptr<RenderDelayBuffer> render_buffer,
|
std::unique_ptr<RenderDelayBuffer> render_buffer,
|
||||||
std::unique_ptr<RenderDelayController> delay_controller,
|
std::unique_ptr<RenderDelayController> delay_controller,
|
||||||
std::unique_ptr<EchoRemover> echo_remover)
|
std::unique_ptr<EchoRemover> echo_remover)
|
||||||
: data_dumper_(
|
: data_dumper_(new ApmDataDumper(instance_count_.fetch_add(1) + 1)),
|
||||||
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))),
|
|
||||||
config_(config),
|
config_(config),
|
||||||
sample_rate_hz_(sample_rate_hz),
|
sample_rate_hz_(sample_rate_hz),
|
||||||
render_buffer_(std::move(render_buffer)),
|
render_buffer_(std::move(render_buffer)),
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
#include "modules/audio_processing/aec3/aec3_common.h"
|
#include "modules/audio_processing/aec3/aec3_common.h"
|
||||||
#include "modules/audio_processing/high_pass_filter.h"
|
#include "modules/audio_processing/high_pass_filter.h"
|
||||||
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/experiments/field_trial_parser.h"
|
#include "rtc_base/experiments/field_trial_parser.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "system_wrappers/include/field_trial.h"
|
#include "system_wrappers/include/field_trial.h"
|
||||||
@ -707,7 +706,7 @@ void EchoCanceller3::RenderWriter::Insert(const AudioBuffer& input) {
|
|||||||
static_cast<void>(render_transfer_queue_->Insert(&render_queue_input_frame_));
|
static_cast<void>(render_transfer_queue_->Insert(&render_queue_input_frame_));
|
||||||
}
|
}
|
||||||
|
|
||||||
int EchoCanceller3::instance_count_ = 0;
|
std::atomic<int> EchoCanceller3::instance_count_(0);
|
||||||
|
|
||||||
EchoCanceller3::EchoCanceller3(
|
EchoCanceller3::EchoCanceller3(
|
||||||
const EchoCanceller3Config& config,
|
const EchoCanceller3Config& config,
|
||||||
@ -715,8 +714,7 @@ EchoCanceller3::EchoCanceller3(
|
|||||||
int sample_rate_hz,
|
int sample_rate_hz,
|
||||||
size_t num_render_channels,
|
size_t num_render_channels,
|
||||||
size_t num_capture_channels)
|
size_t num_capture_channels)
|
||||||
: data_dumper_(
|
: data_dumper_(new ApmDataDumper(instance_count_.fetch_add(1) + 1)),
|
||||||
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))),
|
|
||||||
config_(AdjustConfig(config)),
|
config_(AdjustConfig(config)),
|
||||||
sample_rate_hz_(sample_rate_hz),
|
sample_rate_hz_(sample_rate_hz),
|
||||||
num_bands_(NumBandsForRate(sample_rate_hz_)),
|
num_bands_(NumBandsForRate(sample_rate_hz_)),
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -185,7 +186,7 @@ class EchoCanceller3 : public EchoControl {
|
|||||||
RTC_GUARDED_BY(render_race_checker_);
|
RTC_GUARDED_BY(render_race_checker_);
|
||||||
|
|
||||||
// State that may be accessed by the capture thread.
|
// State that may be accessed by the capture thread.
|
||||||
static int instance_count_;
|
static std::atomic<int> instance_count_;
|
||||||
std::unique_ptr<ApmDataDumper> data_dumper_;
|
std::unique_ptr<ApmDataDumper> data_dumper_;
|
||||||
const EchoCanceller3Config config_;
|
const EchoCanceller3Config config_;
|
||||||
const int sample_rate_hz_;
|
const int sample_rate_hz_;
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <atomic>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@ -33,7 +34,6 @@
|
|||||||
#include "modules/audio_processing/aec3/suppression_filter.h"
|
#include "modules/audio_processing/aec3/suppression_filter.h"
|
||||||
#include "modules/audio_processing/aec3/suppression_gain.h"
|
#include "modules/audio_processing/aec3/suppression_gain.h"
|
||||||
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ class EchoRemoverImpl final : public EchoRemover {
|
|||||||
void FormLinearFilterOutput(const SubtractorOutput& subtractor_output,
|
void FormLinearFilterOutput(const SubtractorOutput& subtractor_output,
|
||||||
rtc::ArrayView<float> output);
|
rtc::ArrayView<float> output);
|
||||||
|
|
||||||
static int instance_count_;
|
static std::atomic<int> instance_count_;
|
||||||
const EchoCanceller3Config config_;
|
const EchoCanceller3Config config_;
|
||||||
const Aec3Fft fft_;
|
const Aec3Fft fft_;
|
||||||
std::unique_ptr<ApmDataDumper> data_dumper_;
|
std::unique_ptr<ApmDataDumper> data_dumper_;
|
||||||
@ -180,7 +180,7 @@ class EchoRemoverImpl final : public EchoRemover {
|
|||||||
std::vector<SubtractorOutput> subtractor_output_heap_;
|
std::vector<SubtractorOutput> subtractor_output_heap_;
|
||||||
};
|
};
|
||||||
|
|
||||||
int EchoRemoverImpl::instance_count_ = 0;
|
std::atomic<int> EchoRemoverImpl::instance_count_(0);
|
||||||
|
|
||||||
EchoRemoverImpl::EchoRemoverImpl(const EchoCanceller3Config& config,
|
EchoRemoverImpl::EchoRemoverImpl(const EchoCanceller3Config& config,
|
||||||
int sample_rate_hz,
|
int sample_rate_hz,
|
||||||
@ -188,8 +188,7 @@ EchoRemoverImpl::EchoRemoverImpl(const EchoCanceller3Config& config,
|
|||||||
size_t num_capture_channels)
|
size_t num_capture_channels)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
fft_(),
|
fft_(),
|
||||||
data_dumper_(
|
data_dumper_(new ApmDataDumper(instance_count_.fetch_add(1) + 1)),
|
||||||
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))),
|
|
||||||
optimization_(DetectOptimization()),
|
optimization_(DetectOptimization()),
|
||||||
sample_rate_hz_(sample_rate_hz),
|
sample_rate_hz_(sample_rate_hz),
|
||||||
num_render_channels_(num_render_channels),
|
num_render_channels_(num_render_channels),
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
#include "modules/audio_processing/aec3/aec3_common.h"
|
#include "modules/audio_processing/aec3/aec3_common.h"
|
||||||
#include "modules/audio_processing/aec3/render_buffer.h"
|
#include "modules/audio_processing/aec3/render_buffer.h"
|
||||||
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
@ -45,12 +44,11 @@ size_t FindPeakIndex(rtc::ArrayView<const float> filter_time_domain,
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int FilterAnalyzer::instance_count_ = 0;
|
std::atomic<int> FilterAnalyzer::instance_count_(0);
|
||||||
|
|
||||||
FilterAnalyzer::FilterAnalyzer(const EchoCanceller3Config& config,
|
FilterAnalyzer::FilterAnalyzer(const EchoCanceller3Config& config,
|
||||||
size_t num_capture_channels)
|
size_t num_capture_channels)
|
||||||
: data_dumper_(
|
: data_dumper_(new ApmDataDumper(instance_count_.fetch_add(1) + 1)),
|
||||||
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))),
|
|
||||||
bounded_erl_(config.ep_strength.bounded_erl),
|
bounded_erl_(config.ep_strength.bounded_erl),
|
||||||
default_gain_(config.ep_strength.default_gain),
|
default_gain_(config.ep_strength.default_gain),
|
||||||
h_highpass_(num_capture_channels,
|
h_highpass_(num_capture_channels,
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -129,7 +130,7 @@ class FilterAnalyzer {
|
|||||||
ConsistentFilterDetector consistent_filter_detector;
|
ConsistentFilterDetector consistent_filter_detector;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int instance_count_;
|
static std::atomic<int> instance_count_;
|
||||||
std::unique_ptr<ApmDataDumper> data_dumper_;
|
std::unique_ptr<ApmDataDumper> data_dumper_;
|
||||||
const bool bounded_erl_;
|
const bool bounded_erl_;
|
||||||
const float default_gain_;
|
const float default_gain_;
|
||||||
|
|||||||
@ -20,7 +20,6 @@
|
|||||||
#include "modules/audio_processing/aec3/render_signal_analyzer.h"
|
#include "modules/audio_processing/aec3/render_signal_analyzer.h"
|
||||||
#include "modules/audio_processing/aec3/subtractor_output.h"
|
#include "modules/audio_processing/aec3/subtractor_output.h"
|
||||||
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
@ -31,13 +30,12 @@ constexpr int kPoorExcitationCounterInitial = 1000;
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int RefinedFilterUpdateGain::instance_count_ = 0;
|
std::atomic<int> RefinedFilterUpdateGain::instance_count_(0);
|
||||||
|
|
||||||
RefinedFilterUpdateGain::RefinedFilterUpdateGain(
|
RefinedFilterUpdateGain::RefinedFilterUpdateGain(
|
||||||
const EchoCanceller3Config::Filter::RefinedConfiguration& config,
|
const EchoCanceller3Config::Filter::RefinedConfiguration& config,
|
||||||
size_t config_change_duration_blocks)
|
size_t config_change_duration_blocks)
|
||||||
: data_dumper_(
|
: data_dumper_(new ApmDataDumper(instance_count_.fetch_add(1) + 1)),
|
||||||
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))),
|
|
||||||
config_change_duration_blocks_(
|
config_change_duration_blocks_(
|
||||||
static_cast<int>(config_change_duration_blocks)),
|
static_cast<int>(config_change_duration_blocks)),
|
||||||
poor_excitation_counter_(kPoorExcitationCounterInitial) {
|
poor_excitation_counter_(kPoorExcitationCounterInitial) {
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "api/array_view.h"
|
#include "api/array_view.h"
|
||||||
@ -69,7 +70,7 @@ class RefinedFilterUpdateGain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int instance_count_;
|
static std::atomic<int> instance_count_;
|
||||||
std::unique_ptr<ApmDataDumper> data_dumper_;
|
std::unique_ptr<ApmDataDumper> data_dumper_;
|
||||||
const int config_change_duration_blocks_;
|
const int config_change_duration_blocks_;
|
||||||
float one_by_config_change_duration_blocks_;
|
float one_by_config_change_duration_blocks_;
|
||||||
|
|||||||
@ -32,7 +32,6 @@
|
|||||||
#include "modules/audio_processing/aec3/render_buffer.h"
|
#include "modules/audio_processing/aec3/render_buffer.h"
|
||||||
#include "modules/audio_processing/aec3/spectrum_buffer.h"
|
#include "modules/audio_processing/aec3/spectrum_buffer.h"
|
||||||
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "system_wrappers/include/field_trial.h"
|
#include "system_wrappers/include/field_trial.h"
|
||||||
@ -74,7 +73,7 @@ class RenderDelayBufferImpl final : public RenderDelayBuffer {
|
|||||||
bool HasReceivedBufferDelay() override;
|
bool HasReceivedBufferDelay() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int instance_count_;
|
static std::atomic<int> instance_count_;
|
||||||
std::unique_ptr<ApmDataDumper> data_dumper_;
|
std::unique_ptr<ApmDataDumper> data_dumper_;
|
||||||
const Aec3Optimization optimization_;
|
const Aec3Optimization optimization_;
|
||||||
const EchoCanceller3Config config_;
|
const EchoCanceller3Config config_;
|
||||||
@ -119,13 +118,12 @@ class RenderDelayBufferImpl final : public RenderDelayBuffer {
|
|||||||
bool RenderUnderrun();
|
bool RenderUnderrun();
|
||||||
};
|
};
|
||||||
|
|
||||||
int RenderDelayBufferImpl::instance_count_ = 0;
|
std::atomic<int> RenderDelayBufferImpl::instance_count_ = 0;
|
||||||
|
|
||||||
RenderDelayBufferImpl::RenderDelayBufferImpl(const EchoCanceller3Config& config,
|
RenderDelayBufferImpl::RenderDelayBufferImpl(const EchoCanceller3Config& config,
|
||||||
int sample_rate_hz,
|
int sample_rate_hz,
|
||||||
size_t num_render_channels)
|
size_t num_render_channels)
|
||||||
: data_dumper_(
|
: data_dumper_(new ApmDataDumper(instance_count_.fetch_add(1) + 1)),
|
||||||
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))),
|
|
||||||
optimization_(DetectOptimization()),
|
optimization_(DetectOptimization()),
|
||||||
config_(config),
|
config_(config),
|
||||||
update_capture_call_counter_on_skipped_blocks_(
|
update_capture_call_counter_on_skipped_blocks_(
|
||||||
|
|||||||
@ -23,7 +23,6 @@
|
|||||||
#include "modules/audio_processing/aec3/echo_path_delay_estimator.h"
|
#include "modules/audio_processing/aec3/echo_path_delay_estimator.h"
|
||||||
#include "modules/audio_processing/aec3/render_delay_controller_metrics.h"
|
#include "modules/audio_processing/aec3/render_delay_controller_metrics.h"
|
||||||
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
@ -51,7 +50,7 @@ class RenderDelayControllerImpl final : public RenderDelayController {
|
|||||||
bool HasClockdrift() const override;
|
bool HasClockdrift() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int instance_count_;
|
static std::atomic<int> instance_count_;
|
||||||
std::unique_ptr<ApmDataDumper> data_dumper_;
|
std::unique_ptr<ApmDataDumper> data_dumper_;
|
||||||
const int hysteresis_limit_blocks_;
|
const int hysteresis_limit_blocks_;
|
||||||
const int delay_headroom_samples_;
|
const int delay_headroom_samples_;
|
||||||
@ -90,14 +89,13 @@ DelayEstimate ComputeBufferDelay(
|
|||||||
return new_delay;
|
return new_delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RenderDelayControllerImpl::instance_count_ = 0;
|
std::atomic<int> RenderDelayControllerImpl::instance_count_(0);
|
||||||
|
|
||||||
RenderDelayControllerImpl::RenderDelayControllerImpl(
|
RenderDelayControllerImpl::RenderDelayControllerImpl(
|
||||||
const EchoCanceller3Config& config,
|
const EchoCanceller3Config& config,
|
||||||
int sample_rate_hz,
|
int sample_rate_hz,
|
||||||
size_t num_capture_channels)
|
size_t num_capture_channels)
|
||||||
: data_dumper_(
|
: data_dumper_(new ApmDataDumper(instance_count_.fetch_add(1) + 1)),
|
||||||
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))),
|
|
||||||
hysteresis_limit_blocks_(
|
hysteresis_limit_blocks_(
|
||||||
static_cast<int>(config.delay.hysteresis_limit_blocks)),
|
static_cast<int>(config.delay.hysteresis_limit_blocks)),
|
||||||
delay_headroom_samples_(config.delay.delay_headroom_samples),
|
delay_headroom_samples_(config.delay.delay_headroom_samples),
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
#include "modules/audio_processing/aec3/aec3_common.h"
|
#include "modules/audio_processing/aec3/aec3_common.h"
|
||||||
#include "modules/audio_processing/aec3/spectrum_buffer.h"
|
#include "modules/audio_processing/aec3/spectrum_buffer.h"
|
||||||
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
@ -29,8 +28,7 @@ constexpr int kNBlocksInitialPhase = kNumBlocksPerSecond * 2.;
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
StationarityEstimator::StationarityEstimator()
|
StationarityEstimator::StationarityEstimator()
|
||||||
: data_dumper_(
|
: data_dumper_(new ApmDataDumper(instance_count_.fetch_add(1) + 1)) {
|
||||||
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))) {
|
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +151,7 @@ void StationarityEstimator::SmoothStationaryPerFreq() {
|
|||||||
stationarity_flags_ = all_ahead_stationary_smooth;
|
stationarity_flags_ = all_ahead_stationary_smooth;
|
||||||
}
|
}
|
||||||
|
|
||||||
int StationarityEstimator::instance_count_ = 0;
|
std::atomic<int> StationarityEstimator::instance_count_(0);
|
||||||
|
|
||||||
StationarityEstimator::NoiseSpectrum::NoiseSpectrum() {
|
StationarityEstimator::NoiseSpectrum::NoiseSpectrum() {
|
||||||
Reset();
|
Reset();
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "api/array_view.h"
|
#include "api/array_view.h"
|
||||||
@ -110,7 +111,7 @@ class StationarityEstimator {
|
|||||||
size_t block_counter_;
|
size_t block_counter_;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int instance_count_;
|
static std::atomic<int> instance_count_;
|
||||||
std::unique_ptr<ApmDataDumper> data_dumper_;
|
std::unique_ptr<ApmDataDumper> data_dumper_;
|
||||||
NoiseSpectrum noise_;
|
NoiseSpectrum noise_;
|
||||||
std::array<int, kFftLengthBy2Plus1> hangovers_;
|
std::array<int, kFftLengthBy2Plus1> hangovers_;
|
||||||
|
|||||||
@ -21,7 +21,6 @@
|
|||||||
#include "modules/audio_processing/aec3/subband_nearend_detector.h"
|
#include "modules/audio_processing/aec3/subband_nearend_detector.h"
|
||||||
#include "modules/audio_processing/aec3/vector_math.h"
|
#include "modules/audio_processing/aec3/vector_math.h"
|
||||||
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "system_wrappers/include/field_trial.h"
|
#include "system_wrappers/include/field_trial.h"
|
||||||
|
|
||||||
@ -102,7 +101,7 @@ void WeightEchoForAudibility(const EchoCanceller3Config& config,
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int SuppressionGain::instance_count_ = 0;
|
std::atomic<int> SuppressionGain::instance_count_(0);
|
||||||
|
|
||||||
float SuppressionGain::UpperBandsGain(
|
float SuppressionGain::UpperBandsGain(
|
||||||
rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> echo_spectrum,
|
rtc::ArrayView<const std::array<float, kFftLengthBy2Plus1>> echo_spectrum,
|
||||||
@ -326,8 +325,7 @@ SuppressionGain::SuppressionGain(const EchoCanceller3Config& config,
|
|||||||
Aec3Optimization optimization,
|
Aec3Optimization optimization,
|
||||||
int sample_rate_hz,
|
int sample_rate_hz,
|
||||||
size_t num_capture_channels)
|
size_t num_capture_channels)
|
||||||
: data_dumper_(
|
: data_dumper_(new ApmDataDumper(instance_count_.fetch_add(1) + 1)),
|
||||||
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))),
|
|
||||||
optimization_(optimization),
|
optimization_(optimization),
|
||||||
config_(config),
|
config_(config),
|
||||||
num_capture_channels_(num_capture_channels),
|
num_capture_channels_(num_capture_channels),
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
#define MODULES_AUDIO_PROCESSING_AEC3_SUPPRESSION_GAIN_H_
|
#define MODULES_AUDIO_PROCESSING_AEC3_SUPPRESSION_GAIN_H_
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -118,7 +119,7 @@ class SuppressionGain {
|
|||||||
std::array<float, kFftLengthBy2Plus1> emr_transparent_;
|
std::array<float, kFftLengthBy2Plus1> emr_transparent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int instance_count_;
|
static std::atomic<int> instance_count_;
|
||||||
std::unique_ptr<ApmDataDumper> data_dumper_;
|
std::unique_ptr<ApmDataDumper> data_dumper_;
|
||||||
const Aec3Optimization optimization_;
|
const Aec3Optimization optimization_;
|
||||||
const EchoCanceller3Config config_;
|
const EchoCanceller3Config config_;
|
||||||
|
|||||||
@ -30,7 +30,6 @@ rtc_library("agc") {
|
|||||||
"../../../api:array_view",
|
"../../../api:array_view",
|
||||||
"../../../common_audio",
|
"../../../common_audio",
|
||||||
"../../../common_audio:common_audio_c",
|
"../../../common_audio:common_audio_c",
|
||||||
"../../../rtc_base:atomicops",
|
|
||||||
"../../../rtc_base:checks",
|
"../../../rtc_base:checks",
|
||||||
"../../../rtc_base:gtest_prod",
|
"../../../rtc_base:gtest_prod",
|
||||||
"../../../rtc_base:logging",
|
"../../../rtc_base:logging",
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
#include "modules/audio_processing/agc/gain_control.h"
|
#include "modules/audio_processing/agc/gain_control.h"
|
||||||
#include "modules/audio_processing/agc/gain_map_internal.h"
|
#include "modules/audio_processing/agc/gain_map_internal.h"
|
||||||
#include "modules/audio_processing/include/audio_frame_view.h"
|
#include "modules/audio_processing/include/audio_frame_view.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/numerics/safe_minmax.h"
|
#include "rtc_base/numerics/safe_minmax.h"
|
||||||
@ -439,7 +438,7 @@ void MonoAgc::UpdateCompressor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int AgcManagerDirect::instance_counter_ = 0;
|
std::atomic<int> AgcManagerDirect::instance_counter_(0);
|
||||||
|
|
||||||
AgcManagerDirect::AgcManagerDirect(
|
AgcManagerDirect::AgcManagerDirect(
|
||||||
Agc* agc,
|
Agc* agc,
|
||||||
@ -472,8 +471,7 @@ AgcManagerDirect::AgcManagerDirect(
|
|||||||
int clipped_wait_frames,
|
int clipped_wait_frames,
|
||||||
const ClippingPredictorConfig& clipping_config)
|
const ClippingPredictorConfig& clipping_config)
|
||||||
: min_mic_level_override_(GetMinMicLevelOverride()),
|
: min_mic_level_override_(GetMinMicLevelOverride()),
|
||||||
data_dumper_(
|
data_dumper_(new ApmDataDumper(instance_counter_.fetch_add(1) + 1)),
|
||||||
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_counter_))),
|
|
||||||
use_min_channel_level_(!UseMaxAnalogChannelLevel()),
|
use_min_channel_level_(!UseMaxAnalogChannelLevel()),
|
||||||
num_capture_channels_(num_capture_channels),
|
num_capture_channels_(num_capture_channels),
|
||||||
disable_digital_adaptive_(disable_digital_adaptive),
|
disable_digital_adaptive_(disable_digital_adaptive),
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#ifndef MODULES_AUDIO_PROCESSING_AGC_AGC_MANAGER_DIRECT_H_
|
#ifndef MODULES_AUDIO_PROCESSING_AGC_AGC_MANAGER_DIRECT_H_
|
||||||
#define MODULES_AUDIO_PROCESSING_AGC_AGC_MANAGER_DIRECT_H_
|
#define MODULES_AUDIO_PROCESSING_AGC_AGC_MANAGER_DIRECT_H_
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
@ -128,7 +129,7 @@ class AgcManagerDirect final {
|
|||||||
|
|
||||||
const absl::optional<int> min_mic_level_override_;
|
const absl::optional<int> min_mic_level_override_;
|
||||||
std::unique_ptr<ApmDataDumper> data_dumper_;
|
std::unique_ptr<ApmDataDumper> data_dumper_;
|
||||||
static int instance_counter_;
|
static std::atomic<int> instance_counter_;
|
||||||
const bool use_min_channel_level_;
|
const bool use_min_channel_level_;
|
||||||
const int num_capture_channels_;
|
const int num_capture_channels_;
|
||||||
const bool disable_digital_adaptive_;
|
const bool disable_digital_adaptive_;
|
||||||
|
|||||||
@ -28,7 +28,6 @@
|
|||||||
#include "modules/audio_processing/include/audio_frame_view.h"
|
#include "modules/audio_processing/include/audio_frame_view.h"
|
||||||
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
||||||
#include "modules/audio_processing/optionally_built_submodule_creators.h"
|
#include "modules/audio_processing/optionally_built_submodule_creators.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/time_utils.h"
|
#include "rtc_base/time_utils.h"
|
||||||
@ -253,7 +252,7 @@ AudioProcessingImpl::AudioProcessingImpl()
|
|||||||
/*echo_detector=*/nullptr,
|
/*echo_detector=*/nullptr,
|
||||||
/*capture_analyzer=*/nullptr) {}
|
/*capture_analyzer=*/nullptr) {}
|
||||||
|
|
||||||
int AudioProcessingImpl::instance_count_ = 0;
|
std::atomic<int> AudioProcessingImpl::instance_count_(0);
|
||||||
|
|
||||||
AudioProcessingImpl::AudioProcessingImpl(
|
AudioProcessingImpl::AudioProcessingImpl(
|
||||||
const AudioProcessing::Config& config,
|
const AudioProcessing::Config& config,
|
||||||
@ -262,8 +261,7 @@ AudioProcessingImpl::AudioProcessingImpl(
|
|||||||
std::unique_ptr<EchoControlFactory> echo_control_factory,
|
std::unique_ptr<EchoControlFactory> echo_control_factory,
|
||||||
rtc::scoped_refptr<EchoDetector> echo_detector,
|
rtc::scoped_refptr<EchoDetector> echo_detector,
|
||||||
std::unique_ptr<CustomAudioAnalyzer> capture_analyzer)
|
std::unique_ptr<CustomAudioAnalyzer> capture_analyzer)
|
||||||
: data_dumper_(
|
: data_dumper_(new ApmDataDumper(instance_count_.fetch_add(1) + 1)),
|
||||||
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))),
|
|
||||||
use_setup_specific_default_aec3_config_(
|
use_setup_specific_default_aec3_config_(
|
||||||
UseSetupSpecificDefaultAec3Congfig()),
|
UseSetupSpecificDefaultAec3Congfig()),
|
||||||
use_denormal_disabler_(
|
use_denormal_disabler_(
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -180,7 +181,7 @@ class AudioProcessingImpl : public AudioProcessing {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const std::unique_ptr<ApmDataDumper> data_dumper_;
|
const std::unique_ptr<ApmDataDumper> data_dumper_;
|
||||||
static int instance_count_;
|
static std::atomic<int> instance_count_;
|
||||||
const bool use_setup_specific_default_aec3_config_;
|
const bool use_setup_specific_default_aec3_config_;
|
||||||
|
|
||||||
const bool use_denormal_disabler_;
|
const bool use_denormal_disabler_;
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -17,7 +18,6 @@
|
|||||||
#include "modules/audio_processing/audio_processing_impl.h"
|
#include "modules/audio_processing/audio_processing_impl.h"
|
||||||
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
|
#include "modules/audio_processing/test/audio_processing_builder_for_testing.h"
|
||||||
#include "modules/audio_processing/test/test_utils.h"
|
#include "modules/audio_processing/test/test_utils.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/event.h"
|
#include "rtc_base/event.h"
|
||||||
#include "rtc_base/numerics/safe_conversions.h"
|
#include "rtc_base/numerics/safe_conversions.h"
|
||||||
#include "rtc_base/platform_thread.h"
|
#include "rtc_base/platform_thread.h"
|
||||||
@ -134,16 +134,16 @@ struct SimulationConfig {
|
|||||||
// Handler for the frame counters.
|
// Handler for the frame counters.
|
||||||
class FrameCounters {
|
class FrameCounters {
|
||||||
public:
|
public:
|
||||||
void IncreaseRenderCounter() { rtc::AtomicOps::Increment(&render_count_); }
|
void IncreaseRenderCounter() { render_count_.fetch_add(1); }
|
||||||
|
|
||||||
void IncreaseCaptureCounter() { rtc::AtomicOps::Increment(&capture_count_); }
|
void IncreaseCaptureCounter() { capture_count_.fetch_add(1); }
|
||||||
|
|
||||||
int CaptureMinusRenderCounters() const {
|
int CaptureMinusRenderCounters() const {
|
||||||
// The return value will be approximate, but that's good enough since
|
// The return value will be approximate, but that's good enough since
|
||||||
// by the time we return the value, it's not guaranteed to be correct
|
// by the time we return the value, it's not guaranteed to be correct
|
||||||
// anyway.
|
// anyway.
|
||||||
return rtc::AtomicOps::AcquireLoad(&capture_count_) -
|
return capture_count_.load(std::memory_order_acquire) -
|
||||||
rtc::AtomicOps::AcquireLoad(&render_count_);
|
render_count_.load(std::memory_order_acquire);
|
||||||
}
|
}
|
||||||
|
|
||||||
int RenderMinusCaptureCounters() const {
|
int RenderMinusCaptureCounters() const {
|
||||||
@ -153,28 +153,31 @@ class FrameCounters {
|
|||||||
bool BothCountersExceedeThreshold(int threshold) const {
|
bool BothCountersExceedeThreshold(int threshold) const {
|
||||||
// TODO(tommi): We could use an event to signal this so that we don't need
|
// TODO(tommi): We could use an event to signal this so that we don't need
|
||||||
// to be polling from the main thread and possibly steal cycles.
|
// to be polling from the main thread and possibly steal cycles.
|
||||||
const int capture_count = rtc::AtomicOps::AcquireLoad(&capture_count_);
|
const int capture_count = capture_count_.load(std::memory_order_acquire);
|
||||||
const int render_count = rtc::AtomicOps::AcquireLoad(&render_count_);
|
const int render_count = render_count_.load(std::memory_order_acquire);
|
||||||
return (render_count > threshold && capture_count > threshold);
|
return (render_count > threshold && capture_count > threshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int render_count_ = 0;
|
std::atomic<int> render_count_{0};
|
||||||
int capture_count_ = 0;
|
std::atomic<int> capture_count_{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class that represents a flag that can only be raised.
|
// Class that represents a flag that can only be raised.
|
||||||
class LockedFlag {
|
class LockedFlag {
|
||||||
public:
|
public:
|
||||||
bool get_flag() const { return rtc::AtomicOps::AcquireLoad(&flag_); }
|
bool get_flag() const { return flag_.load(std::memory_order_acquire); }
|
||||||
|
|
||||||
void set_flag() {
|
void set_flag() {
|
||||||
if (!get_flag()) // read-only operation to avoid affecting the cache-line.
|
if (!get_flag()) {
|
||||||
rtc::AtomicOps::CompareAndSwap(&flag_, 0, 1);
|
// read-only operation to avoid affecting the cache-line.
|
||||||
|
int zero = 0;
|
||||||
|
flag_.compare_exchange_strong(zero, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int flag_ = 0;
|
std::atomic<int> flag_{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parent class for the thread processors.
|
// Parent class for the thread processors.
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
#include "modules/audio_processing/audio_buffer.h"
|
#include "modules/audio_processing/audio_buffer.h"
|
||||||
#include "modules/audio_processing/include/audio_frame_view.h"
|
#include "modules/audio_processing/include/audio_frame_view.h"
|
||||||
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/strings/string_builder.h"
|
#include "rtc_base/strings/string_builder.h"
|
||||||
@ -65,14 +64,14 @@ std::unique_ptr<AdaptiveDigitalGainController> CreateAdaptiveDigitalController(
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int GainController2::instance_count_ = 0;
|
std::atomic<int> GainController2::instance_count_(0);
|
||||||
|
|
||||||
GainController2::GainController2(const Agc2Config& config,
|
GainController2::GainController2(const Agc2Config& config,
|
||||||
int sample_rate_hz,
|
int sample_rate_hz,
|
||||||
int num_channels,
|
int num_channels,
|
||||||
bool use_internal_vad)
|
bool use_internal_vad)
|
||||||
: cpu_features_(GetAllowedCpuFeatures()),
|
: cpu_features_(GetAllowedCpuFeatures()),
|
||||||
data_dumper_(rtc::AtomicOps::Increment(&instance_count_)),
|
data_dumper_(instance_count_.fetch_add(1) + 1),
|
||||||
fixed_gain_applier_(
|
fixed_gain_applier_(
|
||||||
/*hard_clip_samples=*/false,
|
/*hard_clip_samples=*/false,
|
||||||
/*initial_gain_factor=*/DbToRatio(config.fixed_digital.gain_db)),
|
/*initial_gain_factor=*/DbToRatio(config.fixed_digital.gain_db)),
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#ifndef MODULES_AUDIO_PROCESSING_GAIN_CONTROLLER2_H_
|
#ifndef MODULES_AUDIO_PROCESSING_GAIN_CONTROLLER2_H_
|
||||||
#define MODULES_AUDIO_PROCESSING_GAIN_CONTROLLER2_H_
|
#define MODULES_AUDIO_PROCESSING_GAIN_CONTROLLER2_H_
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ class GainController2 {
|
|||||||
AvailableCpuFeatures GetCpuFeatures() const { return cpu_features_; }
|
AvailableCpuFeatures GetCpuFeatures() const { return cpu_features_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int instance_count_;
|
static std::atomic<int> instance_count_;
|
||||||
const AvailableCpuFeatures cpu_features_;
|
const AvailableCpuFeatures cpu_features_;
|
||||||
ApmDataDumper data_dumper_;
|
ApmDataDumper data_dumper_;
|
||||||
GainApplier fixed_gain_applier_;
|
GainApplier fixed_gain_applier_;
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
#include "modules/audio_processing/logging/apm_data_dumper.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "system_wrappers/include/metrics.h"
|
#include "system_wrappers/include/metrics.h"
|
||||||
@ -41,11 +40,10 @@ constexpr size_t kAggregationBufferSize = 10 * 100;
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
int ResidualEchoDetector::instance_count_ = 0;
|
std::atomic<int> ResidualEchoDetector::instance_count_(0);
|
||||||
|
|
||||||
ResidualEchoDetector::ResidualEchoDetector()
|
ResidualEchoDetector::ResidualEchoDetector()
|
||||||
: data_dumper_(
|
: data_dumper_(new ApmDataDumper(instance_count_.fetch_add(1) + 1)),
|
||||||
new ApmDataDumper(rtc::AtomicOps::Increment(&instance_count_))),
|
|
||||||
render_buffer_(kRenderBufferSize),
|
render_buffer_(kRenderBufferSize),
|
||||||
render_power_(kLookbackFrames),
|
render_power_(kLookbackFrames),
|
||||||
render_power_mean_(kLookbackFrames),
|
render_power_mean_(kLookbackFrames),
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#ifndef MODULES_AUDIO_PROCESSING_RESIDUAL_ECHO_DETECTOR_H_
|
#ifndef MODULES_AUDIO_PROCESSING_RESIDUAL_ECHO_DETECTOR_H_
|
||||||
#define MODULES_AUDIO_PROCESSING_RESIDUAL_ECHO_DETECTOR_H_
|
#define MODULES_AUDIO_PROCESSING_RESIDUAL_ECHO_DETECTOR_H_
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "api/array_view.h"
|
#include "api/array_view.h"
|
||||||
@ -49,7 +50,7 @@ class ResidualEchoDetector : public EchoDetector {
|
|||||||
EchoDetector::Metrics GetMetrics() const override;
|
EchoDetector::Metrics GetMetrics() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int instance_count_;
|
static std::atomic<int> instance_count_;
|
||||||
std::unique_ptr<ApmDataDumper> data_dumper_;
|
std::unique_ptr<ApmDataDumper> data_dumper_;
|
||||||
// Keep track if the `Process` function has been previously called.
|
// Keep track if the `Process` function has been previously called.
|
||||||
bool first_process_call_ = true;
|
bool first_process_call_ = true;
|
||||||
|
|||||||
@ -194,7 +194,6 @@ rtc_library("event_tracer") {
|
|||||||
"trace_event.h",
|
"trace_event.h",
|
||||||
]
|
]
|
||||||
deps = [
|
deps = [
|
||||||
":atomicops",
|
|
||||||
":checks",
|
":checks",
|
||||||
":logging",
|
":logging",
|
||||||
":macromagic",
|
":macromagic",
|
||||||
@ -346,7 +345,6 @@ rtc_library("criticalsection") {
|
|||||||
"deprecated/recursive_critical_section.h",
|
"deprecated/recursive_critical_section.h",
|
||||||
]
|
]
|
||||||
deps = [
|
deps = [
|
||||||
":atomicops",
|
|
||||||
":checks",
|
":checks",
|
||||||
":macromagic",
|
":macromagic",
|
||||||
":platform_thread_types",
|
":platform_thread_types",
|
||||||
@ -361,7 +359,6 @@ rtc_library("platform_thread") {
|
|||||||
"platform_thread.h",
|
"platform_thread.h",
|
||||||
]
|
]
|
||||||
deps = [
|
deps = [
|
||||||
":atomicops",
|
|
||||||
":checks",
|
":checks",
|
||||||
":macromagic",
|
":macromagic",
|
||||||
":platform_thread_types",
|
":platform_thread_types",
|
||||||
@ -453,10 +450,6 @@ rtc_library("logging") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc_source_set("atomicops") {
|
|
||||||
sources = [ "atomic_ops.h" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
rtc_library("checks") {
|
rtc_library("checks") {
|
||||||
# TODO(bugs.webrtc.org/9607): This should not be public.
|
# TODO(bugs.webrtc.org/9607): This should not be public.
|
||||||
visibility = [ "*" ]
|
visibility = [ "*" ]
|
||||||
@ -922,7 +915,6 @@ rtc_library("threading") {
|
|||||||
]
|
]
|
||||||
deps = [
|
deps = [
|
||||||
":async_resolver_interface",
|
":async_resolver_interface",
|
||||||
":atomicops",
|
|
||||||
":byte_order",
|
":byte_order",
|
||||||
":checks",
|
":checks",
|
||||||
":criticalsection",
|
":criticalsection",
|
||||||
@ -1497,7 +1489,6 @@ if (rtc_include_tests) {
|
|||||||
rtc_library("rtc_base_approved_unittests") {
|
rtc_library("rtc_base_approved_unittests") {
|
||||||
testonly = true
|
testonly = true
|
||||||
sources = [
|
sources = [
|
||||||
"atomic_ops_unittest.cc",
|
|
||||||
"base64_unittest.cc",
|
"base64_unittest.cc",
|
||||||
"bit_buffer_unittest.cc",
|
"bit_buffer_unittest.cc",
|
||||||
"bitstream_reader_unittest.cc",
|
"bitstream_reader_unittest.cc",
|
||||||
@ -1541,7 +1532,6 @@ if (rtc_include_tests) {
|
|||||||
"zero_memory_unittest.cc",
|
"zero_memory_unittest.cc",
|
||||||
]
|
]
|
||||||
deps = [
|
deps = [
|
||||||
":atomicops",
|
|
||||||
":bit_buffer",
|
":bit_buffer",
|
||||||
":bitstream_reader",
|
":bitstream_reader",
|
||||||
":bounded_inline_vector",
|
":bounded_inline_vector",
|
||||||
@ -1710,7 +1700,6 @@ if (rtc_include_tests) {
|
|||||||
"unique_id_generator_unittest.cc",
|
"unique_id_generator_unittest.cc",
|
||||||
]
|
]
|
||||||
deps = [
|
deps = [
|
||||||
":atomicops",
|
|
||||||
":buffer",
|
":buffer",
|
||||||
":buffer_queue",
|
":buffer_queue",
|
||||||
":checks",
|
":checks",
|
||||||
|
|||||||
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 The WebRTC Project Authors. All rights reserved.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by a BSD-style license
|
|
||||||
* that can be found in the LICENSE file in the root of the source
|
|
||||||
* tree. An additional intellectual property rights grant can be found
|
|
||||||
* in the file PATENTS. All contributing project authors may
|
|
||||||
* be found in the AUTHORS file in the root of the source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef RTC_BASE_ATOMIC_OPS_H_
|
|
||||||
#define RTC_BASE_ATOMIC_OPS_H_
|
|
||||||
|
|
||||||
#if defined(WEBRTC_WIN)
|
|
||||||
// clang-format off
|
|
||||||
// clang formating would change include order.
|
|
||||||
|
|
||||||
// Include winsock2.h before including <windows.h> to maintain consistency with
|
|
||||||
// win32.h. To include win32.h directly, it must be broken out into its own
|
|
||||||
// build target.
|
|
||||||
#include <winsock2.h>
|
|
||||||
#include <windows.h>
|
|
||||||
// clang-format on
|
|
||||||
#endif // defined(WEBRTC_WIN)
|
|
||||||
|
|
||||||
namespace rtc {
|
|
||||||
class AtomicOps {
|
|
||||||
public:
|
|
||||||
#if defined(WEBRTC_WIN)
|
|
||||||
// Assumes sizeof(int) == sizeof(LONG), which it is on Win32 and Win64.
|
|
||||||
static int Increment(volatile int* i) {
|
|
||||||
return ::InterlockedIncrement(reinterpret_cast<volatile LONG*>(i));
|
|
||||||
}
|
|
||||||
static int Decrement(volatile int* i) {
|
|
||||||
return ::InterlockedDecrement(reinterpret_cast<volatile LONG*>(i));
|
|
||||||
}
|
|
||||||
static int AcquireLoad(volatile const int* i) { return *i; }
|
|
||||||
static void ReleaseStore(volatile int* i, int value) { *i = value; }
|
|
||||||
static int CompareAndSwap(volatile int* i, int old_value, int new_value) {
|
|
||||||
return ::InterlockedCompareExchange(reinterpret_cast<volatile LONG*>(i),
|
|
||||||
new_value, old_value);
|
|
||||||
}
|
|
||||||
// Pointer variants.
|
|
||||||
template <typename T>
|
|
||||||
static T* AcquireLoadPtr(T* volatile* ptr) {
|
|
||||||
return *ptr;
|
|
||||||
}
|
|
||||||
template <typename T>
|
|
||||||
static T* CompareAndSwapPtr(T* volatile* ptr, T* old_value, T* new_value) {
|
|
||||||
return static_cast<T*>(::InterlockedCompareExchangePointer(
|
|
||||||
reinterpret_cast<PVOID volatile*>(ptr), new_value, old_value));
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static int Increment(volatile int* i) { return __sync_add_and_fetch(i, 1); }
|
|
||||||
static int Decrement(volatile int* i) { return __sync_sub_and_fetch(i, 1); }
|
|
||||||
static int AcquireLoad(volatile const int* i) {
|
|
||||||
return __atomic_load_n(i, __ATOMIC_ACQUIRE);
|
|
||||||
}
|
|
||||||
static void ReleaseStore(volatile int* i, int value) {
|
|
||||||
__atomic_store_n(i, value, __ATOMIC_RELEASE);
|
|
||||||
}
|
|
||||||
static int CompareAndSwap(volatile int* i, int old_value, int new_value) {
|
|
||||||
return __sync_val_compare_and_swap(i, old_value, new_value);
|
|
||||||
}
|
|
||||||
// Pointer variants.
|
|
||||||
template <typename T>
|
|
||||||
static T* AcquireLoadPtr(T* volatile* ptr) {
|
|
||||||
return __atomic_load_n(ptr, __ATOMIC_ACQUIRE);
|
|
||||||
}
|
|
||||||
template <typename T>
|
|
||||||
static T* CompareAndSwapPtr(T* volatile* ptr, T* old_value, T* new_value) {
|
|
||||||
return __sync_val_compare_and_swap(ptr, old_value, new_value);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace rtc
|
|
||||||
|
|
||||||
#endif // RTC_BASE_ATOMIC_OPS_H_
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 The WebRTC Project Authors. All rights reserved.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by a BSD-style license
|
|
||||||
* that can be found in the LICENSE file in the root of the source
|
|
||||||
* tree. An additional intellectual property rights grant can be found
|
|
||||||
* in the file PATENTS. All contributing project authors may
|
|
||||||
* be found in the AUTHORS file in the root of the source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO(pbos): Move AtomicOps tests to here from
|
|
||||||
// webrtc/rtc_base/criticalsection_unittest.cc.
|
|
||||||
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/platform_thread_types.h"
|
#include "rtc_base/platform_thread_types.h"
|
||||||
#include "rtc_base/synchronization/yield.h"
|
#include "rtc_base/synchronization/yield.h"
|
||||||
|
|||||||
@ -11,6 +11,8 @@
|
|||||||
#ifndef RTC_BASE_DEPRECATED_RECURSIVE_CRITICAL_SECTION_H_
|
#ifndef RTC_BASE_DEPRECATED_RECURSIVE_CRITICAL_SECTION_H_
|
||||||
#define RTC_BASE_DEPRECATED_RECURSIVE_CRITICAL_SECTION_H_
|
#define RTC_BASE_DEPRECATED_RECURSIVE_CRITICAL_SECTION_H_
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
#include "rtc_base/platform_thread_types.h"
|
#include "rtc_base/platform_thread_types.h"
|
||||||
#include "rtc_base/thread_annotations.h"
|
#include "rtc_base/thread_annotations.h"
|
||||||
|
|
||||||
@ -68,7 +70,7 @@ class RTC_LOCKABLE RecursiveCriticalSection {
|
|||||||
// Number of times the lock has been locked + number of threads waiting.
|
// Number of times the lock has been locked + number of threads waiting.
|
||||||
// TODO(tommi): We could use this number and subtract the recursion count
|
// TODO(tommi): We could use this number and subtract the recursion count
|
||||||
// to find places where we have multiple threads contending on the same lock.
|
// to find places where we have multiple threads contending on the same lock.
|
||||||
mutable volatile int lock_queue_;
|
mutable std::atomic<int> lock_queue_;
|
||||||
// `recursion_` represents the recursion count + 1 for the thread that owns
|
// `recursion_` represents the recursion count + 1 for the thread that owns
|
||||||
// the lock. Only modified by the thread that owns the lock.
|
// the lock. Only modified by the thread that owns the lock.
|
||||||
mutable int recursion_;
|
mutable int recursion_;
|
||||||
|
|||||||
@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
#include "absl/base/attributes.h"
|
#include "absl/base/attributes.h"
|
||||||
#include "rtc_base/arraysize.h"
|
#include "rtc_base/arraysize.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/event.h"
|
#include "rtc_base/event.h"
|
||||||
#include "rtc_base/location.h"
|
#include "rtc_base/location.h"
|
||||||
@ -94,7 +93,7 @@ class RunnerBase : public MessageHandlerAutoCleanup {
|
|||||||
return done_event_.Wait(kLongTime);
|
return done_event_.Wait(kLongTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetExpectedThreadCount(int count) { threads_active_ = count; }
|
void SetExpectedThreadCount(int count) { threads_active_.store(count); }
|
||||||
|
|
||||||
int shared_value() const { return shared_value_; }
|
int shared_value() const { return shared_value_; }
|
||||||
|
|
||||||
@ -105,14 +104,14 @@ class RunnerBase : public MessageHandlerAutoCleanup {
|
|||||||
|
|
||||||
// Returns true if all threads have finished.
|
// Returns true if all threads have finished.
|
||||||
bool AfterEnd() {
|
bool AfterEnd() {
|
||||||
if (AtomicOps::Decrement(&threads_active_) == 0) {
|
if (threads_active_.fetch_sub(1) == 1) {
|
||||||
done_event_.Set();
|
done_event_.Set();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int threads_active_;
|
std::atomic<int> threads_active_;
|
||||||
Event start_event_;
|
Event start_event_;
|
||||||
Event done_event_;
|
Event done_event_;
|
||||||
int shared_value_;
|
int shared_value_;
|
||||||
@ -156,49 +155,6 @@ class LockRunner : public RunnerBase {
|
|||||||
Lock lock_;
|
Lock lock_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Op, class Verifier>
|
|
||||||
class AtomicOpRunner : public RunnerBase {
|
|
||||||
public:
|
|
||||||
explicit AtomicOpRunner(int initial_value) : RunnerBase(initial_value) {}
|
|
||||||
|
|
||||||
void OnMessage(Message* msg) override {
|
|
||||||
BeforeStart();
|
|
||||||
|
|
||||||
std::vector<int> values;
|
|
||||||
values.reserve(kOperationsToRun);
|
|
||||||
|
|
||||||
// Generate a bunch of values by updating shared_value_ atomically.
|
|
||||||
for (int i = 0; i < kOperationsToRun; ++i) {
|
|
||||||
values.push_back(Op::AtomicOp(&shared_value_));
|
|
||||||
}
|
|
||||||
|
|
||||||
{ // Add them all to the set.
|
|
||||||
CritScope cs(&all_values_crit_);
|
|
||||||
verifier_.Verify(values);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AfterEnd()) {
|
|
||||||
verifier_.Finalize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
RecursiveCriticalSection all_values_crit_;
|
|
||||||
Verifier verifier_;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct IncrementOp {
|
|
||||||
static int AtomicOp(int* i) { return AtomicOps::Increment(i); }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DecrementOp {
|
|
||||||
static int AtomicOp(int* i) { return AtomicOps::Decrement(i); }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CompareAndSwapOp {
|
|
||||||
static int AtomicOp(int* i) { return AtomicOps::CompareAndSwap(i, 0, 1); }
|
|
||||||
};
|
|
||||||
|
|
||||||
void StartThreads(std::vector<std::unique_ptr<Thread>>* threads,
|
void StartThreads(std::vector<std::unique_ptr<Thread>>* threads,
|
||||||
MessageHandler* handler) {
|
MessageHandler* handler) {
|
||||||
for (int i = 0; i < kNumThreads; ++i) {
|
for (int i = 0; i < kNumThreads; ++i) {
|
||||||
@ -211,77 +167,6 @@ void StartThreads(std::vector<std::unique_ptr<Thread>>* threads,
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
TEST(AtomicOpsTest, Simple) {
|
|
||||||
int value = 0;
|
|
||||||
EXPECT_EQ(1, AtomicOps::Increment(&value));
|
|
||||||
EXPECT_EQ(1, value);
|
|
||||||
EXPECT_EQ(2, AtomicOps::Increment(&value));
|
|
||||||
EXPECT_EQ(2, value);
|
|
||||||
EXPECT_EQ(1, AtomicOps::Decrement(&value));
|
|
||||||
EXPECT_EQ(1, value);
|
|
||||||
EXPECT_EQ(0, AtomicOps::Decrement(&value));
|
|
||||||
EXPECT_EQ(0, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(AtomicOpsTest, SimplePtr) {
|
|
||||||
class Foo {};
|
|
||||||
Foo* volatile foo = nullptr;
|
|
||||||
std::unique_ptr<Foo> a(new Foo());
|
|
||||||
std::unique_ptr<Foo> b(new Foo());
|
|
||||||
// Reading the initial value should work as expected.
|
|
||||||
EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == nullptr);
|
|
||||||
// Setting using compare and swap should work.
|
|
||||||
EXPECT_TRUE(rtc::AtomicOps::CompareAndSwapPtr(
|
|
||||||
&foo, static_cast<Foo*>(nullptr), a.get()) == nullptr);
|
|
||||||
EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == a.get());
|
|
||||||
// Setting another value but with the wrong previous pointer should fail
|
|
||||||
// (remain a).
|
|
||||||
EXPECT_TRUE(rtc::AtomicOps::CompareAndSwapPtr(
|
|
||||||
&foo, static_cast<Foo*>(nullptr), b.get()) == a.get());
|
|
||||||
EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == a.get());
|
|
||||||
// Replacing a with b should work.
|
|
||||||
EXPECT_TRUE(rtc::AtomicOps::CompareAndSwapPtr(&foo, a.get(), b.get()) ==
|
|
||||||
a.get());
|
|
||||||
EXPECT_TRUE(rtc::AtomicOps::AcquireLoadPtr(&foo) == b.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(AtomicOpsTest, Increment) {
|
|
||||||
// Create and start lots of threads.
|
|
||||||
AtomicOpRunner<IncrementOp, UniqueValueVerifier> runner(0);
|
|
||||||
std::vector<std::unique_ptr<Thread>> threads;
|
|
||||||
StartThreads(&threads, &runner);
|
|
||||||
runner.SetExpectedThreadCount(kNumThreads);
|
|
||||||
|
|
||||||
// Release the hounds!
|
|
||||||
EXPECT_TRUE(runner.Run());
|
|
||||||
EXPECT_EQ(kOperationsToRun * kNumThreads, runner.shared_value());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(AtomicOpsTest, Decrement) {
|
|
||||||
// Create and start lots of threads.
|
|
||||||
AtomicOpRunner<DecrementOp, UniqueValueVerifier> runner(kOperationsToRun *
|
|
||||||
kNumThreads);
|
|
||||||
std::vector<std::unique_ptr<Thread>> threads;
|
|
||||||
StartThreads(&threads, &runner);
|
|
||||||
runner.SetExpectedThreadCount(kNumThreads);
|
|
||||||
|
|
||||||
// Release the hounds!
|
|
||||||
EXPECT_TRUE(runner.Run());
|
|
||||||
EXPECT_EQ(0, runner.shared_value());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(AtomicOpsTest, CompareAndSwap) {
|
|
||||||
// Create and start lots of threads.
|
|
||||||
AtomicOpRunner<CompareAndSwapOp, CompareAndSwapVerifier> runner(0);
|
|
||||||
std::vector<std::unique_ptr<Thread>> threads;
|
|
||||||
StartThreads(&threads, &runner);
|
|
||||||
runner.SetExpectedThreadCount(kNumThreads);
|
|
||||||
|
|
||||||
// Release the hounds!
|
|
||||||
EXPECT_TRUE(runner.Run());
|
|
||||||
EXPECT_EQ(1, runner.shared_value());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(RecursiveCriticalSectionTest, Basic) {
|
TEST(RecursiveCriticalSectionTest, Basic) {
|
||||||
// Create and start lots of threads.
|
// Create and start lots of threads.
|
||||||
LockRunner<CriticalSectionLock> runner;
|
LockRunner<CriticalSectionLock> runner;
|
||||||
|
|||||||
@ -14,12 +14,12 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "absl/strings/string_view.h"
|
#include "absl/strings/string_view.h"
|
||||||
#include "api/sequence_checker.h"
|
#include "api/sequence_checker.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/event.h"
|
#include "rtc_base/event.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
@ -81,7 +81,7 @@ namespace tracing {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Atomic-int fast path for avoiding logging when disabled.
|
// Atomic-int fast path for avoiding logging when disabled.
|
||||||
static volatile int g_event_logging_active = 0;
|
static std::atomic<int> g_event_logging_active(0);
|
||||||
|
|
||||||
// TODO(pbos): Log metadata for all threads, etc.
|
// TODO(pbos): Log metadata for all threads, etc.
|
||||||
class EventLogger final {
|
class EventLogger final {
|
||||||
@ -199,8 +199,8 @@ class EventLogger final {
|
|||||||
}
|
}
|
||||||
// Enable event logging (fast-path). This should be disabled since starting
|
// Enable event logging (fast-path). This should be disabled since starting
|
||||||
// shouldn't be done twice.
|
// shouldn't be done twice.
|
||||||
RTC_CHECK_EQ(0,
|
int zero = 0;
|
||||||
rtc::AtomicOps::CompareAndSwap(&g_event_logging_active, 0, 1));
|
RTC_CHECK(g_event_logging_active.compare_exchange_strong(zero, 1));
|
||||||
|
|
||||||
// Finally start, everything should be set up now.
|
// Finally start, everything should be set up now.
|
||||||
logging_thread_ =
|
logging_thread_ =
|
||||||
@ -212,7 +212,8 @@ class EventLogger final {
|
|||||||
RTC_DCHECK(thread_checker_.IsCurrent());
|
RTC_DCHECK(thread_checker_.IsCurrent());
|
||||||
TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Stop");
|
TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Stop");
|
||||||
// Try to stop. Abort if we're not currently logging.
|
// Try to stop. Abort if we're not currently logging.
|
||||||
if (rtc::AtomicOps::CompareAndSwap(&g_event_logging_active, 1, 0) == 0)
|
int one = 1;
|
||||||
|
if (g_event_logging_active.compare_exchange_strong(one, 0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Wake up logging thread to finish writing.
|
// Wake up logging thread to finish writing.
|
||||||
@ -321,7 +322,7 @@ class EventLogger final {
|
|||||||
bool output_file_owned_ = false;
|
bool output_file_owned_ = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
static EventLogger* volatile g_event_logger = nullptr;
|
static std::atomic<EventLogger*> g_event_logger(nullptr);
|
||||||
static const char* const kDisabledTracePrefix = TRACE_DISABLED_BY_DEFAULT("");
|
static const char* const kDisabledTracePrefix = TRACE_DISABLED_BY_DEFAULT("");
|
||||||
const unsigned char* InternalGetCategoryEnabled(const char* name) {
|
const unsigned char* InternalGetCategoryEnabled(const char* name) {
|
||||||
const char* prefix_ptr = &kDisabledTracePrefix[0];
|
const char* prefix_ptr = &kDisabledTracePrefix[0];
|
||||||
@ -349,33 +350,35 @@ void InternalAddTraceEvent(char phase,
|
|||||||
const unsigned long long* arg_values,
|
const unsigned long long* arg_values,
|
||||||
unsigned char flags) {
|
unsigned char flags) {
|
||||||
// Fast path for when event tracing is inactive.
|
// Fast path for when event tracing is inactive.
|
||||||
if (rtc::AtomicOps::AcquireLoad(&g_event_logging_active) == 0)
|
if (g_event_logging_active.load() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_event_logger->AddTraceEvent(name, category_enabled, phase, num_args,
|
g_event_logger.load()->AddTraceEvent(
|
||||||
arg_names, arg_types, arg_values,
|
name, category_enabled, phase, num_args, arg_names, arg_types, arg_values,
|
||||||
rtc::TimeMicros(), 1, rtc::CurrentThreadId());
|
rtc::TimeMicros(), 1, rtc::CurrentThreadId());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void SetupInternalTracer(bool enable_all_categories) {
|
void SetupInternalTracer(bool enable_all_categories) {
|
||||||
RTC_CHECK(rtc::AtomicOps::CompareAndSwapPtr(
|
EventLogger* null_logger = nullptr;
|
||||||
&g_event_logger, static_cast<EventLogger*>(nullptr),
|
RTC_CHECK(
|
||||||
new EventLogger()) == nullptr);
|
g_event_logger.compare_exchange_strong(null_logger, new EventLogger()));
|
||||||
webrtc::SetupEventTracer(enable_all_categories ? InternalEnableAllCategories
|
webrtc::SetupEventTracer(enable_all_categories ? InternalEnableAllCategories
|
||||||
: InternalGetCategoryEnabled,
|
: InternalGetCategoryEnabled,
|
||||||
InternalAddTraceEvent);
|
InternalAddTraceEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartInternalCaptureToFile(FILE* file) {
|
void StartInternalCaptureToFile(FILE* file) {
|
||||||
if (g_event_logger) {
|
EventLogger* event_logger = g_event_logger.load();
|
||||||
g_event_logger->Start(file, false);
|
if (event_logger) {
|
||||||
|
event_logger->Start(file, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StartInternalCapture(absl::string_view filename) {
|
bool StartInternalCapture(absl::string_view filename) {
|
||||||
if (!g_event_logger)
|
EventLogger* event_logger = g_event_logger.load();
|
||||||
|
if (!event_logger)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
FILE* file = fopen(std::string(filename).c_str(), "w");
|
FILE* file = fopen(std::string(filename).c_str(), "w");
|
||||||
@ -384,23 +387,22 @@ bool StartInternalCapture(absl::string_view filename) {
|
|||||||
<< "' for writing.";
|
<< "' for writing.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
g_event_logger->Start(file, true);
|
event_logger->Start(file, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StopInternalCapture() {
|
void StopInternalCapture() {
|
||||||
if (g_event_logger) {
|
EventLogger* event_logger = g_event_logger.load();
|
||||||
g_event_logger->Stop();
|
if (event_logger) {
|
||||||
|
event_logger->Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShutdownInternalTracer() {
|
void ShutdownInternalTracer() {
|
||||||
StopInternalCapture();
|
StopInternalCapture();
|
||||||
EventLogger* old_logger = rtc::AtomicOps::AcquireLoadPtr(&g_event_logger);
|
EventLogger* old_logger = g_event_logger.load(std::memory_order_acquire);
|
||||||
RTC_DCHECK(old_logger);
|
RTC_DCHECK(old_logger);
|
||||||
RTC_CHECK(rtc::AtomicOps::CompareAndSwapPtr(
|
RTC_CHECK(g_event_logger.compare_exchange_strong(old_logger, nullptr));
|
||||||
&g_event_logger, old_logger,
|
|
||||||
static_cast<EventLogger*>(nullptr)) == old_logger);
|
|
||||||
delete old_logger;
|
delete old_logger;
|
||||||
webrtc::SetupEventTracer(nullptr, nullptr);
|
webrtc::SetupEventTracer(nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,7 +33,6 @@
|
|||||||
#include "absl/algorithm/container.h"
|
#include "absl/algorithm/container.h"
|
||||||
#include "api/sequence_checker.h"
|
#include "api/sequence_checker.h"
|
||||||
#include "api/task_queue/to_queued_task.h"
|
#include "api/task_queue/to_queued_task.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/deprecated/recursive_critical_section.h"
|
#include "rtc_base/deprecated/recursive_critical_section.h"
|
||||||
#include "rtc_base/event.h"
|
#include "rtc_base/event.h"
|
||||||
@ -212,19 +211,19 @@ void ThreadManager::ProcessAllMessageQueuesInternal() {
|
|||||||
// This works by posting a delayed message at the current time and waiting
|
// This works by posting a delayed message at the current time and waiting
|
||||||
// for it to be dispatched on all queues, which will ensure that all messages
|
// for it to be dispatched on all queues, which will ensure that all messages
|
||||||
// that came before it were also dispatched.
|
// that came before it were also dispatched.
|
||||||
volatile int queues_not_done = 0;
|
std::atomic<int> queues_not_done(0);
|
||||||
|
|
||||||
// This class is used so that whether the posted message is processed, or the
|
// This class is used so that whether the posted message is processed, or the
|
||||||
// message queue is simply cleared, queues_not_done gets decremented.
|
// message queue is simply cleared, queues_not_done gets decremented.
|
||||||
class ScopedIncrement : public MessageData {
|
class ScopedIncrement : public MessageData {
|
||||||
public:
|
public:
|
||||||
ScopedIncrement(volatile int* value) : value_(value) {
|
ScopedIncrement(std::atomic<int>* value) : value_(value) {
|
||||||
AtomicOps::Increment(value_);
|
value_->fetch_add(1);
|
||||||
}
|
}
|
||||||
~ScopedIncrement() override { AtomicOps::Decrement(value_); }
|
~ScopedIncrement() override { value_->fetch_sub(1); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
volatile int* value_;
|
std::atomic<int>* value_;
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -245,7 +244,7 @@ void ThreadManager::ProcessAllMessageQueuesInternal() {
|
|||||||
// Note: One of the message queues may have been on this thread, which is
|
// Note: One of the message queues may have been on this thread, which is
|
||||||
// why we can't synchronously wait for queues_not_done to go to 0; we need
|
// why we can't synchronously wait for queues_not_done to go to 0; we need
|
||||||
// to process messages as well.
|
// to process messages as well.
|
||||||
while (AtomicOps::AcquireLoad(&queues_not_done) > 0) {
|
while (queues_not_done.load() > 0) {
|
||||||
if (current) {
|
if (current) {
|
||||||
current->ProcessMessages(0);
|
current->ProcessMessages(0);
|
||||||
}
|
}
|
||||||
@ -436,16 +435,16 @@ void Thread::WakeUpSocketServer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Thread::Quit() {
|
void Thread::Quit() {
|
||||||
AtomicOps::ReleaseStore(&stop_, 1);
|
stop_.store(1, std::memory_order_release);
|
||||||
WakeUpSocketServer();
|
WakeUpSocketServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Thread::IsQuitting() {
|
bool Thread::IsQuitting() {
|
||||||
return AtomicOps::AcquireLoad(&stop_) != 0;
|
return stop_.load(std::memory_order_acquire) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thread::Restart() {
|
void Thread::Restart() {
|
||||||
AtomicOps::ReleaseStore(&stop_, 0);
|
stop_.store(0, std::memory_order_release);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Thread::Peek(Message* pmsg, int cmsWait) {
|
bool Thread::Peek(Message* pmsg, int cmsWait) {
|
||||||
|
|||||||
@ -628,7 +628,7 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public webrtc::TaskQueueBase {
|
|||||||
bool fInitialized_;
|
bool fInitialized_;
|
||||||
bool fDestroyed_;
|
bool fDestroyed_;
|
||||||
|
|
||||||
volatile int stop_;
|
std::atomic<int> stop_;
|
||||||
|
|
||||||
// The SocketServer might not be owned by Thread.
|
// The SocketServer might not be owned by Thread.
|
||||||
SocketServer* const ss_;
|
SocketServer* const ss_;
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
#include "api/task_queue/to_queued_task.h"
|
#include "api/task_queue/to_queued_task.h"
|
||||||
#include "rtc_base/async_invoker.h"
|
#include "rtc_base/async_invoker.h"
|
||||||
#include "rtc_base/async_udp_socket.h"
|
#include "rtc_base/async_udp_socket.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/event.h"
|
#include "rtc_base/event.h"
|
||||||
#include "rtc_base/gunit.h"
|
#include "rtc_base/gunit.h"
|
||||||
@ -658,7 +657,7 @@ TEST(ThreadManager, ProcessAllMessageQueues) {
|
|||||||
a->Start();
|
a->Start();
|
||||||
b->Start();
|
b->Start();
|
||||||
|
|
||||||
volatile int messages_processed = 0;
|
std::atomic<int> messages_processed(0);
|
||||||
auto incrementer = [&messages_processed,
|
auto incrementer = [&messages_processed,
|
||||||
&entered_process_all_message_queues] {
|
&entered_process_all_message_queues] {
|
||||||
// Wait for event as a means to ensure Increment doesn't occur outside
|
// Wait for event as a means to ensure Increment doesn't occur outside
|
||||||
@ -666,7 +665,7 @@ TEST(ThreadManager, ProcessAllMessageQueues) {
|
|||||||
// the main thread, which is guaranteed to be handled inside
|
// the main thread, which is guaranteed to be handled inside
|
||||||
// ProcessAllMessageQueues.
|
// ProcessAllMessageQueues.
|
||||||
entered_process_all_message_queues.Wait(Event::kForever);
|
entered_process_all_message_queues.Wait(Event::kForever);
|
||||||
AtomicOps::Increment(&messages_processed);
|
messages_processed.fetch_add(1);
|
||||||
};
|
};
|
||||||
auto event_signaler = [&entered_process_all_message_queues] {
|
auto event_signaler = [&entered_process_all_message_queues] {
|
||||||
entered_process_all_message_queues.Set();
|
entered_process_all_message_queues.Set();
|
||||||
@ -680,7 +679,7 @@ TEST(ThreadManager, ProcessAllMessageQueues) {
|
|||||||
main_thread.PostTask(ToQueuedTask(event_signaler));
|
main_thread.PostTask(ToQueuedTask(event_signaler));
|
||||||
|
|
||||||
ThreadManager::ProcessAllMessageQueuesForTesting();
|
ThreadManager::ProcessAllMessageQueuesForTesting();
|
||||||
EXPECT_EQ(4, AtomicOps::AcquireLoad(&messages_processed));
|
EXPECT_EQ(4, messages_processed.load(std::memory_order_acquire));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that ProcessAllMessageQueues doesn't hang if a thread is quitting.
|
// Test that ProcessAllMessageQueues doesn't hang if a thread is quitting.
|
||||||
|
|||||||
@ -277,7 +277,6 @@ if (is_ios || is_mac) {
|
|||||||
"../modules/audio_device:audio_device_buffer",
|
"../modules/audio_device:audio_device_buffer",
|
||||||
"../modules/audio_device:audio_device_generic",
|
"../modules/audio_device:audio_device_generic",
|
||||||
"../rtc_base",
|
"../rtc_base",
|
||||||
"../rtc_base:atomicops",
|
|
||||||
"../rtc_base:buffer",
|
"../rtc_base:buffer",
|
||||||
"../rtc_base:checks",
|
"../rtc_base:checks",
|
||||||
"../rtc_base:logging",
|
"../rtc_base:logging",
|
||||||
@ -348,7 +347,6 @@ if (is_ios || is_mac) {
|
|||||||
":base_objc",
|
":base_objc",
|
||||||
":helpers_objc",
|
":helpers_objc",
|
||||||
"../rtc_base",
|
"../rtc_base",
|
||||||
"../rtc_base:atomicops",
|
|
||||||
"../rtc_base:checks",
|
"../rtc_base:checks",
|
||||||
"../rtc_base/synchronization:mutex",
|
"../rtc_base/synchronization:mutex",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -951,7 +951,6 @@ if (current_os == "linux" || is_android) {
|
|||||||
":generated_native_api_jni",
|
":generated_native_api_jni",
|
||||||
":internal_jni",
|
":internal_jni",
|
||||||
"../../api:sequence_checker",
|
"../../api:sequence_checker",
|
||||||
"../../rtc_base:atomicops",
|
|
||||||
"//api:array_view",
|
"//api:array_view",
|
||||||
"//rtc_base:checks",
|
"//rtc_base:checks",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
#include "sdk/android/src/jni/jni_generator_helper.h"
|
#include "sdk/android/src/jni/jni_generator_helper.h"
|
||||||
|
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "sdk/android/native_api/jni/class_loader.h"
|
#include "sdk/android/native_api/jni/class_loader.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|||||||
@ -12,10 +12,10 @@
|
|||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "absl/base/attributes.h"
|
#include "absl/base/attributes.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/synchronization/mutex.h"
|
#include "rtc_base/synchronization/mutex.h"
|
||||||
|
|
||||||
@ -48,8 +48,8 @@ ABSL_CONST_INIT thread_local bool mutex_locked = false;
|
|||||||
@implementation RTC_OBJC_TYPE (RTCAudioSession) {
|
@implementation RTC_OBJC_TYPE (RTCAudioSession) {
|
||||||
webrtc::Mutex _mutex;
|
webrtc::Mutex _mutex;
|
||||||
AVAudioSession *_session;
|
AVAudioSession *_session;
|
||||||
volatile int _activationCount;
|
std::atomic<int> _activationCount;
|
||||||
volatile int _webRTCSessionCount;
|
std::atomic<int> _webRTCSessionCount;
|
||||||
BOOL _isActive;
|
BOOL _isActive;
|
||||||
BOOL _useManualAudio;
|
BOOL _useManualAudio;
|
||||||
BOOL _isAudioEnabled;
|
BOOL _isAudioEnabled;
|
||||||
@ -351,7 +351,7 @@ ABSL_CONST_INIT thread_local bool mutex_locked = false;
|
|||||||
if (![self checkLock:outError]) {
|
if (![self checkLock:outError]) {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
int activationCount = _activationCount;
|
int activationCount = _activationCount.load();
|
||||||
if (!active && activationCount == 0) {
|
if (!active && activationCount == 0) {
|
||||||
RTCLogWarning(@"Attempting to deactivate without prior activation.");
|
RTCLogWarning(@"Attempting to deactivate without prior activation.");
|
||||||
}
|
}
|
||||||
@ -403,7 +403,7 @@ ABSL_CONST_INIT thread_local bool mutex_locked = false;
|
|||||||
[self notifyDidSetActive:active];
|
[self notifyDidSetActive:active];
|
||||||
[self decrementActivationCount];
|
[self decrementActivationCount];
|
||||||
}
|
}
|
||||||
RTCLog(@"Number of current activations: %d", _activationCount);
|
RTCLog(@"Number of current activations: %d", _activationCount.load());
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -643,21 +643,21 @@ ABSL_CONST_INIT thread_local bool mutex_locked = false;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (int)activationCount {
|
- (int)activationCount {
|
||||||
return _activationCount;
|
return _activationCount.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)incrementActivationCount {
|
- (int)incrementActivationCount {
|
||||||
RTCLog(@"Incrementing activation count.");
|
RTCLog(@"Incrementing activation count.");
|
||||||
return rtc::AtomicOps::Increment(&_activationCount);
|
return _activationCount.fetch_add(1) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSInteger)decrementActivationCount {
|
- (NSInteger)decrementActivationCount {
|
||||||
RTCLog(@"Decrementing activation count.");
|
RTCLog(@"Decrementing activation count.");
|
||||||
return rtc::AtomicOps::Decrement(&_activationCount);
|
return _activationCount.fetch_sub(1) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)webRTCSessionCount {
|
- (int)webRTCSessionCount {
|
||||||
return _webRTCSessionCount;
|
return _webRTCSessionCount.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)canPlayOrRecord {
|
- (BOOL)canPlayOrRecord {
|
||||||
@ -693,7 +693,7 @@ ABSL_CONST_INIT thread_local bool mutex_locked = false;
|
|||||||
if (outError) {
|
if (outError) {
|
||||||
*outError = nil;
|
*outError = nil;
|
||||||
}
|
}
|
||||||
rtc::AtomicOps::Increment(&_webRTCSessionCount);
|
_webRTCSessionCount.fetch_add(1);
|
||||||
[self notifyDidStartPlayOrRecord];
|
[self notifyDidStartPlayOrRecord];
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
@ -702,7 +702,7 @@ ABSL_CONST_INIT thread_local bool mutex_locked = false;
|
|||||||
if (outError) {
|
if (outError) {
|
||||||
*outError = nil;
|
*outError = nil;
|
||||||
}
|
}
|
||||||
rtc::AtomicOps::Decrement(&_webRTCSessionCount);
|
_webRTCSessionCount.fetch_sub(1);
|
||||||
[self notifyDidStopPlayOrRecord];
|
[self notifyDidStopPlayOrRecord];
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#ifndef SDK_OBJC_NATIVE_SRC_AUDIO_AUDIO_DEVICE_IOS_H_
|
#ifndef SDK_OBJC_NATIVE_SRC_AUDIO_AUDIO_DEVICE_IOS_H_
|
||||||
#define SDK_OBJC_NATIVE_SRC_AUDIO_AUDIO_DEVICE_IOS_H_
|
#define SDK_OBJC_NATIVE_SRC_AUDIO_AUDIO_DEVICE_IOS_H_
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "api/sequence_checker.h"
|
#include "api/sequence_checker.h"
|
||||||
@ -266,10 +267,10 @@ class AudioDeviceIOS : public AudioDeviceGeneric,
|
|||||||
rtc::BufferT<int16_t> record_audio_buffer_;
|
rtc::BufferT<int16_t> record_audio_buffer_;
|
||||||
|
|
||||||
// Set to 1 when recording is active and 0 otherwise.
|
// Set to 1 when recording is active and 0 otherwise.
|
||||||
volatile int recording_;
|
std::atomic<int> recording_;
|
||||||
|
|
||||||
// Set to 1 when playout is active and 0 otherwise.
|
// Set to 1 when playout is active and 0 otherwise.
|
||||||
volatile int playing_;
|
std::atomic<int> playing_;
|
||||||
|
|
||||||
// Set to true after successful call to Init(), false otherwise.
|
// Set to true after successful call to Init(), false otherwise.
|
||||||
bool initialized_ RTC_GUARDED_BY(thread_checker_);
|
bool initialized_ RTC_GUARDED_BY(thread_checker_);
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
#include "api/array_view.h"
|
#include "api/array_view.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "modules/audio_device/fine_audio_buffer.h"
|
#include "modules/audio_device/fine_audio_buffer.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
#include "rtc_base/thread.h"
|
#include "rtc_base/thread.h"
|
||||||
@ -188,7 +187,7 @@ int32_t AudioDeviceIOS::InitPlayout() {
|
|||||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||||
RTC_DCHECK(initialized_);
|
RTC_DCHECK(initialized_);
|
||||||
RTC_DCHECK(!audio_is_initialized_);
|
RTC_DCHECK(!audio_is_initialized_);
|
||||||
RTC_DCHECK(!playing_);
|
RTC_DCHECK(!playing_.load());
|
||||||
if (!audio_is_initialized_) {
|
if (!audio_is_initialized_) {
|
||||||
if (!InitPlayOrRecord()) {
|
if (!InitPlayOrRecord()) {
|
||||||
RTC_LOG_F(LS_ERROR) << "InitPlayOrRecord failed for InitPlayout!";
|
RTC_LOG_F(LS_ERROR) << "InitPlayOrRecord failed for InitPlayout!";
|
||||||
@ -214,7 +213,7 @@ int32_t AudioDeviceIOS::InitRecording() {
|
|||||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||||
RTC_DCHECK(initialized_);
|
RTC_DCHECK(initialized_);
|
||||||
RTC_DCHECK(!audio_is_initialized_);
|
RTC_DCHECK(!audio_is_initialized_);
|
||||||
RTC_DCHECK(!recording_);
|
RTC_DCHECK(!recording_.load());
|
||||||
if (!audio_is_initialized_) {
|
if (!audio_is_initialized_) {
|
||||||
if (!InitPlayOrRecord()) {
|
if (!InitPlayOrRecord()) {
|
||||||
RTC_LOG_F(LS_ERROR) << "InitPlayOrRecord failed for InitRecording!";
|
RTC_LOG_F(LS_ERROR) << "InitPlayOrRecord failed for InitRecording!";
|
||||||
@ -229,12 +228,12 @@ int32_t AudioDeviceIOS::StartPlayout() {
|
|||||||
LOGI() << "StartPlayout";
|
LOGI() << "StartPlayout";
|
||||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||||
RTC_DCHECK(audio_is_initialized_);
|
RTC_DCHECK(audio_is_initialized_);
|
||||||
RTC_DCHECK(!playing_);
|
RTC_DCHECK(!playing_.load());
|
||||||
RTC_DCHECK(audio_unit_);
|
RTC_DCHECK(audio_unit_);
|
||||||
if (fine_audio_buffer_) {
|
if (fine_audio_buffer_) {
|
||||||
fine_audio_buffer_->ResetPlayout();
|
fine_audio_buffer_->ResetPlayout();
|
||||||
}
|
}
|
||||||
if (!recording_ && audio_unit_->GetState() == VoiceProcessingAudioUnit::kInitialized) {
|
if (!recording_.load() && audio_unit_->GetState() == VoiceProcessingAudioUnit::kInitialized) {
|
||||||
OSStatus result = audio_unit_->Start();
|
OSStatus result = audio_unit_->Start();
|
||||||
if (result != noErr) {
|
if (result != noErr) {
|
||||||
RTC_OBJC_TYPE(RTCAudioSession)* session = [RTC_OBJC_TYPE(RTCAudioSession) sharedInstance];
|
RTC_OBJC_TYPE(RTCAudioSession)* session = [RTC_OBJC_TYPE(RTCAudioSession) sharedInstance];
|
||||||
@ -244,7 +243,7 @@ int32_t AudioDeviceIOS::StartPlayout() {
|
|||||||
}
|
}
|
||||||
RTC_LOG(LS_INFO) << "Voice-Processing I/O audio unit is now started";
|
RTC_LOG(LS_INFO) << "Voice-Processing I/O audio unit is now started";
|
||||||
}
|
}
|
||||||
rtc::AtomicOps::ReleaseStore(&playing_, 1);
|
playing_.store(1, std::memory_order_release);
|
||||||
num_playout_callbacks_ = 0;
|
num_playout_callbacks_ = 0;
|
||||||
num_detected_playout_glitches_ = 0;
|
num_detected_playout_glitches_ = 0;
|
||||||
return 0;
|
return 0;
|
||||||
@ -253,14 +252,14 @@ int32_t AudioDeviceIOS::StartPlayout() {
|
|||||||
int32_t AudioDeviceIOS::StopPlayout() {
|
int32_t AudioDeviceIOS::StopPlayout() {
|
||||||
LOGI() << "StopPlayout";
|
LOGI() << "StopPlayout";
|
||||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||||
if (!audio_is_initialized_ || !playing_) {
|
if (!audio_is_initialized_ || !playing_.load()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!recording_) {
|
if (!recording_.load()) {
|
||||||
ShutdownPlayOrRecord();
|
ShutdownPlayOrRecord();
|
||||||
audio_is_initialized_ = false;
|
audio_is_initialized_ = false;
|
||||||
}
|
}
|
||||||
rtc::AtomicOps::ReleaseStore(&playing_, 0);
|
playing_.store(0, std::memory_order_release);
|
||||||
|
|
||||||
// Derive average number of calls to OnGetPlayoutData() between detected
|
// Derive average number of calls to OnGetPlayoutData() between detected
|
||||||
// audio glitches and add the result to a histogram.
|
// audio glitches and add the result to a histogram.
|
||||||
@ -278,19 +277,19 @@ int32_t AudioDeviceIOS::StopPlayout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool AudioDeviceIOS::Playing() const {
|
bool AudioDeviceIOS::Playing() const {
|
||||||
return playing_;
|
return playing_.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t AudioDeviceIOS::StartRecording() {
|
int32_t AudioDeviceIOS::StartRecording() {
|
||||||
LOGI() << "StartRecording";
|
LOGI() << "StartRecording";
|
||||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||||
RTC_DCHECK(audio_is_initialized_);
|
RTC_DCHECK(audio_is_initialized_);
|
||||||
RTC_DCHECK(!recording_);
|
RTC_DCHECK(!recording_.load());
|
||||||
RTC_DCHECK(audio_unit_);
|
RTC_DCHECK(audio_unit_);
|
||||||
if (fine_audio_buffer_) {
|
if (fine_audio_buffer_) {
|
||||||
fine_audio_buffer_->ResetRecord();
|
fine_audio_buffer_->ResetRecord();
|
||||||
}
|
}
|
||||||
if (!playing_ && audio_unit_->GetState() == VoiceProcessingAudioUnit::kInitialized) {
|
if (!playing_.load() && audio_unit_->GetState() == VoiceProcessingAudioUnit::kInitialized) {
|
||||||
OSStatus result = audio_unit_->Start();
|
OSStatus result = audio_unit_->Start();
|
||||||
if (result != noErr) {
|
if (result != noErr) {
|
||||||
RTC_OBJC_TYPE(RTCAudioSession)* session = [RTC_OBJC_TYPE(RTCAudioSession) sharedInstance];
|
RTC_OBJC_TYPE(RTCAudioSession)* session = [RTC_OBJC_TYPE(RTCAudioSession) sharedInstance];
|
||||||
@ -300,26 +299,26 @@ int32_t AudioDeviceIOS::StartRecording() {
|
|||||||
}
|
}
|
||||||
RTC_LOG(LS_INFO) << "Voice-Processing I/O audio unit is now started";
|
RTC_LOG(LS_INFO) << "Voice-Processing I/O audio unit is now started";
|
||||||
}
|
}
|
||||||
rtc::AtomicOps::ReleaseStore(&recording_, 1);
|
recording_.store(1, std::memory_order_release);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t AudioDeviceIOS::StopRecording() {
|
int32_t AudioDeviceIOS::StopRecording() {
|
||||||
LOGI() << "StopRecording";
|
LOGI() << "StopRecording";
|
||||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||||
if (!audio_is_initialized_ || !recording_) {
|
if (!audio_is_initialized_ || !recording_.load()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!playing_) {
|
if (!playing_.load()) {
|
||||||
ShutdownPlayOrRecord();
|
ShutdownPlayOrRecord();
|
||||||
audio_is_initialized_ = false;
|
audio_is_initialized_ = false;
|
||||||
}
|
}
|
||||||
rtc::AtomicOps::ReleaseStore(&recording_, 0);
|
recording_.store(0, std::memory_order_release);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioDeviceIOS::Recording() const {
|
bool AudioDeviceIOS::Recording() const {
|
||||||
return recording_;
|
return recording_.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t AudioDeviceIOS::PlayoutDelay(uint16_t& delayMS) const {
|
int32_t AudioDeviceIOS::PlayoutDelay(uint16_t& delayMS) const {
|
||||||
@ -381,7 +380,7 @@ OSStatus AudioDeviceIOS::OnDeliverRecordedData(AudioUnitRenderActionFlags* flags
|
|||||||
RTC_DCHECK_RUN_ON(&io_thread_checker_);
|
RTC_DCHECK_RUN_ON(&io_thread_checker_);
|
||||||
OSStatus result = noErr;
|
OSStatus result = noErr;
|
||||||
// Simply return if recording is not enabled.
|
// Simply return if recording is not enabled.
|
||||||
if (!rtc::AtomicOps::AcquireLoad(&recording_)) return result;
|
if (!recording_.load(std::memory_order_acquire)) return result;
|
||||||
|
|
||||||
// Set the size of our own audio buffer and clear it first to avoid copying
|
// Set the size of our own audio buffer and clear it first to avoid copying
|
||||||
// in combination with potential reallocations.
|
// in combination with potential reallocations.
|
||||||
@ -434,7 +433,7 @@ OSStatus AudioDeviceIOS::OnGetPlayoutData(AudioUnitRenderActionFlags* flags,
|
|||||||
|
|
||||||
// Produce silence and give audio unit a hint about it if playout is not
|
// Produce silence and give audio unit a hint about it if playout is not
|
||||||
// activated.
|
// activated.
|
||||||
if (!rtc::AtomicOps::AcquireLoad(&playing_)) {
|
if (!playing_.load(std::memory_order_acquire)) {
|
||||||
const size_t size_in_bytes = audio_buffer->mDataByteSize;
|
const size_t size_in_bytes = audio_buffer->mDataByteSize;
|
||||||
RTC_CHECK_EQ(size_in_bytes / VoiceProcessingAudioUnit::kBytesPerSample, num_frames);
|
RTC_CHECK_EQ(size_in_bytes / VoiceProcessingAudioUnit::kBytesPerSample, num_frames);
|
||||||
*flags |= kAudioUnitRenderAction_OutputIsSilence;
|
*flags |= kAudioUnitRenderAction_OutputIsSilence;
|
||||||
@ -783,16 +782,17 @@ void AudioDeviceIOS::UpdateAudioUnit(bool can_play_or_record) {
|
|||||||
case VoiceProcessingAudioUnit::kUninitialized:
|
case VoiceProcessingAudioUnit::kUninitialized:
|
||||||
RTCLog(@"VPAU state: Uninitialized");
|
RTCLog(@"VPAU state: Uninitialized");
|
||||||
should_initialize_audio_unit = can_play_or_record;
|
should_initialize_audio_unit = can_play_or_record;
|
||||||
should_start_audio_unit = should_initialize_audio_unit && (playing_ || recording_);
|
should_start_audio_unit =
|
||||||
|
should_initialize_audio_unit && (playing_.load() || recording_.load());
|
||||||
break;
|
break;
|
||||||
case VoiceProcessingAudioUnit::kInitialized:
|
case VoiceProcessingAudioUnit::kInitialized:
|
||||||
RTCLog(@"VPAU state: Initialized");
|
RTCLog(@"VPAU state: Initialized");
|
||||||
should_start_audio_unit = can_play_or_record && (playing_ || recording_);
|
should_start_audio_unit = can_play_or_record && (playing_.load() || recording_.load());
|
||||||
should_uninitialize_audio_unit = !can_play_or_record;
|
should_uninitialize_audio_unit = !can_play_or_record;
|
||||||
break;
|
break;
|
||||||
case VoiceProcessingAudioUnit::kStarted:
|
case VoiceProcessingAudioUnit::kStarted:
|
||||||
RTCLog(@"VPAU state: Started");
|
RTCLog(@"VPAU state: Started");
|
||||||
RTC_DCHECK(playing_ || recording_);
|
RTC_DCHECK(playing_.load() || recording_.load());
|
||||||
should_stop_audio_unit = !can_play_or_record;
|
should_stop_audio_unit = !can_play_or_record;
|
||||||
should_uninitialize_audio_unit = should_stop_audio_unit;
|
should_uninitialize_audio_unit = should_stop_audio_unit;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -102,7 +102,6 @@ rtc_library("metrics") {
|
|||||||
defines = [ "WEBRTC_EXCLUDE_METRICS_DEFAULT" ]
|
defines = [ "WEBRTC_EXCLUDE_METRICS_DEFAULT" ]
|
||||||
}
|
}
|
||||||
deps = [
|
deps = [
|
||||||
"../rtc_base:atomicops",
|
|
||||||
"../rtc_base:checks",
|
"../rtc_base:checks",
|
||||||
"../rtc_base:macromagic",
|
"../rtc_base:macromagic",
|
||||||
"../rtc_base:stringutils",
|
"../rtc_base:stringutils",
|
||||||
|
|||||||
@ -13,12 +13,12 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "absl/strings/string_view.h"
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/string_utils.h"
|
#include "rtc_base/string_utils.h"
|
||||||
|
|
||||||
@ -190,25 +190,22 @@ void NoOp(const Ts&...) {}
|
|||||||
webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary))
|
webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary))
|
||||||
|
|
||||||
// The name of the histogram should not vary.
|
// The name of the histogram should not vary.
|
||||||
#define RTC_HISTOGRAM_COMMON_BLOCK(constant_name, sample, \
|
#define RTC_HISTOGRAM_COMMON_BLOCK(constant_name, sample, \
|
||||||
factory_get_invocation) \
|
factory_get_invocation) \
|
||||||
do { \
|
do { \
|
||||||
static webrtc::metrics::Histogram* atomic_histogram_pointer = nullptr; \
|
static std::atomic<webrtc::metrics::Histogram*> atomic_histogram_pointer( \
|
||||||
webrtc::metrics::Histogram* histogram_pointer = \
|
nullptr); \
|
||||||
rtc::AtomicOps::AcquireLoadPtr(&atomic_histogram_pointer); \
|
webrtc::metrics::Histogram* histogram_pointer = \
|
||||||
if (!histogram_pointer) { \
|
atomic_histogram_pointer.load(std::memory_order_acquire); \
|
||||||
histogram_pointer = factory_get_invocation; \
|
if (!histogram_pointer) { \
|
||||||
webrtc::metrics::Histogram* prev_pointer = \
|
histogram_pointer = factory_get_invocation; \
|
||||||
rtc::AtomicOps::CompareAndSwapPtr( \
|
webrtc::metrics::Histogram* null_histogram = nullptr; \
|
||||||
&atomic_histogram_pointer, \
|
atomic_histogram_pointer.compare_exchange_strong(null_histogram, \
|
||||||
static_cast<webrtc::metrics::Histogram*>(nullptr), \
|
histogram_pointer); \
|
||||||
histogram_pointer); \
|
} \
|
||||||
RTC_DCHECK(prev_pointer == nullptr || \
|
if (histogram_pointer) { \
|
||||||
prev_pointer == histogram_pointer); \
|
webrtc::metrics::HistogramAdd(histogram_pointer, sample); \
|
||||||
} \
|
} \
|
||||||
if (histogram_pointer) { \
|
|
||||||
webrtc::metrics::HistogramAdd(histogram_pointer, sample); \
|
|
||||||
} \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// The histogram is constructed/found for each call.
|
// The histogram is constructed/found for each call.
|
||||||
|
|||||||
@ -190,15 +190,13 @@ class RtcHistogramMap {
|
|||||||
// The histogram getter functions, which return pointer values to the histograms
|
// The histogram getter functions, which return pointer values to the histograms
|
||||||
// in the map, are cached in WebRTC. Therefore, this memory is not freed by the
|
// in the map, are cached in WebRTC. Therefore, this memory is not freed by the
|
||||||
// application (the memory will be reclaimed by the OS).
|
// application (the memory will be reclaimed by the OS).
|
||||||
static RtcHistogramMap* volatile g_rtc_histogram_map = nullptr;
|
static std::atomic<RtcHistogramMap*> g_rtc_histogram_map(nullptr);
|
||||||
|
|
||||||
void CreateMap() {
|
void CreateMap() {
|
||||||
RtcHistogramMap* map = rtc::AtomicOps::AcquireLoadPtr(&g_rtc_histogram_map);
|
RtcHistogramMap* map = g_rtc_histogram_map.load(std::memory_order_acquire);
|
||||||
if (map == nullptr) {
|
if (map == nullptr) {
|
||||||
RtcHistogramMap* new_map = new RtcHistogramMap();
|
RtcHistogramMap* new_map = new RtcHistogramMap();
|
||||||
RtcHistogramMap* old_map = rtc::AtomicOps::CompareAndSwapPtr(
|
if (!g_rtc_histogram_map.compare_exchange_strong(map, new_map))
|
||||||
&g_rtc_histogram_map, static_cast<RtcHistogramMap*>(nullptr), new_map);
|
|
||||||
if (old_map != nullptr)
|
|
||||||
delete new_map;
|
delete new_map;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,15 +204,15 @@ void CreateMap() {
|
|||||||
// Set the first time we start using histograms. Used to make sure Enable() is
|
// Set the first time we start using histograms. Used to make sure Enable() is
|
||||||
// not called thereafter.
|
// not called thereafter.
|
||||||
#if RTC_DCHECK_IS_ON
|
#if RTC_DCHECK_IS_ON
|
||||||
static volatile int g_rtc_histogram_called = 0;
|
static std::atomic<int> g_rtc_histogram_called(0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Gets the map (or nullptr).
|
// Gets the map (or nullptr).
|
||||||
RtcHistogramMap* GetMap() {
|
RtcHistogramMap* GetMap() {
|
||||||
#if RTC_DCHECK_IS_ON
|
#if RTC_DCHECK_IS_ON
|
||||||
rtc::AtomicOps::ReleaseStore(&g_rtc_histogram_called, 1);
|
g_rtc_histogram_called.store(1, std::memory_order_release);
|
||||||
#endif
|
#endif
|
||||||
return g_rtc_histogram_map;
|
return g_rtc_histogram_map.load();
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -287,9 +285,9 @@ SampleInfo::~SampleInfo() {}
|
|||||||
|
|
||||||
// Implementation of global functions in metrics.h.
|
// Implementation of global functions in metrics.h.
|
||||||
void Enable() {
|
void Enable() {
|
||||||
RTC_DCHECK(g_rtc_histogram_map == nullptr);
|
RTC_DCHECK(g_rtc_histogram_map.load() == nullptr);
|
||||||
#if RTC_DCHECK_IS_ON
|
#if RTC_DCHECK_IS_ON
|
||||||
RTC_DCHECK_EQ(0, rtc::AtomicOps::AcquireLoad(&g_rtc_histogram_called));
|
RTC_DCHECK_EQ(0, g_rtc_histogram_called.load(std::memory_order_acquire));
|
||||||
#endif
|
#endif
|
||||||
CreateMap();
|
CreateMap();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -112,7 +112,6 @@ rtc_library("video") {
|
|||||||
"../modules/video_coding/timing:inter_frame_delay",
|
"../modules/video_coding/timing:inter_frame_delay",
|
||||||
"../modules/video_coding/timing:timing_module",
|
"../modules/video_coding/timing:timing_module",
|
||||||
"../modules/video_processing",
|
"../modules/video_processing",
|
||||||
"../rtc_base:atomicops",
|
|
||||||
"../rtc_base:checks",
|
"../rtc_base:checks",
|
||||||
"../rtc_base:event_tracer",
|
"../rtc_base:event_tracer",
|
||||||
"../rtc_base:histogram_percentile_counter",
|
"../rtc_base:histogram_percentile_counter",
|
||||||
|
|||||||
@ -26,7 +26,6 @@
|
|||||||
#include "call/rtp_transport_controller_send_interface.h"
|
#include "call/rtp_transport_controller_send_interface.h"
|
||||||
#include "call/video_send_stream.h"
|
#include "call/video_send_stream.h"
|
||||||
#include "modules/pacing/pacing_controller.h"
|
#include "modules/pacing/pacing_controller.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/experiments/alr_experiment.h"
|
#include "rtc_base/experiments/alr_experiment.h"
|
||||||
#include "rtc_base/experiments/field_trial_parser.h"
|
#include "rtc_base/experiments/field_trial_parser.h"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user