Skip to content

chan_simpleusb: Use PortAudio for audio output#1029

Open
mkmer wants to merge 9 commits into
masterfrom
portaudio-threaded-read
Open

chan_simpleusb: Use PortAudio for audio output#1029
mkmer wants to merge 9 commits into
masterfrom
portaudio-threaded-read

Conversation

@mkmer

@mkmer mkmer commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

Add PortAudio thread
Refactor startup of HID thread
Allow use of hw:xxx to configure usb

This allows ASL to work on any modern kernel by eliminating the obsolete /dev/dsp interface.

Add a USB buffer "monitor" to handle the mysterious condition were the audio buffer stops draining causing the TX output to remain active. When the buffer exceeds 200ms the stream is now reset.

Summary by CodeRabbit

  • New Features

    • PortAudio integration for cross-platform audio I/O
    • New audiodev option to target specific hardware
    • Public API to map an ALSA card to its USB device
    • ast_radio_check_audio accepts mono/stereo indication
  • Changes

    • Replaces legacy OSS/DSP flow with PortAudio streaming and threaded audio handling
    • Module lifecycle updated to manage audio streams/threads cleanly
    • Audio processing improved (resampling, underflow handling, TX/RX queueing)
    • USB/ALSA device discovery and HID timing refined

@mkmer mkmer added the enhancement New feature or request label Apr 22, 2026
@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Migration of chan_simpleusb audio I/O from OSS sounddev to PortAudio library, including refactored audio threading, new USB device lookup API in res_usbradio, and updated build configuration to link PortAudio.

Changes

Cohort / File(s) Summary
Build Configuration
channels/Makefile
Updated chan_simpleusb.so build rule to link against -lportaudio library.
chan_simpleusb Audio Refactor
channels/chan_simpleusb.c
Replaced OSS//dev/dsp audio device with PortAudio integration; added PaStream management, fixed sample rate (48kHz) and channel counts; split audio I/O into separate simpleusb_audio_thread(), refactored device initialization with init_audio_device(), added audio stream lifecycle helpers, updated call startup/shutdown to initialize audio and manage thread lifecycle, removed sounddev buffering configuration parsing.
USB Radio Device Lookup API
include/asterisk/res_usbradio.h, res/res_usbradio.c
Added public API function ast_radio_usb_device_from_alsa_card() with helper read_card_usbbus() to resolve ALSA card numbers to underlying libusb usb_device structures via /proc/asound/card<cardno>/usbbus lookup and libusb-0.1 bus/device enumeration.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested labels

code quality

Suggested reviewers

  • Allan-N
  • KB4MDD
  • okcrum
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly and specifically summarizes the primary change: replacing OSS /dev/dsp audio I/O with PortAudio integration in chan_simpleusb, which is the main focus of the extensive refactoring across the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch portaudio-threaded-read

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

github-actions[bot]

This comment was marked as resolved.

@github-actions github-actions Bot dismissed their stale review April 22, 2026 12:09

