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

Side by Side Diff: media/audio/win/audio_low_latency_input_win.h

Issue 2680873002: Add UMA stats for open and fix memory leak (Closed)
Patch Set: Fix strange git cl format issue Created 3 years, 10 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
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 // Implementation of AudioInputStream for Windows using Windows Core Audio 5 // Implementation of AudioInputStream for Windows using Windows Core Audio
6 // WASAPI for low latency capturing. 6 // WASAPI for low latency capturing.
7 // 7 //
8 // Overview of operation: 8 // Overview of operation:
9 // 9 //
10 // - An object of WASAPIAudioInputStream is created by the AudioManager 10 // - An object of WASAPIAudioInputStream is created by the AudioManager
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // per-session basis. It is also possible to use of the IAudioEndpointVolume 50 // per-session basis. It is also possible to use of the IAudioEndpointVolume
51 // interface to control the master volume level of an audio endpoint device. 51 // interface to control the master volume level of an audio endpoint device.
52 // This implementation is using the ISimpleAudioVolume interface. 52 // This implementation is using the ISimpleAudioVolume interface.
53 // MSDN states that "In rare cases, a specialized audio application might 53 // MSDN states that "In rare cases, a specialized audio application might
54 // require the use of the IAudioEndpointVolume". 54 // require the use of the IAudioEndpointVolume".
55 // 55 //
56 #ifndef MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ 56 #ifndef MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_
57 #define MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ 57 #define MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_
58 58
59 #include <Audioclient.h> 59 #include <Audioclient.h>
60 #include <MMDeviceAPI.h>
60 #include <endpointvolume.h> 61 #include <endpointvolume.h>
61 #include <MMDeviceAPI.h>
62 #include <stddef.h> 62 #include <stddef.h>
63 #include <stdint.h> 63 #include <stdint.h>
64 64
65 #include <memory> 65 #include <memory>
66 #include <string> 66 #include <string>
67 67
68 #include "base/compiler_specific.h" 68 #include "base/compiler_specific.h"
69 #include "base/macros.h" 69 #include "base/macros.h"
70 #include "base/threading/non_thread_safe.h" 70 #include "base/threading/non_thread_safe.h"
71 #include "base/threading/platform_thread.h" 71 #include "base/threading/platform_thread.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 private: 114 private:
115 // DelegateSimpleThread::Delegate implementation. 115 // DelegateSimpleThread::Delegate implementation.
116 void Run() override; 116 void Run() override;
117 117
118 // Issues the OnError() callback to the |sink_|. 118 // Issues the OnError() callback to the |sink_|.
119 void HandleError(HRESULT err); 119 void HandleError(HRESULT err);
120 120
121 // The Open() method is divided into these sub methods. 121 // The Open() method is divided into these sub methods.
122 HRESULT SetCaptureDevice(); 122 HRESULT SetCaptureDevice();
123 HRESULT ActivateCaptureDevice();
124 HRESULT GetAudioEngineStreamFormat(); 123 HRESULT GetAudioEngineStreamFormat();
125 bool DesiredFormatIsSupported(); 124 bool DesiredFormatIsSupported();
126 HRESULT InitializeAudioEngine(); 125 HRESULT InitializeAudioEngine();
126 void ReportOpenResult() const;
127
128 // Used to track down where we fail during initialization which at the
129 // moment seems to be happening frequently and we're not sure why.
130 // The reason might be expected (e.g. trying to open "default" on a machine
131 // that has no audio devices).
jwd 2017/02/09 16:04:07 Mention this enum is used to record a histogram va
tommi (sloooow) - chröme 2017/02/09 16:31:37 Done.
132 enum StreamOpenResult {
133 OPEN_RESULT_OK = 0,
134 OPEN_RESULT_CREATE_INSTANCE = 1,
135 OPEN_RESULT_NO_ENDPOINT = 2,
136 OPEN_RESULT_NO_STATE = 3,
137 OPEN_RESULT_DEVICE_NOT_ACTIVE = 4,
138 OPEN_RESULT_ACTIVATION_FAILED = 5,
139 OPEN_RESULT_FORMAT_NOT_SUPPORTED = 6,
140 OPEN_RESULT_AUDIO_CLIENT_INIT_FAILED = 7,
141 OPEN_RESULT_GET_BUFFER_SIZE_FAILED = 8,
142 OPEN_RESULT_LOOPBACK_ACTIVATE_FAILED = 9,
143 OPEN_RESULT_LOOPBACK_INIT_FAILED = 10,
144 OPEN_RESULT_SET_EVENT_HANDLE = 11,
145 OPEN_RESULT_NO_CAPTURE_CLIENT = 12,
146 OPEN_RESULT_NO_AUDIO_VOLUME = 13,
147 OPEN_RESULT_MAX = OPEN_RESULT_NO_AUDIO_VOLUME
148 };
127 149
128 // Our creator, the audio manager needs to be notified when we close. 150 // Our creator, the audio manager needs to be notified when we close.
129 AudioManagerWin* manager_; 151 AudioManagerWin* const manager_;
130 152
131 // Capturing is driven by this thread (which has no message loop). 153 // Capturing is driven by this thread (which has no message loop).
132 // All OnData() callbacks will be called from this thread. 154 // All OnData() callbacks will be called from this thread.
133 base::DelegateSimpleThread* capture_thread_; 155 std::unique_ptr<base::DelegateSimpleThread> capture_thread_;
134 156
135 // Contains the desired audio format which is set up at construction. 157 // Contains the desired audio format which is set up at construction.
136 WAVEFORMATEX format_; 158 WAVEFORMATEX format_;
137 159
138 bool opened_; 160 bool opened_ = false;
139 bool started_; 161 bool started_ = false;
162 StreamOpenResult open_result_ = OPEN_RESULT_OK;
140 163
141 // Size in bytes of each audio frame (4 bytes for 16-bit stereo PCM) 164 // Size in bytes of each audio frame (4 bytes for 16-bit stereo PCM)
142 size_t frame_size_; 165 size_t frame_size_ = 0;
143 166
144 // Size in audio frames of each audio packet where an audio packet 167 // Size in audio frames of each audio packet where an audio packet
145 // is defined as the block of data which the user received in each 168 // is defined as the block of data which the user received in each
146 // OnData() callback. 169 // OnData() callback.
147 size_t packet_size_frames_; 170 size_t packet_size_frames_ = 0;
148 171
149 // Size in bytes of each audio packet. 172 // Size in bytes of each audio packet.
150 size_t packet_size_bytes_; 173 size_t packet_size_bytes_ = 0;
151 174
152 // Length of the audio endpoint buffer. 175 // Length of the audio endpoint buffer.
153 uint32_t endpoint_buffer_size_frames_; 176 uint32_t endpoint_buffer_size_frames_ = 0;
154 177
155 // Contains the unique name of the selected endpoint device. 178 // Contains the unique name of the selected endpoint device.
156 // Note that AudioDeviceDescription::kDefaultDeviceId represents the default 179 // Note that AudioDeviceDescription::kDefaultDeviceId represents the default
157 // device role and is not a valid ID as such. 180 // device role and is not a valid ID as such.
158 std::string device_id_; 181 std::string device_id_;
159 182
160 // Conversion factor used in delay-estimation calculations. 183 // Conversion factor used in delay-estimation calculations.
161 // Converts a raw performance counter value to 100-nanosecond unit. 184 // Converts a raw performance counter value to 100-nanosecond unit.
162 double perf_count_to_100ns_units_; 185 double perf_count_to_100ns_units_ = 0.0;
163 186
164 // Conversion factor used in delay-estimation calculations. 187 // Conversion factor used in delay-estimation calculations.
165 // Converts from milliseconds to audio frames. 188 // Converts from milliseconds to audio frames.
166 double ms_to_frame_count_; 189 double ms_to_frame_count_ = 0.0;
167 190
168 // Pointer to the object that will receive the recorded audio samples. 191 // Pointer to the object that will receive the recorded audio samples.
169 AudioInputCallback* sink_; 192 AudioInputCallback* sink_ = nullptr;
170 193
171 // Windows Multimedia Device (MMDevice) API interfaces. 194 // Windows Multimedia Device (MMDevice) API interfaces.
172 195
173 // An IMMDevice interface which represents an audio endpoint device. 196 // An IMMDevice interface which represents an audio endpoint device.
174 base::win::ScopedComPtr<IMMDevice> endpoint_device_; 197 base::win::ScopedComPtr<IMMDevice> endpoint_device_;
175 198
176 // Windows Audio Session API (WASAPI) interfaces. 199 // Windows Audio Session API (WASAPI) interfaces.
177 200
178 // An IAudioClient interface which enables a client to create and initialize 201 // An IAudioClient interface which enables a client to create and initialize
179 // an audio stream between an audio application and the audio engine. 202 // an audio stream between an audio application and the audio engine.
(...skipping 29 matching lines...) Expand all
209 base::win::ScopedHandle stop_capture_event_; 232 base::win::ScopedHandle stop_capture_event_;
210 233
211 // Extra audio bus used for storage of deinterleaved data for the OnData 234 // Extra audio bus used for storage of deinterleaved data for the OnData
212 // callback. 235 // callback.
213 std::unique_ptr<media::AudioBus> audio_bus_; 236 std::unique_ptr<media::AudioBus> audio_bus_;
214 237
215 // Never set it through external API. Only used when |device_id_| == 238 // Never set it through external API. Only used when |device_id_| ==
216 // kLoopbackWithMuteDeviceId. 239 // kLoopbackWithMuteDeviceId.
217 // True, if we have muted the system audio for the stream capturing, and 240 // True, if we have muted the system audio for the stream capturing, and
218 // indicates that we need to unmute the system audio when stopping capturing. 241 // indicates that we need to unmute the system audio when stopping capturing.
219 bool mute_done_; 242 bool mute_done_ = false;
220 243
221 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioInputStream); 244 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioInputStream);
222 }; 245 };
223 246
224 } // namespace media 247 } // namespace media
225 248
226 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ 249 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_
OLDNEW
« no previous file with comments | « no previous file | media/audio/win/audio_low_latency_input_win.cc » ('j') | media/audio/win/audio_low_latency_input_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698