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_OUTPUT_WIN_H_ 12 #define MODULES_AUDIO_DEVICE_WIN_CORE_AUDIO_OUTPUT_WIN_H_ 13 14 #include <memory> 15 #include <string> 16 17 #include "modules/audio_device/win/audio_device_module_win.h" 18 #include "modules/audio_device/win/core_audio_base_win.h" 19 20 namespace webrtc { 21 22 class AudioDeviceBuffer; 23 class FineAudioBuffer; 24 25 namespace webrtc_win { 26 27 // Windows specific AudioOutput implementation using a CoreAudioBase class where 28 // an output direction is set at construction. Supports render device handling 29 // and streaming of decoded audio from a WebRTC client to the native audio 30 // layer. 31 class CoreAudioOutput final : public CoreAudioBase, public AudioOutput { 32 public: 33 CoreAudioOutput(bool automatic_restart); 34 ~CoreAudioOutput() override; 35 36 // AudioOutput 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 PlayoutIsInitialized() const override; 45 int InitPlayout() override; 46 int StartPlayout() override; 47 int StopPlayout() override; 48 bool Playing() override; 49 int VolumeIsAvailable(bool* available) override; 50 int RestartPlayout() override; 51 bool Restarting() const override; 52 int SetSampleRate(uint32_t sample_rate) override; 53 54 CoreAudioOutput(const CoreAudioOutput&) = delete; 55 CoreAudioOutput& operator=(const CoreAudioOutput&) = delete; 56 57 private: 58 void ReleaseCOMObjects(); 59 bool OnDataCallback(uint64_t device_frequency); 60 bool OnErrorCallback(ErrorType error); 61 int EstimateOutputLatencyMillis(uint64_t device_frequency); 62 bool HandleStreamDisconnected(); 63 64 std::unique_ptr<FineAudioBuffer> fine_audio_buffer_; 65 Microsoft::WRL::ComPtr<IAudioRenderClient> audio_render_client_; 66 uint64_t num_frames_written_ = 0; 67 }; 68 69 } // namespace webrtc_win 70 } // namespace webrtc 71 72 #endif // MODULES_AUDIO_DEVICE_WIN_CORE_AUDIO_OUTPUT_WIN_H_ 73