outdated suggestion

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 8

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@channels/chan_simpleusb.c`:
- Around line 480-492: open_stream() currently logs errors when
input_params.device or output_params.device equals paNoDevice but proceeds to
call Pa_OpenStream(), causing confusing PortAudio errors; update open_stream()
to check those conditions and return a PortAudio error (e.g., set res =
paInternalError or another appropriate paError) and exit early if either
input_params.device == paNoDevice or output_params.device == paNoDevice,
avoiding calling Pa_OpenStream() and ensuring pvt->stream is not used/left
uninitialized and the caller receives the clear failure immediately.
- Around line 1995-2004: The hangup path unconditionally calls
pthread_join(o->audiothread, ...) which is UB if that thread was never started;
update simpleusb_hangup to check o->audiothread != AST_PTHREADT_NULL before
calling pthread_join and only then set o->audiothread = AST_PTHREADT_NULL after
joining; likewise ensure the o->hidthread guard uses the same null-check
pattern. Also update the error path in simpleusb_call (where the HID thread is
joined on failure) to set o->hidthread = AST_PTHREADT_NULL after joining so
subsequent simpleusb_hangup won't attempt to join it again; keep store_config’s
initial AST_PTHREADT_NULL semantics intact.
- Around line 2071-2076: The current simpleusb_read() emits ast_log(LOG_ERROR)
on every call which can flood logs; change this to a non-noisy diagnostic by
either downgrading to ast_debug and include the channel name (use c->name or
ast_channel_name(c)) or implement a one-shot error log (static/atomic flag) so
the message is logged only once; keep returning &ast_null_frame and reference
simpleusb_read, simpleusb_audio_thread, ast_queue_frame, and ast_null_frame in
your fix so callers are clear this path is not used.
- Around line 1157-1164: The return path after
ast_radio_hid_device_init(o->devstr) failing in init_audio_device currently
returns without releasing usb_dev_lock; before returning on that error (the
block where o->usb_dev is NULL), call ast_mutex_unlock(&usb_dev_lock) to match
the other error paths and ensure the lock is released, then return -1. Locate
init_audio_device and the check around ast_radio_hid_device_init(o->devstr) to
add the ast_mutex_unlock(&usb_dev_lock) call just prior to the ast_log/return to
prevent the deadlock.
- Around line 2277-2292: When queuing the ENDPAGE frame inside the loop, clear
o->waspager before the continue so the condition won't fire again on the next
iteration; specifically, in the block that checks "if (o->waspager &&
(!ispager))" set o->waspager = false (or 0) prior to checking o->owner and
calling ast_queue_frame(&wf) (or before the continue) so that the ENDPAGE_STR
frame is only queued once per transition; preserve the existing owner check and
ast_queue_frame call and keep o->waspager = ispager after the loop as intended.
- Around line 462-490: The device matching using strstr(dev->name,
pvt->hw_device) in the device-discovery loop can mis-match prefixes (e.g.,
"hw:1" matching "hw:10"); update the check in that loop (the block that sets
input_params.device and output_params.device using pvt->hw_device and dev->name)
to perform an anchored match instead of plain substring: find the substring
position and then ensure the character after the match (if any) is a valid
boundary (',', ')', or '\0') or perform a stricter parse of dev->name to compare
the exact hw:<N> token; apply the same fix for both input and output device
selection so only exact card-index matches are accepted.
- Around line 4281-4285: The module calls Pa_Initialize() on load (see
Pa_Initialize at line ~4281) but never calls Pa_Terminate() on unload; update
unload_module() to call Pa_Terminate() after you close and destroy all PortAudio
streams and clean up channel pvts (the same cleanup sequence where you close
streams and free channel state in unload_module), ensuring Pa_Terminate() is
invoked only if Pa_Initialize() succeeded so host API threads and handles are
released.

In `@res/res_usbradio.c`:
- Around line 970-979: The loop currently returns any matching usb device (using
usb_busses, bus->dirname, dev->filename, and returning dev when strcasecmp(cur,
target) == 0); change it to only return devices that are supported HID audio
devices by applying the same filter/logic as ast_radio_hid_device_init(): after
matching cur to target, call or inline the HID-support check (e.g., the helper
that validates vendor/product/class or the ast_radio_hid_device_init()
predicates) and only return dev when that check succeeds; otherwise continue the
loop so unsupported USB audio cards do not get treated as HID-capable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: de0d2cc7-e9c5-4ed4-ab4a-9d2df459cdc6

📥 Commits

Reviewing files that changed from the base of the PR and between 3bf84e1 and 5d9a4b8.

📒 Files selected for processing (4)
  • channels/Makefile.diff
  • channels/chan_simpleusb.c
  • include/asterisk/res_usbradio.h
  • res/res_usbradio.c

Comment thread channels/chan_simpleusb.c
Comment thread channels/chan_simpleusb.c
Comment thread channels/chan_simpleusb.c
Comment thread channels/chan_simpleusb.c Outdated
Comment thread channels/chan_simpleusb.c
Comment thread channels/chan_simpleusb.c Outdated
Comment thread channels/chan_simpleusb.c Outdated
Comment thread res/res_usbradio.c
@mkmer mkmer force-pushed the portaudio-threaded-read branch 2 times, most recently from 2a84b0d to 0b6fc4c Compare April 22, 2026 14:02
coderabbitai[bot]

This comment was marked as outdated.

@mkmer mkmer requested review from Allan-N and okcrum April 22, 2026 14:10
coderabbitai[bot]

This comment was marked as resolved.

@mkmer mkmer force-pushed the portaudio-threaded-read branch from 4e8237c to c618b52 Compare April 24, 2026 13:30
Comment thread channels/chan_simpleusb.c Outdated
Comment thread channels/chan_simpleusb.c Outdated
Comment thread channels/chan_simpleusb.c Outdated
Comment thread channels/chan_simpleusb.c Outdated
github-actions[bot]

This comment was marked as resolved.

@mkmer mkmer force-pushed the portaudio-threaded-read branch from ec574c0 to ffd86c7 Compare April 24, 2026 18:43
@github-actions github-actions Bot dismissed their stale review April 24, 2026 18:44

outdated suggestion

Comment thread channels/chan_simpleusb.c Outdated
Comment thread include/asterisk/res_usbradio.h
coderabbitai[bot]

This comment was marked as resolved.

@mkmer mkmer force-pushed the portaudio-threaded-read branch from a5f429a to af3ea39 Compare May 1, 2026 15:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@res/res_usbradio.c`:
- Around line 909-915: In ast_radio_check_audio the consecutive-clipping run
counter seq_clips and last_clip handling are wrong: ensure seq_clips is
initialized to 1 when a new clip is detected (not 0) and reset to 1 whenever a
gap is detected (i.e., when last_clip < 0 or last_clip + 1 != i start a new
run), and increment seq_clips only when the current sample immediately follows
the previous clipped sample (last_clip + 1 == i); apply the identical correction
to the second occurrence of this logic (the block around the other
CLIP_SAMP_THRESH check) so both clipping-run counters behave symmetrically.
- Around line 500-505: The code assigns the result of ast_realloc directly to
usb_device_list which can drop the original pointer on failure; change to use a
temporary pointer (e.g., new_list) when calling ast_realloc, check if new_list
is NULL, and only assign it to usb_device_list on success; if allocation fails,
keep the original usb_device_list intact, release the usb_list_lock and return
-1 (ensuring usb_device_list_size remains correct) — update the allocation site
that references ast_realloc, usb_device_list, usb_device_list_size, and
usb_list_lock accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 40ba8553-9a49-4060-a872-aa1afcd78424

