Rename WasapiMode to SharingMode

The mode is more general and will be applied
in a second step also to other audio devices
This commit is contained in:
badaix 2020-04-10 10:15:58 +02:00
parent 5cc37f98f4
commit 30753f9f61
5 changed files with 17 additions and 21 deletions

View file

@ -27,13 +27,11 @@
struct ClientSettings struct ClientSettings
{ {
#ifdef HAS_WASAPI enum class SharingMode
enum class WasapiMode
{ {
SHARED, exclusive,
EXCLUSIVE shared
}; };
#endif
struct ServerSettings struct ServerSettings
{ {
@ -47,9 +45,7 @@ struct ClientSettings
int latency{0}; int latency{0};
PcmDevice pcm_device; PcmDevice pcm_device;
SampleFormat sample_format; SampleFormat sample_format;
#ifdef HAS_WASAPI SharingMode sharing_mode{SharingMode::shared};
WasapiMode wasapi_mode{WasapiMode::SHARED};
#endif
}; };
struct LoggingSettings struct LoggingSettings

View file

@ -145,7 +145,7 @@ void Controller::onMessageReceived(ClientConnection* /*connection*/, const msg::
#endif #endif
#ifdef HAS_WASAPI #ifdef HAS_WASAPI
if (!player_ && (player_name.empty() || (player_name == "wasapi"))) if (!player_ && (player_name.empty() || (player_name == "wasapi")))
player_ = make_unique<WASAPIPlayer>(pcm_device, stream_, settings_.player.wasapi_mode); player_ = make_unique<WASAPIPlayer>(pcm_device, stream_, settings_.player.sharing_mode);
#endif #endif
if (!player_) if (!player_)
throw SnapException("No audio player support"); throw SnapException("No audio player support");

View file

@ -68,7 +68,7 @@ EXTERN_C const PROPERTYKEY DECLSPEC_SELECTANY PKEY_Device_FriendlyName = {{0xa45
throw SnapException(ss.str()); \ throw SnapException(ss.str()); \
} }
WASAPIPlayer::WASAPIPlayer(const PcmDevice& pcmDevice, std::shared_ptr<Stream> stream, ClientSettings::WasapiMode mode) : Player(pcmDevice, stream), mode_(mode) WASAPIPlayer::WASAPIPlayer(const PcmDevice& pcmDevice, std::shared_ptr<Stream> stream, ClientSettings::SharingMode mode) : Player(pcmDevice, stream), mode_(mode)
{ {
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
CHECK_HR(hr); CHECK_HR(hr);
@ -217,7 +217,7 @@ void WASAPIPlayer::worker()
hr = device->Activate(IID_IAudioClient, CLSCTX_SERVER, NULL, (void**)&audioClient); hr = device->Activate(IID_IAudioClient, CLSCTX_SERVER, NULL, (void**)&audioClient);
CHECK_HR(hr); CHECK_HR(hr);
if (mode_ == ClientSettings::WasapiMode::EXCLUSIVE) if (mode_ == ClientSettings::SharingMode::exclusive)
{ {
hr = audioClient->IsFormatSupported(AUDCLNT_SHAREMODE_EXCLUSIVE, &(waveformatExtended->Format), NULL); hr = audioClient->IsFormatSupported(AUDCLNT_SHAREMODE_EXCLUSIVE, &(waveformatExtended->Format), NULL);
CHECK_HR(hr); CHECK_HR(hr);
@ -245,10 +245,10 @@ void WASAPIPlayer::worker()
hr = audioClient->GetDevicePeriod(NULL, &hnsRequestedDuration); hr = audioClient->GetDevicePeriod(NULL, &hnsRequestedDuration);
CHECK_HR(hr); CHECK_HR(hr);
LOG(INFO, LOG_TAG) << "Initializing WASAPI in " << (mode_ == ClientSettings::WasapiMode::SHARED ? "shared" : "exclusive") << " mode\n"; LOG(INFO, LOG_TAG) << "Initializing WASAPI in " << (mode_ == ClientSettings::SharingMode::shared ? "shared" : "exclusive") << " mode\n";
_AUDCLNT_SHAREMODE share_mode = mode_ == ClientSettings::WasapiMode::SHARED ? AUDCLNT_SHAREMODE_SHARED : AUDCLNT_SHAREMODE_EXCLUSIVE; _AUDCLNT_SHAREMODE share_mode = mode_ == ClientSettings::SharingMode::shared ? AUDCLNT_SHAREMODE_SHARED : AUDCLNT_SHAREMODE_EXCLUSIVE;
DWORD stream_flags = mode_ == ClientSettings::WasapiMode::SHARED DWORD stream_flags = mode_ == ClientSettings::SharingMode::shared
? AUDCLNT_STREAMFLAGS_EVENTCALLBACK | AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM | AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY ? AUDCLNT_STREAMFLAGS_EVENTCALLBACK | AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM | AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY
: AUDCLNT_STREAMFLAGS_EVENTCALLBACK; : AUDCLNT_STREAMFLAGS_EVENTCALLBACK;
@ -339,7 +339,7 @@ void WASAPIPlayer::worker()
clock->GetPosition(&position, NULL); clock->GetPosition(&position, NULL);
UINT32 padding = 0; UINT32 padding = 0;
if (mode_ == ClientSettings::WasapiMode::SHARED) if (mode_ == ClientSettings::SharingMode::shared)
{ {
hr = audioClient->GetCurrentPadding(&padding); hr = audioClient->GetCurrentPadding(&padding);
CHECK_HR(hr); CHECK_HR(hr);

View file

@ -93,7 +93,7 @@ public:
class WASAPIPlayer : public Player class WASAPIPlayer : public Player
{ {
public: public:
WASAPIPlayer(const PcmDevice& pcmDevice, std::shared_ptr<Stream> stream, ClientSettings::WasapiMode mode); WASAPIPlayer(const PcmDevice& pcmDevice, std::shared_ptr<Stream> stream, ClientSettings::SharingMode mode);
virtual ~WASAPIPlayer(); virtual ~WASAPIPlayer();
static std::vector<PcmDevice> pcm_list(void); static std::vector<PcmDevice> pcm_list(void);
@ -103,7 +103,7 @@ protected:
private: private:
AudioSessionEventListener* audioEventListener_; AudioSessionEventListener* audioEventListener_;
ClientSettings::WasapiMode mode_; ClientSettings::SharingMode mode_;
}; };
#endif #endif

View file

@ -118,7 +118,7 @@ int main(int argc, char** argv)
auto sample_format = op.add<Value<string>>("", "sampleformat", "resample audio stream to <rate>:<bits>:<channels>", ""); auto sample_format = op.add<Value<string>>("", "sampleformat", "resample audio stream to <rate>:<bits>:<channels>", "");
#endif #endif
#ifdef HAS_WASAPI #ifdef HAS_WASAPI
auto wasapi_mode = op.add<Value<string>>("", "wasapimode", "WASAPI mode to use [shared/exclusive]", "shared"); auto sharing_mode = op.add<Value<string>>("", "sharingmode", "audio mode to use [shared/exclusive]", "shared");
#endif #endif
try try
@ -243,10 +243,10 @@ int main(int argc, char** argv)
#endif #endif
#ifdef HAS_WASAPI #ifdef HAS_WASAPI
if (wasapi_mode->is_set()) if (sharing_mode->is_set())
{ {
settings.player.wasapi_mode = settings.player.sharing_mode =
(strcmp(wasapi_mode->value().c_str(), "exclusive") == 0) ? ClientSettings::WasapiMode::EXCLUSIVE : ClientSettings::WasapiMode::SHARED; (sharing_mode->value() == "exclusive") ? ClientSettings::SharingMode::exclusive : ClientSettings::SharingMode::shared;
} }
#endif #endif