OLD | NEW |
---|---|
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/base/audio_renderer_mixer_input.h" | 5 #include "media/base/audio_renderer_mixer_input.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "media/base/audio_renderer_mixer.h" | 9 #include "media/base/audio_renderer_mixer.h" |
10 | 10 |
11 namespace media { | 11 namespace media { |
12 | 12 |
13 AudioRendererMixerInput::AudioRendererMixerInput( | 13 AudioRendererMixerInput::AudioRendererMixerInput( |
14 const GetMixerCB& get_mixer_cb, const RemoveMixerCB& remove_mixer_cb) | 14 const GetMixerCB& get_mixer_cb, const RemoveMixerCB& remove_mixer_cb) |
15 : playing_(false), | 15 : playing_(false), |
16 initialized_(false), | 16 initialized_(false), |
17 volume_(1.0f), | 17 volume_(1.0f), |
18 get_mixer_cb_(get_mixer_cb), | 18 get_mixer_cb_(get_mixer_cb), |
19 remove_mixer_cb_(remove_mixer_cb), | 19 remove_mixer_cb_(remove_mixer_cb), |
20 mixer_(NULL), | 20 mixer_(NULL), |
21 callback_(NULL), | 21 callback_(NULL), |
22 error_cb_(base::Bind( | 22 error_cb_(base::Bind( |
23 &AudioRendererMixerInput::OnRenderError, base::Unretained(this))) { | 23 &AudioRendererMixerInput::OnRenderError, base::Unretained(this))) { |
24 } | 24 } |
25 | 25 |
26 AudioRendererMixerInput::~AudioRendererMixerInput() { | 26 AudioRendererMixerInput::~AudioRendererMixerInput() { |
27 DCHECK(!callback_); | |
28 DCHECK(!playing_); | 27 DCHECK(!playing_); |
29 DCHECK(!mixer_); | 28 DCHECK(!mixer_); |
30 } | 29 } |
31 | 30 |
32 void AudioRendererMixerInput::Initialize( | 31 void AudioRendererMixerInput::Initialize( |
rileya (GONE FROM CHROMIUM)
2014/07/10 19:12:42
Initialize() doesn't seem to do much anymore. Afte
DaleCurtis
2014/07/10 19:18:55
Unfortunately it's a common interface used through
| |
33 const AudioParameters& params, | 32 const AudioParameters& params, |
34 AudioRendererSink::RenderCallback* callback) { | 33 AudioRendererSink::RenderCallback* callback) { |
35 DCHECK(callback); | 34 DCHECK(callback); |
36 DCHECK(!initialized_); | 35 DCHECK(!initialized_); |
37 | 36 |
38 params_ = params; | 37 params_ = params; |
39 callback_ = callback; | 38 callback_ = callback; |
40 initialized_ = true; | 39 initialized_ = true; |
41 mixer_ = get_mixer_cb_.Run(params_); | |
42 | |
43 // Note: OnRenderError() may be called immediately after this call completes, | |
44 // so ensure |callback_| has been set first. | |
45 mixer_->AddErrorCallback(error_cb_); | |
46 } | 40 } |
47 | 41 |
48 void AudioRendererMixerInput::Start() { | 42 void AudioRendererMixerInput::Start() { |
49 DCHECK(initialized_); | 43 DCHECK(initialized_); |
50 DCHECK(!playing_); | 44 DCHECK(!playing_); |
45 DCHECK(!mixer_); | |
46 mixer_ = get_mixer_cb_.Run(params_); | |
47 | |
48 // Note: OnRenderError() may be called immediately after this call returns. | |
49 mixer_->AddErrorCallback(error_cb_); | |
51 } | 50 } |
52 | 51 |
53 void AudioRendererMixerInput::Stop() { | 52 void AudioRendererMixerInput::Stop() { |
54 // Stop() may be called at any time, if Pause() hasn't been called we need to | 53 // Stop() may be called at any time, if Pause() hasn't been called we need to |
55 // remove our mixer input before shutdown. | 54 // remove our mixer input before shutdown. |
56 if (playing_) { | 55 if (playing_) { |
57 mixer_->RemoveMixerInput(this); | 56 mixer_->RemoveMixerInput(this); |
58 playing_ = false; | 57 playing_ = false; |
59 } | 58 } |
60 | 59 |
61 // Once Stop() is called the input can no longer be used. | 60 if (mixer_) { |
62 if (callback_) { | 61 // TODO(dalecurtis): This is required so that |callback_| isn't called after |
62 // Stop() by an error event since it may outlive this ref-counted object. We | |
63 // should instead have sane ownership semantics: http://crbug.com/151051 | |
63 mixer_->RemoveErrorCallback(error_cb_); | 64 mixer_->RemoveErrorCallback(error_cb_); |
64 remove_mixer_cb_.Run(params_); | 65 remove_mixer_cb_.Run(params_); |
65 mixer_ = NULL; | 66 mixer_ = NULL; |
66 callback_ = NULL; | |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 void AudioRendererMixerInput::Play() { | 70 void AudioRendererMixerInput::Play() { |
71 DCHECK(initialized_); | 71 DCHECK(initialized_); |
rileya (GONE FROM CHROMIUM)
2014/07/10 19:12:43
Maybe DCHECK(mixer_) here?
DaleCurtis
2014/07/10 19:18:55
Done.
| |
72 | 72 |
73 if (playing_) | 73 if (playing_) |
74 return; | 74 return; |
75 | 75 |
76 mixer_->AddMixerInput(this); | 76 mixer_->AddMixerInput(this); |
77 playing_ = true; | 77 playing_ = true; |
78 } | 78 } |
79 | 79 |
80 void AudioRendererMixerInput::Pause() { | 80 void AudioRendererMixerInput::Pause() { |
81 DCHECK(initialized_); | 81 DCHECK(initialized_); |
rileya (GONE FROM CHROMIUM)
2014/07/10 19:12:43
ditto
DaleCurtis
2014/07/10 19:18:55
Done.
| |
82 | 82 |
83 if (!playing_) | 83 if (!playing_) |
84 return; | 84 return; |
85 | 85 |
86 mixer_->RemoveMixerInput(this); | 86 mixer_->RemoveMixerInput(this); |
87 playing_ = false; | 87 playing_ = false; |
88 } | 88 } |
89 | 89 |
90 bool AudioRendererMixerInput::SetVolume(double volume) { | 90 bool AudioRendererMixerInput::SetVolume(double volume) { |
91 volume_ = volume; | 91 volume_ = volume; |
(...skipping 12 matching lines...) Expand all Loading... | |
104 } | 104 } |
105 | 105 |
106 return frames_filled > 0 ? volume_ : 0; | 106 return frames_filled > 0 ? volume_ : 0; |
107 } | 107 } |
108 | 108 |
109 void AudioRendererMixerInput::OnRenderError() { | 109 void AudioRendererMixerInput::OnRenderError() { |
110 callback_->OnRenderError(); | 110 callback_->OnRenderError(); |
111 } | 111 } |
112 | 112 |
113 } // namespace media | 113 } // namespace media |
OLD | NEW |