-
Notifications
You must be signed in to change notification settings - Fork 907
Handle redundancy payload type mapping ensuring symmetric PT #4548
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
base: master
Are you sure you want to change the base?
Conversation
Enhanced SDP negotiation to correctly map redundancy payload types in fmtp attributes, ensuring proper PT translation. Also added support for configuring txt_red_level in account modification to propagate text redundancy settings.
There was a problem hiding this 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 fixes an issue with symmetric payload type (PT) handling for RT Text redundancy streams in SDP negotiation. When PJMEDIA_SDP_NEG_ANSWER_SYMMETRIC_PT is enabled, the library now properly updates redundancy PT numbers in fmtp attributes to match the remote offer, instead of keeping them hardcoded.
- Added text redundancy level configuration update in account modification
- Enhanced SDP negotiation to handle redundancy PT mapping symmetrically
- Updated fmtp attribute processing to rewrite redundancy PT values based on offer
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pjsip/src/pjsua-lib/pjsua_acc.c | Adds text redundancy level configuration update during account modification |
| pjmedia/src/pjmedia/sdp_neg.c | Implements symmetric PT handling for redundancy streams by updating fmtp attributes |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if (a) { | ||
| rewrite_pt(pool, &a->value, &pt_answer[i], &pt_offer[i]); | ||
| if (is_red) { | ||
| enum { MAX_FMTP_STR_LEN = 32 }; |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 32 for MAX_FMTP_STR_LEN should be defined as a named constant at the file or function level to improve maintainability and make the buffer size limit more explicit.
| enum { MAX_FMTP_STR_LEN = 32 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defining const as enum is common use in other parts of the code.
| (j==0)?"%d":"/%d", pt_o); | ||
| buf_len = PJ_MIN(buf_len + len, | ||
| MAX_FMTP_STR_LEN); | ||
| } |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The buffer length calculation using PJ_MIN could lead to truncated output without proper error handling. If the buffer becomes full, the function continues processing but may produce incomplete fmtp strings. Consider adding bounds checking and error handling.
| } | |
| if ((unsigned)len >= MAX_FMTP_STR_LEN - buf_len) { | |
| /* Truncation occurred, stop processing further. */ | |
| buf_len = MAX_FMTP_STR_LEN - 1; | |
| buf[buf_len] = '\0'; | |
| PJ_LOG(2, (THIS_FILE, "FMTP string truncated due to buffer size limit")); | |
| break; | |
| } else { | |
| buf_len += len; | |
| } |
|
|
||
| pt_o = pj_strtoul(&pt_offer[i]); | ||
| pt_a = pj_strtoul(&pt_answer[i]); | ||
| buf_len = pj_ansi_snprintf(buf, MAX_FMTP_STR_LEN, "%d ", pt_o); |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return value of pj_ansi_snprintf is not checked for potential buffer overflow. If the formatted string exceeds MAX_FMTP_STR_LEN, this could lead to undefined behavior. Add bounds checking.
| buf_len = pj_ansi_snprintf(buf, MAX_FMTP_STR_LEN, "%d ", pt_o); | |
| buf_len = pj_ansi_snprintf(buf, MAX_FMTP_STR_LEN, "%d ", pt_o); | |
| if (buf_len < 0 || buf_len >= MAX_FMTP_STR_LEN) { | |
| /* Truncate and null-terminate to be safe */ | |
| buf_len = MAX_FMTP_STR_LEN - 1; | |
| buf[buf_len] = '\0'; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With MAX_FMTP_STR_LEN is set to 32, buffer overflow most likely not going to happen
| /* Update the fmtp redundancy PT. */ | ||
| for (j = 0; j < fmtp.cnt; ++j) { | ||
| pt_o = pj_strtoul(&fmtp.param[j].val); | ||
| for (k = 0; k < pt_cnt ;++k) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm understanding this correctly, it looks like we're searching for the text pt for every redundancy level (instead of just once)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct. The goal is to be generic, since redundant audio data might have a different number.
e.g.: https://datatracker.ietf.org/doc/html/rfc2198#section-5
m=audio 12345 RTP/AVP 121 0 5
a=rtpmap:121 red/8000/1
a=fmtp:121 0/5
PR #4344 added support for RT Text, including text stream redundancy level.
The default PT is configured from
PJMEDIA_RTP_PT_REDUNDANCY/PJMEDIA_RTP_PT_T140.When
PJMEDIA_SDP_NEG_ANSWER_SYMMETRIC_PTis set, the library will rewrite the PT number to match the PT number as the remote offer.Currently, the redundancy PT is not updated and still hardcoded to
PJMEDIA_RTP_PT_T140instead matching to the offer.e,g: offer:
answer:
This PR will update the redundancy PT based on the offer to ensure the symmetric PT.