Skip to content

Commit

Permalink
Close pjsip#1297:
Browse files Browse the repository at this point in the history
 - Updated PJMEDIA endpoint to rearrange dynamic payload type allocation in generating SDP for audio, the allocation arranged in pjmedia_audio_pt enumeation is no longer used.
 - Updated PJMEDIA_RTP_PT_TELEPHONE_EVENTS default value to 120, so lower PT values will be used by audio codecs.



git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@6105 74dad513-b988-da41-8d7b-12977e46ad98
  • Loading branch information
nanangizz committed Nov 13, 2019
1 parent d1ee4a6 commit dc0335a
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 50 deletions.
22 changes: 9 additions & 13 deletions pjmedia/include/pjmedia-codec/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@
* These are the dynamic payload types that are used by audio codecs in
* this library. Also see the header file <pjmedia/codec.h> for list
* of static payload types.
*
* These enumeration is for older audio codecs only, newer audio codec using
* dynamic payload type can simply assign PJMEDIA_RTP_PT_DYNAMIC in its
* payload type (i.e: pjmedia_codec_info.pt). Endpoint will automatically
* rearrange dynamic payload types in SDP generation.
*/
enum pjmedia_audio_pt
{
/* According to IANA specifications, dynamic payload types are to be in
* the range 96-127 (inclusive). This enum is structured to place the
* values of the payload types specified below into that range.
* the range 96-127 (inclusive), but this enum allows the value to be
* outside that range, later endpoint will rearrange dynamic payload types
* in SDP generation to be inside the 96-127 range and not equal to
* PJMEDIA_RTP_PT_TELEPHONE_EVENTS.
*
* PJMEDIA_RTP_PT_DYNAMIC is defined in <pjmedia/codec.h>. It is defined
* to be 96.
*
* PJMEDIA_RTP_PT_TELEPHONE_EVENTS is defined in <pjmedia/config.h>.
* The default value is 96.
*/
#if PJMEDIA_RTP_PT_TELEPHONE_EVENTS
PJMEDIA_RTP_PT_START = PJMEDIA_RTP_PT_TELEPHONE_EVENTS,
#else
PJMEDIA_RTP_PT_START = (PJMEDIA_RTP_PT_DYNAMIC-1),
#endif

PJMEDIA_RTP_PT_SPEEX_NB, /**< Speex narrowband/8KHz */
PJMEDIA_RTP_PT_SPEEX_WB, /**< Speex wideband/16KHz */
Expand Down Expand Up @@ -108,10 +108,6 @@ enum pjmedia_audio_pt
#if PJMEDIA_CODEC_L16_HAS_48KHZ_STEREO
PJMEDIA_RTP_PT_L16_48KHZ_STEREO, /**< L16 @ 48KHz, stereo */
#endif

/* Caution!
* Ensure the value of the last pt above is <= 127.
*/
};

/**
Expand Down
16 changes: 2 additions & 14 deletions pjmedia/include/pjmedia/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -844,25 +844,13 @@


/**
* This macro declares the payload type for telephone-event
* This macro declares the start payload type for telephone-event
* that is advertised by PJMEDIA for outgoing SDP. If this macro
* is set to zero, telephone events would not be advertised nor
* supported.
*
* If this value is changed to other number, please update the
* PJMEDIA_RTP_PT_TELEPHONE_EVENTS_STR too.
*/
#ifndef PJMEDIA_RTP_PT_TELEPHONE_EVENTS
# define PJMEDIA_RTP_PT_TELEPHONE_EVENTS 96
#endif


/**
* Macro to get the string representation of the telephone-event
* payload type.
*/
#ifndef PJMEDIA_RTP_PT_TELEPHONE_EVENTS_STR
# define PJMEDIA_RTP_PT_TELEPHONE_EVENTS_STR "96"
# define PJMEDIA_RTP_PT_TELEPHONE_EVENTS 120
#endif


