| 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/renderer_webaudiodevice_impl.h" | 5 #include "content/renderer/media/renderer_webaudiodevice_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "content/renderer/media/audio_device_factory.h" | 17 #include "content/renderer/media/audio_device_factory.h" |
| 18 #include "content/renderer/render_frame_impl.h" | 18 #include "content/renderer/render_frame_impl.h" |
| 19 #include "media/audio/null_audio_sink.h" | 19 #include "media/audio/null_audio_sink.h" |
| 20 #include "media/base/media_switches.h" | 20 #include "media/base/media_switches.h" |
| 21 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 21 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 22 #include "third_party/WebKit/public/web/WebView.h" | 22 #include "third_party/WebKit/public/web/WebView.h" |
| 23 | 23 |
| 24 using blink::WebAudioDevice; | 24 using blink::WebAudioDevice; |
| 25 using blink::WebAudioTimestamp; |
| 25 using blink::WebLocalFrame; | 26 using blink::WebLocalFrame; |
| 26 using blink::WebVector; | 27 using blink::WebVector; |
| 27 using blink::WebView; | 28 using blink::WebView; |
| 28 | 29 |
| 29 namespace content { | 30 namespace content { |
| 30 | 31 |
| 31 #if defined(OS_ANDROID) | 32 #if defined(OS_ANDROID) |
| 32 static const int kSilenceInSecondsToEnterIdleMode = 30; | 33 static const int kSilenceInSecondsToEnterIdleMode = 30; |
| 33 #endif | 34 #endif |
| 34 | 35 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 is_first_buffer_after_silence_ = false; | 96 is_first_buffer_after_silence_ = false; |
| 96 start_null_audio_sink_callback_.Cancel(); | 97 start_null_audio_sink_callback_.Cancel(); |
| 97 } | 98 } |
| 98 | 99 |
| 99 double RendererWebAudioDeviceImpl::sampleRate() { | 100 double RendererWebAudioDeviceImpl::sampleRate() { |
| 100 return params_.sample_rate(); | 101 return params_.sample_rate(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 int RendererWebAudioDeviceImpl::Render(media::AudioBus* dest, | 104 int RendererWebAudioDeviceImpl::Render(media::AudioBus* dest, |
| 104 uint32_t frames_delayed, | 105 uint32_t frames_delayed, |
| 105 uint32_t frames_skipped) { | 106 uint32_t frames_skipped, |
| 107 const media::AudioTimestamp& timestamp) { |
| 106 #if defined(OS_ANDROID) | 108 #if defined(OS_ANDROID) |
| 107 if (is_first_buffer_after_silence_) { | 109 if (is_first_buffer_after_silence_) { |
| 108 DCHECK(!is_using_null_audio_sink_); | 110 DCHECK(!is_using_null_audio_sink_); |
| 109 first_buffer_after_silence_->CopyTo(dest); | 111 first_buffer_after_silence_->CopyTo(dest); |
| 110 is_first_buffer_after_silence_ = false; | 112 is_first_buffer_after_silence_ = false; |
| 111 return dest->frames(); | 113 return dest->frames(); |
| 112 } | 114 } |
| 113 #endif | 115 #endif |
| 114 // Wrap the output pointers using WebVector. | 116 // Wrap the output pointers using WebVector. |
| 115 WebVector<float*> web_audio_dest_data( | 117 WebVector<float*> web_audio_dest_data( |
| 116 static_cast<size_t>(dest->channels())); | 118 static_cast<size_t>(dest->channels())); |
| 117 for (int i = 0; i < dest->channels(); ++i) | 119 for (int i = 0; i < dest->channels(); ++i) |
| 118 web_audio_dest_data[i] = dest->channel(i); | 120 web_audio_dest_data[i] = dest->channel(i); |
| 119 | 121 |
| 120 // TODO(xians): Remove the following |web_audio_source_data| after | 122 // TODO(xians): Remove the following |web_audio_source_data| after |
| 121 // changing the blink interface. | 123 // changing the blink interface. |
| 122 WebVector<float*> web_audio_source_data(static_cast<size_t>(0)); | 124 WebVector<float*> web_audio_source_data(static_cast<size_t>(0)); |
| 125 |
| 126 double seconds = timestamp.ticks |
| 127 / static_cast<double>(base::Time::kMicrosecondsPerSecond); |
| 128 WebAudioTimestamp web_audio_timestamp(static_cast<size_t>(timestamp.frames), |
| 129 seconds); |
| 123 client_callback_->render(web_audio_source_data, | 130 client_callback_->render(web_audio_source_data, |
| 124 web_audio_dest_data, | 131 web_audio_dest_data, |
| 125 dest->frames()); | 132 dest->frames(), |
| 133 web_audio_timestamp); |
| 126 | 134 |
| 127 #if defined(OS_ANDROID) | 135 #if defined(OS_ANDROID) |
| 128 const bool is_zero = dest->AreFramesZero(); | 136 const bool is_zero = dest->AreFramesZero(); |
| 129 if (!is_zero) { | 137 if (!is_zero) { |
| 130 first_silence_time_ = base::TimeTicks(); | 138 first_silence_time_ = base::TimeTicks(); |
| 131 if (is_using_null_audio_sink_) { | 139 if (is_using_null_audio_sink_) { |
| 132 // This is called on the main render thread when audio is detected. | 140 // This is called on the main render thread when audio is detected. |
| 133 DCHECK(thread_checker_.CalledOnValidThread()); | 141 DCHECK(thread_checker_.CalledOnValidThread()); |
| 134 is_using_null_audio_sink_ = false; | 142 is_using_null_audio_sink_ = false; |
| 135 is_first_buffer_after_silence_ = true; | 143 is_first_buffer_after_silence_ = true; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 161 } | 169 } |
| 162 #endif | 170 #endif |
| 163 return dest->frames(); | 171 return dest->frames(); |
| 164 } | 172 } |
| 165 | 173 |
| 166 void RendererWebAudioDeviceImpl::OnRenderError() { | 174 void RendererWebAudioDeviceImpl::OnRenderError() { |
| 167 // TODO(crogers): implement error handling. | 175 // TODO(crogers): implement error handling. |
| 168 } | 176 } |
| 169 | 177 |
| 170 } // namespace content | 178 } // namespace content |
| OLD | NEW |