Skip to content

Commit

Permalink
sync upstream libnoson 1.12.3
Browse files Browse the repository at this point in the history
  • Loading branch information
janbar committed Mar 7, 2019
1 parent 517adcc commit 5abf8cf
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 47 deletions.
23 changes: 2 additions & 21 deletions backend/NosonApp/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion backend/lib/noson/noson/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
60 changes: 45 additions & 15 deletions backend/lib/noson/noson/src/sonosplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include "smapimetadata.h"
#include "filestreamer.h"
#include "imageservice.h"
#ifdef HAVE_PULSEAUDIO
#include "pulsestreamer.h"
#endif

#include <cassert>

Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion backend/lib/noson/noson/src/sonosplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 2 additions & 9 deletions cli/noson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 5abf8cf

Please sign in to comment.