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/pepper/pepper_platform_audio_input_impl.h" | 5 #include "content/renderer/pepper/pepper_platform_audio_input_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() { | 23 PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() { |
24 // Make sure we have been shut down. Warning: this will usually happen on | 24 // Make sure we have been shut down. Warning: this will usually happen on |
25 // the I/O thread! | 25 // the I/O thread! |
26 DCHECK_EQ(0, stream_id_); | 26 DCHECK_EQ(0, stream_id_); |
27 DCHECK(!client_); | 27 DCHECK(!client_); |
28 } | 28 } |
29 | 29 |
30 // static | 30 // static |
31 PepperPlatformAudioInputImpl* PepperPlatformAudioInputImpl::Create( | 31 PepperPlatformAudioInputImpl* PepperPlatformAudioInputImpl::Create( |
32 uint32_t sample_rate, | 32 int sample_rate, |
33 uint32_t sample_count, | 33 int frames_per_buffer, |
34 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) { | 34 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) { |
35 scoped_refptr<PepperPlatformAudioInputImpl> audio_input( | 35 scoped_refptr<PepperPlatformAudioInputImpl> audio_input( |
36 new PepperPlatformAudioInputImpl); | 36 new PepperPlatformAudioInputImpl); |
37 if (audio_input->Initialize(sample_rate, sample_count, client)) { | 37 if (audio_input->Initialize(sample_rate, frames_per_buffer, client)) { |
38 // Balanced by Release invoked in | 38 // Balanced by Release invoked in |
39 // PepperPlatformAudioInputImpl::ShutDownOnIOThread(). | 39 // PepperPlatformAudioInputImpl::ShutDownOnIOThread(). |
40 return audio_input.release(); | 40 return audio_input.release(); |
41 } | 41 } |
42 return NULL; | 42 return NULL; |
43 } | 43 } |
44 | 44 |
45 bool PepperPlatformAudioInputImpl::StartCapture() { | 45 bool PepperPlatformAudioInputImpl::StartCapture() { |
46 ChildProcess::current()->io_message_loop()->PostTask( | 46 ChildProcess::current()->io_message_loop()->PostTask( |
47 FROM_HERE, | 47 FROM_HERE, |
(...skipping 11 matching lines...) Expand all Loading... |
59 void PepperPlatformAudioInputImpl::ShutDown() { | 59 void PepperPlatformAudioInputImpl::ShutDown() { |
60 // Called on the main thread to stop all audio callbacks. We must only change | 60 // Called on the main thread to stop all audio callbacks. We must only change |
61 // the client on the main thread, and the delegates from the I/O thread. | 61 // the client on the main thread, and the delegates from the I/O thread. |
62 client_ = NULL; | 62 client_ = NULL; |
63 ChildProcess::current()->io_message_loop()->PostTask( | 63 ChildProcess::current()->io_message_loop()->PostTask( |
64 FROM_HERE, | 64 FROM_HERE, |
65 base::Bind(&PepperPlatformAudioInputImpl::ShutDownOnIOThread, this)); | 65 base::Bind(&PepperPlatformAudioInputImpl::ShutDownOnIOThread, this)); |
66 } | 66 } |
67 | 67 |
68 bool PepperPlatformAudioInputImpl::Initialize( | 68 bool PepperPlatformAudioInputImpl::Initialize( |
69 uint32_t sample_rate, | 69 int sample_rate, |
70 uint32_t sample_count, | 70 int frames_per_buffer, |
71 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) { | 71 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) { |
72 DCHECK(client); | 72 DCHECK(client); |
73 // Make sure we don't call init more than once. | 73 // Make sure we don't call init more than once. |
74 DCHECK_EQ(0, stream_id_); | 74 DCHECK_EQ(0, stream_id_); |
75 | 75 |
76 client_ = client; | 76 client_ = client; |
77 | 77 |
78 AudioParameters params; | 78 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
79 params.format = AudioParameters::AUDIO_PCM_LINEAR; | 79 CHANNEL_LAYOUT_MONO, |
80 params.channels = 1; | 80 sample_rate, 16, frames_per_buffer); |
81 params.sample_rate = sample_rate; | |
82 params.bits_per_sample = 16; | |
83 params.samples_per_packet = sample_count; | |
84 | 81 |
85 ChildProcess::current()->io_message_loop()->PostTask( | 82 ChildProcess::current()->io_message_loop()->PostTask( |
86 FROM_HERE, | 83 FROM_HERE, |
87 base::Bind(&PepperPlatformAudioInputImpl::InitializeOnIOThread, | 84 base::Bind(&PepperPlatformAudioInputImpl::InitializeOnIOThread, |
88 this, params)); | 85 this, params)); |
89 return true; | 86 return true; |
90 } | 87 } |
91 | 88 |
92 void PepperPlatformAudioInputImpl::InitializeOnIOThread( | 89 void PepperPlatformAudioInputImpl::InitializeOnIOThread( |
93 const AudioParameters& params) { | 90 const AudioParameters& params) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 } | 143 } |
147 | 144 |
148 void PepperPlatformAudioInputImpl::OnVolume(double volume) { | 145 void PepperPlatformAudioInputImpl::OnVolume(double volume) { |
149 } | 146 } |
150 | 147 |
151 void PepperPlatformAudioInputImpl::OnStateChanged(AudioStreamState state) { | 148 void PepperPlatformAudioInputImpl::OnStateChanged(AudioStreamState state) { |
152 } | 149 } |
153 | 150 |
154 void PepperPlatformAudioInputImpl::OnDeviceReady(const std::string&) { | 151 void PepperPlatformAudioInputImpl::OnDeviceReady(const std::string&) { |
155 } | 152 } |
OLD | NEW |