Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 | 71 |
| 72 // AudioInputStream implementation using Windows Core Audio APIs. | 72 // AudioInputStream implementation using Windows Core Audio APIs. |
| 73 class MEDIA_EXPORT WASAPIAudioInputStream | 73 class MEDIA_EXPORT WASAPIAudioInputStream |
| 74 : public AudioInputStream, | 74 : public AudioInputStream, |
| 75 public base::DelegateSimpleThread::Delegate { | 75 public base::DelegateSimpleThread::Delegate { |
| 76 public: | 76 public: |
| 77 // The ctor takes all the usual parameters, plus |manager| which is the | 77 // The ctor takes all the usual parameters, plus |manager| which is the |
| 78 // the audio manager who is creating this object. | 78 // the audio manager who is creating this object. |
| 79 WASAPIAudioInputStream(AudioManagerWin* manager, | 79 WASAPIAudioInputStream(AudioManagerWin* manager, |
| 80 const AudioParameters& params, | 80 const AudioParameters& params, |
| 81 ERole device_role); | 81 const std::string& device_id); |
| 82 // The dtor is typically called by the AudioManager only and it is usually | 82 // The dtor is typically called by the AudioManager only and it is usually |
| 83 // triggered by calling AudioInputStream::Close(). | 83 // triggered by calling AudioInputStream::Close(). |
| 84 virtual ~WASAPIAudioInputStream(); | 84 virtual ~WASAPIAudioInputStream(); |
| 85 | 85 |
| 86 // Implementation of AudioInputStream. | 86 // Implementation of AudioInputStream. |
| 87 virtual bool Open() OVERRIDE; | 87 virtual bool Open() OVERRIDE; |
| 88 virtual void Start(AudioInputCallback* callback) OVERRIDE; | 88 virtual void Start(AudioInputCallback* callback) OVERRIDE; |
| 89 virtual void Stop() OVERRIDE; | 89 virtual void Stop() OVERRIDE; |
| 90 virtual void Close() OVERRIDE; | 90 virtual void Close() OVERRIDE; |
| 91 | 91 |
| 92 // Retrieves the stream format that the audio engine uses for its internal | 92 // Retrieves the stream format that the audio engine uses for its internal |
| 93 // processing/mixing of shared-mode streams. | 93 // processing/mixing of shared-mode streams. |
| 94 static double HardwareSampleRate(ERole device_role); | 94 static double HardwareSampleRate(ERole device_role); |
| 95 | 95 |
| 96 bool started() const { return started_; } | 96 bool started() const { return started_; } |
| 97 | 97 |
| 98 private: | 98 private: |
| 99 // DelegateSimpleThread::Delegate implementation. | 99 // DelegateSimpleThread::Delegate implementation. |
| 100 virtual void Run() OVERRIDE; | 100 virtual void Run() OVERRIDE; |
| 101 | 101 |
| 102 // Issues the OnError() callback to the |sink_|. | 102 // Issues the OnError() callback to the |sink_|. |
| 103 void HandleError(HRESULT err); | 103 void HandleError(HRESULT err); |
| 104 | 104 |
| 105 // The Open() method is divided into these sub methods. | 105 // The Open() method is divided into these sub methods. |
| 106 HRESULT SetCaptureDevice(ERole device_role); | 106 HRESULT SetCaptureDevice(const std::string& device_id); |
|
tommi (sloooow) - chröme
2011/12/01 14:11:03
if the device_id has already been handed to the cl
henrika (OOO until Aug 14)
2011/12/01 16:02:38
Done.
| |
| 107 HRESULT ActivateCaptureDevice(); | 107 HRESULT ActivateCaptureDevice(); |
| 108 HRESULT GetAudioEngineStreamFormat(); | 108 HRESULT GetAudioEngineStreamFormat(); |
| 109 bool DesiredFormatIsSupported(); | 109 bool DesiredFormatIsSupported(); |
| 110 HRESULT InitializeAudioEngine(); | 110 HRESULT InitializeAudioEngine(); |
| 111 | 111 |
| 112 // Initializes the COM library for use by the calling thread and set the | 112 // Initializes the COM library for use by the calling thread and set the |
| 113 // thread's concurrency model to multi-threaded. | 113 // thread's concurrency model to multi-threaded. |
| 114 base::win::ScopedCOMInitializer com_init_; | 114 base::win::ScopedCOMInitializer com_init_; |
| 115 | 115 |
| 116 // Our creator, the audio manager needs to be notified when we close. | 116 // Our creator, the audio manager needs to be notified when we close. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 138 // is defined as the block of data which the user received in each | 138 // is defined as the block of data which the user received in each |
| 139 // OnData() callback. | 139 // OnData() callback. |
| 140 size_t packet_size_frames_; | 140 size_t packet_size_frames_; |
| 141 | 141 |
| 142 // Size in bytes of each audio packet. | 142 // Size in bytes of each audio packet. |
| 143 size_t packet_size_bytes_; | 143 size_t packet_size_bytes_; |
| 144 | 144 |
| 145 // Length of the audio endpoint buffer. | 145 // Length of the audio endpoint buffer. |
| 146 size_t endpoint_buffer_size_frames_; | 146 size_t endpoint_buffer_size_frames_; |
| 147 | 147 |
| 148 // Defines the role that the system has assigned to an audio endpoint device. | 148 // Contains the unique name of the selected endpoint device. |
| 149 ERole device_role_; | 149 // Note that AudioManagerBase::kDefaultDeviceId represents the default |
| 150 // device role and is not a valid ID as such. | |
| 151 std::string device_id_; | |
| 150 | 152 |
| 151 // Conversion factor used in delay-estimation calculations. | 153 // Conversion factor used in delay-estimation calculations. |
| 152 // Converts a raw performance counter value to 100-nanosecond unit. | 154 // Converts a raw performance counter value to 100-nanosecond unit. |
| 153 double perf_count_to_100ns_units_; | 155 double perf_count_to_100ns_units_; |
| 154 | 156 |
| 155 // Conversion factor used in delay-estimation calculations. | 157 // Conversion factor used in delay-estimation calculations. |
| 156 // Converts from milliseconds to audio frames. | 158 // Converts from milliseconds to audio frames. |
| 157 double ms_to_frame_count_; | 159 double ms_to_frame_count_; |
| 158 | 160 |
| 159 // Pointer to the object that will receive the recorded audio samples. | 161 // Pointer to the object that will receive the recorded audio samples. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 174 // recorded. | 176 // recorded. |
| 175 base::win::ScopedHandle audio_samples_ready_event_; | 177 base::win::ScopedHandle audio_samples_ready_event_; |
| 176 | 178 |
| 177 // This event will be signaled when capturing shall stop. | 179 // This event will be signaled when capturing shall stop. |
| 178 base::win::ScopedHandle stop_capture_event_; | 180 base::win::ScopedHandle stop_capture_event_; |
| 179 | 181 |
| 180 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioInputStream); | 182 DISALLOW_COPY_AND_ASSIGN(WASAPIAudioInputStream); |
| 181 }; | 183 }; |
| 182 | 184 |
| 183 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ | 185 #endif // MEDIA_AUDIO_WIN_AUDIO_LOW_LATENCY_INPUT_WIN_H_ |
| OLD | NEW |