Skip to content

Commit

Permalink
Allow kvmd-otg to enable audio capture with UAC2.
Browse files Browse the repository at this point in the history
Along with pikvm/ustreamer#304 this
allows audio capture with hdmiusb devices and HDMI->CSI Bridges without adding any more cables.
  • Loading branch information
shantur committed Feb 16, 2025
1 parent b3d1291 commit e238ee7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions kvmd/apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ def _get_config_scheme() -> dict:
"audio": {
"enabled": Option(False, type=valid_bool),
"start": Option(True, type=valid_bool),
"enable_audio_capture": Option(False, type=valid_bool),
},

"drives": {
Expand Down
15 changes: 10 additions & 5 deletions kvmd/apps/otg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,22 @@ def __init__(self, gadget_path: str, profile_path: str, meta_path: str, eps: int
self.__msd_instance = 0
_mkdir(meta_path)

def add_audio_mic(self, start: bool) -> None:
def add_audio_devices(self, start: bool, enable_capture: bool) -> None:
eps = 2
func = "uac2.usb0"
func_path = self.__create_function(func)
_write(join(func_path, "c_chmask"), 0)
if enable_capture:
_write(join(func_path, "c_chmask"), 0b11)
_write(join(func_path, "c_srate"), 48000)
_write(join(func_path, "c_ssize"), 2)
else:
_write(join(func_path, "c_chmask"), 0)
_write(join(func_path, "p_chmask"), 0b11)
_write(join(func_path, "p_srate"), 48000)
_write(join(func_path, "p_ssize"), 2)
if start:
self.__start_function(func, eps)
self.__create_meta(func, "Microphone", eps)
self.__create_meta(func, "USB Audio", eps)

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

if cod.audio.enabled:
logger.info("===== Microphone =====")
gc.add_audio_mic(cod.audio.start)
logger.info("===== Audio Devices =====")
gc.add_audio_devices(cod.audio.start, cod.audio.enable_audio_capture)

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

Expand Down

0 comments on commit e238ee7

Please # to comment.