📥 Commits

Reviewing files that changed from the base of the PR and between 5d9a4b8 and a2dc960.

📒 Files selected for processing (5)
  • channels/Makefile.diff
  • channels/chan_simpleusb.c
  • channels/chan_usbradio.c
  • include/asterisk/res_usbradio.h
  • res/res_usbradio.c
✅ Files skipped from review due to trivial changes (1)
  • channels/Makefile.diff
🚧 Files skipped from review as they are similar to previous changes (1)
  • channels/chan_simpleusb.c

Comment thread res/res_usbradio.c Outdated
Comment thread res/res_usbradio.c
@davidgsd

davidgsd commented May 4, 2026

Copy link
Copy Markdown
Contributor

The locked up USB interface issue occurred again. I was listening to a couple nets over the past couple hours, not doing anything in the terminal or transmitting to the node. Then about 5 minutes ago the audio just stopped, and the status LED on the UCI is lit solid, not flashing. ASL and the AllScan dashboard web app are all still running fine. Logfile is quite large with the extra debug enabled and with it showing all the AMI log messages for the status data sent to the dashboard. LMK if you see anything, and next steps...
messages.log

@davidgsd

davidgsd commented May 4, 2026

Copy link
Copy Markdown
Contributor

USB interface locked up again, this time after only about 10 minutes. This time I did not have the web dashboard running so there should be less clutter in the log. I do not see anything in the log that seems to indicate in any way that the USB comms stopped.
messages.log

@mkmer

mkmer commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

USB interface locked up again, this time after only about 10 minutes. This time I did not have the web dashboard running so there should be less clutter in the log. I do not see anything in the log that seems to indicate in any way that the USB comms stopped. messages.log

Well... here is where it "died" (~11:27.359):

