Skip to content

RSDK-13833 Fix orin nano discovery spam#38

Merged
oliviamiller merged 4 commits intoviam-modules:mainfrom
oliviamiller:fix-discovery
May 4, 2026
Merged

RSDK-13833 Fix orin nano discovery spam#38
oliviamiller merged 4 commits intoviam-modules:mainfrom
oliviamiller:fix-discovery

Conversation

@oliviamiller
Copy link
Copy Markdown
Collaborator

@oliviamiller oliviamiller commented Apr 28, 2026

Filter unusable Tegra ADMAIFs in discovery; clamp channels to mono/stereo

On Jetson Orin Nano, discovery surfaced ~40 phantom devices because PortAudio enumerates all 20 ADMAIF DMA endpoints on the Tegra APE card as both speakers and mics, even though most aren't wired to any physical peripheral. They also report num_channels: 16, causing runtime errors bc the module's max is 2 channels.
Fix

  • New routing_filter (Linux-only) drops ADMAIFs the cross-bar isn't routing externally, by querying ALSA's mixer state.
  • discovery clamps num_channels to min(maxChannels, 2) since module only does mono/stereo.
  • Shared file_utils.hpp for parse_alsa_hw and small file helpers (used by both routing_filter and device_id).

Result on Jetson

40 ADMAIF enteries → 4

Reviews
1 reviewer

Copy link
Copy Markdown

@seanavery seanavery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Those builtins are super annoying...

Is it reasonable to add test coverage for the routing_filter.cpp helpers? Or would that require a lot of effort to mock?

Comment thread src/discovery.cpp Outdated
int count_output = 0;

auto is_unrouted = [&](const PaDeviceInfo& info, bool is_input, const char* dir) {
if (audio::routing::is_unrouted_admaif(info, is_input)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question] how long does the is_unrouted_admaif walk over the sound cards take?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont have exact timing num, but now with refactor its one scan per discovery pass instead of one per PCM so will be way faster than before

Comment thread src/discovery.cpp
// actually use.
constexpr int kMaxSupportedChannels = 2;

if (info->maxInputChannels > 0 && !is_unrouted(*info, true, "input")) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question] Should the is_unrouted set be pulled first (just a single time) before the for loop here to avoid duplicating the lookup on each device?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, refactored to scan the cards first, and now is_unrouted just looks up in map

@oliviamiller
Copy link
Copy Markdown
Collaborator Author

Is it reasonable to add test coverage for the routing_filter.cpp helpers? Or would that require a lot of effort to mock?

added tests where reasonable

@oliviamiller oliviamiller requested a review from seanavery May 1, 2026 21:36
Copy link
Copy Markdown

@seanavery seanavery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for adding more test coverage

@oliviamiller oliviamiller merged commit 1bcf2bb into viam-modules:main May 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants