Fix inhibit-sleep-for-audio.lisp
This commit is contained in:
@ -17,16 +17,17 @@
|
|||||||
(when *debug-output*
|
(when *debug-output*
|
||||||
(apply 'format t control-string args)))
|
(apply 'format t control-string args)))
|
||||||
|
|
||||||
(defun event-has-live-stream-p (event)
|
(defun event-stream-states (event)
|
||||||
"Return non-nil if EVENT has a live stream."
|
"Return a alist mapping ids to stream states."
|
||||||
(loop for obj across event
|
(loop for obj across event
|
||||||
for info = (gethash "info" obj)
|
for info = (gethash "info" obj)
|
||||||
when (and (hash-table-p info)
|
for id = (gethash "id" obj)
|
||||||
|
for running = (and (hash-table-p info)
|
||||||
(equal (gethash "type" obj) "PipeWire:Interface:Node")
|
(equal (gethash "type" obj) "PipeWire:Interface:Node")
|
||||||
(equal (gethash "state" info) "running")
|
(equal (gethash "state" info) "running")
|
||||||
(or (not (equal (gethash "n-input-ports" info) 0))
|
(or (not (equal (gethash "n-input-ports" info) 0))
|
||||||
(not (equal (gethash "n-output-ports" info) 0))))
|
(not (equal (gethash "n-output-ports" info) 0))))
|
||||||
do (return t)))
|
collect (cons id running)))
|
||||||
|
|
||||||
(defvar *inhibitor-process* nil
|
(defvar *inhibitor-process* nil
|
||||||
"The systemd-inhibit process object.")
|
"The systemd-inhibit process object.")
|
||||||
@ -54,14 +55,33 @@
|
|||||||
(setq *inhibitor-process* nil)
|
(setq *inhibitor-process* nil)
|
||||||
(debug-format "Stopped inhibitor process~%"))
|
(debug-format "Stopped inhibitor process~%"))
|
||||||
|
|
||||||
|
(defvar *running-streams* (make-hash-table :test #'eql)
|
||||||
|
"Hash table (set) of running streams. This maps ids to the symbol t.")
|
||||||
|
|
||||||
|
(defun have-running-streams-p ()
|
||||||
|
"Return non-nil if there are running streams."
|
||||||
|
(not (zerop (hash-table-count *running-streams*))))
|
||||||
|
|
||||||
(defun process-event (event)
|
(defun process-event (event)
|
||||||
"Process one event from pw-dump."
|
"Process one event from pw-dump."
|
||||||
(let ((has-live-stream (event-has-live-stream-p event)))
|
(let ((live-streams (event-stream-states event)))
|
||||||
|
(dolist (entry live-streams)
|
||||||
|
(destructuring-bind (id . state) entry
|
||||||
|
(if state
|
||||||
|
(progn
|
||||||
|
(when (not (gethash id *running-streams*))
|
||||||
|
(debug-format "Stream ~A started~%" id))
|
||||||
|
(setf (gethash id *running-streams*) t))
|
||||||
|
(progn
|
||||||
|
(when (gethash id *running-streams*)
|
||||||
|
(debug-format "Stream ~A stopped~%" id))
|
||||||
|
(remhash id *running-streams*)))))
|
||||||
|
(let ((has-live-stream (have-running-streams-p)))
|
||||||
(cond
|
(cond
|
||||||
((and has-live-stream (not (inhibitor-running-p)))
|
((and has-live-stream (not (inhibitor-running-p)))
|
||||||
(start-inhibitor))
|
(start-inhibitor))
|
||||||
((and (not has-live-stream) (inhibitor-running-p))
|
((and (not has-live-stream) (inhibitor-running-p))
|
||||||
(stop-inhibitor)))))
|
(stop-inhibitor))))))
|
||||||
|
|
||||||
(defun print-help-and-exit ()
|
(defun print-help-and-exit ()
|
||||||
"Print a help message and then exit."
|
"Print a help message and then exit."
|
||||||
|
Reference in New Issue
Block a user