aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Möller <nisse@webrtc.org>2019-01-08 13:47:12 +0100
committerCommit Bot <commit-bot@chromium.org>2019-01-09 13:49:19 +0000
commitac63ac7193e4b344d3c682afce9bc1488d6df573 (patch)
tree80d7a5ff2cecb689966182d57450fd8723a9d0ef
parent8b6995b3d4ae65a3e730d50c00b9fe41d6dbe407 (diff)
downloadwebrtc-ac63ac7193e4b344d3c682afce9bc1488d6df573.tar.gz
Update refcounting of AudioState to use rtc::RefCountedObject
Bug: webrtc:8270, webrtc:9305 Change-Id: I9ce76ebe358b3f34d2ad424861a396a0dc2a537d Reviewed-on: https://webrtc-review.googlesource.com/c/116486 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#26177}
-rw-r--r--audio/audio_state.cc18
-rw-r--r--audio/audio_state.h10
-rw-r--r--audio/audio_state_unittest.cc21
3 files changed, 14 insertions, 35 deletions
diff --git a/audio/audio_state.cc b/audio/audio_state.cc
index 7d473ae631..ce9e89480f 100644
--- a/audio/audio_state.cc
+++ b/audio/audio_state.cc
@@ -17,9 +17,9 @@
#include "absl/memory/memory.h"
#include "audio/audio_receive_stream.h"
#include "modules/audio_device/include/audio_device.h"
-#include "rtc_base/atomicops.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
+#include "rtc_base/refcountedobject.h"
#include "rtc_base/thread.h"
namespace webrtc {
@@ -168,20 +168,6 @@ void AudioState::SetStereoChannelSwapping(bool enable) {
audio_transport_.SetStereoChannelSwapping(enable);
}
-// Reference count; implementation copied from rtc::RefCountedObject.
-void AudioState::AddRef() const {
- rtc::AtomicOps::Increment(&ref_count_);
-}
-
-// Reference count; implementation copied from rtc::RefCountedObject.
-rtc::RefCountReleaseStatus AudioState::Release() const {
- if (rtc::AtomicOps::Decrement(&ref_count_) == 0) {
- delete this;
- return rtc::RefCountReleaseStatus::kDroppedLastRef;
- }
- return rtc::RefCountReleaseStatus::kOtherRefsRemained;
-}
-
void AudioState::UpdateAudioTransportWithSendingStreams() {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
std::vector<webrtc::AudioSendStream*> sending_streams;
@@ -199,6 +185,6 @@ void AudioState::UpdateAudioTransportWithSendingStreams() {
rtc::scoped_refptr<AudioState> AudioState::Create(
const AudioState::Config& config) {
- return rtc::scoped_refptr<AudioState>(new internal::AudioState(config));
+ return new rtc::RefCountedObject<internal::AudioState>(config);
}
} // namespace webrtc
diff --git a/audio/audio_state.h b/audio/audio_state.h
index 9e302c4007..f633f2ffcd 100644
--- a/audio/audio_state.h
+++ b/audio/audio_state.h
@@ -30,7 +30,7 @@ class AudioReceiveStream;
namespace internal {
-class AudioState final : public webrtc::AudioState {
+class AudioState : public webrtc::AudioState {
public:
explicit AudioState(const AudioState::Config& config);
~AudioState() override;
@@ -60,10 +60,6 @@ class AudioState final : public webrtc::AudioState {
void RemoveSendingStream(webrtc::AudioSendStream* stream);
private:
- // rtc::RefCountInterface implementation.
- void AddRef() const override;
- rtc::RefCountReleaseStatus Release() const override;
-
void UpdateAudioTransportWithSendingStreams();
rtc::ThreadChecker thread_checker_;
@@ -72,10 +68,6 @@ class AudioState final : public webrtc::AudioState {
bool recording_enabled_ = true;
bool playout_enabled_ = true;
- // Reference count; implementation copied from rtc::RefCountedObject.
- // TODO(nisse): Use RefCountedObject or RefCountedBase instead.
- mutable volatile int ref_count_ = 0;
-
// Transports mixed audio from the mixer to the audio device and
// recorded audio to the sending streams.
AudioTransportImpl audio_transport_;
diff --git a/audio/audio_state_unittest.cc b/audio/audio_state_unittest.cc
index dc622df00d..790b6433dd 100644
--- a/audio/audio_state_unittest.cc
+++ b/audio/audio_state_unittest.cc
@@ -98,14 +98,14 @@ TEST(AudioStateTest, Create) {
TEST(AudioStateTest, ConstructDestruct) {
ConfigHelper helper;
- std::unique_ptr<internal::AudioState> audio_state(
- new internal::AudioState(helper.config()));
+ rtc::scoped_refptr<internal::AudioState> audio_state(
+ new rtc::RefCountedObject<internal::AudioState>(helper.config()));
}
TEST(AudioStateTest, RecordedAudioArrivesAtSingleStream) {
ConfigHelper helper;
- std::unique_ptr<internal::AudioState> audio_state(
- new internal::AudioState(helper.config()));
+ rtc::scoped_refptr<internal::AudioState> audio_state(
+ new rtc::RefCountedObject<internal::AudioState>(helper.config()));
MockAudioSendStream stream;
audio_state->AddSendingStream(&stream, 8000, 2);
@@ -142,8 +142,8 @@ TEST(AudioStateTest, RecordedAudioArrivesAtSingleStream) {
TEST(AudioStateTest, RecordedAudioArrivesAtMultipleStreams) {
ConfigHelper helper;
- std::unique_ptr<internal::AudioState> audio_state(
- new internal::AudioState(helper.config()));
+ rtc::scoped_refptr<internal::AudioState> audio_state(
+ new rtc::RefCountedObject<internal::AudioState>(helper.config()));
MockAudioSendStream stream_1;
MockAudioSendStream stream_2;
@@ -196,8 +196,9 @@ TEST(AudioStateTest, EnableChannelSwap) {
constexpr size_t kNumChannels = 2;
ConfigHelper helper;
- std::unique_ptr<internal::AudioState> audio_state(
- new internal::AudioState(helper.config()));
+ rtc::scoped_refptr<internal::AudioState> audio_state(
+ new rtc::RefCountedObject<internal::AudioState>(helper.config()));
+
audio_state->SetStereoChannelSwapping(true);
MockAudioSendStream stream;
@@ -227,8 +228,8 @@ TEST(AudioStateTest, InputLevelStats) {
constexpr size_t kNumChannels = 1;
ConfigHelper helper;
- std::unique_ptr<internal::AudioState> audio_state(
- new internal::AudioState(helper.config()));
+ rtc::scoped_refptr<internal::AudioState> audio_state(
+ new rtc::RefCountedObject<internal::AudioState>(helper.config()));
// Push a silent buffer -> Level stats should be zeros except for duration.
{