Changeset 176


Ignore:
Timestamp:
Feb 10, 2006 3:57:08 PM (18 years ago)
Author:
bennylp
Message:

Added pjmedia-codec library

Location:
pjproject/trunk/pjmedia
Files:
35 added
7 edited

Legend:

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

    r129 r176  
    6161############################################################################### 
    6262 
     63Project: "pjmedia_codec"=.\pjmedia_codec.dsp - Package Owner=<4> 
     64 
     65Package=<5> 
     66{{{ 
     67}}} 
     68 
     69Package=<4> 
     70{{{ 
     71}}} 
     72 
     73############################################################################### 
     74 
    6375Project: "pjmedia_test"=.\pjmedia_test.dsp - Package Owner=<4> 
    6476 
  • pjproject/trunk/pjmedia/include/pjmedia/codec.h

    r171 r176  
    183183 
    184184 
     185    /** 
     186     * Instruct the codec to inspect the specified payload/packet and 
     187     * split the packet info individual frames. 
     188     * 
     189     * @param codec     The codec instance 
     190     * @param pkt       The input packet. 
     191     * @param pkt_size  Size of the packet. 
     192     * @param frame_cnt On input, specifies the maximum number of frames 
     193     *                  in the array. On output, the codec must fill 
     194     *                  with number of frames detected in the packet. 
     195     * @param frames    On output, specifies the frames that have been 
     196     *                  detected in the packet. 
     197     * 
     198     * @return          PJ_SUCCESS on success. 
     199     */ 
     200    pj_status_t (*get_frames)(pjmedia_codec *codec, 
     201                              void *pkt, 
     202                              pj_size_t pkt_size, 
     203                              unsigned *frame_cnt, 
     204                              pjmedia_frame frames[]); 
     205 
    185206    /**  
    186207     * Instruct the codec to encode the specified input frame. 
     
    400421 
    401422/** 
     423 * Get default codec param for the specified codec info. 
     424 * 
     425 * @param mgr       The codec manager. 
     426 * @param info      The codec info, which default parameter's is being 
     427 *                  queried. 
     428 * @param param     On return, will be filled with the default codec 
     429 *                  parameter. 
     430 * 
     431 * @return          PJ_SUCCESS on success. 
     432 */ 
     433PJ_DECL(pj_status_t) pjmedia_codec_mgr_get_default_param(pjmedia_codec_mgr *mgr, 
     434                                                         const pjmedia_codec_info *info, 
     435                                                         pjmedia_codec_param *param ); 
     436 
     437/** 
    402438 * Request the codec manager to allocate one instance of codec with the 
    403439 * specified codec info. The codec will enumerate all codec factories 
  • pjproject/trunk/pjmedia/include/pjmedia/endpoint.h

    r159 r176  
    119119 
    120120 
     121/** 
     122 * Dump media endpoint capabilities. 
     123 * 
     124 * @param endpt         The media endpoint. 
     125 * 
     126 * @return              PJ_SUCCESS on success. 
     127 */ 
     128PJ_DECL(pj_status_t) pjmedia_endpt_dump(pjmedia_endpt *endpt); 
     129 
    121130 
    122131PJ_END_DECL 
  • pjproject/trunk/pjmedia/include/pjmedia/errno.h

    r169 r176  
    249249 */ 
    250250#define PJMEDIA_CODEC_EUNSUP        (PJMEDIA_ERRNO_START+80)    /* 220080 */ 
     251/** 
     252 * @hideinitializer 
     253 * Unable to create codec. 
     254 */ 
     255#define PJMEDIA_CODEC_EFAILED       (PJMEDIA_ERRNO_START+81)    /* 220081 */ 
     256/** 
     257 * @hideinitializer 
     258 * Codec frame is too short. 
     259 */ 
     260#define PJMEDIA_CODEC_EFRMTOOSHORT  (PJMEDIA_ERRNO_START+82)    /* 220082 */ 
     261/** 
     262 * @hideinitializer 
     263 * PCM buffer is too short. 
     264 */ 
     265#define PJMEDIA_CODEC_EPCMTOOSHORT  (PJMEDIA_ERRNO_START+83)    /* 220083 */ 
    251266 
    252267 
     
    274289 */ 
    275290#define PJMEDIA_EMISSINGRTPMAP      (PJMEDIA_ERRNO_START+103)    /* 220103 */ 
     291/** 
     292 * @hideinitializer 
     293 * Invalid media type. 
     294 */ 
     295#define PJMEDIA_EINVALIMEDIATYPE    (PJMEDIA_ERRNO_START+104)    /* 220104 */ 
    276296 
    277297 
  • pjproject/trunk/pjmedia/src/pjmedia/codec.c

    r159 r176  
    149149} 
    150150 
     151 
     152/* 
     153 * Get default codec parameter. 
     154 */ 
     155PJ_DEF(pj_status_t) pjmedia_codec_mgr_get_default_param( pjmedia_codec_mgr *mgr, 
     156                                                        const pjmedia_codec_info *info, 
     157                                                        pjmedia_codec_param *param ) 
     158{ 
     159    pjmedia_codec_factory *factory; 
     160    pj_status_t status; 
     161 
     162    PJ_ASSERT_RETURN(mgr && info && param, PJ_EINVAL); 
     163 
     164    factory = mgr->factory_list.next; 
     165    while (factory != &mgr->factory_list) { 
     166 
     167        if ( (*factory->op->test_alloc)(factory, info) == PJ_SUCCESS ) { 
     168 
     169            status = (*factory->op->default_attr)(factory, info, param); 
     170            if (status == PJ_SUCCESS) 
     171                return PJ_SUCCESS; 
     172 
     173        } 
     174 
     175        factory = factory->next; 
     176    } 
     177 
     178 
     179    return PJMEDIA_CODEC_EUNSUP; 
     180} 
     181 
     182 
    151183/* 
    152184 * Dealloc codec. 
  • pjproject/trunk/pjmedia/src/pjmedia/endpoint.c

    r162 r176  
    2525#include <pj/assert.h> 
    2626#include <pj/os.h> 
     27#include <pj/log.h> 
    2728 
    2829 
     
    270271} 
    271272 
     273 
     274PJ_DEF(pj_status_t) pjmedia_endpt_dump(pjmedia_endpt *endpt) 
     275{ 
     276 
     277#if PJ_LOG_MAX_LEVEL >= 3 
     278    unsigned i, count; 
     279    pjmedia_codec_info codec_info[32]; 
     280 
     281    PJ_LOG(3,(THIS_FILE, "Dumping PJMEDIA capabilities:")); 
     282 
     283    count = PJ_ARRAY_SIZE(codec_info); 
     284    if (pjmedia_codec_mgr_enum_codecs(&endpt->codec_mgr,  
     285                                      &count, codec_info) != PJ_SUCCESS) 
     286    { 
     287        PJ_LOG(3,(THIS_FILE, " -error: failed to enum codecs")); 
     288        return PJ_SUCCESS; 
     289    } 
     290 
     291    PJ_LOG(3,(THIS_FILE, "  Total number of installed codecs: %d", count)); 
     292    for (i=0; i<count; ++i) { 
     293        const char *type; 
     294        pjmedia_codec_param param; 
     295 
     296        switch (codec_info[i].type) { 
     297        case PJMEDIA_TYPE_AUDIO: 
     298            type = "Audio"; break; 
     299        case PJMEDIA_TYPE_VIDEO: 
     300            type = "Video"; break; 
     301        default: 
     302            type = "Unknown type"; break; 
     303        } 
     304 
     305        if (pjmedia_codec_mgr_get_default_param(&endpt->codec_mgr, 
     306                                                &codec_info[i], 
     307                                                &param) != PJ_SUCCESS) 
     308        { 
     309            pj_memset(&param, 0, sizeof(pjmedia_codec_param)); 
     310        } 
     311 
     312        PJ_LOG(3,(THIS_FILE,  
     313                  "   %s codec #%2d: pt=%d (%.*s, %d bps, ptime=%d ms, vad=%d, cng=%d)",  
     314                  type, i, codec_info[i].pt, 
     315                  (int)codec_info[i].encoding_name.slen, 
     316                  codec_info[i].encoding_name.ptr, 
     317                  param.avg_bps, param.ptime, 
     318                  param.vad_enabled, 
     319                  param.cng_enabled)); 
     320    } 
     321#endif 
     322 
     323    return PJ_SUCCESS; 
     324} 
  • pjproject/trunk/pjmedia/src/pjmedia/g711.c

    r159 r176  
    4141 
    4242/* Prototypes for G711 factory */ 
    43 static pj_status_t g711_match_id( pjmedia_codec_factory *factory, const pjmedia_codec_info *id ); 
    44 static pj_status_t g711_default_attr( pjmedia_codec_factory *factory, const pjmedia_codec_info *id, pjmedia_codec_param *attr ); 
    45 static pj_status_t g711_enum_codecs (pjmedia_codec_factory *factory, unsigned *count, pjmedia_codec_info codecs[]); 
    46 static pj_status_t g711_alloc_codec( pjmedia_codec_factory *factory, const pjmedia_codec_info *id, pjmedia_codec **p_codec); 
    47 static pj_status_t g711_dealloc_codec( pjmedia_codec_factory *factory, pjmedia_codec *codec ); 
     43static pj_status_t g711_test_alloc( pjmedia_codec_factory *factory,  
     44                                    const pjmedia_codec_info *id ); 
     45static pj_status_t g711_default_attr( pjmedia_codec_factory *factory,  
     46                                      const pjmedia_codec_info *id,  
     47                                      pjmedia_codec_param *attr ); 
     48static pj_status_t g711_enum_codecs (pjmedia_codec_factory *factory,  
     49                                     unsigned *count,  
     50                                     pjmedia_codec_info codecs[]); 
     51static pj_status_t g711_alloc_codec( pjmedia_codec_factory *factory,  
     52                                     const pjmedia_codec_info *id,  
     53                                     pjmedia_codec **p_codec); 
     54static pj_status_t g711_dealloc_codec( pjmedia_codec_factory *factory,  
     55                                       pjmedia_codec *codec ); 
    4856 
    4957/* Prototypes for G711 implementation. */ 
    50 static pj_status_t  g711_codec_default_attr (pjmedia_codec *codec, pjmedia_codec_param *attr); 
    51 static pj_status_t  g711_init( pjmedia_codec *codec, pj_pool_t *pool ); 
    52 static pj_status_t  g711_open( pjmedia_codec *codec, pjmedia_codec_param *attr ); 
     58static pj_status_t  g711_codec_default_attr (pjmedia_codec *codec,  
     59                                             pjmedia_codec_param *attr); 
     60static pj_status_t  g711_init( pjmedia_codec *codec,  
     61                               pj_pool_t *pool ); 
     62static pj_status_t  g711_open( pjmedia_codec *codec,  
     63                               pjmedia_codec_param *attr ); 
    5364static pj_status_t  g711_close( pjmedia_codec *codec ); 
    54 static pj_status_t  g711_encode( pjmedia_codec *codec, const struct pjmedia_frame *input, 
    55                                  unsigned output_buf_len, struct pjmedia_frame *output); 
    56 static pj_status_t  g711_decode( pjmedia_codec *codec, const struct pjmedia_frame *input, 
    57                                  unsigned output_buf_len, struct pjmedia_frame *output); 
     65static pj_status_t  g711_get_frames(pjmedia_codec *codec, 
     66                                    void *pkt, 
     67                                    pj_size_t pkt_size, 
     68                                    unsigned *frame_cnt, 
     69                                    pjmedia_frame frames[]); 
     70static pj_status_t  g711_encode( pjmedia_codec *codec,  
     71                                 const struct pjmedia_frame *input, 
     72                                 unsigned output_buf_len,  
     73                                 struct pjmedia_frame *output); 
     74static pj_status_t  g711_decode( pjmedia_codec *codec,  
     75                                 const struct pjmedia_frame *input, 
     76                                 unsigned output_buf_len,  
     77                                 struct pjmedia_frame *output); 
    5878 
    5979/* Definition for G711 codec operations. */ 
     
    6484    &g711_open, 
    6585    &g711_close, 
     86    &g711_get_frames, 
    6687    &g711_encode, 
    6788    &g711_decode 
     
    7192static pjmedia_codec_factory_op g711_factory_op = 
    7293{ 
    73     &g711_match_id, 
     94    &g711_test_alloc, 
    7495    &g711_default_attr, 
    7596    &g711_enum_codecs, 
     
    129150} 
    130151 
    131 static pj_status_t g711_match_id( pjmedia_codec_factory *factory, const pjmedia_codec_info *id ) 
     152static pj_status_t g711_test_alloc( pjmedia_codec_factory *factory, const pjmedia_codec_info *id ) 
    132153{ 
    133154    PJ_UNUSED_ARG(factory); 
     
    143164    PJ_UNUSED_ARG(factory); 
    144165 
    145     memset(attr, 0, sizeof(pjmedia_codec_param)); 
     166    pj_memset(attr, 0, sizeof(pjmedia_codec_param)); 
    146167    attr->sample_rate = 8000; 
    147168    attr->avg_bps = G711_BPS; 
     
    156177 
    157178static pj_status_t g711_enum_codecs(pjmedia_codec_factory *factory,  
    158                                     unsigned *count,  
     179                                    unsigned *max_count,  
    159180                                    pjmedia_codec_info codecs[]) 
    160181{ 
     182    unsigned count = 0; 
     183 
    161184    PJ_UNUSED_ARG(factory); 
    162185 
    163     if (*count > 0) { 
    164         codecs[0].type = PJMEDIA_TYPE_AUDIO; 
    165         codecs[0].pt = PJMEDIA_RTP_PT_PCMU; 
    166         codecs[0].encoding_name = pj_str("PCMU"); 
    167         codecs[0].sample_rate = 8000; 
     186    if (count < *max_count) { 
     187        codecs[count].type = PJMEDIA_TYPE_AUDIO; 
     188        codecs[count].pt = PJMEDIA_RTP_PT_PCMU; 
     189        codecs[count].encoding_name = pj_str("PCMU"); 
     190        codecs[count].sample_rate = 8000; 
     191        ++count; 
    168192    } 
    169     if (*count > 1) { 
     193    if (count < *max_count) { 
    170194        codecs[1].type = PJMEDIA_TYPE_AUDIO; 
    171195        codecs[1].pt = PJMEDIA_RTP_PT_PCMA; 
    172196        codecs[1].encoding_name = pj_str("PCMA"); 
    173197        codecs[1].sample_rate = 8000; 
     198        ++count; 
    174199    } 
    175200 
    176     if (*count > 0) *count=1; 
    177     if (*count > 1) *count=2; 
     201    *max_count = count; 
    178202 
    179203    return PJ_SUCCESS; 
     
    258282    PJ_UNUSED_ARG(codec); 
    259283    /* Nothing to do */ 
     284    return PJ_SUCCESS; 
     285} 
     286 
     287static pj_status_t  g711_get_frames(pjmedia_codec *codec, 
     288                                    void *pkt, 
     289                                    pj_size_t pkt_size, 
     290                                    unsigned *frame_cnt, 
     291                                    pjmedia_frame frames[]) 
     292{ 
     293    unsigned count = 0; 
     294 
     295    PJ_UNUSED_ARG(codec); 
     296    PJ_ASSERT_RETURN(frame_cnt, PJ_EINVAL); 
     297 
     298    while (pkt_size >= 160 && count < *frame_cnt) { 
     299        frames[0].type = PJMEDIA_FRAME_TYPE_AUDIO; 
     300        frames[0].buf = pkt; 
     301        frames[0].size = 160; 
     302 
     303        pkt = ((char*)pkt) + 160; 
     304        pkt_size -= 160; 
     305 
     306        ++count; 
     307    } 
     308 
     309    *frame_cnt = count; 
    260310    return PJ_SUCCESS; 
    261311} 
Note: See TracChangeset for help on using the changeset viewer.