From d8ae699b4c5c9a70a8236d293e303707bcd59e39 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Tue, 26 Mar 2024 15:34:23 +0700 Subject: [PATCH] #3964 implement 'save-to-file' so we can inspect the stream --- xpra/codecs/gstreamer/capture.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/xpra/codecs/gstreamer/capture.py b/xpra/codecs/gstreamer/capture.py index f25e3fe7a0..456607e04b 100755 --- a/xpra/codecs/gstreamer/capture.py +++ b/xpra/codecs/gstreamer/capture.py @@ -8,7 +8,8 @@ from typing import Any from xpra.os_util import gi_import -from xpra.util.objects import typedict +from xpra.util.env import envbool +from xpra.util.objects import typedict, AtomicInteger from xpra.gstreamer.common import ( import_gst, GST_FLOW_OK, get_element_str, get_default_appsink_attributes, get_all_plugin_names, @@ -33,6 +34,10 @@ log(f"capture: {get_type()} {get_version()}, {init_module}, {cleanup_module}") +SAVE_TO_FILE = envbool("XPRA_SAVE_TO_FILE") + +generation = AtomicInteger() + class Capture(Pipeline): """ @@ -121,6 +126,10 @@ def refresh(self) -> bool: def clean(self) -> None: self.stop() + f = self.file + if f: + self.file = None + f.close() def get_type(self) -> str: return self.capture_element @@ -191,6 +200,7 @@ def create_pipeline(self, capture_element: str = "ximagesrc") -> None: raise RuntimeError("failed to setup gstreamer pipeline") self.sink: Gst.Element = self.pipeline.get_by_name("sink") self.capture = self.pipeline.get_by_name("capture") + self.file = None def sh(sig, handler): self.element_connect(self.sink, sig, handler) @@ -210,6 +220,14 @@ def on_new_sample(self, _bus) -> int: client_info["frame"] = self.frames self.extra_client_info = {} self.emit("new-image", self.pixel_format, data, client_info) + if SAVE_TO_FILE: + if not self.file: + encoding = self.pixel_format + gen = generation.increase() + filename = "gstreamer-" + str(gen) + f".{encoding}" + self.file = open(filename, "wb") + log.info(f"saving gstreamer {encoding} stream to {filename!r}") + self.file.write(data) return GST_FLOW_OK def on_new_preroll(self, _appsink) -> int: