| OLD | NEW |
| 1 // Copyright (c) 2011 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 #ifndef PPAPI_CPP_DEV_AUDIO_INPUT_DEV_H_ | 5 #ifndef PPAPI_CPP_DEV_AUDIO_INPUT_DEV_H_ |
| 6 #define PPAPI_CPP_DEV_AUDIO_INPUT_DEV_H_ | 6 #define PPAPI_CPP_DEV_AUDIO_INPUT_DEV_H_ |
| 7 | 7 |
| 8 #include <vector> |
| 9 |
| 8 #include "ppapi/c/dev/ppb_audio_input_dev.h" | 10 #include "ppapi/c/dev/ppb_audio_input_dev.h" |
| 9 #include "ppapi/cpp/audio_config.h" | 11 #include "ppapi/cpp/audio_config.h" |
| 10 #include "ppapi/cpp/resource.h" | 12 #include "ppapi/cpp/resource.h" |
| 11 | 13 |
| 12 namespace pp { | 14 namespace pp { |
| 13 | 15 |
| 16 class CompletionCallback; |
| 17 class DeviceRef_Dev; |
| 14 class InstanceHandle; | 18 class InstanceHandle; |
| 15 | 19 |
| 16 class AudioInput_Dev : public Resource { | 20 class AudioInput_Dev : public Resource { |
| 17 public: | 21 public: |
| 18 /// An empty constructor for an AudioInput resource. | 22 /// An empty constructor for an AudioInput resource. |
| 19 AudioInput_Dev() {} | 23 AudioInput_Dev(); |
| 20 | 24 |
| 25 /// This constructor tries to create an audio input resource using the v0.2 |
| 26 /// interface, and falls back on the v0.1 interface if that is not available. |
| 27 /// Please use the 2-parameter Open() if you used this constructor. |
| 28 /// |
| 29 /// Note: This constructor is deprecated. Unless your code has to deal with |
| 30 /// browsers that only support the v0.1 interface, please use the 1-parameter |
| 31 /// constructor instead. |
| 21 AudioInput_Dev(const InstanceHandle& instance, | 32 AudioInput_Dev(const InstanceHandle& instance, |
| 22 const AudioConfig& config, | 33 const AudioConfig& config, |
| 23 PPB_AudioInput_Callback callback, | 34 PPB_AudioInput_Callback callback, |
| 24 void* user_data); | 35 void* user_data); |
| 25 | 36 |
| 37 /// This constructor uses the v0.2 interface to create an audio input |
| 38 /// resource. Please use the 5-parameter Open() if you used this constructor. |
| 39 explicit AudioInput_Dev(const InstanceHandle& instance); |
| 40 |
| 41 AudioInput_Dev(const AudioInput_Dev& other); |
| 42 |
| 43 virtual ~AudioInput_Dev(); |
| 44 |
| 45 AudioInput_Dev& operator=(const AudioInput_Dev& other); |
| 46 |
| 26 /// Static function for determining whether the browser supports the required | 47 /// Static function for determining whether the browser supports the required |
| 27 /// AudioInput interface. | 48 /// AudioInput interface. |
| 28 /// | 49 /// |
| 29 /// @return true if the interface is available, false otherwise. | 50 /// @return true if the interface is available, false otherwise. |
| 30 static bool IsAvailable(); | 51 static bool IsAvailable(); |
| 31 | 52 |
| 32 /// Getter function for returning the internal <code>PPB_AudioConfig</code> | 53 /// Getter function for returning the internal <code>PPB_AudioConfig</code> |
| 33 /// struct. | 54 /// struct. |
| 34 /// | 55 /// |
| 35 /// @return A mutable reference to the PPB_AudioConfig struct. | 56 /// @return A mutable reference to the PPB_AudioConfig struct. |
| 36 AudioConfig& config() { return config_; } | 57 AudioConfig& config() { return config_; } |
| 37 | 58 |
| 38 /// Getter function for returning the internal <code>PPB_AudioConfig</code> | 59 /// Getter function for returning the internal <code>PPB_AudioConfig</code> |
| 39 /// struct. | 60 /// struct. |
| 40 /// | 61 /// |
| 41 /// @return A const reference to the internal <code>PPB_AudioConfig</code> | 62 /// @return A const reference to the internal <code>PPB_AudioConfig</code> |
| 42 /// struct. | 63 /// struct. |
| 43 const AudioConfig& config() const { return config_; } | 64 const AudioConfig& config() const { return config_; } |
| 44 | 65 |
| 66 /// |devices| must stay alive until either this AudioInput_Dev object goes |
| 67 /// away or |callback| is run, if this method returns PP_OK_COMPLETIONPENDING. |
| 68 int32_t EnumerateDevices(std::vector<DeviceRef_Dev>* devices, |
| 69 const CompletionCallback& callback); |
| 70 |
| 71 /// If |device_ref| is null (i.e., is_null() returns true), the default device |
| 72 /// will be used. |
| 73 /// In order to maintain backward compatibility, this method doesn't have |
| 74 /// input parameters config, audio_input_callback and user_data. Instead, it |
| 75 /// uses those values stored when the 4-parameter constructor was called. |
| 76 /// |
| 77 /// Note: This method is deprecated. Unless your code has to deal with |
| 78 /// browsers that only support the v0.1 interface, please use the other |
| 79 /// Open(). |
| 80 int32_t Open(const DeviceRef_Dev& device_ref, |
| 81 const CompletionCallback& callback); |
| 82 |
| 83 int32_t Open(const DeviceRef_Dev& device_ref, |
| 84 const AudioConfig& config, |
| 85 PPB_AudioInput_Callback audio_input_callback, |
| 86 void* user_data, |
| 87 const CompletionCallback& callback); |
| 88 |
| 45 bool StartCapture(); | 89 bool StartCapture(); |
| 46 bool StopCapture(); | 90 bool StopCapture(); |
| 91 void Close(); |
| 47 | 92 |
| 48 private: | 93 private: |
| 94 struct EnumerateDevicesState; |
| 95 |
| 96 void AbortEnumerateDevices(); |
| 97 |
| 98 // |user_data| is an EnumerateDevicesState object. It is this method's |
| 99 // responsibility to delete it. |
| 100 static void OnEnumerateDevicesComplete(void* user_data, int32_t result); |
| 101 |
| 49 AudioConfig config_; | 102 AudioConfig config_; |
| 103 |
| 104 // It is set in EnumerateDevices(), and cleared in AbortEnumerateDevices() or |
| 105 // OnEnumerateDevicesComplete(). The object will be deleted by |
| 106 // OnEnumerateDevicesComplete(). |
| 107 EnumerateDevicesState* enum_state_; |
| 108 |
| 109 // Used to store the arguments of Open() for the v0.2 interface. |
| 110 PPB_AudioInput_Callback audio_input_callback_; |
| 111 void* user_data_; |
| 50 }; | 112 }; |
| 51 | 113 |
| 52 } // namespace pp | 114 } // namespace pp |
| 53 | 115 |
| 54 #endif // PPAPI_CPP_DEV_AUDIO_INPUT_DEV_H_ | 116 #endif // PPAPI_CPP_DEV_AUDIO_INPUT_DEV_H_ |
| OLD | NEW |