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 "content/renderer/media/webaudio_capturer_source.h" | 5 #include "content/renderer/media/webaudio_capturer_source.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "content/renderer/media/webrtc_local_audio_track.h" | 9 #include "content/renderer/media/webrtc_local_audio_track.h" |
10 | 10 |
11 using media::AudioBus; | 11 using media::AudioBus; |
12 using media::AudioFifo; | 12 using media::AudioFifo; |
13 using media::AudioParameters; | 13 using media::AudioParameters; |
14 using media::ChannelLayout; | 14 using media::ChannelLayout; |
15 using media::CHANNEL_LAYOUT_MONO; | 15 using media::CHANNEL_LAYOUT_MONO; |
16 using media::CHANNEL_LAYOUT_STEREO; | 16 using media::CHANNEL_LAYOUT_STEREO; |
17 | 17 |
18 static const int kMaxNumberOfBuffersInFifo = 5; | 18 static const int kMaxNumberOfBuffersInFifo = 5; |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 WebAudioCapturerSource::WebAudioCapturerSource() | 22 WebAudioCapturerSource::WebAudioCapturerSource( |
23 const blink::WebMediaStreamSource &blink_source) | |
23 : track_(NULL), | 24 : track_(NULL), |
24 audio_format_changed_(false) { | 25 audio_format_changed_(false), |
26 blink_source_(blink_source) { | |
25 } | 27 } |
26 | 28 |
27 WebAudioCapturerSource::~WebAudioCapturerSource() { | 29 WebAudioCapturerSource::~WebAudioCapturerSource() { |
30 removeFromBlinkSource(); | |
28 } | 31 } |
29 | 32 |
30 void WebAudioCapturerSource::setFormat( | 33 void WebAudioCapturerSource::setFormat( |
31 size_t number_of_channels, float sample_rate) { | 34 size_t number_of_channels, float sample_rate) { |
32 DCHECK(thread_checker_.CalledOnValidThread()); | 35 DCHECK(thread_checker_.CalledOnValidThread()); |
33 DVLOG(1) << "WebAudioCapturerSource::setFormat(sample_rate=" | 36 DVLOG(1) << "WebAudioCapturerSource::setFormat(sample_rate=" |
34 << sample_rate << ")"; | 37 << sample_rate << ")"; |
35 if (number_of_channels > 2) { | 38 if (number_of_channels > 2) { |
36 // TODO(xians): Handle more than just the mono and stereo cases. | 39 // TODO(xians): Handle more than just the mono and stereo cases. |
37 LOG(WARNING) << "WebAudioCapturerSource::setFormat() : unhandled format."; | 40 LOG(WARNING) << "WebAudioCapturerSource::setFormat() : unhandled format."; |
(...skipping 23 matching lines...) Expand all Loading... | |
61 DCHECK(thread_checker_.CalledOnValidThread()); | 64 DCHECK(thread_checker_.CalledOnValidThread()); |
62 DCHECK(track); | 65 DCHECK(track); |
63 base::AutoLock auto_lock(lock_); | 66 base::AutoLock auto_lock(lock_); |
64 track_ = track; | 67 track_ = track; |
65 } | 68 } |
66 | 69 |
67 void WebAudioCapturerSource::Stop() { | 70 void WebAudioCapturerSource::Stop() { |
68 DCHECK(thread_checker_.CalledOnValidThread()); | 71 DCHECK(thread_checker_.CalledOnValidThread()); |
69 base::AutoLock auto_lock(lock_); | 72 base::AutoLock auto_lock(lock_); |
70 track_ = NULL; | 73 track_ = NULL; |
74 removeFromBlinkSource(); | |
71 } | 75 } |
72 | 76 |
73 void WebAudioCapturerSource::consumeAudio( | 77 void WebAudioCapturerSource::consumeAudio( |
74 const blink::WebVector<const float*>& audio_data, | 78 const blink::WebVector<const float*>& audio_data, |
75 size_t number_of_frames) { | 79 size_t number_of_frames) { |
76 base::AutoLock auto_lock(lock_); | 80 base::AutoLock auto_lock(lock_); |
77 if (!track_) | 81 if (!track_) |
78 return; | 82 return; |
79 | 83 |
80 // Update the downstream client if the audio format has been changed. | 84 // Update the downstream client if the audio format has been changed. |
(...skipping 28 matching lines...) Expand all Loading... | |
109 fifo_->Consume(capture_bus_.get(), 0, capture_bus_->frames()); | 113 fifo_->Consume(capture_bus_.get(), 0, capture_bus_->frames()); |
110 track_->Capture(*capture_bus_, estimated_capture_time, false); | 114 track_->Capture(*capture_bus_, estimated_capture_time, false); |
111 | 115 |
112 // Advance the estimated capture time for the next FIFO consume operation. | 116 // Advance the estimated capture time for the next FIFO consume operation. |
113 estimated_capture_time += | 117 estimated_capture_time += |
114 capture_bus_->frames() * base::TimeDelta::FromSeconds(1) / | 118 capture_bus_->frames() * base::TimeDelta::FromSeconds(1) / |
115 params_.sample_rate(); | 119 params_.sample_rate(); |
116 } | 120 } |
117 } | 121 } |
118 | 122 |
123 void WebAudioCapturerSource::removeFromBlinkSource() { | |
henrika (OOO until Aug 14)
2015/04/09 11:53:40
Can you add some comments about what happens here
| |
124 if (!blink_source_.isNull()) { | |
125 blink_source_.removeAudioConsumer(this); | |
126 blink_source_.reset(); | |
127 } | |
128 } | |
129 | |
119 } // namespace content | 130 } // namespace content |
OLD | NEW |