cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / cpp / dev / audio_input_dev.cc
blob0c2f37786fee4fe672e40cb521fef1982613811b
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/cpp/dev/audio_input_dev.h"
7 #include "ppapi/c/pp_bool.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/cpp/dev/resource_array_dev.h"
10 #include "ppapi/cpp/instance_handle.h"
11 #include "ppapi/cpp/module_impl.h"
13 namespace pp {
15 namespace {
17 template <> const char* interface_name<PPB_AudioInput_Dev_0_2>() {
18 return PPB_AUDIO_INPUT_DEV_INTERFACE_0_2;
21 template <> const char* interface_name<PPB_AudioInput_Dev_0_3>() {
22 return PPB_AUDIO_INPUT_DEV_INTERFACE_0_3;
25 template <> const char* interface_name<PPB_AudioInput_Dev_0_4>() {
26 return PPB_AUDIO_INPUT_DEV_INTERFACE_0_4;
29 } // namespace
31 AudioInput_Dev::AudioInput_Dev() {
34 AudioInput_Dev::AudioInput_Dev(const InstanceHandle& instance) {
35 if (has_interface<PPB_AudioInput_Dev_0_4>()) {
36 PassRefFromConstructor(get_interface<PPB_AudioInput_Dev_0_4>()->Create(
37 instance.pp_instance()));
38 } else if (has_interface<PPB_AudioInput_Dev_0_3>()) {
39 PassRefFromConstructor(get_interface<PPB_AudioInput_Dev_0_3>()->Create(
40 instance.pp_instance()));
41 } else if (has_interface<PPB_AudioInput_Dev_0_2>()) {
42 PassRefFromConstructor(get_interface<PPB_AudioInput_Dev_0_2>()->Create(
43 instance.pp_instance()));
47 AudioInput_Dev::~AudioInput_Dev() {
50 // static
51 bool AudioInput_Dev::IsAvailable() {
52 return has_interface<PPB_AudioInput_Dev_0_4>() ||
53 has_interface<PPB_AudioInput_Dev_0_3>() ||
54 has_interface<PPB_AudioInput_Dev_0_2>();
57 int32_t AudioInput_Dev::EnumerateDevices(
58 const CompletionCallbackWithOutput<std::vector<DeviceRef_Dev> >& callback) {
59 if (has_interface<PPB_AudioInput_Dev_0_4>()) {
60 return get_interface<PPB_AudioInput_Dev_0_4>()->EnumerateDevices(
61 pp_resource(), callback.output(), callback.pp_completion_callback());
63 if (has_interface<PPB_AudioInput_Dev_0_3>()) {
64 return get_interface<PPB_AudioInput_Dev_0_3>()->EnumerateDevices(
65 pp_resource(), callback.output(), callback.pp_completion_callback());
67 if (has_interface<PPB_AudioInput_Dev_0_2>()) {
68 if (!callback.pp_completion_callback().func)
69 return callback.MayForce(PP_ERROR_BLOCKS_MAIN_THREAD);
71 // ArrayOutputCallbackConverter is responsible to delete it.
72 ResourceArray_Dev::ArrayOutputCallbackData* data =
73 new ResourceArray_Dev::ArrayOutputCallbackData(
74 callback.output(), callback.pp_completion_callback());
75 return get_interface<PPB_AudioInput_Dev_0_2>()->EnumerateDevices(
76 pp_resource(), &data->resource_array_output,
77 PP_MakeCompletionCallback(
78 &ResourceArray_Dev::ArrayOutputCallbackConverter, data));
81 return callback.MayForce(PP_ERROR_NOINTERFACE);
84 int32_t AudioInput_Dev::MonitorDeviceChange(
85 PP_MonitorDeviceChangeCallback callback,
86 void* user_data) {
87 if (has_interface<PPB_AudioInput_Dev_0_4>()) {
88 return get_interface<PPB_AudioInput_Dev_0_4>()->MonitorDeviceChange(
89 pp_resource(), callback, user_data);
91 if (has_interface<PPB_AudioInput_Dev_0_3>()) {
92 return get_interface<PPB_AudioInput_Dev_0_3>()->MonitorDeviceChange(
93 pp_resource(), callback, user_data);
96 return PP_ERROR_NOINTERFACE;
99 int32_t AudioInput_Dev::Open(const DeviceRef_Dev& device_ref,
100 const AudioConfig& config,
101 PPB_AudioInput_Callback audio_input_callback,
102 void* user_data,
103 const CompletionCallback& callback) {
104 if (has_interface<PPB_AudioInput_Dev_0_4>()) {
105 return get_interface<PPB_AudioInput_Dev_0_4>()->Open(
106 pp_resource(), device_ref.pp_resource(), config.pp_resource(),
107 audio_input_callback, user_data, callback.pp_completion_callback());
110 return callback.MayForce(PP_ERROR_NOINTERFACE);
113 int32_t AudioInput_Dev::Open(
114 const DeviceRef_Dev& device_ref,
115 const AudioConfig& config,
116 PPB_AudioInput_Callback_0_2 audio_input_callback_0_2,
117 void* user_data,
118 const CompletionCallback& callback) {
119 if (has_interface<PPB_AudioInput_Dev_0_3>()) {
120 return get_interface<PPB_AudioInput_Dev_0_3>()->Open(
121 pp_resource(), device_ref.pp_resource(), config.pp_resource(),
122 audio_input_callback_0_2, user_data, callback.pp_completion_callback());
124 if (has_interface<PPB_AudioInput_Dev_0_2>()) {
125 return get_interface<PPB_AudioInput_Dev_0_2>()->Open(
126 pp_resource(), device_ref.pp_resource(), config.pp_resource(),
127 audio_input_callback_0_2, user_data, callback.pp_completion_callback());
130 return callback.MayForce(PP_ERROR_NOINTERFACE);
133 bool AudioInput_Dev::StartCapture() {
134 if (has_interface<PPB_AudioInput_Dev_0_4>()) {
135 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_4>()->StartCapture(
136 pp_resource()));
138 if (has_interface<PPB_AudioInput_Dev_0_3>()) {
139 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_3>()->StartCapture(
140 pp_resource()));
142 if (has_interface<PPB_AudioInput_Dev_0_2>()) {
143 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_2>()->StartCapture(
144 pp_resource()));
147 return false;
150 bool AudioInput_Dev::StopCapture() {
151 if (has_interface<PPB_AudioInput_Dev_0_4>()) {
152 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_4>()->StopCapture(
153 pp_resource()));
155 if (has_interface<PPB_AudioInput_Dev_0_3>()) {
156 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_3>()->StopCapture(
157 pp_resource()));
159 if (has_interface<PPB_AudioInput_Dev_0_2>()) {
160 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_2>()->StopCapture(
161 pp_resource()));
164 return false;
167 void AudioInput_Dev::Close() {
168 if (has_interface<PPB_AudioInput_Dev_0_4>()) {
169 get_interface<PPB_AudioInput_Dev_0_4>()->Close(pp_resource());
170 } else if (has_interface<PPB_AudioInput_Dev_0_3>()) {
171 get_interface<PPB_AudioInput_Dev_0_3>()->Close(pp_resource());
172 } else if (has_interface<PPB_AudioInput_Dev_0_2>()) {
173 get_interface<PPB_AudioInput_Dev_0_2>()->Close(pp_resource());
177 } // namespace pp