Changeset 411


Ignore:
Timestamp:
Apr 27, 2006 10:36:40 PM (18 years ago)
Author:
bennylp
Message:

Initial support for stereo codecs, and added L16 codecs. Also better handling for case remote media is restarted

Location:
pjproject/trunk/pjmedia
Files:
4 added
2 deleted
27 edited
1 moved

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/build/Makefile

    r366 r411  
    6565export PJMEDIA_SRCDIR = ../src/pjmedia 
    6666export PJMEDIA_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \ 
    67                         codec.o conference.o endpoint.o errno.o file_player.o \ 
    68                         file_writer.o \ 
    69                         g711.o jbuf.o null_port.o port.o resample.o resample_port.o \ 
    70                         rtcp.o rtp.o sdp.o sdp_cmp.o sdp_neg.o session.o silencedet.o \ 
    71                         sound_port.o stream.o wave.o $(SOUND_OBJS) $(NULLSOUND_OBJS) 
     67                        clock_thread.o codec.o conference.o endpoint.o errno.o \ 
     68                        wav_player.o wav_writer.o g711.o jbuf.o \ 
     69                        master_port.o null_port.o port.o resample.o \ 
     70                        resample_port.o rtcp.o rtp.o sdp.o sdp_cmp.o sdp_neg.o \ 
     71                        session.o silencedet.o sound_port.o stream.o wave.o \ 
     72                        $(SOUND_OBJS) $(NULLSOUND_OBJS) 
    7273 
    7374export PJMEDIA_CFLAGS += $(_CFLAGS) 
     
    8889SPEEX_OBJS :=   speex_codec.o \ 
    8990                speex/bits.o speex/cb_search.o speex/exc_10_16_table.o  \ 
    90                 speex/exc_10_32_table.o speex/exc_20_32_table.o speex/exc_5_256_table.o \ 
    91                 speex/exc_5_64_table.o speex/exc_8_128_table.o speex/filters.o \ 
    92                 speex/gain_table.o speex/gain_table_lbr.o speex/hexc_10_32_table.o \ 
    93                 speex/hexc_table.o speex/high_lsp_tables.o speex/lpc_spx.o \ 
    94                 speex/lsp.o speex/lsp_tables_nb.o speex/ltp.o speex/math_approx.o \ 
    95                 speex/misc.o speex/modes.o speex/nb_celp.o speex/preprocess_spx.o \ 
    96                 speex/quant_lsp.o speex/sb_celp.o speex/smallft.o speex/speex.o \ 
    97                 speex/speex_callbacks.o speex/speex_header.o speex/stereo.o \ 
    98                 speex/vbr.o speex/vq.o 
     91                speex/exc_10_32_table.o speex/exc_20_32_table.o \ 
     92                speex/exc_5_256_table.o speex/exc_5_64_table.o \ 
     93                speex/exc_8_128_table.o speex/filters.o \ 
     94                speex/gain_table.o speex/gain_table_lbr.o \ 
     95                speex/hexc_10_32_table.o speex/hexc_table.o \ 
     96                speex/high_lsp_tables.o speex/lpc_spx.o \ 
     97                speex/lsp.o speex/lsp_tables_nb.o speex/ltp.o \ 
     98                speex/math_approx.o speex/misc.o speex/modes.o \ 
     99                speex/nb_celp.o speex/preprocess_spx.o \ 
     100                speex/quant_lsp.o speex/sb_celp.o speex/smallft.o \ 
     101                speex/speex.o speex/speex_callbacks.o speex/speex_header.o \ 
     102                speex/stereo.o speex/vbr.o speex/vq.o 
    99103SPEEX_CFLAGS := -DHAVE_CONFIG=1 -I../src/pjmedia-codec 
    100104 
  • pjproject/trunk/pjmedia/build/pjmedia.dsp

    r404 r411  
    6666# PROP Target_Dir "" 
    6767# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c 
    68 # ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "../include" /I "../../pjlib/include" /I "../../pjlib-util/include" /I "../src/pjmedia/portaudio" /D "_DEBUG" /D "PA_NO_ASIO" /D "WIN32" /D "_MBCS" /D "_LIB" /D PJ_WIN32=1 /D PJ_M_I386=1 /FR /FD /GZ /c 
     68# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "../include" /I "../../pjlib/include" /I "../../pjlib-util/include" /I "../src/pjmedia/portaudio" /D "_DEBUG" /D "PA_NO_ASIO" /D "PA_NO_WMME" /D "WIN32" /D "_MBCS" /D "_LIB" /D PJ_WIN32=1 /D PJ_M_I386=1 /FR /FD /GZ /c 
    6969# SUBTRACT CPP /YX 
    7070# ADD BASE RSC /l 0x409 /d "_DEBUG" 
     
    112112# Begin Source File 
    113113 
    114 SOURCE=..\src\pjmedia\file_player.c 
    115 # End Source File 
    116 # Begin Source File 
    117  
    118 SOURCE=..\src\pjmedia\file_writer.c 
    119 # End Source File 
    120 # Begin Source File 
    121  
    122114SOURCE=..\src\pjmedia\g711.c 
    123115# End Source File 
     
    189181 
    190182SOURCE=..\src\pjmedia\stream.c 
     183# End Source File 
     184# Begin Source File 
     185 
     186SOURCE=..\src\pjmedia\wav_player.c 
     187# End Source File 
     188# Begin Source File 
     189 
     190SOURCE=..\src\pjmedia\wav_writer.c 
    191191# End Source File 
    192192# Begin Source File 
     
    228228# Begin Source File 
    229229 
    230 SOURCE=..\include\pjmedia\file_port.h 
    231 # End Source File 
    232 # Begin Source File 
    233  
    234230SOURCE=..\include\pjmedia\g711.h 
    235231# End Source File 
     
    297293 
    298294SOURCE=..\include\pjmedia\types.h 
     295# End Source File 
     296# Begin Source File 
     297 
     298SOURCE=..\include\pjmedia\wav_port.h 
    299299# End Source File 
    300300# Begin Source File 
  • pjproject/trunk/pjmedia/build/pjmedia_codec.dsp

    r328 r411  
    9292# Begin Source File 
    9393 
     94SOURCE="..\src\pjmedia-codec\l16.c" 
     95# End Source File 
     96# Begin Source File 
     97 
    9498SOURCE="..\src\pjmedia-codec\speex_codec.c" 
    9599# End Source File 
     
    105109 
    106110SOURCE="..\include\pjmedia-codec\gsm.h" 
     111# End Source File 
     112# Begin Source File 
     113 
     114SOURCE="..\include\pjmedia-codec\l16.h" 
    107115# End Source File 
    108116# Begin Source File 
  • pjproject/trunk/pjmedia/include/pjmedia-codec.h

    r320 r411  
    2020#define __PJMEDIA_CODEC_PJMEDIA_CODEC_H__ 
    2121 
     22#include <pjmedia-codec/l16.h> 
    2223#include <pjmedia-codec/gsm.h> 
    2324#include <pjmedia-codec/speex.h> 
  • pjproject/trunk/pjmedia/include/pjmedia-codec/config.h

    r320 r411  
    2424 
    2525/** 
     26 * Unless specified otherwise, L16 codec is included by default. 
     27 */ 
     28#ifndef PJMEDIA_HAS_L16_CODEC 
     29#   define PJMEDIA_HAS_L16_CODEC    1 
     30#endif 
     31 
     32 
     33/** 
    2634 * Unless specified otherwise, GSM codec is included by default. 
    2735 */ 
  • pjproject/trunk/pjmedia/include/pjmedia-codec/types.h

    r320 r411  
    2323 
    2424 
     25/** 
     26 * These are the dynamic payload types that are used by codecs in 
     27 * this library. Also see the header file <pjmedia/codec.h> for list 
     28 * of static payload types. 
     29 */ 
     30enum 
     31{ 
     32    /* Telephone events must have pt=101, or otherwise some code needs 
     33     * to be updated (this would not affect outgoing pt). 
     34     */ 
     35    PJMEDIA_RTP_PT_TELEPHONE_EVENTS = 101,      /**< telephone-events       */ 
     36 
     37    PJMEDIA_RTP_PT_SPEEX_NB,                    /**< Speex narrowband/8KHz  */ 
     38    PJMEDIA_RTP_PT_SPEEX_WB,                    /**< Speex wideband/16KHz   */ 
     39    PJMEDIA_RTP_PT_SPEEX_UWB,                   /**< Speex 32KHz            */ 
     40    PJMEDIA_RTP_PT_L16_8KHZ_MONO,               /**< L16 @ 8KHz, mono       */ 
     41    PJMEDIA_RTP_PT_L16_8KHZ_STEREO,             /**< L16 @ 8KHz, stereo     */ 
     42    PJMEDIA_RTP_PT_L16_11KHZ_MONO,              /**< L16 @ 11KHz, mono      */ 
     43    PJMEDIA_RTP_PT_L16_11KHZ_STEREO,            /**< L16 @ 11KHz, stereo    */ 
     44    PJMEDIA_RTP_PT_L16_16KHZ_MONO,              /**< L16 @ 16KHz, mono      */ 
     45    PJMEDIA_RTP_PT_L16_16KHZ_STEREO,            /**< L16 @ 16KHz, stereo    */ 
     46    PJMEDIA_RTP_PT_L16_22KHZ_MONO,              /**< L16 @ 22KHz, mono      */ 
     47    PJMEDIA_RTP_PT_L16_22KHZ_STEREO,            /**< L16 @ 22KHz, stereo    */ 
     48    PJMEDIA_RTP_PT_L16_32KHZ_MONO,              /**< L16 @ 32KHz, mono      */ 
     49    PJMEDIA_RTP_PT_L16_32KHZ_STEREO,            /**< L16 @ 32KHz, stereo    */ 
     50    PJMEDIA_RTP_PT_L16_48KHZ_MONO,              /**< L16 @ 48KHz, mono      */ 
     51    PJMEDIA_RTP_PT_L16_48KHZ_STEREO,            /**< L16 @ 48KHz, stereo    */ 
     52}; 
     53 
     54 
     55 
    2556#endif  /* __PJMEDIA_CODEC_TYPES_H__ */ 
  • pjproject/trunk/pjmedia/include/pjmedia.h

    r404 r411  
    3131#include <pjmedia/endpoint.h> 
    3232#include <pjmedia/errno.h> 
    33 #include <pjmedia/file_port.h> 
    3433#include <pjmedia/g711.h> 
    3534#include <pjmedia/jbuf.h> 
     
    4645#include <pjmedia/sound.h> 
    4746#include <pjmedia/sound_port.h> 
     47#include <pjmedia/wav_port.h> 
    4848#include <pjmedia/wave.h> 
    4949 
  • pjproject/trunk/pjmedia/include/pjmedia/codec.h

    r276 r411  
    4949/**  
    5050 * Standard RTP static payload types, as defined by RFC 3551.  
     51 * The header file <pjmedia-codec/types.h> also declares dynamic payload 
     52 * types that are supported by pjmedia-codec library. 
    5153 */ 
    5254enum pjmedia_rtp_pt 
     
    9294    unsigned        pt;             /**< Payload type (can be dynamic). */ 
    9395    pj_str_t        encoding_name;  /**< Encoding name.                 */ 
    94     unsigned        sample_rate;    /**< Sampling rate.                 */ 
    95 }; 
     96    unsigned        clock_rate;     /**< Sampling rate.                 */ 
     97    unsigned        channel_cnt;    /**< Channel count.                 */ 
     98}; 
     99 
     100 
     101/** 
     102 * @see pjmedia_codec_info 
     103 */ 
     104typedef struct pjmedia_codec_info pjmedia_codec_info; 
    96105 
    97106 
     
    102111struct pjmedia_codec_param 
    103112{ 
    104     pj_uint32_t sample_rate;        /**< Sampling rate in Hz            */ 
     113    unsigned    clock_rate;         /**< Sampling rate in Hz            */ 
     114    unsigned    channel_cnt;        /**< Channel count.                 */ 
    105115    pj_uint32_t avg_bps;            /**< Average bandwidth in bits/sec  */ 
    106116 
     117    pj_uint16_t ptime;              /**< Packet time in miliseconds     */ 
    107118    pj_uint8_t  pcm_bits_per_sample;/**< Bits/sample in the PCM side    */ 
    108     pj_uint16_t ptime;              /**< Packet time in miliseconds     */ 
    109119 
    110120    unsigned    pt:8;               /**< Payload type.                  */ 
    111     unsigned    vad_enabled:1;      /**< Voice Activity Detector.       */ 
    112     unsigned    cng_enabled:1;      /**< Comfort Noise Generator.       */ 
    113     unsigned    lpf_enabled:1;      /**< Low pass filter                */ 
    114     unsigned    hpf_enabled:1;      /**< High pass filter               */ 
    115     unsigned    penh_enabled:1;     /**< Perceptual Enhancement         */ 
    116     unsigned    concl_enabled:1;    /**< Packet loss concealment        */ 
    117     unsigned    reserved_bit:1;     /**< Reserved, must be NULL.        */ 
    118  
    119 }; 
     121    unsigned    vad:1;              /**< Voice Activity Detector.       */ 
     122    unsigned    cng:1;              /**< Comfort Noise Generator.       */ 
     123    unsigned    lpf:1;              /**< Low pass filter                */ 
     124    unsigned    hpf:1;              /**< High pass filter               */ 
     125    unsigned    penh:1;             /**< Perceptual Enhancement         */ 
     126    unsigned    concl:1;            /**< Packet loss concealment        */ 
     127    unsigned    reserved:1;         /**< Reserved, must be NULL.        */ 
     128 
     129}; 
     130 
     131/** 
     132 * @see pjmedia_codec_param 
     133 */ 
     134typedef struct pjmedia_codec_param pjmedia_codec_param; 
     135 
     136 
     137/** 
     138 * @see pjmedia_codec 
     139 */ 
     140typedef struct pjmedia_codec pjmedia_codec; 
    120141 
    121142 
     
    126147struct pjmedia_codec_op 
    127148{ 
    128     /**  
    129      * Get default attributes for this codec.  
    130      * 
    131      * @param codec     The codec instance. 
    132      * @param attr      Pointer to receive default codec attributes. 
    133      * 
    134      * @return          PJ_SUCCESS on success. 
    135      */ 
    136     pj_status_t (*default_attr)(pjmedia_codec *codec,  
    137                                 pjmedia_codec_param *attr); 
    138  
    139149    /**  
    140150     * Initialize codec using the specified attribute. 
     
    226236 
    227237/** 
     238 * Codec operation. 
     239 */ 
     240typedef struct pjmedia_codec_op pjmedia_codec_op; 
     241 
     242 
     243/** 
     244 * @see pjmedia_codec_factory 
     245 */ 
     246typedef struct pjmedia_codec_factory pjmedia_codec_factory; 
     247 
     248 
     249/** 
    228250 * This structure describes a codec instance.  
    229251 */ 
     
    234256 
    235257    /** Codec's private data. */ 
    236     void        *codec_data; 
     258    void                    *codec_data; 
    237259 
    238260    /** Codec factory where this codec was allocated. */ 
    239     pjmedia_codec_factory *factory; 
     261    pjmedia_codec_factory   *factory; 
    240262 
    241263    /** Operations to codec. */ 
    242     pjmedia_codec_op    *op; 
    243 }; 
     264    pjmedia_codec_op        *op; 
     265}; 
     266 
    244267 
    245268 
     
    274297     */ 
    275298    pj_status_t (*default_attr)(pjmedia_codec_factory *factory,  
    276                                 const pjmedia_codec_info *info, 
    277                                 pjmedia_codec_param *attr ); 
     299                                const pjmedia_codec_info *info, 
     300                                pjmedia_codec_param *attr ); 
    278301 
    279302    /**  
     
    323346 
    324347/** 
     348 * @see pjmedia_codec_factory_op 
     349 */ 
     350typedef struct pjmedia_codec_factory_op pjmedia_codec_factory_op; 
     351 
     352 
     353/** 
    325354 * Codec factory describes a module that is able to create codec with specific 
    326355 * capabilities. These capabilities can be queried by codec manager to create 
     
    340369}; 
    341370 
     371 
    342372/** 
    343373 * Declare maximum codecs 
     
    345375#define PJMEDIA_CODEC_MGR_MAX_CODECS        32 
    346376 
    347 /** 
    348  * Codec manager maintains codec factory etc. 
     377 
     378/** 
     379 * Specify these values to set the codec priority, by calling 
     380 * #pjmedia_codec_mgr_set_codec_priority(). 
     381 */ 
     382enum pjmedia_codec_priority 
     383{ 
     384    /** 
     385     * This priority makes the codec the highest in the order. 
     386     * The last codec specified with this priority will get the 
     387     * highest place in the order, and will change the priority 
     388     * of previously highest priority codec to NEXT_HIGHER. 
     389     */ 
     390    PJMEDIA_CODEC_PRIO_HIGHEST, 
     391 
     392    /** 
     393     * This priority will put the codec as the next codec after 
     394     * codecs with this same priority. 
     395     */ 
     396    PJMEDIA_CODEC_PRIO_NEXT_HIGHER, 
     397 
     398    /** 
     399     * This is the initial codec priority when it is registered to 
     400     * codec manager by codec factory. 
     401     */ 
     402    PJMEDIA_CODEC_PRIO_NORMAL, 
     403 
     404    /** 
     405     * This priority makes the codec the lowest in the order. 
     406     * The last codec specified with this priority will be put 
     407     * in the last place in the order. 
     408     */ 
     409    PJMEDIA_CODEC_PRIO_LOWEST, 
     410 
     411    /** 
     412     * This priority will prevent the codec from being listed in the 
     413     * SDP created by media endpoint, thus should prevent the codec 
     414     * from being used in the sessions. However, the codec will still 
     415     * be listed by #pjmedia_codec_mgr_enum_codecs() and other codec 
     416     * query functions. 
     417     */ 
     418    PJMEDIA_CODEC_PRIO_DISABLED, 
     419}; 
     420 
     421 
     422/** 
     423 * @see pjmedia_codec_priority 
     424 */ 
     425typedef enum pjmedia_codec_priority pjmedia_codec_priority; 
     426 
     427 
     428/** Fully qualified codec name  (e.g. "pcmu/8000/1") */ 
     429typedef char pjmedia_codec_id[32]; 
     430 
     431 
     432/**  
     433 * Codec manager maintains array of these structs for each supported 
     434 * codec. 
     435 */ 
     436struct pjmedia_codec_desc 
     437{ 
     438    pjmedia_codec_info      info;       /**< Codec info.            */ 
     439    pjmedia_codec_id        id;         /**< Fully qualified name   */ 
     440    pjmedia_codec_priority  prio;       /**< Priority.              */ 
     441    pjmedia_codec_factory  *factory;    /**< The factory.           */ 
     442}; 
     443 
     444 
     445/** 
     446 * The declaration for codec manager. Application doesn't normally need 
     447 * to see this declaration, but nevertheless this declaration is needed 
     448 * by media endpoint to instantiate the codec manager. 
    349449 */ 
    350450struct pjmedia_codec_mgr 
    351451{ 
    352452    /** List of codec factories registered to codec manager. */ 
    353     pjmedia_codec_factory   factory_list; 
     453    pjmedia_codec_factory       factory_list; 
    354454 
    355455    /** Number of supported codesc. */ 
    356     unsigned                codec_cnt; 
    357  
    358     /** Array of codec info. */ 
    359     pjmedia_codec_info      codecs[PJMEDIA_CODEC_MGR_MAX_CODECS]; 
    360 }; 
    361  
    362  
    363  
    364 /** 
    365  * Initialize codec manager. 
     456    unsigned                    codec_cnt; 
     457 
     458    /** Array of codec descriptor. */ 
     459    struct pjmedia_codec_desc   codec_desc[PJMEDIA_CODEC_MGR_MAX_CODECS]; 
     460}; 
     461 
     462 
     463/** 
     464 * @see pjmedia_codec_mgr 
     465 */ 
     466typedef struct pjmedia_codec_mgr pjmedia_codec_mgr; 
     467 
     468 
     469 
     470/** 
     471 * Initialize codec manager. Normally this function is called by pjmedia 
     472 * endpoint's initialization code. 
    366473 * 
    367474 * @param mgr       Codec manager instance. 
     
    373480 
    374481/**  
    375  * Register codec factory to codec manager.  
    376  * 
    377  * @param mgr       The codec manager. 
     482 * Register codec factory to codec manager. This will also register 
     483 * all supported codecs in the factory to the codec manager. 
     484 * 
     485 * @param mgr       The codec manager instance. Application can get the 
     486 *                  instance by calling #pjmedia_endpt_get_codec_mgr(). 
    378487 * @param factory   The codec factory to be registered. 
    379488 * 
     
    385494 
    386495/** 
    387  * Unregister codec factory from the codec manager. 
    388  * 
    389  * @param mgr       The codec manager. 
     496 * Unregister codec factory from the codec manager. This will also 
     497 * remove all the codecs registered by the codec factory from the 
     498 * codec manager's list of supported codecs. 
     499 * 
     500 * @param mgr       The codec manager instance. Application can get the 
     501 *                  instance by calling #pjmedia_endpt_get_codec_mgr(). 
    390502 * @param factory   The codec factory to be unregistered. 
    391503 * 
     
    397509 
    398510/** 
    399  * Enumerate all supported codec. 
    400  * 
    401  * @param mgr       The codec manager. 
     511 * Enumerate all supported codecs that have been registered to the 
     512 * codec manager by codec factories. 
     513 * 
     514 * @param mgr       The codec manager instance. Application can get the 
     515 *                  instance by calling #pjmedia_endpt_get_codec_mgr(). 
    402516 * @param count     On input, specifies the number of elements in 
    403517 *                  the array. On output, the value will be set to 
     
    406520 * @param info      The codec info array, which contents will be  
    407521 *                  initialized upon return. 
     522 * @param prio      Optional pointer to receive array of codec priorities. 
    408523 * 
    409524 * @return          PJ_SUCCESS on success. 
     
    411526PJ_DECL(pj_status_t) pjmedia_codec_mgr_enum_codecs( pjmedia_codec_mgr *mgr,  
    412527                                                    unsigned *count,  
    413                                                     pjmedia_codec_info info[]); 
    414  
    415 /** 
    416  * Get codec info for the specified static payload type. 
    417  * 
    418  * @param mgr       The codec manager. 
     528                                                    pjmedia_codec_info info[], 
     529                                                    unsigned *prio); 
     530 
     531/** 
     532 * Get codec info for the specified static payload type. Note that 
     533 * this can only find codec with static payload types. This function can 
     534 * be used to find codec info for a payload type inside SDP which doesn't 
     535 * have the corresponding rtpmap attribute. 
     536 * 
     537 * @param mgr       The codec manager instance. Application can get the 
     538 *                  instance by calling #pjmedia_endpt_get_codec_mgr(). 
    419539 * @param pt        Static payload type/number. 
    420540 * @param inf       Pointer to receive codec info. 
     
    422542 * @return          PJ_SUCCESS on success. 
    423543 */ 
    424 PJ_DECL(pj_status_t) pjmedia_codec_mgr_get_codec_info(pjmedia_codec_mgr *mgr, 
    425                                                       unsigned pt, 
    426                                                       pjmedia_codec_info *inf); 
     544PJ_DECL(pj_status_t)  
     545pjmedia_codec_mgr_get_codec_info( pjmedia_codec_mgr *mgr, 
     546                                  unsigned pt, 
     547                                  const pjmedia_codec_info **inf); 
     548 
     549/** 
     550 * Convert codec info struct into a unique codec identifier. 
     551 * A codec identifier looks something like "L16/44100/2". 
     552 * 
     553 * @param info      The codec info 
     554 * @param id        Buffer to put the codec info string. 
     555 * @param max_len   The length of the buffer. 
     556 * 
     557 * @return          The null terminated codec info string, or NULL if 
     558 *                  the buffer is not long enough. 
     559 */ 
     560PJ_DECL(char*) pjmedia_codec_info_to_id(const pjmedia_codec_info *info, 
     561                                        char *id, unsigned max_len ); 
     562 
     563 
     564/** 
     565 * Find codecs by the unique codec identifier. This function will find 
     566 * all codecs that match the codec identifier prefix. For example, if 
     567 * "L16" is specified, then it will find "L16/8000/1", "L16/16000/1", 
     568 * and so on, up to the maximum count specified in the argument. 
     569 * 
     570 * @param mgr       The codec manager instance. Application can get the 
     571 *                  instance by calling #pjmedia_endpt_get_codec_mgr(). 
     572 * @param codec_id  The full codec ID or codec ID prefix. If an empty 
     573 *                  string is given, it will match all codecs. 
     574 * @param count     Maximum number of codecs to find. On return, it 
     575 *                  contains the actual number of codecs found. 
     576 * @param p_info    Array of pointer to codec info to be filled. This 
     577 *                  argument may be NULL, which in this case, only 
     578 *                  codec count will be returned. 
     579 * @param prio      Optional array of codec priorities. 
     580 * 
     581 * @return          PJ_SUCCESS if at least one codec info is found. 
     582 */ 
     583PJ_DECL(pj_status_t)  
     584pjmedia_codec_mgr_find_codecs_by_id( pjmedia_codec_mgr *mgr, 
     585                                     const pj_str_t *codec_id, 
     586                                     unsigned *count, 
     587                                     const pjmedia_codec_info *p_info[], 
     588                                     unsigned prio[]); 
     589 
     590 
     591/** 
     592 * Set codec priority. The codec priority determines the order of 
     593 * the codec in the SDP created by the endpoint. If more than one codecs 
     594 * are found with the same codec_id prefix, then the function sets the 
     595 * priorities of all those codecs. 
     596 * 
     597 * @param mgr       The codec manager instance. Application can get the 
     598 *                  instance by calling #pjmedia_endpt_get_codec_mgr(). 
     599 * @param codec_id  The full codec ID or codec ID prefix. If an empty 
     600 *                  string is given, it will match all codecs. 
     601 * @param prio      Priority to be set. 
     602 * 
     603 * @return          PJ_SUCCESS if at least one codec info is found. 
     604 */ 
     605PJ_DECL(pj_status_t) 
     606pjmedia_codec_mgr_set_codec_priority(pjmedia_codec_mgr *mgr,  
     607                                     const pj_str_t *codec_id, 
     608                                     pjmedia_codec_priority prio); 
     609 
    427610 
    428611/** 
    429612 * Get default codec param for the specified codec info. 
    430613 * 
    431  * @param mgr       The codec manager. 
     614 * @param mgr       The codec manager instance. Application can get the 
     615 *                  instance by calling #pjmedia_endpt_get_codec_mgr(). 
    432616 * @param info      The codec info, which default parameter's is being 
    433617 *                  queried. 
     
    437621 * @return          PJ_SUCCESS on success. 
    438622 */ 
    439 PJ_DECL(pj_status_t) pjmedia_codec_mgr_get_default_param(pjmedia_codec_mgr *mgr, 
    440                                                          const pjmedia_codec_info *info, 
    441                                                          pjmedia_codec_param *param ); 
     623PJ_DECL(pj_status_t)  
     624pjmedia_codec_mgr_get_default_param( pjmedia_codec_mgr *mgr, 
     625                                     const pjmedia_codec_info *info, 
     626                                     pjmedia_codec_param *param ); 
    442627 
    443628/** 
     
    446631 * until it finds factory that is able to create the specified codec. 
    447632 * 
    448  * @param mgr       The codec manager. 
     633 * @param mgr       The codec manager instance. Application can get the 
     634 *                  instance by calling #pjmedia_endpt_get_codec_mgr(). 
    449635 * @param info      The information about the codec to be created. 
    450636 * @param p_codec   Pointer to receive the codec instance. 
     
    452638 * @return          PJ_SUCCESS on success. 
    453639 */ 
    454 PJ_DECL(pj_status_t) pjmedia_codec_mgr_alloc_codec(pjmedia_codec_mgr *mgr,  
    455                                                    const pjmedia_codec_info *info, 
    456                                                    pjmedia_codec **p_codec); 
     640PJ_DECL(pj_status_t)  
     641pjmedia_codec_mgr_alloc_codec( pjmedia_codec_mgr *mgr,  
     642                               const pjmedia_codec_info *info, 
     643                               pjmedia_codec **p_codec); 
    457644 
    458645/** 
     
    460647 * the instance of the codec back to its factory. 
    461648 * 
    462  * @param mgr       The codec manager. 
     649 * @param mgr       The codec manager instance. Application can get the 
     650 *                  instance by calling #pjmedia_endpt_get_codec_mgr(). 
    463651 * @param codec     The codec instance. 
    464652 * 
     
    468656                                                     pjmedia_codec *codec); 
    469657 
     658 
     659 
     660 
     661 
    470662/** 
    471663 * @} 
  • pjproject/trunk/pjmedia/include/pjmedia/endpoint.h

    r350 r411  
    4040#include <pjmedia/sound.h> 
    4141#include <pjmedia/codec.h> 
     42#include <pjmedia/sdp.h> 
    4243 
    4344 
  • pjproject/trunk/pjmedia/include/pjmedia/port.h

    r321 r411  
    7878    unsigned        pt;                 /**< Payload type (can be dynamic). */ 
    7979    pj_str_t        encoding_name;      /**< Encoding name.                 */ 
    80     unsigned        sample_rate;        /**< Sampling rate.                 */ 
     80    unsigned        clock_rate;         /**< Sampling rate.                 */ 
    8181    unsigned        channel_count;      /**< Number of channels.            */ 
    8282    unsigned        bits_per_sample;    /**< Bits/sample                    */ 
     
    102102}; 
    103103 
     104 
     105/**  
     106 * @see pjmedia_frame_type 
     107 */ 
     108typedef enum pjmedia_frame_type pjmedia_frame_type; 
     109 
     110 
    104111/**  
    105112 * This structure describes a media frame.  
     
    112119    pj_timestamp         timestamp; /**< Frame timestamp.           */ 
    113120}; 
     121 
     122 
     123/**  
     124 * @see pjmedia_frame 
     125 */ 
     126typedef struct pjmedia_frame pjmedia_frame; 
     127 
    114128 
    115129/** 
  • pjproject/trunk/pjmedia/include/pjmedia/sdp.h

    r295 r411  
    7878    pj_str_t            value;      /**< Attribute value.   */ 
    7979}; 
     80 
     81/** 
     82 * @see pjmedia_sdp_attr 
     83 */ 
     84typedef struct pjmedia_sdp_attr pjmedia_sdp_attr; 
    8085 
    8186 
     
    203208}; 
    204209 
     210/** 
     211 * @see pjmedia_sdp_rtpmap 
     212 */ 
     213typedef struct pjmedia_sdp_rtpmap pjmedia_sdp_rtpmap; 
     214 
    205215 
    206216/** 
     
    262272    pj_str_t            fmt_param;  /**< Format specific parameter. */ 
    263273}; 
     274 
     275 
     276/** 
     277 * @see pjmedia_sdp_fmtp 
     278 */ 
     279typedef struct pjmedia_sdp_fmtp pjmedia_sdp_fmtp; 
     280 
    264281 
    265282 
     
    291308    pj_str_t    addr;           /**< The address.                       */ 
    292309}; 
     310 
     311 
     312/** 
     313 * @see pjmedia_sdp_conn 
     314 */ 
     315typedef struct pjmedia_sdp_conn pjmedia_sdp_conn; 
    293316 
    294317 
     
    336359 
    337360 
     361/** 
     362 * @see pjmedia_sdp_media 
     363 */ 
     364typedef struct pjmedia_sdp_media pjmedia_sdp_media; 
     365 
     366 
    338367/**  
    339368 * Clone SDP media description.  
     
    482511}; 
    483512 
     513/** 
     514 * @see pjmedia_sdp_session 
     515 */ 
     516typedef struct pjmedia_sdp_session pjmedia_sdp_session; 
     517 
     518 
    484519 
    485520/** 
  • pjproject/trunk/pjmedia/include/pjmedia/sdp_neg.h

    r207 r411  
    234234 */ 
    235235 
    236 #include <pjmedia/types.h> 
     236#include <pjmedia/sdp.h> 
    237237 
    238238PJ_BEGIN_DECL 
     
    277277 
    278278/** 
     279 * @see pjmedia_sdp_neg_state 
     280 */ 
     281typedef enum pjmedia_sdp_neg_state pjmedia_sdp_neg_state; 
     282 
     283 
     284/** 
     285 * Opaque declaration of SDP negotiator. 
     286 */ 
     287typedef struct pjmedia_sdp_neg pjmedia_sdp_neg; 
     288 
     289 
     290/** 
    279291 * Get the state string description of the specified state. 
    280292 * 
  • pjproject/trunk/pjmedia/include/pjmedia/types.h

    r352 r411  
    4444}; 
    4545 
     46/** 
     47 * @see pjmedia_type 
     48 */ 
     49typedef enum pjmedia_type pjmedia_type; 
     50 
     51 
    4652 
    4753/**  
     
    6470}; 
    6571 
     72/** 
     73 * @see pjmedia_dir 
     74 */ 
     75typedef enum pjmedia_dir pjmedia_dir; 
     76 
     77 
    6678/* Alternate names for media direction: */ 
    6779 
     
    8193#define PJMEDIA_DIR_CAPTURE_PLAYBACK    PJMEDIA_DIR_ENCODING_DECODING 
    8294 
    83  
    84 /** 
    85  * Top level media type. 
    86  */ 
    87 typedef enum pjmedia_type pjmedia_type; 
    88  
    89 /** 
    90  * Media direction. 
    91  */ 
    92 typedef enum pjmedia_dir pjmedia_dir; 
    93  
    94 /** 
    95  * Codec info. 
    96  */ 
    97 typedef struct pjmedia_codec_info pjmedia_codec_info; 
    98  
    99 /** 
    100  * Codec initialization parameter. 
    101  */ 
    102 typedef struct pjmedia_codec_param pjmedia_codec_param; 
    103  
    104 /**  
    105  * Types of media frames.  
    106  */ 
    107 typedef enum pjmedia_frame_type pjmedia_frame_type; 
    108  
    109 /**  
    110  * This structure describes a media frame.  
    111  */ 
    112 typedef struct pjmedia_frame pjmedia_frame; 
    113  
    114 /** 
    115  * Codec instance. 
    116  */ 
    117 typedef struct pjmedia_codec pjmedia_codec; 
    118  
    119 /** 
    120  * Codec factory. 
    121  */ 
    122 typedef struct pjmedia_codec_factory pjmedia_codec_factory; 
    123  
    124 /** 
    125  * Codec operation. 
    126  */ 
    127 typedef struct pjmedia_codec_op pjmedia_codec_op; 
    128  
    129 /** 
    130  * Codec factory operation. 
    131  */ 
    132 typedef struct pjmedia_codec_factory_op pjmedia_codec_factory_op; 
    133  
    134 /** 
    135  * Codec manager. 
    136  */ 
    137 typedef struct pjmedia_codec_mgr pjmedia_codec_mgr; 
    13895 
    13996/**  
     
    188145 
    189146/** 
    190  * Forward declaration for SDP attribute (sdp.h) 
    191  */ 
    192 typedef struct pjmedia_sdp_attr pjmedia_sdp_attr; 
    193  
    194 /** 
    195  * Forward declaration for SDP rtpmap attribute (sdp.h) 
    196  */ 
    197 typedef struct pjmedia_sdp_rtpmap pjmedia_sdp_rtpmap; 
    198  
    199 /** 
    200  * Forward declaration for SDP fmtp attribute (sdp.h) 
    201  */ 
    202 typedef struct pjmedia_sdp_fmtp pjmedia_sdp_fmtp; 
    203  
    204 /** 
    205  * Forward declaration for SDP connection info (sdp.h) 
    206  */ 
    207 typedef struct pjmedia_sdp_conn pjmedia_sdp_conn; 
    208  
    209 /** 
    210  * Forward declaration for SDP media line (sdp.h) 
    211  */ 
    212 typedef struct pjmedia_sdp_media pjmedia_sdp_media; 
    213  
    214 /** 
    215  * Forward declaration for SDP session (sdp.h) 
    216  */ 
    217 typedef struct pjmedia_sdp_session pjmedia_sdp_session; 
    218  
    219 /** 
    220  * Forward declaration for SDP negotiator state (sdp_neg.h). 
    221  */ 
    222 typedef enum pjmedia_sdp_neg_state pjmedia_sdp_neg_state; 
    223  
    224 /** 
    225  * Forward declaration for SDP negotiator (sdp_neg.h). 
    226  */ 
    227 typedef struct pjmedia_sdp_neg pjmedia_sdp_neg; 
    228  
    229 /** 
    230147 * Types of frame returned from jitter buffer (jbuf.h). 
    231148 */ 
  • pjproject/trunk/pjmedia/include/pjmedia/wav_port.h

    r409 r411  
    1717 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
    1818 */ 
    19 #ifndef __PJMEDIA_FILE_PORT_H__ 
    20 #define __PJMEDIA_FILE_PORT_H__ 
     19#ifndef __PJMEDIA_WAV_PORT_H__ 
     20#define __PJMEDIA_WAV_PORT_H__ 
    2121 
    2222/** 
    23  * @file file_port.h 
    24  * @brief File player and recorder. 
     23 * @file wav_port.h 
     24 * @brief WAV file player and writer. 
    2525 */ 
    2626#include <pjmedia/port.h> 
     
    3636 * @param pool          Pool to create memory buffers for this port. 
    3737 * @param filename      File name to open. 
     38 * @param ptime         The duration (in miliseconds) of each frame read 
     39 *                      from this port. If the value is zero, the default 
     40 *                      duration (20ms) will be used. 
    3841 * @param flags         Port creation flags. 
    3942 * @param buf_size      Buffer size to be allocated. If the value is zero or 
     
    4548 * @return              PJ_SUCCESS on success. 
    4649 */ 
    47 PJ_DECL(pj_status_t) pjmedia_file_player_port_create( pj_pool_t *pool, 
    48                                                       const char *filename, 
    49                                                       unsigned flags, 
    50                                                       pj_ssize_t buff_size, 
    51                                                       void *user_data, 
    52                                                       pjmedia_port **p_port ); 
    53  
     50PJ_DECL(pj_status_t) pjmedia_wav_player_port_create( pj_pool_t *pool, 
     51                                                     const char *filename, 
     52                                                     unsigned ptime, 
     53                                                     unsigned flags, 
     54                                                     pj_ssize_t buff_size, 
     55                                                     void *user_data, 
     56                                                     pjmedia_port **p_port ); 
    5457 
    5558 
     
    7073 * @return              PJ_SUCCESS on success. 
    7174 */ 
    72 PJ_DECL(pj_status_t) pjmedia_file_writer_port_create( pj_pool_t *pool, 
     75PJ_DECL(pj_status_t) pjmedia_wav_writer_port_create( pj_pool_t *pool, 
    7376                                                      const char *filename, 
    7477                                                      unsigned sampling_rate, 
     
    8790 
    8891 
    89 #endif  /* __PJMEDIA_FILE_PORT_H__ */ 
     92#endif  /* __PJMEDIA_WAV_PORT_H__ */ 
  • pjproject/trunk/pjmedia/src/pjmedia-codec/gsm.c

    r320 r411  
    5050 
    5151/* Prototypes for GSM implementation. */ 
    52 static pj_status_t  gsm_codec_default_attr(pjmedia_codec *codec,  
    53                                            pjmedia_codec_param *attr); 
    5452static pj_status_t  gsm_codec_init( pjmedia_codec *codec,  
    5553                                    pj_pool_t *pool ); 
     
    7472static pjmedia_codec_op gsm_op =  
    7573{ 
    76     &gsm_codec_default_attr, 
    7774    &gsm_codec_init, 
    7875    &gsm_codec_open, 
     
    234231 
    235232    pj_memset(attr, 0, sizeof(pjmedia_codec_param)); 
    236     attr->sample_rate = 8000; 
     233    attr->clock_rate = 8000; 
     234    attr->channel_cnt = 1; 
    237235    attr->avg_bps = 13200; 
    238236    attr->pcm_bits_per_sample = 16; 
     
    259257    codecs[0].pt = PJMEDIA_RTP_PT_GSM; 
    260258    codecs[0].type = PJMEDIA_TYPE_AUDIO; 
    261     codecs[0].sample_rate = 8000; 
     259    codecs[0].clock_rate = 8000; 
     260    codecs[0].channel_cnt = 1; 
    262261 
    263262    *count = 1; 
     
    329328 
    330329/* 
    331  * Get codec default attributes. 
    332  */ 
    333 static pj_status_t gsm_codec_default_attr( pjmedia_codec *codec,  
    334                                            pjmedia_codec_param *attr) 
    335 { 
    336     return gsm_default_attr( codec->factory, NULL, attr); 
    337 } 
    338  
    339 /* 
    340330 * Init codec. 
    341331 */ 
  • pjproject/trunk/pjmedia/src/pjmedia-codec/speex_codec.c

    r320 r411  
    5757 
    5858/* Prototypes for Speex implementation. */ 
    59 static pj_status_t  spx_codec_default_attr(pjmedia_codec *codec,  
    60                                            pjmedia_codec_param *attr); 
    6159static pj_status_t  spx_codec_init( pjmedia_codec *codec,  
    6260                                    pj_pool_t *pool ); 
     
    8179static pjmedia_codec_op spx_op =  
    8280{ 
    83     &spx_codec_default_attr, 
    8481    &spx_codec_init, 
    8582    &spx_codec_open, 
     
    231228    spx_factory.speex_param[PARAM_NB].enabled =  
    232229        ((options & PJMEDIA_SPEEX_NO_NB) == 0); 
    233     spx_factory.speex_param[PARAM_NB].pt = 102; 
     230    spx_factory.speex_param[PARAM_NB].pt = PJMEDIA_RTP_PT_SPEEX_NB; 
    234231    spx_factory.speex_param[PARAM_NB].mode = &speex_nb_mode; 
    235232    spx_factory.speex_param[PARAM_NB].clock_rate = 8000; 
     
    239236    spx_factory.speex_param[PARAM_WB].enabled =  
    240237        ((options & PJMEDIA_SPEEX_NO_WB) == 0); 
    241     spx_factory.speex_param[PARAM_WB].pt = 103; 
     238    spx_factory.speex_param[PARAM_WB].pt = PJMEDIA_RTP_PT_SPEEX_WB; 
    242239    spx_factory.speex_param[PARAM_WB].mode = &speex_wb_mode; 
    243240    spx_factory.speex_param[PARAM_WB].clock_rate = 16000; 
     
    247244    spx_factory.speex_param[PARAM_UWB].enabled =  
    248245        ((options & PJMEDIA_SPEEX_NO_UWB) == 0); 
    249     spx_factory.speex_param[PARAM_UWB].pt = 104; 
     246    spx_factory.speex_param[PARAM_UWB].pt = PJMEDIA_RTP_PT_SPEEX_UWB; 
    250247    spx_factory.speex_param[PARAM_UWB].mode = &speex_uwb_mode; 
    251248    spx_factory.speex_param[PARAM_UWB].clock_rate = 32000; 
     
    359356    /* Check clock-rate */ 
    360357    for (i=0; i<PJ_ARRAY_SIZE(spx_factory.speex_param); ++i) { 
    361         if (info->sample_rate == spx_factory.speex_param[i].clock_rate) { 
     358        if (info->clock_rate == spx_factory.speex_param[i].clock_rate) { 
    362359            /* Okay, let's Speex! */ 
    363360            return PJ_SUCCESS; 
     
    382379    pj_memset(attr, 0, sizeof(pjmedia_codec_param)); 
    383380    attr->pt = id->pt; 
    384  
    385     if (id->sample_rate <= 8000) { 
    386         attr->sample_rate = spx_factory.speex_param[PARAM_NB].clock_rate; 
     381    attr->channel_cnt = 1; 
     382 
     383    if (id->clock_rate <= 8000) { 
     384        attr->clock_rate = spx_factory.speex_param[PARAM_NB].clock_rate; 
    387385        attr->avg_bps = spx_factory.speex_param[PARAM_NB].bitrate; 
    388386 
    389     } else if (id->sample_rate <= 16000) { 
    390         attr->sample_rate = spx_factory.speex_param[PARAM_WB].clock_rate; 
     387    } else if (id->clock_rate <= 16000) { 
     388        attr->clock_rate = spx_factory.speex_param[PARAM_WB].clock_rate; 
    391389        attr->avg_bps = spx_factory.speex_param[PARAM_WB].bitrate; 
    392390 
    393391    } else { 
    394392        /* Wow.. somebody is doing ultra-wideband. Cool...! */ 
    395         attr->sample_rate = spx_factory.speex_param[PARAM_UWB].clock_rate; 
     393        attr->clock_rate = spx_factory.speex_param[PARAM_UWB].clock_rate; 
    396394        attr->avg_bps = spx_factory.speex_param[PARAM_UWB].bitrate; 
    397395    } 
     
    402400 
    403401    /* Default flags. */ 
    404     attr->cng_enabled = 1; 
    405     attr->concl_enabled = 1; 
    406     attr->hpf_enabled = 1; 
    407     attr->lpf_enabled =1 ; 
    408     attr->penh_enabled =1 ; 
     402    attr->cng = 1; 
     403    attr->concl = 1; 
     404    attr->hpf = 1; 
     405    attr->lpf =1 ; 
     406    attr->penh =1 ; 
    409407 
    410408    /* Default, set VAD off as it caused voice chip off */ 
    411     attr->vad_enabled = 0; 
     409    attr->vad = 0; 
    412410 
    413411    return PJ_SUCCESS; 
     
    443441        codecs[*count].pt = spx_factory.speex_param[i].pt; 
    444442        codecs[*count].type = PJMEDIA_TYPE_AUDIO; 
    445         codecs[*count].sample_rate = spx_factory.speex_param[i].clock_rate; 
     443        codecs[*count].clock_rate = spx_factory.speex_param[i].clock_rate; 
     444        codecs[*count].channel_cnt = 1; 
    446445 
    447446        ++*count; 
     
    487486    spx->dec = NULL; 
    488487 
    489     if (id->sample_rate <= 8000) 
     488    if (id->clock_rate <= 8000) 
    490489        spx->param_id = PARAM_NB; 
    491     else if (id->sample_rate <= 16000) 
     490    else if (id->clock_rate <= 16000) 
    492491        spx->param_id = PARAM_WB; 
    493492    else 
     
    521520 
    522521    return PJ_SUCCESS; 
    523 } 
    524  
    525 /* 
    526  * Get codec default attributes. 
    527  */ 
    528 static pj_status_t spx_codec_default_attr( pjmedia_codec *codec,  
    529                                            pjmedia_codec_param *attr) 
    530 { 
    531     struct spx_private *spx; 
    532     pjmedia_codec_info info; 
    533  
    534     spx = (struct spx_private*) codec->codec_data; 
    535  
    536     info.encoding_name = pj_str("speex"); 
    537     info.pt = 200;  /* Don't care */ 
    538     info.sample_rate = spx_factory.speex_param[spx->param_id].clock_rate; 
    539     info.type = PJMEDIA_TYPE_AUDIO; 
    540  
    541     return spx_default_attr( codec->factory, &info, attr); 
    542522} 
    543523 
     
    580560 
    581561    /* Sampling rate. */ 
    582     tmp = attr->sample_rate; 
     562    tmp = attr->clock_rate; 
    583563    speex_encoder_ctl(spx->enc, SPEEX_SET_SAMPLING_RATE,  
    584564                      &spx_factory.speex_param[id].clock_rate); 
    585565 
    586566    /* VAD */ 
    587     tmp = attr->vad_enabled; 
     567    tmp = attr->vad; 
    588568    speex_encoder_ctl(spx->enc, SPEEX_SET_VAD, &tmp); 
    589569 
     
    609589 
    610590    /* PENH */ 
    611     tmp = attr->penh_enabled; 
     591    tmp = attr->penh; 
    612592    speex_decoder_ctl(spx->dec, SPEEX_SET_ENH, &tmp); 
    613593 
  • pjproject/trunk/pjmedia/src/pjmedia/codec.c

    r276 r411  
    1919#include <pjmedia/codec.h> 
    2020#include <pjmedia/errno.h> 
     21#include <pj/array.h> 
     22#include <pj/assert.h> 
     23#include <pj/log.h> 
    2124#include <pj/pool.h> 
    2225#include <pj/string.h> 
    23 #include <pj/assert.h> 
    24 #include <pj/log.h> 
    2526 
    2627#define THIS_FILE   "codec.c" 
    2728 
    28 /* 
    29  * Reinitialize array of supported codecs. 
    30  */ 
    31 static void enum_all_codecs (pjmedia_codec_mgr *mgr) 
    32 { 
    33     pjmedia_codec_factory *factory; 
    34  
    35     mgr->codec_cnt = 0; 
    36  
    37     factory = mgr->factory_list.next; 
    38     while (factory != &mgr->factory_list) { 
    39         unsigned count; 
    40         pj_status_t status; 
    41  
    42         count = PJ_ARRAY_SIZE(mgr->codecs) - mgr->codec_cnt; 
    43         status = factory->op->enum_info(factory, &count,  
    44                                         mgr->codecs+mgr->codec_cnt); 
    45         if (status == PJ_SUCCESS) 
    46             mgr->codec_cnt += count; 
    47  
    48         factory = factory->next; 
    49     } 
    50 } 
     29 
     30 
     31 
     32/* Sort codecs in codec manager based on priorities */ 
     33static void sort_codecs(pjmedia_codec_mgr *mgr); 
     34 
    5135 
    5236/* 
     
    6246    return PJ_SUCCESS; 
    6347} 
     48 
    6449 
    6550/* 
     
    7055                                    pjmedia_codec_factory *factory) 
    7156{ 
     57    pjmedia_codec_info info[PJMEDIA_CODEC_MGR_MAX_CODECS]; 
     58    unsigned i, count; 
     59    pj_status_t status; 
     60 
    7261    PJ_ASSERT_RETURN(mgr && factory, PJ_EINVAL); 
    7362 
     63    /* Enum codecs */ 
     64    count = PJ_ARRAY_SIZE(info); 
     65    status = factory->op->enum_info(factory, &count, info); 
     66    if (status != PJ_SUCCESS) 
     67        return status; 
     68     
     69 
     70    /* Check codec count */ 
     71    if (count + mgr->codec_cnt > PJ_ARRAY_SIZE(mgr->codec_desc)) 
     72        return PJ_ETOOMANY; 
     73 
     74 
     75    /* Save the codecs */ 
     76    for (i=0; i<count; ++i) { 
     77        pj_memcpy( &mgr->codec_desc[mgr->codec_cnt+i], 
     78                   &info[i], sizeof(pjmedia_codec_info)); 
     79        mgr->codec_desc[mgr->codec_cnt+i].prio = PJMEDIA_CODEC_PRIO_NORMAL; 
     80        mgr->codec_desc[mgr->codec_cnt+i].factory = factory; 
     81        pjmedia_codec_info_to_id( &info[i], 
     82                                  mgr->codec_desc[mgr->codec_cnt+i].id, 
     83                                  sizeof(pjmedia_codec_id)); 
     84    } 
     85 
     86    /* Update count */ 
     87    mgr->codec_cnt += count; 
     88 
     89    /* Re-sort codec based on priorities */ 
     90    sort_codecs(mgr); 
     91 
     92    /* Add factory to the list */ 
    7493    pj_list_push_back(&mgr->factory_list, factory); 
    75     enum_all_codecs (mgr); 
     94 
    7695 
    7796    return PJ_SUCCESS; 
    7897} 
     98 
    7999 
    80100/* 
     
    85105                                     pjmedia_codec_factory *factory) 
    86106{ 
    87  
     107    unsigned i; 
    88108    PJ_ASSERT_RETURN(mgr && factory, PJ_EINVAL); 
    89109 
     
    92112                     PJ_ENOTFOUND); 
    93113 
    94  
     114    /* Erase factory from the factory list */ 
    95115    pj_list_erase(factory); 
    96     enum_all_codecs (mgr); 
     116 
     117 
     118    /* Remove all supported codecs from the codec manager that were created  
     119     * by the specified factory. 
     120     */ 
     121    for (i=0; i<mgr->codec_cnt; ) { 
     122 
     123        if (mgr->codec_desc[i].factory == factory) { 
     124 
     125            pj_array_erase(mgr->codec_desc, sizeof(mgr->codec_desc[0]),  
     126                           mgr->codec_cnt, i); 
     127            --mgr->codec_cnt; 
     128 
     129        } else { 
     130            ++i; 
     131        } 
     132    } 
     133 
    97134 
    98135    return PJ_SUCCESS; 
    99136} 
     137 
    100138 
    101139/* 
     
    105143pjmedia_codec_mgr_enum_codecs(pjmedia_codec_mgr *mgr,  
    106144                              unsigned *count,  
    107                               pjmedia_codec_info codecs[]) 
    108 { 
     145                              pjmedia_codec_info codecs[], 
     146                              unsigned *prio) 
     147{ 
     148    unsigned i; 
     149 
    109150    PJ_ASSERT_RETURN(mgr && count && codecs, PJ_EINVAL); 
    110151 
     
    112153        *count = mgr->codec_cnt; 
    113154     
    114     pj_memcpy(codecs, mgr->codecs, *count * sizeof(pjmedia_codec_info)); 
     155    for (i=0; i<*count; ++i) { 
     156        pj_memcpy(&codecs[i],  
     157                  &mgr->codec_desc[i].info,  
     158                  sizeof(pjmedia_codec_info)); 
     159    } 
     160 
     161    if (prio) { 
     162        for (i=0; i < *count; ++i) 
     163            prio[i] = mgr->codec_desc[i].prio; 
     164    } 
    115165 
    116166    return PJ_SUCCESS; 
    117167} 
    118168 
     169 
    119170/* 
    120171 * Get codec info for static payload type. 
    121172 */ 
    122 PJ_DEF(pj_status_t) pjmedia_codec_mgr_get_codec_info(pjmedia_codec_mgr *mgr, 
    123                                                      unsigned pt, 
    124                                                      pjmedia_codec_info *inf) 
     173PJ_DEF(pj_status_t)  
     174pjmedia_codec_mgr_get_codec_info( pjmedia_codec_mgr *mgr, 
     175                                  unsigned pt, 
     176                                  const pjmedia_codec_info **p_info) 
    125177{ 
    126178    unsigned i; 
    127179 
    128     PJ_ASSERT_RETURN(mgr && inf && pt>=0 && pt < 96, PJ_EINVAL); 
     180    PJ_ASSERT_RETURN(mgr && p_info && pt>=0 && pt < 96, PJ_EINVAL); 
    129181 
    130182    for (i=0; i<mgr->codec_cnt; ++i) { 
    131         if (mgr->codecs[i].pt == pt) { 
    132             pj_memcpy(inf, &mgr->codecs[i], sizeof(pjmedia_codec_info)); 
     183        if (mgr->codec_desc[i].info.pt == pt) { 
     184            *p_info = &mgr->codec_desc[i].info; 
    133185            return PJ_SUCCESS; 
    134186        } 
     
    137189    return PJMEDIA_CODEC_EUNSUP; 
    138190} 
     191 
     192 
     193/* 
     194 * Convert codec info struct into a unique codec identifier. 
     195 * A codec identifier looks something like "L16/44100/2". 
     196 */ 
     197PJ_DEF(char*) pjmedia_codec_info_to_id( const pjmedia_codec_info *info, 
     198                                        char *id, unsigned max_len ) 
     199{ 
     200    int len; 
     201 
     202    PJ_ASSERT_RETURN(info && id && max_len, NULL); 
     203 
     204    len = pj_ansi_snprintf(id, max_len, "%.*s/%u/%u",  
     205                           (int)info->encoding_name.slen, 
     206                           info->encoding_name.ptr, 
     207                           info->clock_rate, 
     208                           info->channel_cnt); 
     209 
     210    if (len < 1 || len >= (int)max_len) { 
     211        id[0] = '\0'; 
     212        return NULL; 
     213    } 
     214 
     215    return id; 
     216} 
     217 
     218 
     219/* 
     220 * Find codecs by the unique codec identifier. This function will find 
     221 * all codecs that match the codec identifier prefix. For example, if 
     222 * "L16" is specified, then it will find "L16/8000/1", "L16/16000/1", 
     223 * and so on, up to the maximum count specified in the argument. 
     224 */ 
     225PJ_DEF(pj_status_t)  
     226pjmedia_codec_mgr_find_codecs_by_id( pjmedia_codec_mgr *mgr, 
     227                                     const pj_str_t *codec_id, 
     228                                     unsigned *count, 
     229                                     const pjmedia_codec_info *p_info[], 
     230                                     unsigned prio[]) 
     231{ 
     232    unsigned i, found = 0; 
     233 
     234    PJ_ASSERT_RETURN(mgr && codec_id && count && *count, PJ_EINVAL); 
     235 
     236    for (i=0; i<mgr->codec_cnt; ++i) { 
     237 
     238        if (pj_strnicmp2(codec_id, mgr->codec_desc[i].id,  
     239                         codec_id->slen) == 0)  
     240        { 
     241 
     242            if (p_info) 
     243                p_info[found] = &mgr->codec_desc[i].info; 
     244            if (prio) 
     245                prio[found] = mgr->codec_desc[i].prio; 
     246 
     247            ++found; 
     248 
     249            if (found >= *count) 
     250                break; 
     251        } 
     252 
     253    } 
     254 
     255    *count = found; 
     256 
     257    return found ? PJ_SUCCESS : PJ_ENOTFOUND; 
     258} 
     259 
     260 
     261/* Swap two codecs positions in codec manager */ 
     262static void swap_codec(pjmedia_codec_mgr *mgr, unsigned i, unsigned j) 
     263{ 
     264    struct pjmedia_codec_desc tmp; 
     265 
     266    pj_memcpy(&tmp, &mgr->codec_desc[i], sizeof(struct pjmedia_codec_desc)); 
     267 
     268    pj_memcpy(&mgr->codec_desc[i], &mgr->codec_desc[j],  
     269               sizeof(struct pjmedia_codec_desc)); 
     270 
     271    pj_memcpy(&mgr->codec_desc[j], &tmp, sizeof(struct pjmedia_codec_desc)); 
     272} 
     273 
     274 
     275/* Sort codecs in codec manager based on priorities */ 
     276static void sort_codecs(pjmedia_codec_mgr *mgr) 
     277{ 
     278    unsigned i; 
     279 
     280   /* Re-sort */ 
     281    for (i=0; i<mgr->codec_cnt; ++i) { 
     282        unsigned j, max; 
     283 
     284        for (max=i, j=i+1; j<mgr->codec_cnt; ++j) { 
     285            if (mgr->codec_desc[j].prio > mgr->codec_desc[max].prio) 
     286                max = j; 
     287        } 
     288 
     289        if (max != i) 
     290            swap_codec(mgr, i, max); 
     291    } 
     292 
     293    /* Change PJMEDIA_CODEC_PRIO_HIGHEST codecs to NEXT_HIGHER */ 
     294    for (i=0; i<mgr->codec_cnt; ++i) { 
     295        if (mgr->codec_desc[i].prio == PJMEDIA_CODEC_PRIO_HIGHEST) 
     296            mgr->codec_desc[i].prio = PJMEDIA_CODEC_PRIO_NEXT_HIGHER; 
     297        else 
     298            break; 
     299    } 
     300} 
     301 
     302 
     303/** 
     304 * Set codec priority. The codec priority determines the order of 
     305 * the codec in the SDP created by the endpoint. If more than one codecs 
     306 * are found with the same codec_id prefix, then the function sets the 
     307 * priorities of all those codecs. 
     308 */ 
     309PJ_DEF(pj_status_t) 
     310pjmedia_codec_mgr_set_codec_priority(pjmedia_codec_mgr *mgr,  
     311                                     const pj_str_t *codec_id, 
     312                                     pjmedia_codec_priority prio) 
     313{ 
     314    unsigned i, found = 0; 
     315 
     316    PJ_ASSERT_RETURN(mgr && codec_id, PJ_EINVAL); 
     317 
     318    /* Update the priorities of affected codecs */ 
     319    for (i=0; i<mgr->codec_cnt; ++i)  
     320    { 
     321        if (codec_id->slen == 0 || 
     322            pj_strnicmp2(codec_id, mgr->codec_desc[i].id,  
     323                         codec_id->slen) == 0)  
     324        { 
     325            mgr->codec_desc[i].prio = prio; 
     326            ++found; 
     327        } 
     328    } 
     329 
     330    if (!found) 
     331        return PJ_ENOTFOUND; 
     332 
     333    /* Re-sort codecs */ 
     334    sort_codecs(mgr); 
     335  
     336 
     337    return PJ_SUCCESS; 
     338} 
     339 
    139340 
    140341/* 
  • pjproject/trunk/pjmedia/src/pjmedia/conference.c

    r358 r411  
    238238    if (port) { 
    239239        conf_port->port = port; 
    240         conf_port->clock_rate = port->info.sample_rate; 
     240        conf_port->clock_rate = port->info.clock_rate; 
    241241        conf_port->samples_per_frame = port->info.samples_per_frame; 
    242242    } else { 
     
    443443    conf->master_port->info.need_info = 0; 
    444444    conf->master_port->info.pt = 0xFF; 
    445     conf->master_port->info.sample_rate = clock_rate; 
     445    conf->master_port->info.clock_rate = clock_rate; 
    446446    conf->master_port->info.samples_per_frame = samples_per_frame; 
    447447    conf->master_port->info.signature = 0; 
     
    10911091    pj_int16_t *buf; 
    10921092    unsigned j; 
     1093    pj_status_t status; 
    10931094 
    10941095    /* If port is muted or nobody is transmitting to this port,  
     
    11811182    } 
    11821183 
    1183     /* If port has the same clock_date and samples_per_frame settings as 
     1184    /* If port has the same clock_rate and samples_per_frame settings as 
    11841185     * the conference bridge, transmit the frame as is. 
    11851186     */ 
     
    12251226    } 
    12261227 
    1227     /* Transmit once we have enough frame in the tx_buf. */ 
    1228     if (cport->tx_buf_count >= cport->samples_per_frame) { 
     1228    /* Transmit while we have enough frame in the tx_buf. */ 
     1229    status = PJ_SUCCESS; 
     1230    while (cport->tx_buf_count >= cport->samples_per_frame && 
     1231           status == PJ_SUCCESS)  
     1232    { 
    12291233         
    1230         pj_status_t status; 
    1231  
    12321234        TRACE_((THIS_FILE, "write_port %.*s: count=%d",  
    12331235                           (int)cport->name.slen, cport->name.ptr, 
     
    12601262        TRACE_((THIS_FILE, " tx_buf count now is %d",  
    12611263                           cport->tx_buf_count)); 
    1262  
    1263         return status; 
    1264     } 
    1265  
    1266     return PJ_SUCCESS; 
     1264    } 
     1265 
     1266    return status; 
    12671267} 
    12681268 
  • pjproject/trunk/pjmedia/src/pjmedia/endpoint.c

    r350 r411  
    330330    for (i=0; i<endpt->codec_mgr.codec_cnt; ++i) { 
    331331 
    332         pjmedia_codec_info *codec_info = &endpt->codec_mgr.codecs[i]; 
     332        pjmedia_codec_info *codec_info; 
    333333        pjmedia_sdp_rtpmap rtpmap; 
     334        char tmp_param[3]; 
    334335        pjmedia_sdp_attr *attr; 
    335         pj_str_t *fmt = &m->desc.fmt[m->desc.fmt_count++]; 
     336        pj_str_t *fmt; 
     337 
     338        if (endpt->codec_mgr.codec_desc[i].prio == PJMEDIA_CODEC_PRIO_DISABLED) 
     339            break; 
     340 
     341        codec_info = &endpt->codec_mgr.codec_desc[i].info; 
     342        fmt = &m->desc.fmt[m->desc.fmt_count++]; 
    336343 
    337344        fmt->ptr = pj_pool_alloc(pool, 8); 
     
    339346 
    340347        rtpmap.pt = *fmt; 
    341         rtpmap.clock_rate = codec_info->sample_rate; 
     348        rtpmap.clock_rate = codec_info->clock_rate; 
    342349        rtpmap.enc_name = codec_info->encoding_name; 
    343         rtpmap.param.slen = 0; 
     350         
     351        /* For audio codecs, rtpmap parameters denotes the number 
     352         * of channels, which can be omited if the value is 1. 
     353         */ 
     354        if (codec_info->type == PJMEDIA_TYPE_AUDIO && 
     355            codec_info->channel_cnt > 1) 
     356        { 
     357            /* Can only support one digit channel count */ 
     358            pj_assert(codec_info->channel_cnt < 10); 
     359 
     360            tmp_param[0] = '/'; 
     361            tmp_param[1] = (char)('0' + codec_info->channel_cnt); 
     362 
     363            rtpmap.param.ptr = tmp_param; 
     364            rtpmap.param.slen = 2; 
     365 
     366        } else { 
     367            rtpmap.param.slen = 0; 
     368        } 
    344369 
    345370        pjmedia_sdp_rtpmap_to_attr(pool, &rtpmap, &attr); 
     
    389414    count = PJ_ARRAY_SIZE(codec_info); 
    390415    if (pjmedia_codec_mgr_enum_codecs(&endpt->codec_mgr,  
    391                                       &count, codec_info) != PJ_SUCCESS) 
     416                                      &count, codec_info, NULL) != PJ_SUCCESS) 
    392417    { 
    393418        PJ_LOG(3,(THIS_FILE, " -error: failed to enum codecs")); 
     
    417442 
    418443        PJ_LOG(3,(THIS_FILE,  
    419                   "   %s codec #%2d: pt=%d (%.*s @%dKHz, %d bps, ptime=%d ms, vad=%d, cng=%d)",  
     444                  "   %s codec #%2d: pt=%d (%.*s @%dKHz/%d, %d bps, ptime=%d ms, vad=%d, cng=%d)",  
    420445                  type, i, codec_info[i].pt, 
    421446                  (int)codec_info[i].encoding_name.slen, 
    422447                  codec_info[i].encoding_name.ptr, 
    423                   codec_info[i].sample_rate/1000, 
     448                  codec_info[i].clock_rate/1000, 
     449                  codec_info[i].channel_cnt, 
    424450                  param.avg_bps, param.ptime, 
    425                   param.vad_enabled, 
    426                   param.cng_enabled)); 
     451                  param.vad, 
     452                  param.cng)); 
    427453    } 
    428454#endif 
  • pjproject/trunk/pjmedia/src/pjmedia/g711.c

    r320 r411  
    3636/* These are the only public functions exported to applications */ 
    3737PJ_DECL(pj_status_t) g711_init_factory (pjmedia_codec_factory *factory, pj_pool_t *pool); 
    38 PJ_DECL(pj_status_t) g711_deinit_factory (pjmedia_codec_factory *factory); 
    3938 
    4039/* Algorithm prototypes. */ 
     
    6059 
    6160/* Prototypes for G711 implementation. */ 
    62 static pj_status_t  g711_codec_default_attr (pjmedia_codec *codec,  
    63                                              pjmedia_codec_param *attr); 
    6461static pj_status_t  g711_init( pjmedia_codec *codec,  
    6562                               pj_pool_t *pool ); 
     
    8481static pjmedia_codec_op g711_op =  
    8582{ 
    86     &g711_codec_default_attr , 
    8783    &g711_init, 
    8884    &g711_open, 
     
    120116 
    121117 
    122 PJ_DEF(pj_status_t) g711_deinit_factory (pjmedia_codec_factory *factory) 
    123 { 
    124     PJ_ASSERT_RETURN(factory==&g711_factory.base, PJ_EINVAL); 
    125  
    126     /* Invalidate member to help detect errors */ 
    127     g711_factory.codec_list.next = g711_factory.codec_list.prev = NULL; 
    128     return 0; 
    129 } 
    130  
    131118PJ_DEF(pj_status_t) pjmedia_codec_g711_init(pjmedia_endpt *endpt) 
    132119{ 
     
    223210} 
    224211 
    225 static pj_status_t g711_test_alloc( pjmedia_codec_factory *factory, const pjmedia_codec_info *id ) 
     212static pj_status_t g711_test_alloc(pjmedia_codec_factory *factory,  
     213                                   const pjmedia_codec_info *id ) 
    226214{ 
    227215    PJ_UNUSED_ARG(factory); 
     
    238226 
    239227    pj_memset(attr, 0, sizeof(pjmedia_codec_param)); 
    240     attr->sample_rate = 8000; 
     228    attr->clock_rate = 8000; 
     229    attr->channel_cnt = 1; 
    241230    attr->avg_bps = G711_BPS; 
    242231    attr->pcm_bits_per_sample = 16; 
     
    261250        codecs[count].pt = PJMEDIA_RTP_PT_PCMU; 
    262251        codecs[count].encoding_name = pj_str("PCMU"); 
    263         codecs[count].sample_rate = 8000; 
     252        codecs[count].clock_rate = 8000; 
     253        codecs[count].channel_cnt = 1; 
    264254        ++count; 
    265255    } 
    266256    if (count < *max_count) { 
    267         codecs[1].type = PJMEDIA_TYPE_AUDIO; 
    268         codecs[1].pt = PJMEDIA_RTP_PT_PCMA; 
    269         codecs[1].encoding_name = pj_str("PCMA"); 
    270         codecs[1].sample_rate = 8000; 
     257        codecs[count].type = PJMEDIA_TYPE_AUDIO; 
     258        codecs[count].pt = PJMEDIA_RTP_PT_PCMA; 
     259        codecs[count].encoding_name = pj_str("PCMA"); 
     260        codecs[count].clock_rate = 8000; 
     261        codecs[count].channel_cnt = 1; 
    271262        ++count; 
    272263    } 
     
    293284 
    294285        codec = pj_pool_alloc(g711_factory.pool, sizeof(pjmedia_codec)); 
    295         codec_priv = pj_pool_alloc(g711_factory.pool, sizeof(struct g711_private)); 
     286        codec_priv = pj_pool_alloc(g711_factory.pool,  
     287                                   sizeof(struct g711_private)); 
    296288        if (!codec || !codec_priv) { 
    297289            pj_mutex_unlock(g711_factory.mutex); 
     
    320312} 
    321313 
    322 static pj_status_t g711_dealloc_codec( pjmedia_codec_factory *factory, pjmedia_codec *codec ) 
     314static pj_status_t g711_dealloc_codec(pjmedia_codec_factory *factory,  
     315                                      pjmedia_codec *codec ) 
    323316{ 
    324317     
     
    343336} 
    344337 
    345 static pj_status_t g711_codec_default_attr  (pjmedia_codec *codec, pjmedia_codec_param *attr) 
    346 { 
    347     struct g711_private *priv = codec->codec_data; 
    348     pjmedia_codec_info id; 
    349  
    350     id.pt = priv->pt; 
    351     return g711_default_attr (NULL, &id, attr); 
    352 } 
    353  
    354338static pj_status_t g711_init( pjmedia_codec *codec, pj_pool_t *pool ) 
    355339{ 
     
    361345} 
    362346 
    363 static pj_status_t g711_open( pjmedia_codec *codec, pjmedia_codec_param *attr ) 
     347static pj_status_t g711_open(pjmedia_codec *codec,  
     348                             pjmedia_codec_param *attr ) 
    364349{ 
    365350    struct g711_private *priv = codec->codec_data; 
     
    401386} 
    402387 
    403 static pj_status_t  g711_encode( pjmedia_codec *codec, const struct pjmedia_frame *input, 
    404                                  unsigned output_buf_len, struct pjmedia_frame *output) 
     388static pj_status_t  g711_encode(pjmedia_codec *codec,  
     389                                const struct pjmedia_frame *input, 
     390                                unsigned output_buf_len,  
     391                                struct pjmedia_frame *output) 
    405392{ 
    406393    pj_int16_t *samples = (pj_int16_t*) input->buf; 
     
    409396    /* Check output buffer length */ 
    410397    if (output_buf_len < input->size / 2) 
    411         return -1; 
     398        return PJMEDIA_CODEC_EFRMTOOSHORT; 
    412399 
    413400    /* Encode */ 
     
    428415 
    429416    } else { 
    430         return -1; 
     417        return PJMEDIA_EINVALIDPT; 
    431418    } 
    432419 
     
    434421    output->size = input->size / 2; 
    435422 
    436     return 0; 
    437 } 
    438  
    439 static pj_status_t  g711_decode( pjmedia_codec *codec, const struct pjmedia_frame *input, 
    440                                  unsigned output_buf_len, struct pjmedia_frame *output) 
     423    return PJ_SUCCESS; 
     424} 
     425 
     426static pj_status_t  g711_decode(pjmedia_codec *codec,  
     427                                const struct pjmedia_frame *input, 
     428                                unsigned output_buf_len,  
     429                                struct pjmedia_frame *output) 
    441430{ 
    442431    struct g711_private *priv = codec->codec_data; 
     
    444433    /* Check output buffer length */ 
    445434    if (output_buf_len < input->size * 2) 
    446         return -1; 
     435        return PJMEDIA_CODEC_EPCMTOOSHORT; 
    447436 
    448437    /* Decode */ 
     
    465454 
    466455    } else { 
    467         return -1; 
     456        return PJMEDIA_EINVALIDPT; 
    468457    } 
    469458 
     
    471460    output->size = input->size * 2; 
    472461 
    473     return 0; 
     462    return PJ_SUCCESS; 
    474463} 
    475464 
  • pjproject/trunk/pjmedia/src/pjmedia/jbuf.c

    r408 r411  
    323323static void jbuf_calculate_jitter(pjmedia_jbuf *jb) 
    324324{ 
    325     enum { STABLE_HISTORY_LIMIT = (500/20) }; 
     325    enum { STABLE_HISTORY_LIMIT = (100*2) }; 
    326326 
    327327    jb->jb_last_jitter = PJ_ABS(jb->jb_level-jb->jb_last_level); 
     
    342342            jb->jb_max_hist_jitter = 0; 
    343343 
    344             if (jb->jb_op_count >= 100 && 
     344            if (jb->jb_op_count >= STABLE_HISTORY_LIMIT*2 && 
    345345                (int)jb_framelist_size(&jb->jb_framelist) > jb->jb_prefetch+2) 
    346346            { 
     
    361361        jb->jb_max_hist_jitter = 0; 
    362362 
    363         if (jb->jb_op_count >= 100) { 
     363        if (jb->jb_op_count >= STABLE_HISTORY_LIMIT * 2) { 
    364364            if ((int)jb_framelist_size(&jb->jb_framelist) > jb->jb_prefetch+2)  
    365365            { 
  • pjproject/trunk/pjmedia/src/pjmedia/master_port.c

    r404 r411  
    6060 
    6161    /* Both ports MUST have the equal ptime */ 
    62     PJ_ASSERT_RETURN(u_port->info.sample_rate/u_port->info.samples_per_frame== 
    63                      d_port->info.sample_rate/d_port->info.samples_per_frame, 
     62    PJ_ASSERT_RETURN(u_port->info.clock_rate/u_port->info.samples_per_frame== 
     63                     d_port->info.clock_rate/d_port->info.samples_per_frame, 
    6464                     PJMEDIA_ENCSAMPLESPFRAME); 
    6565 
    6666 
    6767    /* Get clock_rate and samples_per_frame from one of the port. */ 
    68     clock_rate = u_port->info.sample_rate; 
     68    clock_rate = u_port->info.clock_rate; 
    6969    samples_per_frame = u_port->info.samples_per_frame; 
    7070 
  • pjproject/trunk/pjmedia/src/pjmedia/null_port.c

    r322 r411  
    5252    port->info.need_info = 0; 
    5353    port->info.pt = 0xFF; 
    54     port->info.sample_rate = sampling_rate; 
     54    port->info.clock_rate = sampling_rate; 
    5555    port->info.samples_per_frame = samples_per_frame; 
    5656    port->info.channel_count = channel_count; 
  • pjproject/trunk/pjmedia/src/pjmedia/resample_port.c

    r358 r411  
    7676    rport->base.info.need_info = 0; 
    7777    rport->base.info.pt = 0xFF; 
    78     rport->base.info.sample_rate = upstream_rate; 
     78    rport->base.info.clock_rate = upstream_rate; 
    7979    rport->base.info.samples_per_frame = upstream_samples_per_frame; 
    8080    rport->base.info.signature = 0; 
  • pjproject/trunk/pjmedia/src/pjmedia/rtcp.c

    r408 r411  
    134134    pj_time_val now; 
    135135     
     136    /* Reset packet */ 
    136137    pj_memset(rtcp_pkt, 0, sizeof(pjmedia_rtcp_pkt)); 
    137138     
     139    /* Reset statistics */ 
     140    pj_memset(&sess->stat, 0, sizeof(pjmedia_rtcp_stat)); 
     141 
    138142    /* Name */ 
    139143    sess->name = name ? name : THIS_FILE, 
  • pjproject/trunk/pjmedia/src/pjmedia/session.c

    r390 r411  
    195195            si->fmt.pt = pj_strtoul(&local_m->desc.fmt[0]); 
    196196            pj_strdup(pool, &si->fmt.encoding_name, &rtpmap->enc_name); 
    197             si->fmt.sample_rate = rtpmap->clock_rate; 
     197            si->fmt.clock_rate = rtpmap->clock_rate; 
     198             
     199            /* For audio codecs, rtpmap parameters denotes the number of 
     200             * channels. 
     201             */ 
     202            if (si->type == PJMEDIA_TYPE_AUDIO && rtpmap->param.slen) { 
     203                 
     204                if (rtpmap->param.slen == 2) { 
     205                    si->fmt.channel_cnt = rtpmap->param.ptr[1] - '0'; 
     206                } else { 
     207                    pj_str_t cnt; 
     208                    cnt.ptr = rtpmap->param.ptr + 1; 
     209                    cnt.slen = rtpmap->param.slen - 1; 
     210                    si->fmt.channel_cnt = (unsigned) pj_strtoul(&cnt); 
     211                } 
     212 
     213            } else { 
     214                si->fmt.channel_cnt = 1; 
     215            } 
    198216 
    199217        } else { 
    200218            pjmedia_codec_mgr *mgr; 
     219            pjmedia_codec_info *p_info; 
    201220 
    202221            mgr = pjmedia_endpt_get_codec_mgr(endpt); 
    203222 
    204             status = pjmedia_codec_mgr_get_codec_info( mgr, pt, &si->fmt); 
     223            status = pjmedia_codec_mgr_get_codec_info( mgr, pt, &p_info); 
    205224            if (status != PJ_SUCCESS) 
    206225                return status; 
     226 
     227            pj_memcpy(&si->fmt, p_info, sizeof(pjmedia_codec_info)); 
    207228        } 
    208229 
     
    225246        si->fmt.pt = pj_strtoul(&local_m->desc.fmt[0]); 
    226247        pj_strdup(pool, &si->fmt.encoding_name, &rtpmap->enc_name); 
    227         si->fmt.sample_rate = rtpmap->clock_rate; 
     248        si->fmt.clock_rate = rtpmap->clock_rate; 
     249 
     250        /* For audio codecs, rtpmap parameters denotes the number of 
     251         * channels. 
     252         */ 
     253        if (si->type == PJMEDIA_TYPE_AUDIO && rtpmap->param.slen) { 
     254             
     255            if (rtpmap->param.slen == 2) { 
     256                si->fmt.channel_cnt = rtpmap->param.ptr[1] - '0'; 
     257            } else { 
     258                pj_str_t cnt; 
     259                cnt.ptr = rtpmap->param.ptr + 1; 
     260                cnt.slen = rtpmap->param.slen - 1; 
     261                si->fmt.channel_cnt = (unsigned) pj_strtoul(&cnt); 
     262            } 
     263 
     264        } else { 
     265            si->fmt.channel_cnt = 1; 
     266        } 
    228267 
    229268        /* Determine payload type for outgoing channel, by finding 
  • pjproject/trunk/pjmedia/src/pjmedia/sound_port.c

    r358 r411  
    345345     */ 
    346346    pinfo = &port->info; 
    347     if (pinfo->sample_rate != snd_port->clock_rate) 
     347    if (pinfo->clock_rate != snd_port->clock_rate) 
    348348        return PJMEDIA_ENCCLOCKRATE; 
    349349 
  • pjproject/trunk/pjmedia/src/pjmedia/stream.c

    r408 r411  
    159159    struct pjmedia_frame frame_in, frame_out; 
    160160 
     161    /* Return no frame is channel is paused */ 
     162    if (channel->paused) { 
     163        frame->type = PJMEDIA_FRAME_TYPE_NONE; 
     164        return PJ_SUCCESS; 
     165    } 
     166 
    161167    /* Lock jitter buffer mutex */ 
    162168    pj_mutex_lock( stream->jb_mutex ); 
     
    175181        return PJ_SUCCESS; 
    176182    } 
    177  
    178183 
    179184    /* Decode */ 
     
    321326    int rtphdrlen; 
    322327    pj_ssize_t sent; 
     328 
     329 
     330    /* Don't do anything if stream is paused */ 
     331    if (channel->paused) 
     332        return PJ_SUCCESS; 
     333 
    323334 
    324335    /* Number of samples in the frame */ 
     
    758769    /* Allocate buffer for decoding to PCM: */ 
    759770 
    760     channel->pcm_buf_size = codec_param->sample_rate *  
     771    channel->pcm_buf_size = codec_param->clock_rate *  
     772                            codec_param->channel_cnt * 
    761773                            codec_param->pcm_bits_per_sample / 8 * 
    762774                            PJMEDIA_MAX_FRAME_DURATION_MS / 1000; 
     
    791803    pj_ioqueue_callback ioqueue_cb; 
    792804    pj_uint16_t rtcp_port; 
     805    unsigned jbuf_init, jbuf_max; 
    793806    pj_status_t status; 
    794807 
     
    814827    stream->port.info.pt = info->fmt.pt; 
    815828    pj_strdup(pool, &stream->port.info.encoding_name, &info->fmt.encoding_name); 
    816     stream->port.info.channel_count = 1; 
    817     stream->port.info.sample_rate = info->fmt.sample_rate; 
     829    stream->port.info.clock_rate = info->fmt.clock_rate; 
     830    stream->port.info.channel_count = info->fmt.channel_cnt; 
    818831    stream->port.user_data = stream; 
    819832    stream->port.put_frame = &put_frame; 
     
    832845    stream->rem_rtcp_addr.sin_port = pj_htons(rtcp_port); 
    833846    stream->rtcp_interval = (PJMEDIA_RTCP_INTERVAL + (pj_rand() % 8000)) *  
    834                             info->fmt.sample_rate / 1000; 
     847                            info->fmt.clock_rate / 1000; 
    835848 
    836849    stream->tx_event_pt = info->tx_event_pt ? info->tx_event_pt : -1; 
     
    856869    /* Get default codec param: */ 
    857870 
    858     status = stream->codec->op->default_attr(stream->codec, &codec_param); 
     871    //status = stream->codec->op->default_attr(stream->codec, &codec_param); 
     872    status = pjmedia_codec_mgr_get_default_param( stream->codec_mgr,  
     873                                                  &info->fmt, &codec_param); 
    859874    if (status != PJ_SUCCESS) 
    860875        goto err_cleanup; 
     
    862877    /* Set additional info. */ 
    863878    stream->port.info.bits_per_sample = 16; 
    864     stream->port.info.samples_per_frame = info->fmt.sample_rate*codec_param.ptime/1000; 
     879    stream->port.info.samples_per_frame = info->fmt.clock_rate*codec_param.ptime/1000; 
    865880    stream->port.info.bytes_per_frame = codec_param.avg_bps/8 * codec_param.ptime/1000; 
    866881 
     
    881896 
    882897    pjmedia_rtcp_init(&stream->rtcp, stream->port.info.name.ptr, 
    883                       info->fmt.sample_rate,  
     898                      info->fmt.clock_rate,  
    884899                      stream->port.info.samples_per_frame,  
    885900                      info->ssrc); 
     
    887902 
    888903    /* Create jitter buffer: */ 
    889  
     904    jbuf_init = 100 / (stream->port.info.samples_per_frame * 1000 /  
     905                       info->fmt.clock_rate); 
     906    jbuf_max = 600 / (stream->port.info.samples_per_frame * 1000 /  
     907                       info->fmt.clock_rate); 
    890908    status = pjmedia_jbuf_create(pool, &stream->port.info.name, 
    891                                  stream->frame_size, 15, 100, 
     909                                 stream->frame_size,  
     910                                 jbuf_init, jbuf_max, 
    892911                                 &stream->jb); 
    893912    if (status != PJ_SUCCESS) 
Note: See TracChangeset for help on using the changeset viewer.