Reformat code

This commit is contained in:
badaix 2020-04-10 09:45:19 +02:00
parent 1fcb8b4fc2
commit 5cc37f98f4
8 changed files with 293 additions and 315 deletions

View file

@ -2,19 +2,19 @@
#include <initguid.h>
#include <mmdeviceapi.h>
//#include <functiondiscoverykeys_devpkey.h>
#include <functional>
#include "common/aixlog.hpp"
#include "common/snap_exception.hpp"
#include <assert.h>
#include <audioclient.h>
#include <mmdeviceapi.h>
#include <avrt.h>
#include <chrono>
#include <codecvt>
#include <comdef.h>
#include <comip.h>
#include <avrt.h>
#include <functional>
#include <ksmedia.h>
#include <chrono>
#include <assert.h>
#include <codecvt>
#include <locale>
#include "common/snap_exception.hpp"
#include "common/aixlog.hpp"
#include <mmdeviceapi.h>
using namespace std;
using namespace std::chrono;
@ -59,13 +59,18 @@ _COM_SMARTPTR_TYPEDEF(IAudioSessionControl, __uuidof(IAudioSessionControl));
EXTERN_C const PROPERTYKEY DECLSPEC_SELECTANY PKEY_Device_FriendlyName = {{0xa45c254e, 0xdf1c, 0x4efd, {0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0}}, 14};
#define CHECK_HR(hres) if(FAILED(hres)){stringstream ss;ss<<"HRESULT fault status: "<<hex<<(hres)<<" line "<<dec<<__LINE__<<endl; LOG(FATAL, LOG_TAG) << ss.str();throw SnapException(ss.str());}
#define CHECK_HR(hres) \
if (FAILED(hres)) \
{ \
stringstream ss; \
ss << "HRESULT fault status: " << hex << (hres) << " line " << dec << __LINE__ << endl; \
LOG(FATAL, LOG_TAG) << ss.str(); \
throw SnapException(ss.str()); \
}
WASAPIPlayer::WASAPIPlayer(const PcmDevice& pcmDevice, std::shared_ptr<Stream> stream, ClientSettings::WasapiMode mode) : Player(pcmDevice, stream), mode_(mode)
{
HRESULT hr = CoInitializeEx(
NULL,
COINIT_MULTITHREADED);
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
CHECK_HR(hr);
audioEventListener_ = new AudioSessionEventListener();
@ -109,16 +114,11 @@ vector<PcmDevice> WASAPIPlayer::pcm_list()
IMMDeviceCollectionPtr devices = nullptr;
IMMDeviceEnumeratorPtr deviceEnumerator = nullptr;
hr = CoInitializeEx(
NULL,
COINIT_MULTITHREADED);
hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (hr != CO_E_ALREADYINITIALIZED)
CHECK_HR(hr);
hr = CoCreateInstance(
CLSID_MMDeviceEnumerator, NULL,
CLSCTX_SERVER, IID_IMMDeviceEnumerator,
(void**)&deviceEnumerator);
hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_SERVER, IID_IMMDeviceEnumerator, (void**)&deviceEnumerator);
CHECK_HR(hr);
hr = deviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &devices);
@ -183,10 +183,7 @@ void WASAPIPlayer::worker()
// Retrieve the device enumerator
IMMDeviceEnumeratorPtr deviceEnumerator = nullptr;
hr = CoCreateInstance(
CLSID_MMDeviceEnumerator, NULL,
CLSCTX_SERVER, IID_IMMDeviceEnumerator,
(void**)&deviceEnumerator);
hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_SERVER, IID_IMMDeviceEnumerator, (void**)&deviceEnumerator);
CHECK_HR(hr);
// Register the default playback device (eRender for playback)
@ -222,10 +219,7 @@ void WASAPIPlayer::worker()
if (mode_ == ClientSettings::WasapiMode::EXCLUSIVE)
{
hr = audioClient->IsFormatSupported(
AUDCLNT_SHAREMODE_EXCLUSIVE,
&(waveformatExtended->Format),
NULL);
hr = audioClient->IsFormatSupported(AUDCLNT_SHAREMODE_EXCLUSIVE, &(waveformatExtended->Format), NULL);
CHECK_HR(hr);
}
@ -259,13 +253,7 @@ void WASAPIPlayer::worker()
: AUDCLNT_STREAMFLAGS_EVENTCALLBACK;
// Initialize the client at minimum latency
hr = audioClient->Initialize(
share_mode,
stream_flags,
hnsRequestedDuration,
hnsRequestedDuration,
&(waveformatExtended->Format),
NULL);
hr = audioClient->Initialize(share_mode, stream_flags, hnsRequestedDuration, hnsRequestedDuration, &(waveformatExtended->Format), NULL);
if (hr == AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED)
{
@ -276,13 +264,7 @@ void WASAPIPlayer::worker()
hnsRequestedDuration = (REFERENCE_TIME)((10000.0 * 1000 / waveformatExtended->Format.nSamplesPerSec * alignedBufferSize) + 0.5);
hr = device->Activate(IID_IAudioClient, CLSCTX_SERVER, NULL, (void**)&audioClient);
CHECK_HR(hr);
hr = audioClient->Initialize(
share_mode,
stream_flags,
hnsRequestedDuration,
hnsRequestedDuration,
&(waveformatExtended->Format),
NULL);
hr = audioClient->Initialize(share_mode, stream_flags, hnsRequestedDuration, hnsRequestedDuration, &(waveformatExtended->Format), NULL);
}
CHECK_HR(hr);
@ -300,22 +282,17 @@ void WASAPIPlayer::worker()
// Get the rendering service
IAudioRenderClient* renderClient = NULL;
hr = audioClient->GetService(
IID_IAudioRenderClient,
(void**)&renderClient);
hr = audioClient->GetService(IID_IAudioRenderClient, (void**)&renderClient);
CHECK_HR(hr);
// Grab the clock service
IAudioClock* clock = NULL;
hr = audioClient->GetService(
IID_IAudioClock,
(void**)&clock);
hr = audioClient->GetService(IID_IAudioClock, (void**)&clock);
CHECK_HR(hr);
// Boost our priority
DWORD taskIndex = 0;
com_handle taskHandle(AvSetMmThreadCharacteristics(TEXT("Pro Audio"), &taskIndex),
&::AvRevertMmThreadCharacteristics);
com_handle taskHandle(AvSetMmThreadCharacteristics(TEXT("Pro Audio"), &taskIndex), &::AvRevertMmThreadCharacteristics);
if (taskHandle == NULL)
CHECK_HR(E_FAIL);
@ -370,10 +347,8 @@ void WASAPIPlayer::worker()
int available = bufferFrameCount - padding;
if (stream_->getPlayerChunk(queueBuffer.get(), microseconds(
((bufferPosition * 1000000) / waveformat->nSamplesPerSec) -
((position * 1000000) / frequency)),
available))
if (stream_->getPlayerChunk(queueBuffer.get(),
microseconds(((bufferPosition * 1000000) / waveformat->nSamplesPerSec) - ((position * 1000000) / frequency)), available))
{
if (available > 0)
{

View file

@ -18,9 +18,9 @@
#ifndef WASAPI_PLAYER_H
#define WASAPI_PLAYER_H
#include "client_settings.hpp"
#include "player.hpp"
#include <audiopolicy.h>
#include "client_settings.hpp"
class AudioSessionEventListener : public IAudioSessionEvents
{
@ -97,6 +97,7 @@ public:
virtual ~WASAPIPlayer();
static std::vector<PcmDevice> pcm_list(void);
protected:
virtual void worker();

View file

@ -245,14 +245,15 @@ int main(int argc, char** argv)
#ifdef HAS_WASAPI
if (wasapi_mode->is_set())
{
settings.player.wasapi_mode = (strcmp(wasapi_mode->value().c_str(), "exclusive") == 0) ?
ClientSettings::WasapiMode::EXCLUSIVE : ClientSettings::WasapiMode::SHARED;
settings.player.wasapi_mode =
(strcmp(wasapi_mode->value().c_str(), "exclusive") == 0) ? ClientSettings::WasapiMode::EXCLUSIVE : ClientSettings::WasapiMode::SHARED;
}
#endif
bool active = true;
std::shared_ptr<Controller> controller;
auto signal_handler = install_signal_handler({
auto signal_handler = install_signal_handler(
{
#ifndef WINDOWS // no sighup on windows
SIGHUP,
#endif

View file

@ -38,11 +38,11 @@
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <mutex>
#include <map>
#include <thread>
#include <sstream>
#include <thread>
#include <vector>
#ifdef __ANDROID__
@ -109,7 +109,8 @@
#define TIMESTAMP AixLog::Timestamp(std::chrono::system_clock::now())
// stijnvdb: sorry! :) LOG(SEV, "tag") was not working for Windows and I couldn't figure out how to fix it for windows without potentially breaking everything else...
// stijnvdb: sorry! :) LOG(SEV, "tag") was not working for Windows and I couldn't figure out how to fix it for windows without potentially breaking everything
// else...
// https://stackoverflow.com/questions/3046889/optional-parameters-with-c-macros (Jason Deng)
#ifdef WIN32
#define LOG_2(severity, tag) AIXLOG_INTERNAL__LOG_SEVERITY_TAG(severity, tag)

View file

@ -36,8 +36,8 @@
#include <net/if.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <unistd.h>
#endif
#include <sstream>
#include <string>
@ -58,11 +58,11 @@
#endif
#ifdef WINDOWS
#include <chrono>
#include <windows.h>
#include <direct.h>
#include <winsock2.h>
#include <iphlpapi.h>
#include <versionhelpers.h>
#include <windows.h>
#include <winsock2.h>
#endif