Ignore:
Timestamp:
Apr 29, 2006 8:31:09 AM (18 years ago)
Author:
bennylp
Message:

Improve codec handling in pjsua cmd-line options, and add URI to call

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r412 r422  
    8080#if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 
    8181    pjsua.clock_rate = 44100; 
    82 #else 
    83     pjsua.clock_rate = 8000; 
    8482#endif 
    8583    pjsua.complexity = -1; 
    8684    pjsua.quality = 4; 
    87     pjsua.has_wb = 0; 
    88     pjsua.has_uwb = 0; 
    8985 
    9086 
     
    621617static pj_status_t init_media(void) 
    622618{ 
     619    int i; 
    623620    unsigned options; 
     621    unsigned clock_rate; 
     622    unsigned samples_per_frame; 
     623    pj_str_t codec_id; 
    624624    pj_status_t status; 
    625625 
    626     /* If user doesn't specify any codecs, register all of them. */ 
    627     if (pjsua.codec_cnt == 0) { 
    628  
     626    /* Register all codecs */ 
    629627#if PJMEDIA_HAS_SPEEX_CODEC 
    630         unsigned option = PJMEDIA_SPEEX_NO_WB | PJMEDIA_SPEEX_NO_UWB; 
    631  
    632         /* Register speex. */ 
    633         if (pjsua.has_wb) 
    634             option &= ~PJMEDIA_SPEEX_NO_WB; 
    635         if (pjsua.has_uwb) 
    636             option &= ~PJMEDIA_SPEEX_NO_UWB; 
    637  
    638         status = pjmedia_codec_speex_init(pjsua.med_endpt, option,  
    639                                           pjsua.quality, pjsua.complexity ); 
    640         if (status != PJ_SUCCESS) { 
    641             pjsua_perror(THIS_FILE, "Error initializing Speex codec", 
    642                          status); 
    643             return status; 
    644         } 
    645  
    646         pjsua.codec_arg[pjsua.codec_cnt] = pj_str("speex"); 
    647         pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_speex_deinit; 
    648         pjsua.codec_cnt++; 
     628    /* Register speex. */ 
     629    status = pjmedia_codec_speex_init(pjsua.med_endpt,  
     630                                      PJMEDIA_SPEEX_NO_UWB, 
     631                                      pjsua.quality, pjsua.complexity ); 
     632    if (status != PJ_SUCCESS) { 
     633        pjsua_perror(THIS_FILE, "Error initializing Speex codec", 
     634                     status); 
     635        return status; 
     636    } 
     637 
     638    /* Set "speex/16000/1" to have highest priority */ 
     639    codec_id = pj_str("speex/16000/1"); 
     640    pjmedia_codec_mgr_set_codec_priority(  
     641        pjmedia_endpt_get_codec_mgr(pjsua.med_endpt), 
     642        &codec_id,  
     643        PJMEDIA_CODEC_PRIO_HIGHEST); 
     644 
    649645#endif /* PJMEDIA_HAS_SPEEX_CODEC */ 
    650646 
    651647#if PJMEDIA_HAS_GSM_CODEC 
    652         /* Register GSM */ 
    653         status = pjmedia_codec_gsm_init(pjsua.med_endpt); 
    654         if (status != PJ_SUCCESS) { 
    655             pjsua_perror(THIS_FILE, "Error initializing GSM codec", 
    656                          status); 
    657             return status; 
    658         } 
    659  
    660         pjsua.codec_arg[pjsua.codec_cnt] = pj_str("gsm"); 
    661         pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_gsm_deinit; 
    662         pjsua.codec_cnt++; 
     648    /* Register GSM */ 
     649    status = pjmedia_codec_gsm_init(pjsua.med_endpt); 
     650    if (status != PJ_SUCCESS) { 
     651        pjsua_perror(THIS_FILE, "Error initializing GSM codec", 
     652                     status); 
     653        return status; 
     654    } 
    663655#endif /* PJMEDIA_HAS_GSM_CODEC */ 
    664656 
     657#if PJMEDIA_HAS_G711_CODEC 
     658    /* Register PCMA and PCMU */ 
     659    status = pjmedia_codec_g711_init(pjsua.med_endpt); 
     660    if (status != PJ_SUCCESS) { 
     661        pjsua_perror(THIS_FILE, "Error initializing G711 codec", 
     662                     status); 
     663        return status; 
     664    } 
     665#endif  /* PJMEDIA_HAS_G711_CODEC */ 
     666 
    665667#if PJMEDIA_HAS_L16_CODEC 
    666         /* Register L16 */ 
    667         status = pjmedia_codec_l16_init(pjsua.med_endpt, 0); 
    668         if (status != PJ_SUCCESS) { 
    669             pjsua_perror(THIS_FILE, "Error initializing L16 codec", 
    670                          status); 
    671             return status; 
    672         } 
    673  
    674         pjsua.codec_arg[pjsua.codec_cnt] = pj_str("l16"); 
    675         pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_l16_deinit; 
    676         pjsua.codec_cnt++; 
    677 #endif /* PJMEDIA_HAS_L16_CODEC */ 
    678  
    679  
    680 #if PJMEDIA_HAS_G711_CODEC 
    681         /* Register PCMA and PCMU */ 
    682         status = pjmedia_codec_g711_init(pjsua.med_endpt); 
    683         if (status != PJ_SUCCESS) { 
    684             pjsua_perror(THIS_FILE, "Error initializing G711 codec", 
    685                          status); 
    686             return status; 
    687         } 
    688  
    689         pjsua.codec_arg[pjsua.codec_cnt] = pj_str("pcmu"); 
    690         pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_g711_deinit; 
    691         pjsua.codec_cnt++; 
    692         pjsua.codec_arg[pjsua.codec_cnt] = pj_str("pcma"); 
    693         pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_g711_deinit; 
    694         pjsua.codec_cnt++; 
    695 #endif  /* PJMEDIA_HAS_G711_CODEC */ 
    696  
    697     } else { 
    698  
    699         /* If user specifies the exact codec to be used, then create only 
    700          * those codecs. 
    701          */ 
    702         int i; 
    703  
    704         for (i=0; i<pjsua.codec_cnt; ++i) { 
     668    /* Register L16 family codecs, but disable all */ 
     669    status = pjmedia_codec_l16_init(pjsua.med_endpt, 0); 
     670    if (status != PJ_SUCCESS) { 
     671        pjsua_perror(THIS_FILE, "Error initializing L16 codecs", 
     672                     status); 
     673        return status; 
     674    } 
     675 
     676    /* Disable ALL L16 codecs */ 
     677    codec_id = pj_str("L16"); 
     678    pjmedia_codec_mgr_set_codec_priority(  
     679        pjmedia_endpt_get_codec_mgr(pjsua.med_endpt), 
     680        &codec_id,  
     681        PJMEDIA_CODEC_PRIO_DISABLED); 
     682 
     683#endif  /* PJMEDIA_HAS_L16_CODEC */ 
     684 
     685 
     686    /* If user specifies the exact codec to be used, then disable all codecs 
     687     * and only enable those specific codecs. 
     688     */ 
     689    if (pjsua.codec_cnt != 0) { 
     690        codec_id = pj_str(""); 
     691        pjmedia_codec_mgr_set_codec_priority(  
     692            pjmedia_endpt_get_codec_mgr(pjsua.med_endpt), 
     693            &codec_id,  
     694            PJMEDIA_CODEC_PRIO_DISABLED); 
     695    } 
     696 
    705697         
    706             if (0) { 
    707                 /* Dummy */ 
    708             } 
    709 #if PJMEDIA_HAS_SPEEX_CODEC 
    710             /* Is it speex? */ 
    711             else if (!pj_stricmp2(&pjsua.codec_arg[i], "speex")) { 
    712  
    713                 unsigned option = PJMEDIA_SPEEX_NO_WB | PJMEDIA_SPEEX_NO_UWB; 
    714  
    715                 /* Register speex. */ 
    716                 if (pjsua.has_wb) 
    717                     option &= ~(PJMEDIA_SPEEX_NO_WB); 
    718                 if (pjsua.has_uwb) 
    719                     option &= ~(PJMEDIA_SPEEX_NO_UWB); 
    720  
    721                 status = pjmedia_codec_speex_init(pjsua.med_endpt, option, 
    722                                                   -1, -1); 
    723                 if (status != PJ_SUCCESS) { 
    724                     pjsua_perror(THIS_FILE, "Error initializing Speex codec", 
    725                                  status); 
    726                     return status; 
    727                 } 
    728  
    729                 pjsua.codec_deinit[i] = &pjmedia_codec_speex_deinit; 
    730             } 
    731 #endif  /* PJMEDIA_HAS_SPEEX_CODEC */ 
    732  
    733 #if PJMEDIA_HAS_GSM_CODEC 
    734             /* Is it gsm? */ 
    735             else if (!pj_stricmp2(&pjsua.codec_arg[i], "gsm")) { 
    736  
    737                 status = pjmedia_codec_gsm_init(pjsua.med_endpt); 
    738                 if (status != PJ_SUCCESS) { 
    739                     pjsua_perror(THIS_FILE, "Error initializing GSM codec", 
    740                                  status); 
    741                     return status; 
    742                 } 
    743  
    744                 pjsua.codec_deinit[i] = &pjmedia_codec_gsm_deinit; 
    745  
    746             } 
    747 #endif  /* PJMEDIA_HAS_GSM_CODEC */ 
    748  
    749 #if PJMEDIA_HAS_L16_CODEC 
    750             /* Is it l16? */ 
    751             else if (!pj_stricmp2(&pjsua.codec_arg[i], "l16")) { 
    752  
    753                 status = pjmedia_codec_l16_init(pjsua.med_endpt, 0); 
    754                 if (status != PJ_SUCCESS) { 
    755                     pjsua_perror(THIS_FILE, "Error initializing L16 codec", 
    756                                  status); 
    757                     return status; 
    758                 } 
    759  
    760                 pjsua.codec_deinit[i] = &pjmedia_codec_l16_deinit; 
    761  
    762                 pjsua.clock_rate = 44100; 
    763             } 
    764 #endif  /* PJMEDIA_HAS_L16_CODEC */ 
    765  
    766 #if PJMEDIA_HAS_G711_CODEC 
    767             /* Is it pcma/pcmu? */ 
    768             else if (!pj_stricmp2(&pjsua.codec_arg[i], "pcmu") || 
    769                      !pj_stricmp2(&pjsua.codec_arg[i], "pcma")) 
    770             { 
    771  
    772                 status = pjmedia_codec_g711_init(pjsua.med_endpt); 
    773                 if (status != PJ_SUCCESS) { 
    774                     pjsua_perror(THIS_FILE, "Error initializing G711 codec", 
    775                                  status); 
    776                     return status; 
    777                 } 
    778  
    779                 pjsua.codec_deinit[i] = &pjmedia_codec_g711_deinit; 
    780  
    781             } 
    782 #endif  /* PJMEDIA_HAS_G711_CODEC */ 
    783  
    784             /* Don't know about this codec... */ 
    785             else { 
    786  
    787                 PJ_LOG(1,(THIS_FILE, "Error: unsupported codecs %s", 
    788                           pjsua.codec_arg[i].ptr)); 
    789                 return PJMEDIA_CODEC_EUNSUP; 
    790             } 
    791         } 
    792     } 
     698 
     699    for (i=0; i<pjsua.codec_cnt; ++i) { 
     700        pjmedia_codec_mgr_set_codec_priority(  
     701            pjmedia_endpt_get_codec_mgr(pjsua.med_endpt), 
     702            &pjsua.codec_arg[i],  
     703            PJMEDIA_CODEC_PRIO_NEXT_HIGHER); 
     704    } 
     705 
    793706 
    794707    /* Init options for conference bridge. */ 
     
    798711 
    799712    /* Init conference bridge. */ 
    800  
     713    clock_rate = pjsua.clock_rate ? pjsua.clock_rate : 16000; 
     714    samples_per_frame = clock_rate * 20 / 1000; 
    801715    status = pjmedia_conf_create(pjsua.pool,  
    802716                                 pjsua.max_calls+PJSUA_CONF_MORE_PORTS,  
    803                                  pjsua.clock_rate,  
     717                                 clock_rate,  
    804718                                 1, /* mono */ 
    805                                  pjsua.clock_rate * 20 / 1000, 16,  
     719                                 samples_per_frame,  
     720                                 16,  
    806721                                 options, 
    807722                                 &pjsua.mconf); 
     
    814729 
    815730    /* Add NULL port to the bridge. */ 
    816     status = pjmedia_null_port_create( pjsua.pool, pjsua.clock_rate,  
     731    status = pjmedia_null_port_create( pjsua.pool, clock_rate,  
    817732                                       1, /* mono */ 
    818                                        pjsua.clock_rate * 20 / 1000, 16, 
     733                                       samples_per_frame, 16, 
    819734                                       &pjsua.null_port); 
    820735    pjmedia_conf_add_port( pjsua.mconf, pjsua.pool, pjsua.null_port,  
     
    11281043 
    11291044    /* Shutdown all codecs: */ 
    1130     for (i = pjsua.codec_cnt-1; i >= 0; --i) { 
    1131         (*pjsua.codec_deinit[i])(); 
    1132     } 
     1045#if PJMEDIA_HAS_SPEEX_CODEC 
     1046    pjmedia_codec_speex_deinit(); 
     1047#endif /* PJMEDIA_HAS_SPEEX_CODEC */ 
     1048 
     1049#if PJMEDIA_HAS_GSM_CODEC 
     1050    pjmedia_codec_gsm_deinit(); 
     1051#endif /* PJMEDIA_HAS_GSM_CODEC */ 
     1052 
     1053#if PJMEDIA_HAS_G711_CODEC 
     1054    pjmedia_codec_g711_deinit(); 
     1055#endif  /* PJMEDIA_HAS_G711_CODEC */ 
     1056 
     1057#if PJMEDIA_HAS_L16_CODEC 
     1058    pjmedia_codec_l16_deinit(); 
     1059#endif  /* PJMEDIA_HAS_L16_CODEC */ 
    11331060 
    11341061    /* Destroy media endpoint. */ 
Note: See TracChangeset for help on using the changeset viewer.