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

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

Powered by Google App Engine
This is Rietveld 408576698