Skip to content

Use high precision scheduler to send RTP packets#52

Merged
codingjoe merged 7 commits intomainfrom
pref-audio
Mar 18, 2026
Merged

Use high precision scheduler to send RTP packets#52
codingjoe merged 7 commits intomainfrom
pref-audio

Conversation

@codingjoe
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings March 18, 2026 11:26
@codingjoe codingjoe self-assigned this Mar 18, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 47.43590% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.50%. Comparing base (f1d62a7) to head (b71eb3f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
voip/audio.py 49.18% 31 Missing ⚠️
voip/ai.py 41.17% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #52      +/-   ##
==========================================
- Coverage   94.59%   92.50%   -2.10%     
==========================================
  Files          24       24              
  Lines        1721     1788      +67     
==========================================
+ Hits         1628     1654      +26     
- Misses         93      134      +41     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates outbound RTP audio pacing in AudioCall.send_audio to use absolute-time scheduling rather than incremental asyncio.sleep, aiming for more consistent 20ms packet spacing.

Changes:

  • Replace per-packet asyncio.sleep pacing with sched.scheduler-based absolute scheduling.
  • Add a send_audio_scheduler field on AudioCall.
  • Update the pacing unit test to validate scheduler-based timing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
voip/audio.py Switches RTP packet pacing implementation to a scheduler/executor approach and introduces a scheduler field on AudioCall.
tests/test_audio.py Reworks the pacing test to mock sched.scheduler and assert scheduled timing intervals.

You can also share your feedback on Copilot code review. Take the survey.

@codingjoe codingjoe changed the title Use hi-precision scheduler to send RTP packets Use high precision scheduler to send RTP packets Mar 18, 2026
@codingjoe codingjoe requested a review from Copilot March 18, 2026 11:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR changes outbound RTP audio pacing in AudioCall.send_audio() to use a sched.scheduler-based approach (run in an executor) rather than per-packet asyncio.sleep() delays, aiming for more precise packet timing.

Changes:

  • Add a per-call sched.scheduler instance to AudioCall.
  • Rework AudioCall.send_audio() to enqueue packet sends at absolute times and run the scheduler in a thread via run_in_executor.
  • Update the pacing unit test to assert enterabs() scheduling intervals instead of captured asyncio.sleep() delays.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
voip/audio.py Introduces sched.scheduler pacing and executes scheduled sends via a threadpool executor.
tests/test_audio.py Updates pacing test to validate scheduler enterabs() spacing.

You can also share your feedback on Copilot code review. Take the survey.

@codingjoe codingjoe requested a review from Copilot March 18, 2026 18:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates outbound RTP audio transmission to use event-loop scheduling (call_later) instead of asyncio.sleep-based pacing, enabling outbound audio to be cancelled/preempted (notably for AI/agent calls).

Changes:

  • Replace per-packet asyncio.sleep pacing in AudioCall.send_audio() with a call_later-driven scheduler and add outbound-cancellation support.
  • Add AgentCall hooks to cancel outbound speech when user speech/transcriptions arrive.
  • Update and extend unit tests to reflect the new scheduling/cancellation behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
voip/audio.py Introduces timer-handle based outbound packet scheduling and cancellation API.
voip/ai.py Cancels outbound audio on transcription and adds speech/silence-based cancellation timers.
tests/test_audio.py Updates send-audio pacing assertions and adds cancellation/preemption tests.

You can also share your feedback on Copilot code review. Take the survey.

@codingjoe codingjoe merged commit d0dd643 into main Mar 18, 2026
21 of 22 checks passed
@codingjoe codingjoe deleted the pref-audio branch March 18, 2026 20:19
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