Skip to content

Allow kvmd-otg to enable audio capture with UAC2. #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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