Changeset 278


Ignore:
Timestamp:
Mar 4, 2006 8:43:52 PM (18 years ago)
Author:
bennylp
Message:

Added Speex for narrowband, wideband, and ultra-wideband!!

Location:
pjproject/trunk
Files:
102 added
12 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/build/pjmedia.dsp

    r277 r278  
    206206# Begin Source File 
    207207 
     208SOURCE=..\include\pjmedia\g711.h 
     209# End Source File 
     210# Begin Source File 
     211 
    208212SOURCE=..\include\pjmedia\jbuf.h 
    209213# End Source File 
  • pjproject/trunk/pjmedia/build/pjmedia_codec.dsp

    r198 r278  
    4242# PROP Target_Dir "" 
    4343# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c 
    44 # ADD CPP /nologo /MD /W4 /GX /O2 /I "../include" /I "../../pjlib/include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D PJ_WIN32=1 /D PJ_M_I386=1 /YX /FD /c 
     44# ADD CPP /nologo /MD /W4 /GX- /O2 /I "../include" /I "../../pjlib/include" /I "../src/pjmedia-codec" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D PJ_WIN32=1 /D PJ_M_I386=1 /D "HAVE_CONFIG_H" /FD /c 
     45# SUBTRACT CPP /YX 
    4546# ADD BASE RSC /l 0x409 /d "NDEBUG" 
    4647# ADD RSC /l 0x409 /d "NDEBUG" 
     
    6566# PROP Target_Dir "" 
    6667# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c 
    67 # ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "../include" /I "../../pjlib/include" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D PJ_WIN32=1 /D PJ_M_I386=1 /FR /YX /FD /GZ /c 
     68# ADD CPP /nologo /MTd /W4 /Gm /GX- /ZI /Od /I "../include" /I "../../pjlib/include" /I "../src/pjmedia-codec" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D PJ_WIN32=1 /D PJ_M_I386=1 /D "HAVE_CONFIG_H" /FR /FD /GZ /c 
     69# SUBTRACT CPP /YX 
    6870# ADD BASE RSC /l 0x409 /d "_DEBUG" 
    6971# ADD RSC /l 0x409 /d "_DEBUG" 
     
    9294SOURCE="..\src\pjmedia-codec\pjmedia-codec-lib.c" 
    9395# End Source File 
     96# Begin Source File 
     97 
     98SOURCE="..\src\pjmedia-codec\speex_codec.c" 
     99# End Source File 
    94100# End Group 
    95101# Begin Group "Header Files" 
     
    110116# Begin Source File 
    111117 
     118SOURCE="..\include\pjmedia-codec\speex.h" 
     119# End Source File 
     120# Begin Source File 
     121 
    112122SOURCE="..\include\pjmedia-codec\types.h" 
    113123# End Source File 
     
    204214SOURCE="..\src\pjmedia-codec\gsm\unproto.h" 
    205215# End Source File 
     216# End Group 
     217# Begin Group "Speex Codec" 
     218 
     219# PROP Default_Filter "" 
     220# Begin Group "Speex Header Files" 
     221 
     222# PROP Default_Filter "" 
     223# Begin Source File 
     224 
     225SOURCE="..\src\pjmedia-codec\speex\arch.h" 
     226# End Source File 
     227# Begin Source File 
     228 
     229SOURCE="..\src\pjmedia-codec\speex\cb_search.h" 
     230# End Source File 
     231# Begin Source File 
     232 
     233SOURCE="..\src\pjmedia-codec\speex\cb_search_arm4.h" 
     234# End Source File 
     235# Begin Source File 
     236 
     237SOURCE="..\src\pjmedia-codec\speex\cb_search_bfin.h" 
     238# End Source File 
     239# Begin Source File 
     240 
     241SOURCE="..\src\pjmedia-codec\speex\cb_search_sse.h" 
     242# End Source File 
     243# Begin Source File 
     244 
     245SOURCE="..\src\pjmedia-codec\speex\config.h" 
     246# End Source File 
     247# Begin Source File 
     248 
     249SOURCE="..\src\pjmedia-codec\speex\filters.h" 
     250# End Source File 
     251# Begin Source File 
     252 
     253SOURCE="..\src\pjmedia-codec\speex\filters_arm4.h" 
     254# End Source File 
     255# Begin Source File 
     256 
     257SOURCE="..\src\pjmedia-codec\speex\filters_bfin.h" 
     258# End Source File 
     259# Begin Source File 
     260 
     261SOURCE="..\src\pjmedia-codec\speex\filters_sse.h" 
     262# End Source File 
     263# Begin Source File 
     264 
     265SOURCE="..\src\pjmedia-codec\speex\fixed_arm4.h" 
     266# End Source File 
     267# Begin Source File 
     268 
     269SOURCE="..\src\pjmedia-codec\speex\fixed_arm5e.h" 
     270# End Source File 
     271# Begin Source File 
     272 
     273SOURCE="..\src\pjmedia-codec\speex\fixed_bfin.h" 
     274# End Source File 
     275# Begin Source File 
     276 
     277SOURCE="..\src\pjmedia-codec\speex\fixed_debug.h" 
     278# End Source File 
     279# Begin Source File 
     280 
     281SOURCE="..\src\pjmedia-codec\speex\fixed_generic.h" 
     282# End Source File 
     283# Begin Source File 
     284 
     285SOURCE="..\src\pjmedia-codec\speex\lpc.h" 
     286# End Source File 
     287# Begin Source File 
     288 
     289SOURCE="..\src\pjmedia-codec\speex\lpc_bfin.h" 
     290# End Source File 
     291# Begin Source File 
     292 
     293SOURCE="..\src\pjmedia-codec\speex\lsp.h" 
     294# End Source File 
     295# Begin Source File 
     296 
     297SOURCE="..\src\pjmedia-codec\speex\ltp.h" 
     298# End Source File 
     299# Begin Source File 
     300 
     301SOURCE="..\src\pjmedia-codec\speex\ltp_arm4.h" 
     302# End Source File 
     303# Begin Source File 
     304 
     305SOURCE="..\src\pjmedia-codec\speex\ltp_bfin.h" 
     306# End Source File 
     307# Begin Source File 
     308 
     309SOURCE="..\src\pjmedia-codec\speex\ltp_sse.h" 
     310# End Source File 
     311# Begin Source File 
     312 
     313SOURCE="..\src\pjmedia-codec\speex\math_approx.h" 
     314# End Source File 
     315# Begin Source File 
     316 
     317SOURCE="..\src\pjmedia-codec\speex\misc.h" 
     318# End Source File 
     319# Begin Source File 
     320 
     321SOURCE="..\src\pjmedia-codec\speex\misc_bfin.h" 
     322# End Source File 
     323# Begin Source File 
     324 
     325SOURCE="..\src\pjmedia-codec\speex\modes.h" 
     326# End Source File 
     327# Begin Source File 
     328 
     329SOURCE="..\src\pjmedia-codec\speex\nb_celp.h" 
     330# End Source File 
     331# Begin Source File 
     332 
     333SOURCE="..\src\pjmedia-codec\speex\pseudofloat.h" 
     334# End Source File 
     335# Begin Source File 
     336 
     337SOURCE="..\src\pjmedia-codec\speex\quant_lsp.h" 
     338# End Source File 
     339# Begin Source File 
     340 
     341SOURCE="..\src\pjmedia-codec\speex\sb_celp.h" 
     342# End Source File 
     343# Begin Source File 
     344 
     345SOURCE="..\src\pjmedia-codec\speex\smallft.h" 
     346# End Source File 
     347# Begin Source File 
     348 
     349SOURCE="..\src\pjmedia-codec\speex\speex.h" 
     350# End Source File 
     351# Begin Source File 
     352 
     353SOURCE="..\src\pjmedia-codec\speex\speex_bits.h" 
     354# End Source File 
     355# Begin Source File 
     356 
     357SOURCE="..\src\pjmedia-codec\speex\speex_callbacks.h" 
     358# End Source File 
     359# Begin Source File 
     360 
     361SOURCE="..\src\pjmedia-codec\speex\speex_echo.h" 
     362# End Source File 
     363# Begin Source File 
     364 
     365SOURCE="..\src\pjmedia-codec\speex\speex_header.h" 
     366# End Source File 
     367# Begin Source File 
     368 
     369SOURCE="..\src\pjmedia-codec\speex\speex_jitter.h" 
     370# End Source File 
     371# Begin Source File 
     372 
     373SOURCE="..\src\pjmedia-codec\speex\speex_preprocess.h" 
     374# End Source File 
     375# Begin Source File 
     376 
     377SOURCE="..\src\pjmedia-codec\speex\speex_stereo.h" 
     378# End Source File 
     379# Begin Source File 
     380 
     381SOURCE="..\src\pjmedia-codec\speex\speex_types.h" 
     382# End Source File 
     383# Begin Source File 
     384 
     385SOURCE="..\src\pjmedia-codec\speex\stack_alloc.h" 
     386# End Source File 
     387# Begin Source File 
     388 
     389SOURCE="..\src\pjmedia-codec\speex\vbr.h" 
     390# End Source File 
     391# Begin Source File 
     392 
     393SOURCE="..\src\pjmedia-codec\speex\vq.h" 
     394# End Source File 
     395# Begin Source File 
     396 
     397SOURCE="..\src\pjmedia-codec\speex\vq_arm4.h" 
     398# End Source File 
     399# Begin Source File 
     400 
     401SOURCE="..\src\pjmedia-codec\speex\vq_bfin.h" 
     402# End Source File 
     403# Begin Source File 
     404 
     405SOURCE="..\src\pjmedia-codec\speex\vq_sse.h" 
     406# End Source File 
     407# End Group 
     408# Begin Group "Speex Source Files" 
     409 
     410# PROP Default_Filter "" 
     411# Begin Source File 
     412 
     413SOURCE="..\src\pjmedia-codec\speex\bits.c" 
     414# End Source File 
     415# Begin Source File 
     416 
     417SOURCE="..\src\pjmedia-codec\speex\cb_search.c" 
     418# End Source File 
     419# Begin Source File 
     420 
     421SOURCE="..\src\pjmedia-codec\speex\exc_10_16_table.c" 
     422# End Source File 
     423# Begin Source File 
     424 
     425SOURCE="..\src\pjmedia-codec\speex\exc_10_32_table.c" 
     426# End Source File 
     427# Begin Source File 
     428 
     429SOURCE="..\src\pjmedia-codec\speex\exc_20_32_table.c" 
     430# End Source File 
     431# Begin Source File 
     432 
     433SOURCE="..\src\pjmedia-codec\speex\exc_5_256_table.c" 
     434# End Source File 
     435# Begin Source File 
     436 
     437SOURCE="..\src\pjmedia-codec\speex\exc_5_64_table.c" 
     438# End Source File 
     439# Begin Source File 
     440 
     441SOURCE="..\src\pjmedia-codec\speex\exc_8_128_table.c" 
     442# End Source File 
     443# Begin Source File 
     444 
     445SOURCE="..\src\pjmedia-codec\speex\filters.c" 
     446# End Source File 
     447# Begin Source File 
     448 
     449SOURCE="..\src\pjmedia-codec\speex\gain_table.c" 
     450# End Source File 
     451# Begin Source File 
     452 
     453SOURCE="..\src\pjmedia-codec\speex\gain_table_lbr.c" 
     454# End Source File 
     455# Begin Source File 
     456 
     457SOURCE="..\src\pjmedia-codec\speex\hexc_10_32_table.c" 
     458# End Source File 
     459# Begin Source File 
     460 
     461SOURCE="..\src\pjmedia-codec\speex\hexc_table.c" 
     462# End Source File 
     463# Begin Source File 
     464 
     465SOURCE="..\src\pjmedia-codec\speex\high_lsp_tables.c" 
     466# End Source File 
     467# Begin Source File 
     468 
     469SOURCE="..\src\pjmedia-codec\speex\lpc_spx.c" 
     470# End Source File 
     471# Begin Source File 
     472 
     473SOURCE="..\src\pjmedia-codec\speex\lsp.c" 
     474# End Source File 
     475# Begin Source File 
     476 
     477SOURCE="..\src\pjmedia-codec\speex\lsp_tables_nb.c" 
     478# End Source File 
     479# Begin Source File 
     480 
     481SOURCE="..\src\pjmedia-codec\speex\ltp.c" 
     482# End Source File 
     483# Begin Source File 
     484 
     485SOURCE="..\src\pjmedia-codec\speex\math_approx.c" 
     486# End Source File 
     487# Begin Source File 
     488 
     489SOURCE="..\src\pjmedia-codec\speex\misc.c" 
     490# End Source File 
     491# Begin Source File 
     492 
     493SOURCE="..\src\pjmedia-codec\speex\modes.c" 
     494# End Source File 
     495# Begin Source File 
     496 
     497SOURCE="..\src\pjmedia-codec\speex\nb_celp.c" 
     498# End Source File 
     499# Begin Source File 
     500 
     501SOURCE="..\src\pjmedia-codec\speex\preprocess_spx.c" 
     502# End Source File 
     503# Begin Source File 
     504 
     505SOURCE="..\src\pjmedia-codec\speex\quant_lsp.c" 
     506# End Source File 
     507# Begin Source File 
     508 
     509SOURCE="..\src\pjmedia-codec\speex\sb_celp.c" 
     510# End Source File 
     511# Begin Source File 
     512 
     513SOURCE="..\src\pjmedia-codec\speex\smallft.c" 
     514# End Source File 
     515# Begin Source File 
     516 
     517SOURCE="..\src\pjmedia-codec\speex\speex.c" 
     518# End Source File 
     519# Begin Source File 
     520 
     521SOURCE="..\src\pjmedia-codec\speex\speex_callbacks.c" 
     522# End Source File 
     523# Begin Source File 
     524 
     525SOURCE="..\src\pjmedia-codec\speex\speex_header.c" 
     526# End Source File 
     527# Begin Source File 
     528 
     529SOURCE="..\src\pjmedia-codec\speex\stereo.c" 
     530# End Source File 
     531# Begin Source File 
     532 
     533SOURCE="..\src\pjmedia-codec\speex\vbr.c" 
     534# End Source File 
     535# Begin Source File 
     536 
     537SOURCE="..\src\pjmedia-codec\speex\vq.c" 
     538# End Source File 
     539# End Group 
    206540# End Group 
    207541# End Target 
  • pjproject/trunk/pjmedia/include/pjmedia-codec.h

    r176 r278  
    2020#define __PJMEDIA_CODEC1_H__ 
    2121 
    22 #include <pjmedia-codec/types.h> 
     22#include <pjmedia-codec/gsm.h> 
     23#include <pjmedia-codec/speex.h> 
     24 
    2325 
    2426PJ_BEGIN_DECL 
     
    2729/** 
    2830 * Initialize pjmedia-codec library, and register all codec factories 
    29  * in this library. 
     31 * in this library. If application wants to controll the order of 
     32 * the codec, it MUST NOT call this function, but instead register 
     33 * each codec individually. 
    3034 * 
    3135 * @param endpt     The pjmedia endpoint. 
  • pjproject/trunk/pjmedia/include/pjmedia-codec/config.h

    r176 r278  
    3131 
    3232 
     33/* 
     34 * Include Speex codec? 
     35 */ 
     36#ifndef PJMEDIA_CODEC_HAS_SPEEX 
     37#   define PJMEDIA_CODEC_HAS_SPEEX    1 
     38#endif 
     39 
     40 
    3341 
    3442#endif  /* __PJMEDIA_CODEC_CONFIG_H__ */ 
  • pjproject/trunk/pjmedia/include/pjmedia.h

    r222 r278  
    3131#include <pjmedia/errno.h> 
    3232#include <pjmedia/file_port.h> 
     33#include <pjmedia/g711.h> 
    3334#include <pjmedia/jbuf.h> 
    3435#include <pjmedia/port.h> 
  • pjproject/trunk/pjmedia/src/pjmedia-codec/pjmedia-codec-lib.c

    r198 r278  
    2222#include <pjmedia-codec/config.h> 
    2323#include <pjmedia-codec/gsm.h> 
     24#include <pjmedia-codec/speex.h> 
    2425 
    2526 
     
    3435#if PJMEDIA_CODEC_HAS_GSM 
    3536    { &pjmedia_codec_gsm_init, &pjmedia_codec_gsm_deinit}, 
     37#endif 
     38 
     39#if PJMEDIA_CODEC_HAS_SPEEX 
     40    { &pjmedia_codec_speex_init_default, &pjmedia_codec_speex_deinit}, 
    3641#endif 
    3742 
  • pjproject/trunk/pjmedia/src/pjmedia/conference.c

    r277 r278  
    890890{ 
    891891    pj_int16_t *buf; 
     892    pj_bool_t sent = PJ_FALSE; 
    892893    unsigned j; 
    893894 
     
    965966         
    966967        pjmedia_frame frame; 
     968        pj_status_t status; 
    967969 
    968970        frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 
     
    972974 
    973975        if (cport->port) 
    974             return pjmedia_port_put_frame(cport->port, &frame); 
     976            status = pjmedia_port_put_frame(cport->port, &frame); 
    975977        else 
    976             return PJ_SUCCESS; 
     978            status = PJ_SUCCESS; 
     979 
     980        cport->tx_buf_count -= cport->samples_per_frame; 
     981        if (cport->tx_buf_count) { 
     982            copy_samples(cport->tx_buf,  
     983                         cport->tx_buf + cport->samples_per_frame, 
     984                         cport->tx_buf_count); 
     985        } 
     986 
     987        return status; 
    977988    } 
    978989 
  • pjproject/trunk/pjmedia/src/pjmedia/endpoint.c

    r215 r278  
    3939 
    4040 
    41 PJ_DECL(pj_status_t) g711_init_factory (pjmedia_codec_factory *factory, pj_pool_t *pool); 
    42 PJ_DECL(pj_status_t) g711_deinit_factory (pjmedia_codec_factory *factory); 
    4341 
    4442/* Flag to indicate whether pjmedia error subsystem has been registered 
     
    9088    pj_pool_t *pool; 
    9189    pjmedia_endpt *endpt; 
    92     pjmedia_codec_factory *factory; 
    9390    pj_status_t status; 
    9491 
     
    120117 
    121118    /* Init and register G.711 codec. */ 
     119#if 0 
     120    // Starting from 0.5.4, codec factory is registered by applications. 
    122121    factory = pj_pool_alloc (endpt->pool, sizeof(pjmedia_codec_factory)); 
    123122 
     
    133132        goto on_error; 
    134133    } 
     134#endif 
    135135 
    136136    *p_endpt = endpt; 
     
    327327 
    328328        PJ_LOG(3,(THIS_FILE,  
    329                   "   %s codec #%2d: pt=%d (%.*s, %d bps, ptime=%d ms, vad=%d, cng=%d)",  
     329                  "   %s codec #%2d: pt=%d (%.*s @%dKHz, %d bps, ptime=%d ms, vad=%d, cng=%d)",  
    330330                  type, i, codec_info[i].pt, 
    331331                  (int)codec_info[i].encoding_name.slen, 
    332332                  codec_info[i].encoding_name.ptr, 
     333                  codec_info[i].sample_rate/1000, 
    333334                  param.avg_bps, param.ptime, 
    334335                  param.vad_enabled, 
  • pjproject/trunk/pjmedia/src/pjmedia/g711.c

    r205 r278  
    2121 */ 
    2222#include <pjmedia/codec.h> 
     23#include <pjmedia/endpoint.h> 
    2324#include <pjmedia/errno.h> 
    2425#include <pjmedia/port.h> 
     
    101102 
    102103/* G711 factory private data */ 
    103 struct g711_factory_private 
    104 { 
    105     pj_pool_t  *pool; 
    106     pjmedia_codec       codec_list; 
    107 }; 
     104static struct g711_factory 
     105{ 
     106    pjmedia_codec_factory       base; 
     107    pjmedia_endpt              *endpt; 
     108    pj_pool_t                  *pool; 
     109    pj_mutex_t                 *mutex; 
     110    pjmedia_codec               codec_list; 
     111} g711_factory; 
    108112 
    109113/* G711 codec private data. */ 
     
    114118 
    115119 
    116 PJ_DEF(pj_status_t) g711_init_factory (pjmedia_codec_factory *factory, pj_pool_t *pool) 
    117 { 
    118     struct g711_factory_private *priv; 
    119     //enum { CODEC_MEM_SIZE = sizeof(pjmedia_codec) + sizeof(struct g711_private) + 4 }; 
    120  
    121     /* Create pool. */ 
    122     /* 
    123     pool = pj_pool_pool_create_pool(pp, "g711ftry",  
    124                                         G711_CODEC_CNT*CODEC_MEM_SIZE +  
    125                                         sizeof(struct g711_factory_private), 
    126                                         CODEC_MEM_SIZE, NULL); 
    127     if (!pool) 
    128         return -1; 
    129     */ 
    130  
    131     priv = pj_pool_alloc(pool, sizeof(struct g711_factory_private)); 
    132     if (!priv) 
    133         return -1; 
    134  
    135     factory->factory_data = priv; 
    136     factory->op = &g711_factory_op; 
    137  
    138     priv->pool = pool; 
    139     pj_list_init(&priv->codec_list); 
     120PJ_DEF(pj_status_t) g711_deinit_factory (pjmedia_codec_factory *factory) 
     121{ 
     122    PJ_ASSERT_RETURN(factory==&g711_factory.base, PJ_EINVAL); 
     123 
     124    /* Invalidate member to help detect errors */ 
     125    g711_factory.codec_list.next = g711_factory.codec_list.prev = NULL; 
    140126    return 0; 
    141127} 
    142128 
    143 PJ_DEF(pj_status_t) g711_deinit_factory (pjmedia_codec_factory *factory) 
    144 { 
    145     struct g711_factory_private *priv = factory->factory_data; 
    146  
    147     /* Invalidate member to help detect errors */ 
    148     priv->pool = NULL; 
    149     priv->codec_list.next = priv->codec_list.prev = NULL; 
    150     return 0; 
     129PJ_DEF(pj_status_t) pjmedia_codec_g711_init(pjmedia_endpt *endpt) 
     130{ 
     131    pjmedia_codec_mgr *codec_mgr; 
     132    pj_status_t status; 
     133 
     134    if (g711_factory.endpt != NULL) { 
     135        /* Already initialized. */ 
     136        return PJ_SUCCESS; 
     137    } 
     138 
     139    /* Init factory */ 
     140    g711_factory.base.op = &g711_factory_op; 
     141    g711_factory.base.factory_data = NULL; 
     142    g711_factory.endpt = endpt; 
     143 
     144    pj_list_init(&g711_factory.codec_list); 
     145 
     146    /* Create pool */ 
     147    g711_factory.pool = pjmedia_endpt_create_pool(endpt, "g711", 4000, 4000); 
     148    if (!g711_factory.pool) 
     149        return PJ_ENOMEM; 
     150 
     151    /* Create mutex. */ 
     152    status = pj_mutex_create_simple(g711_factory.pool, "g611",  
     153                                    &g711_factory.mutex); 
     154    if (status != PJ_SUCCESS) 
     155        goto on_error; 
     156 
     157    /* Get the codec manager. */ 
     158    codec_mgr = pjmedia_endpt_get_codec_mgr(endpt); 
     159    if (!codec_mgr) { 
     160        return PJ_EINVALIDOP; 
     161    } 
     162 
     163    /* Register codec factory to endpoint. */ 
     164    status = pjmedia_codec_mgr_register_factory(codec_mgr,  
     165                                                &g711_factory.base); 
     166    if (status != PJ_SUCCESS) 
     167        return status; 
     168 
     169 
     170    return PJ_SUCCESS; 
     171 
     172on_error: 
     173    if (g711_factory.mutex) { 
     174        pj_mutex_destroy(g711_factory.mutex); 
     175        g711_factory.mutex = NULL; 
     176    } 
     177    if (g711_factory.pool) { 
     178        pj_pool_release(g711_factory.pool); 
     179        g711_factory.pool = NULL; 
     180    } 
     181    return status; 
     182} 
     183 
     184PJ_DEF(pj_status_t) pjmedia_codec_g711_deinit(void) 
     185{ 
     186    pjmedia_codec_mgr *codec_mgr; 
     187    pj_status_t status; 
     188 
     189    if (g711_factory.endpt == NULL) { 
     190        /* Not registered. */ 
     191        return PJ_SUCCESS; 
     192    } 
     193 
     194    /* Lock mutex. */ 
     195    pj_mutex_lock(g711_factory.mutex); 
     196 
     197    /* Get the codec manager. */ 
     198    codec_mgr = pjmedia_endpt_get_codec_mgr(g711_factory.endpt); 
     199    if (!codec_mgr) { 
     200        g711_factory.endpt = NULL; 
     201        pj_mutex_unlock(g711_factory.mutex); 
     202        return PJ_EINVALIDOP; 
     203    } 
     204 
     205    /* Unregister G711 codec factory. */ 
     206    status = pjmedia_codec_mgr_unregister_factory(codec_mgr, 
     207                                                  &g711_factory.base); 
     208    g711_factory.endpt = NULL; 
     209 
     210    /* Destroy mutex. */ 
     211    pj_mutex_destroy(g711_factory.mutex); 
     212    g711_factory.mutex = NULL; 
     213 
     214 
     215    /* Release pool. */ 
     216    pj_pool_release(g711_factory.pool); 
     217    g711_factory.pool = NULL; 
     218 
     219 
     220    return status; 
    151221} 
    152222 
     
    209279                                     pjmedia_codec **p_codec) 
    210280{ 
    211     struct g711_factory_private *priv = factory->factory_data; 
    212281    pjmedia_codec *codec = NULL; 
    213282 
     283    PJ_ASSERT_RETURN(factory==&g711_factory.base, PJ_EINVAL); 
     284 
     285    /* Lock mutex. */ 
     286    pj_mutex_lock(g711_factory.mutex); 
     287 
    214288    /* Allocate new codec if no more is available */ 
    215     if (pj_list_empty(&priv->codec_list)) { 
     289    if (pj_list_empty(&g711_factory.codec_list)) { 
    216290        struct g711_private *codec_priv; 
    217291 
    218         codec = pj_pool_alloc(priv->pool, sizeof(pjmedia_codec)); 
    219         codec_priv = pj_pool_alloc(priv->pool, sizeof(struct g711_private)); 
    220         if (!codec || !codec_priv) 
     292        codec = pj_pool_alloc(g711_factory.pool, sizeof(pjmedia_codec)); 
     293        codec_priv = pj_pool_alloc(g711_factory.pool, sizeof(struct g711_private)); 
     294        if (!codec || !codec_priv) { 
     295            pj_mutex_unlock(g711_factory.mutex); 
    221296            return PJ_ENOMEM; 
     297        } 
    222298 
    223299        codec_priv->pt = id->pt; 
     
    227303        codec->codec_data = codec_priv; 
    228304    } else { 
    229         codec = priv->codec_list.next; 
     305        codec = g711_factory.codec_list.next; 
    230306        pj_list_erase(codec); 
    231307    } 
     
    235311 
    236312    *p_codec = codec; 
     313 
     314    /* Unlock mutex. */ 
     315    pj_mutex_unlock(g711_factory.mutex); 
     316 
    237317    return PJ_SUCCESS; 
    238318} 
     
    240320static pj_status_t g711_dealloc_codec( pjmedia_codec_factory *factory, pjmedia_codec *codec ) 
    241321{ 
    242     struct g711_factory_private *priv = factory->factory_data; 
     322     
     323    PJ_ASSERT_RETURN(factory==&g711_factory.base, PJ_EINVAL); 
    243324 
    244325    /* Check that this node has not been deallocated before */ 
     
    248329    } 
    249330 
     331    /* Lock mutex. */ 
     332    pj_mutex_lock(g711_factory.mutex); 
     333 
    250334    /* Insert at the back of the list */ 
    251     pj_list_insert_before(&priv->codec_list, codec); 
     335    pj_list_insert_before(&g711_factory.codec_list, codec); 
     336 
     337    /* Unlock mutex. */ 
     338    pj_mutex_unlock(g711_factory.mutex); 
    252339 
    253340    return PJ_SUCCESS; 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r277 r278  
    187187    pj_bool_t        auto_conf;     /**< Auto put to conference?        */ 
    188188 
     189    /* Codec arguments: */ 
     190    int              codec_cnt;     /**< Number of --add-codec args.    */ 
     191    pj_str_t         codec_arg[32]; /**< Array of --add-codec args.     */ 
     192    pj_status_t     (*codec_deinit[32])(void);  /**< Array of funcs.    */ 
    189193 
    190194    /* User Agent behaviour: */ 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r277 r278  
    529529    } 
    530530 
    531     /* Init pjmedia-codecs: */ 
    532  
    533     status = pjmedia_codec_init(pjsua.med_endpt); 
    534     if (status != PJ_SUCCESS) { 
    535         pj_caching_pool_destroy(&pjsua.cp); 
    536         pjsua_perror(THIS_FILE,  
    537                      "Media codec initialization has returned error",  
    538                      status); 
    539         return status; 
    540     } 
    541  
    542  
    543531    /* Done. */ 
    544532    return PJ_SUCCESS; 
     
    609597 
    610598/* 
    611  * Start pjsua stack. 
    612  * This will start the registration process, if registration is configured. 
    613  */ 
    614 pj_status_t pjsua_start(void) 
    615 { 
    616     int i;  /* Must be signed */ 
    617     pjsip_transport *udp_transport; 
    618     pj_status_t status = PJ_SUCCESS; 
     599 * Init media. 
     600 */ 
     601static pj_status_t init_media(void) 
     602{ 
     603 
     604    pj_status_t status; 
     605 
     606    /* If user doesn't specify any codecs, register all of them. */ 
     607    if (pjsua.codec_cnt == 0) { 
     608 
     609        unsigned option = PJMEDIA_SPEEX_NO_WB | PJMEDIA_SPEEX_NO_UWB; 
     610 
     611        /* Register speex. */ 
     612        if (pjsua.clock_rate >= 16000) 
     613            option &= ~(PJMEDIA_SPEEX_NO_WB); 
     614        if (pjsua.clock_rate >= 32000) 
     615            option &= ~(PJMEDIA_SPEEX_NO_UWB); 
     616 
     617        status = pjmedia_codec_speex_init(pjsua.med_endpt, option, -1, -1); 
     618        if (status != PJ_SUCCESS) { 
     619            pjsua_perror(THIS_FILE, "Error initializing Speex codec", 
     620                         status); 
     621            return status; 
     622        } 
     623 
     624        pjsua.codec_arg[pjsua.codec_cnt] = pj_str("speex"); 
     625        pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_speex_deinit; 
     626        pjsua.codec_cnt++; 
     627 
     628        /* Register GSM */ 
     629        status = pjmedia_codec_gsm_init(pjsua.med_endpt); 
     630        if (status != PJ_SUCCESS) { 
     631            pjsua_perror(THIS_FILE, "Error initializing GSM codec", 
     632                         status); 
     633            return status; 
     634        } 
     635 
     636        pjsua.codec_arg[pjsua.codec_cnt] = pj_str("gsm"); 
     637        pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_gsm_deinit; 
     638        pjsua.codec_cnt++; 
     639 
     640        /* Register PCMA and PCMU */ 
     641        status = pjmedia_codec_g711_init(pjsua.med_endpt); 
     642        if (status != PJ_SUCCESS) { 
     643            pjsua_perror(THIS_FILE, "Error initializing G711 codec", 
     644                         status); 
     645            return status; 
     646        } 
     647 
     648        pjsua.codec_arg[pjsua.codec_cnt] = pj_str("pcmu"); 
     649        pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_g711_deinit; 
     650        pjsua.codec_cnt++; 
     651        pjsua.codec_arg[pjsua.codec_cnt] = pj_str("pcma"); 
     652        pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_g711_deinit; 
     653        pjsua.codec_cnt++; 
     654 
     655    } else { 
     656 
     657        /* If user specifies the exact codec to be used, then create only 
     658         * those codecs. 
     659         */ 
     660        int i; 
     661 
     662        for (i=0; i<pjsua.codec_cnt; ++i) { 
     663         
     664            /* Is it speex? */ 
     665            if (!pj_stricmp2(&pjsua.codec_arg[i], "speex")) { 
     666 
     667                unsigned option = PJMEDIA_SPEEX_NO_WB | PJMEDIA_SPEEX_NO_UWB; 
     668 
     669                /* Register speex. */ 
     670                if (pjsua.clock_rate >= 16000) 
     671                    option &= ~(PJMEDIA_SPEEX_NO_WB); 
     672                if (pjsua.clock_rate >= 32000) 
     673                    option &= ~(PJMEDIA_SPEEX_NO_UWB); 
     674 
     675                status = pjmedia_codec_speex_init(pjsua.med_endpt, option, 
     676                                                  -1, -1); 
     677                if (status != PJ_SUCCESS) { 
     678                    pjsua_perror(THIS_FILE, "Error initializing Speex codec", 
     679                                 status); 
     680                    return status; 
     681                } 
     682 
     683                pjsua.codec_deinit[i] = &pjmedia_codec_speex_deinit; 
     684            } 
     685            /* Is it gsm? */ 
     686            else if (!pj_stricmp2(&pjsua.codec_arg[i], "gsm")) { 
     687 
     688                status = pjmedia_codec_gsm_init(pjsua.med_endpt); 
     689                if (status != PJ_SUCCESS) { 
     690                    pjsua_perror(THIS_FILE, "Error initializing GSM codec", 
     691                                 status); 
     692                    return status; 
     693                } 
     694 
     695                pjsua.codec_deinit[i] = &pjmedia_codec_gsm_deinit; 
     696 
     697            } 
     698            /* Is it pcma/pcmu? */ 
     699            else if (!pj_stricmp2(&pjsua.codec_arg[i], "pcmu") || 
     700                     !pj_stricmp2(&pjsua.codec_arg[i], "pcma")) 
     701            { 
     702 
     703                status = pjmedia_codec_g711_init(pjsua.med_endpt); 
     704                if (status != PJ_SUCCESS) { 
     705                    pjsua_perror(THIS_FILE, "Error initializing G711 codec", 
     706                                 status); 
     707                    return status; 
     708                } 
     709 
     710                pjsua.codec_deinit[i] = &pjmedia_codec_g711_deinit; 
     711 
     712            } 
     713            /* Don't know about this codec... */ 
     714            else { 
     715 
     716                PJ_LOG(1,(THIS_FILE, "Error: unsupported codecs %s", 
     717                          pjsua.codec_arg[i].ptr)); 
     718                return PJMEDIA_CODEC_EUNSUP; 
     719            } 
     720        } 
     721    } 
    619722 
    620723    /* Init conference bridge. */ 
     
    662765 
    663766 
     767    return PJ_SUCCESS; 
     768} 
     769 
     770 
     771/* 
     772 * Start pjsua stack. 
     773 * This will start the registration process, if registration is configured. 
     774 */ 
     775pj_status_t pjsua_start(void) 
     776{ 
     777    int i;  /* Must be signed */ 
     778    pjsip_transport *udp_transport; 
     779    pj_status_t status = PJ_SUCCESS; 
     780 
     781    /* 
     782     * Init media subsystem (codecs, conference bridge, et all). 
     783     */ 
     784    status = init_media(); 
     785    if (status != PJ_SUCCESS) 
     786        return status; 
     787 
    664788    /* Init sockets (STUN etc): */ 
    665789    for (i=0; i<(int)pjsua.max_calls; ++i) { 
     
    871995pj_status_t pjsua_destroy(void) 
    872996{ 
    873     int i; 
     997    int i;  /* Must be signed */ 
    874998 
    875999    /* Signal threads to quit: */ 
     
    9081032        pjmedia_conf_destroy(pjsua.mconf); 
    9091033 
    910     /* Shutdown pjmedia-codec: */ 
    911     pjmedia_codec_deinit(); 
    912  
    9131034    /* Destroy sound framework:  
    9141035     * (this should be done in pjmedia_shutdown()) 
     
    9161037    pj_snd_deinit(); 
    9171038 
     1039    /* Shutdown all codecs: */ 
     1040    for (i = pjsua.codec_cnt-1; i >= 0; --i) { 
     1041        (*pjsua.codec_deinit[i])(); 
     1042    } 
     1043 
     1044    /* Destroy media endpoint. */ 
     1045 
     1046    pjmedia_endpt_destroy(pjsua.med_endpt); 
     1047 
    9181048    /* Destroy endpoint. */ 
    9191049 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_settings.c

    r277 r278  
    9191    puts("  --auto-loop         Automatically loop incoming RTP to outgoing RTP"); 
    9292    puts("  --auto-conf         Automatically put incoming calls to conference"); 
    93     puts("  --rtp-port=N        Base port to try for RTP"); 
     93    puts("  --rtp-port=N        Base port to try for RTP"); 
     94    puts("  --add-codec=name    Specify alternate codec order"); 
    9495    puts(""); 
    9596    puts("Buddy List (can be more than one):"); 
     
    221222           OPT_AUTO_ANSWER, OPT_AUTO_HANGUP, OPT_AUTO_PLAY, OPT_AUTO_LOOP, 
    222223           OPT_AUTO_CONF, 
    223            OPT_PLAY_FILE, OPT_WB, OPT_UWB, OPT_RTP_PORT, 
     224           OPT_PLAY_FILE, OPT_WB, OPT_UWB, OPT_RTP_PORT, OPT_ADD_CODEC, 
    224225           OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS, 
    225226    }; 
     
    256257        { "play-file",  1, 0, OPT_PLAY_FILE}, 
    257258        { "rtp-port",   1, 0, OPT_RTP_PORT}, 
     259        { "add-codec",  1, 0, OPT_ADD_CODEC}, 
    258260        { "next-account",0,0, OPT_NEXT_ACCOUNT}, 
    259261        { "next-cred",  0, 0, OPT_NEXT_CRED}, 
     
    490492                return -1; 
    491493            } 
     494 
     495        case OPT_ADD_CODEC: 
     496            pjsua.codec_arg[pjsua.codec_cnt++] = pj_str(optarg); 
     497            break; 
    492498 
    493499        case OPT_AUTO_ANSWER: 
Note: See TracChangeset for help on using the changeset viewer.