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 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 | 21 |
22 using blink::WebAudioDevice; | 22 using blink::WebAudioDevice; |
23 using blink::WebLocalFrame; | 23 using blink::WebLocalFrame; |
24 using blink::WebVector; | 24 using blink::WebVector; |
25 using blink::WebView; | 25 using blink::WebView; |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 | 28 |
29 RendererWebAudioDeviceImpl::RendererWebAudioDeviceImpl( | 29 RendererWebAudioDeviceImpl::RendererWebAudioDeviceImpl( |
30 const media::AudioParameters& params, | 30 const media::AudioParameters& params, |
31 const AudioDeviceFactory::SourceType source_type, | |
31 WebAudioDevice::RenderCallback* callback, | 32 WebAudioDevice::RenderCallback* callback, |
32 int session_id, | 33 int session_id, |
33 const url::Origin& security_origin) | 34 const url::Origin& security_origin) |
34 : params_(params), | 35 : sink_params_(params), |
o1ka
2016/11/15 22:44:27
There is no point in passing these params. Sink wi
Andrew MacPherson
2016/11/16 10:58:29
This makes perfect sense to me, thanks for the det
| |
36 source_type_(source_type), | |
35 client_callback_(callback), | 37 client_callback_(callback), |
36 session_id_(session_id), | 38 session_id_(session_id), |
37 security_origin_(security_origin) { | 39 security_origin_(security_origin) { |
38 DCHECK(client_callback_); | 40 DCHECK(client_callback_); |
39 } | 41 } |
40 | 42 |
41 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() { | 43 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() { |
42 DCHECK(!sink_); | 44 DCHECK(!sink_); |
43 } | 45 } |
44 | 46 |
45 void RendererWebAudioDeviceImpl::start() { | 47 void RendererWebAudioDeviceImpl::start() { |
46 DCHECK(thread_checker_.CalledOnValidThread()); | 48 DCHECK(thread_checker_.CalledOnValidThread()); |
47 | 49 |
48 if (sink_) | 50 if (sink_) |
49 return; // Already started. | 51 return; // Already started. |
50 | 52 |
51 // Assumption: This method is being invoked within a V8 call stack. CHECKs | 53 // Assumption: This method is being invoked within a V8 call stack. CHECKs |
52 // will fail in the call to frameForCurrentContext() otherwise. | 54 // will fail in the call to frameForCurrentContext() otherwise. |
53 // | 55 // |
54 // Therefore, we can perform look-ups to determine which RenderView is | 56 // Therefore, we can perform look-ups to determine which RenderView is |
55 // starting the audio device. The reason for all this is because the creator | 57 // starting the audio device. The reason for all this is because the creator |
56 // of the WebAudio objects might not be the actual source of the audio (e.g., | 58 // of the WebAudio objects might not be the actual source of the audio (e.g., |
57 // an extension creates a object that is passed and used within a page). | 59 // an extension creates a object that is passed and used within a page). |
58 WebLocalFrame* const web_frame = WebLocalFrame::frameForCurrentContext(); | 60 WebLocalFrame* const web_frame = WebLocalFrame::frameForCurrentContext(); |
59 RenderFrame* const render_frame = | 61 RenderFrame* const render_frame = |
60 web_frame ? RenderFrame::FromWebFrame(web_frame) : NULL; | 62 web_frame ? RenderFrame::FromWebFrame(web_frame) : NULL; |
61 sink_ = AudioDeviceFactory::NewAudioRendererSink( | 63 sink_ = AudioDeviceFactory::NewAudioRendererSink( |
62 AudioDeviceFactory::kSourceWebAudioInteractive, | 64 source_type_, |
63 render_frame ? render_frame->GetRoutingID() : MSG_ROUTING_NONE, | 65 render_frame ? render_frame->GetRoutingID() : MSG_ROUTING_NONE, |
64 session_id_, std::string(), security_origin_); | 66 session_id_, std::string(), security_origin_); |
65 | 67 |
66 // Specify the latency info to be passed to the browser side. | |
67 media::AudioParameters sink_params(params_); | |
68 sink_params.set_latency_tag(AudioDeviceFactory::GetSourceLatencyType( | |
69 AudioDeviceFactory::kSourceWebAudioInteractive)); | |
70 | |
71 #if defined(OS_ANDROID) | 68 #if defined(OS_ANDROID) |
72 // Use the media thread instead of the render thread for fake Render() calls | 69 // Use the media thread instead of the render thread for fake Render() calls |
73 // since it has special connotations for Blink and garbage collection. Timeout | 70 // since it has special connotations for Blink and garbage collection. Timeout |
74 // value chosen to be highly unlikely in the normal case. | 71 // value chosen to be highly unlikely in the normal case. |
75 webaudio_suspender_.reset(new media::SilentSinkSuspender( | 72 webaudio_suspender_.reset(new media::SilentSinkSuspender( |
76 this, base::TimeDelta::FromSeconds(30), sink_params, sink_, | 73 this, base::TimeDelta::FromSeconds(30), sink_params_, sink_, |
77 RenderThreadImpl::current()->GetMediaThreadTaskRunner())); | 74 RenderThreadImpl::current()->GetMediaThreadTaskRunner())); |
78 sink_->Initialize(sink_params, webaudio_suspender_.get()); | 75 sink_->Initialize(sink_params_, webaudio_suspender_.get()); |
79 #else | 76 #else |
80 sink_->Initialize(sink_params, this); | 77 sink_->Initialize(sink_params_, this); |
81 #endif | 78 #endif |
82 | 79 |
83 sink_->Start(); | 80 sink_->Start(); |
84 sink_->Play(); | 81 sink_->Play(); |
85 } | 82 } |
86 | 83 |
87 void RendererWebAudioDeviceImpl::stop() { | 84 void RendererWebAudioDeviceImpl::stop() { |
88 DCHECK(thread_checker_.CalledOnValidThread()); | 85 DCHECK(thread_checker_.CalledOnValidThread()); |
89 if (sink_) { | 86 if (sink_) { |
90 sink_->Stop(); | 87 sink_->Stop(); |
91 sink_ = nullptr; | 88 sink_ = nullptr; |
92 } | 89 } |
93 | 90 |
94 #if defined(OS_ANDROID) | 91 #if defined(OS_ANDROID) |
95 webaudio_suspender_.reset(); | 92 webaudio_suspender_.reset(); |
96 #endif | 93 #endif |
97 } | 94 } |
98 | 95 |
99 double RendererWebAudioDeviceImpl::sampleRate() { | 96 double RendererWebAudioDeviceImpl::sampleRate() { |
100 return params_.sample_rate(); | 97 return sink_params_.sample_rate(); |
98 } | |
99 | |
100 int RendererWebAudioDeviceImpl::framesPerBuffer() { | |
101 return sink_params_.frames_per_buffer(); | |
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) { |
106 // Wrap the output pointers using WebVector. | 107 // Wrap the output pointers using WebVector. |
107 WebVector<float*> web_audio_dest_data(static_cast<size_t>(dest->channels())); | 108 WebVector<float*> web_audio_dest_data(static_cast<size_t>(dest->channels())); |
108 for (int i = 0; i < dest->channels(); ++i) | 109 for (int i = 0; i < dest->channels(); ++i) |
109 web_audio_dest_data[i] = dest->channel(i); | 110 web_audio_dest_data[i] = dest->channel(i); |
110 | 111 |
111 // TODO(xians): Remove the following |web_audio_source_data| after | 112 // TODO(xians): Remove the following |web_audio_source_data| after |
112 // changing the blink interface. | 113 // changing the blink interface. |
113 WebVector<float*> web_audio_source_data(static_cast<size_t>(0)); | 114 WebVector<float*> web_audio_source_data(static_cast<size_t>(0)); |
114 client_callback_->render(web_audio_source_data, web_audio_dest_data, | 115 client_callback_->render(web_audio_source_data, web_audio_dest_data, |
115 dest->frames()); | 116 dest->frames()); |
116 return dest->frames(); | 117 return dest->frames(); |
117 } | 118 } |
118 | 119 |
119 void RendererWebAudioDeviceImpl::OnRenderError() { | 120 void RendererWebAudioDeviceImpl::OnRenderError() { |
120 // TODO(crogers): implement error handling. | 121 // TODO(crogers): implement error handling. |
121 } | 122 } |
122 | 123 |
123 } // namespace content | 124 } // namespace content |
OLD | NEW |