Skip to content

Commit ee9fe32

Browse files
authored
Merge pull request labgrid-project#759 from jluebbe/macrosilicon-video
driver/usbvideodriver: add basic MacroSilicon USB Video support
2 parents 306726b + 1006f75 commit ee9fe32

2 files changed

Lines changed: 33 additions & 10 deletions

File tree

labgrid/driver/usbvideodriver.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ def get_qualities(self):
2828
("mid", "image/jpeg,width=1280,height=720,framerate=15/2"),
2929
("high", "image/jpeg,width=1920,height=1080,framerate=10/1"),
3030
])
31+
if match == (0x534d, 0x2109): # MacroSilicon
32+
return ("mid", [
33+
("low", "image/jpeg,width=720,height=480,framerate=10/1"),
34+
("mid", "image/jpeg,width=1280,height=720,framerate=10/1"),
35+
("high", "image/jpeg,width=1920,height=1080,framerate=10/1"),
36+
])
3137
raise InvalidConfigError("Unkown USB video device {:04x}:{:04x}".format(*match))
3238

3339
def select_caps(self, hint=None):
@@ -39,23 +45,37 @@ def select_caps(self, hint=None):
3945
raise InvalidConfigError("Unkown video format {} for device {:04x}:{:04x}".format(
4046
variant, self.video.vendor_id, self.video.model_id))
4147

42-
def get_pipeline(self):
48+
def get_pipeline(self, path, caps, controls=None):
4349
match = (self.video.vendor_id, self.video.model_id)
4450
if match == (0x046d, 0x082d):
45-
return "v4l2src device={} ! {} ! h264parse ! fdsink"
46-
if match == (0x046d, 0x0892):
47-
return "v4l2src device={} ! {} ! decodebin ! vaapipostproc ! vaapih264enc ! h264parse ! fdsink" # pylint: disable=line-too-long
48-
raise InvalidConfigError("Unkown USB video device {:04x}:{:04x}".format(*match))
51+
controls = controls or "focus_auto=1"
52+
inner = "h264parse"
53+
elif match == (0x046d, 0x0892):
54+
controls = controls or "focus_auto=1"
55+
inner = None
56+
elif match == (0x534d, 0x2109):
57+
inner = None # just forward the jpeg frames
58+
else:
59+
raise InvalidConfigError("Unkown USB video device {:04x}:{:04x}".format(*match))
60+
61+
pipeline = f"v4l2src device={path} "
62+
if controls:
63+
pipeline += f"extra-controls=c,{controls} "
64+
pipeline += f"! {caps} "
65+
if inner:
66+
pipeline += f"! {inner} "
67+
pipeline += "! matroskamux streamable=true ! fdsink"
68+
return pipeline
4969

5070
@Driver.check_active
51-
def stream(self, caps_hint=None):
71+
def stream(self, caps_hint=None, controls=None):
5272
caps = self.select_caps(caps_hint)
53-
pipeline = self.get_pipeline()
73+
pipeline = self.get_pipeline(self.video.path, caps, controls)
5474

5575
tx_cmd = self.video.command_prefix + ["gst-launch-1.0", "-q"]
56-
tx_cmd += pipeline.format(self.video.path, caps).split()
76+
tx_cmd += pipeline.split()
5777
rx_cmd = ["gst-launch-1.0"]
58-
rx_cmd += "fdsrc ! h264parse ! avdec_h264 ! glimagesink sync=false".split()
78+
rx_cmd += "playbin uri=fd://0".split()
5979

6080
tx = subprocess.Popen(
6181
tx_cmd,

labgrid/remote/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,7 @@ def telnet(self):
11591159
def video(self):
11601160
place = self.get_acquired_place()
11611161
quality = self.args.quality
1162+
controls = self.args.controls
11621163
target = self._get_target(place)
11631164
from ..driver.usbvideodriver import USBVideoDriver
11641165
from ..driver.httpvideodriver import HTTPVideoDriver
@@ -1192,7 +1193,7 @@ def video(self):
11921193
mark = '*' if default == name else ' '
11931194
print("{} {:<10s} {:s}".format(mark, name, caps))
11941195
else:
1195-
drv.stream(quality)
1196+
drv.stream(quality, controls=controls)
11961197

11971198
def audio(self):
11981199
place = self.get_acquired_place()
@@ -1703,6 +1704,8 @@ def main():
17031704
help="start a video stream")
17041705
subparser.add_argument('-q', '--quality', type=str,
17051706
help="select a video quality (use 'list' to show options)")
1707+
subparser.add_argument('-c', '--controls', type=str,
1708+
help="configure v4l controls (such as 'focus_auto=0,focus_absolute=40')")
17061709
subparser.set_defaults(func=ClientSession.video)
17071710

17081711
subparser = subparsers.add_parser('audio', help="start a audio stream")

0 commit comments

Comments
 (0)