Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: remoting/host/audio_capturer_win.h

Issue 2163473002: [Chromoting] Audio playback won't work after switching default playback device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve review comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | remoting/host/audio_capturer_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Executes Deinitialize() and Initialize(). If Initialize() function call
40 // returns false, Deinitialize() will be called again to ensure we will
41 // initialize COM components again.
42 bool ResetAndInitialize();
43
44 // Resets all COM components to nullptr, so is_initialized() will return
45 // false.
46 void Deinitialize();
47
48 // Initializes default audio device related components. These components must
49 // be recreated once the default audio device changed. Returns false if
50 // initialization failed.
51 bool Initialize();
52
53 // Whether all components are correctly initialized. If last
54 // Initialize() function call failed, this function will return false.
55 // Otherwise this function will return true.
56 bool is_initialized() const;
57
34 // Receives all packets from the audio capture endpoint buffer and pushes them 58 // Receives all packets from the audio capture endpoint buffer and pushes them
35 // to the network. 59 // to the network.
36 void DoCapture(); 60 void DoCapture();
37 61
38 // Returns current volume setting of the host, in range [0.0, 1.0]. If the 62 // 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 63 // 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 64 // (such as audio device has been disabled or unpluged), this function ignores
41 // host volume setting, and returns 1.0. 65 // host volume setting, and returns 1.0.
42 float GetAudioLevel(); 66 float GetAudioLevel();
43 67
44 // Processes a series of samples, and executes callback if the packet is 68 // Processes a series of samples, and executes callback if the packet is
45 // qualified to be sent to client. 69 // qualified to be sent to client.
46 void ProcessSamples(uint8_t* data, size_t frames); 70 void ProcessSamples(uint8_t* data, size_t frames);
47 71
48 PacketCapturedCallback callback_; 72 PacketCapturedCallback callback_;
49 73
50 AudioPacket::SamplingRate sampling_rate_; 74 AudioPacket::SamplingRate sampling_rate_;
51 75
52 std::unique_ptr<base::RepeatingTimer> capture_timer_; 76 std::unique_ptr<base::RepeatingTimer> capture_timer_;
53 base::TimeDelta audio_device_period_; 77 base::TimeDelta audio_device_period_;
54 78
55 AudioSilenceDetector silence_detector_; 79 AudioSilenceDetector silence_detector_;
56 80
57 base::win::ScopedCoMem<WAVEFORMATEX> wave_format_ex_; 81 base::win::ScopedCoMem<WAVEFORMATEX> wave_format_ex_;
82 base::win::ScopedComPtr<IMMDeviceEnumerator> mm_device_enumerator_;
58 base::win::ScopedComPtr<IAudioCaptureClient> audio_capture_client_; 83 base::win::ScopedComPtr<IAudioCaptureClient> audio_capture_client_;
59 base::win::ScopedComPtr<IAudioClient> audio_client_; 84 base::win::ScopedComPtr<IAudioClient> audio_client_;
60 base::win::ScopedComPtr<IMMDevice> mm_device_; 85 base::win::ScopedComPtr<IMMDevice> mm_device_;
61 base::win::ScopedComPtr<IAudioEndpointVolume> audio_volume_; 86 base::win::ScopedComPtr<IAudioEndpointVolume> audio_volume_;
62 87
88 const std::unique_ptr<MMNotificationClient> mm_notification_client_;
89
63 HRESULT last_capture_error_; 90 HRESULT last_capture_error_;
64 91
65 base::ThreadChecker thread_checker_; 92 base::ThreadChecker thread_checker_;
66 93
67 DISALLOW_COPY_AND_ASSIGN(AudioCapturerWin); 94 DISALLOW_COPY_AND_ASSIGN(AudioCapturerWin);
68 }; 95 };
69 96
70 } // namespace remoting 97 } // namespace remoting
71 98
72 #endif // REMOTING_HOST_AUDIO_CAPTURER_WIN_H_ 99 #endif // REMOTING_HOST_AUDIO_CAPTURER_WIN_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/host/audio_capturer_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698