Chromium Code Reviews| Index: content/renderer/media/audio_input_device.cc |
| diff --git a/content/renderer/media/audio_input_device.cc b/content/renderer/media/audio_input_device.cc |
| index 6d8514375575339aa1be3108811e5e3fe52d1f27..1a7d6ca1165513aea949839b75cf249807356f68 100644 |
| --- a/content/renderer/media/audio_input_device.cc |
| +++ b/content/renderer/media/audio_input_device.cc |
| @@ -45,12 +45,12 @@ AudioInputDevice::AudioInputDevice(const media::AudioParameters& params, |
| audio_parameters_(params), |
| callback_(callback), |
| event_handler_(event_handler), |
| - volume_(1.0), |
| stream_id_(0), |
| session_id_(0), |
| pending_device_ready_(false), |
| agc_is_enabled_(false) { |
| - filter_ = RenderThreadImpl::current()->audio_input_message_filter(); |
| + // TODO(tommi): This needs to be updated to match AudioDevice. |
| + ipc_ = RenderThreadImpl::current()->audio_input_message_filter(); |
| } |
| void AudioInputDevice::SetDevice(int session_id) { |
| @@ -133,7 +133,8 @@ void AudioInputDevice::OnVolume(double volume) { |
| NOTIMPLEMENTED(); |
| } |
| -void AudioInputDevice::OnStateChanged(AudioStreamState state) { |
| +void AudioInputDevice::OnStateChanged( |
| + media::AudioInputDeviceIPCDelegate::State state) { |
| DCHECK(message_loop()->BelongsToCurrentThread()); |
| // Do nothing if the stream has been closed. |
| @@ -141,11 +142,9 @@ void AudioInputDevice::OnStateChanged(AudioStreamState state) { |
| return; |
| switch (state) { |
| - // TODO(xians): This should really be kAudioStreamStopped since the stream |
| - // has been closed at this point. |
| - case kAudioStreamPaused: |
| + case media::AudioInputDeviceIPCDelegate::kStopped: |
| // TODO(xians): Should we just call ShutDownOnIOThread here instead? |
| - filter_->RemoveDelegate(stream_id_); |
| + ipc_->RemoveDelegate(stream_id_); |
| audio_thread_.Stop(MessageLoop::current()); |
| audio_callback_.reset(); |
| @@ -156,10 +155,10 @@ void AudioInputDevice::OnStateChanged(AudioStreamState state) { |
| stream_id_ = 0; |
| pending_device_ready_ = false; |
| break; |
| - case kAudioStreamPlaying: |
| + case media::AudioInputDeviceIPCDelegate::kRecording: |
| NOTIMPLEMENTED(); |
| break; |
| - case kAudioStreamError: |
| + case media::AudioInputDeviceIPCDelegate::kError: |
| DLOG(WARNING) << "AudioInputDevice::OnStateChanged(kError)"; |
| // Don't dereference the callback object if the audio thread |
| // is stopped or stopping. That could mean that the callback |
| @@ -187,11 +186,11 @@ void AudioInputDevice::OnDeviceReady(const std::string& device_id) { |
| // If AudioInputDeviceManager returns an empty string, it means no device |
| // is ready for start. |
| if (device_id.empty()) { |
| - filter_->RemoveDelegate(stream_id_); |
| + ipc_->RemoveDelegate(stream_id_); |
| stream_id_ = 0; |
| } else { |
| - Send(new AudioInputHostMsg_CreateStream(stream_id_, audio_parameters_, |
| - device_id, agc_is_enabled_)); |
| + ipc_->CreateStream(stream_id_, audio_parameters_, device_id, |
| + agc_is_enabled_); |
|
scherkus (not reviewing)
2012/07/24 17:57:48
indenting
tommi (sloooow) - chröme
2012/07/25 13:46:17
Done.
|
| } |
| pending_device_ready_ = false; |
| @@ -200,6 +199,10 @@ void AudioInputDevice::OnDeviceReady(const std::string& device_id) { |
| event_handler_->OnDeviceStarted(device_id); |
| } |
| +void AudioInputDevice::OnIPCClosed() { |
| + ipc_ = NULL; |
|
scherkus (not reviewing)
2012/07/24 17:57:48
FYI we seem to guard against calling ipc_ with str
tommi (sloooow) - chröme
2012/07/25 13:46:17
The stream_id_ checks are not really meant to guar
|
| +} |
| + |
| AudioInputDevice::~AudioInputDevice() { |
| // TODO(henrika): The current design requires that the user calls |
| // Stop before deleting this class. |
| @@ -213,17 +216,15 @@ void AudioInputDevice::InitializeOnIOThread() { |
| if (stream_id_) |
| return; |
| - stream_id_ = filter_->AddDelegate(this); |
| + stream_id_ = ipc_->AddDelegate(this); |
| // If |session_id_| is not specified, it will directly create the stream; |
| // otherwise it will send a AudioInputHostMsg_StartDevice msg to the browser |
| // and create the stream when getting a OnDeviceReady() callback. |
| if (!session_id_) { |
| - Send(new AudioInputHostMsg_CreateStream( |
| - stream_id_, audio_parameters_, |
| - media::AudioManagerBase::kDefaultDeviceId, |
| - agc_is_enabled_)); |
| + ipc_->CreateStream(stream_id_, audio_parameters_, |
| + media::AudioManagerBase::kDefaultDeviceId, agc_is_enabled_); |
| } else { |
| - Send(new AudioInputHostMsg_StartDevice(stream_id_, session_id_)); |
| + ipc_->StartDevice(stream_id_, session_id_); |
| pending_device_ready_ = true; |
| } |
| } |
| @@ -236,7 +237,7 @@ void AudioInputDevice::SetSessionIdOnIOThread(int session_id) { |
| void AudioInputDevice::StartOnIOThread() { |
| DCHECK(message_loop()->BelongsToCurrentThread()); |
| if (stream_id_) |
| - Send(new AudioInputHostMsg_RecordStream(stream_id_)); |
| + ipc_->RecordStream(stream_id_); |
| } |
| void AudioInputDevice::ShutDownOnIOThread() { |
| @@ -244,8 +245,8 @@ void AudioInputDevice::ShutDownOnIOThread() { |
| // NOTE: |completion| may be NULL. |
| // Make sure we don't call shutdown more than once. |
| if (stream_id_) { |
| - filter_->RemoveDelegate(stream_id_); |
| - Send(new AudioInputHostMsg_CloseStream(stream_id_)); |
| + ipc_->CloseStream(stream_id_); |
| + ipc_->RemoveDelegate(stream_id_); |
| stream_id_ = 0; |
| session_id_ = 0; |
| @@ -268,7 +269,7 @@ void AudioInputDevice::ShutDownOnIOThread() { |
| void AudioInputDevice::SetVolumeOnIOThread(double volume) { |
| DCHECK(message_loop()->BelongsToCurrentThread()); |
| if (stream_id_) |
| - Send(new AudioInputHostMsg_SetVolume(stream_id_, volume)); |
| + ipc_->SetVolume(stream_id_, volume); |
| } |
| void AudioInputDevice::SetAutomaticGainControlOnIOThread(bool enabled) { |
| @@ -283,10 +284,6 @@ void AudioInputDevice::SetAutomaticGainControlOnIOThread(bool enabled) { |
| agc_is_enabled_ = enabled; |
| } |
| -void AudioInputDevice::Send(IPC::Message* message) { |
| - filter_->Send(message); |
| -} |
| - |
| void AudioInputDevice::WillDestroyCurrentMessageLoop() { |
| LOG(ERROR) << "IO loop going away before the input device has been stopped"; |
| ShutDownOnIOThread(); |