@@ -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 ,
0 commit comments