Skip automatic sinks update cycle in case no remote source was updated by the browser
This commit is contained in:
parent
f89d8a9693
commit
cd0d7b6210
@ -72,24 +72,23 @@ bool Browser::worker() {
|
|||||||
BOOST_LOG_TRIVIAL(debug) << "browser:: received SAP message for " << id;
|
BOOST_LOG_TRIVIAL(debug) << "browser:: received SAP message for " << id;
|
||||||
|
|
||||||
std::unique_lock sources_lock(sources_mutex_);
|
std::unique_lock sources_lock(sources_mutex_);
|
||||||
|
last_update_ =
|
||||||
|
duration_cast<second_t>(steady_clock::now() - startup_).count();
|
||||||
|
|
||||||
auto it = sources_.get<id_tag>().find(id);
|
auto it = sources_.get<id_tag>().find(id);
|
||||||
if (it == sources_.end()) {
|
if (it == sources_.end()) {
|
||||||
// Source is not in the map
|
// Source is not in the map
|
||||||
if (is_announce) {
|
if (is_announce) {
|
||||||
// annoucement, add new source
|
// annoucement, add new source
|
||||||
sources_.insert(
|
sources_.insert({id,
|
||||||
{id,
|
"SAP",
|
||||||
"SAP",
|
ip::address_v4(ntohl(addr)).to_string(),
|
||||||
ip::address_v4(ntohl(addr)).to_string(),
|
sdp_get_subject(sdp),
|
||||||
sdp_get_subject(sdp),
|
{},
|
||||||
{},
|
sdp_get_origin(sdp),
|
||||||
sdp_get_origin(sdp),
|
sdp,
|
||||||
sdp,
|
last_update_,
|
||||||
static_cast<uint32_t>(
|
config_->get_sap_interval()});
|
||||||
duration_cast<second_t>(steady_clock::now() - startup_)
|
|
||||||
.count()),
|
|
||||||
config_->get_sap_interval()});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Source is already in the map
|
// Source is already in the map
|
||||||
@ -97,12 +96,10 @@ bool Browser::worker() {
|
|||||||
BOOST_LOG_TRIVIAL(debug)
|
BOOST_LOG_TRIVIAL(debug)
|
||||||
<< "browser:: refreshing SAP source " << it->id;
|
<< "browser:: refreshing SAP source " << it->id;
|
||||||
// annoucement, update last seen and announce period
|
// annoucement, update last seen and announce period
|
||||||
uint32_t last_seen =
|
|
||||||
duration_cast<second_t>(steady_clock::now() - startup_).count();
|
|
||||||
auto upd_source{*it};
|
auto upd_source{*it};
|
||||||
if ((last_seen - upd_source.last_seen) != 0) {
|
if ((last_update_ - upd_source.last_seen) != 0) {
|
||||||
upd_source.announce_period = last_seen - upd_source.last_seen;
|
upd_source.announce_period = last_update_ - upd_source.last_seen;
|
||||||
upd_source.last_seen = last_seen;
|
upd_source.last_seen = last_update_;
|
||||||
sources_.replace(it, upd_source);
|
sources_.replace(it, upd_source);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -130,6 +127,8 @@ bool Browser::worker() {
|
|||||||
BOOST_LOG_TRIVIAL(info)
|
BOOST_LOG_TRIVIAL(info)
|
||||||
<< "browser:: SAP source " << it->id << " timeout";
|
<< "browser:: SAP source " << it->id << " timeout";
|
||||||
it = sources_.erase(it);
|
it = sources_.erase(it);
|
||||||
|
last_update_ =
|
||||||
|
duration_cast<second_t>(steady_clock::now() - startup_).count();
|
||||||
} else {
|
} else {
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
@ -150,9 +149,9 @@ bool Browser::worker() {
|
|||||||
void Browser::on_change_rtsp_source(const std::string& name,
|
void Browser::on_change_rtsp_source(const std::string& name,
|
||||||
const std::string& domain,
|
const std::string& domain,
|
||||||
const RtspSource& s) {
|
const RtspSource& s) {
|
||||||
uint32_t last_seen =
|
|
||||||
duration_cast<second_t>(steady_clock::now() - startup_).count();
|
|
||||||
std::unique_lock sources_lock(sources_mutex_);
|
std::unique_lock sources_lock(sources_mutex_);
|
||||||
|
last_update_ =
|
||||||
|
duration_cast<second_t>(steady_clock::now() - startup_).count();
|
||||||
/* search by name */
|
/* search by name */
|
||||||
auto rng = sources_.get<name_tag>().equal_range(name);
|
auto rng = sources_.get<name_tag>().equal_range(name);
|
||||||
while (rng.first != rng.second) {
|
while (rng.first != rng.second) {
|
||||||
@ -166,7 +165,7 @@ void Browser::on_change_rtsp_source(const std::string& name,
|
|||||||
upd_source.address = s.address;
|
upd_source.address = s.address;
|
||||||
upd_source.origin = sdp_get_origin(s.sdp);
|
upd_source.origin = sdp_get_origin(s.sdp);
|
||||||
upd_source.sdp = s.sdp;
|
upd_source.sdp = s.sdp;
|
||||||
upd_source.last_seen = last_seen;
|
upd_source.last_seen = last_update_;
|
||||||
sources_.get<name_tag>().replace(it, upd_source);
|
sources_.get<name_tag>().replace(it, upd_source);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -176,7 +175,7 @@ void Browser::on_change_rtsp_source(const std::string& name,
|
|||||||
BOOST_LOG_TRIVIAL(info) << "browser:: adding RTSP source " << s.id << " name "
|
BOOST_LOG_TRIVIAL(info) << "browser:: adding RTSP source " << s.id << " name "
|
||||||
<< name << " domain " << domain;
|
<< name << " domain " << domain;
|
||||||
sources_.insert({s.id, s.source, s.address, name, domain,
|
sources_.insert({s.id, s.source, s.address, name, domain,
|
||||||
sdp_get_origin(s.sdp), s.sdp, last_seen, 0});
|
sdp_get_origin(s.sdp), s.sdp, last_update_, 0});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::on_remove_rtsp_source(const std::string& name,
|
void Browser::on_remove_rtsp_source(const std::string& name,
|
||||||
@ -191,6 +190,8 @@ void Browser::on_remove_rtsp_source(const std::string& name,
|
|||||||
<< "browser:: removing RTSP source " << it->id << " name " << it->name
|
<< "browser:: removing RTSP source " << it->id << " name " << it->name
|
||||||
<< " domain " << it->domain;
|
<< " domain " << it->domain;
|
||||||
name_idx.erase(it);
|
name_idx.erase(it);
|
||||||
|
last_update_ =
|
||||||
|
duration_cast<second_t>(steady_clock::now() - startup_).count();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++rng.first;
|
++rng.first;
|
||||||
@ -206,6 +207,7 @@ bool Browser::init() {
|
|||||||
running_ = true;
|
running_ = true;
|
||||||
res_ = std::async(std::launch::async, &Browser::worker, this);
|
res_ = std::async(std::launch::async, &Browser::worker, this);
|
||||||
}
|
}
|
||||||
|
last_update_ = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ class Browser : public MDNSClient {
|
|||||||
|
|
||||||
bool init() override;
|
bool init() override;
|
||||||
bool terminate() override;
|
bool terminate() override;
|
||||||
|
uint32_t get_last_update_ts() const { return last_update_; }
|
||||||
|
|
||||||
std::list<RemoteSource> get_remote_sources(
|
std::list<RemoteSource> get_remote_sources(
|
||||||
const std::string& source = "all") const;
|
const std::string& source = "all") const;
|
||||||
@ -99,6 +100,7 @@ class Browser : public MDNSClient {
|
|||||||
SAP sap_{config_->get_sap_mcast_addr()};
|
SAP sap_{config_->get_sap_mcast_addr()};
|
||||||
IGMP igmp_;
|
IGMP igmp_;
|
||||||
std::chrono::time_point<std::chrono::steady_clock> startup_;
|
std::chrono::time_point<std::chrono::steady_clock> startup_;
|
||||||
|
uint32_t last_update_{0}; /* seconds from daemon startup */
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1056,12 +1056,18 @@ std::list<StreamSink> SessionManager::get_updated_sinks(
|
|||||||
|
|
||||||
void SessionManager::update_sinks() {
|
void SessionManager::update_sinks() {
|
||||||
if (config_->get_auto_sinks_update()) {
|
if (config_->get_auto_sinks_update()) {
|
||||||
std::list<RemoteSource> remote_sources = browser_->get_remote_sources();
|
uint32_t last_update = browser_->get_last_update_ts();
|
||||||
auto sinks_list = get_updated_sinks(remote_sources);
|
// check remote sources only if an update arrived
|
||||||
for (auto& sink : sinks_list) {
|
if (last_update && last_sink_update_ != last_update) {
|
||||||
// Re-add sink with new SDP, since the sink.id is the same there will be
|
BOOST_LOG_TRIVIAL(debug) << "Updating sinks ...";
|
||||||
// an update
|
std::list<RemoteSource> remote_sources = browser_->get_remote_sources();
|
||||||
add_sink(sink);
|
auto sinks_list = get_updated_sinks(remote_sources);
|
||||||
|
for (auto& sink : sinks_list) {
|
||||||
|
// Re-add sink with new SDP, since the sink.id is the same there will be
|
||||||
|
// an update
|
||||||
|
add_sink(sink);
|
||||||
|
}
|
||||||
|
last_sink_update_ = last_update;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,7 @@ class SessionManager {
|
|||||||
bool init() {
|
bool init() {
|
||||||
if (!running_) {
|
if (!running_) {
|
||||||
running_ = true;
|
running_ = true;
|
||||||
|
// to have an increasing session versions between restarts
|
||||||
res_ = std::async(std::launch::async, &SessionManager::worker, this);
|
res_ = std::async(std::launch::async, &SessionManager::worker, this);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -241,6 +242,7 @@ class SessionManager {
|
|||||||
|
|
||||||
SAP sap_{config_->get_sap_mcast_addr()};
|
SAP sap_{config_->get_sap_mcast_addr()};
|
||||||
IGMP igmp_;
|
IGMP igmp_;
|
||||||
|
uint32_t last_sink_update_{0};
|
||||||
|
|
||||||
/* used to handle session versioning */
|
/* used to handle session versioning */
|
||||||
inline static std::atomic<uint16_t> g_session_version{0};
|
inline static std::atomic<uint16_t> g_session_version{0};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user