OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_ | |
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_ | |
7 | |
8 #include "base/ref_counted.h" | |
9 #include "base/shared_memory.h" | |
10 #include "base/sync_socket.h" | |
11 #include "ppapi/c/dev/ppb_audio_dev.h" | |
12 #include "ppapi/c/dev/ppb_audio_config_dev.h" | |
13 #include "ppapi/c/dev/ppb_audio_trusted_dev.h" | |
14 #include "ppapi/c/pp_completion_callback.h" | |
15 #include "ppapi/shared_impl/audio_impl.h" | |
16 #include "webkit/glue/plugins/pepper_plugin_delegate.h" | |
17 #include "webkit/glue/plugins/pepper_plugin_instance.h" | |
18 #include "webkit/glue/plugins/pepper_plugin_module.h" | |
19 #include "webkit/glue/plugins/pepper_resource.h" | |
20 | |
21 namespace pepper { | |
22 | |
23 class PluginInstance; | |
24 class PluginModule; | |
25 | |
26 class AudioConfig : public Resource { | |
27 public: | |
28 AudioConfig(PluginModule* module, | |
29 PP_AudioSampleRate_Dev sample_rate, | |
30 uint32_t sample_frame_count); | |
31 size_t BufferSize(); | |
32 static const PPB_AudioConfig_Dev* GetInterface(); | |
33 | |
34 PP_AudioSampleRate_Dev sample_rate() { return sample_rate_; } | |
35 uint32_t sample_frame_count() { return sample_frame_count_; } | |
36 | |
37 private: | |
38 // Resource override. | |
39 virtual AudioConfig* AsAudioConfig(); | |
40 | |
41 PP_AudioSampleRate_Dev sample_rate_; | |
42 uint32_t sample_frame_count_; | |
43 }; | |
44 | |
45 // Some of the backend functionality of this class is implemented by the | |
46 // AudioImpl so it can be shared with the proxy. | |
47 class Audio : public Resource, | |
48 public pp::shared_impl::AudioImpl, | |
49 public PluginDelegate::PlatformAudio::Client { | |
50 public: | |
51 explicit Audio(PluginModule* module, PP_Instance instance_id); | |
52 virtual ~Audio(); | |
53 | |
54 static const PPB_Audio_Dev* GetInterface(); | |
55 static const PPB_AudioTrusted_Dev* GetTrustedInterface(); | |
56 | |
57 PP_Instance pp_instance() { | |
58 return pp_instance_; | |
59 } | |
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); | |
73 int32_t GetSyncSocket(int* sync_socket); | |
74 int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size); | |
75 | |
76 // Resource override. | |
77 virtual Audio* AsAudio(); | |
78 | |
79 private: | |
80 // pepper::PluginDelegate::PlatformAudio::Client implementation. | |
81 virtual void StreamCreated(base::SharedMemoryHandle shared_memory_handle, | |
82 size_t shared_memory_size_, | |
83 base::SyncSocket::Handle socket); | |
84 | |
85 // AudioConfig used for creating this Audio object. | |
86 scoped_refptr<AudioConfig> config_; | |
87 | |
88 // Plugin instance that owns this audio object. | |
89 PP_Instance pp_instance_; | |
90 | |
91 // PluginDelegate audio object that we delegate audio IPC through. | |
92 PluginDelegate::PlatformAudio* audio_; | |
93 | |
94 // Is a create callback pending to fire? | |
95 bool create_callback_pending_; | |
96 | |
97 // Trusted callback invoked from StreamCreated. | |
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 be | |
103 // invalid all other times. | |
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_; | |
107 }; | |
108 | |
109 } // namespace pepper | |
110 | |
111 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_ | |
OLD | NEW |