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

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

Issue 10790121: First step towards moving AudioDevice from content/ to media/audio. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update comments after closing ppapi bug Created 8 years, 5 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
« no previous file with comments | « content/renderer/media/audio_device_unittest.cc ('k') | content/renderer/media/audio_input_device.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/audio_input_device.h
diff --git a/content/renderer/media/audio_input_device.h b/content/renderer/media/audio_input_device.h
index 8ef72b7e277704866cce16215f96b760ab671ad3..cf05f85a6ad61c2567034c5d233e5a702fa8ff79 100644
--- a/content/renderer/media/audio_input_device.h
+++ b/content/renderer/media/audio_input_device.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Low-latency audio capturing unit utilizing audio input stream provided
-// by browser process through IPC.
+// Low-latency audio capturing class utilizing audio input stream provided
+// by a server (browser) process by use of an IPC interface.
//
// Relationship of classes:
//
@@ -11,58 +11,51 @@
// ^ ^
// | |
// v IPC v
-// AudioInputRendererHost <---------> AudioInputMessageFilter
-// ^
+// AudioInputRendererHost <---------> media::AudioInputIPCDelegate
+// ^ (impl in AudioInputMessageFilter)
// |
// v
// AudioInputDeviceManager
//
// Transportation of audio samples from the browser to the render process
-// is done by using shared memory in combination with a sync socket pair
-// to generate a low latency transport. The AudioInputDevice user registers
-// an AudioInputDevice::CaptureCallback at construction and will be called
-// by the AudioInputDevice with recorded audio from the underlying audio layers.
+// is done by using shared memory in combination with a SyncSocket.
+// The AudioInputDevice user registers an AudioInputDevice::CaptureCallback by
+// calling Initialize(). The callback will be called with recorded audio from
+// the underlying audio layers.
// The session ID is used by the AudioInputRendererHost to start the device
// referenced by this ID.
//
// State sequences:
//
-// Task [IO thread] IPC [IO thread]
-//
// Sequence where session_id has not been set using SetDevice():
-// Start -> InitializeOnIOThread -----> AudioInputHostMsg_CreateStream ------->
-// <- OnLowLatencyCreated <- AudioInputMsg_NotifyLowLatencyStreamCreated <-
-// ---> StartOnIOThread ---------> AudioInputHostMsg_PlayStream -------->
+// ('<-' signifies callbacks, -> signifies calls made by AudioInputDevice)
+// Start -> InitializeOnIOThread -> CreateStream ->
+// <- OnStreamCreated <-
+// -> StartOnIOThread -> PlayStream ->
//
// Sequence where session_id has been set using SetDevice():
-// Start -> InitializeOnIOThread --> AudioInputHostMsg_StartDevice --->
-// <---- OnStarted <-------------- AudioInputMsg_NotifyDeviceStarted <----
-// -> OnDeviceReady ------------> AudioInputHostMsg_CreateStream ------->
-// <- OnLowLatencyCreated <- AudioInputMsg_NotifyLowLatencyStreamCreated <-
-// ---> StartOnIOThread ---------> AudioInputHostMsg_PlayStream -------->
+// Start -> InitializeOnIOThread -> StartDevice ->
+// <- OnDeviceReady <-
+// -> CreateStream ->
+// <- OnStreamCreated <-
+// -> StartOnIOThread -> PlayStream ->
//
// AudioInputDevice::Capture => low latency audio transport on audio thread =>
// |
-// Stop --> ShutDownOnIOThread ------> AudioInputHostMsg_CloseStream -> Close
+// Stop --> ShutDownOnIOThread ------> CloseStream -> Close
//
-// This class utilizes three threads during its lifetime, namely:
+// This class depends on two threads to function:
//
-// 1. Creating thread.
-// Must be the main render thread. Start and Stop should be called on
-// this thread.
-// 2. IO thread.
-// The thread within which this class receives all the IPC messages and
-// IPC communications can only happen in this thread.
-// 3. Audio transport thread.
-// Responsible for calling the CaptrureCallback and feed audio samples from
-// the audio layer in the browser process using sync sockets and shared
-// memory.
+// 1. An IO thread.
+// This thread is used to asynchronously process Start/Stop etc operations
+// that are available via the public interface. The public methods are
+// asynchronous and simply post a task to the IO thread to actually perform
+// the work.
+// 2. Audio transport thread.
+// Responsible for calling the CaptureCallback and feed audio samples from
+// the server side audio layer using a socket and shared memory.
//
// Implementation notes:
-//
-// - Start() is asynchronous/non-blocking.
-// - Stop() is synchronous/blocking.
-// - SetDevice() is asynchronous/non-blocking.
// - The user must call Stop() before deleting the class instance.
#ifndef CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_
@@ -87,7 +80,7 @@
// OnCaptureStopped etc.) and ensure that we can deliver these notifications
// to any clients using this class.
class CONTENT_EXPORT AudioInputDevice
- : public AudioInputMessageFilter::Delegate,
+ : NON_EXPORTED_BASE(public media::AudioInputIPCDelegate),
NON_EXPORTED_BASE(public ScopedLoopObserver),
public base::RefCountedThreadSafe<AudioInputDevice> {
public:
@@ -116,10 +109,14 @@ class CONTENT_EXPORT AudioInputDevice
virtual ~CaptureEventHandler() {}
};
- // Methods called on main render thread -------------------------------------
- AudioInputDevice(const media::AudioParameters& params,
- CaptureCallback* callback,
- CaptureEventHandler* event_handler);
+ AudioInputDevice(media::AudioInputIPC* ipc,
+ const scoped_refptr<base::MessageLoopProxy>& io_loop);
+
+ // Initializes the AudioInputDevice. This method must be called before
+ // any other methods can be used.
+ void Initialize(const media::AudioParameters& params,
+ CaptureCallback* callback,
+ CaptureEventHandler* event_handler);
// Specify the |session_id| to query which device to use. This method is
// asynchronous/non-blocking.
@@ -138,38 +135,27 @@ class CONTENT_EXPORT AudioInputDevice
// Returns |true| on success.
bool SetVolume(double volume);
- // Gets the capture volume scaling, with range [0.0, 1.0] inclusive.
- // Returns |true| on success.
- bool GetVolume(double* volume);
-
- double sample_rate() const {
- return audio_parameters_.sample_rate();
- }
-
- int buffer_size() const {
- return audio_parameters_.frames_per_buffer();
- }
-
// Sets the Automatic Gain Control state to on or off.
// This method must be called before Start(). It will not have any effect
// if it is called while capturing has already started.
void SetAutomaticGainControl(bool enabled);
+ protected:
// Methods called on IO thread ----------------------------------------------
- // AudioInputMessageFilter::Delegate impl., called by AudioInputMessageFilter.
+ // media::AudioInputIPCDelegate implementation.
virtual void OnStreamCreated(base::SharedMemoryHandle handle,
base::SyncSocket::Handle socket_handle,
- uint32 length) OVERRIDE;
+ int length) OVERRIDE;
virtual void OnVolume(double volume) OVERRIDE;
- virtual void OnStateChanged(AudioStreamState state) OVERRIDE;
+ virtual void OnStateChanged(
+ media::AudioInputIPCDelegate::State state) OVERRIDE;
virtual void OnDeviceReady(const std::string& device_id) OVERRIDE;
+ virtual void OnIPCClosed() OVERRIDE;
- protected:
+ friend class base::RefCountedThreadSafe<AudioInputDevice>;
virtual ~AudioInputDevice();
private:
- friend class base::RefCountedThreadSafe<AudioInputDevice>;
-
// 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
@@ -181,26 +167,19 @@ class CONTENT_EXPORT AudioInputDevice
void SetVolumeOnIOThread(double volume);
void SetAutomaticGainControlOnIOThread(bool enabled);
- void Send(IPC::Message* message);
-
// MessageLoop::DestructionObserver implementation for the IO loop.
// If the IO loop dies before we do, we shut down the audio thread from here.
virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
- // Format
media::AudioParameters audio_parameters_;
CaptureCallback* callback_;
CaptureEventHandler* event_handler_;
- // The current volume scaling [0.0, 1.0] of the audio stream.
- double volume_;
-
- // Cached audio input message filter (lives on the main render thread).
- scoped_refptr<AudioInputMessageFilter> filter_;
+ media::AudioInputIPC* ipc_;
// Our stream ID on the message filter. Only modified on the IO thread.
- int32 stream_id_;
+ int stream_id_;
// The media session ID used to identify which input device to be started.
// Only modified on the IO thread.
« no previous file with comments | « content/renderer/media/audio_device_unittest.cc ('k') | content/renderer/media/audio_input_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698