Commit 9840d2cf authored by tommi@chromium.org's avatar tommi@chromium.org

Move AudioDevice and AudioInputDevice to media.

This CL does the following:
* Move AudioDevice, AudioInputDevice out of content, into media/audio.
* ...and a couple of dependent classes: AudioDeviceThread and ScopedLoopObserver.
* ...and the unit test.
* Renamed AudioDevice -> AudioOutputDevice
* Moved the classes into the media namespace.
* Updated the unit test code as necessary.

Aside from the unit test*, there are minimal code changes.  Only what was required to make things build and work as before - mostly just adding or removing "media::".

* The unit test changes were to add expectations for AddDelegate/RemoveDelegate since previously a mock class was inheriting from AudioMessageFilter and not the IPC interface.
Review URL: https://chromiumcodereview.appspot.com/10834033

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148777 0039d316-1c4b-4281-b951-d872f2087c98
parent 0392ff47
...@@ -97,16 +97,10 @@ ...@@ -97,16 +97,10 @@
'renderer/java/java_bridge_dispatcher.h', 'renderer/java/java_bridge_dispatcher.h',
'renderer/load_progress_tracker.cc', 'renderer/load_progress_tracker.cc',
'renderer/load_progress_tracker.h', 'renderer/load_progress_tracker.h',
'renderer/media/audio_device.cc',
'renderer/media/audio_device.h',
'renderer/media/audio_device_factory.cc', 'renderer/media/audio_device_factory.cc',
'renderer/media/audio_device_factory.h', 'renderer/media/audio_device_factory.h',
'renderer/media/audio_device_thread.cc',
'renderer/media/audio_device_thread.h',
'renderer/media/audio_hardware.cc', 'renderer/media/audio_hardware.cc',
'renderer/media/audio_hardware.h', 'renderer/media/audio_hardware.h',
'renderer/media/audio_input_device.cc',
'renderer/media/audio_input_device.h',
'renderer/media/audio_input_message_filter.cc', 'renderer/media/audio_input_message_filter.cc',
'renderer/media/audio_input_message_filter.h', 'renderer/media/audio_input_message_filter.h',
'renderer/media/audio_message_filter.cc', 'renderer/media/audio_message_filter.cc',
...@@ -132,8 +126,6 @@ ...@@ -132,8 +126,6 @@
'renderer/media/renderer_webaudiodevice_impl.h', 'renderer/media/renderer_webaudiodevice_impl.h',
'renderer/media/rtc_video_decoder.cc', 'renderer/media/rtc_video_decoder.cc',
'renderer/media/rtc_video_decoder.h', 'renderer/media/rtc_video_decoder.h',
'renderer/media/scoped_loop_observer.cc',
'renderer/media/scoped_loop_observer.h',
'renderer/media/stream_texture_factory_impl_android.cc', 'renderer/media/stream_texture_factory_impl_android.cc',
'renderer/media/stream_texture_factory_impl_android.h', 'renderer/media/stream_texture_factory_impl_android.h',
'renderer/media/video_capture_impl.cc', 'renderer/media/video_capture_impl.cc',
......
...@@ -332,7 +332,6 @@ ...@@ -332,7 +332,6 @@
'renderer/android/phone_number_detector_unittest.cc', 'renderer/android/phone_number_detector_unittest.cc',
'renderer/gpu/input_event_filter_unittest.cc', 'renderer/gpu/input_event_filter_unittest.cc',
'renderer/hyphenator/hyphenator_unittest.cc', 'renderer/hyphenator/hyphenator_unittest.cc',
'renderer/media/audio_device_unittest.cc',
'renderer/media/audio_message_filter_unittest.cc', 'renderer/media/audio_message_filter_unittest.cc',
'renderer/media/audio_renderer_mixer_manager_unittest.cc', 'renderer/media/audio_renderer_mixer_manager_unittest.cc',
'renderer/media/capture_video_decoder_unittest.cc', 'renderer/media/capture_video_decoder_unittest.cc',
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
#include "base/logging.h" #include "base/logging.h"
#include "content/common/child_process.h" #include "content/common/child_process.h"
#include "content/renderer/media/audio_device.h"
#include "content/renderer/media/audio_input_device.h"
#include "content/renderer/media/audio_input_message_filter.h" #include "content/renderer/media/audio_input_message_filter.h"
#include "content/renderer/media/audio_message_filter.h" #include "content/renderer/media/audio_message_filter.h"
#include "media/audio/audio_input_device.h"
#include "media/audio/audio_output_device.h"
namespace content { namespace content {
...@@ -22,18 +22,18 @@ media::AudioRendererSink* AudioDeviceFactory::NewOutputDevice() { ...@@ -22,18 +22,18 @@ media::AudioRendererSink* AudioDeviceFactory::NewOutputDevice() {
if (factory_) if (factory_)
device = factory_->CreateOutputDevice(); device = factory_->CreateOutputDevice();
return device ? device : new AudioDevice( return device ? device : new media::AudioOutputDevice(
AudioMessageFilter::Get(), AudioMessageFilter::Get(),
ChildProcess::current()->io_message_loop()->message_loop_proxy()); ChildProcess::current()->io_message_loop()->message_loop_proxy());
} }
// static // static
AudioInputDevice* AudioDeviceFactory::NewInputDevice() { media::AudioInputDevice* AudioDeviceFactory::NewInputDevice() {
AudioInputDevice* device = NULL; media::AudioInputDevice* device = NULL;
if (factory_) if (factory_)
device = factory_->CreateInputDevice(); device = factory_->CreateInputDevice();
return device ? device : new AudioInputDevice( return device ? device : new media::AudioInputDevice(
AudioInputMessageFilter::Get(), AudioInputMessageFilter::Get(),
ChildProcess::current()->io_message_loop()->message_loop_proxy()); ChildProcess::current()->io_message_loop()->message_loop_proxy());
} }
......
...@@ -9,28 +9,26 @@ ...@@ -9,28 +9,26 @@
#include "content/common/content_export.h" #include "content/common/content_export.h"
namespace media { namespace media {
class AudioInputDevice;
class AudioRendererSink; class AudioRendererSink;
} }
class AudioInputDevice;
namespace content { namespace content {
// A factory for creating AudioRendererSinks. There is a global factory // A factory for creating AudioRendererSinks. There is a global factory
// function that can be installed for the purposes of testing to provide // function that can be installed for the purposes of testing to provide
// a specialized AudioRendererSink class. // a specialized AudioRendererSink class.
// This class uses the same pattern as content::RenderViewHostFactory.
class CONTENT_EXPORT AudioDeviceFactory { class CONTENT_EXPORT AudioDeviceFactory {
public: public:
// Creates an AudioRendererSink using the currently registered factory, // Creates an AudioRendererSink using the currently registered factory,
// or the default one if no factory is registered. Ownership of the returned // or the default one if no factory is registered. Ownership of the returned
// pointer will be passed to the caller. // pointer will be passed to the caller.
static media::AudioRendererSink* NewOutputDevice(); static media::AudioRendererSink* NewOutputDevice();
// TODO(henrika): Update AudioInputDevice to inherit from an interface // TODO(henrika): Update AudioInputDevice to inherit from an interface
// similar to AudioRendererSink, but for input. Same for the callback // similar to AudioRendererSink, but for input. Same for the callback
// interfaces. // interfaces.
static AudioInputDevice* NewInputDevice(); static media::AudioInputDevice* NewInputDevice();
protected: protected:
AudioDeviceFactory(); AudioDeviceFactory();
...@@ -41,7 +39,7 @@ class CONTENT_EXPORT AudioDeviceFactory { ...@@ -41,7 +39,7 @@ class CONTENT_EXPORT AudioDeviceFactory {
// If the return value of either of these function is NULL, we fall back // If the return value of either of these function is NULL, we fall back
// on the default implementation. // on the default implementation.
virtual media::AudioRendererSink* CreateOutputDevice() = 0; virtual media::AudioRendererSink* CreateOutputDevice() = 0;
virtual AudioInputDevice* CreateInputDevice() = 0; virtual media::AudioInputDevice* CreateInputDevice() = 0;
private: private:
// The current globally registered factory. This is NULL when we should // The current globally registered factory. This is NULL when we should
......
...@@ -29,8 +29,8 @@ namespace content { ...@@ -29,8 +29,8 @@ namespace content {
// TODO(dalecurtis): Right now we require AudioParameters to be an exact match // TODO(dalecurtis): Right now we require AudioParameters to be an exact match
// when we should be able to ignore bits per channel since we're only dealing // when we should be able to ignore bits per channel since we're only dealing
// with floats. However, bits per channel is currently used to interleave the // with floats. However, bits per channel is currently used to interleave the
// audio data by AudioDevice::AudioThreadCallback::Process for consumption via // audio data by AudioOutputDevice::AudioThreadCallback::Process for consumption
// the shared memory. See http://crbug.com/114700. // via the shared memory. See http://crbug.com/114700.
class CONTENT_EXPORT AudioRendererMixerManager { class CONTENT_EXPORT AudioRendererMixerManager {
public: public:
// Construct an instance using the given audio hardware configuration. // Construct an instance using the given audio hardware configuration.
......
...@@ -34,7 +34,7 @@ class MockAudioRenderSinkFactory : public AudioDeviceFactory { ...@@ -34,7 +34,7 @@ class MockAudioRenderSinkFactory : public AudioDeviceFactory {
return sink; return sink;
} }
virtual AudioInputDevice* CreateInputDevice() OVERRIDE { virtual media::AudioInputDevice* CreateInputDevice() OVERRIDE {
ADD_FAILURE(); ADD_FAILURE();
return NULL; return NULL;
} }
...@@ -45,8 +45,8 @@ class MockAudioRenderSinkFactory : public AudioDeviceFactory { ...@@ -45,8 +45,8 @@ class MockAudioRenderSinkFactory : public AudioDeviceFactory {
class AudioRendererMixerManagerTest : public testing::Test { class AudioRendererMixerManagerTest : public testing::Test {
public: public:
AudioRendererMixerManagerTest() { AudioRendererMixerManagerTest() {
// We don't want to deal with instantiating a real AudioDevice since it's // We don't want to deal with instantiating a real AudioOutputDevice since
// not important to our testing, so use a mock AudioDeviceFactory. // it's not important to our testing, so use a mock AudioDeviceFactory.
mock_sink_factory_.reset(new MockAudioRenderSinkFactory()); mock_sink_factory_.reset(new MockAudioRenderSinkFactory());
manager_.reset(new AudioRendererMixerManager(kSampleRate, kBufferSize)); manager_.reset(new AudioRendererMixerManager(kSampleRate, kBufferSize));
} }
......
...@@ -83,7 +83,7 @@ void RenderAudioSourceProvider::provideInput( ...@@ -83,7 +83,7 @@ void RenderAudioSourceProvider::provideInput(
} else { } else {
// Provide silence if the source is not running. // Provide silence if the source is not running.
for (size_t i = 0; i < audio_data.size(); ++i) for (size_t i = 0; i < audio_data.size(); ++i)
memset(audio_data[i], 0, sizeof(float) * number_of_frames); memset(audio_data[i], 0, sizeof(audio_data[0]) * number_of_frames);
} }
} }
......
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
// WebKit::WebAudioSourceProvider <---> media::AudioRendererSink // WebKit::WebAudioSourceProvider <---> media::AudioRendererSink
// //
// RenderAudioSourceProvider is a "sink" of audio, and uses a default // RenderAudioSourceProvider is a "sink" of audio, and uses a default
// AudioDevice if a client has not explicitly been set. // AudioOutputDevice if a client has not explicitly been set.
// //
// WebKit optionally sets a client, and then periodically calls provideInput() // WebKit optionally sets a client, and then periodically calls provideInput()
// to render a certain number of audio sample-frames. provideInput() // to render a certain number of audio sample-frames. provideInput()
// uses the renderer to get this data, and then massages it into the form // uses the renderer to get this data, and then massages it into the form
// required by provideInput(). In this case, the default AudioDevice // required by provideInput(). In this case, the default AudioOutputDevice
// is no longer used. // is no longer used.
// //
// THREAD SAFETY: // THREAD SAFETY:
......
...@@ -423,7 +423,8 @@ int32_t WebRtcAudioDeviceImpl::Init() { ...@@ -423,7 +423,8 @@ int32_t WebRtcAudioDeviceImpl::Init() {
// TODO(henrika): it could be possible to allow one of the directions (input // TODO(henrika): it could be possible to allow one of the directions (input
// or output) to use a non-supported rate. As an example: if only the // or output) to use a non-supported rate. As an example: if only the
// output rate is OK, we could finalize Init() and only set up an AudioDevice. // output rate is OK, we could finalize Init() and only set up an
// AudioOutputDevice.
// Ask the browser for the default audio output hardware sample-rate. // Ask the browser for the default audio output hardware sample-rate.
// This request is based on a synchronous IPC message. // This request is based on a synchronous IPC message.
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "base/message_loop_proxy.h" #include "base/message_loop_proxy.h"
#include "base/time.h" #include "base/time.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/renderer/media/audio_input_device.h" #include "media/audio/audio_input_device.h"
#include "media/base/audio_renderer_sink.h" #include "media/base/audio_renderer_sink.h"
#include "third_party/webrtc/modules/audio_device/main/interface/audio_device.h" #include "third_party/webrtc/modules/audio_device/main/interface/audio_device.h"
...@@ -63,7 +63,8 @@ ...@@ -63,7 +63,8 @@
// implements the RecordedDataIsAvailable() and NeedMorePlayData() callbacks. // implements the RecordedDataIsAvailable() and NeedMorePlayData() callbacks.
// //
// Init() // Init()
// Creates and initializes the AudioDevice and AudioInputDevice objects. // Creates and initializes the AudioOutputDevice and AudioInputDevice
// objects.
// //
// SetAGC(true) // SetAGC(true)
// Enables the adaptive analog mode of the AGC which ensures that a // Enables the adaptive analog mode of the AGC which ensures that a
...@@ -73,7 +74,7 @@ ...@@ -73,7 +74,7 @@
// Media example: // Media example:
// //
// When the underlying audio layer wants data samples to be played out, the // When the underlying audio layer wants data samples to be played out, the
// AudioDevice::RenderCallback() will be called, which in turn uses the // AudioOutputDevice::RenderCallback() will be called, which in turn uses the
// registered webrtc::AudioTransport callback and gets the data to be played // registered webrtc::AudioTransport callback and gets the data to be played
// out from the webrtc::VoiceEngine. // out from the webrtc::VoiceEngine.
// //
...@@ -203,9 +204,9 @@ ...@@ -203,9 +204,9 @@
// //
class CONTENT_EXPORT WebRtcAudioDeviceImpl class CONTENT_EXPORT WebRtcAudioDeviceImpl
: NON_EXPORTED_BASE(public webrtc::AudioDeviceModule), : NON_EXPORTED_BASE(public webrtc::AudioDeviceModule),
public media::AudioRendererSink::RenderCallback, NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback),
public AudioInputDevice::CaptureCallback, NON_EXPORTED_BASE(public media::AudioInputDevice::CaptureCallback),
public AudioInputDevice::CaptureEventHandler { NON_EXPORTED_BASE(public media::AudioInputDevice::CaptureEventHandler) {
public: public:
// Methods called on main render thread. // Methods called on main render thread.
WebRtcAudioDeviceImpl(); WebRtcAudioDeviceImpl();
...@@ -403,7 +404,7 @@ class CONTENT_EXPORT WebRtcAudioDeviceImpl ...@@ -403,7 +404,7 @@ class CONTENT_EXPORT WebRtcAudioDeviceImpl
scoped_refptr<base::MessageLoopProxy> render_loop_; scoped_refptr<base::MessageLoopProxy> render_loop_;
// Provides access to the native audio input layer in the browser process. // Provides access to the native audio input layer in the browser process.
scoped_refptr<AudioInputDevice> audio_input_device_; scoped_refptr<media::AudioInputDevice> audio_input_device_;
// Provides access to the native audio output layer in the browser process. // Provides access to the native audio output layer in the browser process.
scoped_refptr<media::AudioRendererSink> audio_output_device_; scoped_refptr<media::AudioRendererSink> audio_output_device_;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "media/audio/audio_output_ipc.h" #include "media/audio/audio_output_ipc.h"
#include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/plugin_delegate.h"
namespace media{ namespace media {
class AudioParameters; class AudioParameters;
} }
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "content/public/renderer/content_renderer_client.h" #include "content/public/renderer/content_renderer_client.h"
#include "content/renderer/dom_storage/webstoragenamespace_impl.h" #include "content/renderer/dom_storage/webstoragenamespace_impl.h"
#include "content/renderer/gamepad_shared_memory_reader.h" #include "content/renderer/gamepad_shared_memory_reader.h"
#include "content/renderer/media/audio_device.h"
#include "content/renderer/media/audio_hardware.h" #include "content/renderer/media/audio_hardware.h"
#include "content/renderer/media/renderer_webaudiodevice_impl.h" #include "content/renderer/media/renderer_webaudiodevice_impl.h"
#include "content/renderer/render_thread_impl.h" #include "content/renderer/render_thread_impl.h"
...@@ -34,6 +33,7 @@ ...@@ -34,6 +33,7 @@
#include "content/renderer/websharedworkerrepository_impl.h" #include "content/renderer/websharedworkerrepository_impl.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "ipc/ipc_sync_message_filter.h" #include "ipc/ipc_sync_message_filter.h"
#include "media/audio/audio_output_device.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebBlobRegistry.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebBlobRegistry.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
#include "content/renderer/media/audio_device_factory.h" #include "content/renderer/media/audio_device_factory.h"
#include "content/renderer/media/audio_hardware.h" #include "content/renderer/media/audio_hardware.h"
#include "content/renderer/media/audio_input_message_filter.h"
#include "content/renderer/media/audio_message_filter.h" #include "content/renderer/media/audio_message_filter.h"
#include "content/renderer/media/webrtc_audio_device_impl.h" #include "content/renderer/media/webrtc_audio_device_impl.h"
#include "content/renderer/render_process.h" #include "content/renderer/render_process.h"
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/renderer/media/audio_device_thread.h" #include "media/audio/audio_device_thread.h"
#include <algorithm>
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
...@@ -13,6 +15,8 @@ ...@@ -13,6 +15,8 @@
using base::PlatformThread; using base::PlatformThread;
namespace media {
// The actual worker thread implementation. It's very bare bones and much // The actual worker thread implementation. It's very bare bones and much
// simpler than SimpleThread (no synchronization in Start, etc) and supports // simpler than SimpleThread (no synchronization in Start, etc) and supports
// joining the thread handle asynchronously via a provided message loop even // joining the thread handle asynchronously via a provided message loop even
...@@ -170,7 +174,7 @@ void AudioDeviceThread::Thread::Run() { ...@@ -170,7 +174,7 @@ void AudioDeviceThread::Thread::Run() {
// AudioDeviceThread::Callback implementation // AudioDeviceThread::Callback implementation
AudioDeviceThread::Callback::Callback( AudioDeviceThread::Callback::Callback(
const media::AudioParameters& audio_parameters, const AudioParameters& audio_parameters,
base::SharedMemoryHandle memory, int memory_length) base::SharedMemoryHandle memory, int memory_length)
: audio_parameters_(audio_parameters), : audio_parameters_(audio_parameters),
samples_per_ms_(audio_parameters.sample_rate() / 1000), samples_per_ms_(audio_parameters.sample_rate() / 1000),
...@@ -200,3 +204,5 @@ void AudioDeviceThread::Callback::InitializeOnAudioThread() { ...@@ -200,3 +204,5 @@ void AudioDeviceThread::Callback::InitializeOnAudioThread() {
audio_data_.push_back(channel_data); audio_data_.push_back(channel_data);
} }
} }
} // namespace media.
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_THREAD_H_ #ifndef MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_
#define CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_THREAD_H_ #define MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_
#include <vector> #include <vector>
...@@ -12,11 +12,13 @@ ...@@ -12,11 +12,13 @@
#include "base/shared_memory.h" #include "base/shared_memory.h"
#include "base/sync_socket.h" #include "base/sync_socket.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "content/common/content_export.h" #include "media/base/media_export.h"
#include "media/audio/audio_parameters.h" #include "media/audio/audio_parameters.h"
class MessageLoop; class MessageLoop;
namespace media {
// Data transfer between browser and render process uses a combination // Data transfer between browser and render process uses a combination
// of sync sockets and shared memory. To read from the socket and render // of sync sockets and shared memory. To read from the socket and render
// data, we use a worker thread, a.k.a. the AudioDeviceThread, which reads // data, we use a worker thread, a.k.a. the AudioDeviceThread, which reads
...@@ -24,16 +26,16 @@ class MessageLoop; ...@@ -24,16 +26,16 @@ class MessageLoop;
// audio thread via the AudioDeviceThread::Callback interface/class. // audio thread via the AudioDeviceThread::Callback interface/class.
// For more details see the documentation in audio_device.h. // For more details see the documentation in audio_device.h.
// //
// TODO(tommi): Multiple Audio[Input]Device instances should be able to share // TODO(tommi): Multiple audio input/output device instances should be able to
// the same thread instead of spinning one per instance. // share the same thread instead of spinning one per instance.
class CONTENT_EXPORT AudioDeviceThread { class MEDIA_EXPORT AudioDeviceThread {
public: public:
// This is the callback interface/base class that Audio[Input]Device // This is the callback interface/base class that Audio[Output|Input]Device
// implements to render input/output data. The callback happens on the // implements to render input/output data. The callbacks run on the
// AudioDevice thread. // thread owned by AudioDeviceThread.
class Callback { class Callback {
public: public:
Callback(const media::AudioParameters& audio_parameters, Callback(const AudioParameters& audio_parameters,
base::SharedMemoryHandle memory, base::SharedMemoryHandle memory,
int memory_length); int memory_length);
virtual ~Callback(); virtual ~Callback();
...@@ -52,7 +54,7 @@ class CONTENT_EXPORT AudioDeviceThread { ...@@ -52,7 +54,7 @@ class CONTENT_EXPORT AudioDeviceThread {
// Protected so that derived classes can access directly. // Protected so that derived classes can access directly.
// The variables are 'const' since values are calculated/set in the // The variables are 'const' since values are calculated/set in the
// constructor and must never change. // constructor and must never change.
const media::AudioParameters audio_parameters_; const AudioParameters audio_parameters_;
const int samples_per_ms_; const int samples_per_ms_;
const int bytes_per_ms_; const int bytes_per_ms_;
...@@ -104,4 +106,6 @@ class CONTENT_EXPORT AudioDeviceThread { ...@@ -104,4 +106,6 @@ class CONTENT_EXPORT AudioDeviceThread {
DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread); DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread);
}; };
#endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_THREAD_H_ } // namespace media.
#endif // MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/renderer/media/audio_input_device.h" #include "media/audio/audio_input_device.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/message_loop.h" #include "base/message_loop.h"
...@@ -11,13 +11,18 @@ ...@@ -11,13 +11,18 @@
#include "media/audio/audio_manager_base.h" #include "media/audio/audio_manager_base.h"
#include "media/audio/audio_util.h" #include "media/audio/audio_util.h"
namespace media {
AudioInputDevice::CaptureCallback::~CaptureCallback() {}
AudioInputDevice::CaptureEventHandler::~CaptureEventHandler() {}
// Takes care of invoking the capture callback on the audio thread. // Takes care of invoking the capture callback on the audio thread.
// An instance of this class is created for each capture stream in // An instance of this class is created for each capture stream in
// OnLowLatencyCreated(). // OnLowLatencyCreated().
class AudioInputDevice::AudioThreadCallback class AudioInputDevice::AudioThreadCallback
: public AudioDeviceThread::Callback { : public AudioDeviceThread::Callback {
public: public:
AudioThreadCallback(const media::AudioParameters& audio_parameters, AudioThreadCallback(const AudioParameters& audio_parameters,
base::SharedMemoryHandle memory, base::SharedMemoryHandle memory,
int memory_length, int memory_length,
CaptureCallback* capture_callback); CaptureCallback* capture_callback);
...@@ -34,7 +39,7 @@ class AudioInputDevice::AudioThreadCallback ...@@ -34,7 +39,7 @@ class AudioInputDevice::AudioThreadCallback
}; };
AudioInputDevice::AudioInputDevice( AudioInputDevice::AudioInputDevice(
media::AudioInputIPC* ipc, AudioInputIPC* ipc,
const scoped_refptr<base::MessageLoopProxy>& io_loop) const scoped_refptr<base::MessageLoopProxy>& io_loop)
: ScopedLoopObserver(io_loop), : ScopedLoopObserver(io_loop),
callback_(NULL), callback_(NULL),
...@@ -47,7 +52,7 @@ AudioInputDevice::AudioInputDevice( ...@@ -47,7 +52,7 @@ AudioInputDevice::AudioInputDevice(
CHECK(ipc_); CHECK(ipc_);
} }
void AudioInputDevice::Initialize(const media::AudioParameters& params, void AudioInputDevice::Initialize(const AudioParameters& params,
CaptureCallback* callback, CaptureCallback* callback,
CaptureEventHandler* event_handler) { CaptureEventHandler* event_handler) {
DCHECK(!callback_); DCHECK(!callback_);
...@@ -137,7 +142,7 @@ void AudioInputDevice::OnVolume(double volume) { ...@@ -137,7 +142,7 @@ void AudioInputDevice::OnVolume(double volume) {
} }
void AudioInputDevice::OnStateChanged( void AudioInputDevice::OnStateChanged(
media::AudioInputIPCDelegate::State state) { AudioInputIPCDelegate::State state) {
DCHECK(message_loop()->BelongsToCurrentThread()); DCHECK(message_loop()->BelongsToCurrentThread());
// Do nothing if the stream has been closed. // Do nothing if the stream has been closed.
...@@ -145,7 +150,7 @@ void AudioInputDevice::OnStateChanged( ...@@ -145,7 +150,7 @@ void AudioInputDevice::OnStateChanged(
return; return;
switch (state) { switch (state) {
case media::AudioInputIPCDelegate::kStopped: case AudioInputIPCDelegate::kStopped:
// TODO(xians): Should we just call ShutDownOnIOThread here instead? // TODO(xians): Should we just call ShutDownOnIOThread here instead?
ipc_->RemoveDelegate(stream_id_); ipc_->RemoveDelegate(stream_id_);
...@@ -158,10 +163,10 @@ void AudioInputDevice::OnStateChanged( ...@@ -158,10 +163,10 @@ void AudioInputDevice::OnStateChanged(
stream_id_ = 0; stream_id_ = 0;
pending_device_ready_ = false; pending_device_ready_ = false;
break; break;
case media::AudioInputIPCDelegate::kRecording: case AudioInputIPCDelegate::kRecording:
NOTIMPLEMENTED(); NOTIMPLEMENTED();
break; break;
case media::AudioInputIPCDelegate::kError: case AudioInputIPCDelegate::kError:
DLOG(WARNING) << "AudioInputDevice::OnStateChanged(kError)"; DLOG(WARNING) << "AudioInputDevice::OnStateChanged(kError)";
// Don't dereference the callback object if the audio thread // Don't dereference the callback object if the audio thread
// is stopped or stopping. That could mean that the callback // is stopped or stopping. That could mean that the callback
...@@ -225,7 +230,7 @@ void AudioInputDevice::InitializeOnIOThread() { ...@@ -225,7 +230,7 @@ void AudioInputDevice::InitializeOnIOThread() {
// and create the stream when getting a OnDeviceReady() callback. // and create the stream when getting a OnDeviceReady() callback.
if (!session_id_) { if (!session_id_) {
ipc_->CreateStream(stream_id_, audio_parameters_, ipc_->CreateStream(stream_id_, audio_parameters_,
media::AudioManagerBase::kDefaultDeviceId, agc_is_enabled_); AudioManagerBase::kDefaultDeviceId, agc_is_enabled_);
} else { } else {
ipc_->StartDevice(stream_id_, session_id_); ipc_->StartDevice(stream_id_, session_id_);
pending_device_ready_ = true; pending_device_ready_ = true;
...@@ -294,7 +299,7 @@ void AudioInputDevice::WillDestroyCurrentMessageLoop() { ...@@ -294,7 +299,7 @@ void AudioInputDevice::WillDestroyCurrentMessageLoop() {
// AudioInputDevice::AudioThreadCallback // AudioInputDevice::AudioThreadCallback
AudioInputDevice::AudioThreadCallback::AudioThreadCallback( AudioInputDevice::AudioThreadCallback::AudioThreadCallback(
const media::AudioParameters& audio_parameters, const AudioParameters& audio_parameters,
base::SharedMemoryHandle memory, base::SharedMemoryHandle memory,
int memory_length, int memory_length,
CaptureCallback* capture_callback) CaptureCallback* capture_callback)
...@@ -313,10 +318,10 @@ void AudioInputDevice::AudioThreadCallback::Process(int pending_data) { ...@@ -313,10 +318,10 @@ void AudioInputDevice::AudioThreadCallback::Process(int pending_data) {
// The shared memory represents parameters, size of the data buffer and the // The shared memory represents parameters, size of the data buffer and the
// actual data buffer containing audio data. Map the memory into this // actual data buffer containing audio data. Map the memory into this
// structure and parse out parameters and the data area. // structure and parse out parameters and the data area.
media::AudioInputBuffer* buffer = AudioInputBuffer* buffer =
reinterpret_cast<media::AudioInputBuffer*>(shared_memory_.memory()); reinterpret_cast<AudioInputBuffer*>(shared_memory_.memory());
DCHECK_EQ(buffer->params.size, DCHECK_EQ(buffer->params.size,
memory_length_ - sizeof(media::AudioInputBufferParameters)); memory_length_ - sizeof(AudioInputBufferParameters));
double volume = buffer->params.volume; double volume = buffer->params.volume;
int audio_delay_milliseconds = pending_data / bytes_per_ms_; int audio_delay_milliseconds = pending_data / bytes_per_ms_;
...@@ -328,12 +333,12 @@ void AudioInputDevice::AudioThreadCallback::Process(int pending_data) { ...@@ -328,12 +333,12 @@ void AudioInputDevice::AudioThreadCallback::Process(int pending_data) {
// with nominal range -1.0 -> +1.0. // with nominal range -1.0 -> +1.0.
for (int channel_index = 0; channel_index < audio_parameters_.channels(); for (int channel_index = 0; channel_index < audio_parameters_.channels();
++channel_index) { ++channel_index) {
media::DeinterleaveAudioChannel(memory, DeinterleaveAudioChannel(memory,
audio_data_[channel_index], audio_data_[channel_index],
audio_parameters_.channels(), audio_parameters_.channels(),
channel_index, channel_index,
bytes_per_sample, bytes_per_sample,
number_of_frames); number_of_frames);
} }
// Deliver captured data to the client in floating point format // Deliver captured data to the client in floating point format
...@@ -341,3 +346,5 @@ void AudioInputDevice::AudioThreadCallback::Process(int pending_data) { ...@@ -341,3 +346,5 @@ void AudioInputDevice::AudioThreadCallback::Process(int pending_data) {
capture_callback_->Capture(audio_data_, number_of_frames, capture_callback_->Capture(audio_data_, number_of_frames,
audio_delay_milliseconds, volume); audio_delay_milliseconds, volume);
} }
} // namespace media
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
// ^ ^ // ^ ^
// | | // | |
// v IPC v // v IPC v
// AudioInputRendererHost <---------> media::AudioInputIPCDelegate // AudioInputRendererHost <---------> AudioInputIPCDelegate
// ^ (impl in AudioInputMessageFilter) // ^ (impl in AudioInputMessageFilter)
// | // |
// v // v
...@@ -58,8 +58,8 @@ ...@@ -58,8 +58,8 @@
// Implementation notes: // Implementation notes:
// - The user must call Stop() before deleting the class instance. // - The user must call Stop() before deleting the class instance.
#ifndef CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_ #ifndef MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_
#define CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_ #define MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -68,23 +68,25 @@ ...@@ -68,23 +68,25 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/shared_memory.h" #include "base/shared_memory.h"
#include "content/common/content_export.h" #include "media/audio/audio_device_thread.h"
#include "content/renderer/media/audio_device_thread.h" #include "media/audio/audio_input_ipc.h"
#include "content/renderer/media/audio_input_message_filter.h"
#include "content/renderer/media/scoped_loop_observer.h"
#include "media/audio/audio_parameters.h" #include "media/audio/audio_parameters.h"
#include "media/audio/scoped_loop_observer.h"
#include "media/base/media_export.h"
// TODO(henrika): This class is based on the AudioDevice class and it has namespace media {
// TODO(henrika): This class is based on the AudioOutputDevice class and it has
// many components in common. Investigate potential for re-factoring. // many components in common. Investigate potential for re-factoring.
// TODO(henrika): Add support for event handling (e.g. OnStateChanged, // TODO(henrika): Add support for event handling (e.g. OnStateChanged,
// OnCaptureStopped etc.) and ensure that we can deliver these notifications // OnCaptureStopped etc.) and ensure that we can deliver these notifications
// to any clients using this class. // to any clients using this class.
class CONTENT_EXPORT AudioInputDevice class MEDIA_EXPORT AudioInputDevice
: NON_EXPORTED_BASE(public media::AudioInputIPCDelegate), : NON_EXPORTED_BASE(public AudioInputIPCDelegate),
NON_EXPORTED_BASE(public ScopedLoopObserver), NON_EXPORTED_BASE(public ScopedLoopObserver),
public base::RefCountedThreadSafe<AudioInputDevice> { public base::RefCountedThreadSafe<AudioInputDevice> {
public: public:
class CONTENT_EXPORT CaptureCallback { class MEDIA_EXPORT CaptureCallback {
public: public:
virtual void Capture(const std::vector<float*>& audio_data, virtual void Capture(const std::vector<float*>& audio_data,
int number_of_frames, int number_of_frames,
...@@ -92,10 +94,10 @@ class CONTENT_EXPORT AudioInputDevice ...@@ -92,10 +94,10 @@ class CONTENT_EXPORT AudioInputDevice
double volume) = 0; double volume) = 0;
virtual void OnCaptureError() = 0; virtual void OnCaptureError() = 0;
protected: protected:
virtual ~CaptureCallback() {} virtual ~CaptureCallback();
}; };
class CONTENT_EXPORT CaptureEventHandler { class MEDIA_EXPORT CaptureEventHandler {
public: public:
// Notification to the client that the device with the specific |device_id| // Notification to the client that the device with the specific |device_id|
// has been started. // has been started.
...@@ -106,15 +108,15 @@ class CONTENT_EXPORT AudioInputDevice ...@@ -106,15 +108,15 @@ class CONTENT_EXPORT AudioInputDevice
virtual void OnDeviceStopped() = 0; virtual void OnDeviceStopped() = 0;
protected: protected:
virtual ~CaptureEventHandler() {} virtual ~CaptureEventHandler();
}; };
AudioInputDevice(media::AudioInputIPC* ipc, AudioInputDevice(AudioInputIPC* ipc,
const scoped_refptr<base::MessageLoopProxy>& io_loop); const scoped_refptr<base::MessageLoopProxy>& io_loop);
// Initializes the AudioInputDevice. This method must be called before // Initializes the AudioInputDevice. This method must be called before
// any other methods can be used. // any other methods can be used.
void Initialize(const media::AudioParameters& params, void Initialize(const AudioParameters& params,
CaptureCallback* callback, CaptureCallback* callback,
CaptureEventHandler* event_handler); CaptureEventHandler* event_handler);
...@@ -141,13 +143,13 @@ class CONTENT_EXPORT AudioInputDevice ...@@ -141,13 +143,13 @@ class CONTENT_EXPORT AudioInputDevice
protected: protected:
// Methods called on IO thread ---------------------------------------------- // Methods called on IO thread ----------------------------------------------
// media::AudioInputIPCDelegate implementation. // AudioInputIPCDelegate implementation.
virtual void OnStreamCreated(base::SharedMemoryHandle handle, virtual void OnStreamCreated(base::SharedMemoryHandle handle,
base::SyncSocket::Handle socket_handle, base::SyncSocket::Handle socket_handle,
int length) OVERRIDE; int length) OVERRIDE;
virtual void OnVolume(double volume) OVERRIDE; virtual void OnVolume(double volume) OVERRIDE;
virtual void OnStateChanged( virtual void OnStateChanged(
media::AudioInputIPCDelegate::State state) OVERRIDE; AudioInputIPCDelegate::State state) OVERRIDE;
virtual void OnDeviceReady(const std::string& device_id) OVERRIDE; virtual void OnDeviceReady(const std::string& device_id) OVERRIDE;
virtual void OnIPCClosed() OVERRIDE; virtual void OnIPCClosed() OVERRIDE;
...@@ -170,12 +172,12 @@ class CONTENT_EXPORT AudioInputDevice ...@@ -170,12 +172,12 @@ class CONTENT_EXPORT AudioInputDevice
// If the IO loop dies before we do, we shut down the audio thread from here. // If the IO loop dies before we do, we shut down the audio thread from here.
virtual void WillDestroyCurrentMessageLoop() OVERRIDE; virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
media::AudioParameters audio_parameters_; AudioParameters audio_parameters_;
CaptureCallback* callback_; CaptureCallback* callback_;
CaptureEventHandler* event_handler_; CaptureEventHandler* event_handler_;
media::AudioInputIPC* ipc_; AudioInputIPC* ipc_;
// Our stream ID on the message filter. Only modified on the IO thread. // Our stream ID on the message filter. Only modified on the IO thread.
int stream_id_; int stream_id_;
...@@ -204,4 +206,6 @@ class CONTENT_EXPORT AudioInputDevice ...@@ -204,4 +206,6 @@ class CONTENT_EXPORT AudioInputDevice
DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice);
}; };
#endif // CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_ } // namespace media
#endif // MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_
...@@ -7,17 +7,17 @@ ...@@ -7,17 +7,17 @@
// //
// Relationship of classes. // Relationship of classes.
// //
// AudioOutputController AudioDevice // AudioOutputController AudioOutputDevice
// ^ ^ // ^ ^
// | | // | |
// v IPC v // v IPC v
// AudioRendererHost <---------> AudioMessageFilter // AudioRendererHost <---------> AudioOutputIPC (AudioMessageFilter)
// //
// Transportation of audio samples from the render to the browser process // Transportation of audio samples from the render to the browser process
// is done by using shared memory in combination with a sync socket pair // is done by using shared memory in combination with a sync socket pair
// to generate a low latency transport. The AudioDevice user registers an // to generate a low latency transport. The AudioOutputDevice user registers an
// AudioDevice::RenderCallback at construction and will be polled by the // AudioOutputDevice::RenderCallback at construction and will be polled by the
// AudioDevice for audio to be played out by the underlying audio layers. // AudioOutputDevice for audio to be played out by the underlying audio layers.
// //
// State sequences. // State sequences.
// //
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
// (note that Play() / Pause() sequences before OnStreamCreated are // (note that Play() / Pause() sequences before OnStreamCreated are
// deferred until OnStreamCreated, with the last valid state being used) // deferred until OnStreamCreated, with the last valid state being used)
// //
// AudioDevice::Render => audio transport on audio thread => // AudioOutputDevice::Render => audio transport on audio thread =>
// | // |
// Stop --> ShutDownOnIOThread --------> CloseStream -> Close // Stop --> ShutDownOnIOThread --------> CloseStream -> Close
// //
...@@ -53,41 +53,32 @@ ...@@ -53,41 +53,32 @@
// memory. // memory.
// //
// Implementation notes: // Implementation notes:
//
// - Start() is asynchronous/non-blocking.
// - Stop() is asynchronous/non-blocking.
// - Play() is asynchronous/non-blocking.
// - Pause() is asynchronous/non-blocking.
// - The user must call Stop() before deleting the class instance. // - The user must call Stop() before deleting the class instance.
#ifndef CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_
#define CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ #define MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/shared_memory.h" #include "base/shared_memory.h"
#include "content/common/content_export.h" #include "media/base/media_export.h"
#include "content/renderer/media/audio_device_thread.h" #include "media/audio/audio_device_thread.h"
#include "content/renderer/media/scoped_loop_observer.h"
#include "media/audio/audio_output_ipc.h" #include "media/audio/audio_output_ipc.h"
#include "media/audio/audio_parameters.h" #include "media/audio/audio_parameters.h"
#include "media/audio/scoped_loop_observer.h"
#include "media/base/audio_renderer_sink.h" #include "media/base/audio_renderer_sink.h"
namespace media { namespace media {
class AudioParameters;
}
class CONTENT_EXPORT AudioDevice class MEDIA_EXPORT AudioOutputDevice
: NON_EXPORTED_BASE(public media::AudioRendererSink), : NON_EXPORTED_BASE(public AudioRendererSink),
public media::AudioOutputIPCDelegate, public AudioOutputIPCDelegate,
NON_EXPORTED_BASE(public ScopedLoopObserver) { NON_EXPORTED_BASE(public ScopedLoopObserver) {
public: public:
// Methods called on main render thread -------------------------------------
// AudioRendererSink implementation. // AudioRendererSink implementation.
virtual void Initialize(const media::AudioParameters& params, virtual void Initialize(const AudioParameters& params,
RenderCallback* callback) OVERRIDE; RenderCallback* callback) OVERRIDE;
virtual void Start() OVERRIDE; virtual void Start() OVERRIDE;
virtual void Stop() OVERRIDE; virtual void Stop() OVERRIDE;
...@@ -97,32 +88,31 @@ class CONTENT_EXPORT AudioDevice ...@@ -97,32 +88,31 @@ class CONTENT_EXPORT AudioDevice
// Methods called on IO thread ---------------------------------------------- // Methods called on IO thread ----------------------------------------------
// AudioOutputIPCDelegate methods. // AudioOutputIPCDelegate methods.
virtual void OnStateChanged( virtual void OnStateChanged(AudioOutputIPCDelegate::State state) OVERRIDE;
media::AudioOutputIPCDelegate::State state) OVERRIDE;
virtual void OnStreamCreated(base::SharedMemoryHandle handle, virtual void OnStreamCreated(base::SharedMemoryHandle handle,
base::SyncSocket::Handle socket_handle, base::SyncSocket::Handle socket_handle,
int length) OVERRIDE; int length) OVERRIDE;
virtual void OnIPCClosed() OVERRIDE; virtual void OnIPCClosed() OVERRIDE;
// Creates an uninitialized AudioDevice. Clients must call Initialize() // Creates an uninitialized AudioOutputDevice. Clients must call Initialize()
// before using. // before using.
// TODO(tommi): When all dependencies on |content| have been removed // TODO(tommi): When all dependencies on |content| have been removed
// from AudioDevice, move this class over to media/audio. // from AudioOutputDevice, move this class over to media/audio.
AudioDevice(media::AudioOutputIPC* ipc, AudioOutputDevice(AudioOutputIPC* ipc,
const scoped_refptr<base::MessageLoopProxy>& io_loop); const scoped_refptr<base::MessageLoopProxy>& io_loop);
protected: protected:
// Magic required by ref_counted.h to avoid any code deleting the object // Magic required by ref_counted.h to avoid any code deleting the object
// accidentally while there are references to it. // accidentally while there are references to it.
friend class base::RefCountedThreadSafe<AudioDevice>; friend class base::RefCountedThreadSafe<AudioOutputDevice>;
virtual ~AudioDevice(); virtual ~AudioOutputDevice();
private: private:
// Methods called on IO thread ---------------------------------------------- // Methods called on IO thread ----------------------------------------------
// The following methods are tasks posted on the IO thread that needs to // The following methods are tasks posted on the IO thread that needs to
// be executed on that thread. They interact with AudioMessageFilter and // be executed on that thread. They interact with AudioMessageFilter and
// sends IPC messages on that thread. // sends IPC messages on that thread.
void CreateStreamOnIOThread(const media::AudioParameters& params); void CreateStreamOnIOThread(const AudioParameters& params);
void PlayOnIOThread(); void PlayOnIOThread();
void PauseOnIOThread(bool flush); void PauseOnIOThread(bool flush);
void ShutDownOnIOThread(); void ShutDownOnIOThread();
...@@ -132,13 +122,13 @@ class CONTENT_EXPORT AudioDevice ...@@ -132,13 +122,13 @@ class CONTENT_EXPORT AudioDevice
// If the IO loop dies before we do, we shut down the audio thread from here. // If the IO loop dies before we do, we shut down the audio thread from here.
virtual void WillDestroyCurrentMessageLoop() OVERRIDE; virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
media::AudioParameters audio_parameters_; AudioParameters audio_parameters_;
RenderCallback* callback_; RenderCallback* callback_;
// A pointer to the IPC layer that takes care of sending requests over to // A pointer to the IPC layer that takes care of sending requests over to
// the AudioRendererHost. // the AudioRendererHost.
media::AudioOutputIPC* ipc_; AudioOutputIPC* ipc_;
// Our stream ID on the message filter. Only accessed on the IO thread. // Our stream ID on the message filter. Only accessed on the IO thread.
// Must only be modified on the IO thread. // Must only be modified on the IO thread.
...@@ -160,10 +150,12 @@ class CONTENT_EXPORT AudioDevice ...@@ -160,10 +150,12 @@ class CONTENT_EXPORT AudioDevice
// guard to control stopping and starting the audio thread. // guard to control stopping and starting the audio thread.
base::Lock audio_thread_lock_; base::Lock audio_thread_lock_;
AudioDeviceThread audio_thread_; AudioDeviceThread audio_thread_;
scoped_ptr<AudioDevice::AudioThreadCallback> audio_callback_; scoped_ptr<AudioOutputDevice::AudioThreadCallback> audio_callback_;
DISALLOW_COPY_AND_ASSIGN(AudioDevice); DISALLOW_COPY_AND_ASSIGN(AudioOutputDevice);
}; };
#endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ } // namespace media
#endif // MEDIA_AUDIO_AUDIO_OUTPUT_DEVICE_H_
...@@ -14,7 +14,7 @@ namespace media { ...@@ -14,7 +14,7 @@ namespace media {
// Contains IPC notifications for the state of the server side // Contains IPC notifications for the state of the server side
// (AudioOutputController) audio state changes and when an AudioOutputController // (AudioOutputController) audio state changes and when an AudioOutputController
// has been created. Implemented by AudioDevice. // has been created. Implemented by AudioOutputDevice.
class MEDIA_EXPORT AudioOutputIPCDelegate { class MEDIA_EXPORT AudioOutputIPCDelegate {
public: public:
// Current status of the audio output stream in the browser process. Browser // Current status of the audio output stream in the browser process. Browser
...@@ -51,9 +51,9 @@ class MEDIA_EXPORT AudioOutputIPCDelegate { ...@@ -51,9 +51,9 @@ class MEDIA_EXPORT AudioOutputIPCDelegate {
virtual ~AudioOutputIPCDelegate(); virtual ~AudioOutputIPCDelegate();
}; };
// Provides IPC functionality for an AudioDevice. The implementation should // Provides IPC functionality for an AudioOutputDevice. The implementation
// asynchronously deliver the messages to an AudioOutputController object (or // should asynchronously deliver the messages to an AudioOutputController object
// create one in the case of CreateStream()), that may live in a separate // (or create one in the case of CreateStream()), that may live in a separate
// process. // process.
class MEDIA_EXPORT AudioOutputIPC { class MEDIA_EXPORT AudioOutputIPC {
public: public:
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <CoreAudio/AudioHardware.h> #include <CoreAudio/AudioHardware.h>
#include <string>
#include "base/mac/mac_logging.h" #include "base/mac/mac_logging.h"
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_cftyperef.h"
...@@ -282,7 +284,7 @@ AudioInputStream* AudioManagerMac::MakeLinearInputStream( ...@@ -282,7 +284,7 @@ AudioInputStream* AudioManagerMac::MakeLinearInputStream(
AudioInputStream* AudioManagerMac::MakeLowLatencyInputStream( AudioInputStream* AudioManagerMac::MakeLowLatencyInputStream(
const AudioParameters& params, const std::string& device_id) { const AudioParameters& params, const std::string& device_id) {
DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
// Gets the AudioDeviceID that refers to the AudioDevice with the device // Gets the AudioDeviceID that refers to the AudioOutputDevice with the device
// unique id. This AudioDeviceID is used to set the device for Audio Unit. // unique id. This AudioDeviceID is used to set the device for Audio Unit.
AudioDeviceID audio_device_id = GetAudioDeviceIdByUId(true, device_id); AudioDeviceID audio_device_id = GetAudioDeviceIdByUId(true, device_id);
AudioInputStream* stream = NULL; AudioInputStream* stream = NULL;
......
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/renderer/media/scoped_loop_observer.h" #include "media/audio/scoped_loop_observer.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
namespace media {
ScopedLoopObserver::ScopedLoopObserver( ScopedLoopObserver::ScopedLoopObserver(
const scoped_refptr<base::MessageLoopProxy>& loop) const scoped_refptr<base::MessageLoopProxy>& loop)
: loop_(loop) { : loop_(loop) {
...@@ -41,3 +43,5 @@ void ScopedLoopObserver::ObserveLoopDestruction(bool enable, ...@@ -41,3 +43,5 @@ void ScopedLoopObserver::ObserveLoopDestruction(bool enable,
if (done) if (done)
done->Signal(); done->Signal();
} }
} // namespace media.
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CONTENT_RENDERER_MEDIA_SCOPED_LOOP_OBSERVER_H_ #ifndef MEDIA_AUDIO_SCOPED_LOOP_OBSERVER_H_
#define CONTENT_RENDERER_MEDIA_SCOPED_LOOP_OBSERVER_H_ #define MEDIA_AUDIO_SCOPED_LOOP_OBSERVER_H_
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/message_loop.h" #include "base/message_loop.h"
...@@ -13,7 +13,9 @@ namespace base { ...@@ -13,7 +13,9 @@ namespace base {
class WaitableEvent; class WaitableEvent;
} }
// A common base class for AudioDevice and AudioInputDevice that manages namespace media {
// A common base class for AudioOutputDevice and AudioInputDevice that manages
// a message loop pointer and monitors it for destruction. If the object goes // a message loop pointer and monitors it for destruction. If the object goes
// out of scope before the message loop, the object will automatically remove // out of scope before the message loop, the object will automatically remove
// itself from the message loop's list of destruction observers. // itself from the message loop's list of destruction observers.
...@@ -43,4 +45,6 @@ class ScopedLoopObserver ...@@ -43,4 +45,6 @@ class ScopedLoopObserver
DISALLOW_COPY_AND_ASSIGN(ScopedLoopObserver); DISALLOW_COPY_AND_ASSIGN(ScopedLoopObserver);
}; };
#endif // CONTENT_RENDERER_MEDIA_SCOPED_LOOP_OBSERVER_H_ } // namespace media.
#endif // MEDIA_AUDIO_SCOPED_LOOP_OBSERVER_H_
...@@ -45,8 +45,12 @@ ...@@ -45,8 +45,12 @@
'audio/audio_buffers_state.h', 'audio/audio_buffers_state.h',
'audio/audio_device_name.cc', 'audio/audio_device_name.cc',
'audio/audio_device_name.h', 'audio/audio_device_name.h',
'audio/audio_device_thread.cc',
'audio/audio_device_thread.h',
'audio/audio_input_controller.cc', 'audio/audio_input_controller.cc',
'audio/audio_input_controller.h', 'audio/audio_input_controller.h',
'audio/audio_input_device.cc',
'audio/audio_input_device.h',
'audio/audio_input_ipc.cc', 'audio/audio_input_ipc.cc',
'audio/audio_input_ipc.h', 'audio/audio_input_ipc.h',
'audio/audio_input_stream_impl.cc', 'audio/audio_input_stream_impl.cc',
...@@ -58,6 +62,8 @@ ...@@ -58,6 +62,8 @@
'audio/audio_manager_base.h', 'audio/audio_manager_base.h',
'audio/audio_output_controller.cc', 'audio/audio_output_controller.cc',
'audio/audio_output_controller.h', 'audio/audio_output_controller.h',
'audio/audio_output_device.cc',
'audio/audio_output_device.h',
'audio/audio_output_dispatcher.cc', 'audio/audio_output_dispatcher.cc',
'audio/audio_output_dispatcher.h', 'audio/audio_output_dispatcher.h',
'audio/audio_output_dispatcher_impl.cc', 'audio/audio_output_dispatcher_impl.cc',
...@@ -112,6 +118,8 @@ ...@@ -112,6 +118,8 @@
'audio/pulse/pulse_output.h', 'audio/pulse/pulse_output.h',
'audio/sample_rates.cc', 'audio/sample_rates.cc',
'audio/sample_rates.h', 'audio/sample_rates.h',
'audio/scoped_loop_observer.cc',
'audio/scoped_loop_observer.h',
'audio/simple_sources.cc', 'audio/simple_sources.cc',
'audio/simple_sources.h', 'audio/simple_sources.h',
'audio/win/audio_low_latency_input_win.cc', 'audio/win/audio_low_latency_input_win.cc',
...@@ -677,6 +685,7 @@ ...@@ -677,6 +685,7 @@
'audio/audio_input_volume_unittest.cc', 'audio/audio_input_volume_unittest.cc',
'audio/audio_low_latency_input_output_unittest.cc', 'audio/audio_low_latency_input_output_unittest.cc',
'audio/audio_output_controller_unittest.cc', 'audio/audio_output_controller_unittest.cc',
'audio/audio_output_device_unittest.cc',
'audio/audio_output_proxy_unittest.cc', 'audio/audio_output_proxy_unittest.cc',
'audio/audio_parameters_unittest.cc', 'audio/audio_parameters_unittest.cc',
'audio/audio_util_unittest.cc', 'audio/audio_util_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment