Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions native/waze-on-cluster/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fcntl.h>
#include <poll.h>
#include <pthread.h>
#include <sys/signalfd.h>
#include <sys/stat.h>
#include <unistd.h>
#include <vector>

Expand Down Expand Up @@ -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) +
Expand Down Expand Up @@ -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());
Expand Down
24 changes: 24 additions & 0 deletions native/waze-on-cluster/src/map_feed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 4 additions & 0 deletions native/waze-on-cluster/src/map_feed.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions native/waze-on-cluster/src/map_feeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(&copy_))
cluster_->hold(&copy_, id_);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions native/waze-on-cluster/src/map_feeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<pollfd> *fds) const;
Expand Down Expand Up @@ -100,6 +102,7 @@ class MapFeeds {
FeedConfig base_;
unsigned hud_fps_;
bool cluster_on_, hud_on_;
bool cluster_yield_ = false;
std::unique_ptr<MapFeed> cluster_, hud_;
std::vector<uint8_t> copy_; /* a picture on its way from one feed to the other */
uint64_t id_ = 0; /* the newest frame's */
Expand Down
17 changes: 17 additions & 0 deletions native/waze-on-cluster/test/map_feed_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> 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. */
Expand Down Expand Up @@ -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();
Expand Down