Skip to content

Commit f329da8

Browse files
Removed integrated MJPEG streamer
1 parent 74dd01c commit f329da8

File tree

7 files changed

+7
-134
lines changed

7 files changed

+7
-134
lines changed

demo.yaml/mxcube-web/server.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ sso:
2222
CODE_CHALLANGE_METHOD: S256
2323

2424
mxcube:
25-
USE_EXTERNAL_STREAMER: true
2625
VIDEO_FORMAT: MPEG1
2726
VIDEO_STREAM_URL: ws://localhost:8000/ws
2827

demo/mxcube-web/server.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ sso:
5959
CODE_CHALLANGE_METHOD: S256
6060

6161
mxcube:
62-
USE_EXTERNAL_STREAMER: true
6362
VIDEO_FORMAT: MPEG1
6463
VIDEO_STREAM_URL: ws://localhost:8000/ws
6564

docs/source/config/server.rst

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ The section has the following syntax:
172172
173173
mxcube:
174174
mode: <experiment mode>
175-
USE_EXTERNAL_STREAMER: <boolean>
176175
VIDEO_FORMAT: <format name>
177176
VIDEO_STREAM_URL: <stream URL>
178177
VIDEO_STREAM_PORT: <stream port>
@@ -206,15 +205,8 @@ The following values are supported:
206205

207206
Default mode is ``OSC``.
208207

209-
``USE_EXTERNAL_STREAMER``
210208
~~~~~~~~~~~~~~~~~~~~~~~~~
211209

212-
Use an external process to stream the sample view video.
213-
When enabled, MXCuBE will invoke an appropriate hook on the camera hardware object to start the streamer.
214-
It is assumed that the camera object supports the external streamer feature.
215-
216-
Default value is ``False``.
217-
218210
``VIDEO_FORMAT``
219211
~~~~~~~~~~~~~~~~
220212

@@ -226,18 +218,12 @@ Default format is ``MPEG1``.
226218

227219
``VIDEO_STREAM_URL``
228220
~~~~~~~~~~~~~~~~~~~~
229-
230-
The URL that is used by the UI to fetch the sample view video.
231-
When set, it will override the default video stream URL.
232-
This configuration is primarily useful with external streams,
233-
that provide video stream from custom URLs.
221+
The URL from which the video stream is served. This URL is used by the front-end to
222+
connect to the video stream.
234223

235224
``VIDEO_STREAM_PORT``
236225
~~~~~~~~~~~~~~~~~~~~~
237-
238-
This configuration is used when ``USE_EXTERNAL_STREAMER`` flag is enabled.
239-
The specified value is passed on to the camera hardware object,
240-
when invoking the start stream hook.
226+
Port from which the video stream is served
241227

242228
``SESSION_REFRESH_INTERVAL``
243229
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

