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

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

Issue 7497025: refactor AudioInputDevice to remove race condition. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase + minor update Created 9 years, 4 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_input_device.h
===================================================================
--- content/renderer/media/audio_input_device.h (revision 95453)
+++ content/renderer/media/audio_input_device.h (working copy)
@@ -21,17 +21,22 @@
//
// State sequences.
//
-// Task [IO thread] IPC [IO thread]
+// [Capture thread] [IO thread]
//
-// Start -> InitializeOnIOThread -----> AudioInputHostMsg_CreateStream ------->
-// <- OnLowLatencyCreated <- AudioInputMsg_NotifyLowLatencyStreamCreated <-
-// ---> StartOnIOThread ---------> AudioInputHostMsg_PlayStream -------->
+// StartOnCaptureThread --> AddDelegateOnIOThread
+// DelegateAddedOnCaptureThread <--
+// --> AudioInputHostMsg_CreateStream
+// AudioInputMsg_NotifyLowLatencyStreamCreated
henrika_dont_use 2011/08/07 16:52:27 <-- ?
wjia(left Chromium) 2011/08/09 01:40:36 This is the message coming from browser process an
+// StartRecordingOnCaptureThread <-- OnLowLatencyCreated
+// --> AudioInputHostMsg_RecordStream
//
// AudioInputDevice::Capture => low latency audio transport on audio thread =>
// |
-// Stop --> ShutDownOnIOThread ------> AudioInputHostMsg_CloseStream -> Close
+// StopOnCaptureThread --> RemoveDelegateOnIOThread
+// DelegateRemovedOnCaptureThread <--
+// --> AudioInputHostMsg_CloseStream
//
-// This class utilizes three threads during its lifetime, namely:
+// This class utilizes four threads during its lifetime, namely:
// 1. Creating thread.
// Must be the main render thread. Start and Stop should be called on
// this thread.
@@ -42,6 +47,8 @@
// Responsible for calling the CaptrureCallback and feed audio samples from
// the audio layer in the browser process using sync sockets and shared
// memory.
+// 4. Capture thread.
+// The main working thread on which AudioInputDevice runs its methods.
#ifndef CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_
#define CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_
@@ -55,7 +62,7 @@
#include "base/threading/simple_thread.h"
#include "content/renderer/media/audio_input_message_filter.h"
-struct AudioParameters;
+class AudioInputDeviceEventHandler;
// TODO(henrika): This class is based on the AudioDevice class and it has
// many components in common. Investigate potential for re-factoring.
@@ -77,6 +84,8 @@
AudioInputDevice(size_t buffer_size,
int channels,
double sample_rate,
+ base::MessageLoopProxy* message_loop_proxy,
+ AudioInputDeviceEventHandler* event_handler,
CaptureCallback* callback);
virtual ~AudioInputDevice();
@@ -105,15 +114,26 @@
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 AudioInputMessageFilter and
- // sends IPC messages on that thread.
- void InitializeOnIOThread(const AudioParameters& params);
- void StartOnIOThread();
- void ShutDownOnIOThread();
- void SetVolumeOnIOThread(double volume);
+ enum State {
+ kStarting,
+ kStarted,
+ kPaused,
+ kStopped,
+ kStopping,
+ kError,
+ };
+ // Methods called on main working thread for AudioInputDevice----------------
henrika_dont_use 2011/08/07 16:52:27 e - (missing space)
wjia(left Chromium) 2011/08/09 01:40:36 Done.
+ // The following methods are tasks posted on capturethread that needs to
henrika_dont_use 2011/08/07 16:52:27 capture thread
wjia(left Chromium) 2011/08/09 01:40:36 Done.
+ // be executed on that thread.
+ void StartOnCaptureThread();
+ void StartRecordingOnCaptureThread(base::SharedMemoryHandle handle,
+ base::SyncSocket::Handle socket_handle,
+ uint32 length);
+ void StopOnCaptureThread();
+ void SetVolumeOnCaptureThread(double volume);
+ void OnDelegateAddedOnCaptureThread(int32 stream_id);
+ void OnDelegateRemovedOnCaptureThread();
void Send(IPC::Message* message);
// Method called on the audio thread ----------------------------------------
@@ -123,6 +143,15 @@
// DelegateSimpleThread::Delegate implementation.
virtual void Run();
+ // Add/Remove delegate on IO thread------------------------------------------
+ void AddDelegateOnIOThread();
+ void RemoveDelegateOnIOThread(int32 stream_id);
+
+ // IPC message stuff.
+ base::SharedMemory* shared_memory() { return shared_memory_.get(); }
+ base::SyncSocket* socket() { return socket_.get(); }
+ void* shared_memory_data() { return shared_memory()->memory(); }
+
// Format
size_t buffer_size_; // in sample-frames
int channels_;
@@ -130,6 +159,7 @@
double sample_rate_;
CaptureCallback* callback_;
+ AudioInputDeviceEventHandler* event_handler_;
// The client callback receives captured audio here.
std::vector<float*> audio_data_;
@@ -142,14 +172,14 @@
// The current volume scaling [0.0, 1.0] of the audio stream.
double volume_;
+ // The working thread for AudioInputDevice.
+ scoped_refptr<base::MessageLoopProxy> capture_message_loop_proxy_;
+
+ State state_;
+
// Callbacks for capturing audio occur on this thread.
scoped_ptr<base::DelegateSimpleThread> audio_thread_;
- // IPC message stuff.
- base::SharedMemory* shared_memory() { return shared_memory_.get(); }
- base::SyncSocket* socket() { return socket_.get(); }
- void* shared_memory_data() { return shared_memory()->memory(); }
-
// Cached audio input message filter (lives on the main render thread).
scoped_refptr<AudioInputMessageFilter> filter_;

Powered by Google App Engine
This is Rietveld 408576698