| OLD | NEW |
| 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>() { | |
| 18 return PPB_AUDIO_INPUT_DEV_INTERFACE_0_2; | |
| 19 } | |
| 20 | |
| 21 template <> const char* interface_name<PPB_AudioInput_Dev_0_3>() { | 17 template <> const char* interface_name<PPB_AudioInput_Dev_0_3>() { |
| 22 return PPB_AUDIO_INPUT_DEV_INTERFACE_0_3; | 18 return PPB_AUDIO_INPUT_DEV_INTERFACE_0_3; |
| 23 } | 19 } |
| 24 | 20 |
| 25 template <> const char* interface_name<PPB_AudioInput_Dev_0_4>() { | 21 template <> const char* interface_name<PPB_AudioInput_Dev_0_4>() { |
| 26 return PPB_AUDIO_INPUT_DEV_INTERFACE_0_4; | 22 return PPB_AUDIO_INPUT_DEV_INTERFACE_0_4; |
| 27 } | 23 } |
| 28 | 24 |
| 29 } // namespace | 25 } // namespace |
| 30 | 26 |
| 31 AudioInput_Dev::AudioInput_Dev() { | 27 AudioInput_Dev::AudioInput_Dev() { |
| 32 } | 28 } |
| 33 | 29 |
| 34 AudioInput_Dev::AudioInput_Dev(const InstanceHandle& instance) { | 30 AudioInput_Dev::AudioInput_Dev(const InstanceHandle& instance) { |
| 35 if (has_interface<PPB_AudioInput_Dev_0_4>()) { | 31 if (has_interface<PPB_AudioInput_Dev_0_4>()) { |
| 36 PassRefFromConstructor(get_interface<PPB_AudioInput_Dev_0_4>()->Create( | 32 PassRefFromConstructor(get_interface<PPB_AudioInput_Dev_0_4>()->Create( |
| 37 instance.pp_instance())); | 33 instance.pp_instance())); |
| 38 } else if (has_interface<PPB_AudioInput_Dev_0_3>()) { | 34 } else if (has_interface<PPB_AudioInput_Dev_0_3>()) { |
| 39 PassRefFromConstructor(get_interface<PPB_AudioInput_Dev_0_3>()->Create( | 35 PassRefFromConstructor(get_interface<PPB_AudioInput_Dev_0_3>()->Create( |
| 40 instance.pp_instance())); | 36 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())); | |
| 44 } | 37 } |
| 45 } | 38 } |
| 46 | 39 |
| 47 AudioInput_Dev::~AudioInput_Dev() { | 40 AudioInput_Dev::~AudioInput_Dev() { |
| 48 } | 41 } |
| 49 | 42 |
| 50 // static | 43 // static |
| 51 bool AudioInput_Dev::IsAvailable() { | 44 bool AudioInput_Dev::IsAvailable() { |
| 52 return has_interface<PPB_AudioInput_Dev_0_4>() || | 45 return has_interface<PPB_AudioInput_Dev_0_4>() || |
| 53 has_interface<PPB_AudioInput_Dev_0_3>() || | 46 has_interface<PPB_AudioInput_Dev_0_3>(); |
| 54 has_interface<PPB_AudioInput_Dev_0_2>(); | |
| 55 } | 47 } |
| 56 | 48 |
| 57 int32_t AudioInput_Dev::EnumerateDevices( | 49 int32_t AudioInput_Dev::EnumerateDevices( |
| 58 const CompletionCallbackWithOutput<std::vector<DeviceRef_Dev> >& callback) { | 50 const CompletionCallbackWithOutput<std::vector<DeviceRef_Dev> >& callback) { |
| 59 if (has_interface<PPB_AudioInput_Dev_0_4>()) { | 51 if (has_interface<PPB_AudioInput_Dev_0_4>()) { |
| 60 return get_interface<PPB_AudioInput_Dev_0_4>()->EnumerateDevices( | 52 return get_interface<PPB_AudioInput_Dev_0_4>()->EnumerateDevices( |
| 61 pp_resource(), callback.output(), callback.pp_completion_callback()); | 53 pp_resource(), callback.output(), callback.pp_completion_callback()); |
| 62 } | 54 } |
| 63 if (has_interface<PPB_AudioInput_Dev_0_3>()) { | 55 if (has_interface<PPB_AudioInput_Dev_0_3>()) { |
| 64 return get_interface<PPB_AudioInput_Dev_0_3>()->EnumerateDevices( | 56 return get_interface<PPB_AudioInput_Dev_0_3>()->EnumerateDevices( |
| 65 pp_resource(), callback.output(), callback.pp_completion_callback()); | 57 pp_resource(), callback.output(), callback.pp_completion_callback()); |
| 66 } | 58 } |
| 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); | |
| 70 | |
| 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)); | |
| 79 } | |
| 80 | 59 |
| 81 return callback.MayForce(PP_ERROR_NOINTERFACE); | 60 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 82 } | 61 } |
| 83 | 62 |
| 84 int32_t AudioInput_Dev::MonitorDeviceChange( | 63 int32_t AudioInput_Dev::MonitorDeviceChange( |
| 85 PP_MonitorDeviceChangeCallback callback, | 64 PP_MonitorDeviceChangeCallback callback, |
| 86 void* user_data) { | 65 void* user_data) { |
| 87 if (has_interface<PPB_AudioInput_Dev_0_4>()) { | 66 if (has_interface<PPB_AudioInput_Dev_0_4>()) { |
| 88 return get_interface<PPB_AudioInput_Dev_0_4>()->MonitorDeviceChange( | 67 return get_interface<PPB_AudioInput_Dev_0_4>()->MonitorDeviceChange( |
| 89 pp_resource(), callback, user_data); | 68 pp_resource(), callback, user_data); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 106 pp_resource(), device_ref.pp_resource(), config.pp_resource(), | 85 pp_resource(), device_ref.pp_resource(), config.pp_resource(), |
| 107 audio_input_callback, user_data, callback.pp_completion_callback()); | 86 audio_input_callback, user_data, callback.pp_completion_callback()); |
| 108 } | 87 } |
| 109 | 88 |
| 110 return callback.MayForce(PP_ERROR_NOINTERFACE); | 89 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 111 } | 90 } |
| 112 | 91 |
| 113 int32_t AudioInput_Dev::Open( | 92 int32_t AudioInput_Dev::Open( |
| 114 const DeviceRef_Dev& device_ref, | 93 const DeviceRef_Dev& device_ref, |
| 115 const AudioConfig& config, | 94 const AudioConfig& config, |
| 116 PPB_AudioInput_Callback_0_2 audio_input_callback_0_2, | 95 PPB_AudioInput_Callback_0_3 audio_input_callback_0_3, |
| 117 void* user_data, | 96 void* user_data, |
| 118 const CompletionCallback& callback) { | 97 const CompletionCallback& callback) { |
| 119 if (has_interface<PPB_AudioInput_Dev_0_3>()) { | 98 if (has_interface<PPB_AudioInput_Dev_0_3>()) { |
| 120 return get_interface<PPB_AudioInput_Dev_0_3>()->Open( | 99 return get_interface<PPB_AudioInput_Dev_0_3>()->Open( |
| 121 pp_resource(), device_ref.pp_resource(), config.pp_resource(), | 100 pp_resource(), device_ref.pp_resource(), config.pp_resource(), |
| 122 audio_input_callback_0_2, user_data, callback.pp_completion_callback()); | 101 audio_input_callback_0_3, user_data, callback.pp_completion_callback()); |
| 123 } | |
| 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()); | |
| 128 } | 102 } |
| 129 | 103 |
| 130 return callback.MayForce(PP_ERROR_NOINTERFACE); | 104 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 131 } | 105 } |
| 132 | 106 |
| 133 bool AudioInput_Dev::StartCapture() { | 107 bool AudioInput_Dev::StartCapture() { |
| 134 if (has_interface<PPB_AudioInput_Dev_0_4>()) { | 108 if (has_interface<PPB_AudioInput_Dev_0_4>()) { |
| 135 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_4>()->StartCapture( | 109 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_4>()->StartCapture( |
| 136 pp_resource())); | 110 pp_resource())); |
| 137 } | 111 } |
| 138 if (has_interface<PPB_AudioInput_Dev_0_3>()) { | 112 if (has_interface<PPB_AudioInput_Dev_0_3>()) { |
| 139 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_3>()->StartCapture( | 113 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_3>()->StartCapture( |
| 140 pp_resource())); | 114 pp_resource())); |
| 141 } | 115 } |
| 142 if (has_interface<PPB_AudioInput_Dev_0_2>()) { | |
| 143 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_2>()->StartCapture( | |
| 144 pp_resource())); | |
| 145 } | |
| 146 | 116 |
| 147 return false; | 117 return false; |
| 148 } | 118 } |
| 149 | 119 |
| 150 bool AudioInput_Dev::StopCapture() { | 120 bool AudioInput_Dev::StopCapture() { |
| 151 if (has_interface<PPB_AudioInput_Dev_0_4>()) { | 121 if (has_interface<PPB_AudioInput_Dev_0_4>()) { |
| 152 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_4>()->StopCapture( | 122 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_4>()->StopCapture( |
| 153 pp_resource())); | 123 pp_resource())); |
| 154 } | 124 } |
| 155 if (has_interface<PPB_AudioInput_Dev_0_3>()) { | 125 if (has_interface<PPB_AudioInput_Dev_0_3>()) { |
| 156 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_3>()->StopCapture( | 126 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_3>()->StopCapture( |
| 157 pp_resource())); | 127 pp_resource())); |
| 158 } | 128 } |
| 159 if (has_interface<PPB_AudioInput_Dev_0_2>()) { | |
| 160 return PP_ToBool(get_interface<PPB_AudioInput_Dev_0_2>()->StopCapture( | |
| 161 pp_resource())); | |
| 162 } | |
| 163 | 129 |
| 164 return false; | 130 return false; |
| 165 } | 131 } |
| 166 | 132 |
| 167 void AudioInput_Dev::Close() { | 133 void AudioInput_Dev::Close() { |
| 168 if (has_interface<PPB_AudioInput_Dev_0_4>()) { | 134 if (has_interface<PPB_AudioInput_Dev_0_4>()) { |
| 169 get_interface<PPB_AudioInput_Dev_0_4>()->Close(pp_resource()); | 135 get_interface<PPB_AudioInput_Dev_0_4>()->Close(pp_resource()); |
| 170 } else if (has_interface<PPB_AudioInput_Dev_0_3>()) { | 136 } else if (has_interface<PPB_AudioInput_Dev_0_3>()) { |
| 171 get_interface<PPB_AudioInput_Dev_0_3>()->Close(pp_resource()); | 137 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()); | |
| 174 } | 138 } |
| 175 } | 139 } |
| 176 | 140 |
| 177 } // namespace pp | 141 } // namespace pp |
| OLD | NEW |