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