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

Side by Side Diff: media/audio/audio_output_proxy.cc

Issue 9691001: Audio software mixer. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 audio_source_callback_(NULL),
18 pending_bytes_(0) {
17 } 19 }
18 20
19 AudioOutputProxy::~AudioOutputProxy() { 21 AudioOutputProxy::~AudioOutputProxy() {
20 DCHECK(CalledOnValidThread()); 22 DCHECK(CalledOnValidThread());
21 DCHECK(state_ == kCreated || state_ == kClosed); 23 DCHECK(state_ == kCreated || state_ == kClosed);
22 DCHECK(!physical_stream_); 24 DCHECK(!physical_stream_);
25 DCHECK(!audio_source_callback_);
23 } 26 }
24 27
25 bool AudioOutputProxy::Open() { 28 bool AudioOutputProxy::Open() {
26 DCHECK(CalledOnValidThread()); 29 DCHECK(CalledOnValidThread());
27 DCHECK_EQ(state_, kCreated); 30 DCHECK_EQ(state_, kCreated);
28 31
29 if (!dispatcher_->StreamOpened()) { 32 if (!dispatcher_->StreamOpened()) {
30 state_ = kError; 33 state_ = kError;
31 return false; 34 return false;
32 } 35 }
33 36
34 state_ = kOpened; 37 state_ = kOpened;
35 return true; 38 return true;
36 } 39 }
37 40
38 void AudioOutputProxy::Start(AudioSourceCallback* callback) { 41 void AudioOutputProxy::Start(AudioSourceCallback* callback) {
39 DCHECK(CalledOnValidThread()); 42 DCHECK(CalledOnValidThread());
40 DCHECK(physical_stream_ == NULL); 43 DCHECK(physical_stream_ == NULL);
41 DCHECK_EQ(state_, kOpened); 44 DCHECK_EQ(state_, kOpened);
tommi (sloooow) - chröme 2012/04/03 13:47:51 DCHECK(!audio_source_callback_)?
enal1 2012/04/04 18:46:55 Done.
42 45
43 physical_stream_= dispatcher_->StreamStarted(); 46 audio_source_callback_ = callback;
tommi (sloooow) - chröme 2012/04/03 13:47:51 nit: just assign to this variable where you set st
enal1 2012/04/04 18:46:55 audio_source_callback_->OnMoreData() is called by
47 pending_bytes_ = 0;
48 physical_stream_= dispatcher_->StreamStarted(callback, this);
vrk (LEFT CHROMIUM) 2012/03/30 22:25:58 Yikes, this is a big hack. If |dispatcher_| is an
enal1 2012/04/04 18:46:55 Done.
44 if (!physical_stream_) { 49 if (!physical_stream_) {
45 state_ = kError; 50 state_ = kError;
46 callback->OnError(this, 0); 51 callback->OnError(this, 0);
52 audio_source_callback_ = NULL;
47 return; 53 return;
48 } 54 }
49 55
50 physical_stream_->SetVolume(volume_);
51 physical_stream_->Start(callback);
52 state_ = kPlaying; 56 state_ = kPlaying;
53 } 57 }
54 58
55 void AudioOutputProxy::Stop() { 59 void AudioOutputProxy::Stop() {
56 DCHECK(CalledOnValidThread()); 60 DCHECK(CalledOnValidThread());
57 if (state_ != kPlaying) 61 if (state_ != kPlaying)
58 return; 62 return;
59 63
60 DCHECK(physical_stream_); 64 DCHECK(physical_stream_);
61 physical_stream_->Stop(); 65 dispatcher_->StreamStopped(physical_stream_, this);
62 dispatcher_->StreamStopped(physical_stream_);
63 physical_stream_ = NULL; 66 physical_stream_ = NULL;
67 audio_source_callback_ = NULL;
64 state_ = kOpened; 68 state_ = kOpened;
65 } 69 }
66 70
67 void AudioOutputProxy::SetVolume(double volume) { 71 void AudioOutputProxy::SetVolume(double volume) {
68 DCHECK(CalledOnValidThread()); 72 DCHECK(CalledOnValidThread());
69 volume_ = volume; 73 {
70 if (physical_stream_) { 74 base::AutoLock lock(lock_);
71 physical_stream_->SetVolume(volume); 75 volume_ = volume;
72 } 76 }
77 dispatcher_->StreamVolumeSet(physical_stream_, volume);
73 } 78 }
74 79
75 void AudioOutputProxy::GetVolume(double* volume) { 80 void AudioOutputProxy::GetVolume(double* volume) {
76 DCHECK(CalledOnValidThread()); 81 base::AutoLock lock(lock_);
77 *volume = volume_; 82 *volume = volume_;
78 } 83 }
79 84
80 void AudioOutputProxy::Close() { 85 void AudioOutputProxy::Close() {
81 DCHECK(CalledOnValidThread()); 86 DCHECK(CalledOnValidThread());
82 DCHECK(state_ == kCreated || state_ == kError || state_ == kOpened); 87 DCHECK(state_ == kCreated || state_ == kError || state_ == kOpened);
83 DCHECK(!physical_stream_); 88 DCHECK(!physical_stream_);
89 DCHECK(!audio_source_callback_);
84 90
85 if (state_ != kCreated) 91 if (state_ != kCreated)
86 dispatcher_->StreamClosed(); 92 dispatcher_->StreamClosed(this);
87 93
88 state_ = kClosed; 94 state_ = kClosed;
89 95
90 // Delete the object now like is done in the Close() implementation of 96 // Delete the object now like is done in the Close() implementation of
91 // physical stream objects. If we delete the object via DeleteSoon, we 97 // physical stream objects. If we delete the object via DeleteSoon, we
92 // unnecessarily complicate the Shutdown procedure of the 98 // unnecessarily complicate the Shutdown procedure of the
93 // dispatcher+audio manager. 99 // dispatcher+audio manager.
94 delete this; 100 delete this;
95 } 101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698