cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / proxy / audio_input_resource.h
blob84785d08052201aad471e0887fc84b8423c718b3
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.
5 #ifndef PPAPI_PROXY_AUDIO_INPUT_RESOURCE_H_
6 #define PPAPI_PROXY_AUDIO_INPUT_RESOURCE_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/shared_memory.h"
13 #include "base/sync_socket.h"
14 #include "base/threading/simple_thread.h"
15 #include "ppapi/proxy/device_enumeration_resource_helper.h"
16 #include "ppapi/proxy/plugin_resource.h"
17 #include "ppapi/shared_impl/scoped_pp_resource.h"
18 #include "ppapi/thunk/ppb_audio_input_api.h"
20 namespace ppapi {
21 namespace proxy {
23 class ResourceMessageReplyParams;
25 class AudioInputResource : public PluginResource,
26 public thunk::PPB_AudioInput_API,
27 public base::DelegateSimpleThread::Delegate {
28 public:
29 AudioInputResource(Connection connection, PP_Instance instance);
30 virtual ~AudioInputResource();
32 // Resource overrides.
33 virtual thunk::PPB_AudioInput_API* AsPPB_AudioInput_API() OVERRIDE;
34 virtual void OnReplyReceived(const ResourceMessageReplyParams& params,
35 const IPC::Message& msg) OVERRIDE;
37 // PPB_AudioInput_API implementation.
38 virtual int32_t EnumerateDevices0_2(
39 PP_Resource* devices,
40 scoped_refptr<TrackedCallback> callback) OVERRIDE;
41 virtual int32_t EnumerateDevices(
42 const PP_ArrayOutput& output,
43 scoped_refptr<TrackedCallback> callback) OVERRIDE;
44 virtual int32_t MonitorDeviceChange(
45 PP_MonitorDeviceChangeCallback callback,
46 void* user_data) OVERRIDE;
47 virtual int32_t Open0_2(PP_Resource device_ref,
48 PP_Resource config,
49 PPB_AudioInput_Callback_0_2 audio_input_callback_0_2,
50 void* user_data,
51 scoped_refptr<TrackedCallback> callback) OVERRIDE;
52 virtual int32_t Open(PP_Resource device_ref,
53 PP_Resource config,
54 PPB_AudioInput_Callback audio_input_callback,
55 void* user_data,
56 scoped_refptr<TrackedCallback> callback) OVERRIDE;
57 virtual PP_Resource GetCurrentConfig() OVERRIDE;
58 virtual PP_Bool StartCapture() OVERRIDE;
59 virtual PP_Bool StopCapture() OVERRIDE;
60 virtual void Close() OVERRIDE;
62 protected:
63 // Resource override.
64 virtual void LastPluginRefWasDeleted() OVERRIDE;
66 private:
67 enum OpenState {
68 BEFORE_OPEN,
69 OPENED,
70 CLOSED
73 void OnPluginMsgOpenReply(const ResourceMessageReplyParams& params);
75 // Sets the shared memory and socket handles. This will automatically start
76 // capture if we're currently set to capture.
77 void SetStreamInfo(base::SharedMemoryHandle shared_memory_handle,
78 size_t shared_memory_size,
79 base::SyncSocket::Handle socket_handle);
81 // Starts execution of the audio input thread.
82 void StartThread();
84 // Stops execution of the audio input thread.
85 void StopThread();
87 // DelegateSimpleThread::Delegate implementation.
88 // Run on the audio input thread.
89 virtual void Run() OVERRIDE;
91 int32_t CommonOpen(PP_Resource device_ref,
92 PP_Resource config,
93 PPB_AudioInput_Callback_0_2 audio_input_callback_0_2,
94 PPB_AudioInput_Callback audio_input_callback,
95 void* user_data,
96 scoped_refptr<TrackedCallback> callback);
98 OpenState open_state_;
100 // True if capturing the stream.
101 bool capturing_;
103 // Socket used to notify us when new samples are available. This pointer is
104 // created in SetStreamInfo().
105 scoped_ptr<base::CancelableSyncSocket> socket_;
107 // Sample buffer in shared memory. This pointer is created in
108 // SetStreamInfo(). The memory is only mapped when the audio thread is
109 // created.
110 scoped_ptr<base::SharedMemory> shared_memory_;
112 // The size of the sample buffer in bytes.
113 size_t shared_memory_size_;
115 // When the callback is set, this thread is spawned for calling it.
116 scoped_ptr<base::DelegateSimpleThread> audio_input_thread_;
118 // Callback to call when new samples are available.
119 PPB_AudioInput_Callback_0_2 audio_input_callback_0_2_;
120 PPB_AudioInput_Callback audio_input_callback_;
122 // User data pointer passed verbatim to the callback function.
123 void* user_data_;
125 // The callback is not directly passed to OnPluginMsgOpenReply() because we
126 // would like to be able to cancel it early in Close().
127 scoped_refptr<TrackedCallback> open_callback_;
129 // Owning reference to the current config object. This isn't actually used,
130 // we just dish it out as requested by the plugin.
131 ScopedPPResource config_;
133 DeviceEnumerationResourceHelper enumeration_helper_;
135 // The data size (in bytes) of one second of audio input. Used to calculate
136 // latency.
137 size_t bytes_per_second_;
139 DISALLOW_COPY_AND_ASSIGN(AudioInputResource);
142 } // namespace proxy
143 } // namespace ppapi
145 #endif // PPAPI_PROXY_AUDIO_INPUT_RESOURCE_H_