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}
This commit is contained in:
Niels Möller 2019-01-08 13:47:12 +01:00 committed by Commit Bot
parent 8b6995b3d4
commit ac63ac7193
3 changed files with 14 additions and 35 deletions

View File

@ -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

View File

@ -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_;

View File

@ -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.
{