[2026-05-04 23:11:01.791] DEBUG[13627] chan_simpleusb.c: Channel 571573: tx set to 1
[2026-05-04 23:11:24.019] DEBUG[13624] chan_simpleusb.c: Channel 571573: ACRUK TX OFF.
[2026-05-04 23:11:24.105] DEBUG[13627] chan_simpleusb.c: Channel 571573: update PTT = 0.
[2026-05-04 23:11:24.105] DEBUG[13627] chan_simpleusb.c: Channel 571573: tx set to 0
[2026-05-04 23:11:25.125] DEBUG[13624] chan_simpleusb.c: Channel 571573: ACRK TX ON.
[2026-05-04 23:11:25.148] DEBUG[13627] chan_simpleusb.c: Channel 571573: update PTT = 1 on channel.
[2026-05-04 23:11:25.148] DEBUG[13627] chan_simpleusb.c: Channel 571573: tx set to 1
[2026-05-04 23:11:27.359] DEBUG[13624] chan_simpleusb.c: Channel 571573: ACRUK TX OFF.
[2026-05-04 23:11:35.799] DEBUG[13624] chan_simpleusb.c: Channel 571573: ACRK TX ON.
[2026-05-04 23:11:53.679] DEBUG[13624] chan_simpleusb.c: Channel 571573: ACRUK TX OFF.
[2026-05-04 23:12:01.439] DEBUG[13624] chan_simpleusb.c: Channel 571573: ACRK TX ON.

We can see that the HID thread stopped or stopped hearing the pttkick pipe....
I suspect the HID thread is dead mostly because you say the heartbeat led is no longer blinking.

It looks like you only captured the debug in this log file, do you have the error and warning logs for this time frame? Maybe just clip out this time window (ish)?

@mkmer mkmer force-pushed the portaudio-threaded-read branch from 3cc24a9 to dc2ac15 Compare May 5, 2026 15:40
@mkmer

mkmer commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

I found a situation where Pa_ReadStream() becomes hung "forever" while working on restoring the "hotplug" functionality. I've added some code to handle this situation -> it appears the base Asterisk chan_console code has this issue as well... so much for proven examples.
"Maybe" this latest push will fix your situation...

@davidgsd

davidgsd commented May 5, 2026

Copy link
Copy Markdown
Contributor

Updated everything and the issue is still happening. Occurred after about 20 minutes.

I think I definitely pulled in everything,

git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
arduino@Q1:~/app_rpt$ git pull upstream master
From https://github.com/AllStarLink/app_rpt
 * branch            master     -> FETCH_HEAD
Updating 274d534..57e28c4
Fast-forward
 apps/app_rpt.c        | 11 ++++++++---
 channels/chan_usrp.c  | 23 +++++++++++++----------
 channels/chan_voter.c | 31 ++++++-------------------------
 3 files changed, 27 insertions(+), 38 deletions(-)
arduino@Q1:~/app_rpt$ git branch
* master
  portaudio-threaded-read
  uno-q
arduino@Q1:~/app_rpt$ git checkout portaudio-threaded-read
Switched to branch 'portaudio-threaded-read'
Your branch is behind 'upstream/portaudio-threaded-read' by 11 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
arduino@Q1:~/app_rpt$ git pull
Updating ffd86c7..dc2ac15
Fast-forward
 channels/chan_simpleusb.c       | 1130 +++++++++++++++++++++++++++++++----------------------------
 channels/chan_usbradio.c        |    4 +-
 include/asterisk/res_usbradio.h |    5 +-
 res/res_usbradio.c              |  183 +++++-----
 4 files changed, 705 insertions(+), 617 deletions(-)
