| 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> |
| 11 | 11 |
| 12 #include <memory> | 12 #include <memory> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 17 #include "base/win/scoped_co_mem.h" | 17 #include "base/win/scoped_co_mem.h" |
| 18 #include "base/win/scoped_comptr.h" | 18 #include "base/win/scoped_comptr.h" |
| 19 #include "remoting/host/audio_capturer.h" | 19 #include "remoting/host/audio_capturer.h" |
| 20 #include "remoting/host/audio_silence_detector.h" | 20 #include "remoting/host/audio_silence_detector.h" |
| 21 #include "remoting/proto/audio.pb.h" | 21 #include "remoting/proto/audio.pb.h" |
| 22 | 22 |
| 23 namespace remoting { | 23 namespace remoting { |
| 24 | 24 |
| 25 class DefaultAudioDeviceChangeDetector; |
| 26 |
| 25 class AudioCapturerWin : public AudioCapturer { | 27 class AudioCapturerWin : public AudioCapturer { |
| 26 public: | 28 public: |
| 27 AudioCapturerWin(); | 29 AudioCapturerWin(); |
| 28 ~AudioCapturerWin() override; | 30 ~AudioCapturerWin() override; |
| 29 | 31 |
| 30 // AudioCapturer interface. | 32 // AudioCapturer interface. |
| 31 bool Start(const PacketCapturedCallback& callback) override; | 33 bool Start(const PacketCapturedCallback& callback) override; |
| 32 | 34 |
| 33 private: | 35 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 // Executes Deinitialize() and Initialize(). If Initialize() function call | 36 // Executes Deinitialize() and Initialize(). If Initialize() function call |
| 40 // returns false, Deinitialize() will be called again to ensure we will | 37 // returns false, Deinitialize() will be called again to ensure we will |
| 41 // initialize COM components again. | 38 // initialize COM components again. |
| 42 bool ResetAndInitialize(); | 39 bool ResetAndInitialize(); |
| 43 | 40 |
| 44 // Resets all COM components to nullptr, so is_initialized() will return | 41 // Resets all COM components to nullptr, so is_initialized() will return |
| 45 // false. | 42 // false. |
| 46 void Deinitialize(); | 43 void Deinitialize(); |
| 47 | 44 |
| 48 // Initializes default audio device related components. These components must | 45 // Initializes default audio device related components. These components must |
| (...skipping 23 matching lines...) Expand all Loading... |
| 72 PacketCapturedCallback callback_; | 69 PacketCapturedCallback callback_; |
| 73 | 70 |
| 74 AudioPacket::SamplingRate sampling_rate_; | 71 AudioPacket::SamplingRate sampling_rate_; |
| 75 | 72 |
| 76 std::unique_ptr<base::RepeatingTimer> capture_timer_; | 73 std::unique_ptr<base::RepeatingTimer> capture_timer_; |
| 77 base::TimeDelta audio_device_period_; | 74 base::TimeDelta audio_device_period_; |
| 78 | 75 |
| 79 AudioSilenceDetector silence_detector_; | 76 AudioSilenceDetector silence_detector_; |
| 80 | 77 |
| 81 base::win::ScopedCoMem<WAVEFORMATEX> wave_format_ex_; | 78 base::win::ScopedCoMem<WAVEFORMATEX> wave_format_ex_; |
| 82 base::win::ScopedComPtr<IMMDeviceEnumerator> mm_device_enumerator_; | |
| 83 base::win::ScopedComPtr<IAudioCaptureClient> audio_capture_client_; | 79 base::win::ScopedComPtr<IAudioCaptureClient> audio_capture_client_; |
| 84 base::win::ScopedComPtr<IAudioClient> audio_client_; | 80 base::win::ScopedComPtr<IAudioClient> audio_client_; |
| 85 base::win::ScopedComPtr<IMMDevice> mm_device_; | 81 base::win::ScopedComPtr<IMMDevice> mm_device_; |
| 86 base::win::ScopedComPtr<IAudioEndpointVolume> audio_volume_; | 82 base::win::ScopedComPtr<IAudioEndpointVolume> audio_volume_; |
| 87 | 83 |
| 88 const std::unique_ptr<MMNotificationClient> mm_notification_client_; | 84 std::unique_ptr<DefaultAudioDeviceChangeDetector> default_device_detector_; |
| 89 | 85 |
| 90 HRESULT last_capture_error_; | 86 HRESULT last_capture_error_; |
| 91 | 87 |
| 92 base::ThreadChecker thread_checker_; | 88 base::ThreadChecker thread_checker_; |
| 93 | 89 |
| 94 DISALLOW_COPY_AND_ASSIGN(AudioCapturerWin); | 90 DISALLOW_COPY_AND_ASSIGN(AudioCapturerWin); |
| 95 }; | 91 }; |
| 96 | 92 |
| 97 } // namespace remoting | 93 } // namespace remoting |
| 98 | 94 |
| 99 #endif // REMOTING_HOST_AUDIO_CAPTURER_WIN_H_ | 95 #endif // REMOTING_HOST_AUDIO_CAPTURER_WIN_H_ |
| OLD | NEW |