Skip to content

Commit

Permalink
[OAV - Video] - Made restarting of video stream more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-oscarsson committed Apr 3, 2024
1 parent 48fdace commit 941379c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
31 changes: 19 additions & 12 deletions mxcubecore/HardwareObjects/TangoLimaMpegVideo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Class for streaming MPEG1 video with cameras connected to
Class for streaming MPEG1 video with cameras connected to
Lima Tango Device Servers
Example configuration:
Expand All @@ -12,6 +12,7 @@
<video_mode>RGB24</video_mode>
</device>
"""

import os
import subprocess
import uuid
Expand All @@ -29,6 +30,7 @@ def __init__(self, name):
self.stream_hash = str(uuid.uuid1())
self._quality_str = "High"
self._QUALITY_STR_TO_INT = {"High": 4, "Medium": 10, "Low": 20, "Adaptive": -1}
self._port = 8000

def init(self):
super().init()
Expand Down Expand Up @@ -73,12 +75,12 @@ def start_video_stream_process(self, port):
self._video_stream_process = subprocess.Popen(
[
"video-streamer",
"-tu",
"-uri",
self.get_property("tangoname").strip(),
"-hs",
"localhost",
"-p",
str(port),
str(self._port),
"-q",
str(self._quality),
"-s",
Expand All @@ -96,27 +98,32 @@ def start_video_stream_process(self, port):

def stop_streaming(self):
if self._video_stream_process:
ps = psutil.Process(self._video_stream_process.pid).children() + [
self._video_stream_process
]

for p in ps:
p.kill()
try:
ps = [self._video_stream_process] + psutil.Process(
self._video_stream_process.pid
).children()
for p in ps:
p.kill()
except psutil.NoSuchProcess:
pass

self._video_stream_process = None

def start_streaming(self, _format=None, size=(0, 0), port="4042"):
def start_streaming(self, _format=None, size=(0, 0), port=None):
if _format:
self._format = _format

if port:
self._port = port

if not size[0]:
_s = self.get_width(), self.get_height()
else:
_s = size

self.set_stream_size(_s[0], _s[1])
self.start_video_stream_process(port)
self.start_video_stream_process(self._port)

def restart_streaming(self, size):
self.stop_streaming()
self.start_streaming(self._format)
self.start_streaming(self._format, size=size)
2 changes: 1 addition & 1 deletion mxcubecore/HardwareObjects/mockup/MDCameraMockup.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def start_video_stream_process(self, size):
"-hs",
"localhost",
"-p",
self._port,
str(self._port),
"-of",
self._format,
"-q",
Expand Down

0 comments on commit 941379c

Please sign in to comment.