pepper_audio_input_host.h revision bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3
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 CONTENT_RENDERER_PEPPER_PEPPER_AUDIO_INPUT_HOST_H_
6#define CONTENT_RENDERER_PEPPER_PEPPER_AUDIO_INPUT_HOST_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/compiler_specific.h"
12#include "base/memory/scoped_ptr.h"
13#include "base/memory/shared_memory.h"
14#include "base/sync_socket.h"
15#include "content/renderer/pepper/pepper_device_enumeration_host_helper.h"
16#include "content/renderer/pepper/plugin_delegate.h"
17#include "ipc/ipc_platform_file.h"
18#include "ppapi/c/ppb_audio_config.h"
19#include "ppapi/host/host_message_context.h"
20#include "ppapi/host/resource_host.h"
21
22namespace content {
23
24class RendererPpapiHostImpl;
25
26class PepperAudioInputHost
27    : public ppapi::host::ResourceHost,
28      public webkit::ppapi::PluginDelegate::PlatformAudioInputClient,
29      public PepperDeviceEnumerationHostHelper::Delegate {
30 public:
31  PepperAudioInputHost(RendererPpapiHostImpl* host,
32                       PP_Instance instance,
33                       PP_Resource resource);
34  virtual ~PepperAudioInputHost();
35
36  virtual int32_t OnResourceMessageReceived(
37      const IPC::Message& msg,
38      ppapi::host::HostMessageContext* context) OVERRIDE;
39
40  // PluginDelegate::PlatformAudioInputClient implementation.
41  virtual void StreamCreated(base::SharedMemoryHandle shared_memory_handle,
42                             size_t shared_memory_size,
43                             base::SyncSocket::Handle socket) OVERRIDE;
44  virtual void StreamCreationFailed() OVERRIDE;
45
46  // PepperDeviceEnumerationHostHelper::Delegate implementation.
47  virtual webkit::ppapi::PluginDelegate* GetPluginDelegate() OVERRIDE;
48
49 private:
50  int32_t OnOpen(ppapi::host::HostMessageContext* context,
51                 const std::string& device_id,
52                 PP_AudioSampleRate sample_rate,
53                 uint32_t sample_frame_count);
54  int32_t OnStartOrStop(ppapi::host::HostMessageContext* context,
55                        bool capture);
56  int32_t OnClose(ppapi::host::HostMessageContext* context);
57
58  void OnOpenComplete(int32_t result,
59                      base::SharedMemoryHandle shared_memory_handle,
60                      size_t shared_memory_size,
61                      base::SyncSocket::Handle socket_handle);
62
63  int32_t GetRemoteHandles(
64      const base::SyncSocket& socket,
65      const base::SharedMemory& shared_memory,
66      IPC::PlatformFileForTransit* remote_socket_handle,
67      base::SharedMemoryHandle* remote_shared_memory_handle);
68
69  void Close();
70
71  // Non-owning pointer.
72  RendererPpapiHostImpl* renderer_ppapi_host_;
73
74  scoped_ptr<ppapi::host::ReplyMessageContext> open_context_;
75
76  // PluginDelegate audio input object that we delegate audio IPC through.
77  // We don't own this pointer but are responsible for calling Shutdown on it.
78  webkit::ppapi::PluginDelegate::PlatformAudioInput* audio_input_;
79
80  PepperDeviceEnumerationHostHelper enumeration_helper_;
81
82  DISALLOW_COPY_AND_ASSIGN(PepperAudioInputHost);
83};
84
85}  // namespace content
86
87#endif  // CONTENT_RENDERER_PEPPER_PEPPER_AUDIO_INPUT_HOST_H_
88