Avi Drissman | db497b3 | 2022-09-15 19:47:28 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[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 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
Alexandr Ilin | 20f2841c | 2018-06-01 11:56:18 | [diff] [blame] | 10 | #include "base/memory/unsafe_shared_memory_region.h" |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 11 | #include "base/sync_socket.h" |
| 12 | #include "ipc/ipc_platform_file.h" |
| 13 | #include "ppapi/c/pp_instance.h" |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 14 | #include "ppapi/c/pp_resource.h" |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 15 | #include "ppapi/c/ppb_audio.h" |
[email protected] | ae5ff9ae | 2012-01-06 22:50:33 | [diff] [blame] | 16 | #include "ppapi/c/ppb_audio_config.h" |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 17 | #include "ppapi/proxy/interface_proxy.h" |
[email protected] | 47a961c | 2012-07-13 19:18:52 | [diff] [blame] | 18 | #include "ppapi/proxy/proxy_completion_callback_factory.h" |
[email protected] | ae5ff9ae | 2012-01-06 22:50:33 | [diff] [blame] | 19 | #include "ppapi/utility/completion_callback_factory.h" |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 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] | 6b151126 | 2013-09-06 21:46:34 | [diff] [blame] | 23 | class AudioCallbackCombined; |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 24 | class HostResource; |
| 25 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 26 | namespace proxy { |
| 27 | |
[email protected] | eb5960da | 2013-01-16 23:23:53 | [diff] [blame] | 28 | class SerializedHandle; |
| 29 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 30 | class PPB_Audio_Proxy : public InterfaceProxy { |
| 31 | public: |
Lei Zhang | 94f57fe3 | 2017-08-30 23:58:24 | [diff] [blame] | 32 | explicit PPB_Audio_Proxy(Dispatcher* dispatcher); |
Peter Boström | 3d5b3cb | 2021-09-23 21:35:45 | [diff] [blame] | 33 | |
| 34 | PPB_Audio_Proxy(const PPB_Audio_Proxy&) = delete; |
| 35 | PPB_Audio_Proxy& operator=(const PPB_Audio_Proxy&) = delete; |
| 36 | |
Lei Zhang | 94f57fe3 | 2017-08-30 23:58:24 | [diff] [blame] | 37 | ~PPB_Audio_Proxy() override; |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 38 | |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 39 | // Creates an Audio object in the plugin process. |
[email protected] | 6b151126 | 2013-09-06 21:46:34 | [diff] [blame] | 40 | static PP_Resource CreateProxyResource( |
| 41 | PP_Instance instance_id, |
| 42 | PP_Resource config_id, |
| 43 | const AudioCallbackCombined& audio_callback, |
| 44 | void* user_data); |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 45 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 46 | // InterfaceProxy implementation. |
Lei Zhang | 94f57fe3 | 2017-08-30 23:58:24 | [diff] [blame] | 47 | bool OnMessageReceived(const IPC::Message& msg) override; |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 48 | |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 49 | static const ApiID kApiID = API_ID_PPB_AUDIO; |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 50 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 51 | private: |
| 52 | // Plugin->renderer message handlers. |
| 53 | void OnMsgCreate(PP_Instance instance_id, |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 54 | int32_t sample_rate, |
| 55 | uint32_t sample_frame_count, |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 56 | ppapi::HostResource* result); |
| 57 | void OnMsgStartOrStop(const ppapi::HostResource& audio_id, bool play); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 58 | |
| 59 | // Renderer->plugin message handlers. |
[email protected] | 246fc49 | 2012-08-27 20:28:18 | [diff] [blame] | 60 | void OnMsgNotifyAudioStreamCreated( |
| 61 | const ppapi::HostResource& audio_id, |
| 62 | int32_t result_code, |
| 63 | ppapi::proxy::SerializedHandle socket_handle, |
| 64 | ppapi::proxy::SerializedHandle handle); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 65 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 66 | void AudioChannelConnected(int32_t result, |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 67 | const ppapi::HostResource& resource); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 68 | |
| 69 | // In the renderer, this is called in response to a stream created message. |
| 70 | // It will retrieve the shared memory and socket handles and place them into |
| 71 | // the given out params. The return value is a PPAPI error code. |
| 72 | // |
| 73 | // The input arguments should be initialized to 0 or -1, depending on the |
| 74 | // platform's default invalid handle values. On error, some of these |
| 75 | // arguments may be written to, and others may be untouched, depending on |
| 76 | // where the error occurred. |
| 77 | int32_t GetAudioConnectedHandles( |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 78 | const ppapi::HostResource& resource, |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 79 | IPC::PlatformFileForTransit* foreign_socket_handle, |
Alexandr Ilin | 20f2841c | 2018-06-01 11:56:18 | [diff] [blame] | 80 | base::UnsafeSharedMemoryRegion* foreign_shared_memory_region); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 81 | |
[email protected] | 47a961c | 2012-07-13 19:18:52 | [diff] [blame] | 82 | ProxyCompletionCallbackFactory<PPB_Audio_Proxy> callback_factory_; |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | } // namespace proxy |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 86 | } // namespace ppapi |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 87 | |
| 88 | #endif // PPAPI_PROXY_PPB_AUDIO_PROXY_H_ |