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