diff --git a/backend/NosonApp/player.cpp b/backend/NosonApp/player.cpp index 8888bce6..849615de 100644 --- a/backend/NosonApp/player.cpp +++ b/backend/NosonApp/player.cpp @@ -352,31 +352,12 @@ bool Player::startPlayPulse() bool Player::playPulse() { - if (m_player && m_sonos->havePulseAudio()) - { - SONOS::RequestBrokerPtr rb = m_sonos->getSystem().GetRequestBroker("pulse"); - if (rb) - { - SONOS::RequestBroker::ResourcePtr res = rb->GetResource("pulse"); - return (res && m_player->PlayMyStream(res->uri, res->description, res->iconUri)); - } - } - return false; + return (m_player && m_player->PlayPulse()); } bool Player::isPulseStream(const QString &url) { - if (m_player) - { - SONOS::RequestBrokerPtr rb = m_sonos->getSystem().GetRequestBroker("pulse"); - if (rb) - { - SONOS::RequestBroker::ResourceList list = rb->GetResourceList(); - for (SONOS::RequestBroker::ResourceList::iterator it = list.begin(); it != list.end(); ++it) - return (url.contains((*it)->uri.c_str()) && m_player->IsMyStream(url.toUtf8().constData())); - } - } - return false; + return (m_player && m_player->IsPulseStream(url.toUtf8().constData())); } bool Player::isMyStream(const QString &url) diff --git a/backend/lib/noson/noson/CMakeLists.txt b/backend/lib/noson/noson/CMakeLists.txt index e6635634..b5876ebf 100644 --- a/backend/lib/noson/noson/CMakeLists.txt +++ b/backend/lib/noson/noson/CMakeLists.txt @@ -18,7 +18,7 @@ endif () # set lib version here set (noson_VERSION_MAJOR 1) set (noson_VERSION_MINOR 12) -set (noson_VERSION_PATCH 2) +set (noson_VERSION_PATCH 3) set (noson_VERSION ${noson_VERSION_MAJOR}.${noson_VERSION_MINOR}.${noson_VERSION_PATCH}) set (NOSON_LIB_VERSION ${noson_VERSION}) diff --git a/backend/lib/noson/noson/src/sonosplayer.cpp b/backend/lib/noson/noson/src/sonosplayer.cpp index 97b5f0ca..e19bf5d7 100644 --- a/backend/lib/noson/noson/src/sonosplayer.cpp +++ b/backend/lib/noson/noson/src/sonosplayer.cpp @@ -35,6 +35,9 @@ #include "smapimetadata.h" #include "filestreamer.h" #include "imageservice.h" +#ifdef HAVE_PULSEAUDIO +#include "pulsestreamer.h" +#endif #include @@ -476,25 +479,52 @@ bool Player::SetCurrentURI(const DigitalItemPtr& item) return m_AVTransport->SetCurrentURI(item->GetValue("res"), item->DIDL()); } -bool Player::PlayMyStream(const std::string& streamURI, const std::string& title, const std::string& iconURI) +bool Player::PlayPulse() { - bool hasParam = (streamURI.find("?") != std::string::npos); - // define the stream URL for the local handler - std::string streamURL; - streamURL.assign(m_controllerUri).append(streamURI) - .append(hasParam ? "&" : "?") - .append("acr=").append(m_controllerName).append(":").append(std::to_string(m_eventHandler.GetPort())); - // define the icon URL for the local handler - std::string iconURL; - iconURL.assign(m_controllerUri).append(iconURI); + RequestBroker::ResourcePtr res(nullptr); +#ifdef HAVE_PULSEAUDIO + RequestBrokerPtr rb = m_eventHandler.GetRequestBroker(PULSESTREAMER_CNAME); + if (rb) + res = rb->GetResource(PULSESTREAMER_CNAME); +#endif + if (res) + { + bool hasParam = (res->uri.find("?") != std::string::npos); + // define the stream URL for the local handler + std::string streamURL; + streamURL.assign(m_controllerUri).append(res->uri) + .append(hasParam ? "&" : "?") + .append("acr=").append(m_controllerName).append(":").append(std::to_string(m_eventHandler.GetPort())); + // define the icon URL for the local handler + std::string iconURL; + iconURL.assign(m_controllerUri).append(res->iconUri); + + // write my formatted name + std::string _title = res->description; + _title.replace(res->description.find("%s"), 2, m_controllerName); + return PlayStream(streamURL, _title, iconURL); + } + DBG(DBG_ERROR, "%s: service unavaible\n", __FUNCTION__); + return false; +} - // write my formatted name - std::string _title = title; - _title.replace(title.find("%s"), 2, m_controllerName); - return PlayStream(streamURL, _title, iconURL); +bool Player::IsPulseStream(const std::string& streamURL) +{ + RequestBrokerPtr rb(nullptr); +#ifdef HAVE_PULSEAUDIO + rb = m_eventHandler.GetRequestBroker(PULSESTREAMER_CNAME); +#endif + if (rb && IsMyStream(streamURL)) + { + RequestBroker::ResourceList list = rb->GetResourceList(); + for (RequestBroker::ResourceList::iterator it = list.begin(); it != list.end(); ++it) + if (streamURL.find((*it)->uri) != std::string::npos) + return true; + } + return false; } -bool Player::IsMyStream(const std::string &streamURL) +bool Player::IsMyStream(const std::string& streamURL) { return (streamURL.find(m_controllerUri) == 0); } diff --git a/backend/lib/noson/noson/src/sonosplayer.h b/backend/lib/noson/noson/src/sonosplayer.h index a463f70c..97d9f503 100644 --- a/backend/lib/noson/noson/src/sonosplayer.h +++ b/backend/lib/noson/noson/src/sonosplayer.h @@ -118,7 +118,8 @@ namespace NSROOT bool SetTreble(const std::string& uuid, int8_t value); bool SetCurrentURI(const DigitalItemPtr& item); - bool PlayMyStream(const std::string& streamURI, const std::string& title, const std::string& iconURI); + bool PlayPulse(); + bool IsPulseStream(const std::string& streamURL); bool IsMyStream(const std::string& streamURL); bool PlayStream(const std::string& streamURL, const std::string& title, const std::string& iconURL); bool PlayStream(const std::string& streamURL, const std::string& title); diff --git a/cli/noson.cpp b/cli/noson.cpp index 53f3cd3d..8a4e307a 100644 --- a/cli/noson.cpp +++ b/cli/noson.cpp @@ -557,15 +557,8 @@ static bool parseCommand(const std::string& line) #ifdef HAVE_PULSEAUDIO else if (token == "PLAYPULSE") { - SONOS::RequestBrokerPtr rb = gSonos->GetRequestBroker("pulse"); - if (rb) - { - SONOS::RequestBroker::ResourcePtr res = rb->GetResource("pulse"); - if (res && gSonos->GetPlayer()->PlayMyStream(res->uri, res->description, res->iconUri)) - ERROR("Succeeded\n"); - else - ERROR("Failed\n"); - } + if (gSonos->GetPlayer()->PlayPulse()) + ERROR("Succeeded\n"); else ERROR("Failed\n"); }