Skip to content

Commit e238ee7

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 e238ee7

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

kvmd/apps/__init__.py

Lines changed: 1 addition & 0 deletions
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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,22 @@ 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+
if enable_capture:
120+
_write(join(func_path, "c_chmask"), 0b11)
121+
_write(join(func_path, "c_srate"), 48000)
122+
_write(join(func_path, "c_ssize"), 2)
123+
else:
124+
_write(join(func_path, "c_chmask"), 0)
120125
_write(join(func_path, "p_chmask"), 0b11)
121126
_write(join(func_path, "p_srate"), 48000)
122127
_write(join(func_path, "p_ssize"), 2)
123128
if start:
124129
self.__start_function(func, eps)
125-
self.__create_meta(func, "Microphone", eps)
130+
self.__create_meta(func, "USB Audio", eps)
126131

127132
def add_serial(self, start: bool) -> None:
128133
eps = 3
@@ -334,8 +339,8 @@ def _cmd_start(config: Section) -> None: # pylint: disable=too-many-statements,
334339
gc.add_serial(cod.serial.start)
335340

336341
if cod.audio.enabled:
337-
logger.info("===== Microphone =====")
338-
gc.add_audio_mic(cod.audio.start)
342+
logger.info("===== Audio Devices =====")
343+
gc.add_audio_devices(cod.audio.start, cod.audio.enable_audio_capture)
339344

340345
logger.info("===== Preparing complete =====")
341346

0 commit comments

Comments
 (0)