Changeset 5460 for pjproject


Ignore:
Timestamp:
Oct 13, 2016 11:49:57 AM (7 years ago)
Author:
riza
Message:

Re #1970: Implement function pjmedia_rtp_decode_rtp2().

Location:
pjproject/trunk/pjmedia
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/include/pjmedia/rtp.h

    r3553 r5460  
    114114 
    115115/** 
    116  * RTP extendsion header. 
     116 * RTP extension header. 
    117117 */ 
    118118struct pjmedia_rtp_ext_hdr 
     
    127127typedef struct pjmedia_rtp_ext_hdr pjmedia_rtp_ext_hdr; 
    128128 
     129/** 
     130 * This will contain the RTP header decode output. 
     131 */ 
     132struct pjmedia_rtp_dec_hdr 
     133{ 
     134    /* RTP extension header output decode */ 
     135    pjmedia_rtp_ext_hdr *ext_hdr; 
     136    pj_uint32_t *ext; 
     137    unsigned ext_len; 
     138}; 
     139 
     140/** 
     141 * @see pjmedia_rtp_dec_hdr 
     142 */ 
     143typedef struct pjmedia_rtp_dec_hdr pjmedia_rtp_dec_hdr; 
    129144 
    130145#pragma pack(1) 
     
    322337                                             unsigned *payloadlen); 
    323338 
     339 
     340/** 
     341 * This function decodes incoming packet into RTP header and payload. 
     342 * The decode function is guaranteed to point the payload to the correct 
     343 * position regardless of any options present in the RTP packet. 
     344 * 
     345 * Note that this function does not modify the returned RTP header to 
     346 * host byte order. 
     347 * 
     348 * @param ses           The session. 
     349 * @param pkt           The received RTP packet. 
     350 * @param pkt_len       The length of the packet. 
     351 * @param hdr           Upon return will point to the location of the RTP 
     352 *                      header inside the packet. Note that the RTP header 
     353 *                      will be given back as is, meaning that the fields 
     354 *                      will be in network byte order. 
     355 * @param dec_hdr       Upon return will point to the location of the  
     356 *                      additional RTP header inside the packet, if any. 
     357 * @param payload       Upon return will point to the location of the 
     358 *                      payload inside the packet. 
     359 * @param payloadlen    Upon return will indicate the size of the payload. 
     360 * 
     361 * @return              PJ_SUCCESS if successfull. 
     362 */ 
     363PJ_DECL(pj_status_t) pjmedia_rtp_decode_rtp2( 
     364                                    pjmedia_rtp_session *ses, 
     365                                    const void *pkt, int pkt_len, 
     366                                    const pjmedia_rtp_hdr **hdr, 
     367                                    pjmedia_rtp_dec_hdr *dec_hdr, 
     368                                    const void **payload, 
     369                                    unsigned *payloadlen); 
     370 
    324371/** 
    325372 * Call this function everytime an RTP packet is received to check whether  
  • pjproject/trunk/pjmedia/src/pjmedia/rtp.c

    r4235 r5460  
    150150                                            unsigned *payloadlen) 
    151151{ 
     152    pjmedia_rtp_dec_hdr dec_hdr; 
     153 
     154    return pjmedia_rtp_decode_rtp2(ses, pkt, pkt_len, hdr, &dec_hdr,  
     155                                   payload, payloadlen); 
     156} 
     157 
     158 
     159PJ_DEF(pj_status_t) pjmedia_rtp_decode_rtp2( 
     160                                            pjmedia_rtp_session *ses, 
     161                                            const void *pkt, int pkt_len, 
     162                                            const pjmedia_rtp_hdr **hdr, 
     163                                            pjmedia_rtp_dec_hdr *dec_hdr, 
     164                                            const void **payload, 
     165                                            unsigned *payloadlen) 
     166{ 
    152167    int offset; 
    153168 
     
    165180    offset = sizeof(pjmedia_rtp_hdr) + ((*hdr)->cc * sizeof(pj_uint32_t)); 
    166181 
    167     /* Adjust offset if RTP extension is used. */ 
     182    /* Decode RTP extension. */ 
    168183    if ((*hdr)->x) { 
    169         pjmedia_rtp_ext_hdr *ext = (pjmedia_rtp_ext_hdr*)  
    170                                     (((pj_uint8_t*)pkt) + offset); 
    171         offset += ((pj_ntohs(ext->length)+1) * sizeof(pj_uint32_t)); 
     184        dec_hdr->ext_hdr = (pjmedia_rtp_ext_hdr*)(((pj_uint8_t*)pkt) + offset); 
     185        dec_hdr->ext = (pj_uint32_t*)(dec_hdr->ext_hdr + 1); 
     186        dec_hdr->ext_len = pj_ntohs((dec_hdr->ext_hdr)->length); 
     187        offset += ((dec_hdr->ext_len + 1) * sizeof(pj_uint32_t)); 
     188    } else { 
     189        dec_hdr->ext_hdr = NULL; 
     190        dec_hdr->ext = NULL; 
     191        dec_hdr->ext_len = 0; 
    172192    } 
    173193 
Note: See TracChangeset for help on using the changeset viewer.