Ignore:
Timestamp:
Feb 8, 2006 10:43:39 PM (18 years ago)
Author:
bennylp
Message:

Finished new pjmedia rewrite

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/codec.c

    r121 r159  
    1818 */ 
    1919#include <pjmedia/codec.h> 
     20#include <pjmedia/errno.h> 
    2021#include <pj/pool.h> 
    2122#include <pj/string.h> 
     
    2526#define THIS_FILE   "codec.c" 
    2627 
    27 static void enum_all_codecs (pj_codec_mgr *cm) 
     28/* 
     29 * Reinitialize array of supported codecs. 
     30 */ 
     31static void enum_all_codecs (pjmedia_codec_mgr *mgr) 
    2832{ 
    29     pj_codec_factory *cf; 
     33    pjmedia_codec_factory *factory; 
    3034 
    31     cf = cm->factory_list.next; 
    32     cm->codec_cnt = 0; 
    33     while (cf != &cm->factory_list) { 
    34         pj_codec_id temp[PJ_CODEC_MGR_MAX_CODECS]; 
    35         int i, cnt; 
     35    mgr->codec_cnt = 0; 
    3636 
    37         cnt = cf->op->enum_codecs (cf, PJ_CODEC_MGR_MAX_CODECS, temp); 
    38         if (cnt > PJ_CODEC_MGR_MAX_CODECS) { 
    39             pj_assert(0); 
    40             PJ_LOG(4, (THIS_FILE, "Too many codecs reported by factory")); 
    41             cnt = PJ_CODEC_MGR_MAX_CODECS; 
    42         } 
     37    factory = mgr->factory_list.next; 
     38    while (factory != &mgr->factory_list) { 
     39        unsigned count; 
     40        pj_status_t status; 
    4341 
    44         for (i=0; i<cnt && cm->codec_cnt < PJ_CODEC_MGR_MAX_CODECS; ++i) { 
    45             cm->codecs[cm->codec_cnt++] = temp[i]; 
    46         } 
     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; 
    4747 
    48         cf = cf->next; 
     48        factory = factory->next; 
    4949    } 
    5050} 
    5151 
    52 PJ_DEF(pj_status_t) pj_codec_mgr_init (pj_codec_mgr *mgr) 
     52/* 
     53 * Initialize codec manager. 
     54 */ 
     55PJ_DEF(pj_status_t) pjmedia_codec_mgr_init (pjmedia_codec_mgr *mgr) 
    5356{ 
     57    PJ_ASSERT_RETURN(mgr, PJ_EINVAL); 
     58 
    5459    pj_list_init (&mgr->factory_list); 
    5560    mgr->codec_cnt = 0; 
    56     return 0; 
     61 
     62    return PJ_SUCCESS; 
    5763} 
    5864 
    59 PJ_DEF(pj_status_t) pj_codec_mgr_register_factory (pj_codec_mgr *mgr, 
    60                                                    pj_codec_factory *factory) 
     65/* 
     66 * Register a codec factory. 
     67 */ 
     68PJ_DEF(pj_status_t)  
     69pjmedia_codec_mgr_register_factory( pjmedia_codec_mgr *mgr, 
     70                                    pjmedia_codec_factory *factory) 
    6171{ 
    62     pj_list_insert_before (&mgr->factory_list, factory); 
     72    PJ_ASSERT_RETURN(mgr && factory, PJ_EINVAL); 
     73 
     74    pj_list_push_back(&mgr->factory_list, factory); 
    6375    enum_all_codecs (mgr); 
    64     return 0; 
     76 
     77    return PJ_SUCCESS; 
    6578} 
    6679 
    67 PJ_DEF(void) pj_codec_mgr_unregister_factory (pj_codec_mgr *mgr, pj_codec_factory *factory) 
     80/* 
     81 * Unregister a codec factory. 
     82 */ 
     83PJ_DEF(pj_status_t)  
     84pjmedia_codec_mgr_unregister_factory(pjmedia_codec_mgr *mgr,  
     85                                     pjmedia_codec_factory *factory) 
    6886{ 
    69     PJ_UNUSED_ARG(mgr); 
     87 
     88    PJ_ASSERT_RETURN(mgr && factory, PJ_EINVAL); 
     89 
     90    /* Factory must be registered. */ 
     91    PJ_ASSERT_RETURN(pj_list_find_node(&mgr->factory_list, factory)==factory, 
     92                     PJ_ENOTFOUND); 
     93 
     94 
    7095    pj_list_erase(factory); 
    7196    enum_all_codecs (mgr); 
     97 
     98    return PJ_SUCCESS; 
    7299} 
    73100 
    74 PJ_DEF(unsigned) 
    75 pj_codec_mgr_enum_codecs (pj_codec_mgr *mgr, unsigned count, const pj_codec_id *codecs[]) 
     101/* 
     102 * Enum all codecs. 
     103 */ 
     104PJ_DEF(pj_status_t) 
     105pjmedia_codec_mgr_enum_codecs(pjmedia_codec_mgr *mgr,  
     106                              unsigned *count,  
     107                              pjmedia_codec_info codecs[]) 
    76108{ 
    77     unsigned i; 
     109    PJ_ASSERT_RETURN(mgr && count && codecs, PJ_EINVAL); 
    78110 
    79     if (count > mgr->codec_cnt) 
    80         count = mgr->codec_cnt; 
     111    if (*count > mgr->codec_cnt) 
     112        *count = mgr->codec_cnt; 
     113     
     114    pj_memcpy(codecs, mgr->codecs, *count * sizeof(pjmedia_codec_info)); 
    81115 
    82     for (i=0; i<count; ++i) 
    83         codecs[i] = &mgr->codecs[i]; 
    84  
    85     return mgr->codec_cnt; 
     116    return PJ_SUCCESS; 
    86117} 
    87118 
    88 PJ_DEF(pj_codec*) pj_codec_mgr_alloc_codec (pj_codec_mgr *mgr, const struct pj_codec_id *id) 
     119/* 
     120 * Allocate one codec. 
     121 */ 
     122PJ_DEF(pj_status_t) pjmedia_codec_mgr_alloc_codec(pjmedia_codec_mgr *mgr,  
     123                                                  const pjmedia_codec_info *info, 
     124                                                  pjmedia_codec **p_codec) 
    89125{ 
    90     pj_codec_factory *factory = mgr->factory_list.next; 
     126    pjmedia_codec_factory *factory; 
     127    pj_status_t status; 
     128 
     129    PJ_ASSERT_RETURN(mgr && info && p_codec, PJ_EINVAL); 
     130 
     131    *p_codec = NULL; 
     132 
     133    factory = mgr->factory_list.next; 
    91134    while (factory != &mgr->factory_list) { 
    92         if ( (*factory->op->match_id)(factory, id) == 0 ) { 
    93             pj_codec *codec = (*factory->op->alloc_codec)(factory, id); 
    94             if (codec != NULL) 
    95                 return codec; 
     135 
     136        if ( (*factory->op->test_alloc)(factory, info) == PJ_SUCCESS ) { 
     137 
     138            status = (*factory->op->alloc_codec)(factory, info, p_codec); 
     139            if (status == PJ_SUCCESS) 
     140                return PJ_SUCCESS; 
     141 
    96142        } 
     143 
    97144        factory = factory->next; 
    98145    } 
    99     return NULL; 
     146 
     147 
     148    return PJMEDIA_CODEC_EUNSUP; 
    100149} 
    101150 
    102 PJ_DEF(void) pj_codec_mgr_dealloc_codec (pj_codec_mgr *mgr, pj_codec *codec) 
     151/* 
     152 * Dealloc codec. 
     153 */ 
     154PJ_DEF(pj_status_t) pjmedia_codec_mgr_dealloc_codec(pjmedia_codec_mgr *mgr,  
     155                                                    pjmedia_codec *codec) 
    103156{ 
    104     PJ_UNUSED_ARG(mgr); 
    105     (*codec->factory->op->dealloc_codec)(codec->factory, codec); 
     157    PJ_ASSERT_RETURN(mgr && codec, PJ_EINVAL); 
     158 
     159    return (*codec->factory->op->dealloc_codec)(codec->factory, codec); 
    106160} 
    107161 
Note: See TracChangeset for help on using the changeset viewer.