| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "media/audio/audio_output_proxy.h" | 5 #include "media/audio/audio_output_proxy.h" | 
| 6 | 6 | 
| 7 #include "base/logging.h" | 7 #include "base/logging.h" | 
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" | 
| 9 #include "media/audio/audio_manager.h" | 9 #include "media/audio/audio_manager.h" | 
| 10 #include "media/audio/audio_output_dispatcher.h" | 10 #include "media/audio/audio_output_dispatcher.h" | 
| 11 | 11 | 
| 12 AudioOutputProxy::AudioOutputProxy(AudioOutputDispatcher* dispatcher) | 12 AudioOutputProxy::AudioOutputProxy(AudioOutputDispatcher* dispatcher) | 
| 13     : dispatcher_(dispatcher), | 13     : dispatcher_(dispatcher), | 
| 14       state_(kCreated), | 14       state_(kCreated), | 
| 15       physical_stream_(NULL), | 15       physical_stream_(NULL), | 
| 16       volume_(1.0) { | 16       volume_(1.0) { | 
| 17   DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); |  | 
| 18 } | 17 } | 
| 19 | 18 | 
| 20 AudioOutputProxy::~AudioOutputProxy() { | 19 AudioOutputProxy::~AudioOutputProxy() { | 
| 21   DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); | 20   DCHECK(CalledOnValidThread()); | 
| 22   DCHECK(state_ == kCreated || state_ == kClosed); | 21   DCHECK(state_ == kCreated || state_ == kClosed); | 
| 23   DCHECK(!physical_stream_); | 22   DCHECK(!physical_stream_); | 
| 24 } | 23 } | 
| 25 | 24 | 
| 26 bool AudioOutputProxy::Open() { | 25 bool AudioOutputProxy::Open() { | 
| 27   DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); | 26   DCHECK(CalledOnValidThread()); | 
| 28   DCHECK_EQ(state_, kCreated); | 27   DCHECK_EQ(state_, kCreated); | 
| 29 | 28 | 
| 30   if (!dispatcher_->StreamOpened()) { | 29   if (!dispatcher_->StreamOpened()) { | 
| 31     state_ = kError; | 30     state_ = kError; | 
| 32     return false; | 31     return false; | 
| 33   } | 32   } | 
| 34 | 33 | 
| 35   state_ = kOpened; | 34   state_ = kOpened; | 
| 36   return true; | 35   return true; | 
| 37 } | 36 } | 
| 38 | 37 | 
| 39 void AudioOutputProxy::Start(AudioSourceCallback* callback) { | 38 void AudioOutputProxy::Start(AudioSourceCallback* callback) { | 
| 40   DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); | 39   DCHECK(CalledOnValidThread()); | 
| 41   DCHECK(physical_stream_ == NULL); | 40   DCHECK(physical_stream_ == NULL); | 
| 42   DCHECK_EQ(state_, kOpened); | 41   DCHECK_EQ(state_, kOpened); | 
| 43 | 42 | 
| 44   physical_stream_= dispatcher_->StreamStarted(); | 43   physical_stream_= dispatcher_->StreamStarted(); | 
| 45   if (!physical_stream_) { | 44   if (!physical_stream_) { | 
| 46     state_ = kError; | 45     state_ = kError; | 
| 47     callback->OnError(this, 0); | 46     callback->OnError(this, 0); | 
| 48     return; | 47     return; | 
| 49   } | 48   } | 
| 50 | 49 | 
| 51   physical_stream_->SetVolume(volume_); | 50   physical_stream_->SetVolume(volume_); | 
| 52   physical_stream_->Start(callback); | 51   physical_stream_->Start(callback); | 
| 53   state_ = kPlaying; | 52   state_ = kPlaying; | 
| 54 } | 53 } | 
| 55 | 54 | 
| 56 void AudioOutputProxy::Stop() { | 55 void AudioOutputProxy::Stop() { | 
| 57   DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); | 56   DCHECK(CalledOnValidThread()); | 
| 58   if (state_ != kPlaying) | 57   if (state_ != kPlaying) | 
| 59     return; | 58     return; | 
| 60 | 59 | 
| 61   DCHECK(physical_stream_); | 60   DCHECK(physical_stream_); | 
| 62   physical_stream_->Stop(); | 61   physical_stream_->Stop(); | 
| 63   dispatcher_->StreamStopped(physical_stream_); | 62   dispatcher_->StreamStopped(physical_stream_); | 
| 64   physical_stream_ = NULL; | 63   physical_stream_ = NULL; | 
| 65   state_ = kOpened; | 64   state_ = kOpened; | 
| 66 } | 65 } | 
| 67 | 66 | 
| 68 void AudioOutputProxy::SetVolume(double volume) { | 67 void AudioOutputProxy::SetVolume(double volume) { | 
| 69   DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); | 68   DCHECK(CalledOnValidThread()); | 
| 70   volume_ = volume; | 69   volume_ = volume; | 
| 71   if (physical_stream_) { | 70   if (physical_stream_) { | 
| 72     physical_stream_->SetVolume(volume); | 71     physical_stream_->SetVolume(volume); | 
| 73   } | 72   } | 
| 74 } | 73 } | 
| 75 | 74 | 
| 76 void AudioOutputProxy::GetVolume(double* volume) { | 75 void AudioOutputProxy::GetVolume(double* volume) { | 
| 77   DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); | 76   DCHECK(CalledOnValidThread()); | 
| 78   *volume = volume_; | 77   *volume = volume_; | 
| 79 } | 78 } | 
| 80 | 79 | 
| 81 void AudioOutputProxy::Close() { | 80 void AudioOutputProxy::Close() { | 
| 82   DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop()); | 81   DCHECK(CalledOnValidThread()); | 
| 83   DCHECK(state_ == kCreated || state_ == kError || state_ == kOpened); | 82   DCHECK(state_ == kCreated || state_ == kError || state_ == kOpened); | 
| 84   DCHECK(!physical_stream_); | 83   DCHECK(!physical_stream_); | 
| 85 | 84 | 
| 86   if (state_ != kCreated) | 85   if (state_ != kCreated) | 
| 87     dispatcher_->StreamClosed(); | 86     dispatcher_->StreamClosed(); | 
| 88 | 87 | 
| 89   state_ = kClosed; | 88   state_ = kClosed; | 
| 90 | 89 | 
| 91   // Delete the object now like is done in the Close() implementation of | 90   // Delete the object now like is done in the Close() implementation of | 
| 92   // physical stream objects.  If we delete the object via DeleteSoon, we | 91   // physical stream objects.  If we delete the object via DeleteSoon, we | 
| 93   // unnecessarily complicate the Shutdown procedure of the | 92   // unnecessarily complicate the Shutdown procedure of the | 
| 94   // dispatcher+audio manager. | 93   // dispatcher+audio manager. | 
| 95   delete this; | 94   delete this; | 
| 96 } | 95 } | 
| OLD | NEW | 
|---|