| 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 REMOTING_HOST_AUDIO_CAPTURER_WIN_H_ | 5 #ifndef REMOTING_HOST_AUDIO_CAPTURER_WIN_H_ |
| 6 #define REMOTING_HOST_AUDIO_CAPTURER_WIN_H_ | 6 #define REMOTING_HOST_AUDIO_CAPTURER_WIN_H_ |
| 7 | 7 |
| 8 #include <audioclient.h> | 8 #include <audioclient.h> |
| 9 #include <endpointvolume.h> | 9 #include <endpointvolume.h> |
| 10 #include <mmdeviceapi.h> | 10 #include <mmdeviceapi.h> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 class AudioCapturerWin : public AudioCapturer { | 25 class AudioCapturerWin : public AudioCapturer { |
| 26 public: | 26 public: |
| 27 AudioCapturerWin(); | 27 AudioCapturerWin(); |
| 28 ~AudioCapturerWin() override; | 28 ~AudioCapturerWin() override; |
| 29 | 29 |
| 30 // AudioCapturer interface. | 30 // AudioCapturer interface. |
| 31 bool Start(const PacketCapturedCallback& callback) override; | 31 bool Start(const PacketCapturedCallback& callback) override; |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 // An IMMNotificationClient implementation to detect the event of default |
| 35 // audio device recently changed. If it indicates a changed happend recently, |
| 36 // we need to recreate all audio components. |
| 37 class MMNotificationClient; |
| 38 |
| 39 // Resets and reinitializes default audio device related components. These |
| 40 // components must be recreated once the default audio device changed. Returns |
| 41 // false if initialization failed. |
| 42 bool ResetAndInitialize(); |
| 43 |
| 34 // Receives all packets from the audio capture endpoint buffer and pushes them | 44 // Receives all packets from the audio capture endpoint buffer and pushes them |
| 35 // to the network. | 45 // to the network. |
| 36 void DoCapture(); | 46 void DoCapture(); |
| 37 | 47 |
| 38 // Returns current volume setting of the host, in range [0.0, 1.0]. If the | 48 // Returns current volume setting of the host, in range [0.0, 1.0]. If the |
| 39 // audio has been muted, this function returns 0. If Windows API returns error | 49 // audio has been muted, this function returns 0. If Windows API returns error |
| 40 // (such as audio device has been disabled or unpluged), this function ignores | 50 // (such as audio device has been disabled or unpluged), this function ignores |
| 41 // host volume setting, and returns 1.0. | 51 // host volume setting, and returns 1.0. |
| 42 float GetAudioLevel(); | 52 float GetAudioLevel(); |
| 43 | 53 |
| 44 // Processes a series of samples, and executes callback if the packet is | 54 // Processes a series of samples, and executes callback if the packet is |
| 45 // qualified to be sent to client. | 55 // qualified to be sent to client. |
| 46 void ProcessSamples(uint8_t* data, size_t frames); | 56 void ProcessSamples(uint8_t* data, size_t frames); |
| 47 | 57 |
| 48 PacketCapturedCallback callback_; | 58 PacketCapturedCallback callback_; |
| 49 | 59 |
| 50 AudioPacket::SamplingRate sampling_rate_; | 60 AudioPacket::SamplingRate sampling_rate_; |
| 51 | 61 |
| 52 std::unique_ptr<base::RepeatingTimer> capture_timer_; | 62 std::unique_ptr<base::RepeatingTimer> capture_timer_; |
| 53 base::TimeDelta audio_device_period_; | 63 base::TimeDelta audio_device_period_; |
| 54 | 64 |
| 55 AudioSilenceDetector silence_detector_; | 65 AudioSilenceDetector silence_detector_; |
| 56 | 66 |
| 57 base::win::ScopedCoMem<WAVEFORMATEX> wave_format_ex_; | 67 base::win::ScopedCoMem<WAVEFORMATEX> wave_format_ex_; |
| 68 base::win::ScopedComPtr<IMMDeviceEnumerator> mm_device_enumerator_; |
| 58 base::win::ScopedComPtr<IAudioCaptureClient> audio_capture_client_; | 69 base::win::ScopedComPtr<IAudioCaptureClient> audio_capture_client_; |
| 59 base::win::ScopedComPtr<IAudioClient> audio_client_; | 70 base::win::ScopedComPtr<IAudioClient> audio_client_; |
| 60 base::win::ScopedComPtr<IMMDevice> mm_device_; | 71 base::win::ScopedComPtr<IMMDevice> mm_device_; |
| 61 base::win::ScopedComPtr<IAudioEndpointVolume> audio_volume_; | 72 base::win::ScopedComPtr<IAudioEndpointVolume> audio_volume_; |
| 62 | 73 |
| 74 const std::unique_ptr<MMNotificationClient> mm_notification_client_; |
| 75 |
| 63 HRESULT last_capture_error_; | 76 HRESULT last_capture_error_; |
| 64 | 77 |
| 65 base::ThreadChecker thread_checker_; | 78 base::ThreadChecker thread_checker_; |
| 66 | 79 |
| 67 DISALLOW_COPY_AND_ASSIGN(AudioCapturerWin); | 80 DISALLOW_COPY_AND_ASSIGN(AudioCapturerWin); |
| 68 }; | 81 }; |
| 69 | 82 |
| 70 } // namespace remoting | 83 } // namespace remoting |
| 71 | 84 |
| 72 #endif // REMOTING_HOST_AUDIO_CAPTURER_WIN_H_ | 85 #endif // REMOTING_HOST_AUDIO_CAPTURER_WIN_H_ |
| OLD | NEW |