Index: media/audio/audio_output_device.cc |
diff --git a/media/audio/audio_output_device.cc b/media/audio/audio_output_device.cc |
index 093330c855c8ebaa738d38ff7e4694e93bc6de7c..fccb3cfd2ef22449ffc2b961343b4e522497fe26 100644 |
--- a/media/audio/audio_output_device.cc |
+++ b/media/audio/audio_output_device.cc |
@@ -40,12 +40,11 @@ class AudioOutputDevice::AudioThreadCallback |
}; |
AudioOutputDevice::AudioOutputDevice( |
- AudioOutputIPC* ipc, |
+ scoped_ptr<AudioOutputIPC> ipc, |
const scoped_refptr<base::MessageLoopProxy>& io_loop) |
: ScopedLoopObserver(io_loop), |
callback_(NULL), |
- ipc_(ipc), |
- stream_id_(0), |
+ ipc_(ipc.Pass()), |
state_(IDLE), |
play_on_start_(true), |
stopping_hack_(false) { |
@@ -109,16 +108,15 @@ bool AudioOutputDevice::SetVolume(double volume) { |
void AudioOutputDevice::CreateStreamOnIOThread(const AudioParameters& params) { |
DCHECK(message_loop()->BelongsToCurrentThread()); |
if (state_ == IDLE) { |
- stream_id_ = ipc_->AddDelegate(this); |
state_ = CREATING_STREAM; |
- ipc_->CreateStream(stream_id_, params); |
+ ipc_->CreateStream(this, params); |
} |
} |
void AudioOutputDevice::PlayOnIOThread() { |
DCHECK(message_loop()->BelongsToCurrentThread()); |
if (state_ == PAUSED) { |
- ipc_->PlayStream(stream_id_); |
+ ipc_->PlayStream(); |
state_ = PLAYING; |
play_on_start_ = false; |
} else { |
@@ -129,9 +127,9 @@ void AudioOutputDevice::PlayOnIOThread() { |
void AudioOutputDevice::PauseOnIOThread(bool flush) { |
DCHECK(message_loop()->BelongsToCurrentThread()); |
if (state_ == PLAYING) { |
- ipc_->PauseStream(stream_id_); |
+ ipc_->PauseStream(); |
if (flush) |
- ipc_->FlushStream(stream_id_); |
+ ipc_->FlushStream(); |
state_ = PAUSED; |
} else { |
// Note that |flush| isn't relevant here since this is the case where |
@@ -143,12 +141,10 @@ void AudioOutputDevice::PauseOnIOThread(bool flush) { |
void AudioOutputDevice::ShutDownOnIOThread() { |
DCHECK(message_loop()->BelongsToCurrentThread()); |
- // Make sure we don't call shutdown more than once. |
+ // Close the stream, if we haven't already. |
if (state_ >= CREATING_STREAM) { |
- ipc_->CloseStream(stream_id_); |
- ipc_->RemoveDelegate(stream_id_); |
+ ipc_->CloseStream(); |
state_ = IDLE; |
- stream_id_ = 0; |
} |
// We can run into an issue where ShutDownOnIOThread is called right after |
@@ -169,7 +165,7 @@ void AudioOutputDevice::ShutDownOnIOThread() { |
void AudioOutputDevice::SetVolumeOnIOThread(double volume) { |
DCHECK(message_loop()->BelongsToCurrentThread()); |
if (state_ >= CREATING_STREAM) |
- ipc_->SetVolume(stream_id_, volume); |
+ ipc_->SetVolume(volume); |
} |
void AudioOutputDevice::OnStateChanged(AudioOutputIPCDelegate::State state) { |
@@ -179,16 +175,25 @@ void AudioOutputDevice::OnStateChanged(AudioOutputIPCDelegate::State state) { |
if (state_ < CREATING_STREAM) |
return; |
- if (state == AudioOutputIPCDelegate::kError) { |
- DLOG(WARNING) << "AudioOutputDevice::OnStateChanged(kError)"; |
- // Don't dereference the callback object if the audio thread |
- // is stopped or stopping. That could mean that the callback |
- // object has been deleted. |
- // TODO(tommi): Add an explicit contract for clearing the callback |
- // object. Possibly require calling Initialize again or provide |
- // a callback object via Start() and clear it in Stop(). |
- if (!audio_thread_.IsStopped()) |
- callback_->OnRenderError(); |
+ switch (state) { |
+ case AudioOutputIPCDelegate::kPlaying: |
+ case AudioOutputIPCDelegate::kPaused: |
+ NOTIMPLEMENTED(); |
+ break; |
+ case AudioOutputIPCDelegate::kError: |
DaleCurtis
2013/03/05 23:29:54
Technically this isn't really implemented either :
miu
2013/03/06 22:36:52
Yep. http://crbug.com/180640
|
+ DLOG(WARNING) << "AudioOutputDevice::OnStateChanged(kError)"; |
+ // Don't dereference the callback object if the audio thread |
+ // is stopped or stopping. That could mean that the callback |
+ // object has been deleted. |
+ // TODO(tommi): Add an explicit contract for clearing the callback |
+ // object. Possibly require calling Initialize again or provide |
+ // a callback object via Start() and clear it in Stop(). |
+ if (!audio_thread_.IsStopped()) |
+ callback_->OnRenderError(); |
+ break; |
+ default: |
+ NOTREACHED(); |
+ break; |
} |
} |
@@ -204,6 +209,7 @@ void AudioOutputDevice::OnStreamCreated( |
DCHECK_GE(handle.fd, 0); |
DCHECK_GE(socket_handle, 0); |
#endif |
+ DCHECK_LT(0, length); |
if (state_ != CREATING_STREAM) |
return; |
@@ -240,7 +246,7 @@ void AudioOutputDevice::OnStreamCreated( |
void AudioOutputDevice::OnIPCClosed() { |
DCHECK(message_loop()->BelongsToCurrentThread()); |
state_ = IPC_CLOSED; |
- ipc_ = NULL; |
+ ipc_.reset(); |
} |
void AudioOutputDevice::WillDestroyCurrentMessageLoop() { |