Index: content/renderer/media/audio_device.h |
=================================================================== |
--- content/renderer/media/audio_device.h (revision 88939) |
+++ content/renderer/media/audio_device.h (working copy) |
@@ -10,15 +10,14 @@ |
#include "base/basictypes.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/message_loop.h" |
#include "base/shared_memory.h" |
#include "base/threading/simple_thread.h" |
#include "content/renderer/media/audio_message_filter.h" |
struct AudioParameters; |
-// Each instance of AudioDevice corresponds to one host stream. |
-// This class is not thread-safe, so its methods must be called from |
-// the same thread. |
+// TODO(henrika): add comments here... |
scherkus (not reviewing)
2011/06/16 21:56:22
want to add comments right away? don't see a reas
henrika_dont_use
2011/06/17 11:52:02
Done.
|
class AudioDevice : public AudioMessageFilter::Delegate, |
public base::DelegateSimpleThread::Delegate, |
public base::RefCountedThreadSafe<AudioDevice> { |
@@ -32,7 +31,7 @@ |
virtual ~RenderCallback() {} |
}; |
- // |buffer_size| is the number of sample-frames. |
+ // Methods called on creating thread ---------------------------------------- |
AudioDevice(size_t buffer_size, |
int channels, |
double sample_rate, |
@@ -56,14 +55,8 @@ |
double sample_rate() const { return sample_rate_; } |
size_t buffer_size() const { return buffer_size_; } |
- private: |
- // I/O thread backends to above functions. |
- void InitializeOnIOThread(const AudioParameters& params); |
- void StartOnIOThread(); |
- void ShutDownOnIOThread(); |
- void SetVolumeOnIOThread(double volume); |
- |
- // AudioMessageFilter::Delegate implementation. |
+ // Methods called on IO thread ---------------------------------------------- |
+ // AudioMessageFilter::Delegate methods, called by AudioMessageFilter. |
virtual void OnRequestPacket(AudioBuffersState buffers_state); |
virtual void OnStateChanged(AudioStreamState state); |
virtual void OnCreated(base::SharedMemoryHandle handle, uint32 length); |
@@ -72,6 +65,20 @@ |
uint32 length); |
virtual void OnVolume(double volume); |
+ private: |
+ // Methods called on IO thread ---------------------------------------------- |
+ // The following methods are tasks posted on the IO thread that needs to |
+ // be executed on that thread. They interact with AudioMessageFilter and |
+ // sends IPC messages on that thread. |
+ void InitializeTask(const AudioParameters& params); |
scherkus (not reviewing)
2011/06/16 21:56:22
instead of xxxTask suffix, I wonder if it'd be cle
henrika_dont_use
2011/06/17 11:52:02
Agree. Will change back. Used notation in existing
scherkus (not reviewing)
2011/06/17 17:50:10
We can get to that later :)
|
+ void StartTask(); |
+ void ShutDownTask(); |
+ void SetVolumeTask(double volume); |
+ |
+ // Method called on the audio thread ---------------------------------------- |
+ // Calls the client's callback for rendering audio. |
+ void FireRenderCallback(); |
+ |
// DelegateSimpleThread::Delegate implementation. |
virtual void Run(); |
@@ -81,8 +88,6 @@ |
int bits_per_sample_; |
double sample_rate_; |
- // Calls the client's callback for rendering audio. |
- void FireRenderCallback(); |
RenderCallback* callback_; |
// The client callback renders audio into here. |
@@ -104,12 +109,13 @@ |
base::SyncSocket* socket() { return socket_.get(); } |
void* shared_memory_data() { return shared_memory()->memory(); } |
- // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE |
- // I/O thread except to send messages and get the message loop. |
- static scoped_refptr<AudioMessageFilter> filter_; |
+ // MessageFilter used to send/receive IPC. Only accessed on the IO thread. |
+ scoped_refptr<AudioMessageFilter> filter_; |
- // Our ID on the message filter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD |
- // or else you could race with the initialize function which sets it. |
+ // Message loop for the IO thread. |
+ MessageLoop* io_loop_; |
+ |
+ // Our ID on the message filter. Only modified on the IO thread. |
int32 stream_id_; |
scoped_ptr<base::SharedMemory> shared_memory_; |