Chromium Code Reviews| 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 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_IMPL_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_IMPL_H_ | 6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_IMPL_H_ |
| 7 | 7 |
| 8 #include <string> | |
| 9 | |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | |
| 11 #include "content/renderer/media/audio_input_message_filter.h" | 14 #include "content/renderer/media/audio_input_message_filter.h" |
| 15 #include "media/audio/audio_parameters.h" | |
| 12 #include "webkit/plugins/ppapi/plugin_delegate.h" | 16 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 13 | 17 |
| 18 class PepperPluginDelegateImpl; | |
|
viettrungluu
2012/03/16 22:29:09
Alphabetical order?
yzshen1
2012/03/17 09:32:56
I thought 'class' should be prior to 'struct'.
On
viettrungluu
2012/03/17 23:52:22
Most places I've seen alphabetize based on the nam
yzshen1
2012/03/19 21:47:54
Done.
| |
| 14 struct AudioParameters; | 19 struct AudioParameters; |
| 15 | 20 |
| 16 class PepperPlatformAudioInputImpl | 21 class PepperPlatformAudioInputImpl |
| 17 : public webkit::ppapi::PluginDelegate::PlatformAudioInput, | 22 : public webkit::ppapi::PluginDelegate::PlatformAudioInput, |
| 18 public AudioInputMessageFilter::Delegate, | 23 public AudioInputMessageFilter::Delegate, |
| 19 public base::RefCountedThreadSafe<PepperPlatformAudioInputImpl> { | 24 public base::RefCountedThreadSafe<PepperPlatformAudioInputImpl> { |
| 20 public: | 25 public: |
| 21 virtual ~PepperPlatformAudioInputImpl(); | 26 virtual ~PepperPlatformAudioInputImpl(); |
| 22 | 27 |
| 23 // Factory function, returns NULL on failure. StreamCreated() will be called | 28 // Factory function, returns NULL on failure. StreamCreated() will be called |
| 24 // when the stream is created. | 29 // when the stream is created. |
| 25 static PepperPlatformAudioInputImpl* Create( | 30 static PepperPlatformAudioInputImpl* Create( |
| 31 const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate, | |
| 32 const std::string& device_id, | |
| 26 uint32_t sample_rate, | 33 uint32_t sample_rate, |
| 27 uint32_t sample_count, | 34 uint32_t sample_count, |
| 28 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client); | 35 webkit::ppapi::PluginDelegate::PlatformAudioInputClient* client); |
| 29 | 36 |
| 30 // PlatformAudioInput implementation (called on main thread). | 37 // PlatformAudioInput implementation (called on main thread). |
| 31 virtual bool StartCapture() OVERRIDE; | 38 virtual bool StartCapture() OVERRIDE; |
| 32 virtual bool StopCapture() OVERRIDE; | 39 virtual bool StopCapture() OVERRIDE; |
| 33 virtual void ShutDown() OVERRIDE; | 40 virtual void ShutDown() OVERRIDE; |
| 34 | 41 |
| 35 private: | 42 private: |
| 36 PepperPlatformAudioInputImpl(); | 43 PepperPlatformAudioInputImpl(); |
| 37 | 44 |
| 38 bool Initialize( | 45 bool Initialize( |
| 46 const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate, | |
| 47 const std::string& device_id, | |
| 39 uint32_t sample_rate, | 48 uint32_t sample_rate, |
| 40 uint32_t sample_count, | 49 uint32_t sample_count, |
| 41 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client); | 50 webkit::ppapi::PluginDelegate::PlatformAudioInputClient* client); |
| 42 | 51 |
| 43 // I/O thread backends to above functions. | 52 // I/O thread backends to above functions. |
| 44 void InitializeOnIOThread(const AudioParameters& params); | 53 void InitializeOnIOThread(int session_id); |
| 45 void StartCaptureOnIOThread(); | 54 void StartCaptureOnIOThread(); |
| 46 void StopCaptureOnIOThread(); | 55 void StopCaptureOnIOThread(); |
| 47 void ShutDownOnIOThread(); | 56 void ShutDownOnIOThread(); |
| 48 | 57 |
| 49 // AudioInputMessageFilter::Delegate. | 58 // AudioInputMessageFilter::Delegate. |
| 50 virtual void OnStreamCreated(base::SharedMemoryHandle handle, | 59 virtual void OnStreamCreated(base::SharedMemoryHandle handle, |
| 51 base::SyncSocket::Handle socket_handle, | 60 base::SyncSocket::Handle socket_handle, |
| 52 uint32 length) OVERRIDE; | 61 uint32 length) OVERRIDE; |
| 53 virtual void OnVolume(double volume) OVERRIDE; | 62 virtual void OnVolume(double volume) OVERRIDE; |
| 54 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; | 63 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; |
| 55 virtual void OnDeviceReady(const std::string&) OVERRIDE; | 64 virtual void OnDeviceReady(const std::string&) OVERRIDE; |
| 56 | 65 |
| 66 void OnDeviceOpened(int request_id, | |
| 67 bool succeeded, | |
| 68 const std::string& label); | |
| 69 void CloseDevice(); | |
| 70 void NotifyStreamCreationFailed(); | |
| 71 | |
| 57 // The client to notify when the stream is created. THIS MUST ONLY BE | 72 // The client to notify when the stream is created. THIS MUST ONLY BE |
| 58 // ACCESSED ON THE MAIN THREAD. | 73 // ACCESSED ON THE MAIN THREAD. |
| 59 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client_; | 74 webkit::ppapi::PluginDelegate::PlatformAudioInputClient* client_; |
| 60 | 75 |
| 61 // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE | 76 // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE |
| 62 // I/O thread except to send messages and get the message loop. | 77 // I/O thread except to send messages and get the message loop. |
| 63 scoped_refptr<AudioInputMessageFilter> filter_; | 78 scoped_refptr<AudioInputMessageFilter> filter_; |
| 64 | 79 |
| 65 // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD | 80 // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD |
| 66 // or else you could race with the initialize function which sets it. | 81 // or else you could race with the initialize function which sets it. |
| 67 int32 stream_id_; | 82 int32 stream_id_; |
| 68 | 83 |
| 69 base::MessageLoopProxy* main_message_loop_proxy_; | 84 base::MessageLoopProxy* main_message_loop_proxy_; |
| 70 | 85 |
| 86 // THIS MUST ONLY BE ACCESSED ON THE MAIN THREAD. | |
|
viettrungluu
2012/03/16 22:29:09
Is the thread usage of this class documented somew
yzshen1
2012/03/19 21:47:54
Done. I added a threading comment for this class a
viettrungluu
2012/03/20 18:20:02
Sounds fine, now that you've clarified the thread
| |
| 87 base::WeakPtr<PepperPluginDelegateImpl> plugin_delegate_; | |
| 88 | |
| 89 // The label of the opened device. THIS MUST ONLY BE ACCESSED ON THE MAIN | |
|
viettrungluu
2012/03/16 22:29:09
What exactly is a "label"? (The human-readable nam
yzshen1
2012/03/19 21:47:54
This is a unique ID generated by the media code to
| |
| 90 // THREAD. | |
| 91 std::string label_; | |
| 92 | |
| 93 // Whether ShutDownOnIOThread() has been called. THIS MUST ONLY BE ACCESSED ON | |
| 94 // THE I/O THREAD. | |
| 95 bool shutdown_called_; | |
| 96 | |
| 97 // Initialized on the main thread and accessed on the I/O thread afterwards. | |
| 98 AudioParameters params_; | |
| 99 | |
| 71 DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioInputImpl); | 100 DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioInputImpl); |
| 72 }; | 101 }; |
| 73 | 102 |
| 74 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_IMPL_H_ | 103 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_IMPL_H_ |
| OLD | NEW |