| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/webrtc_local_audio_source_provider.h" | 5 #include "content/renderer/media/webrtc_local_audio_source_provider.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/renderer/render_thread_impl.h" | 8 #include "content/renderer/render_thread_impl.h" |
| 9 #include "media/audio/audio_parameters.h" | 9 #include "media/audio/audio_parameters.h" |
| 10 #include "media/base/audio_fifo.h" | 10 #include "media/base/audio_fifo.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // the converter. | 61 // the converter. |
| 62 audio_converter_.reset( | 62 audio_converter_.reset( |
| 63 new media::AudioConverter(source_params, sink_params_, false)); | 63 new media::AudioConverter(source_params, sink_params_, false)); |
| 64 audio_converter_->AddInput(this); | 64 audio_converter_->AddInput(this); |
| 65 fifo_.reset(new media::AudioFifo( | 65 fifo_.reset(new media::AudioFifo( |
| 66 source_params.channels(), | 66 source_params.channels(), |
| 67 kMaxNumberOfBuffers * source_params.frames_per_buffer())); | 67 kMaxNumberOfBuffers * source_params.frames_per_buffer())); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void WebRtcLocalAudioSourceProvider::DeliverData( | 70 void WebRtcLocalAudioSourceProvider::DeliverData( |
| 71 media::AudioBus* audio_source, | 71 const int16* data, |
| 72 int audio_delay_milliseconds, | 72 int sample_rate, |
| 73 int volume, | 73 int number_of_channels, |
| 74 bool key_pressed) { | 74 int number_of_frames) { |
| 75 base::AutoLock auto_lock(lock_); | 75 base::AutoLock auto_lock(lock_); |
| 76 if (!is_enabled_) | 76 if (!is_enabled_) |
| 77 return; | 77 return; |
| 78 | 78 |
| 79 DCHECK(fifo_.get()); | 79 DCHECK(fifo_.get()); |
| 80 | 80 // TODO(xians): FIXME. |
| 81 /* |
| 81 if (fifo_->frames() + audio_source->frames() <= fifo_->max_frames()) { | 82 if (fifo_->frames() + audio_source->frames() <= fifo_->max_frames()) { |
| 82 fifo_->Push(audio_source); | 83 fifo_->Push(audio_source); |
| 83 } else { | 84 } else { |
| 84 // This can happen if the data in FIFO is too slowed to be consumed or | 85 // This can happen if the data in FIFO is too slowed to be consumed or |
| 85 // WebAudio stops consuming data. | 86 // WebAudio stops consuming data. |
| 86 DLOG(WARNING) << "Local source provicer FIFO is full" << fifo_->frames(); | 87 DLOG(WARNING) << "Local source provicer FIFO is full" << fifo_->frames(); |
| 87 } | 88 } |
| 88 | 89 |
| 89 // Cache the values for GetAudioProcessingParams(). | 90 // Cache the values for GetAudioProcessingParams(). |
| 90 last_fill_ = base::TimeTicks::Now(); | 91 last_fill_ = base::TimeTicks::Now(); |
| 91 audio_delay_ms_ = audio_delay_milliseconds; | 92 audio_delay_ms_ = audio_delay_milliseconds; |
| 92 volume_ = volume; | 93 volume_ = volume; |
| 93 key_pressed_ = key_pressed; | 94 key_pressed_ = key_pressed;*/ |
| 94 } | 95 } |
| 95 | 96 |
| 96 void WebRtcLocalAudioSourceProvider::GetAudioProcessingParams( | 97 void WebRtcLocalAudioSourceProvider::GetAudioProcessingParams( |
| 97 int* delay_ms, int* volume, bool* key_pressed) { | 98 int* delay_ms, int* volume, bool* key_pressed) { |
| 98 int elapsed_ms = 0; | 99 int elapsed_ms = 0; |
| 99 if (!last_fill_.is_null()) { | 100 if (!last_fill_.is_null()) { |
| 100 elapsed_ms = static_cast<int>( | 101 elapsed_ms = static_cast<int>( |
| 101 (base::TimeTicks::Now() - last_fill_).InMilliseconds()); | 102 (base::TimeTicks::Now() - last_fill_).InMilliseconds()); |
| 102 } | 103 } |
| 103 *delay_ms = audio_delay_ms_ + elapsed_ms + static_cast<int>( | 104 *delay_ms = audio_delay_ms_ + elapsed_ms + static_cast<int>( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 return 1.0; | 147 return 1.0; |
| 147 } | 148 } |
| 148 | 149 |
| 149 void WebRtcLocalAudioSourceProvider::SetSinkParamsForTesting( | 150 void WebRtcLocalAudioSourceProvider::SetSinkParamsForTesting( |
| 150 const media::AudioParameters& sink_params) { | 151 const media::AudioParameters& sink_params) { |
| 151 DCHECK(thread_checker_.CalledOnValidThread()); | 152 DCHECK(thread_checker_.CalledOnValidThread()); |
| 152 sink_params_ = sink_params; | 153 sink_params_ = sink_params; |
| 153 } | 154 } |
| 154 | 155 |
| 155 } // namespace content | 156 } // namespace content |
| OLD | NEW |