28
28
wserver = Flask (__name__ )
29
29
dependencies = []
30
30
stream_sources = ["static-images" , "v4l2" , "vnc-browser" ]
31
+ sway_socket_path = "/tmp/sway.sock"
31
32
cmds = {"clock" : "humanbeans_clock" ,
32
33
"image_viewer" : "imv" ,
33
34
"media_player" : "mpv" ,
@@ -76,7 +77,7 @@ def display_screenshot():
76
77
fn = display .screenshot ()
77
78
if not os .path .isfile (fn ):
78
79
logging .error ("screenshot: File {} does not exist" .format (fn ))
79
- return False
80
+ # return False
80
81
return send_file (fn , mimetype = 'image/png' )
81
82
82
83
def which (cmd ):
@@ -380,28 +381,28 @@ def __init__(self, stream_source):
380
381
if stream_source == "v4l2" :
381
382
# Start streaming
382
383
logging .info ("Setting up source" )
383
- stream_create_v4l2_src (stream_source_device )
384
+ self . stream_create_v4l2_src (stream_source_device )
384
385
logging .info ("Setting up stream" )
385
386
time .sleep (3 )
386
- stream_v4l2_ffmpeg ()
387
- #gst = stream_setup_gstreamer(stream_source,
387
+ self . stream_v4l2_ffmpeg ()
388
+ #gst = self. stream_setup_gstreamer(stream_source,
388
389
# stream_source_device,
389
390
# local_ip,
390
391
# listen_port)
391
392
#gst.stdin.close()
392
393
#gst.wait()
393
394
394
395
elif stream_source == "static-images" :
395
- gst = stream_setup_gstreamer (stream_source ,
396
+ gst = self . stream_setup_gstreamer (stream_source ,
396
397
stream_source_device ,
397
398
local_ip ,
398
399
listen_port )
399
400
400
- gst_stream_images (gst , img_path )
401
+ self . gst_stream_images (gst , img_path )
401
402
gst .stdin .close ()
402
403
gst .wait ()
403
404
404
- def stream_setup_gstreamer (stream_source , source_device , ip , port ):
405
+ def stream_setup_gstreamer (self , stream_source , source_device , ip , port ):
405
406
if stream_source == "static-images" :
406
407
gstreamer = subprocess .Popen ([
407
408
'gst-launch-1.0' , '-v' , '-e' ,
@@ -427,16 +428,16 @@ def stream_setup_gstreamer(stream_source, source_device, ip, port):
427
428
428
429
return gstreamer
429
430
430
- def gst_stream_images (gstreamer , img_path , debug = False ):
431
+ def gst_stream_images (self , gstreamer , img_path , debug = False ):
431
432
t0 = int (round (time .time () * 1000 ))
432
433
n = - 1
433
434
434
435
while True :
435
- filename = img_path + '/image_' + str (0 ).zfill (4 ) + '.png'
436
+ #filename = img_path + '/image_' + str(0).zfill(4) + '.png'
437
+ filename = '/tmp/screenshot.png'
436
438
t1 = int (round (time .time () * 1000 ))
437
439
438
- if debug :
439
- logging .debug (filename + ": " + str (t1 - t0 ) + " ms" )
440
+ logging .debug (filename + ": " + str (t1 - t0 ) + " ms" )
440
441
441
442
t0 = t1
442
443
@@ -460,7 +461,7 @@ def gst_stream_images(gstreamer, img_path, debug=False):
460
461
else :
461
462
n += 1
462
463
463
- def stream_create_v4l2_src (device ):
464
+ def stream_create_v4l2_src (self , device ):
464
465
# Check if device is an existing character device
465
466
if not stat .S_ISCHR (os .lstat (device )[stat .ST_MODE ]):
466
467
logging .error (device + " does not exist, aborting.." )
@@ -484,16 +485,12 @@ def stream_create_v4l2_src(device):
484
485
485
486
return True
486
487
487
-
488
- def stream_v4l2_ffmpeg ():
488
+ def stream_v4l2_ffmpeg (self ):
489
489
ffmpeg = subprocess .Popen ([
490
490
'ffmpeg' , '-f' , 'v4l2' , '-i' , '/dev/video0' ,
491
491
'-codec' , 'copy' ,
492
- '-f' , 'mpegts' , 'udp:localhost:6000'
493
- ],
494
- stdin = subprocess .PIPE ,
495
- start_new_session = True ,
496
- close_fds = False )
492
+ '-f' , 'mpegts' , 'udp:0.0.0.0:6000'
493
+ ])
497
494
498
495
499
496
class News :
@@ -676,7 +673,7 @@ def get_windows_whitelist(self):
676
673
return windows
677
674
678
675
def get_windows (self , blacklist = None ):
679
- cmd = "swaymsg -t get_tree"
676
+ cmd = "swaymsg -s {} - t get_tree" . format ( sway_socket_path )
680
677
windows = []
681
678
682
679
p = subprocess .Popen (cmd ,
@@ -727,7 +724,7 @@ def workspace_nodes(self, workspace):
727
724
return windows
728
725
729
726
def active_window ():
730
- cmd = 'swaymsg -t get_tree) | jq ".. | select(.type?) | select(.focused==true).id"'
727
+ cmd = 'swaymsg -s {} - t get_tree) | jq ".. | select(.type?) | select(.focused==true).id"' . format ( sway_socket_path )
731
728
732
729
async def focus_next_window (self ):
733
730
await asyncio .sleep (random .random () * 3 )
@@ -743,7 +740,7 @@ async def focus_next_window(self):
743
740
744
741
next_window = self .switching_windows .pop ()
745
742
logging .info ("display: Switching focus to: " .format (next_window ["id" ]))
746
- cmd = "swaymsg [con_id={}] focus" .format (next_window ["id" ])
743
+ cmd = "swaymsg -s sway_socket_path [con_id={}] focus" .format (next_window ["id" ], sway_socket_path )
747
744
748
745
p = subprocess .Popen (cmd ,
749
746
shell = True )
@@ -765,7 +762,7 @@ async def fullscreen_next_window(self):
765
762
next_window = self .switching_windows .pop ()
766
763
logging .info ("display: Switching focus to: " .format (next_window ["id" ]))
767
764
768
- cmd = "swaymsg [con_id={}] fullscreen" .format (next_window ["id" ])
765
+ cmd = "swaymsg -s sway_socket_path [con_id={}] fullscreen" .format (next_window ["id" ], sway_socket_path )
769
766
770
767
p = subprocess .Popen (cmd ,
771
768
shell = True )
@@ -782,7 +779,7 @@ async def task_scheduler(self, interval_s, interval_function):
782
779
)
783
780
784
781
def switch_workspace (self ):
785
- cmd = "swaymsg workspace {}" .format (next_ws )
782
+ cmd = "swaymsg -s sway_socket_path workspace {}" .format (next_ws , sway_socket_path )
786
783
787
784
p = subprocess .Popen (cmd ,
788
785
shell = True ,
@@ -976,7 +973,7 @@ def __init__(self, threads):
976
973
sources_str = " " .join (str (x ) for x in stream_sources )
977
974
logging .error ("Invalid source, aborting.." )
978
975
logging .info ("Possible choices are: " + sources_str )
979
- sys .exit (1 )
976
+ # sys.exit(1)
980
977
981
978
hostname = socket .gethostname ()
982
979
local_ip = System .net_local_iface_address (probe_ip )
0 commit comments