arduino@Q1:~/app_rpt$ makeasl
CC="cc" CXX="g++" LD="" AR="" RANLIB="" CFLAGS="" LDFLAGS="" make -C menuselect CONFIGURE_SILENT="--silent" makeopts
make[1]: Entering directory '/home/arduino/asl3-asterisk-22.8.2+asl3-3.8.3/menuselect'
make[1]: 'makeopts' is up to date.
make[1]: Leaving directory '/home/arduino/asl3-asterisk-22.8.2+asl3-3.8.3/menuselect'
Generating input for menuselect ...
menuselect/menuselect --check-deps menuselect.makeopts
menuselect/menuselect --check-deps menuselect.makeopts
   [CC] chan_echolink.c -> chan_echolink.o
   [LD] chan_echolink.o -> chan_echolink.so
   [CC] chan_simpleusb.c -> chan_simpleusb.o
   [LD] chan_simpleusb.o -> chan_simpleusb.so
   [CC] chan_usbradio.c -> chan_usbradio.o
   [LD] chan_usbradio.o -> chan_usbradio.so
   [CC] chan_usrp.c -> chan_usrp.o
   [LD] chan_usrp.o -> chan_usrp.so
   [CC] chan_voter.c -> chan_voter.o
   [LD] chan_voter.o -> chan_voter.so
   [CC] app_gps.c -> app_gps.o
   [LD] app_gps.o -> app_gps.so
   [CC] app_rpt.c -> app_rpt.o
   [CC] app_rpt/rpt_serial.c -> app_rpt/rpt_serial.o
   [LD] app_rpt.o app_rpt/rpt_bridging.o app_rpt/rpt_call.o app_rpt/rpt_capabilities.o app_rpt/rpt_channel.o app_rpt/rpt_cli.o app_rpt/rpt_config.o app_rpt/rpt_daq.o app_rpt/rpt_dialplan_functions.o app_rpt/rpt_functions.o app_rpt/rpt_link.o app_rpt/rpt_lock.o app_rpt/rpt_manager.o app_rpt/rpt_mdc1200.o app_rpt/rpt_radio.o app_rpt/rpt_rig.o app_rpt/rpt_serial.o app_rpt/rpt_telemetry.o app_rpt/rpt_translate.o app_rpt/rpt_uchameleon.o app_rpt/rpt_utils.o app_rpt/rpt_vox.o app_rpt/rpt_xcat.o -> app_rpt.so
   [CC] res_usbradio.c -> res_usbradio.o
   [LD] res_usbradio.o -> res_usbradio.so
Building Documentation For: channels pbx apps codecs formats cdr cel bridges funcs tests main res addons
 +--------- Asterisk Build Complete ---------+
 + Asterisk has successfully been built, and +
 + can be installed by running:              +
 +                                           +
 +                make install               +
 +-------------------------------------------+
arduino@Q1:~/asl3-asterisk-22.8.2+asl3-3.8.3$ makeinst
Shutting down "asterisk" before updating
Stopping Asterisk...
systemctl stop asterisk.service
Updating: "/usr/lib/aarch64-linux-gnu/asterisk/modules/app_rpt.so"
Updating: "/usr/lib/aarch64-linux-gnu/asterisk/modules/chan_simpleusb.so"
Updating: "/usr/lib/aarch64-linux-gnu/asterisk/modules/chan_usbradio.so"
Updating: "/usr/lib/aarch64-linux-gnu/asterisk/modules/chan_voter.so"
Updating: "/usr/lib/aarch64-linux-gnu/asterisk/modules/res_usbradio.so"
Restarting "asterisk" after updating
Starting asterisk...
systemctl start asterisk.service

Log file is below. You mentioned earlier about some other error logs but I don't know where that would be? messages.log is the only logfile in /var/log/asterisk/, and I don't see any errors in the system log.
messages.log

@mkmer

mkmer commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

It's strange that we don't see any of the hidthread messages in your log (like these):

[2026-05-05 11:21:58.635] DEBUG[411986] chan_simpleusb.c: hidthread has exited
[2026-05-05 11:28:06.977] DEBUG[412681] chan_simpleusb.c: hidthread has started
[2026-05-05 11:28:06.977] DEBUG[412681] chan_simpleusb.c: hidthread is restarting/starting
[2026-05-05 11:28:06.979] DEBUG[412682] chan_simpleusb.c: Audio thread is starting

Comment thread channels/chan_simpleusb.c Outdated
Comment thread channels/chan_simpleusb.c Outdated
Comment thread channels/chan_simpleusb.c
Comment thread channels/chan_simpleusb.c Outdated
Comment thread channels/chan_simpleusb.c Outdated
github-actions[bot]

This comment was marked as resolved.

@github-actions github-actions Bot dismissed their stale review May 31, 2026 10:43

outdated suggestion

@mkmer mkmer force-pushed the portaudio-threaded-read branch 4 times, most recently from 18eefe9 to 576124e Compare June 4, 2026 12:08
github-actions[bot]

