Skip to content

Commit 9cc0309

Browse files
authored
Fix SDP negotiation for audio with asymmetric encoding parameters (#4622)
To fix #4615. Currently the library assumes to always send offer without encoding param when channel count is 1. But alas, app may modify the SDP or 3rd party media may creates its own SDP.
1 parent 33d66a0 commit 9cc0309

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

pjmedia/src/pjmedia/sdp_neg.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ static pj_status_t process_m_answer( pj_pool_t *pool,
778778
pj_bool_t allow_asym)
779779
{
780780
unsigned i;
781+
pj_bool_t is_audio;
781782

782783
/* Check that the media type match our offer. */
783784

@@ -786,6 +787,8 @@ static pj_status_t process_m_answer( pj_pool_t *pool,
786787
return PJMEDIA_SDPNEG_EINVANSMEDIA;
787788
}
788789

790+
is_audio = (pj_strcmp2(&offer->desc.media, "audio") == 0);
791+
789792
/* Check if remote has rejected our offer */
790793
if (answer->desc.port == 0) {
791794

@@ -886,6 +889,10 @@ static pj_status_t process_m_answer( pj_pool_t *pool,
886889
}
887890
pjmedia_sdp_attr_get_rtpmap(a, &or_);
888891

892+
/* For audio, channel count is 1 if not specified */
893+
if (is_audio && or_.param.slen == 0)
894+
or_.param = pj_str("1");
895+
889896
/* Find paylaod in answer SDP with matching
890897
* encoding name and clock rate.
891898
*/
@@ -896,13 +903,16 @@ static pj_status_t process_m_answer( pj_pool_t *pool,
896903
pjmedia_sdp_rtpmap ar;
897904
pjmedia_sdp_attr_get_rtpmap(a, &ar);
898905

906+
/* For audio, channel count is 1 if not specified */
907+
if (is_audio && ar.param.slen == 0)
908+
ar.param = pj_str("1");
909+
899910
/* See if encoding name, clock rate, and channel
900911
* count match
901912
*/
902913
if (!pj_stricmp(&or_.enc_name, &ar.enc_name) &&
903914
or_.clock_rate == ar.clock_rate &&
904-
(pj_stricmp(&or_.param, &ar.param)==0 ||
905-
(ar.param.slen==1 && *ar.param.ptr=='1')))
915+
(pj_stricmp(&or_.param, &ar.param)==0))
906916
{
907917
/* Call custom format matching callbacks */
908918
if (custom_fmt_match(pool, &or_.enc_name,

0 commit comments

Comments
 (0)