Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7738)

Unified Diff: content/renderer/media/audio_device.h

Issue 7157001: Implements AudioMessageFilter as member in RenderThread (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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...
class AudioDevice : public AudioMessageFilter::Delegate,
public base::DelegateSimpleThread::Delegate,
public base::RefCountedThreadSafe<AudioDevice> {
@@ -32,11 +31,12 @@
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,
- RenderCallback* callback);
+ RenderCallback* callback,
+ AudioMessageFilter* filter);
Chris Rogers 2011/06/14 22:57:10 Can't the AudioDevice simply call AudioMessageFilt
henrika_dont_use 2011/06/15 15:16:39 Good point. Will make such a change and upload for
virtual ~AudioDevice();
// Starts audio playback. Returns |true| on success.
@@ -56,14 +56,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 +66,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);
+ 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 +89,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 +110,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_;

Powered by Google App Engine
This is Rietveld 408576698