Ignore:
Timestamp:
Nov 13, 2019 9:11:04 AM (4 years ago)
Author:
nanang
Message:

Close #1437: Video keyframe request/response using RTCP-FB PLI.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/rtcp_fb.c

    r5827 r6106  
    2222#include <pjmedia/endpoint.h> 
    2323#include <pjmedia/errno.h> 
     24#include <pjmedia/vid_codec.h> 
    2425#include <pj/assert.h> 
    2526#include <pj/log.h> 
     
    215216{ 
    216217    pj_bzero(opt, sizeof(*opt)); 
     218    opt->dont_use_avpf = PJ_TRUE; 
    217219 
    218220    return PJ_SUCCESS; 
     
    332334    pjmedia_codec_mgr *codec_mgr; 
    333335    unsigned j, cnt = 0; 
     336    pjmedia_type type = PJMEDIA_TYPE_UNKNOWN; 
    334337    pj_status_t status; 
     338 
     339    type = pjmedia_get_type(&m->desc.media); 
     340    if (type != PJMEDIA_TYPE_AUDIO && type != PJMEDIA_TYPE_VIDEO) 
     341        return PJMEDIA_EUNSUPMEDIATYPE; 
    335342 
    336343    codec_mgr = pjmedia_endpt_get_codec_mgr(endpt); 
     
    339346        pt = pj_strtoul(&m->desc.fmt[j]); 
    340347        if (pt < 96) { 
    341             const pjmedia_codec_info *ci; 
    342             status = pjmedia_codec_mgr_get_codec_info(codec_mgr, 
    343                                                       pt, &ci); 
    344             if (status != PJ_SUCCESS) 
    345                 continue; 
    346  
    347             pjmedia_codec_info_to_id(ci, sci[cnt].id, sizeof(sci[0].id)); 
     348            if (type == PJMEDIA_TYPE_AUDIO) { 
     349                const pjmedia_codec_info *ci; 
     350                status = pjmedia_codec_mgr_get_codec_info(codec_mgr, pt, &ci); 
     351                if (status != PJ_SUCCESS) 
     352                    continue; 
     353 
     354                pjmedia_codec_info_to_id(ci, sci[cnt].id, sizeof(sci[0].id)); 
     355            } else { 
     356                const pjmedia_vid_codec_info *ci; 
     357                status = pjmedia_vid_codec_mgr_get_codec_info(NULL, pt, &ci); 
     358                if (status != PJ_SUCCESS) 
     359                    continue; 
     360 
     361                pjmedia_vid_codec_info_to_id(ci, sci[cnt].id, 
     362                                             sizeof(sci[0].id)); 
     363            } 
    348364        } else { 
    349365            pjmedia_sdp_attr *a; 
     
    356372            if (status != PJ_SUCCESS) 
    357373                continue; 
    358             if (r.param.slen) { 
     374 
     375            if (type == PJMEDIA_TYPE_AUDIO) { 
     376                /* Audio codec id format: "name/clock-rate/channel-count" */ 
     377                if (r.param.slen) { 
     378                    pj_ansi_snprintf(sci[cnt].id, sizeof(sci[0].id), 
     379                                     "%.*s/%d/%.*s", 
     380                                     (int)r.enc_name.slen, r.enc_name.ptr, 
     381                                     r.clock_rate, 
     382                                     (int)r.param.slen, r.param.ptr); 
     383                } else { 
     384                    pj_ansi_snprintf(sci[cnt].id, sizeof(sci[0].id), 
     385                                     "%.*s/%d/1", 
     386                                     (int)r.enc_name.slen, r.enc_name.ptr, 
     387                                     r.clock_rate); 
     388                } 
     389            } else { 
     390                /* Video codec id format: "name/payload-type" */ 
    359391                pj_ansi_snprintf(sci[cnt].id, sizeof(sci[0].id), 
    360                                  "%.*s/%d/%.*s", 
    361                                  (int)r.enc_name.slen, r.enc_name.ptr, 
    362                                  r.clock_rate, 
    363                                  (int)r.param.slen, r.param.ptr); 
    364             } else { 
    365                 pj_ansi_snprintf(sci[cnt].id, sizeof(sci[0].id), 
    366                                  "%.*s/%d/1", 
    367                                  (int)r.enc_name.slen, r.enc_name.ptr, 
    368                                  r.clock_rate); 
     392                                 "%.*s/%d", 
     393                                 (int)r.enc_name.slen, r.enc_name.ptr, pt); 
    369394            } 
    370395        } 
     
    396421    PJ_UNUSED_ARG(sdp_remote); 
    397422 
    398     PJ_ASSERT_RETURN(pool && endpt&& opt && sdp_local, PJ_EINVAL); 
     423    PJ_ASSERT_RETURN(pool && endpt && opt && sdp_local, PJ_EINVAL); 
    399424    PJ_ASSERT_RETURN(med_idx < sdp_local->media_count, PJ_EINVAL); 
    400425 
     
    403428        unsigned proto = pjmedia_sdp_transport_get_proto(&m->desc.transport); 
    404429        if (!PJMEDIA_TP_PROTO_HAS_FLAG(proto, PJMEDIA_TP_PROFILE_RTCP_FB)) { 
    405             char *new_tp; 
    406             new_tp = (char*)pj_pool_zalloc(pool, m->desc.transport.slen+1); 
    407             pj_ansi_strncpy(new_tp, m->desc.transport.ptr, 
    408                             m->desc.transport.slen); 
    409             pj_ansi_strcat(new_tp, "F"); 
    410             pj_strset2(&m->desc.transport, new_tp); 
     430            pj_str_t new_tp; 
     431            pj_strdup_with_null(pool, &new_tp, &m->desc.transport); 
     432            new_tp.ptr[new_tp.slen++] = 'F'; 
     433            m->desc.transport = new_tp; 
    411434        } 
    412435    } 
     
    477500                                    pjmedia_rtcp_fb_info *info) 
    478501{ 
     502    return pjmedia_rtcp_fb_decode_sdp2(pool, endpt, opt, sdp, med_idx, -1, 
     503                                       info); 
     504} 
     505 
     506/* 
     507 * Decode RTCP Feedback specific information from SDP media. 
     508 */ 
     509PJ_DEF(pj_status_t) pjmedia_rtcp_fb_decode_sdp2( 
     510                                    pj_pool_t *pool, 
     511                                    pjmedia_endpt *endpt, 
     512                                    const void *opt, 
     513                                    const pjmedia_sdp_session *sdp, 
     514                                    unsigned med_idx, 
     515                                    int pt, 
     516                                    pjmedia_rtcp_fb_info *info) 
     517{ 
    479518    unsigned sci_cnt = PJMEDIA_MAX_SDP_FMT; 
    480519    sdp_codec_info_t sci[PJMEDIA_MAX_SDP_FMT]; 
     
    487526    PJ_ASSERT_RETURN(pool && endpt && opt==NULL && sdp, PJ_EINVAL); 
    488527    PJ_ASSERT_RETURN(med_idx < sdp->media_count, PJ_EINVAL); 
     528    PJ_ASSERT_RETURN(pt <= 127, PJ_EINVAL); 
    489529 
    490530    m = sdp->media[med_idx]; 
     
    515555 
    516556        if (pj_strcmp2(&token, "*") == 0) { 
    517             /* Asterisk (all codecs) */ 
     557            /* All codecs */ 
    518558            codec_id = "*"; 
    519559        } else { 
    520             /* Specific PT */ 
    521             unsigned pt = (unsigned) pj_strtoul2(&token, NULL, 10); 
     560            /* Specific PT/codec */ 
     561            unsigned pt_ = (unsigned) pj_strtoul2(&token, NULL, 10); 
    522562            for (j = 0; j < sci_cnt; ++j) { 
    523                 if (pt == sci[j].pt) { 
     563                /* Check if payload type is valid and requested */ 
     564                if (pt_ == sci[j].pt && (pt < 0 || pt == (int)pt_)) { 
    524565                    codec_id = sci[j].id; 
    525566                    break; 
     
    528569        } 
    529570 
    530         /* Skip this a=rtcp-fb if PT is not recognized */ 
     571        /* Skip this a=rtcp-fb if PT is not recognized or not requested */ 
    531572        if (!codec_id) 
    532573            continue; 
Note: See TracChangeset for help on using the changeset viewer.