[email protected] | 25651387 | 2012-01-05 15:41:52 | [diff] [blame^] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 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 PPAPI_PROXY_PPB_AUDIO_PROXY_H_ |
| 6 | #define PPAPI_PROXY_PPB_AUDIO_PROXY_H_ |
| 7 | |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 8 | #include <utility> |
| 9 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 10 | #include "base/basictypes.h" |
| 11 | #include "base/shared_memory.h" |
| 12 | #include "base/sync_socket.h" |
| 13 | #include "ipc/ipc_platform_file.h" |
| 14 | #include "ppapi/c/pp_instance.h" |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 15 | #include "ppapi/c/pp_resource.h" |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 16 | #include "ppapi/c/ppb_audio.h" |
[email protected] | 6ac20de | 2012-01-04 04:47:25 | [diff] [blame] | 17 | #include "ppapi/cpp/completion_callback.h" |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 18 | #include "ppapi/proxy/interface_proxy.h" |
| 19 | #include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" |
| 20 | |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 21 | namespace ppapi { |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 22 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 23 | class HostResource; |
| 24 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 25 | namespace proxy { |
| 26 | |
| 27 | class PPB_Audio_Proxy : public InterfaceProxy { |
| 28 | public: |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 29 | PPB_Audio_Proxy(Dispatcher* dispatcher); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 30 | virtual ~PPB_Audio_Proxy(); |
| 31 | |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 32 | // Creates an Audio object in the plugin process. |
| 33 | static PP_Resource CreateProxyResource(PP_Instance instance_id, |
| 34 | PP_Resource config_id, |
| 35 | PPB_Audio_Callback audio_callback, |
| 36 | void* user_data); |
| 37 | |
| 38 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 39 | // InterfaceProxy implementation. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 40 | virtual bool OnMessageReceived(const IPC::Message& msg); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 41 | |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 42 | static const ApiID kApiID = API_ID_PPB_AUDIO; |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 43 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 44 | private: |
| 45 | // Plugin->renderer message handlers. |
| 46 | void OnMsgCreate(PP_Instance instance_id, |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 47 | int32_t sample_rate, |
| 48 | uint32_t sample_frame_count, |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 49 | ppapi::HostResource* result); |
| 50 | void OnMsgStartOrStop(const ppapi::HostResource& audio_id, bool play); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 51 | |
| 52 | // Renderer->plugin message handlers. |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 53 | void OnMsgNotifyAudioStreamCreated(const ppapi::HostResource& audio_id, |
[email protected] | 2031aeb | 2011-01-28 20:01:16 | [diff] [blame] | 54 | int32_t result_code, |
| 55 | IPC::PlatformFileForTransit socket_handle, |
| 56 | base::SharedMemoryHandle handle, |
| 57 | uint32_t length); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 58 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 59 | void AudioChannelConnected(int32_t result, |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 60 | const ppapi::HostResource& resource); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 61 | |
| 62 | // In the renderer, this is called in response to a stream created message. |
| 63 | // It will retrieve the shared memory and socket handles and place them into |
| 64 | // the given out params. The return value is a PPAPI error code. |
| 65 | // |
| 66 | // The input arguments should be initialized to 0 or -1, depending on the |
| 67 | // platform's default invalid handle values. On error, some of these |
| 68 | // arguments may be written to, and others may be untouched, depending on |
| 69 | // where the error occurred. |
| 70 | int32_t GetAudioConnectedHandles( |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 71 | const ppapi::HostResource& resource, |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 72 | IPC::PlatformFileForTransit* foreign_socket_handle, |
| 73 | base::SharedMemoryHandle* foreign_shared_memory_handle, |
| 74 | uint32_t* shared_memory_length); |
| 75 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 76 | pp::CompletionCallbackFactory<PPB_Audio_Proxy, |
| 77 | ProxyNonThreadSafeRefCount> callback_factory_; |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 78 | |
| 79 | DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Proxy); |
| 80 | }; |
| 81 | |
| 82 | } // namespace proxy |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 83 | } // namespace ppapi |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 84 | |
| 85 | #endif // PPAPI_PROXY_PPB_AUDIO_PROXY_H_ |