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 #include "ppapi/c/pp_errors.h"
6 #include "ppapi/shared_impl/ppb_device_ref_shared.h"
7 #include "ppapi/shared_impl/tracked_callback.h"
8 #include "ppapi/thunk/enter.h"
9 #include "ppapi/thunk/ppb_device_ref_api.h"
10 #include "ppapi/thunk/ppb_audio_input_api.h"
11 #include "ppapi/thunk/resource_creation_api.h"
12 #include "ppapi/thunk/thunk.h"
19 typedef EnterResource
<PPB_AudioInput_API
> EnterAudioInput
;
21 PP_Resource
Create(PP_Instance instance
) {
22 EnterResourceCreation
enter(instance
);
26 return enter
.functions()->CreateAudioInput(instance
);
29 PP_Bool
IsAudioInput(PP_Resource resource
) {
30 EnterAudioInput
enter(resource
, false);
31 return PP_FromBool(enter
.succeeded());
34 int32_t EnumerateDevices(PP_Resource audio_input
,
36 PP_CompletionCallback callback
) {
37 EnterAudioInput
enter(audio_input
, callback
, true);
39 return enter
.retval();
41 return enter
.SetResult(enter
.object()->EnumerateDevices(devices
,
45 int32_t Open(PP_Resource audio_input
,
46 PP_Resource device_ref
,
48 PPB_AudioInput_Callback audio_input_callback
,
50 PP_CompletionCallback callback
) {
51 EnterAudioInput
enter(audio_input
, callback
, true);
53 return enter
.retval();
55 std::string device_id
;
56 // |device_id| remains empty if |device_ref| is 0, which means the default
58 if (device_ref
!= 0) {
59 EnterResourceNoLock
<PPB_DeviceRef_API
> enter_device_ref(device_ref
, true);
60 if (enter_device_ref
.failed())
61 return enter
.SetResult(PP_ERROR_BADRESOURCE
);
62 device_id
= enter_device_ref
.object()->GetDeviceRefData().id
;
65 return enter
.SetResult(enter
.object()->Open(
66 device_id
, config
, audio_input_callback
, user_data
, enter
.callback()));
69 PP_Resource
GetCurrentConfig(PP_Resource audio_input
) {
70 EnterAudioInput
enter(audio_input
, true);
73 return enter
.object()->GetCurrentConfig();
76 PP_Bool
StartCapture(PP_Resource audio_input
) {
77 EnterAudioInput
enter(audio_input
, true);
81 return enter
.object()->StartCapture();
84 PP_Bool
StopCapture(PP_Resource audio_input
) {
85 EnterAudioInput
enter(audio_input
, true);
89 return enter
.object()->StopCapture();
92 void Close(PP_Resource audio_input
) {
93 EnterAudioInput
enter(audio_input
, true);
94 if (enter
.succeeded())
95 enter
.object()->Close();
98 const PPB_AudioInput_Dev_0_2 g_ppb_audioinput_0_2_thunk
= {
111 const PPB_AudioInput_Dev_0_2
* GetPPB_AudioInput_Dev_0_2_Thunk() {
112 return &g_ppb_audioinput_0_2_thunk
;