[WASAPI] set stream audio category
[xbmc.git] / xbmc / cores / AudioEngine / Sinks / AESinkWASAPI.h
blob340641cae29ab4d2f12e96c247775263b49d4958
1 /*
2 * Copyright (C) 2010-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "cores/AudioEngine/Interfaces/AESink.h"
12 #include "cores/AudioEngine/Sinks/windows/AESinkFactoryWin.h"
13 #include "cores/AudioEngine/Utils/AEDeviceInfo.h"
15 #include <stdint.h>
16 #include <vector>
18 #include <Audioclient.h>
19 #include <mmdeviceapi.h>
20 #include <wrl/client.h>
22 class CAESinkWASAPI : public IAESink
24 public:
25 CAESinkWASAPI();
26 virtual ~CAESinkWASAPI();
28 static void Register();
29 static std::unique_ptr<IAESink> Create(std::string& device, AEAudioFormat& desiredFormat);
30 static void EnumerateDevicesEx(AEDeviceInfoList &deviceInfoList, bool force = false);
32 // IAESink overrides
33 const char *GetName() override { return "WASAPI"; }
34 bool Initialize(AEAudioFormat &format, std::string &device) override;
35 void Deinitialize() override;
36 void GetDelay(AEDelayStatus& status) override;
37 double GetCacheTotal() override;
38 unsigned int AddPackets(uint8_t **data, unsigned int frames, unsigned int offset) override;
39 void Drain() override;
41 private:
42 bool InitializeExclusive(AEAudioFormat &format);
43 static void BuildWaveFormatExtensibleIEC61397(AEAudioFormat &format, WAVEFORMATEXTENSIBLE_IEC61937 &wfxex);
44 bool IsUSBDevice();
46 HANDLE m_needDataEvent{0};
47 IAEWASAPIDevice* m_pDevice{nullptr};
48 Microsoft::WRL::ComPtr<IAudioClient> m_pAudioClient;
49 Microsoft::WRL::ComPtr<IAudioRenderClient> m_pRenderClient;
50 Microsoft::WRL::ComPtr<IAudioClock> m_pAudioClock;
52 AEAudioFormat m_format{};
53 unsigned int m_encodedChannels{0};
54 unsigned int m_encodedSampleRate{0};
55 CAEChannelInfo m_channelLayout;
56 std::string m_device;
58 enum AEDataFormat sinkReqFormat = AE_FMT_INVALID;
59 enum AEDataFormat sinkRetFormat = AE_FMT_INVALID;
61 bool m_running{false};
62 bool m_initialized{false};
63 bool m_isSuspended{false}; // sink is in a suspended state - release audio device
64 bool m_isDirty{false}; // sink output failed - needs re-init or new device
66 // time between next buffer of data from SoftAE and driver call for data
67 double m_avgTimeWaiting{50.0};
68 double m_sinkLatency{0.0}; // time in seconds of total duration of the two WASAPI buffers
70 unsigned int m_uiBufferLen{0}; // wasapi endpoint buffer size, in frames
71 uint64_t m_sinkFrames{0};
72 uint64_t m_clockFreq{0};
74 std::vector<uint8_t> m_buffer;
75 int m_bufferPtr{0};