NVDA Helper
In-process and lite high-speed utilities for NVDA
|
#include <thread>
#include <vector>
#include <windows.h>
#include <atlbase.h>
#include <atlcomcli.h>
#include <audioclient.h>
#include <audiopolicy.h>
#include <functiondiscoverykeys.h>
#include <Functiondiscoverykeys_devpkey.h>
#include <mmdeviceapi.h>
#include <common/log.h>
#include <random>
Go to the source code of this file.
Classes | |
class | AutoHandle |
C++ RAII class to manage the lifecycle of a standard Windows HANDLE closed with CloseHandle. More... | |
class | NotificationClient |
Listens for default device changes and device state changes. More... | |
class | WasapiPlayer |
Play a stream of audio using WASAPI. More... | |
class | SilencePlayer |
Asynchronously play silence for requested durations. More... | |
Functions | |
WasapiPlayer * | wasPlay_create (wchar_t *deviceName, WAVEFORMATEX format, WasapiPlayer::ChunkCompletedCallback callback) |
void | wasPlay_destroy (WasapiPlayer *player) |
HRESULT | wasPlay_open (WasapiPlayer *player) |
HRESULT | wasPlay_feed (WasapiPlayer *player, unsigned char *data, unsigned int size, unsigned int *id) |
HRESULT | wasPlay_stop (WasapiPlayer *player) |
HRESULT | wasPlay_sync (WasapiPlayer *player) |
HRESULT | wasPlay_idle (WasapiPlayer *player) |
HRESULT | wasPlay_pause (WasapiPlayer *player) |
HRESULT | wasPlay_resume (WasapiPlayer *player) |
HRESULT | wasPlay_setChannelVolume (WasapiPlayer *player, unsigned int channel, float level) |
HRESULT | wasPlay_startup () |
This must be called once per session at startup before wasPlay_create is called. | |
HRESULT | wasSilence_init (wchar_t *deviceName) |
void | wasSilence_playFor (DWORD ms, float volume) |
void | wasSilence_terminate () |
Variables | |
constexpr REFERENCE_TIME | REFTIMES_PER_MILLISEC = 10000 |
Support for audio playback using WASAPI. | |
constexpr DWORD | BUFFER_MS = 400 |
constexpr REFERENCE_TIME | BUFFER_SIZE = BUFFER_MS * REFTIMES_PER_MILLISEC |
const CLSID | CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator) |
const IID | IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator) |
const IID | IID_IAudioClient = __uuidof(IAudioClient) |
const IID | IID_IAudioRenderClient = __uuidof(IAudioRenderClient) |
const IID | IID_IAudioClock = __uuidof(IAudioClock) |
const IID | IID_IMMNotificationClient = __uuidof(IMMNotificationClient) |
const IID | IID_IAudioStreamVolume = __uuidof(IAudioStreamVolume) |
CComPtr< NotificationClient > | notificationClient |
SilencePlayer * | silence = nullptr |
WasapiPlayer * wasPlay_create | ( | wchar_t * | deviceName, |
WAVEFORMATEX | format, | ||
WasapiPlayer::ChunkCompletedCallback | callback ) |
void wasPlay_destroy | ( | WasapiPlayer * | player | ) |
HRESULT wasPlay_open | ( | WasapiPlayer * | player | ) |
References WasapiPlayer::open().
HRESULT wasPlay_feed | ( | WasapiPlayer * | player, |
unsigned char * | data, | ||
unsigned int | size, | ||
unsigned int * | id ) |
References WasapiPlayer::feed().
HRESULT wasPlay_stop | ( | WasapiPlayer * | player | ) |
References WasapiPlayer::stop().
HRESULT wasPlay_sync | ( | WasapiPlayer * | player | ) |
References WasapiPlayer::sync().
HRESULT wasPlay_idle | ( | WasapiPlayer * | player | ) |
References WasapiPlayer::idle().
HRESULT wasPlay_pause | ( | WasapiPlayer * | player | ) |
References WasapiPlayer::pause().
HRESULT wasPlay_resume | ( | WasapiPlayer * | player | ) |
References WasapiPlayer::resume().
HRESULT wasPlay_setChannelVolume | ( | WasapiPlayer * | player, |
unsigned int | channel, | ||
float | level ) |
References WasapiPlayer::setChannelVolume().
HRESULT wasPlay_startup | ( | ) |
This must be called once per session at startup before wasPlay_create is called.
References CLSID_MMDeviceEnumerator, HRESULT(), and notificationClient.
HRESULT wasSilence_init | ( | wchar_t * | deviceName | ) |
References SilencePlayer::init(), and silence.
void wasSilence_playFor | ( | DWORD | ms, |
float | volume ) |
References SilencePlayer::playFor(), and silence.
void wasSilence_terminate | ( | ) |
References silence, and SilencePlayer::terminate().
|
constexpr |
Support for audio playback using WASAPI.
Most of the core work happens in the WasapiPlayer class. Because Python ctypes can't call C++ classes, NVDA interfaces with this using the wasPlay_* and wasSilence_* functions.
|
constexpr |
|
constexpr |
Referenced by WasapiPlayer::open().
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator) |
Referenced by WasapiPlayer::open(), and wasPlay_startup().
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator) |
const IID IID_IAudioClient = __uuidof(IAudioClient) |
Referenced by WasapiPlayer::open().
const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient) |
Referenced by WasapiPlayer::open().
const IID IID_IAudioClock = __uuidof(IAudioClock) |
Referenced by WasapiPlayer::open().
const IID IID_IMMNotificationClient = __uuidof(IMMNotificationClient) |
Referenced by NotificationClient::QueryInterface().
const IID IID_IAudioStreamVolume = __uuidof(IAudioStreamVolume) |
Referenced by WasapiPlayer::setChannelVolume().
CComPtr<NotificationClient> notificationClient |
Referenced by WasapiPlayer::feed(), WasapiPlayer::open(), and wasPlay_startup().
SilencePlayer* silence = nullptr |
Referenced by wasSilence_init(), wasSilence_playFor(), and wasSilence_terminate().