mxcubeweb/app.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,10 @@ def init(
148148

149149
MXCUBEApplication.mxcubecore.init()
150150

151-
if cfg.app.USE_EXTERNAL_STREAMER:
152-
MXCUBEApplication.init_sample_video(
153-
_format=cfg.app.VIDEO_FORMAT,
154-
port=cfg.app.VIDEO_STREAM_PORT,
155-
)
151+
MXCUBEApplication.init_sample_video(
152+
_format=cfg.app.VIDEO_FORMAT,
153+
port=cfg.app.VIDEO_STREAM_PORT,
154+
)
156155

157156
MXCUBEApplication.init_logging(log_fpath, log_level, enabled_logger_list)
158157

mxcubeweb/core/components/sampleview.py

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import logging
2-
from io import StringIO
32

43
import gevent.event
5-
import PIL
6-
from flask import Response
74
from mxcubecore import HardwareRepository as HWR
85
from mxcubecore.queue_entry.base_queue_entry import CENTRING_METHOD
96

@@ -17,88 +14,12 @@
1714
SNAPSHOT = None
1815

1916

20-
class HttpStreamer:
21-
"""
22-
Implements 'MJPEG' streaming from the sample view camera.
23-
24-
Provides get_response() method, that creates a Response object,
25-
that will stream JPEG images from the sample view camera,
26-
in 'multipart' HTTP response format.
27-
"""
28-
29-
def __init__(self):
30-
self._new_frame = gevent.event.Event()
31-
self._sample_image = None
32-
self._clients = 0
33-
34-
def _client_connected(self):
35-
if self._clients == 0:
36-
# first client connected,
37-
# start listening to frames from sample camera
38-
HWR.beamline.sample_view.camera.connect(
39-
"imageReceived", self._new_frame_received
40-
)
41-
42-
self._clients += 1
43-
44-
def _client_disconnected(self):
45-
self._clients -= 1
46-
if self._clients == 0:
47-
# last client disconnected,
48-
# disconnect from the sample camera
49-
HWR.beamline.sample_view.camera.disconnect(
50-
"imageReceived", self._new_frame_received
51-
)
52-
53-
def _new_frame_received(self, img, width, height, *args, **kwargs):
54-
if not isinstance(img, str | bytes):
55-
rawdata = img.bits().asstring(img.numBytes())
56-
strbuf = StringIO()
57-
image = PIL.Image.frombytes("RGBA", (width, height), rawdata)
58-
(r, g, b, a) = image.split()
59-
image = PIL.Image.merge("RGB", (b, g, r))
60-
image.save(strbuf, "JPEG")
61-
img = strbuf.get_value()
62-
63-
self._sample_image = img
64-
65-
# signal clients that there is a new frame available
66-
self._new_frame.set()
67-
self._new_frame.clear()
68-
69-
def get_response(self) -> Response:
70-
"""
71-
build new Response object, that will send frames to the client
72-
"""
73-
74-
def frames():
75-
while True:
76-
self._new_frame.wait()
77-
yield (
78-
b"--frame\r\n--!>\nContent-type: image/jpeg\n\n"
79-
+ self._sample_image
80-
+ b"\r\n"
81-
)
82-
83-
self._client_connected()
84-
85-
response = Response(
86-
frames(),
87-
mimetype='multipart/x-mixed-replace; boundary="!>"',
88-
)
89-
# keep track of when client stops reading the stream
90-
response.call_on_close(self._client_disconnected)
91-
92-
return response
93-
94-
9517
class SampleView(ComponentBase):
9618
def __init__(self, app, config):
9719
super().__init__(app, config)
9820
self._click_count = 0
9921
self._click_limit = 3
10022
self._centring_point_id = None
101-
self.http_streamer = HttpStreamer()
10223

10324
HWR.beamline.sample_view.connect("shapesChanged", self._emit_shapes_updated)
10425

mxcubeweb/core/models/configmodels.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,6 @@ class MXCUBEAppConfigModel(BaseModel):
211211
# Port from which the video_stream process (https://github.com/mxcube/video-streamer)
212212
# streams video. The process runs in separate process (on localhost)
213213
VIDEO_STREAM_PORT: int = Field(8000, description="Video stream PORT")
214-
USE_EXTERNAL_STREAMER: bool = Field(
215-
False,
216-
description=(
217-
"True to use video stream produced by external software, false otherwise"
218-
),
219-
)
220214
USE_GET_SAMPLES_FROM_SC: bool = Field(
221215
True,
222216
description=(

mxcubeweb/routes/samplecentring.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,6 @@
1616
def init_route(app, server, url_prefix): # noqa: C901
1717
bp = Blueprint("sampleview", __name__, url_prefix=url_prefix)
1818

19-
@bp.route("/camera/subscribe", methods=["GET"])
20-
@server.restrict
21-
def subscribe_to_camera():
22-
"""
23-
Subscribe to the camera streaming
24-
:response: image as html Content-type
25-
"""
26-
if app.CONFIG.app.VIDEO_FORMAT == "MPEG1":
27-
result = Response(status=200)
28-
else:
29-
result = app.sample_view.http_streamer.get_response()
30-
31-
return result
32-
33-
@bp.route("/camera/unsubscribe", methods=["PUT"])
34-
@server.restrict
35-
def unsubscribe_to_camera():
36-
"""
37-
SampleCentring: unsubscribe from the camera streaming
38-
:statuscode: 200: no error
39-
:statuscode: 409: error
40-
"""
41-
HWR.beamline.sample_view.camera.streaming_greenlet.kill()
42-
return Response(status=200)
43-
4419
@bp.route("/camera/snapshot", methods=["POST"])
4520
@server.restrict
4621
def snapshot():

0 commit comments

Comments
 (0)