OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/renderer/media/media_stream_audio_track.h" | 5 #include "content/renderer/media/media_stream_audio_track.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/public/renderer/media_stream_audio_sink.h" | 9 #include "content/public/renderer/media_stream_audio_sink.h" |
10 #include "media/base/audio_bus.h" | 10 #include "media/base/audio_bus.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 deliverer_.GetConsumerList(&sinks_to_end); | 111 deliverer_.GetConsumerList(&sinks_to_end); |
112 for (MediaStreamAudioSink* sink : sinks_to_end) { | 112 for (MediaStreamAudioSink* sink : sinks_to_end) { |
113 deliverer_.RemoveConsumer(sink); | 113 deliverer_.RemoveConsumer(sink); |
114 sink->OnReadyStateChanged(blink::WebMediaStreamSource::ReadyStateEnded); | 114 sink->OnReadyStateChanged(blink::WebMediaStreamSource::ReadyStateEnded); |
115 } | 115 } |
116 | 116 |
117 weak_factory_.InvalidateWeakPtrs(); | 117 weak_factory_.InvalidateWeakPtrs(); |
118 } | 118 } |
119 | 119 |
120 void MediaStreamAudioTrack::OnSetFormat(const media::AudioParameters& params) { | 120 void MediaStreamAudioTrack::OnSetFormat(const media::AudioParameters& params) { |
121 base::OnceCallback<void()> temp_callback; | |
122 // Call the callback if present, but don't hold a lock while doing so. | |
123 { | |
124 base::AutoLock guard(format_set_guard_); | |
125 format_is_set_ = true; | |
126 if (!format_set_callback_.is_null()) { | |
127 temp_callback = std::move(format_set_callback_); | |
128 } | |
129 } | |
130 if (!temp_callback.is_null()) { | |
131 std::move(temp_callback).Run(); | |
132 } | |
133 deliverer_.OnSetFormat(params); | 121 deliverer_.OnSetFormat(params); |
134 } | 122 } |
135 | 123 |
136 void MediaStreamAudioTrack::OnData(const media::AudioBus& audio_bus, | 124 void MediaStreamAudioTrack::OnData(const media::AudioBus& audio_bus, |
137 base::TimeTicks reference_time) { | 125 base::TimeTicks reference_time) { |
138 // Note: Using NoBarrier_Load because the timing of when the audio thread sees | 126 // Note: Using NoBarrier_Load because the timing of when the audio thread sees |
139 // a changed |is_enabled_| value can be relaxed. | 127 // a changed |is_enabled_| value can be relaxed. |
140 const bool deliver_data = !!base::subtle::NoBarrier_Load(&is_enabled_); | 128 const bool deliver_data = !!base::subtle::NoBarrier_Load(&is_enabled_); |
141 | 129 |
142 if (deliver_data) { | 130 if (deliver_data) { |
143 deliverer_.OnData(audio_bus, reference_time); | 131 deliverer_.OnData(audio_bus, reference_time); |
144 } else { | 132 } else { |
145 // The W3C spec requires silent audio to flow while a track is disabled. | 133 // The W3C spec requires silent audio to flow while a track is disabled. |
146 if (!silent_bus_ || silent_bus_->channels() != audio_bus.channels() || | 134 if (!silent_bus_ || silent_bus_->channels() != audio_bus.channels() || |
147 silent_bus_->frames() != audio_bus.frames()) { | 135 silent_bus_->frames() != audio_bus.frames()) { |
148 silent_bus_ = media::AudioBus::Create(audio_bus.channels(), | 136 silent_bus_ = media::AudioBus::Create(audio_bus.channels(), |
149 audio_bus.frames()); | 137 audio_bus.frames()); |
150 silent_bus_->Zero(); | 138 silent_bus_->Zero(); |
151 } | 139 } |
152 deliverer_.OnData(*silent_bus_, reference_time); | 140 deliverer_.OnData(*silent_bus_, reference_time); |
153 } | 141 } |
154 } | 142 } |
155 | 143 |
156 bool MediaStreamAudioTrack::format_is_set() { | |
157 base::AutoLock guard(format_set_guard_); | |
158 return format_is_set_; | |
159 } | |
160 | |
161 void MediaStreamAudioTrack::getSettings( | 144 void MediaStreamAudioTrack::getSettings( |
162 blink::WebMediaStreamTrack::Settings& settings) { | 145 blink::WebMediaStreamTrack::Settings& settings) { |
163 DCHECK(format_is_set()); | 146 // TODO(hta): Extract the real value. |
| 147 settings.deviceId = blink::WebString("audio device ID"); |
164 } | 148 } |
165 | 149 |
166 } // namespace content | 150 } // namespace content |
OLD | NEW |