Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
hfedcba committed Feb 20, 2018
2 parents 8ca9ced + 1f08bd6 commit d2d2d18
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
Binary file added misc/State Directory/audio/Silence_250ms.mp3
Binary file not shown.
Binary file removed misc/State Directory/audio/Silence_2s.mp3
Binary file not shown.
1 change: 1 addition & 0 deletions src/Interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void Interfaces::create()
GD::physicalInterface = device;
}
}
if(!GD::physicalInterface) GD::physicalInterface = std::make_shared<ISonosInterface>(std::make_shared<BaseLib::Systems::PhysicalInterfaceSettings>());
}
catch(const std::exception& ex)
{
Expand Down
9 changes: 5 additions & 4 deletions src/PhysicalInterfaces/ISonosInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ class ISonosInterface : public BaseLib::Systems::IPhysicalInterface
ISonosInterface(std::shared_ptr<BaseLib::Systems::PhysicalInterfaceSettings> settings);
virtual ~ISonosInterface();

virtual std::string listenAddress() = 0;
virtual int32_t listenPort() = 0;
virtual std::string ttsProgram() = 0;
virtual std::string dataPath() = 0;
virtual std::string listenAddress() { return "::1"; }
virtual int32_t listenPort() { return 7373; }
virtual std::string ttsProgram() { return ""; }
virtual std::string dataPath() { return ""; }
virtual void sendPacket(std::shared_ptr<BaseLib::Systems::Packet> packet) {}
protected:
BaseLib::Output _out;
};
Expand Down
23 changes: 19 additions & 4 deletions src/SonosCentral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,26 @@ void SonosCentral::deletePeer(uint64_t id)
}

raiseRPCDeleteDevices(deviceAddresses, deviceInfo);

{
std::lock_guard<std::mutex> peersGuard(_peersMutex);
if(_peersBySerial.find(peer->getSerialNumber()) != _peersBySerial.end()) _peersBySerial.erase(peer->getSerialNumber());
if(_peersById.find(id) != _peersById.end()) _peersById.erase(id);
}

if(_currentPeer && _currentPeer->getID() == id) _currentPeer.reset();

int32_t i = 0;
while(peer.use_count() > 1 && i < 600)
{
if(_currentPeer && _currentPeer->getID() == id) _currentPeer.reset();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
i++;
}
if(i == 600) GD::out.printError("Error: Peer deletion took too long.");

peer->deleteFromDatabase();
_peersMutex.lock();
if(_peersBySerial.find(peer->getSerialNumber()) != _peersBySerial.end()) _peersBySerial.erase(peer->getSerialNumber());
if(_peersById.find(id) != _peersById.end()) _peersById.erase(id);
_peersMutex.unlock();

GD::out.printMessage("Removed Sonos peer " + std::to_string(peer->getID()));
}
catch(const std::exception& ex)
Expand Down
2 changes: 1 addition & 1 deletion src/SonosPeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,7 @@ void SonosPeer::playLocalFile(std::string filename, bool now, bool unmute, int32
playlistFilename = BaseLib::Http::encodeURL(playlistFilename);

std::string silence2sPlaylistFilename = "silence_2s.m3u";
playlistContent = "#EXTM3U\n#EXTINF:0,<Homegear><TTS><TTS>\nhttp://" + GD::physicalInterface->listenAddress() + ':' + std::to_string(GD::physicalInterface->listenPort()) + "/Silence_2s.mp3\n";
playlistContent = "#EXTM3U\n#EXTINF:0,<Homegear><TTS><TTS>\nhttp://" + GD::physicalInterface->listenAddress() + ':' + std::to_string(GD::physicalInterface->listenPort()) + "/Silence_250ms.mp3\n";
std::string silencePlaylistFilepath = tempPath + silence2sPlaylistFilename;
BaseLib::Io::writeFile(silencePlaylistFilepath, playlistContent);
silence2sPlaylistFilename = BaseLib::Http::encodeURL(silence2sPlaylistFilename);
Expand Down

0 comments on commit d2d2d18

Please sign in to comment.