Wasapi player: unregister system volume change callback on player destroy. Fixes crash when changing Windows volume after switching streams

Wasapi player: unregister system volume change callback on player destroy. Fixes crash when changing Windows volume after switching streams
This commit is contained in:
Stijn Van der Borght 2021-03-20 10:04:45 +00:00 committed by badaix
parent ea1236feef
commit af621acf1c
2 changed files with 3 additions and 2 deletions

View file

@ -83,6 +83,7 @@ WASAPIPlayer::WASAPIPlayer(boost::asio::io_context& io_context, const ClientSett
WASAPIPlayer::~WASAPIPlayer() WASAPIPlayer::~WASAPIPlayer()
{ {
audioEndpointListener_->UnregisterControlChangeNotify(&audioEndpointVolumeCallback_);
WASAPIPlayer::stop(); WASAPIPlayer::stop();
} }
@ -250,10 +251,9 @@ void WASAPIPlayer::worker()
hr = control->RegisterAudioSessionNotification(audioEventListener_); hr = control->RegisterAudioSessionNotification(audioEventListener_);
CHECK_HR(hr); CHECK_HR(hr);
AudioEndpointVolumeCallback audioEndpointVolumeCallback;
hr = device->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&audioEndpointListener_); hr = device->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&audioEndpointListener_);
audioEndpointListener_->RegisterControlChangeNotify((IAudioEndpointVolumeCallback*)&audioEndpointVolumeCallback); audioEndpointListener_->RegisterControlChangeNotify((IAudioEndpointVolumeCallback*)&audioEndpointVolumeCallback_);
// Get the device period // Get the device period
REFERENCE_TIME hnsRequestedDuration = REFTIMES_PER_SEC; REFERENCE_TIME hnsRequestedDuration = REFTIMES_PER_SEC;

View file

@ -192,6 +192,7 @@ protected:
private: private:
AudioSessionEventListener* audioEventListener_; AudioSessionEventListener* audioEventListener_;
IAudioEndpointVolume* audioEndpointListener_; IAudioEndpointVolume* audioEndpointListener_;
AudioEndpointVolumeCallback audioEndpointVolumeCallback_;
ClientSettings::SharingMode mode_; ClientSettings::SharingMode mode_;
}; };