Commit c519da77 authored by rkc@chromium.org's avatar rkc@chromium.org

Add a ref counted audio bus.

For some applications where we need to keep multiple copies of the audio bus around (particularly in STL containers), a scoped_ptr to an audio bus isn't enough. For those rare situations, we're adding a RefCounted version of the AudioBus.

R=dalecurtis@chromium.org
BUG=None.

Review URL: https://codereview.chromium.org/388563005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282510 0039d316-1c4b-4281-b951-d872f2087c98
parent f3e77352
...@@ -340,4 +340,15 @@ void AudioBus::SwapChannels(int a, int b) { ...@@ -340,4 +340,15 @@ void AudioBus::SwapChannels(int a, int b) {
std::swap(channel_data_[a], channel_data_[b]); std::swap(channel_data_[a], channel_data_[b]);
} }
scoped_refptr<AudioBusRefCounted> AudioBusRefCounted::Create(
int channels, int frames) {
return scoped_refptr<AudioBusRefCounted>(
new AudioBusRefCounted(channels, frames));
}
AudioBusRefCounted::AudioBusRefCounted(int channels, int frames)
: AudioBus(channels, frames) {}
AudioBusRefCounted::~AudioBusRefCounted() {}
} // namespace media } // namespace media
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <vector> #include <vector>
#include "base/memory/aligned_memory.h" #include "base/memory/aligned_memory.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "media/base/media_export.h" #include "media/base/media_export.h"
...@@ -110,12 +111,13 @@ class MEDIA_EXPORT AudioBus { ...@@ -110,12 +111,13 @@ class MEDIA_EXPORT AudioBus {
virtual ~AudioBus(); virtual ~AudioBus();
private: protected:
AudioBus(int channels, int frames); AudioBus(int channels, int frames);
AudioBus(int channels, int frames, float* data); AudioBus(int channels, int frames, float* data);
AudioBus(int frames, const std::vector<float*>& channel_data); AudioBus(int frames, const std::vector<float*>& channel_data);
explicit AudioBus(int channels); explicit AudioBus(int channels);
private:
// Helper method for building |channel_data_| from a block of memory. |data| // Helper method for building |channel_data_| from a block of memory. |data|
// must be at least BlockSize() bytes in size. // must be at least BlockSize() bytes in size.
void BuildChannelData(int channels, int aligned_frame, float* data); void BuildChannelData(int channels, int aligned_frame, float* data);
...@@ -132,6 +134,24 @@ class MEDIA_EXPORT AudioBus { ...@@ -132,6 +134,24 @@ class MEDIA_EXPORT AudioBus {
DISALLOW_COPY_AND_ASSIGN(AudioBus); DISALLOW_COPY_AND_ASSIGN(AudioBus);
}; };
// RefCounted version of AudioBus. This is not meant for general use. Only use
// this when your lifetime requirements make it impossible to use an
// AudioBus scoped_ptr.
class MEDIA_EXPORT AudioBusRefCounted
: public media::AudioBus,
public base::RefCountedThreadSafe<AudioBusRefCounted> {
public:
static scoped_refptr<AudioBusRefCounted> Create(int channels, int frames);
private:
friend class base::RefCountedThreadSafe<AudioBusRefCounted>;
AudioBusRefCounted(int channels, int frames);
virtual ~AudioBusRefCounted();
DISALLOW_COPY_AND_ASSIGN(AudioBusRefCounted);
};
} // namespace media } // namespace media
#endif // MEDIA_BASE_AUDIO_BUS_H_ #endif // MEDIA_BASE_AUDIO_BUS_H_
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