| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_PLUGINS_PPAPI_PPB_AUDIO_IMPL_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_AUDIO_IMPL_H_ |
| 6 #define WEBKIT_PLUGINS_PPAPI_PPB_AUDIO_IMPL_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_PPB_AUDIO_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
| 11 #include "base/sync_socket.h" | 11 #include "base/sync_socket.h" |
| 12 #include "ppapi/c/pp_completion_callback.h" | 12 #include "ppapi/c/pp_completion_callback.h" |
| 13 #include "ppapi/c/ppb_audio.h" | 13 #include "ppapi/c/ppb_audio.h" |
| 14 #include "ppapi/c/ppb_audio_config.h" | 14 #include "ppapi/c/ppb_audio_config.h" |
| 15 #include "ppapi/c/trusted/ppb_audio_trusted.h" | 15 #include "ppapi/c/trusted/ppb_audio_trusted.h" |
| 16 #include "ppapi/shared_impl/audio_config_impl.h" | 16 #include "ppapi/shared_impl/audio_config_impl.h" |
| 17 #include "ppapi/shared_impl/audio_impl.h" | 17 #include "ppapi/shared_impl/audio_impl.h" |
| 18 #include "ppapi/shared_impl/scoped_pp_resource.h" |
| 19 #include "ppapi/shared_impl/resource.h" |
| 18 #include "webkit/plugins/ppapi/plugin_delegate.h" | 20 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 21 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 20 #include "webkit/plugins/ppapi/resource.h" | |
| 21 | 22 |
| 22 namespace webkit { | 23 namespace webkit { |
| 23 namespace ppapi { | 24 namespace ppapi { |
| 24 | 25 |
| 25 class PluginInstance; | |
| 26 | |
| 27 // The implementation is actually in AudioConfigImpl. | 26 // The implementation is actually in AudioConfigImpl. |
| 28 class PPB_AudioConfig_Impl : public Resource, | 27 class PPB_AudioConfig_Impl : public ::ppapi::Resource, |
| 29 public ::ppapi::AudioConfigImpl { | 28 public ::ppapi::AudioConfigImpl { |
| 30 public: | 29 public: |
| 31 virtual ~PPB_AudioConfig_Impl(); | 30 virtual ~PPB_AudioConfig_Impl(); |
| 32 | 31 |
| 33 // Non-trusted creation. | 32 // Non-trusted creation. |
| 34 static PP_Resource Create(PluginInstance* instance, | 33 static PP_Resource Create(PP_Instance instance, |
| 35 PP_AudioSampleRate sample_rate, | 34 PP_AudioSampleRate sample_rate, |
| 36 uint32_t sample_frame_count); | 35 uint32_t sample_frame_count); |
| 37 | 36 |
| 38 // Resource overrides. | 37 // Resource overrides. |
| 39 virtual ::ppapi::thunk::PPB_AudioConfig_API* AsPPB_AudioConfig_API() OVERRIDE; | 38 virtual ::ppapi::thunk::PPB_AudioConfig_API* AsPPB_AudioConfig_API() OVERRIDE; |
| 40 | 39 |
| 41 private: | 40 private: |
| 42 explicit PPB_AudioConfig_Impl(PluginInstance* instance); | 41 explicit PPB_AudioConfig_Impl(PP_Instance instance); |
| 43 | 42 |
| 44 DISALLOW_COPY_AND_ASSIGN(PPB_AudioConfig_Impl); | 43 DISALLOW_COPY_AND_ASSIGN(PPB_AudioConfig_Impl); |
| 45 }; | 44 }; |
| 46 | 45 |
| 47 // Some of the backend functionality of this class is implemented by the | 46 // Some of the backend functionality of this class is implemented by the |
| 48 // AudioImpl so it can be shared with the proxy. | 47 // AudioImpl so it can be shared with the proxy. |
| 49 class PPB_Audio_Impl : public Resource, | 48 class PPB_Audio_Impl : public ::ppapi::Resource, |
| 50 public ::ppapi::AudioImpl, | 49 public ::ppapi::AudioImpl, |
| 51 public PluginDelegate::PlatformAudio::Client { | 50 public PluginDelegate::PlatformAudio::Client { |
| 52 public: | 51 public: |
| 53 // Trusted initialization. You must call Init after this. | 52 // Trusted initialization. You must call Init after this. |
| 54 // | 53 // |
| 55 // Untrusted initialization should just call the static Create() function | 54 // Untrusted initialization should just call the static Create() function |
| 56 // to properly create & initialize this class. | 55 // to properly create & initialize this class. |
| 57 explicit PPB_Audio_Impl(PluginInstance* instance); | 56 explicit PPB_Audio_Impl(PP_Instance instance); |
| 58 | 57 |
| 59 virtual ~PPB_Audio_Impl(); | 58 virtual ~PPB_Audio_Impl(); |
| 60 | 59 |
| 61 // Creation function for untrusted plugins. This handles all initialization | 60 // Creation function for untrusted plugins. This handles all initialization |
| 62 // and will return 0 on failure. | 61 // and will return 0 on failure. |
| 63 static PP_Resource Create(PluginInstance* instance, | 62 static PP_Resource Create(PP_Instance instance, |
| 64 PP_Resource config_id, | 63 PP_Resource config_id, |
| 65 PPB_Audio_Callback audio_callback, | 64 PPB_Audio_Callback audio_callback, |
| 66 void* user_data); | 65 void* user_data); |
| 67 | 66 |
| 68 // Initialization function for non-trusted init. | 67 // Initialization function for non-trusted init. |
| 69 bool Init(PP_Resource config_id, | 68 bool Init(PP_Resource config_id, |
| 70 PPB_Audio_Callback user_callback, void* user_data); | 69 PPB_Audio_Callback user_callback, void* user_data); |
| 71 | 70 |
| 72 // Resource overrides. | 71 // Resource overrides. |
| 73 virtual ::ppapi::thunk::PPB_Audio_API* AsPPB_Audio_API(); | 72 virtual ::ppapi::thunk::PPB_Audio_API* AsPPB_Audio_API(); |
| 74 | 73 |
| 75 // PPB_Audio_API implementation. | 74 // PPB_Audio_API implementation. |
| 76 virtual PP_Resource GetCurrentConfig() OVERRIDE; | 75 virtual PP_Resource GetCurrentConfig() OVERRIDE; |
| 77 virtual PP_Bool StartPlayback() OVERRIDE; | 76 virtual PP_Bool StartPlayback() OVERRIDE; |
| 78 virtual PP_Bool StopPlayback() OVERRIDE; | 77 virtual PP_Bool StopPlayback() OVERRIDE; |
| 79 virtual int32_t OpenTrusted(PP_Resource config_id, | 78 virtual int32_t OpenTrusted(PP_Resource config_id, |
| 80 PP_CompletionCallback create_callback) OVERRIDE; | 79 PP_CompletionCallback create_callback) OVERRIDE; |
| 81 virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE; | 80 virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE; |
| 82 virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE; | 81 virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE; |
| 83 | 82 |
| 84 private: | 83 private: |
| 85 // PluginDelegate::PlatformAudio::Client implementation. | 84 // PluginDelegate::PlatformAudio::Client implementation. |
| 86 virtual void StreamCreated(base::SharedMemoryHandle shared_memory_handle, | 85 virtual void StreamCreated(base::SharedMemoryHandle shared_memory_handle, |
| 87 size_t shared_memory_size_, | 86 size_t shared_memory_size_, |
| 88 base::SyncSocket::Handle socket); | 87 base::SyncSocket::Handle socket); |
| 89 | 88 |
| 90 // AudioConfig used for creating this Audio object. We own a ref. | 89 // AudioConfig used for creating this Audio object. We own a ref. |
| 91 PP_Resource config_id_; | 90 ::ppapi::ScopedPPResource config_; |
| 92 | 91 |
| 93 // PluginDelegate audio object that we delegate audio IPC through. We don't | 92 // PluginDelegate audio object that we delegate audio IPC through. We don't |
| 94 // own this pointer but are responsible for calling Shutdown on it. | 93 // own this pointer but are responsible for calling Shutdown on it. |
| 95 PluginDelegate::PlatformAudio* audio_; | 94 PluginDelegate::PlatformAudio* audio_; |
| 96 | 95 |
| 97 // Is a create callback pending to fire? | 96 // Is a create callback pending to fire? |
| 98 bool create_callback_pending_; | 97 bool create_callback_pending_; |
| 99 | 98 |
| 100 // Trusted callback invoked from StreamCreated. | 99 // Trusted callback invoked from StreamCreated. |
| 101 PP_CompletionCallback create_callback_; | 100 PP_CompletionCallback create_callback_; |
| 102 | 101 |
| 103 // When a create callback is being issued, these will save the info for | 102 // When a create callback is being issued, these will save the info for |
| 104 // querying from the callback. The proxy uses this to get the handles to the | 103 // querying from the callback. The proxy uses this to get the handles to the |
| 105 // other process instead of mapping them in the renderer. These will be | 104 // other process instead of mapping them in the renderer. These will be |
| 106 // invalid all other times. | 105 // invalid all other times. |
| 107 scoped_ptr<base::SharedMemory> shared_memory_for_create_callback_; | 106 scoped_ptr<base::SharedMemory> shared_memory_for_create_callback_; |
| 108 size_t shared_memory_size_for_create_callback_; | 107 size_t shared_memory_size_for_create_callback_; |
| 109 scoped_ptr<base::SyncSocket> socket_for_create_callback_; | 108 scoped_ptr<base::SyncSocket> socket_for_create_callback_; |
| 110 | 109 |
| 111 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Impl); | 110 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Impl); |
| 112 }; | 111 }; |
| 113 | 112 |
| 114 } // namespace ppapi | 113 } // namespace ppapi |
| 115 } // namespace webkit | 114 } // namespace webkit |
| 116 | 115 |
| 117 #endif // WEBKIT_PLUGINS_PPAPI_PPB_AUDIO_IMPL_H_ | 116 #endif // WEBKIT_PLUGINS_PPAPI_PPB_AUDIO_IMPL_H_ |
| OLD | NEW |