mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-10 11:35:19 -05:00
d24c8453db
subrepo: subdir: "libultraship" merged: "a484cda98" upstream: origin: "https://github.com/HarbourMasters/libultraship.git" branch: "main" commit: "a484cda98" git-subrepo: version: "0.4.1" origin: "???" commit: "???"
42 lines
1.4 KiB
C++
42 lines
1.4 KiB
C++
#pragma once
|
|
#include "AudioPlayer.h"
|
|
#include <wrl/client.h>
|
|
#include <mmdeviceapi.h>
|
|
#include <audioclient.h>
|
|
|
|
using namespace Microsoft::WRL;
|
|
|
|
namespace Ship {
|
|
class WasapiAudioPlayer : public AudioPlayer, public IMMNotificationClient {
|
|
public:
|
|
WasapiAudioPlayer() : refcount(1), bufferFrameCount(0), initialized(false), started(false) { };
|
|
|
|
bool Init(void);
|
|
int Buffered(void);
|
|
int GetDesiredBuffered(void);
|
|
void Play(const uint8_t* Buffer, uint32_t BufferLen);
|
|
|
|
protected:
|
|
virtual HRESULT STDMETHODCALLTYPE OnDeviceStateChanged(LPCWSTR pwstrDeviceId, DWORD dwNewState);
|
|
virtual HRESULT STDMETHODCALLTYPE OnDeviceAdded(LPCWSTR pwstrDeviceId);
|
|
virtual HRESULT STDMETHODCALLTYPE OnDeviceRemoved(LPCWSTR pwstrDeviceId);
|
|
virtual HRESULT STDMETHODCALLTYPE OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR pwstrDefaultDeviceId);
|
|
virtual HRESULT STDMETHODCALLTYPE OnPropertyValueChanged(LPCWSTR pwstrDeviceId, const PROPERTYKEY key);
|
|
virtual ULONG STDMETHODCALLTYPE AddRef();
|
|
virtual ULONG STDMETHODCALLTYPE Release();
|
|
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, VOID** ppvInterface);
|
|
void ThrowIfFailed(HRESULT res);
|
|
bool SetupStream(void);
|
|
|
|
private:
|
|
ComPtr<IMMDeviceEnumerator> DeviceEnumerator;
|
|
ComPtr<IMMDevice> device;
|
|
ComPtr<IAudioClient> client;
|
|
ComPtr<IAudioRenderClient> rclient;
|
|
LONG refcount;
|
|
UINT32 bufferFrameCount;
|
|
bool initialized;
|
|
bool started;
|
|
};
|
|
}
|