Add/resurrect support for bundles of WebStore items.
[chromium-blink-merge.git] / ppapi / cpp / dev / audio_input_dev.cc
blobc98fefa947a7c03e506f12505383f99885162aba
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/instance_handle.h"
10 #include "ppapi/cpp/module_impl.h"
12 namespace pp {
14 namespace {
16 template <> const char* interface_name<PPB_AudioInput_Dev_0_3>() {
17 return PPB_AUDIO_INPUT_DEV_INTERFACE_0_3;
20 template <> const char* interface_name<PPB_AudioInput_Dev_0_4>() {
21 return PPB_AUDIO_INPUT_DEV_INTERFACE_0_4;
24 } // namespace
26 AudioInput_Dev::AudioInput_Dev() {
29 AudioInput_Dev::AudioInput_Dev(const InstanceHandle& instance) {
30 if (has_interface<PPB_AudioInput_Dev_0_4>()) {
31 PassRefFromConstructor(get_interface<PPB_AudioInput_Dev_0_4>()->Create(
32 instance.pp_instance()));
33 } else if (has_interface<PPB_AudioInput_Dev_0_3>()) {
34 PassRefFromConstructor(get_interface<PPB_AudioInput_Dev_0_3>()->Create(
35 instance.pp_instance()));
39 AudioInput_Dev::~AudioInput_Dev() {
42 // static
43 bool AudioInput_Dev::IsAvailable() {
44 return has_interface<PPB_AudioInput_Dev_0_4>() ||
45 has_interface<PPB_AudioInput_Dev_0_3>();
48 int32_t AudioInput_Dev::EnumerateDevices(
49 const CompletionCallbackWithOutput<std::vector<DeviceRef_Dev> >& callback) {
50 if (has_interface<PPB_AudioInput_Dev_0_4>()) {
51 return get_interface<PPB_AudioInput_Dev_0_4>()->EnumerateDevices(
52 pp_resource(), callback.output(), callback.pp_completion_callback());
54 if (has_interface<PPB_AudioInput_Dev_0_3>()) {
55 return get_interface<PPB_AudioInput_Dev_0_3>()->EnumerateDevices(
56 pp_resource(), callback.output(), callback.pp_completion_callback());
59 return callback.MayForce(PP_ERROR_NOINTERFACE);
62 int32_t AudioInput_Dev::MonitorDeviceChange(
63 PP_MonitorDeviceChangeCallback callback,
64 void* user_data) {
65 if (has_interface<PPB_AudioInput_Dev_0_4>()) {
66 return get_interface<PPB_AudioInput_Dev_0_4>()->MonitorDeviceChange(
67 pp_resource(), callback, user_data);
69 if (has_interface<PPB_AudioInput_Dev_0_3>()) {
70 return get_interface<PPB_AudioInput_Dev_0_3>()->MonitorDeviceChange(
71 pp_resource(), callback, user_data);
74 return PP_ERROR_NOINTERFACE;
77 int32_t AudioInput_Dev::Open(const DeviceRef_Dev& device_ref,
78 const AudioConfig& config,
79 PPB_AudioInput_Callback audio_input_callback,
80 void* user_data,
81 const CompletionCallback& callback) {
82 if (has_interface<PPB_AudioInput_Dev_0_4>()) {
83 return get_interface<PPB_AudioInput_Dev_0_4>()->Open(
84 pp_resource(), device_ref.pp_resource(), config.pp_resource(),
85 audio_input_callback, user_data, callback.pp_completion_callback());
88 return callback.MayForce(PP_ERROR_NOINTERFACE);
91 int32_t AudioInput_Dev::Open(
92 const DeviceRef_Dev& device_ref,
93 const AudioConfig& config,
94 PPB_AudioInput_Callback_0_3 audio_input_callback_0_3,
95 void* user_data,
96 const CompletionCallback& callback) {
97 if (has_interface<PPB_AudioInput_Dev_0_3>()) {
98 return get_interface<PPB_AudioInput_Dev_0_3>()->Open(
99 pp_resource(), device_ref.pp_resource(), config.pp_resource(),
100 audio_input_callback_0_3, user_data, callback.pp_completion_callback());
103 return callback.MayForce(PP_ERROR_NOINTERFACE);
106 bool AudioInput_Dev::StartCapture() {
107 if (has_interface<PPB_AudioInput_Dev_0_4>()) {
108 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_4>()->StartCapture(
109 pp_resource()));
111 if (has_interface<PPB_AudioInput_Dev_0_3>()) {
112 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_3>()->StartCapture(
113 pp_resource()));
116 return false;
119 bool AudioInput_Dev::StopCapture() {
120 if (has_interface<PPB_AudioInput_Dev_0_4>()) {
121 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_4>()->StopCapture(
122 pp_resource()));
124 if (has_interface<PPB_AudioInput_Dev_0_3>()) {
125 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_3>()->StopCapture(
126 pp_resource()));
129 return false;
132 void AudioInput_Dev::Close() {
133 if (has_interface<PPB_AudioInput_Dev_0_4>()) {
134 get_interface<PPB_AudioInput_Dev_0_4>()->Close(pp_resource());
135 } else if (has_interface<PPB_AudioInput_Dev_0_3>()) {
136 get_interface<PPB_AudioInput_Dev_0_3>()->Close(pp_resource());
140 } // namespace pp