This comment was marked as resolved.

@mkmer mkmer force-pushed the portaudio-threaded-read branch from 576124e to 4433cde Compare June 4, 2026 12:26
@github-actions github-actions Bot dismissed their stale review June 4, 2026 12:27

outdated suggestion

@mkmer mkmer force-pushed the portaudio-threaded-read branch from a19b9d8 to 355bb8c Compare June 4, 2026 13:19
@mkmer

mkmer commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator Author

This should be "solid" at this point. Turns out something with the USB stream stops draining the TX hardware buffer, which then causes the TX output to remain on ( becuase the code is trying to empty the buffer before releasing the TX).
We now reset the hardware stream whenever the buffer remains "full" for an extended period of time.

github-actions[bot]

This comment was marked as resolved.

@github-actions github-actions Bot dismissed their stale review June 4, 2026 14:08

outdated suggestion

@mkmer mkmer added the bug Something isn't working label Jun 4, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
channels/chan_voter.c (1)

1230-1231: ⚠️ Potential issue | 🔴 Critical

Fix frame-size padding math to avoid tail overread.

audio_samples += audio_samples % FRAME_SIZE does not round up to a FRAME_SIZE boundary; it can still leave a partial tail before the fixed-size copy loop.

Proposed fix
-		audio_samples += audio_samples % FRAME_SIZE;
+		audio_samples += (FRAME_SIZE - (audio_samples % FRAME_SIZE)) % FRAME_SIZE;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@channels/chan_voter.c` around lines 1230 - 1231, The padding math is wrong:
replace the line that does audio_samples += audio_samples % FRAME_SIZE with
logic that rounds audio_samples up to the next multiple of FRAME_SIZE (compute
the padding as (FRAME_SIZE - (audio_samples % FRAME_SIZE)) % FRAME_SIZE and add
that), so audio_samples becomes a true multiple of FRAME_SIZE before the
fixed-size copy loop; update the code around the audio_samples variable in
channels/chan_voter.c accordingly to use the new padded value to avoid tail
overread.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@channels/chan_simpleusb.c`:
- Around line 1156-1159: When ast_radio_usb_device_from_alsa_card(o->devicenum)
returns NULL, fail the audio-device initialization instead of just logging: in
the function that contains the o->usb_dev assignment (the init_audio_device /
simpleusb init routine that sets o->usb_dev and then continues), change the
branch so that if o->usb_dev is NULL you log an error (not just ast_debug) and
immediately return -1 to abort initialization; this ensures the channel isn’t
marked and mixer probing isn’t attempted when the HID-backed USB device cannot
be resolved.

---

Duplicate comments:
In `@channels/chan_voter.c`:
- Around line 1230-1231: The padding math is wrong: replace the line that does
audio_samples += audio_samples % FRAME_SIZE with logic that rounds audio_samples
up to the next multiple of FRAME_SIZE (compute the padding as (FRAME_SIZE -
(audio_samples % FRAME_SIZE)) % FRAME_SIZE and add that), so audio_samples
becomes a true multiple of FRAME_SIZE before the fixed-size copy loop; update
the code around the audio_samples variable in channels/chan_voter.c accordingly
to use the new padded value to avoid tail overread.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9fbe10a7-7392-475a-9bb8-9aae798d0e75

📥 Commits

Reviewing files that changed from the base of the PR and between 5d9a4b8 and 0c5a53a.

📒 Files selected for processing (6)
  • channels/Makefile.diff
  • channels/chan_simpleusb.c
  • channels/chan_usbradio.c
  • channels/chan_voter.c
  • include/asterisk/res_usbradio.h
  • res/res_usbradio.c
✅ Files skipped from review due to trivial changes (1)
  • channels/chan_usbradio.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • channels/Makefile.diff

Comment thread channels/chan_simpleusb.c
@mkmer mkmer mentioned this pull request Jun 4, 2026
2 tasks
github-actions[bot]

This comment was marked as resolved.

@github-actions github-actions Bot dismissed their stale review June 4, 2026 18:32

outdated suggestion

Seperate functions for stream cleanup
Only flush buffer 1 time per exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PTT remain stuck on RPi5 Feature Request: support any sound device

5 participants