2017-05-04 23:44:23 +02:00
|
|
|
//
|
|
|
|
// libtgvoip is free and unencumbered public domain software.
|
|
|
|
// For more information, see http://unlicense.org or the UNLICENSE file
|
|
|
|
// you should have received with this source code distribution.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef LIBTGVOIP_AUDIOINPUTWASAPI_H
|
|
|
|
#define LIBTGVOIP_AUDIOINPUTWASAPI_H
|
|
|
|
|
2017-05-10 01:28:20 +02:00
|
|
|
#if WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP
|
|
|
|
#define TGVOIP_WINDOWS_PHONE
|
|
|
|
#endif
|
|
|
|
#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY==WINAPI_FAMILY_DESKTOP_APP
|
|
|
|
#define TGVOIP_WINDOWS_DESKTOP
|
|
|
|
#endif
|
|
|
|
|
2017-05-04 23:44:23 +02:00
|
|
|
#include <windows.h>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4201)
|
2017-06-06 03:44:16 +02:00
|
|
|
#ifndef TGVOIP_WP_SILVERLIGHT
|
2017-05-04 23:44:23 +02:00
|
|
|
#include <mmdeviceapi.h>
|
2017-06-06 03:44:16 +02:00
|
|
|
#endif
|
2017-05-10 01:28:20 +02:00
|
|
|
#ifdef TGVOIP_WINDOWS_DESKTOP
|
2017-05-04 23:44:23 +02:00
|
|
|
#include <audiopolicy.h>
|
2017-05-10 01:28:20 +02:00
|
|
|
#include <functiondiscoverykeys.h>
|
|
|
|
#else
|
|
|
|
#include <audioclient.h>
|
|
|
|
#include "WindowsSandboxUtils.h"
|
|
|
|
#endif
|
2017-05-04 23:44:23 +02:00
|
|
|
#pragma warning(pop)
|
|
|
|
#include "../../audio/AudioInput.h"
|
|
|
|
|
|
|
|
namespace tgvoip{
|
|
|
|
namespace audio{
|
|
|
|
|
2017-05-10 01:28:20 +02:00
|
|
|
#ifdef TGVOIP_WINDOWS_DESKTOP
|
2017-05-04 23:44:23 +02:00
|
|
|
class AudioInputWASAPI : public AudioInput, IMMNotificationClient, IAudioSessionEvents{
|
2017-05-10 01:28:20 +02:00
|
|
|
#else
|
|
|
|
class AudioInputWASAPI : public AudioInput{
|
|
|
|
#endif
|
|
|
|
|
2017-05-04 23:44:23 +02:00
|
|
|
public:
|
|
|
|
AudioInputWASAPI(std::string deviceID);
|
|
|
|
virtual ~AudioInputWASAPI();
|
|
|
|
virtual void Start();
|
|
|
|
virtual void Stop();
|
|
|
|
virtual bool IsRecording();
|
|
|
|
virtual void SetCurrentDevice(std::string deviceID);
|
|
|
|
static void EnumerateDevices(std::vector<AudioInputDevice>& devs);
|
2017-05-11 05:21:04 +02:00
|
|
|
#ifdef TGVOIP_WINDOWS_DESKTOP
|
2017-05-04 23:44:23 +02:00
|
|
|
STDMETHOD_(ULONG, AddRef)();
|
|
|
|
STDMETHOD_(ULONG, Release)();
|
2017-05-11 05:21:04 +02:00
|
|
|
#endif
|
2017-05-04 23:44:23 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
void ActuallySetCurrentDevice(std::string deviceID);
|
2018-06-04 21:37:43 +02:00
|
|
|
static DWORD WINAPI StartThread(void* arg);
|
2017-05-04 23:44:23 +02:00
|
|
|
void RunThread();
|
|
|
|
WAVEFORMATEX format;
|
|
|
|
bool isRecording;
|
|
|
|
HANDLE shutdownEvent;
|
|
|
|
HANDLE audioSamplesReadyEvent;
|
|
|
|
HANDLE streamSwitchEvent;
|
|
|
|
HANDLE thread;
|
2018-12-31 02:05:58 +01:00
|
|
|
IAudioClient* audioClient=NULL;
|
|
|
|
IAudioCaptureClient* captureClient=NULL;
|
2017-05-10 01:28:20 +02:00
|
|
|
#ifdef TGVOIP_WINDOWS_DESKTOP
|
2017-05-04 23:44:23 +02:00
|
|
|
IMMDeviceEnumerator* enumerator;
|
|
|
|
IAudioSessionControl* audioSessionControl;
|
|
|
|
IMMDevice* device;
|
2017-05-10 01:28:20 +02:00
|
|
|
#endif
|
2017-05-04 23:44:23 +02:00
|
|
|
unsigned char remainingData[10240];
|
|
|
|
size_t remainingDataLen;
|
|
|
|
bool isDefaultDevice;
|
|
|
|
ULONG refCount;
|
|
|
|
std::string streamChangeToDevice;
|
2017-08-01 19:17:44 +02:00
|
|
|
bool started;
|
2017-05-04 23:44:23 +02:00
|
|
|
|
2017-05-10 01:28:20 +02:00
|
|
|
#ifdef TGVOIP_WINDOWS_DESKTOP
|
2017-05-04 23:44:23 +02:00
|
|
|
STDMETHOD(OnDisplayNameChanged) (LPCWSTR /*NewDisplayName*/, LPCGUID /*EventContext*/) { return S_OK; };
|
|
|
|
STDMETHOD(OnIconPathChanged) (LPCWSTR /*NewIconPath*/, LPCGUID /*EventContext*/) { return S_OK; };
|
|
|
|
STDMETHOD(OnSimpleVolumeChanged) (float /*NewSimpleVolume*/, BOOL /*NewMute*/, LPCGUID /*EventContext*/) { return S_OK; }
|
|
|
|
STDMETHOD(OnChannelVolumeChanged) (DWORD /*ChannelCount*/, float /*NewChannelVolumes*/[], DWORD /*ChangedChannel*/, LPCGUID /*EventContext*/) { return S_OK; };
|
|
|
|
STDMETHOD(OnGroupingParamChanged) (LPCGUID /*NewGroupingParam*/, LPCGUID /*EventContext*/) { return S_OK; };
|
|
|
|
STDMETHOD(OnStateChanged) (AudioSessionState /*NewState*/) { return S_OK; };
|
|
|
|
STDMETHOD(OnSessionDisconnected) (AudioSessionDisconnectReason DisconnectReason);
|
|
|
|
STDMETHOD(OnDeviceStateChanged) (LPCWSTR /*DeviceId*/, DWORD /*NewState*/) { return S_OK; }
|
|
|
|
STDMETHOD(OnDeviceAdded) (LPCWSTR /*DeviceId*/) { return S_OK; };
|
|
|
|
STDMETHOD(OnDeviceRemoved) (LPCWSTR /*DeviceId(*/) { return S_OK; };
|
|
|
|
STDMETHOD(OnDefaultDeviceChanged) (EDataFlow Flow, ERole Role, LPCWSTR NewDefaultDeviceId);
|
|
|
|
STDMETHOD(OnPropertyValueChanged) (LPCWSTR /*DeviceId*/, const PROPERTYKEY /*Key*/) { return S_OK; };
|
|
|
|
|
|
|
|
//
|
|
|
|
// IUnknown
|
|
|
|
//
|
|
|
|
STDMETHOD(QueryInterface)(REFIID iid, void **pvObject);
|
2017-05-10 01:28:20 +02:00
|
|
|
#endif
|
2017-05-04 23:44:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //LIBTGVOIP_AUDIOINPUTWASAPI_H
|