Changeset 6105


Ignore:
Timestamp:
Nov 13, 2019 8:09:34 AM (4 years ago)
Author:
nanang
Message:

Close #1297:

  • 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.
Location:
pjproject/trunk/pjmedia
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/include/pjmedia-codec/types.h

    r5791 r6105  
    4242 * this library. Also see the header file <pjmedia/codec.h> for list 
    4343 * of static payload types. 
     44 * 
     45 * These enumeration is for older audio codecs only, newer audio codec using 
     46 * dynamic payload type can simply assign PJMEDIA_RTP_PT_DYNAMIC in its 
     47 * payload type (i.e: pjmedia_codec_info.pt). Endpoint will automatically 
     48 * rearrange dynamic payload types in SDP generation. 
    4449 */ 
    4550enum pjmedia_audio_pt 
    4651{ 
    4752    /* According to IANA specifications, dynamic payload types are to be in 
    48      * the range 96-127 (inclusive). This enum is structured to place the 
    49      * values of the payload types specified below into that range. 
     53     * the range 96-127 (inclusive), but this enum allows the value to be 
     54     * outside that range, later endpoint will rearrange dynamic payload types 
     55     * in SDP generation to be inside the 96-127 range and not equal to 
     56     * PJMEDIA_RTP_PT_TELEPHONE_EVENTS. 
    5057     * 
    5158     * PJMEDIA_RTP_PT_DYNAMIC is defined in <pjmedia/codec.h>. It is defined 
    5259     * to be 96. 
    53      * 
    54      * PJMEDIA_RTP_PT_TELEPHONE_EVENTS is defined in <pjmedia/config.h>. 
    55      * The default value is 96. 
    5660     */ 
    57 #if PJMEDIA_RTP_PT_TELEPHONE_EVENTS 
    58     PJMEDIA_RTP_PT_START = PJMEDIA_RTP_PT_TELEPHONE_EVENTS, 
    59 #else 
    6061    PJMEDIA_RTP_PT_START = (PJMEDIA_RTP_PT_DYNAMIC-1), 
    61 #endif 
    6262 
    6363    PJMEDIA_RTP_PT_SPEEX_NB,                    /**< Speex narrowband/8KHz  */ 
     
    109109    PJMEDIA_RTP_PT_L16_48KHZ_STEREO,            /**< L16 @ 48KHz, stereo    */ 
    110110#endif 
    111  
    112     /* Caution! 
    113      * Ensure the value of the last pt above is <= 127. 
    114      */ 
    115111}; 
    116112 
  • pjproject/trunk/pjmedia/include/pjmedia/config.h

    r6005 r6105  
    845845 
    846846/** 
    847  * This macro declares the payload type for telephone-event 
     847 * This macro declares the start payload type for telephone-event 
    848848 * that is advertised by PJMEDIA for outgoing SDP. If this macro 
    849849 * is set to zero, telephone events would not be advertised nor 
    850850 * supported. 
    851  * 
    852  * If this value is changed to other number, please update the 
    853  * PJMEDIA_RTP_PT_TELEPHONE_EVENTS_STR too. 
    854851 */ 
    855852#ifndef PJMEDIA_RTP_PT_TELEPHONE_EVENTS 
    856 #   define PJMEDIA_RTP_PT_TELEPHONE_EVENTS          96 
    857 #endif 
    858  
    859  
    860 /** 
    861  * Macro to get the string representation of the telephone-event 
    862  * payload type. 
    863  */ 
    864 #ifndef PJMEDIA_RTP_PT_TELEPHONE_EVENTS_STR 
    865 #   define PJMEDIA_RTP_PT_TELEPHONE_EVENTS_STR      "96" 
     853#   define PJMEDIA_RTP_PT_TELEPHONE_EVENTS          120 
    866854#endif 
    867855 
  • pjproject/trunk/pjmedia/src/pjmedia/endpoint.c

    r6103 r6105  
    421421    unsigned televent_num = 0; 
    422422    unsigned televent_clockrates[8]; 
     423#endif 
    423424    unsigned used_pt_num = 0; 
    424425    unsigned used_pt[PJMEDIA_MAX_SDP_FMT]; 
    425 #endif 
    426426 
    427427    PJ_UNUSED_ARG(options); 
     
    430430    PJ_ASSERT_RETURN(endpt->codec_mgr.codec_cnt <= PJMEDIA_MAX_SDP_FMT, 
    431431                     PJ_ETOOMANY); 
     432 
     433    /* Insert PJMEDIA_RTP_PT_TELEPHONE_EVENTS as used PT */ 
     434#if defined(PJMEDIA_RTP_PT_TELEPHONE_EVENTS) && \ 
     435            PJMEDIA_RTP_PT_TELEPHONE_EVENTS != 0 
     436    if (endpt->has_telephone_event) { 
     437        used_pt[used_pt_num++] = PJMEDIA_RTP_PT_TELEPHONE_EVENTS; 
     438    } 
     439#endif 
    432440 
    433441    /* Create and init basic SDP media */ 
     
    445453        pjmedia_codec_param codec_param; 
    446454        pj_str_t *fmt; 
     455        unsigned pt; 
    447456 
    448457        if (endpt->codec_mgr.codec_desc[i].prio == PJMEDIA_CODEC_PRIO_DISABLED) 
     
    453462                                            &codec_param); 
    454463        fmt = &m->desc.fmt[m->desc.fmt_count++]; 
     464        pt = codec_info->pt; 
     465 
     466        /* Rearrange dynamic payload type to make sure it is inside 96-127 
     467         * range and not being used by other codec/tel-event. 
     468         */ 
     469        if (pt >= 96) { 
     470            unsigned pt_check = 96; 
     471            unsigned j = 0; 
     472            while (j < used_pt_num && pt_check <= 127) { 
     473                if (pt_check==used_pt[j]) { 
     474                    pt_check++; 
     475                    j = 0; 
     476                } else { 
     477                    j++; 
     478                } 
     479            } 
     480            if (pt_check > 127) { 
     481                /* No more available PT */ 
     482                PJ_LOG(4,(THIS_FILE, "Warning: no available dynamic " 
     483                          "payload type for audio codec")); 
     484                break; 
     485            } 
     486            pt = pt_check; 
     487        } 
     488 
     489        /* Take a note of used dynamic PT */ 
     490        if (pt >= 96) 
     491            used_pt[used_pt_num++] = pt; 
    455492 
    456493        fmt->ptr = (char*) pj_pool_alloc(pool, 8); 
    457         fmt->slen = pj_utoa(codec_info->pt, fmt->ptr); 
     494        fmt->slen = pj_utoa(pt, fmt->ptr); 
    458495 
    459496        rtpmap.pt = *fmt; 
     
    461498 
    462499#if defined(PJMEDIA_HANDLE_G722_MPEG_BUG) && (PJMEDIA_HANDLE_G722_MPEG_BUG != 0) 
    463         if (codec_info->pt == PJMEDIA_RTP_PT_G722) 
     500        if (pt == PJMEDIA_RTP_PT_G722) 
    464501            rtpmap.clock_rate = 8000; 
    465502        else 
     
    488525        } 
    489526 
    490         if (codec_info->pt >= 96 || pjmedia_add_rtpmap_for_static_pt) { 
     527        if (pt >= 96 || pjmedia_add_rtpmap_for_static_pt) { 
    491528            pjmedia_sdp_rtpmap_to_attr(pool, &rtpmap, &attr); 
    492529            m->attr[m->attr_count++] = attr; 
     
    504541                                        MAX_FMTP_STR_LEN - buf_len, 
    505542                                        "%d", 
    506                                         codec_info->pt); 
     543                                        pt); 
    507544 
    508545            for (ii = 0; ii < dec_fmtp->cnt; ++ii) { 
     
    549586            max_bitrate = codec_param.info.max_bps; 
    550587 
    551         /* List clock rate & channel count of audio codecs for generating 
    552          * telephone-event later. 
    553          */ 
     588        /* List clock rate of audio codecs for generating telephone-event */ 
    554589#if defined(PJMEDIA_RTP_PT_TELEPHONE_EVENTS) && \ 
    555590            PJMEDIA_RTP_PT_TELEPHONE_EVENTS != 0 
    556         { 
     591        if (endpt->has_telephone_event) { 
    557592            unsigned j; 
    558  
    559             /* Take a note of used dynamic PT */ 
    560             if (codec_info->pt >= 96) 
    561                 used_pt[used_pt_num++] = codec_info->pt; 
    562593 
    563594            for (j=0; j<televent_num; ++j) { 
     
    584615            char buf[160]; 
    585616            unsigned j = 0; 
    586             unsigned pt = PJMEDIA_RTP_PT_TELEPHONE_EVENTS; 
     617            unsigned pt; 
    587618 
    588619            /* Find PT for this tel-event */ 
    589             while (j < used_pt_num && pt <= 127) { 
    590                 if (pt == used_pt[j]) { 
    591                     pt++; 
     620            if (i == 0) { 
     621                /* First telephony-event always uses preconfigured PT 
     622                 * PJMEDIA_RTP_PT_TELEPHONE_EVENTS. 
     623                 */ 
     624                pt = PJMEDIA_RTP_PT_TELEPHONE_EVENTS; 
     625            } else { 
     626                /* Otherwise, find any free PT slot, starting from 
     627                 * (PJMEDIA_RTP_PT_TELEPHONE_EVENTS + 1). 
     628                 */ 
     629                pt = PJMEDIA_RTP_PT_TELEPHONE_EVENTS + 1; 
     630                while (j < used_pt_num && pt <= 127) { 
     631                    if (pt == used_pt[j]) { 
     632                        pt++; 
     633                        j = 0; 
     634                    } else { 
     635                        j++; 
     636                    } 
     637                } 
     638                if (pt > 127) { 
     639                    /* Not found? Find more, but now starting from 96 */ 
     640                    pt = 96; 
    592641                    j = 0; 
    593                 } else { 
    594                     j++; 
     642                    while (j < used_pt_num && 
     643                           pt < PJMEDIA_RTP_PT_TELEPHONE_EVENTS) 
     644                    { 
     645                        if (pt == used_pt[j]) { 
     646                            pt++; 
     647                            j = 0; 
     648                        } else { 
     649                            j++; 
     650                        } 
     651                    } 
     652                    if (pt >= PJMEDIA_RTP_PT_TELEPHONE_EVENTS) { 
     653                        /* No more available PT */ 
     654                        PJ_LOG(4,(THIS_FILE, "Warning: no available dynamic " 
     655                                  "payload type for telephone-event")); 
     656                        break; 
     657                    } 
    595658                } 
    596             } 
    597             if (pt > 127) { 
    598                 /* No more available PT */ 
    599                 break; 
    600659            } 
    601660            used_pt[used_pt_num++] = pt; 
Note: See TracChangeset for help on using the changeset viewer.