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