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

Side by Side Diff: webkit/glue/plugins/pepper_audio.h

Issue 4985001: Initial audio implementation. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_ 5 #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_ 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_
7 7
8 #include "base/ref_counted.h" 8 #include "base/ref_counted.h"
9 #include "base/scoped_ptr.h"
10 #include "base/shared_memory.h" 9 #include "base/shared_memory.h"
11 #include "base/simple_thread.h"
12 #include "base/sync_socket.h" 10 #include "base/sync_socket.h"
13 #include "ppapi/c/dev/ppb_audio_dev.h" 11 #include "ppapi/c/dev/ppb_audio_dev.h"
14 #include "ppapi/c/dev/ppb_audio_config_dev.h" 12 #include "ppapi/c/dev/ppb_audio_config_dev.h"
15 #include "ppapi/c/dev/ppb_audio_trusted_dev.h" 13 #include "ppapi/c/dev/ppb_audio_trusted_dev.h"
16 #include "ppapi/c/pp_completion_callback.h" 14 #include "ppapi/c/pp_completion_callback.h"
15 #include "ppapi/shared_impl/audio_impl.h"
17 #include "webkit/glue/plugins/pepper_plugin_delegate.h" 16 #include "webkit/glue/plugins/pepper_plugin_delegate.h"
18 #include "webkit/glue/plugins/pepper_plugin_instance.h" 17 #include "webkit/glue/plugins/pepper_plugin_instance.h"
19 #include "webkit/glue/plugins/pepper_plugin_module.h" 18 #include "webkit/glue/plugins/pepper_plugin_module.h"
20 #include "webkit/glue/plugins/pepper_resource.h" 19 #include "webkit/glue/plugins/pepper_resource.h"
21 20
22 namespace pepper { 21 namespace pepper {
23 22
24 class PluginInstance; 23 class PluginInstance;
25 class PluginModule; 24 class PluginModule;
26 25
27 class AudioConfig : public Resource { 26 class AudioConfig : public Resource {
28 public: 27 public:
29 AudioConfig(PluginModule* module, 28 AudioConfig(PluginModule* module,
30 PP_AudioSampleRate_Dev sample_rate, 29 PP_AudioSampleRate_Dev sample_rate,
31 uint32_t sample_frame_count); 30 uint32_t sample_frame_count);
32 size_t BufferSize(); 31 size_t BufferSize();
33 static const PPB_AudioConfig_Dev* GetInterface(); 32 static const PPB_AudioConfig_Dev* GetInterface();
34 33
35 PP_AudioSampleRate_Dev sample_rate() { return sample_rate_; } 34 PP_AudioSampleRate_Dev sample_rate() { return sample_rate_; }
36 uint32_t sample_frame_count() { return sample_frame_count_; } 35 uint32_t sample_frame_count() { return sample_frame_count_; }
37 36
38 private: 37 private:
39 // Resource override. 38 // Resource override.
40 virtual AudioConfig* AsAudioConfig(); 39 virtual AudioConfig* AsAudioConfig();
41 40
42 PP_AudioSampleRate_Dev sample_rate_; 41 PP_AudioSampleRate_Dev sample_rate_;
43 uint32_t sample_frame_count_; 42 uint32_t sample_frame_count_;
44 }; 43 };
45 44
45 // Some of the backend functionality of this class is implemented by the
46 // AudioImpl so it can be shared with the proxy.
46 class Audio : public Resource, 47 class Audio : public Resource,
47 public PluginDelegate::PlatformAudio::Client, 48 public pp::shared_impl::AudioImpl,
48 public base::DelegateSimpleThread::Delegate { 49 public PluginDelegate::PlatformAudio::Client {
49 public: 50 public:
50 explicit Audio(PluginModule* module, PP_Instance instance_id); 51 explicit Audio(PluginModule* module, PP_Instance instance_id);
51 virtual ~Audio(); 52 virtual ~Audio();
52 53
53 static const PPB_Audio_Dev* GetInterface(); 54 static const PPB_Audio_Dev* GetInterface();
54 static const PPB_AudioTrusted_Dev* GetTrustedInterface(); 55 static const PPB_AudioTrusted_Dev* GetTrustedInterface();
55 56
56 bool Init(PluginDelegate* plugin_delegate,
57 PP_Resource config_id,
58 PPB_Audio_Callback user_callback, void* user_data);
59
60 int32_t Open(PluginDelegate* plugin_delegate,
61 PP_Resource config_id,
62 PP_CompletionCallback create_callback);
63
64 PP_Resource GetCurrentConfiguration() {
65 return config_->GetReference();
66 }
67
68 PP_Instance pp_instance() { 57 PP_Instance pp_instance() {
69 return pp_instance_; 58 return pp_instance_;
70 } 59 }
71 60
61 // PPB_Audio implementation.
62 bool Init(PluginDelegate* plugin_delegate,
63 PP_Resource config_id,
64 PPB_Audio_Callback user_callback, void* user_data);
65 PP_Resource GetCurrentConfig();
66 bool StartPlayback();
67 bool StopPlayback();
68
69 // PPB_Audio_Trusted implementation.
70 int32_t Open(PluginDelegate* plugin_delegate,
71 PP_Resource config_id,
72 PP_CompletionCallback create_callback);
72 int32_t GetSyncSocket(int* sync_socket); 73 int32_t GetSyncSocket(int* sync_socket);
73
74 int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size); 74 int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size);
75 75
76 bool StartPlayback();
77
78 bool StopPlayback();
79
80 // Resource override. 76 // Resource override.
81 virtual Audio* AsAudio(); 77 virtual Audio* AsAudio();
82 78
83 private: 79 private:
84 // pepper::PluginDelegate::PlatformAudio::Client implementation. 80 // pepper::PluginDelegate::PlatformAudio::Client implementation.
85 virtual void StreamCreated(base::SharedMemoryHandle shared_memory_handle, 81 virtual void StreamCreated(base::SharedMemoryHandle shared_memory_handle,
86 size_t shared_memory_size_, 82 size_t shared_memory_size_,
87 base::SyncSocket::Handle socket); 83 base::SyncSocket::Handle socket);
88 // End of pepper::PluginDelegate::PlatformAudio::Client implementation.
89
90 // Audio thread. DelegateSimpleThread::Delegate implementation.
91 virtual void Run();
92 // End of DelegateSimpleThread::Delegate implementation.
93
94 // True if playing the stream.
95 bool playing_;
96 84
97 // AudioConfig used for creating this Audio object. 85 // AudioConfig used for creating this Audio object.
98 scoped_refptr<AudioConfig> config_; 86 scoped_refptr<AudioConfig> config_;
99 87
100 // Instance id 88 // Plugin instance that owns this audio object.
101 PP_Instance pp_instance_; 89 PP_Instance pp_instance_;
102 90
103 // PluginDelegate audio object that we delegate audio IPC through. 91 // PluginDelegate audio object that we delegate audio IPC through.
104 PluginDelegate::PlatformAudio* audio_; 92 PluginDelegate::PlatformAudio* audio_;
105 93
106 // Socket used to notify us when audio is ready to accept new samples. This
107 // pointer is created in StreamCreated().
108 scoped_ptr<base::SyncSocket> socket_;
109
110 // Sample buffer in shared memory. This pointer is created in
111 // StreamCreated(). The memory is only mapped when the audio thread is
112 // created.
113 scoped_ptr<base::SharedMemory> shared_memory_;
114
115 // The size of the sample buffer in bytes.
116 size_t shared_memory_size_;
117
118 // When the callback is set, this thread is spawned for calling it.
119 scoped_ptr<base::DelegateSimpleThread> audio_thread_;
120
121 // Callback to call when audio is ready to accept new samples.
122 volatile PPB_Audio_Callback callback_;
123
124 // User data pointer passed verbatim to the callback function.
125 void* user_data_;
126
127 // Is a create callback pending to fire? 94 // Is a create callback pending to fire?
128 bool create_callback_pending_; 95 bool create_callback_pending_;
129 96
130 // Trusted callback invoked from StreamCreated. 97 // Trusted callback invoked from StreamCreated.
131 PP_CompletionCallback create_callback_; 98 PP_CompletionCallback create_callback_;
99
100 // When a create callback is being issued, these will save the info for
101 // querying from the callback. The proxy uses this to get the handles to the
102 // other process instead of mapping them in the renderer. These will are
103 // invalid all other times.
nfullagar 2010/12/01 23:34:21 check last sentence above. "These will are..."
104 scoped_ptr<base::SharedMemory> shared_memory_for_create_callback_;
105 size_t shared_memory_size_for_create_callback_;
106 scoped_ptr<base::SyncSocket> socket_for_create_callback_;
132 }; 107 };
133 108
134 } // namespace pepper 109 } // namespace pepper
135 110
136 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_ 111 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698