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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 * @} 
Note: See TracChangeset for help on using the changeset viewer.