- add sources.
[platform/framework/web/crosswalk.git] / src / ppapi / thunk / ppb_audio_input_dev_thunk.cc
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 #include "ppapi/c/dev/ppb_audio_input_dev.h"
6 #include "ppapi/c/pp_completion_callback.h"
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/shared_impl/tracked_callback.h"
9 #include "ppapi/thunk/enter.h"
10 #include "ppapi/thunk/ppb_audio_input_api.h"
11 #include "ppapi/thunk/ppb_instance_api.h"
12 #include "ppapi/thunk/resource_creation_api.h"
13 #include "ppapi/thunk/thunk.h"
14
15 namespace ppapi {
16 namespace thunk {
17
18 namespace {
19
20 PP_Resource Create(PP_Instance instance) {
21   VLOG(4) << "PPB_AudioInput_Dev::Create()";
22   EnterResourceCreation enter(instance);
23   if (enter.failed())
24     return 0;
25   return enter.functions()->CreateAudioInput(instance);
26 }
27
28 PP_Bool IsAudioInput(PP_Resource resource) {
29   VLOG(4) << "PPB_AudioInput_Dev::IsAudioInput()";
30   EnterResource<PPB_AudioInput_API> enter(resource, false);
31   return PP_FromBool(enter.succeeded());
32 }
33
34 int32_t EnumerateDevices_0_2(PP_Resource audio_input,
35                              PP_Resource* devices,
36                              struct PP_CompletionCallback callback) {
37   VLOG(4) << "PPB_AudioInput_Dev::EnumerateDevices()";
38   EnterResource<PPB_AudioInput_API> enter(audio_input, callback, true);
39   if (enter.failed())
40     return enter.retval();
41   return enter.SetResult(enter.object()->EnumerateDevices0_2(
42       devices,
43       enter.callback()));
44 }
45
46 int32_t EnumerateDevices(PP_Resource audio_input,
47                          struct PP_ArrayOutput output,
48                          struct PP_CompletionCallback callback) {
49   VLOG(4) << "PPB_AudioInput_Dev::EnumerateDevices()";
50   EnterResource<PPB_AudioInput_API> enter(audio_input, callback, true);
51   if (enter.failed())
52     return enter.retval();
53   return enter.SetResult(enter.object()->EnumerateDevices(output,
54                                                           enter.callback()));
55 }
56
57 int32_t MonitorDeviceChange(PP_Resource audio_input,
58                             PP_MonitorDeviceChangeCallback callback,
59                             void* user_data) {
60   VLOG(4) << "PPB_AudioInput_Dev::MonitorDeviceChange()";
61   EnterResource<PPB_AudioInput_API> enter(audio_input, true);
62   if (enter.failed())
63     return enter.retval();
64   return enter.object()->MonitorDeviceChange(callback, user_data);
65 }
66
67 int32_t Open_0_2(PP_Resource audio_input,
68                  PP_Resource device_ref,
69                  PP_Resource config,
70                  PPB_AudioInput_Callback_0_2 audio_input_callback,
71                  void* user_data,
72                  struct PP_CompletionCallback callback) {
73   VLOG(4) << "PPB_AudioInput_Dev::Open()";
74   EnterResource<PPB_AudioInput_API> enter(audio_input, callback, true);
75   if (enter.failed())
76     return enter.retval();
77   return enter.SetResult(enter.object()->Open0_2(device_ref,
78                                                  config,
79                                                  audio_input_callback,
80                                                  user_data,
81                                                  enter.callback()));
82 }
83
84 int32_t Open(PP_Resource audio_input,
85              PP_Resource device_ref,
86              PP_Resource config,
87              PPB_AudioInput_Callback audio_input_callback,
88              void* user_data,
89              struct PP_CompletionCallback callback) {
90   VLOG(4) << "PPB_AudioInput_Dev::Open()";
91   EnterResource<PPB_AudioInput_API> enter(audio_input, callback, true);
92   if (enter.failed())
93     return enter.retval();
94   return enter.SetResult(enter.object()->Open(device_ref,
95                                               config,
96                                               audio_input_callback,
97                                               user_data,
98                                               enter.callback()));
99 }
100
101 PP_Resource GetCurrentConfig(PP_Resource audio_input) {
102   VLOG(4) << "PPB_AudioInput_Dev::GetCurrentConfig()";
103   EnterResource<PPB_AudioInput_API> enter(audio_input, true);
104   if (enter.failed())
105     return 0;
106   return enter.object()->GetCurrentConfig();
107 }
108
109 PP_Bool StartCapture(PP_Resource audio_input) {
110   VLOG(4) << "PPB_AudioInput_Dev::StartCapture()";
111   EnterResource<PPB_AudioInput_API> enter(audio_input, true);
112   if (enter.failed())
113     return PP_FALSE;
114   return enter.object()->StartCapture();
115 }
116
117 PP_Bool StopCapture(PP_Resource audio_input) {
118   VLOG(4) << "PPB_AudioInput_Dev::StopCapture()";
119   EnterResource<PPB_AudioInput_API> enter(audio_input, true);
120   if (enter.failed())
121     return PP_FALSE;
122   return enter.object()->StopCapture();
123 }
124
125 void Close(PP_Resource audio_input) {
126   VLOG(4) << "PPB_AudioInput_Dev::Close()";
127   EnterResource<PPB_AudioInput_API> enter(audio_input, true);
128   if (enter.failed())
129     return;
130   enter.object()->Close();
131 }
132
133 const PPB_AudioInput_Dev_0_2 g_ppb_audioinput_dev_thunk_0_2 = {
134   &Create,
135   &IsAudioInput,
136   &EnumerateDevices_0_2,
137   &Open_0_2,
138   &GetCurrentConfig,
139   &StartCapture,
140   &StopCapture,
141   &Close
142 };
143
144 const PPB_AudioInput_Dev_0_3 g_ppb_audioinput_dev_thunk_0_3 = {
145   &Create,
146   &IsAudioInput,
147   &EnumerateDevices,
148   &MonitorDeviceChange,
149   &Open_0_2,
150   &GetCurrentConfig,
151   &StartCapture,
152   &StopCapture,
153   &Close
154 };
155
156 const PPB_AudioInput_Dev_0_4 g_ppb_audioinput_dev_thunk_0_4 = {
157   &Create,
158   &IsAudioInput,
159   &EnumerateDevices,
160   &MonitorDeviceChange,
161   &Open,
162   &GetCurrentConfig,
163   &StartCapture,
164   &StopCapture,
165   &Close
166 };
167
168 }  // namespace
169
170 const PPB_AudioInput_Dev_0_2* GetPPB_AudioInput_Dev_0_2_Thunk() {
171   return &g_ppb_audioinput_dev_thunk_0_2;
172 }
173
174 const PPB_AudioInput_Dev_0_3* GetPPB_AudioInput_Dev_0_3_Thunk() {
175   return &g_ppb_audioinput_dev_thunk_0_3;
176 }
177
178 const PPB_AudioInput_Dev_0_4* GetPPB_AudioInput_Dev_0_4_Thunk() {
179   return &g_ppb_audioinput_dev_thunk_0_4;
180 }
181
182 }  // namespace thunk
183 }  // namespace ppapi