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

Side by Side Diff: ppapi/cpp/dev/audio_input_dev.cc

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
« no previous file with comments | « ppapi/cpp/dev/audio_input_dev.h ('k') | ppapi/examples/audio_input/audio_input.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/cpp/dev/audio_input_dev.h" 5 #include "ppapi/cpp/dev/audio_input_dev.h"
6 6
7 #include "ppapi/c/pp_bool.h" 7 #include "ppapi/c/pp_bool.h"
8 #include "ppapi/c/pp_errors.h" 8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/cpp/dev/resource_array_dev.h" 9 #include "ppapi/cpp/dev/resource_array_dev.h"
10 #include "ppapi/cpp/instance_handle.h" 10 #include "ppapi/cpp/instance_handle.h"
11 #include "ppapi/cpp/module_impl.h" 11 #include "ppapi/cpp/module_impl.h"
12 12
13 namespace pp { 13 namespace pp {
14 14
15 namespace { 15 namespace {
16 16
17 template <> const char* interface_name<PPB_AudioInput_Dev_0_2>() { 17 template <> const char* interface_name<PPB_AudioInput_Dev_0_2>() {
18 return PPB_AUDIO_INPUT_DEV_INTERFACE_0_2; 18 return PPB_AUDIO_INPUT_DEV_INTERFACE_0_2;
19 } 19 }
20 20
21 template <> const char* interface_name<PPB_AudioInput_Dev_0_1>() {
22 return PPB_AUDIO_INPUT_DEV_INTERFACE_0_1;
23 }
24
25 } // namespace 21 } // namespace
26 22
27 AudioInput_Dev::AudioInput_Dev() : audio_input_callback_(NULL), 23 AudioInput_Dev::AudioInput_Dev() {
28 user_data_(NULL) {
29 } 24 }
30 25
31 AudioInput_Dev::AudioInput_Dev(const InstanceHandle& instance, 26 AudioInput_Dev::AudioInput_Dev(const InstanceHandle& instance) {
32 const AudioConfig& config,
33 PPB_AudioInput_Callback callback,
34 void* user_data)
35 : config_(config),
36 audio_input_callback_(callback),
37 user_data_(user_data) {
38 if (has_interface<PPB_AudioInput_Dev_0_2>()) { 27 if (has_interface<PPB_AudioInput_Dev_0_2>()) {
39 PassRefFromConstructor(get_interface<PPB_AudioInput_Dev_0_2>()->Create( 28 PassRefFromConstructor(get_interface<PPB_AudioInput_Dev_0_2>()->Create(
40 instance.pp_instance())); 29 instance.pp_instance()));
41 } else if (has_interface<PPB_AudioInput_Dev_0_1>()) {
42 PassRefFromConstructor(get_interface<PPB_AudioInput_Dev_0_1>()->Create(
43 instance.pp_instance(), config.pp_resource(), callback, user_data));
44 }
45 }
46
47 AudioInput_Dev::AudioInput_Dev(const InstanceHandle& instance)
48 : audio_input_callback_(NULL),
49 user_data_(NULL) {
50 if (has_interface<PPB_AudioInput_Dev_0_2>()) {
51 PassRefFromConstructor(get_interface<PPB_AudioInput_Dev_0_2>()->Create(
52 instance.pp_instance()));
53 } 30 }
54 } 31 }
55 32
56 AudioInput_Dev::~AudioInput_Dev() { 33 AudioInput_Dev::~AudioInput_Dev() {
57 } 34 }
58 35
59 // static 36 // static
60 bool AudioInput_Dev::IsAvailable() { 37 bool AudioInput_Dev::IsAvailable() {
61 return has_interface<PPB_AudioInput_Dev_0_2>() || 38 return has_interface<PPB_AudioInput_Dev_0_2>();
62 has_interface<PPB_AudioInput_Dev_0_1>();
63 } 39 }
64 40
65 int32_t AudioInput_Dev::EnumerateDevices( 41 int32_t AudioInput_Dev::EnumerateDevices(
66 const CompletionCallbackWithOutput<std::vector<DeviceRef_Dev> >& callback) { 42 const CompletionCallbackWithOutput<std::vector<DeviceRef_Dev> >& callback) {
67 if (!has_interface<PPB_AudioInput_Dev_0_2>()) 43 if (!has_interface<PPB_AudioInput_Dev_0_2>())
68 return callback.MayForce(PP_ERROR_NOINTERFACE); 44 return callback.MayForce(PP_ERROR_NOINTERFACE);
69 if (!callback.pp_completion_callback().func) 45 if (!callback.pp_completion_callback().func)
70 return callback.MayForce(PP_ERROR_BLOCKS_MAIN_THREAD); 46 return callback.MayForce(PP_ERROR_BLOCKS_MAIN_THREAD);
71 47
72 // ArrayOutputCallbackConverter is responsible to delete it. 48 // ArrayOutputCallbackConverter is responsible to delete it.
73 ResourceArray_Dev::ArrayOutputCallbackData* data = 49 ResourceArray_Dev::ArrayOutputCallbackData* data =
74 new ResourceArray_Dev::ArrayOutputCallbackData( 50 new ResourceArray_Dev::ArrayOutputCallbackData(
75 callback.output(), callback.pp_completion_callback()); 51 callback.output(), callback.pp_completion_callback());
76 return get_interface<PPB_AudioInput_Dev_0_2>()->EnumerateDevices( 52 return get_interface<PPB_AudioInput_Dev_0_2>()->EnumerateDevices(
77 pp_resource(), &data->resource_array_output, 53 pp_resource(), &data->resource_array_output,
78 PP_MakeCompletionCallback( 54 PP_MakeCompletionCallback(
79 &ResourceArray_Dev::ArrayOutputCallbackConverter, data)); 55 &ResourceArray_Dev::ArrayOutputCallbackConverter, data));
80 } 56 }
81 57
82 int32_t AudioInput_Dev::Open(const DeviceRef_Dev& device_ref, 58 int32_t AudioInput_Dev::Open(const DeviceRef_Dev& device_ref,
83 const CompletionCallback& callback) {
84 if (has_interface<PPB_AudioInput_Dev_0_2>()) {
85 return get_interface<PPB_AudioInput_Dev_0_2>()->Open(
86 pp_resource(), device_ref.pp_resource(), config_.pp_resource(),
87 audio_input_callback_, user_data_, callback.pp_completion_callback());
88 }
89
90 if (has_interface<PPB_AudioInput_Dev_0_1>()) {
91 if (is_null())
92 return callback.MayForce(PP_ERROR_FAILED);
93
94 // If the v0.1 interface is being used and there is a valid resource handle,
95 // then the default device has been successfully opened during resource
96 // creation.
97 if (device_ref.is_null())
98 return callback.MayForce(PP_OK);
99
100 // The v0.1 interface doesn't support devices other than the default one.
101 return callback.MayForce(PP_ERROR_NOTSUPPORTED);
102 }
103
104 return callback.MayForce(PP_ERROR_NOINTERFACE);
105 }
106
107 int32_t AudioInput_Dev::Open(const DeviceRef_Dev& device_ref,
108 const AudioConfig& config, 59 const AudioConfig& config,
109 PPB_AudioInput_Callback audio_input_callback, 60 PPB_AudioInput_Callback audio_input_callback,
110 void* user_data, 61 void* user_data,
111 const CompletionCallback& callback) { 62 const CompletionCallback& callback) {
112 if (has_interface<PPB_AudioInput_Dev_0_2>()) { 63 if (has_interface<PPB_AudioInput_Dev_0_2>()) {
113 return get_interface<PPB_AudioInput_Dev_0_2>()->Open( 64 return get_interface<PPB_AudioInput_Dev_0_2>()->Open(
114 pp_resource(), device_ref.pp_resource(), config.pp_resource(), 65 pp_resource(), device_ref.pp_resource(), config.pp_resource(),
115 audio_input_callback, user_data, callback.pp_completion_callback()); 66 audio_input_callback, user_data, callback.pp_completion_callback());
116 } 67 }
117 68
118 return callback.MayForce(PP_ERROR_NOINTERFACE); 69 return callback.MayForce(PP_ERROR_NOINTERFACE);
119 } 70 }
120 71
121 bool AudioInput_Dev::StartCapture() { 72 bool AudioInput_Dev::StartCapture() {
122 if (has_interface<PPB_AudioInput_Dev_0_2>()) { 73 if (has_interface<PPB_AudioInput_Dev_0_2>()) {
123 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_2>()->StartCapture( 74 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_2>()->StartCapture(
124 pp_resource())); 75 pp_resource()));
125 } 76 }
126 77
127 if (has_interface<PPB_AudioInput_Dev_0_1>()) {
128 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_1>()->StartCapture(
129 pp_resource()));
130 }
131
132 return false; 78 return false;
133 } 79 }
134 80
135 bool AudioInput_Dev::StopCapture() { 81 bool AudioInput_Dev::StopCapture() {
136 if (has_interface<PPB_AudioInput_Dev_0_2>()) { 82 if (has_interface<PPB_AudioInput_Dev_0_2>()) {
137 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_2>()->StopCapture( 83 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_2>()->StopCapture(
138 pp_resource())); 84 pp_resource()));
139 } 85 }
140 86
141 if (has_interface<PPB_AudioInput_Dev_0_1>()) {
142 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_1>()->StopCapture(
143 pp_resource()));
144 }
145
146 return false; 87 return false;
147 } 88 }
148 89
149 void AudioInput_Dev::Close() { 90 void AudioInput_Dev::Close() {
150 if (has_interface<PPB_AudioInput_Dev_0_2>()) 91 if (has_interface<PPB_AudioInput_Dev_0_2>())
151 get_interface<PPB_AudioInput_Dev_0_2>()->Close(pp_resource()); 92 get_interface<PPB_AudioInput_Dev_0_2>()->Close(pp_resource());
152 } 93 }
153 94
154 } // namespace pp 95 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/cpp/dev/audio_input_dev.h ('k') | ppapi/examples/audio_input/audio_input.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698