Expand Down
105 changes: 82 additions & 23 deletions pjmedia/src/pjmedia/endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,24 @@ PJ_DEF(pj_status_t) pjmedia_endpt_create_audio_sdp(pjmedia_endpt *endpt,
PJMEDIA_RTP_PT_TELEPHONE_EVENTS != 0
unsigned televent_num = 0;
unsigned televent_clockrates[8];
#endif
unsigned used_pt_num = 0;
unsigned used_pt[PJMEDIA_MAX_SDP_FMT];
#endif

PJ_UNUSED_ARG(options);

/* Check that there are not too many codecs */
PJ_ASSERT_RETURN(endpt->codec_mgr.codec_cnt <= PJMEDIA_MAX_SDP_FMT,
PJ_ETOOMANY);

/* Insert PJMEDIA_RTP_PT_TELEPHONE_EVENTS as used PT */
#if defined(PJMEDIA_RTP_PT_TELEPHONE_EVENTS) && \
PJMEDIA_RTP_PT_TELEPHONE_EVENTS != 0
if (endpt->has_telephone_event) {
used_pt[used_pt_num++] = PJMEDIA_RTP_PT_TELEPHONE_EVENTS;
}
#endif

/* Create and init basic SDP media */
m = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_media);
status = init_sdp_media(m, pool, &STR_AUDIO, si);
Expand All @@ -444,6 +452,7 @@ PJ_DEF(pj_status_t) pjmedia_endpt_create_audio_sdp(pjmedia_endpt *endpt,
char tmp_param[3];
pjmedia_codec_param codec_param;
pj_str_t *fmt;
unsigned pt;

if (endpt->codec_mgr.codec_desc[i].prio == PJMEDIA_CODEC_PRIO_DISABLED)
break;
Expand All @@ -452,15 +461,43 @@ PJ_DEF(pj_status_t) pjmedia_endpt_create_audio_sdp(pjmedia_endpt *endpt,
pjmedia_codec_mgr_get_default_param(&endpt->codec_mgr, codec_info,
&codec_param);
fmt = &m->desc.fmt[m->desc.fmt_count++];
pt = codec_info->pt;

/* Rearrange dynamic payload type to make sure it is inside 96-127
* range and not being used by other codec/tel-event.
*/
if (pt >= 96) {
unsigned pt_check = 96;
unsigned j = 0;
while (j < used_pt_num && pt_check <= 127) {
if (pt_check==used_pt[j]) {
pt_check++;
j = 0;
} else {
j++;
}
}
if (pt_check > 127) {
/* No more available PT */
PJ_LOG(4,(THIS_FILE, "Warning: no available dynamic "
"payload type for audio codec"));
break;
}
pt = pt_check;
}

/* Take a note of used dynamic PT */
if (pt >= 96)
used_pt[used_pt_num++] = pt;

fmt->ptr = (char*) pj_pool_alloc(pool, 8);
fmt->slen = pj_utoa(codec_info->pt, fmt->ptr);
fmt->slen = pj_utoa(pt, fmt->ptr);

rtpmap.pt = *fmt;
rtpmap.enc_name = codec_info->encoding_name;

#if defined(PJMEDIA_HANDLE_G722_MPEG_BUG) && (PJMEDIA_HANDLE_G722_MPEG_BUG != 0)
if (codec_info->pt == PJMEDIA_RTP_PT_G722)
if (pt == PJMEDIA_RTP_PT_G722)
rtpmap.clock_rate = 8000;
else
rtpmap.clock_rate = codec_info->clock_rate;
Expand All @@ -487,7 +524,7 @@ PJ_DEF(pj_status_t) pjmedia_endpt_create_audio_sdp(pjmedia_endpt *endpt,
rtpmap.param.slen = 0;
}

if (codec_info->pt >= 96 || pjmedia_add_rtpmap_for_static_pt) {
if (pt >= 96 || pjmedia_add_rtpmap_for_static_pt) {
pjmedia_sdp_rtpmap_to_attr(pool, &rtpmap, &attr);
m->attr[m->attr_count++] = attr;
}
Expand All @@ -503,7 +540,7 @@ PJ_DEF(pj_status_t) pjmedia_endpt_create_audio_sdp(pjmedia_endpt *endpt,
buf_len += pj_ansi_snprintf(buf,
MAX_FMTP_STR_LEN - buf_len,
"%d",
codec_info->pt);
pt);

for (ii = 0; ii < dec_fmtp->cnt; ++ii) {
pj_size_t test_len = 2;
Expand Down Expand Up @@ -548,18 +585,12 @@ PJ_DEF(pj_status_t) pjmedia_endpt_create_audio_sdp(pjmedia_endpt *endpt,
if (max_bitrate < codec_param.info.max_bps)
max_bitrate = codec_param.info.max_bps;

/* List clock rate & channel count of audio codecs for generating
* telephone-event later.
*/
/* List clock rate of audio codecs for generating telephone-event */
#if defined(PJMEDIA_RTP_PT_TELEPHONE_EVENTS) && \
PJMEDIA_RTP_PT_TELEPHONE_EVENTS != 0
{
if (endpt->has_telephone_event) {
unsigned j;

/* Take a note of used dynamic PT */
if (codec_info->pt >= 96)
used_pt[used_pt_num++] = codec_info->pt;

for (j=0; j<televent_num; ++j) {
if (televent_clockrates[j] == rtpmap.clock_rate)
break;
Expand All @@ -583,21 +614,49 @@ PJ_DEF(pj_status_t) pjmedia_endpt_create_audio_sdp(pjmedia_endpt *endpt,
for (i=0; i<televent_num; i++) {
char buf[160];
unsigned j = 0;
unsigned pt = PJMEDIA_RTP_PT_TELEPHONE_EVENTS;
unsigned pt;

/* Find PT for this tel-event */
while (j < used_pt_num && pt <= 127) {
if (pt == used_pt[j]) {
pt++;
if (i == 0) {
/* First telephony-event always uses preconfigured PT
* PJMEDIA_RTP_PT_TELEPHONE_EVENTS.
*/
pt = PJMEDIA_RTP_PT_TELEPHONE_EVENTS;
} else {
/* Otherwise, find any free PT slot, starting from
* (PJMEDIA_RTP_PT_TELEPHONE_EVENTS + 1).
*/
pt = PJMEDIA_RTP_PT_TELEPHONE_EVENTS + 1;
while (j < used_pt_num && pt <= 127) {
if (pt == used_pt[j]) {
pt++;
j = 0;
} else {
j++;
}
}
if (pt > 127) {
/* Not found? Find more, but now starting from 96 */
pt = 96;
j = 0;
} else {
j++;
while (j < used_pt_num &&
pt < PJMEDIA_RTP_PT_TELEPHONE_EVENTS)
{
if (pt == used_pt[j]) {
pt++;
j = 0;
} else {
j++;
}
}
if (pt >= PJMEDIA_RTP_PT_TELEPHONE_EVENTS) {
/* No more available PT */
PJ_LOG(4,(THIS_FILE, "Warning: no available dynamic "
"payload type for telephone-event"));
break;
}
}
}
if (pt > 127) {
/* No more available PT */
break;
}
used_pt[used_pt_num++] = pt;

/* Print tel-event PT */
Expand Down

0 comments on commit dc0335a

Please sign in to comment.