Skip to content

Commit

Permalink
#3964 implement 'save-to-file' so we can inspect the stream
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Mar 26, 2024
1 parent 31f1590 commit d8ae699
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion xpra/codecs/gstreamer/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit d8ae699

Please sign in to comment.