Chromium Code Reviews| Index: media/audio/audio_input_device.h |
| diff --git a/media/audio/audio_input_device.h b/media/audio/audio_input_device.h |
| index edefdf16962f225ab395c777779cf235d3885442..02bd14c7fc424a835ed0f7ccf8405953f3731837 100644 |
| --- a/media/audio/audio_input_device.h |
| +++ b/media/audio/audio_input_device.h |
| @@ -11,8 +11,8 @@ |
| // ^ ^ |
| // | | |
| // v IPC v |
| -// AudioInputRendererHost <---------> AudioInputIPCDelegate |
| -// ^ (impl in AudioInputMessageFilter) |
| +// AudioInputRendererHost <-----------> AudioInputIPC |
| +// ^ (AudioInputMessageFilter) |
| // | |
| // v |
| // AudioInputDeviceManager |
| @@ -62,7 +62,6 @@ |
| #define MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_ |
| #include <string> |
| -#include <vector> |
| #include "base/basictypes.h" |
| #include "base/compiler_specific.h" |
| @@ -79,6 +78,7 @@ namespace media { |
| // TODO(henrika): This class is based on the AudioOutputDevice class and it has |
| // many components in common. Investigate potential for re-factoring. |
| +// See http://crbug.com/179597. |
| // TODO(henrika): Add support for event handling (e.g. OnStateChanged, |
| // OnCaptureStopped etc.) and ensure that we can deliver these notifications |
| // to any clients using this class. |
| @@ -87,7 +87,8 @@ class MEDIA_EXPORT AudioInputDevice |
| NON_EXPORTED_BASE(public AudioInputIPCDelegate), |
| NON_EXPORTED_BASE(public ScopedLoopObserver) { |
| public: |
| - AudioInputDevice(AudioInputIPC* ipc, |
| + // NOTE: Clients must call Initialize() before using. |
| + AudioInputDevice(scoped_ptr<AudioInputIPC> ipc, |
| const scoped_refptr<base::MessageLoopProxy>& io_loop); |
| // AudioCapturerSource implementation. |
| @@ -101,6 +102,9 @@ class MEDIA_EXPORT AudioInputDevice |
| virtual void SetAutomaticGainControl(bool enabled) OVERRIDE; |
| protected: |
| + friend class base::RefCountedThreadSafe<AudioInputDevice>; |
| + virtual ~AudioInputDevice(); |
| + |
| // Methods called on IO thread ---------------------------------------------- |
| // AudioInputIPCDelegate implementation. |
| virtual void OnStreamCreated(base::SharedMemoryHandle handle, |
| @@ -112,17 +116,22 @@ class MEDIA_EXPORT AudioInputDevice |
| virtual void OnDeviceReady(const std::string& device_id) OVERRIDE; |
| virtual void OnIPCClosed() OVERRIDE; |
| - friend class base::RefCountedThreadSafe<AudioInputDevice>; |
| - virtual ~AudioInputDevice(); |
| - |
| private: |
| + // Note: The ordering of members in this enum is critical to correct behavior! |
|
palmer
2013/03/05 21:09:32
Maybe therefore assign them explicit values (IPC_C
miu
2013/03/06 22:36:52
C++ spec requires enum values assigned as 0, 1, 2,
|
| + enum State { |
| + IPC_CLOSED, // No more IPCs can take place. |
| + IDLE, // Not started. |
| + STARTING_DEVICE, // Waiting for OnDeviceReady() to be called back. |
| + CREATING_STREAM, // Waiting for OnStreamCreated() to be called back. |
| + RECORDING, // Receiving audio data. |
| + }; |
| + |
| // 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(); |
| void SetSessionIdOnIOThread(int session_id); |
| - void StartOnIOThread(); |
| + void StartUpOnIOThread(); |
| void ShutDownOnIOThread(); |
| void SetVolumeOnIOThread(double volume); |
| void SetAutomaticGainControlOnIOThread(bool enabled); |
| @@ -136,19 +145,19 @@ class MEDIA_EXPORT AudioInputDevice |
| CaptureCallback* callback_; |
| CaptureEventHandler* event_handler_; |
| - AudioInputIPC* ipc_; |
| + // A pointer to the IPC layer that takes care of sending requests over to |
| + // the AudioInputRendererHost. Only valid when state_ != IPC_CLOSED and must |
| + // only be accessed on the IO thread. |
| + scoped_ptr<AudioInputIPC> ipc_; |
| - // Our stream ID on the message filter. Only modified on the IO thread. |
| - int stream_id_; |
| + // Current state (must only be accessed from the IO thread). See comments for |
| + // State enum above. |
| + State state_; |
| // The media session ID used to identify which input device to be started. |
| // Only modified on the IO thread. |
| int session_id_; |
| - // State variable used to indicate it is waiting for a OnDeviceReady() |
| - // callback. Only modified on the IO thread. |
| - bool pending_device_ready_; |
| - |
| // Stores the Automatic Gain Control state. Default is false. |
| // Only modified on the IO thread. |
| bool agc_is_enabled_; |
| @@ -162,6 +171,14 @@ class MEDIA_EXPORT AudioInputDevice |
| AudioDeviceThread audio_thread_; |
| scoped_ptr<AudioInputDevice::AudioThreadCallback> audio_callback_; |
| + // Temporary hack to ignore OnStreamCreated() due to the user calling Stop() |
| + // so we don't start the audio thread pointing to a potentially freed |
| + // |callback_|. |
| + // |
| + // TODO(miu): Replace this by changing AudioCapturerSource to accept the |
| + // callback via Start(). See http://crbug.com/151051 for details. |
| + bool stopping_hack_; |
| + |
| DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); |
| }; |