Commit 5dd7073f authored by tzik's avatar tzik Committed by Commit Bot

Refactor WebAudioBus impl

This CL contains:
 1. Remove unneeded WebAudioBusPrivate and casts from/to it.
 2. Avoid applying AdoptRef twice for single AudioBus.
 3. Use nullptr instead of 0 around WebAudioBus

The main part is (2). An upcoming change bans multiple invocation of
WTF::AdoptRef for a single object, and as its preparation, this CL
removes a failing case.

Bug: 763844
Tbr: rtoy@chromium.org
Change-Id: I362a83cd03d49b77ef9e4d81544bd5c7a9b2bc5e
Reviewed-on: https://chromium-review.googlesource.com/686088
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505296}
parent 72f1f3a9
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
namespace blink { namespace blink {
class WebAudioBusPrivate : public AudioBus {};
void WebAudioBus::Initialize(unsigned number_of_channels, void WebAudioBus::Initialize(unsigned number_of_channels,
size_t length, size_t length,
double sample_rate) { double sample_rate) {
...@@ -38,10 +36,9 @@ void WebAudioBus::Initialize(unsigned number_of_channels, ...@@ -38,10 +36,9 @@ void WebAudioBus::Initialize(unsigned number_of_channels,
audio_bus->SetSampleRate(sample_rate); audio_bus->SetSampleRate(sample_rate);
if (private_) if (private_)
(static_cast<AudioBus*>(private_))->Deref(); private_->Deref();
audio_bus->Ref(); private_ = audio_bus.LeakRef();
private_ = static_cast<WebAudioBusPrivate*>(audio_bus.get());
} }
void WebAudioBus::ResizeSmaller(size_t new_length) { void WebAudioBus::ResizeSmaller(size_t new_length) {
...@@ -54,8 +51,8 @@ void WebAudioBus::ResizeSmaller(size_t new_length) { ...@@ -54,8 +51,8 @@ void WebAudioBus::ResizeSmaller(size_t new_length) {
void WebAudioBus::Reset() { void WebAudioBus::Reset() {
if (private_) { if (private_) {
(static_cast<AudioBus*>(private_))->Deref(); private_->Deref();
private_ = 0; private_ = nullptr;
} }
} }
...@@ -79,14 +76,15 @@ double WebAudioBus::SampleRate() const { ...@@ -79,14 +76,15 @@ double WebAudioBus::SampleRate() const {
float* WebAudioBus::ChannelData(unsigned channel_index) { float* WebAudioBus::ChannelData(unsigned channel_index) {
if (!private_) if (!private_)
return 0; return nullptr;
DCHECK_LT(channel_index, NumberOfChannels()); DCHECK_LT(channel_index, NumberOfChannels());
return private_->Channel(channel_index)->MutableData(); return private_->Channel(channel_index)->MutableData();
} }
RefPtr<AudioBus> WebAudioBus::Release() { RefPtr<AudioBus> WebAudioBus::Release() {
RefPtr<AudioBus> audio_bus(WTF::AdoptRef(static_cast<AudioBus*>(private_))); RefPtr<AudioBus> audio_bus(private_);
private_ = 0; private_->Deref();
private_ = nullptr;
return audio_bus; return audio_bus;
} }
......
...@@ -44,7 +44,7 @@ class AudioBus; ...@@ -44,7 +44,7 @@ class AudioBus;
// //
class BLINK_PLATFORM_EXPORT WebAudioBus { class BLINK_PLATFORM_EXPORT WebAudioBus {
public: public:
WebAudioBus() : private_(0) {} WebAudioBus() {}
~WebAudioBus() { Reset(); } ~WebAudioBus() { Reset(); }
// Initialize() allocates memory of the given length for the given number of // Initialize() allocates memory of the given length for the given number of
...@@ -76,7 +76,7 @@ class BLINK_PLATFORM_EXPORT WebAudioBus { ...@@ -76,7 +76,7 @@ class BLINK_PLATFORM_EXPORT WebAudioBus {
WebAudioBus(const WebAudioBus&); WebAudioBus(const WebAudioBus&);
void operator=(const WebAudioBus&); void operator=(const WebAudioBus&);
AudioBus* private_; AudioBus* private_ = nullptr;
}; };
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment