Skip to content

Commit 6dbf096

Browse files
committed
USBVideoDriver: add screenshot function
Useful to create screenshots for regression testing. Signed-off-by: Rouven Czerwinski <[email protected]>
1 parent 71fe895 commit 6dbf096

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

labgrid/driver/usbvideodriver.py

+43
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pathlib
12
import subprocess
23

34
import attr
@@ -170,3 +171,45 @@ def stream(self, caps_hint=None, controls=None):
170171

171172
rx.communicate()
172173
tx.communicate()
174+
175+
@Driver.check_active
176+
def screenshot(self, filename, caps_hint=None, controls=None):
177+
assert isinstance(filename, str)
178+
179+
filepath = pathlib.Path(filename)
180+
caps = self.select_caps(caps_hint)
181+
pipeline = self.get_pipeline(self.video.path, caps, controls)
182+
183+
tx_cmd = self.video.command_prefix + ["gst-launch-1.0", "-q"]
184+
tx_cmd += pipeline.split()
185+
rx_cmd = ["gst-launch-1.0", "fdsrc", " num-buffers=75", "!", "jpegdec", "!", "jpegenc", "!", "filesink", f"location={filepath.absolute()}"]
186+
187+
tx = subprocess.Popen(
188+
tx_cmd,
189+
stdin=subprocess.DEVNULL,
190+
stdout=subprocess.PIPE,
191+
)
192+
rx = subprocess.Popen(
193+
rx_cmd,
194+
stdin=tx.stdout,
195+
stdout=subprocess.DEVNULL,
196+
)
197+
198+
# wait until one subprocess has terminated
199+
while True:
200+
try:
201+
tx.wait(timeout=0.1)
202+
break
203+
except subprocess.TimeoutExpired:
204+
pass
205+
try:
206+
rx.wait(timeout=0.1)
207+
break
208+
except subprocess.TimeoutExpired:
209+
pass
210+
211+
rx.terminate()
212+
tx.terminate()
213+
214+
rx.communicate()
215+
tx.communicate()

0 commit comments

Comments
 (0)