diff --git a/daemon/README.md b/daemon/README.md
index 7c5a70a..aeb931f 100644
--- a/daemon/README.md
+++ b/daemon/README.md
@@ -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.
diff --git a/daemon/browser.cpp b/daemon/browser.cpp
index c27b5c4..81e4c5d 100644
--- a/daemon/browser.cpp
+++ b/daemon/browser.cpp
@@ -17,8 +17,10 @@
// along with this program. If not, see .
//
+#include
#include "browser.hpp"
+using namespace boost::algorithm;
using namespace std::chrono;
using second_t = duration >;
@@ -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(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(steady_clock::now() - startup_).count();
+ uint32_t last_seen = duration_cast(steady_clock::now() -
+ startup_).count();
std::unique_lock sources_lock(sources_mutex_);
- if (sources_.get().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().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();
- 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;
}
}
diff --git a/daemon/browser.hpp b/daemon/browser.hpp
index 5707d43..200c29d 100644
--- a/daemon/browser.hpp
+++ b/daemon/browser.hpp
@@ -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 {
diff --git a/daemon/json.cpp b/daemon/json.cpp
index 3cd58f0..eb12d14 100644
--- a/daemon/json.cpp
+++ b/daemon/json.cpp
@@ -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)