Skip to content

Commit

Permalink
v4p: turn off the display after timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevaev committed Mar 10, 2024
1 parent c4cf4f0 commit 2d9e51a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/v4p/drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ int us_drm_dpms_power_off(us_drm_s *drm) {
assert(drm->run->fd >= 0);
switch (_drm_check_status(drm)) {
case 0: break;
case -2: return -2;
case -2: return 0; // Unplugged, nice
// Во время переключения DPMS монитор моргает один раз состоянием disconnected,
// а потом почему-то снова оказывается connected. Так что просто считаем,
// что отсоединенный монитор на этом этапе - это нормально.
default: return -1;
}
_drm_ensure_dpms_power(drm, false);
Expand Down
23 changes: 17 additions & 6 deletions src/v4p/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,36 +172,47 @@ static void _main_loop(void) {
dev->dma_required = true;

int once = 0;
ldf blank_at_ts = 0;
int drm_opened = -1;
while (!atomic_load(&_g_stop)) {
# define CHECK(x_arg) if ((x_arg) < 0) { goto close; }

if (drm_opened <= 0) {
blank_at_ts = 0;
CHECK(drm_opened = us_drm_open(drm, NULL));
}
assert(drm_opened > 0);

if (atomic_load(&_g_ustreamer_online)) {
US_ONCE({ US_LOG_ERROR("DRM: Online stream is active, stopping capture ..."); });
blank_at_ts = 0;
US_ONCE({ US_LOG_INFO("DRM: Online stream is active, stopping capture ..."); });
CHECK(us_drm_wait_for_vsync(drm));
CHECK(us_drm_expose_stub(drm, US_DRM_STUB_BUSY, NULL));
_slowdown();
continue;
}

if (us_device_open(dev) < 0) {
/*CHECK(us_drm_wait_for_vsync(drm));
CHECK(us_drm_expose_stub(drm, US_DRM_STUB_NO_SIGNAL, NULL));*/
CHECK(us_drm_dpms_power_off(drm));
ldf now_ts = us_get_now_monotonic();
if (blank_at_ts == 0) {
blank_at_ts = now_ts + 5;
}
if (now_ts <= blank_at_ts) {
CHECK(us_drm_wait_for_vsync(drm));
CHECK(us_drm_expose_stub(drm, US_DRM_STUB_NO_SIGNAL, NULL));
} else {
US_ONCE({ US_LOG_INFO("DRM: Turning off the display by timeout ..."); });
CHECK(us_drm_dpms_power_off(drm));
}
_slowdown();
continue;
}

once = 0;
blank_at_ts = 0;
us_drm_close(drm);
CHECK(drm_opened = us_drm_open(drm, dev));

once = 0;

us_hw_buffer_s *prev_hw = NULL;
while (!atomic_load(&_g_stop)) {
if (atomic_load(&_g_ustreamer_online)) {
Expand Down

0 comments on commit 2d9e51a

Please sign in to comment.