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 WEBKIT_PLUGINS_PPAPI_PPB_AUDIO_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_PPB_AUDIO_IMPL_H_ |
6 #define WEBKIT_PLUGINS_PPAPI_PPB_AUDIO_IMPL_H_ | 6 #define CONTENT_RENDERER_PEPPER_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/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
11 #include "base/sync_socket.h" | 11 #include "base/sync_socket.h" |
| 12 #include "content/renderer/pepper/audio_helper.h" |
| 13 #include "content/renderer/pepper/plugin_delegate.h" |
12 #include "ppapi/c/pp_completion_callback.h" | 14 #include "ppapi/c/pp_completion_callback.h" |
13 #include "ppapi/c/ppb_audio.h" | 15 #include "ppapi/c/ppb_audio.h" |
14 #include "ppapi/c/ppb_audio_config.h" | 16 #include "ppapi/c/ppb_audio_config.h" |
15 #include "ppapi/shared_impl/ppb_audio_config_shared.h" | 17 #include "ppapi/shared_impl/ppb_audio_config_shared.h" |
16 #include "ppapi/shared_impl/ppb_audio_shared.h" | 18 #include "ppapi/shared_impl/ppb_audio_shared.h" |
17 #include "ppapi/shared_impl/resource.h" | 19 #include "ppapi/shared_impl/resource.h" |
18 #include "ppapi/shared_impl/scoped_pp_resource.h" | 20 #include "ppapi/shared_impl/scoped_pp_resource.h" |
19 #include "webkit/plugins/ppapi/audio_helper.h" | |
20 #include "webkit/plugins/ppapi/plugin_delegate.h" | |
21 | 21 |
22 namespace webkit { | 22 namespace webkit { |
23 namespace ppapi { | 23 namespace ppapi { |
24 | 24 |
25 // Some of the backend functionality of this class is implemented by the | 25 // Some of the backend functionality of this class is implemented by the |
26 // PPB_Audio_Shared so it can be shared with the proxy. | 26 // PPB_Audio_Shared so it can be shared with the proxy. |
27 class PPB_Audio_Impl : public ::ppapi::Resource, | 27 class PPB_Audio_Impl : public ::ppapi::Resource, |
28 public ::ppapi::PPB_Audio_Shared, | 28 public ::ppapi::PPB_Audio_Shared, |
29 public AudioHelper { | 29 public AudioHelper { |
30 public: | 30 public: |
31 // Trusted initialization. You must call Init after this. | 31 // Trusted initialization. You must call Init after this. |
32 // | 32 // |
33 // Untrusted initialization should just call the static Create() function | 33 // Untrusted initialization should just call the static Create() function |
34 // to properly create & initialize this class. | 34 // to properly create & initialize this class. |
35 explicit PPB_Audio_Impl(PP_Instance instance); | 35 explicit PPB_Audio_Impl(PP_Instance instance); |
36 | 36 |
37 virtual ~PPB_Audio_Impl(); | |
38 | |
39 // Creation function for untrusted plugins. This handles all initialization | 37 // Creation function for untrusted plugins. This handles all initialization |
40 // and will return 0 on failure. | 38 // and will return 0 on failure. |
41 static PP_Resource Create(PP_Instance instance, | 39 static PP_Resource Create(PP_Instance instance, |
42 PP_Resource config_id, | 40 PP_Resource config_id, |
43 PPB_Audio_Callback audio_callback, | 41 PPB_Audio_Callback audio_callback, |
44 void* user_data); | 42 void* user_data); |
45 | 43 |
46 // Initialization function for trusted init. | 44 // Initialization function for trusted init. |
47 bool Init(PP_Resource config_id, | 45 bool Init(PP_Resource config_id, |
48 PPB_Audio_Callback user_callback, | 46 PPB_Audio_Callback user_callback, |
49 void* user_data); | 47 void* user_data); |
50 | 48 |
51 // Resource overrides. | 49 // Resource overrides. |
52 virtual ::ppapi::thunk::PPB_Audio_API* AsPPB_Audio_API(); | 50 virtual ::ppapi::thunk::PPB_Audio_API* AsPPB_Audio_API() OVERRIDE; |
53 | 51 |
54 // PPB_Audio_API implementation. | 52 // PPB_Audio_API implementation. |
55 virtual PP_Resource GetCurrentConfig() OVERRIDE; | 53 virtual PP_Resource GetCurrentConfig() OVERRIDE; |
56 virtual PP_Bool StartPlayback() OVERRIDE; | 54 virtual PP_Bool StartPlayback() OVERRIDE; |
57 virtual PP_Bool StopPlayback() OVERRIDE; | 55 virtual PP_Bool StopPlayback() OVERRIDE; |
58 virtual int32_t Open( | 56 virtual int32_t Open( |
59 PP_Resource config_id, | 57 PP_Resource config_id, |
60 scoped_refptr< ::ppapi::TrackedCallback> create_callback) OVERRIDE; | 58 scoped_refptr< ::ppapi::TrackedCallback> create_callback) OVERRIDE; |
61 virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE; | 59 virtual int32_t GetSyncSocket(int* sync_socket) OVERRIDE; |
62 virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE; | 60 virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) OVERRIDE; |
63 | 61 |
64 private: | 62 private: |
| 63 virtual ~PPB_Audio_Impl(); |
| 64 |
65 // AudioHelper implementation. | 65 // AudioHelper implementation. |
66 virtual void OnSetStreamInfo(base::SharedMemoryHandle shared_memory_handle, | 66 virtual void OnSetStreamInfo(base::SharedMemoryHandle shared_memory_handle, |
67 size_t shared_memory_size_, | 67 size_t shared_memory_size_, |
68 base::SyncSocket::Handle socket); | 68 base::SyncSocket::Handle socket) OVERRIDE; |
69 | 69 |
70 // AudioConfig used for creating this Audio object. We own a ref. | 70 // AudioConfig used for creating this Audio object. We own a ref. |
71 ::ppapi::ScopedPPResource config_; | 71 ::ppapi::ScopedPPResource config_; |
72 | 72 |
73 // PluginDelegate audio object that we delegate audio IPC through. We don't | 73 // PluginDelegate audio object that we delegate audio IPC through. We don't |
74 // own this pointer but are responsible for calling Shutdown on it. | 74 // own this pointer but are responsible for calling Shutdown on it. |
75 PluginDelegate::PlatformAudioOutput* audio_; | 75 PluginDelegate::PlatformAudioOutput* audio_; |
76 | 76 |
77 // Track frame count for passing on to PPB_Audio_Shared::SetStreamInfo(). | 77 // Track frame count for passing on to PPB_Audio_Shared::SetStreamInfo(). |
78 int sample_frame_count_; | 78 int sample_frame_count_; |
79 | 79 |
80 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Impl); | 80 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Impl); |
81 }; | 81 }; |
82 | 82 |
83 } // namespace ppapi | 83 } // namespace ppapi |
84 } // namespace webkit | 84 } // namespace webkit |
85 | 85 |
86 #endif // WEBKIT_PLUGINS_PPAPI_PPB_AUDIO_IMPL_H_ | 86 #endif // CONTENT_RENDERER_PEPPER_PPB_AUDIO_IMPL_H_ |
OLD | NEW |