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

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
« no previous file with comments | « media/audio/audio_output_proxy.h ('k') | media/audio/audio_output_proxy_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 namespace media { 12 namespace media {
13 13
14 AudioOutputProxy::AudioOutputProxy(AudioOutputDispatcher* dispatcher) 14 AudioOutputProxy::AudioOutputProxy(AudioOutputDispatcher* dispatcher)
15 : dispatcher_(dispatcher), 15 : dispatcher_(dispatcher),
16 state_(kCreated), 16 state_(kCreated),
17 physical_stream_(NULL),
18 volume_(1.0) { 17 volume_(1.0) {
19 } 18 }
20 19
21 AudioOutputProxy::~AudioOutputProxy() { 20 AudioOutputProxy::~AudioOutputProxy() {
22 DCHECK(CalledOnValidThread()); 21 DCHECK(CalledOnValidThread());
23 DCHECK(state_ == kCreated || state_ == kClosed); 22 DCHECK(state_ == kCreated || state_ == kClosed);
24 DCHECK(!physical_stream_);
25 } 23 }
26 24
27 bool AudioOutputProxy::Open() { 25 bool AudioOutputProxy::Open() {
28 DCHECK(CalledOnValidThread()); 26 DCHECK(CalledOnValidThread());
29 DCHECK_EQ(state_, kCreated); 27 DCHECK_EQ(state_, kCreated);
30 28
31 if (!dispatcher_->StreamOpened()) { 29 if (!dispatcher_->OpenStream()) {
32 state_ = kError; 30 state_ = kError;
33 return false; 31 return false;
34 } 32 }
35 33
36 state_ = kOpened; 34 state_ = kOpened;
37 return true; 35 return true;
38 } 36 }
39 37
40 void AudioOutputProxy::Start(AudioSourceCallback* callback) { 38 void AudioOutputProxy::Start(AudioSourceCallback* callback) {
41 DCHECK(CalledOnValidThread()); 39 DCHECK(CalledOnValidThread());
42 DCHECK(physical_stream_ == NULL);
43 DCHECK_EQ(state_, kOpened); 40 DCHECK_EQ(state_, kOpened);
44 41
45 physical_stream_= dispatcher_->StreamStarted(); 42 if (!dispatcher_->StartStream(callback, this)) {
46 if (!physical_stream_) {
47 state_ = kError; 43 state_ = kError;
48 callback->OnError(this, 0); 44 callback->OnError(this, 0);
49 return; 45 return;
50 } 46 }
51
52 physical_stream_->SetVolume(volume_);
53 physical_stream_->Start(callback);
54 state_ = kPlaying; 47 state_ = kPlaying;
55 } 48 }
56 49
57 void AudioOutputProxy::Stop() { 50 void AudioOutputProxy::Stop() {
58 DCHECK(CalledOnValidThread()); 51 DCHECK(CalledOnValidThread());
59 if (state_ != kPlaying) 52 if (state_ != kPlaying)
60 return; 53 return;
61 54
62 DCHECK(physical_stream_); 55 dispatcher_->StopStream(this);
63 physical_stream_->Stop();
64 dispatcher_->StreamStopped(physical_stream_);
65 physical_stream_ = NULL;
66 state_ = kOpened; 56 state_ = kOpened;
67 } 57 }
68 58
69 void AudioOutputProxy::SetVolume(double volume) { 59 void AudioOutputProxy::SetVolume(double volume) {
70 DCHECK(CalledOnValidThread()); 60 DCHECK(CalledOnValidThread());
71 volume_ = volume; 61 volume_ = volume;
72 if (physical_stream_) { 62 dispatcher_->StreamVolumeSet(this, volume);
73 physical_stream_->SetVolume(volume);
74 }
75 } 63 }
76 64
77 void AudioOutputProxy::GetVolume(double* volume) { 65 void AudioOutputProxy::GetVolume(double* volume) {
78 DCHECK(CalledOnValidThread()); 66 DCHECK(CalledOnValidThread());
79 *volume = volume_; 67 *volume = volume_;
80 } 68 }
81 69
82 void AudioOutputProxy::Close() { 70 void AudioOutputProxy::Close() {
83 DCHECK(CalledOnValidThread()); 71 DCHECK(CalledOnValidThread());
84 DCHECK(state_ == kCreated || state_ == kError || state_ == kOpened); 72 DCHECK(state_ == kCreated || state_ == kError || state_ == kOpened);
85 DCHECK(!physical_stream_);
86 73
87 if (state_ != kCreated) 74 if (state_ != kCreated)
88 dispatcher_->StreamClosed(); 75 dispatcher_->CloseStream(this);
89 76
90 state_ = kClosed; 77 state_ = kClosed;
91 78
92 // Delete the object now like is done in the Close() implementation of 79 // Delete the object now like is done in the Close() implementation of
93 // physical stream objects. If we delete the object via DeleteSoon, we 80 // physical stream objects. If we delete the object via DeleteSoon, we
94 // unnecessarily complicate the Shutdown procedure of the 81 // unnecessarily complicate the Shutdown procedure of the
95 // dispatcher+audio manager. 82 // dispatcher+audio manager.
96 delete this; 83 delete this;
97 } 84 }
98 85
99 } // namespace media 86 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_output_proxy.h ('k') | media/audio/audio_output_proxy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698