diff --git a/native/waze-on-cluster/src/main.cpp b/native/waze-on-cluster/src/main.cpp index d0526ba8..e062e18b 100644 --- a/native/waze-on-cluster/src/main.cpp +++ b/native/waze-on-cluster/src/main.cpp @@ -26,10 +26,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -67,6 +69,20 @@ namespace { * This version does not read it. */ const char kUnreadLocalConf[] = "/var/opt/waze-on-cluster/waze-on-cluster.local.conf"; +/* Another tool with a video on the cluster's map target (a Turn View camera, for one) keeps this file's time fresh, + * every second, while its video is there: the cluster map gives its video buffer up meanwhile (the display has two, + * and the HUD map may hold the other), its newest picture kept for when it is back. Older than kVideoYieldStaleS: + * the other tool gone, the map back. */ +const char *const kVideoYieldFile = "/run/turn-view/map-yield"; +const time_t kVideoYieldStaleS = 3; + +bool video_yield_wanted() +{ + struct stat st; + return stat(kVideoYieldFile, &st) == 0 && time(nullptr) - st.st_mtime <= kVideoYieldStaleS; +} + + std::string status_line(const FeedStatus &s) { return "{\"ev\":\"status\",\"state\":" + json_escape(s.state) + ",\"target\":" + json_escape(s.target) + @@ -345,6 +361,7 @@ int serve(Config cfg) producer.set_live(live, now); producer.set_pictures(feed.wants_frames()); feed.set_stream(live, producer.frozen(now), producer.picture(now)); + feed.set_cluster_yield(video_yield_wanted()); feed.poll(now); if (fc.vpp_scale) producer.set_part(feed.part()); diff --git a/native/waze-on-cluster/src/map_feed.cpp b/native/waze-on-cluster/src/map_feed.cpp index a255acf9..daa676fe 100644 --- a/native/waze-on-cluster/src/map_feed.cpp +++ b/native/waze-on-cluster/src/map_feed.cpp @@ -97,6 +97,8 @@ MapFeed::MapFeed(const FeedConfig &cfg) void MapFeed::make_layer() { + if (yielded_) + return; part_ = OutputPart(); uint32_t tw = 0, th = 0; if (!target_size(client_.targets, cfg_.target, &tw, &th)) { @@ -326,6 +328,24 @@ void MapFeed::set_guide_hold(bool hold) } } +void MapFeed::set_yield_video(bool yield) +{ + if (yield == yielded_) + return; + yielded_ = yield; + log_info("render: map layer %s", yield ? "dropped: its video buffer given to another video on the cluster" + : "made again: the other video on the cluster is gone"); + if (yield) { + if (layer_) { + keep_newest(); + client_.drop(layer_); + layer_ = 0; + } + } else if (client_.connected() && !layer_) { + make_layer(); + } +} + void MapFeed::poll(int64_t now_ms) { client_.poll(now_ms); @@ -602,6 +622,10 @@ FeedStatus MapFeed::status(const std::string &decode, const std::string &stream) s.state = "idle"; /* no layer: nothing sent */ s.page = decode; s.reason = kHostHidden; + } else if (yielded_) { + s.state = "idle"; /* no layer: its buffer given to another video on the cluster */ + s.page = decode; + s.reason = "another video on the cluster (Turn View)"; } else if (layer_state_ == "shown") { s.state = "showing"; char p[400]; diff --git a/native/waze-on-cluster/src/map_feed.h b/native/waze-on-cluster/src/map_feed.h index 41b9e7cb..4ad0dafe 100644 --- a/native/waze-on-cluster/src/map_feed.h +++ b/native/waze-on-cluster/src/map_feed.h @@ -166,6 +166,9 @@ class MapFeed { /* The layer's guide_hold from now on. */ void set_guide_hold(bool hold); + /* True: no layer, its video buffer free for another video on the cluster (Turn View's camera); its newest + * picture kept and the layer made again with it once false. */ + void set_yield_video(bool yield); const std::string &target() const { return cfg_.target; } /* The HUD map's size (FeedConfig::hud_width_pct), applied at once to a * map on the HUD. */ @@ -264,6 +267,7 @@ class MapFeed { cr::Client client_; cr::Host host_; /* the feed's target's host, from the renderer's events */ uint32_t layer_ = 0; + bool yielded_ = false; /* set_yield_video */ cr::LayerOptions lo_; /* the layer's options as last sent */ bool show_due_ = false; /* visible once the frame waiting has gone */ /* The newest frame, while held_new_; on a layer that scales, once there diff --git a/native/waze-on-cluster/src/map_feeds.cpp b/native/waze-on-cluster/src/map_feeds.cpp index cfd4f318..b8ec41ff 100644 --- a/native/waze-on-cluster/src/map_feeds.cpp +++ b/native/waze-on-cluster/src/map_feeds.cpp @@ -39,6 +39,7 @@ void MapFeeds::follow() * KOMBI shows its own content again */ if (cluster_on_) { cluster_.reset(new MapFeed(base_)); + cluster_->set_yield_video(cluster_yield_); cluster_->set_stream(live_, frozen_, picture_); if (hud_ && hud_->latest(©_)) cluster_->hold(©_, id_); @@ -100,6 +101,13 @@ void MapFeeds::set_hud_keep_shown(bool keep) hud_->set_hud_keep_shown(keep); } +void MapFeeds::set_cluster_yield(bool yield) +{ + cluster_yield_ = yield; + if (cluster_) + cluster_->set_yield_video(yield); +} + void MapFeeds::set_guide_hold(bool hold) { base_.guide_hold = hold; diff --git a/native/waze-on-cluster/src/map_feeds.h b/native/waze-on-cluster/src/map_feeds.h index 92ad6a45..0d8ada96 100644 --- a/native/waze-on-cluster/src/map_feeds.h +++ b/native/waze-on-cluster/src/map_feeds.h @@ -66,6 +66,8 @@ class MapFeeds { int hud_offset_y() const { return base_.hud_offset_y; } /* The cluster map layer's guide_hold. */ void set_guide_hold(bool hold); + /* The cluster map's video buffer given up while another video is on the cluster (MapFeed::set_yield_video). */ + void set_cluster_yield(bool yield); /* For poll(): one entry per feed, appended. */ size_t poll_fds(std::vector *fds) const; @@ -100,6 +102,7 @@ class MapFeeds { FeedConfig base_; unsigned hud_fps_; bool cluster_on_, hud_on_; + bool cluster_yield_ = false; std::unique_ptr cluster_, hud_; std::vector copy_; /* a picture on its way from one feed to the other */ uint64_t id_ = 0; /* the newest frame's */ diff --git a/native/waze-on-cluster/test/map_feed_test.cpp b/native/waze-on-cluster/test/map_feed_test.cpp index 726e7013..22f8764c 100644 --- a/native/waze-on-cluster/test/map_feed_test.cpp +++ b/native/waze-on-cluster/test/map_feed_test.cpp @@ -299,6 +299,22 @@ static void guide_hold() } +/* Another video on the cluster (Turn View's camera): the map's layer dropped, its buffer free; back, the layer made + * again and the map showing with the next frame. */ +static void yield_video() +{ + const std::vector f = atlas(7); + Rig r(false, 6000, true); + r.pump(1500, &f); + ok("yield: the map showing first", r.st().state == "showing"); + r.feed->set_yield_video(true); + r.pump(500, &f); + ok("yield: no layer, the map not showing", !r.feed->takes_frames() && r.st().state != "showing"); + r.feed->set_yield_video(false); + r.pump(1500, &f); + ok("yield over: the layer made again, the map showing", r.feed->takes_frames() && r.st().state == "showing"); +} + /* The HUD's worker is still scaling a frame: the feed then asks to be woken * in kScaleWaitMs however much later it is asked, while a frame due in * kScaleWaitMs asks for a millisecond less a millisecond later. */ @@ -959,6 +975,7 @@ int main() signal(SIGPIPE, SIG_IGN); setvbuf(stdout, nullptr, _IONBF, 0); hosting(); + yield_video(); vpp_hosting(); always_packed_map(); old_renderer();