Set of enhancements and fixes to the daemon browser:

- browser stores the RTSP sources discovered via mDNS by name and domain
- domain field added to JSON Remote Source params
- removed trailing CR/LF to the end of SAP source name
This commit is contained in:
Andrea Bondavalli 2020-04-08 11:24:10 -07:00
parent 8c1f304065
commit 9898c9fac0
4 changed files with 46 additions and 12 deletions

View File

@ -548,6 +548,7 @@ Example:
"source": "SAP",
"id": "d00000a611d",
"name": "ALSA Source 2",
"domain": "",
"address": "10.0.0.13",
"sdp": "v=0\no=- 2 0 IN IP4 10.0.0.13\ns=ALSA Source 2\nc=IN IP4 239.1.0.3/15\nt=0 0\na=clock-domain:PTPv2 0\nm=audio 5004 RTP/AVP 98\nc=IN IP4 239.1.0.3/15\na=rtpmap:98 L16/48000/2\na=sync-time:0\na=framecount:48\na=ptime:1\na=mediaclk:direct=0\na=ts-refclk:ptp=IEEE1588-2008:00-10-4B-FF-FE-7A-87-FC:0\na=recvonly\n",
"last_seen": 2768,
@ -557,6 +558,7 @@ Example:
"source": "SAP",
"id": "d00000a8dd5",
"name": "ALSA Source 1",
"domain": "",
"address": "10.0.0.13",
"sdp": "v=0\no=- 1 0 IN IP4 10.0.0.13\ns=ALSA Source 1\nc=IN IP4 239.1.0.2/15\nt=0 0\na=clock-domain:PTPv2 0\nm=audio 5004 RTP/AVP 98\nc=IN IP4 239.1.0.2/15\na=rtpmap:98 L16/48000/2\na=sync-time:0\na=framecount:48\na=ptime:1\na=mediaclk:direct=0\na=ts-refclk:ptp=IEEE1588-2008:00-10-4B-FF-FE-7A-87-FC:0\na=recvonly\n",
"last_seen": 2768,
@ -578,7 +580,11 @@ where:
> JSON string specifying the remote source unique id.
> **name**
> JSON string specifying the remote source name announced in the SDP file.
> JSON string specifying the remote source name announced.
> **doamin**
> JSON string specifying the remote source domain announced.
**_NOTE:_** This field is only populated for mDNS sources.
> **address**
> JSON string specifying the remote source address announced.

View File

@ -17,8 +17,10 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include <boost/algorithm/string.hpp>
#include "browser.hpp"
using namespace boost::algorithm;
using namespace std::chrono;
using second_t = duration<double, std::ratio<1> >;
@ -83,7 +85,6 @@ bool Browser::worker() {
if (it == sources_.end()) {
// Source is not in the map
if (is_announce) {
BOOST_LOG_TRIVIAL(info) << "browser:: adding SAP source " << id;
// annoucement, add new source
RemoteSource source;
source.id = id;
@ -91,9 +92,12 @@ bool Browser::worker() {
source.source = "SAP";
source.address = ip::address_v4(ntohl(addr)).to_string();
source.name = sdp_get_subject(sdp);
trim(source.name);
source.last_seen =
duration_cast<second_t>(steady_clock::now() - startup_).count();
source.announce_period = 360; //default period
BOOST_LOG_TRIVIAL(info) << "browser:: adding SAP source " << source.id
<< " name " << source.name;
sources_.insert(source);
}
} else {
@ -110,7 +114,8 @@ bool Browser::worker() {
sources_.replace(it, upd_source);
} else {
BOOST_LOG_TRIVIAL(info)
<< "browser:: removing SAP source " << it->id;
<< "browser:: removing SAP source " << it->id
<< " name " << it->name;
// deletion, remove entry
sources_.erase(it);
}
@ -152,24 +157,45 @@ bool Browser::worker() {
void Browser::on_new_rtsp_source(const std::string& name,
const std::string& domain,
const RTSPSSource& s) {
uint32_t last_seen = duration_cast<second_t>(steady_clock::now() - startup_).count();
uint32_t last_seen = duration_cast<second_t>(steady_clock::now() -
startup_).count();
std::unique_lock sources_lock(sources_mutex_);
if (sources_.get<id_tag>().find(s.id) == sources_.end()) {
BOOST_LOG_TRIVIAL(info) << "browser:: adding RTSP source " << s.id;
sources_.insert({ s.id, s.source, s.address, name, s.sdp, last_seen, 0 });
auto rng = sources_.get<name_tag>().equal_range(name);
while(rng.first != rng.second){
const auto& it = rng.first;
if (it->source == "mDNS" && it->domain == domain) {
/* conflict ? */
BOOST_LOG_TRIVIAL(warning) << "browser:: mDNS source conflict on"
<< " name " << it->name
<< " domain " << it->domain
<< ", skipping ... ";
return;
}
++rng.first;
}
BOOST_LOG_TRIVIAL(info) << "browser:: adding RTSP source " << s.id
<< " name " << name
<< " domain " << domain;
sources_.insert(
{s.id, s.source, s.address, name, domain, s.sdp, last_seen, 0});
}
void Browser::on_remove_rtsp_source(const std::string& name,
const std::string& domain) {
std::unique_lock sources_lock(sources_mutex_);
auto& name_idx = sources_.get<name_tag>();
for (auto it = name_idx.find(name); it != name_idx.end(); it++) {
if (it->source == "mDNS") {
BOOST_LOG_TRIVIAL(info) << "browser:: removing RTSP source " << it->id;
auto rng = name_idx.equal_range(name);
while(rng.first != rng.second){
const auto& it = rng.first;
if (it->source == "mDNS" && it->domain == domain && it->name == name) {
BOOST_LOG_TRIVIAL(info) << "browser:: removing RTSP source " << it->id
<< " name " << it->name
<< " domain " << it->domain;
name_idx.erase(it);
break;
}
++rng.first;
}
}

View File

@ -44,9 +44,10 @@ struct RemoteSource {
std::string source;
std::string address;
std::string name;
std::string domain; /* mDNS only */
std::string sdp;
uint32_t last_seen; /* seconds from daemon startup */
uint32_t announce_period; /* period between annoucements */
uint32_t last_seen{0}; /* seconds from daemon startup */
uint32_t announce_period{0}; /* period between annoucements */
};
class Browser : public MDNSClient {

View File

@ -234,6 +234,7 @@ std::string remote_source_to_json(const RemoteSource& source) {
<< "\n \"source\": \"" << escape_json(source.source) << "\""
<< ",\n \"id\": \"" << escape_json(source.id) << "\""
<< ",\n \"name\": \"" << escape_json(source.name) << "\""
<< ",\n \"domain\": \"" << escape_json(source.domain) << "\""
<< ",\n \"address\": \"" << escape_json(source.address) << "\""
<< ",\n \"sdp\": \"" << escape_json(source.sdp) << "\""
<< ",\n \"last_seen\": " << unsigned(source.last_seen)