Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: ppapi/proxy/audio_input_resource.h

Issue 11366038: Rewrite PPB_AudioInput_Dev to use the new-style host/resource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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_AUDIO_INPUT_RESOURCE_H_
6 #define PPAPI_PROXY_AUDIO_INPUT_RESOURCE_H_
7
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/shared_memory.h"
15 #include "base/sync_socket.h"
16 #include "base/threading/simple_thread.h"
17 #include "ppapi/proxy/plugin_resource.h"
18 #include "ppapi/shared_impl/scoped_pp_resource.h"
19 #include "ppapi/thunk/ppb_audio_input_api.h"
20
21 namespace ppapi {
22
23 struct DeviceRefData;
24
25 namespace proxy {
26
27 class ResourceMessageReplyParams;
28 class SerializedHandle;
29
30 class AudioInputResource : public PluginResource,
31 public thunk::PPB_AudioInput_API,
32 public base::DelegateSimpleThread::Delegate {
33 public:
34 AudioInputResource(Connection connection, PP_Instance instance);
35 virtual ~AudioInputResource();
36
37 // Resource overrides.
38 virtual thunk::PPB_AudioInput_API* AsPPB_AudioInput_API() OVERRIDE;
39
40 // PPB_AudioInput_API implementation.
41 virtual int32_t EnumerateDevices(
42 PP_Resource* devices,
43 scoped_refptr<TrackedCallback> callback) OVERRIDE;
44 virtual int32_t Open(const std::string& device_id,
45 PP_Resource config,
46 PPB_AudioInput_Callback audio_input_callback,
47 void* user_data,
48 scoped_refptr<TrackedCallback> callback) OVERRIDE;
49 virtual PP_Resource GetCurrentConfig() OVERRIDE;
50 virtual PP_Bool StartCapture() OVERRIDE;
51 virtual PP_Bool StopCapture() OVERRIDE;
52 virtual void Close() OVERRIDE;
53
54 private:
55 enum OpenState {
56 BEFORE_OPEN,
57 OPENED,
58 CLOSED
59 };
60
61 void OnPluginMsgEnumerateDevicesReply(
62 PP_Resource* devices_resource,
63 scoped_refptr<TrackedCallback> callback,
64 const ResourceMessageReplyParams& params,
65 const std::vector<DeviceRefData>& devices);
66 void OnPluginMsgOpenReply(const ResourceMessageReplyParams& params);
67
68 // Sets the shared memory and socket handles. This will automatically start
69 // capture if we're currently set to capture.
70 void SetStreamInfo(base::SharedMemoryHandle shared_memory_handle,
71 size_t shared_memory_size,
72 base::SyncSocket::Handle socket_handle);
73
74 // Starts execution of the audio input thread.
75 void StartThread();
76
77 // Stops execution of the audio input thread.
78 void StopThread();
79
80 // DelegateSimpleThread::Delegate implementation.
81 // Run on the audio input thread.
82 virtual void Run() OVERRIDE;
83
84 OpenState open_state_;
85
86 // True if capturing the stream.
87 bool capturing_;
88
89 // Socket used to notify us when new samples are available. This pointer is
90 // created in SetStreamInfo().
91 scoped_ptr<base::CancelableSyncSocket> socket_;
92
93 // Sample buffer in shared memory. This pointer is created in
94 // SetStreamInfo(). The memory is only mapped when the audio thread is
95 // created.
96 scoped_ptr<base::SharedMemory> shared_memory_;
97
98 // The size of the sample buffer in bytes.
99 size_t shared_memory_size_;
100
101 // When the callback is set, this thread is spawned for calling it.
102 scoped_ptr<base::DelegateSimpleThread> audio_input_thread_;
103
104 // Callback to call when new samples are available.
105 PPB_AudioInput_Callback audio_input_callback_;
106
107 // User data pointer passed verbatim to the callback function.
108 void* user_data_;
109
110 bool pending_enumerate_devices_;
111 // The callback is not directly passed to OnPluginMsgOpenReply() because we
112 // would like to be able to cancel it early in Close().
113 scoped_refptr<TrackedCallback> open_callback_;
114
115 // Owning reference to the current config object. This isn't actually used,
116 // we just dish it out as requested by the plugin.
117 ScopedPPResource config_;
118
119 DISALLOW_COPY_AND_ASSIGN(AudioInputResource);
120 };
121
122 } // namespace proxy
123 } // namespace ppapi
124
125 #endif // PPAPI_PROXY_AUDIO_INPUT_RESOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698