Skip to content

ffeat: Implement custom RFC 4733 DTMF decoding with End-bit detection#585

Open
usluio wants to merge 1 commit intolivekit:mainfrom
usluio:huseyinemreuslu/rfc4733-marker-option-new-added
Open

ffeat: Implement custom RFC 4733 DTMF decoding with End-bit detection#585
usluio wants to merge 1 commit intolivekit:mainfrom
usluio:huseyinemreuslu/rfc4733-marker-option-new-added

Conversation

@usluio
Copy link

@usluio usluio commented Feb 10, 2026

Summary

This PR implements custom DTMF RTP packet decoding that bypasses the Marker bit requirement
from media-sdk, fixing an issue where DTMF events were silently dropped when SIP providers
do not set the RTP Marker bit on DTMF packets.

Problem

The existing dtmf.DecodeRTP() from media-sdk requires the RTP Marker bit to be set
on incoming DTMF packets as specified in RFC 4733.
However, many SIP providers/gateways do not consistently set the Marker bit, causing DTMF
events to be completely ignored. This results in:

  • IVR/PIN input failures
  • DTMF forwarding to LiveKit rooms silently failing
  • No logging to indicate why DTMF was being dropped

Solution

Custom DTMF Decoding (media_port.go)

  • Replaced dtmf.DecodeRTP() with a custom decoder that directly parses the
    RFC 4733 §2.3 payload format
  • Uses the End bit (byte 1, bit 7) instead of the Marker bit to determine when a DTMF
    event is complete, preventing duplicate events
  • Maps event codes (0-15) to their corresponding DTMF digits (0-9, *, #, a-d)
    as defined in RFC 4733 §7 (Event Code Registry)
  • Added debug/info logging for incoming DTMF RTP packets

Improved DTMF Forwarding (inbound.go)

  • Added structured logging throughout the DTMF handling pipeline
  • Error handling for SendData() — previously errors were silently discarded with _ =
  • Log messages for: DTMF received, forwarded successfully, forward failed, buffered for PIN,
    and buffer full conditions

Changes

  • pkg/sip/media_port.go — Custom RFC 4733 DTMF payload decoding
  • pkg/sip/inbound.go — Enhanced DTMF forwarding with error handling and logging

References

Testing

  • Tested with SIP providers that do not set the Marker bit on DTMF packets
  • Verified DTMF digits are correctly decoded and forwarded to LiveKit rooms
  • Confirmed no duplicate events due to End-bit filtering

@usluio usluio requested a review from a team as a code owner February 10, 2026 11:58
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


root seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.


// Custom decode: ignore Marker bit requirement from media-sdk
// Only emit event when End bit is set to prevent duplicates
if len(payload) < 4 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please file a PR to the media-sdk and add it as an alternative decoding mode (parameter or a new function) instead.

Copy link
Author

Choose a reason for hiding this comment

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

Can you point this file for this project? @dennwc

@usluio usluio force-pushed the huseyinemreuslu/rfc4733-marker-option-new-added branch from 98e7e21 to aa17506 Compare February 10, 2026 12:29
@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.63%. Comparing base (0460b40) to head (aa17506).
⚠️ Report is 219 commits behind head on main.

Files with missing lines Patch % Lines
pkg/sip/inbound.go 55.55% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #585      +/-   ##
==========================================
- Coverage   65.25%   64.63%   -0.62%     
==========================================
  Files          51       34      -17     
  Lines        6588     6527      -61     
==========================================
- Hits         4299     4219      -80     
+ Misses       1915     1888      -27     
- Partials      374      420      +46     

☔ 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
Author

@usluio usluio left a comment

Choose a reason for hiding this comment

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

We just needed to these logs for the point issue. When decode has an occured we can' t understand or see from logs. Needs that!


// Custom decode: ignore Marker bit requirement from media-sdk
// Only emit event when End bit is set to prevent duplicates
if len(payload) < 4 {
Copy link
Author

Choose a reason for hiding this comment

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

Can you point this file for this project? @dennwc

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.

3 participants