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

Side by Side Diff: ppapi/thunk/ppb_audio_input_thunk.cc

Issue 9557007: PPB_AudioInput_Dev: support multiple audio input devices - Part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes in response to Trung's comments. Created 8 years, 9 months 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
« no previous file with comments | « ppapi/thunk/ppb_audio_input_api.h ('k') | ppapi/thunk/ppb_audio_input_trusted_thunk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/c/pp_errors.h" 5 #include "ppapi/c/pp_errors.h"
6 #include "ppapi/shared_impl/ppb_device_ref_shared.h"
6 #include "ppapi/thunk/enter.h" 7 #include "ppapi/thunk/enter.h"
8 #include "ppapi/thunk/ppb_device_ref_api.h"
7 #include "ppapi/thunk/ppb_audio_input_api.h" 9 #include "ppapi/thunk/ppb_audio_input_api.h"
8 #include "ppapi/thunk/resource_creation_api.h" 10 #include "ppapi/thunk/resource_creation_api.h"
9 #include "ppapi/thunk/thunk.h" 11 #include "ppapi/thunk/thunk.h"
10 12
11 namespace ppapi { 13 namespace ppapi {
12 namespace thunk { 14 namespace thunk {
13 15
14 namespace { 16 namespace {
15 17
16 typedef EnterResource<PPB_AudioInput_API> EnterAudioInput; 18 typedef EnterResource<PPB_AudioInput_API> EnterAudioInput;
17 19
18 PP_Resource Create(PP_Instance instance, 20 PP_Resource Create0_1(PP_Instance instance,
19 PP_Resource config_id, 21 PP_Resource config,
20 PPB_AudioInput_Callback callback, 22 PPB_AudioInput_Callback audio_input_callback,
21 void* user_data) { 23 void* user_data) {
22 EnterFunction<ResourceCreationAPI> enter(instance, true); 24 EnterResourceCreation enter(instance);
23 if (enter.failed()) 25 if (enter.failed())
24 return 0; 26 return 0;
25 27
26 return enter.functions()->CreateAudioInput(instance, config_id, 28 return enter.functions()->CreateAudioInput0_1(
27 callback, user_data); 29 instance, config, audio_input_callback, user_data);
30 }
31
32 PP_Resource Create0_2(PP_Instance instance) {
33 EnterResourceCreation enter(instance);
34 if (enter.failed())
35 return 0;
36
37 return enter.functions()->CreateAudioInput(instance);
28 } 38 }
29 39
30 PP_Bool IsAudioInput(PP_Resource resource) { 40 PP_Bool IsAudioInput(PP_Resource resource) {
31 EnterAudioInput enter(resource, false); 41 EnterAudioInput enter(resource, false);
32 return PP_FromBool(enter.succeeded()); 42 return PP_FromBool(enter.succeeded());
33 } 43 }
34 44
35 PP_Resource GetCurrentConfiguration(PP_Resource audio_id) { 45 int32_t EnumerateDevices(PP_Resource audio_input,
36 EnterAudioInput enter(audio_id, true); 46 PP_Resource* devices,
47 PP_CompletionCallback callback) {
48 EnterAudioInput enter(audio_input, callback, true);
49 if (enter.failed())
50 return enter.retval();
51
52 return enter.SetResult(enter.object()->EnumerateDevices(devices, callback));
53 }
54
55 int32_t Open(PP_Resource audio_input,
56 PP_Resource device_ref,
57 PP_Resource config,
58 PPB_AudioInput_Callback audio_input_callback,
59 void* user_data,
60 PP_CompletionCallback callback) {
61 EnterAudioInput enter(audio_input, callback, true);
62 if (enter.failed())
63 return enter.retval();
64
65 std::string device_id;
66 // |device_id| remains empty if |device_ref| is 0, which means the default
67 // device.
68 if (device_ref != 0) {
69 EnterResourceNoLock<PPB_DeviceRef_API> enter_device_ref(device_ref, true);
70 if (enter_device_ref.failed())
71 return enter.SetResult(PP_ERROR_BADRESOURCE);
72 device_id = enter_device_ref.object()->GetDeviceRefData().id;
73 }
74
75 return enter.SetResult(enter.object()->Open(
76 device_id, config, audio_input_callback, user_data, callback));
77 }
78
79 PP_Resource GetCurrentConfig(PP_Resource audio_input) {
80 EnterAudioInput enter(audio_input, true);
37 if (enter.failed()) 81 if (enter.failed())
38 return 0; 82 return 0;
39 return enter.object()->GetCurrentConfig(); 83 return enter.object()->GetCurrentConfig();
40 } 84 }
41 85
42 PP_Bool StartCapture(PP_Resource audio_input) { 86 PP_Bool StartCapture(PP_Resource audio_input) {
43 EnterAudioInput enter(audio_input, true); 87 EnterAudioInput enter(audio_input, true);
44 if (enter.failed()) 88 if (enter.failed())
45 return PP_FALSE; 89 return PP_FALSE;
46 90
47 return enter.object()->StartCapture(); 91 return enter.object()->StartCapture();
48 } 92 }
49 93
50 PP_Bool StopCapture(PP_Resource audio_input) { 94 PP_Bool StopCapture(PP_Resource audio_input) {
51 EnterAudioInput enter(audio_input, true); 95 EnterAudioInput enter(audio_input, true);
52 if (enter.failed()) 96 if (enter.failed())
53 return PP_FALSE; 97 return PP_FALSE;
54 98
55 return enter.object()->StopCapture(); 99 return enter.object()->StopCapture();
56 } 100 }
57 101
58 const PPB_AudioInput_Dev g_ppb_audioinput_thunk = { 102 void Close(PP_Resource audio_input) {
59 &Create, 103 EnterAudioInput enter(audio_input, true);
104 if (enter.succeeded())
105 enter.object()->Close();
106 }
107
108 const PPB_AudioInput_Dev_0_1 g_ppb_audioinput_0_1_thunk = {
109 &Create0_1,
60 &IsAudioInput, 110 &IsAudioInput,
61 &GetCurrentConfiguration, 111 &GetCurrentConfig,
62 &StartCapture, 112 &StartCapture,
63 &StopCapture 113 &StopCapture
64 }; 114 };
65 115
116 const PPB_AudioInput_Dev_0_2 g_ppb_audioinput_0_2_thunk = {
117 &Create0_2,
118 &IsAudioInput,
119 &EnumerateDevices,
120 &Open,
121 &GetCurrentConfig,
122 &StartCapture,
123 &StopCapture,
124 &Close
125 };
126
66 } // namespace 127 } // namespace
67 128
68 const PPB_AudioInput_Dev_0_1* GetPPB_AudioInput_Dev_0_1_Thunk() { 129 const PPB_AudioInput_Dev_0_1* GetPPB_AudioInput_Dev_0_1_Thunk() {
69 return &g_ppb_audioinput_thunk; 130 return &g_ppb_audioinput_0_1_thunk;
131 }
132
133 const PPB_AudioInput_Dev_0_2* GetPPB_AudioInput_Dev_0_2_Thunk() {
134 return &g_ppb_audioinput_0_2_thunk;
70 } 135 }
71 136
72 } // namespace thunk 137 } // namespace thunk
73 } // namespace ppapi 138 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/thunk/ppb_audio_input_api.h ('k') | ppapi/thunk/ppb_audio_input_trusted_thunk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698