Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/render_audiosourceprovider.h" | |
| 6 | |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAudioSourceProvide rClient.h" | |
| 10 | |
| 11 using std::vector; | |
| 12 using WebKit::WebVector; | |
| 13 | |
| 14 RenderAudioSourceProvider::RenderAudioSourceProvider( | |
| 15 media::AudioRendererSink::RenderCallback* renderer) | |
| 16 : is_running_(false), | |
| 17 volume_(1.0), | |
| 18 renderer_(renderer), | |
| 19 client_(0) { | |
|
tommi (sloooow) - chröme
2011/12/19 15:26:24
use NULL for initializing pointers.
Chris Rogers
2011/12/19 21:40:35
Righto! Too much time spent in WebKit :)
On 2011/
| |
| 20 } | |
| 21 | |
| 22 void RenderAudioSourceProvider::Start() { | |
| 23 if (!is_running_) { | |
|
tommi (sloooow) - chröme
2011/12/19 15:26:24
nit: just set is_running_ to true and skip the if(
Chris Rogers
2011/12/19 21:40:35
Done.
| |
| 24 is_running_ = true; | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 void RenderAudioSourceProvider::Stop() { | |
| 29 if (is_running_) { | |
|
tommi (sloooow) - chröme
2011/12/19 15:26:24
ditto
Chris Rogers
2011/12/19 21:40:35
Done.
| |
| 30 is_running_ = false; | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 void RenderAudioSourceProvider::Play() { | |
| 35 is_running_ = true; | |
|
tommi (sloooow) - chröme
2011/12/19 15:26:24
what's the difference between Start() and Play()?
Chris Rogers
2011/12/19 21:40:35
The Start()/Play()/Pause()/Stop() state is describ
| |
| 36 } | |
| 37 | |
| 38 void RenderAudioSourceProvider::Pause(bool flush) { | |
| 39 is_running_ = false; | |
|
tommi (sloooow) - chröme
2011/12/19 15:26:24
same here with Stop vs Pause... could you call Pau
Chris Rogers
2011/12/19 21:40:35
I realize that it's unfortunate to have four calls
tommi (sloooow) - chröme
2011/12/20 15:05:46
ah, I see. Thanks for the info. Two methods would
| |
| 40 } | |
| 41 | |
| 42 bool RenderAudioSourceProvider::SetVolume(double volume) { | |
| 43 volume_ = volume; | |
| 44 return true; | |
| 45 } | |
| 46 | |
| 47 void RenderAudioSourceProvider::Initialize( | |
| 48 size_t buffer_size, | |
| 49 int channels, | |
| 50 double sample_rate, | |
| 51 AudioParameters::Format latency_format, | |
| 52 RenderCallback* renderer) { | |
| 53 // We already know what the renderer is from our constructor. | |
| 54 DCHECK_EQ(renderer, renderer_); | |
| 55 | |
| 56 // Inform WebKit about the audio stream format. | |
| 57 if (client_) | |
| 58 client_->setFormat(channels, sample_rate); | |
| 59 } | |
| 60 | |
| 61 void RenderAudioSourceProvider::setClient( | |
| 62 WebKit::WebAudioSourceProviderClient* client) { | |
| 63 client_ = client; | |
| 64 | |
| 65 if (client) { | |
| 66 // Detach the audio renderer from normal playback and make us be the sink. | |
| 67 // The renderer will call Initialize() when the stream format is known. | |
| 68 renderer_->SetAudioRendererSink(this); | |
| 69 } else { | |
| 70 // Restore normal playback. | |
| 71 renderer_->SetAudioRendererSink(0); | |
|
tommi (sloooow) - chröme
2011/12/19 15:26:24
NULL
Chris Rogers
2011/12/19 21:40:35
Done.
| |
| 72 } | |
| 73 } | |
| 74 | |
| 75 void RenderAudioSourceProvider::provideInput( | |
| 76 const WebVector<float*>& audio_data, size_t number_of_frames) { | |
| 77 DCHECK(renderer_); | |
| 78 DCHECK(client_); | |
| 79 | |
| 80 if (renderer_ && is_running_) { | |
| 81 // Wrap WebVector as std::vector. | |
| 82 vector<float*> v(audio_data.size()); | |
| 83 for (size_t i = 0; i < audio_data.size(); ++i) | |
|
tommi (sloooow) - chröme
2011/12/19 15:26:24
memcpy?
Chris Rogers
2011/12/19 21:40:35
This is copying pointer values (one per audio chan
tommi (sloooow) - chröme
2011/12/20 15:05:46
Yes, I know, but since the pointers are stored in
| |
| 84 v[i] = audio_data[i]; | |
| 85 | |
| 86 // TODO(crogers): figure out if we should volume scale here or in common | |
| 87 // WebAudio code. In any case we need to take care of volume. | |
| 88 renderer_->Render(v, number_of_frames, 0); | |
| 89 } else { | |
| 90 // Provide silence if the source is not running. | |
| 91 for (size_t i = 0; i < audio_data.size(); ++i) { | |
|
tommi (sloooow) - chröme
2011/12/19 15:26:24
nit: no {} like above or add {} there
Chris Rogers
2011/12/19 21:40:35
Done.
| |
| 92 memset(audio_data[i], 0, sizeof(float) * number_of_frames); | |
| 93 } | |
| 94 } | |
| 95 } | |
| OLD | NEW |