Skip to content

Commit fcbffc8

Browse files
committed
Allow kvmd-otg to enable audio capture with UAC2.
Along with pikvm/ustreamer#304 this allows audio capture with hdmiusb devices and HDMI->CSI Bridges without adding any more cables.
1 parent b3d1291 commit fcbffc8

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

kvmd/apps/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ def _get_config_scheme() -> dict:
629629
"audio": {
630630
"enabled": Option(False, type=valid_bool),
631631
"start": Option(True, type=valid_bool),
632+
"enable_audio_capture": Option(False, type=valid_bool),
632633
},
633634

634635
"drives": {

kvmd/apps/otg/__init__.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,25 @@ def __init__(self, gadget_path: str, profile_path: str, meta_path: str, eps: int
112112
self.__msd_instance = 0
113113
_mkdir(meta_path)
114114

115-
def add_audio_mic(self, start: bool) -> None:
115+
def add_audio_devices(self, start: bool, enable_capture: bool) -> None:
116116
eps = 2
117117
func = "uac2.usb0"
118118
func_path = self.__create_function(func)
119-
_write(join(func_path, "c_chmask"), 0)
119+
120+
if enable_capture:
121+
_write(join(func_path, "c_chmask"), 0b11)
122+
_write(join(func_path, "c_srate"), 48000)
123+
_write(join(func_path, "c_ssize"), 2)
124+
else:
125+
_write(join(func_path, "c_chmask"), 0)
126+
120127
_write(join(func_path, "p_chmask"), 0b11)
121128
_write(join(func_path, "p_srate"), 48000)
122129
_write(join(func_path, "p_ssize"), 2)
130+
123131
if start:
124132
self.__start_function(func, eps)
125-
self.__create_meta(func, "Microphone", eps)
133+
self.__create_meta(func, "USB Audio", eps)
126134

127135
def add_serial(self, start: bool) -> None:
128136
eps = 3
@@ -334,8 +342,8 @@ def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements,
334342
gc.add_serial(cod.serial.start)
335343

336344
if cod.audio.enabled:
337-
logger.info("===== Microphone =====")
338-
gc.add_audio_mic(cod.audio.start)
345+
logger.info("===== Audio Devices =====")
346+
gc.add_audio_devices(cod.audio.start, cod.audio.enable_audio_capture)
339347

340348
logger.info("===== Preparing complete =====")
341349

0 commit comments

Comments
 (0)