Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: content/renderer/pepper/pepper_platform_audio_input_impl.h

Issue 9705056: PepperPlatformAudioInputImpl: support audio input device selection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync&resolve again Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
14 class AudioParameters; 18 class AudioParameters;
19 class PepperPluginDelegateImpl;
15 20
21 // PepperPlatformAudioInputImpl is operated on two threads: the main thread (the
22 // thread on which objects are created) and the I/O thread. All public methods,
23 // except the destructor, must be called on the main thread. The notifications
24 // to the users of this class (via the PlatformAudioInputClient interface) are
25 // also sent on the main thread. Internally, this class sends audio input IPC
26 // messages and receives AudioInputMessageFilter::Delegate notifications on the
27 // I/O thread.
16 class PepperPlatformAudioInputImpl 28 class PepperPlatformAudioInputImpl
17 : public webkit::ppapi::PluginDelegate::PlatformAudioInput, 29 : public webkit::ppapi::PluginDelegate::PlatformAudioInput,
18 public AudioInputMessageFilter::Delegate, 30 public AudioInputMessageFilter::Delegate,
19 public base::RefCountedThreadSafe<PepperPlatformAudioInputImpl> { 31 public base::RefCountedThreadSafe<PepperPlatformAudioInputImpl> {
20 public: 32 public:
21 virtual ~PepperPlatformAudioInputImpl(); 33 virtual ~PepperPlatformAudioInputImpl();
22 34
23 // Factory function, returns NULL on failure. StreamCreated() will be called 35 // Factory function, returns NULL on failure. StreamCreated() will be called
24 // when the stream is created. 36 // when the stream is created.
25 static PepperPlatformAudioInputImpl* Create( 37 static PepperPlatformAudioInputImpl* Create(
38 const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate,
39 const std::string& device_id,
26 int sample_rate, 40 int sample_rate,
27 int frames_per_buffer, 41 int frames_per_buffer,
28 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client); 42 webkit::ppapi::PluginDelegate::PlatformAudioInputClient* client);
29 43
30 // PlatformAudioInput implementation (called on main thread). 44 // PlatformAudioInput implementation (called on main thread).
31 virtual bool StartCapture() OVERRIDE; 45 virtual void StartCapture() OVERRIDE;
32 virtual bool StopCapture() OVERRIDE; 46 virtual void StopCapture() OVERRIDE;
33 virtual void ShutDown() OVERRIDE; 47 virtual void ShutDown() OVERRIDE;
34 48
35 private: 49 private:
36 PepperPlatformAudioInputImpl(); 50 PepperPlatformAudioInputImpl();
37 51
38 bool Initialize( 52 bool Initialize(
53 const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate,
54 const std::string& device_id,
39 int sample_rate, 55 int sample_rate,
40 int frames_per_buffer, 56 int frames_per_buffer,
41 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client); 57 webkit::ppapi::PluginDelegate::PlatformAudioInputClient* client);
42 58
43 // I/O thread backends to above functions. 59 // I/O thread backends to above functions.
44 void InitializeOnIOThread(const AudioParameters& params); 60 void InitializeOnIOThread(int session_id);
45 void StartCaptureOnIOThread(); 61 void StartCaptureOnIOThread();
46 void StopCaptureOnIOThread(); 62 void StopCaptureOnIOThread();
47 void ShutDownOnIOThread(); 63 void ShutDownOnIOThread();
48 64
49 // AudioInputMessageFilter::Delegate. 65 // AudioInputMessageFilter::Delegate.
50 virtual void OnStreamCreated(base::SharedMemoryHandle handle, 66 virtual void OnStreamCreated(base::SharedMemoryHandle handle,
51 base::SyncSocket::Handle socket_handle, 67 base::SyncSocket::Handle socket_handle,
52 uint32 length) OVERRIDE; 68 uint32 length) OVERRIDE;
53 virtual void OnVolume(double volume) OVERRIDE; 69 virtual void OnVolume(double volume) OVERRIDE;
54 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; 70 virtual void OnStateChanged(AudioStreamState state) OVERRIDE;
55 virtual void OnDeviceReady(const std::string&) OVERRIDE; 71 virtual void OnDeviceReady(const std::string&) OVERRIDE;
56 72
73 void OnDeviceOpened(int request_id,
74 bool succeeded,
75 const std::string& label);
76 void CloseDevice();
77 void NotifyStreamCreationFailed();
78
57 // The client to notify when the stream is created. THIS MUST ONLY BE 79 // The client to notify when the stream is created. THIS MUST ONLY BE
58 // ACCESSED ON THE MAIN THREAD. 80 // ACCESSED ON THE MAIN THREAD.
59 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client_; 81 webkit::ppapi::PluginDelegate::PlatformAudioInputClient* client_;
60 82
61 // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE 83 // 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. 84 // I/O thread except to send messages and get the message loop.
63 scoped_refptr<AudioInputMessageFilter> filter_; 85 scoped_refptr<AudioInputMessageFilter> filter_;
64 86
65 // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD 87 // 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. 88 // or else you could race with the initialize function which sets it.
67 int32 stream_id_; 89 int32 stream_id_;
68 90
69 base::MessageLoopProxy* main_message_loop_proxy_; 91 base::MessageLoopProxy* main_message_loop_proxy_;
70 92
93 // THIS MUST ONLY BE ACCESSED ON THE MAIN THREAD.
94 base::WeakPtr<PepperPluginDelegateImpl> plugin_delegate_;
95
96 // The unique ID to identify the opened device. THIS MUST ONLY BE ACCESSED ON
97 // THE MAIN THREAD.
98 std::string label_;
99
100 // Whether ShutDownOnIOThread() has been called. THIS MUST ONLY BE ACCESSED ON
101 // THE I/O THREAD.
102 bool shutdown_called_;
103
104 // Initialized on the main thread and accessed on the I/O thread afterwards.
105 AudioParameters params_;
106
71 DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioInputImpl); 107 DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioInputImpl);
72 }; 108 };
73 109
74 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_IMPL_H_ 110 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_IMPL_H_
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_dispatcher.cc ('k') | content/renderer/pepper/pepper_platform_audio_input_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698