Skip to content

Commit 1006f75

Browse files
jluebbeEmantor
authored andcommitted
driver/usbvideodriver: add support for custom controls
This can be used to control the camera focus if needed. When no controls are specified, a default can be used. Signed-off-by: Jan Luebbe <jlu@pengutronix.de> [r.czerwinski@pengutronix.de: remove vaapi, pass controls for new cams] Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
1 parent b627215 commit 1006f75

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

labgrid/driver/usbvideodriver.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,35 @@ def select_caps(self, hint=None):
4545
raise InvalidConfigError("Unkown video format {} for device {:04x}:{:04x}".format(
4646
variant, self.video.vendor_id, self.video.model_id))
4747

48-
def get_pipeline(self):
48+
def get_pipeline(self, path, caps, controls=None):
4949
match = (self.video.vendor_id, self.video.model_id)
50-
transport = " ! matroskamux streamable=true ! fdsink"
5150
if match == (0x046d, 0x082d):
52-
return "v4l2src device={} ! {} ! h264parse" + transport
53-
if match == (0x046d, 0x0892):
54-
return "v4l2src device={} ! {} ! decodebin ! vaapipostproc ! vaapih264enc ! h264parse" + transport # pylint: disable=line-too-long
55-
if match == (0x534d, 0x2109):
56-
return "v4l2src device={} ! {}" + transport
57-
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
5869

5970
@Driver.check_active
60-
def stream(self, caps_hint=None):
71+
def stream(self, caps_hint=None, controls=None):
6172
caps = self.select_caps(caps_hint)
62-
pipeline = self.get_pipeline()
73+
pipeline = self.get_pipeline(self.video.path, caps, controls)
6374

6475
tx_cmd = self.video.command_prefix + ["gst-launch-1.0", "-q"]
65-
tx_cmd += pipeline.format(self.video.path, caps).split()
76+
tx_cmd += pipeline.split()
6677
rx_cmd = ["gst-launch-1.0"]
6778
rx_cmd += "playbin uri=fd://0".split()
6879

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)