From 8c92ab6f4760e6f45475532425fba855bc9c5887 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Tue, 26 Mar 2024 22:20:08 +0200 Subject: [PATCH] ustreamer: blank drm output by timeout --- src/ustreamer/stream.c | 28 +++++++++++++++++++++++----- src/ustreamer/stream.h | 1 + 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/ustreamer/stream.c b/src/ustreamer/stream.c index 7c5e7cfc..f71fba7f 100644 --- a/src/ustreamer/stream.c +++ b/src/ustreamer/stream.c @@ -652,18 +652,36 @@ static int _stream_init_loop(us_stream_s *stream) { #ifdef WITH_V4P static void _stream_drm_ensure_no_signal(us_stream_s *stream) { us_stream_runtime_s *const run = stream->run; + if (!stream->v4p) { return; } + +# define CHECK(x_arg) if ((x_arg) < 0) { goto close; } if (run->drm_opened <= 0) { us_drm_close(run->drm); - run->drm_opened = us_drm_open(run->drm, NULL); + run->drm_blank_at_ts = 0; + CHECK(run->drm_opened = us_drm_open(run->drm, NULL)); } - if (run->drm_opened > 0) { - if (us_drm_wait_for_vsync(run->drm) == 0) { - us_drm_expose_stub(run->drm, US_DRM_STUB_NO_SIGNAL, NULL); - } + + ldf now_ts = us_get_now_monotonic(); + if (run->drm_blank_at_ts == 0) { + run->drm_blank_at_ts = now_ts + 5; } + + if (now_ts <= run->drm_blank_at_ts) { + CHECK(us_drm_wait_for_vsync(run->drm)); + CHECK(us_drm_expose_stub(run->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(run->drm)); + } + return; +# undef CHECK + +close: + us_drm_close(run->drm); + run->drm_opened = -1; } #endif diff --git a/src/ustreamer/stream.h b/src/ustreamer/stream.h index 70891ce9..e51fde19 100644 --- a/src/ustreamer/stream.h +++ b/src/ustreamer/stream.h @@ -46,6 +46,7 @@ typedef struct { # ifdef WITH_V4P us_drm_s *drm; int drm_opened; + ldf drm_blank_at_ts; # endif us_ring_s *http_jpeg_ring;