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

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

Issue 5158003: Implement AudioOutputProxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 10 years 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
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/audio/audio_output_proxy.h"
6
7 #include "base/logging.h"
8 #include "base/message_loop.h"
9 #include "base/task.h"
10 #include "media/audio/audio_manager.h"
11 #include "media/audio/audio_output_dispatcher.h"
12
13 AudioOutputProxy::AudioOutputProxy(AudioOutputDispatcher* dispatcher)
14 : dispatcher_(dispatcher),
15 state_(kCreated),
16 physical_stream_(NULL),
17 volume_(1.0) {
18 DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop());
19 }
20
21 AudioOutputProxy::~AudioOutputProxy() {
22 DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop());
23 DCHECK(state_ == kCreated || state_ == kClosed);
24 DCHECK(!physical_stream_);
25 }
26
27 bool AudioOutputProxy::Open() {
28 DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop());
29 DCHECK_EQ(state_, kCreated);
30
31 if (!dispatcher_->StreamOpened()) {
32 state_ = kError;
33 return false;
34 }
35
36 state_ = kOpened;
37 return true;
38 }
39
40 void AudioOutputProxy::Start(AudioSourceCallback* callback) {
41 DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop());
42 DCHECK(physical_stream_ == NULL);
43 DCHECK_EQ(state_, kOpened);
44
45 physical_stream_= dispatcher_->StreamStarted();
46 if (!physical_stream_) {
47 state_ = kError;
48 callback->OnError(this, 0);
49 return;
50 }
51
52 physical_stream_->SetVolume(volume_);
53 physical_stream_->Start(callback);
54 state_ = kPlaying;
55 }
56
57 void AudioOutputProxy::Stop() {
58 DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop());
59 if (state_ != kPlaying)
60 return;
61
62 DCHECK(physical_stream_);
63 physical_stream_->Stop();
64 dispatcher_->StreamStopped(physical_stream_);
65 physical_stream_ = NULL;
66 state_ = kOpened;
67 }
68
69 void AudioOutputProxy::SetVolume(double volume) {
70 DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop());
71 volume_ = volume;
72 if (physical_stream_) {
73 physical_stream_->SetVolume(volume);
74 }
75 }
76
77 void AudioOutputProxy::GetVolume(double* volume) {
78 DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop());
79 *volume = volume_;
80 }
81
82 void AudioOutputProxy::Close() {
83 DCHECK_EQ(MessageLoop::current(), dispatcher_->message_loop());
84 DCHECK(state_ == kCreated || state_ == kError || state_ == kOpened);
85 DCHECK(!physical_stream_);
86
87 if (state_ != kCreated) {
88 dispatcher_->StreamClosed();
89 }
90 dispatcher_->message_loop()->DeleteSoon(FROM_HERE, this);
91 state_ = kClosed;
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698