1 /* 2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_AUDIO_DEVICE_WIN_CORE_AUDIO_INPUT_WIN_H_ 12 #define MODULES_AUDIO_DEVICE_WIN_CORE_AUDIO_INPUT_WIN_H_ 13 14 #include <memory> 15 #include <string> 16 17 #include "absl/types/optional.h" 18 #include "modules/audio_device/win/audio_device_module_win.h" 19 #include "modules/audio_device/win/core_audio_base_win.h" 20 21 namespace webrtc { 22 23 class AudioDeviceBuffer; 24 class FineAudioBuffer; 25 26 namespace webrtc_win { 27 28 // Windows specific AudioInput implementation using a CoreAudioBase class where 29 // an input direction is set at construction. Supports capture device handling 30 // and streaming of captured audio to a WebRTC client. 31 class CoreAudioInput final : public CoreAudioBase, public AudioInput { 32 public: 33 CoreAudioInput(bool automatic_restart); 34 ~CoreAudioInput() override; 35 36 // AudioInput implementation. 37 int Init() override; 38 int Terminate() override; 39 int NumDevices() const override; 40 int SetDevice(int index) override; 41 int SetDevice(AudioDeviceModule::WindowsDeviceType device) override; 42 int DeviceName(int index, std::string* name, std::string* guid) override; 43 void AttachAudioBuffer(AudioDeviceBuffer* audio_buffer) override; 44 bool RecordingIsInitialized() const override; 45 int InitRecording() override; 46 int StartRecording() override; 47 int StopRecording() override; 48 bool Recording() override; 49 int VolumeIsAvailable(bool* available) override; 50 int RestartRecording() override; 51 bool Restarting() const override; 52 int SetSampleRate(uint32_t sample_rate) override; 53 54 CoreAudioInput(const CoreAudioInput&) = delete; 55 CoreAudioInput& operator=(const CoreAudioInput&) = delete; 56 57 private: 58 void ReleaseCOMObjects(); 59 bool OnDataCallback(uint64_t device_frequency); 60 bool OnErrorCallback(ErrorType error); 61 absl::optional<int> EstimateLatencyMillis(uint64_t capture_time_100ns); 62 bool HandleStreamDisconnected(); 63 64 std::unique_ptr<FineAudioBuffer> fine_audio_buffer_; 65 Microsoft::WRL::ComPtr<IAudioCaptureClient> audio_capture_client_; 66 absl::optional<double> qpc_to_100ns_; 67 }; 68 69 } // namespace webrtc_win 70 71 } // namespace webrtc 72 73 #endif // MODULES_AUDIO_DEVICE_WIN_CORE_AUDIO_INPUT_WIN_H_ 74