Changeset 3078 for pjproject/trunk
- Timestamp:
- Jan 27, 2010 11:48:31 AM (15 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/codec.h
r2875 r3078 29 29 #include <pjmedia/port.h> 30 30 #include <pj/list.h> 31 #include <pj/pool.h> 31 32 32 33 PJ_BEGIN_DECL … … 245 246 * Structure of codec specific parameters which contains name=value pairs. 246 247 * The codec specific parameters are to be used with SDP according to 247 * the standards (e.g: RFC 3555) .248 * the standards (e.g: RFC 3555) in SDP 'a=fmtp' attribute. 248 249 */ 249 250 typedef struct pjmedia_codec_fmtp 250 251 { 251 pj_uint8_t cnt; 252 pj_uint8_t cnt; /**< Number of parameters. */ 252 253 struct param { 253 pj_str_t name; 254 pj_str_t val; 255 } param [PJMEDIA_CODEC_MAX_FMTP_CNT]; 254 pj_str_t name; /**< Parameter name. */ 255 pj_str_t val; /**< Parameter value. */ 256 } param [PJMEDIA_CODEC_MAX_FMTP_CNT]; /**< The parameters. */ 256 257 } pjmedia_codec_fmtp; 257 258 258 259 /** 259 * Detailed codec attributes used both to configure a codec and to query 260 * the capability of codec factories. 260 * Detailed codec attributes used in configuring a codec and in querying 261 * the capability of codec factories. Default attributes of any codecs could 262 * be queried using #pjmedia_codec_mgr_get_default_param() and modified 263 * using #pjmedia_codec_mgr_set_default_param(). 264 * 265 * Please note that codec parameter also contains SDP specific setting, 266 * #dec_fmtp and #enc_fmtp, which may need to be set appropriately based on 267 * the effective setting. See each codec documentation for more detail. 261 268 */ 262 269 typedef struct pjmedia_codec_param … … 629 636 630 637 638 /** 639 * Opaque declaration of default codecs parameters. 640 */ 641 typedef struct pjmedia_codec_default_param pjmedia_codec_default_param; 642 631 643 /** 632 644 * Codec manager maintains array of these structs for each supported … … 639 651 pjmedia_codec_priority prio; /**< Priority. */ 640 652 pjmedia_codec_factory *factory; /**< The factory. */ 653 pjmedia_codec_default_param *param; /**< Default codecs 654 parameters. */ 641 655 }; 642 656 … … 649 663 typedef struct pjmedia_codec_mgr 650 664 { 665 /** Media endpoint instance. */ 666 pj_pool_factory *pf; 667 668 /** Codec manager pool. */ 669 pj_pool_t *pool; 670 671 /** Codec manager mutex. */ 672 pj_mutex_t *mutex; 673 651 674 /** List of codec factories registered to codec manager. */ 652 pjmedia_codec_factory factory_list;653 654 /** Number of supported code sc. */655 unsigned codec_cnt;675 pjmedia_codec_factory factory_list; 676 677 /** Number of supported codecs. */ 678 unsigned codec_cnt; 656 679 657 680 /** Array of codec descriptor. */ 658 struct pjmedia_codec_desc codec_desc[PJMEDIA_CODEC_MGR_MAX_CODECS];681 struct pjmedia_codec_desc codec_desc[PJMEDIA_CODEC_MGR_MAX_CODECS]; 659 682 660 683 } pjmedia_codec_mgr; … … 667 690 * 668 691 * @param mgr Codec manager instance. 692 * @param pf Pool factory instance. 669 693 * 670 694 * @return PJ_SUCCESS on success. 671 695 */ 672 PJ_DECL(pj_status_t) pjmedia_codec_mgr_init(pjmedia_codec_mgr *mgr); 696 PJ_DECL(pj_status_t) pjmedia_codec_mgr_init(pjmedia_codec_mgr *mgr, 697 pj_pool_factory *pf); 698 699 700 /** 701 * Destroy codec manager. Normally this function is called by pjmedia 702 * endpoint's deinitialization code. 703 * 704 * @param mgr Codec manager instance. 705 * 706 * @return PJ_SUCCESS on success. 707 */ 708 PJ_DECL(pj_status_t) pjmedia_codec_mgr_destroy(pjmedia_codec_mgr *mgr); 673 709 674 710 … … 822 858 pjmedia_codec_param *param ); 823 859 860 861 /** 862 * Set default codec param for the specified codec info. 863 * 864 * @param mgr The codec manager instance. Application can get the 865 * instance by calling #pjmedia_endpt_get_codec_mgr(). 866 * @param info The codec info, which default parameter's is being 867 * updated. 868 * @param param The new default codec parameter. Set to NULL to reset 869 * codec parameter to library default settings. 870 * 871 * @return PJ_SUCCESS on success. 872 */ 873 PJ_DECL(pj_status_t) 874 pjmedia_codec_mgr_set_default_param( pjmedia_codec_mgr *mgr, 875 const pjmedia_codec_info *info, 876 const pjmedia_codec_param *param ); 877 878 824 879 /** 825 880 * Request the codec manager to allocate one instance of codec with the -
pjproject/trunk/pjmedia/src/pjmedia-audiodev/symb_vas_dev.cpp
r3075 r3078 492 492 break; 493 493 494 case EAMR_NB: 495 enc_fmt_if->SetBitRate(setting_.mode); 496 break; 497 494 498 default: 495 499 break; -
pjproject/trunk/pjmedia/src/pjmedia-codec/ipp_codecs.c
r3075 r3078 1196 1196 s->enc_mode, 1197 1197 codec_data->info->params.modes.bitrate)); 1198 1199 /* Return back bitrate info to application */ 1200 attr->info.avg_bps = codec_data->info->params.modes.bitrate; 1198 1201 } 1199 1202 #endif -
pjproject/trunk/pjmedia/src/pjmedia-codec/passthrough.c
r3075 r3078 25 25 #include <pj/assert.h> 26 26 #include <pj/log.h> 27 #include <pj/math.h> 27 28 #include <pj/pool.h> 28 29 #include <pj/string.h> … … 697 698 } 698 699 700 for (i = 0; i < attr->setting.enc_fmtp.cnt; ++i) { 701 /* mode-set, encoding mode is chosen based on local default mode 702 * setting: 703 * - if local default mode is included in the mode-set, use it 704 * - otherwise, find the closest mode to local default mode; 705 * if there are two closest modes, prefer to use the higher 706 * one, e.g: local default mode is 4, the mode-set param 707 * contains '2,3,5,6', then 5 will be chosen. 708 */ 709 const pj_str_t STR_FMTP_MODE_SET = {"mode-set", 8}; 710 711 if (pj_stricmp(&attr->setting.enc_fmtp.param[i].name, 712 &STR_FMTP_MODE_SET) == 0) 713 { 714 const char *p; 715 pj_size_t l; 716 pj_int8_t diff = 99; 717 718 p = pj_strbuf(&attr->setting.enc_fmtp.param[i].val); 719 l = pj_strlen(&attr->setting.enc_fmtp.param[i].val); 720 721 while (l--) { 722 if ((desc->pt==PJMEDIA_RTP_PT_AMR && *p>='0' && *p<='7') || 723 (desc->pt==PJMEDIA_RTP_PT_AMRWB && *p>='0' && *p<='8')) 724 { 725 pj_int8_t tmp = (pj_int8_t)(*p - '0' - enc_mode); 726 727 if (PJ_ABS(diff) > PJ_ABS(tmp) || 728 (PJ_ABS(diff) == PJ_ABS(tmp) && tmp > diff)) 729 { 730 diff = tmp; 731 if (diff == 0) break; 732 } 733 } 734 ++p; 735 } 736 737 if (diff == 99) 738 return PJMEDIA_CODEC_EFAILED; 739 740 enc_mode = (pj_int8_t)(enc_mode + diff); 741 742 break; 743 } 744 } 745 699 746 s = PJ_POOL_ZALLOC_T(pool, amr_settings_t); 700 747 codec_data->codec_setting = s; 701 748 702 s->enc_mode = pjmedia_codec_amr_get_mode(desc->def_bitrate);749 s->enc_mode = enc_mode; 703 750 if (s->enc_mode < 0) 704 751 return PJMEDIA_CODEC_EINMODE; -
pjproject/trunk/pjmedia/src/pjmedia/codec.c
r3075 r3078 23 23 #include <pj/assert.h> 24 24 #include <pj/log.h> 25 #include <pj/pool.h>26 25 #include <pj/string.h> 27 26 … … 29 28 30 29 30 31 /* Definition of default codecs parameters */ 32 struct pjmedia_codec_default_param 33 { 34 pj_pool_t *pool; 35 pjmedia_codec_param *param; 36 }; 31 37 32 38 … … 38 44 * Initialize codec manager. 39 45 */ 40 PJ_DEF(pj_status_t) pjmedia_codec_mgr_init (pjmedia_codec_mgr *mgr) 41 { 42 PJ_ASSERT_RETURN(mgr, PJ_EINVAL); 43 46 PJ_DEF(pj_status_t) pjmedia_codec_mgr_init (pjmedia_codec_mgr *mgr, 47 pj_pool_factory *pf) 48 { 49 pj_status_t status; 50 51 PJ_ASSERT_RETURN(mgr && pf, PJ_EINVAL); 52 53 /* Init codec manager */ 54 pj_bzero(mgr, sizeof(pjmedia_codec_mgr)); 55 mgr->pf = pf; 44 56 pj_list_init (&mgr->factory_list); 45 57 mgr->codec_cnt = 0; 58 59 /* Create pool */ 60 mgr->pool = pj_pool_create(mgr->pf, "codec-mgr", 256, 256, NULL); 61 62 /* Create mutex */ 63 status = pj_mutex_create_recursive(mgr->pool, "codec-mgr", &mgr->mutex); 64 if (status != PJ_SUCCESS) 65 return status; 66 67 return PJ_SUCCESS; 68 } 69 70 /* 71 * Initialize codec manager. 72 */ 73 PJ_DEF(pj_status_t) pjmedia_codec_mgr_destroy (pjmedia_codec_mgr *mgr) 74 { 75 unsigned i; 76 77 PJ_ASSERT_RETURN(mgr, PJ_EINVAL); 78 79 /* Cleanup all pools of all codec default params */ 80 for (i=0; i<mgr->codec_cnt; ++i) { 81 if (mgr->codec_desc[i].param) { 82 pj_assert(mgr->codec_desc[i].param->pool); 83 pj_pool_release(mgr->codec_desc[i].param->pool); 84 } 85 } 86 87 /* Destroy mutex */ 88 pj_mutex_destroy(mgr->mutex); 89 90 /* Release pool */ 91 pj_pool_release(mgr->pool); 92 93 /* Just for safety, set codec manager states to zero */ 94 pj_bzero(mgr, sizeof(pjmedia_codec_mgr)); 46 95 47 96 return PJ_SUCCESS; … … 66 115 if (status != PJ_SUCCESS) 67 116 return status; 68 117 118 pj_mutex_lock(mgr->mutex); 69 119 70 120 /* Check codec count */ 71 if (count + mgr->codec_cnt > PJ_ARRAY_SIZE(mgr->codec_desc)) 121 if (count + mgr->codec_cnt > PJ_ARRAY_SIZE(mgr->codec_desc)) { 122 pj_mutex_unlock(mgr->mutex); 72 123 return PJ_ETOOMANY; 124 } 73 125 74 126 … … 93 145 pj_list_push_back(&mgr->factory_list, factory); 94 146 147 pj_mutex_unlock(mgr->mutex); 95 148 96 149 return PJ_SUCCESS; … … 108 161 PJ_ASSERT_RETURN(mgr && factory, PJ_EINVAL); 109 162 163 pj_mutex_lock(mgr->mutex); 164 110 165 /* Factory must be registered. */ 111 PJ_ASSERT_RETURN(pj_list_find_node(&mgr->factory_list, factory)==factory, 112 PJ_ENOTFOUND); 166 if (pj_list_find_node(&mgr->factory_list, factory) != factory) { 167 pj_mutex_unlock(mgr->mutex); 168 return PJ_ENOTFOUND; 169 } 113 170 114 171 /* Erase factory from the factory list */ … … 122 179 123 180 if (mgr->codec_desc[i].factory == factory) { 124 181 /* Release pool of codec default param */ 182 if (mgr->codec_desc[i].param) { 183 pj_assert(mgr->codec_desc[i].param->pool); 184 pj_pool_release(mgr->codec_desc[i].param->pool); 185 } 186 187 /* Remove the codec from array of codec descriptions */ 125 188 pj_array_erase(mgr->codec_desc, sizeof(mgr->codec_desc[0]), 126 189 mgr->codec_cnt, i); … … 132 195 } 133 196 197 pj_mutex_unlock(mgr->mutex); 134 198 135 199 return PJ_SUCCESS; … … 148 212 149 213 PJ_ASSERT_RETURN(mgr && count && codecs, PJ_EINVAL); 214 215 pj_mutex_lock(mgr->mutex); 150 216 151 217 if (*count > mgr->codec_cnt) … … 163 229 } 164 230 231 pj_mutex_unlock(mgr->mutex); 232 165 233 return PJ_SUCCESS; 166 234 } … … 178 246 PJ_ASSERT_RETURN(mgr && p_info && pt>=0 && pt < 96, PJ_EINVAL); 179 247 248 pj_mutex_lock(mgr->mutex); 249 180 250 for (i=0; i<mgr->codec_cnt; ++i) { 181 251 if (mgr->codec_desc[i].info.pt == pt) { 182 252 *p_info = &mgr->codec_desc[i].info; 253 254 pj_mutex_unlock(mgr->mutex); 183 255 return PJ_SUCCESS; 184 256 } 185 257 } 258 259 pj_mutex_unlock(mgr->mutex); 186 260 187 261 return PJMEDIA_CODEC_EUNSUP; … … 231 305 PJ_ASSERT_RETURN(mgr && codec_id && count && *count, PJ_EINVAL); 232 306 307 pj_mutex_lock(mgr->mutex); 308 233 309 for (i=0; i<mgr->codec_cnt; ++i) { 234 310 … … 250 326 251 327 } 328 329 pj_mutex_unlock(mgr->mutex); 252 330 253 331 *count = found; … … 313 391 314 392 PJ_ASSERT_RETURN(mgr && codec_id, PJ_EINVAL); 393 394 pj_mutex_lock(mgr->mutex); 315 395 316 396 /* Update the priorities of affected codecs */ … … 326 406 } 327 407 328 if (!found) 408 if (!found) { 409 pj_mutex_unlock(mgr->mutex); 329 410 return PJ_ENOTFOUND; 411 } 330 412 331 413 /* Re-sort codecs */ 332 414 sort_codecs(mgr); 333 415 416 pj_mutex_unlock(mgr->mutex); 334 417 335 418 return PJ_SUCCESS; … … 351 434 *p_codec = NULL; 352 435 436 pj_mutex_lock(mgr->mutex); 437 353 438 factory = mgr->factory_list.next; 354 439 while (factory != &mgr->factory_list) { … … 357 442 358 443 status = (*factory->op->alloc_codec)(factory, info, p_codec); 359 if (status == PJ_SUCCESS) 444 if (status == PJ_SUCCESS) { 445 pj_mutex_unlock(mgr->mutex); 360 446 return PJ_SUCCESS; 447 } 361 448 362 449 } … … 365 452 } 366 453 454 pj_mutex_unlock(mgr->mutex); 367 455 368 456 return PJMEDIA_CODEC_EUNSUP; … … 379 467 pjmedia_codec_factory *factory; 380 468 pj_status_t status; 469 pjmedia_codec_id codec_id; 470 struct pjmedia_codec_desc *codec_desc = NULL; 471 unsigned i; 381 472 382 473 PJ_ASSERT_RETURN(mgr && info && param, PJ_EINVAL); 383 474 475 if (!pjmedia_codec_info_to_id(info, (char*)&codec_id, sizeof(codec_id))) 476 return PJ_EINVAL; 477 478 pj_mutex_lock(mgr->mutex); 479 480 /* First, lookup default param in codec desc */ 481 for (i=0; i < mgr->codec_cnt; ++i) { 482 if (pj_ansi_stricmp(codec_id, mgr->codec_desc[i].id) == 0) { 483 codec_desc = &mgr->codec_desc[i]; 484 break; 485 } 486 } 487 488 /* If we found the codec and its default param is set, return it */ 489 if (codec_desc && codec_desc->param) { 490 pj_assert(codec_desc->param->param); 491 pj_memcpy(param, codec_desc->param->param, 492 sizeof(pjmedia_codec_param)); 493 494 pj_mutex_unlock(mgr->mutex); 495 return PJ_SUCCESS; 496 } 497 498 /* Otherwise query the default param from codec factory */ 384 499 factory = mgr->factory_list.next; 385 500 while (factory != &mgr->factory_list) { … … 393 508 param->info.max_bps = param->info.avg_bps; 394 509 510 pj_mutex_unlock(mgr->mutex); 395 511 return PJ_SUCCESS; 396 512 } … … 401 517 } 402 518 519 pj_mutex_unlock(mgr->mutex); 520 403 521 404 522 return PJMEDIA_CODEC_EUNSUP; 523 } 524 525 526 /* 527 * Set default codec parameter. 528 */ 529 PJ_DEF(pj_status_t) pjmedia_codec_mgr_set_default_param( 530 pjmedia_codec_mgr *mgr, 531 const pjmedia_codec_info *info, 532 const pjmedia_codec_param *param ) 533 { 534 unsigned i; 535 pjmedia_codec_id codec_id; 536 pj_pool_t *pool; 537 struct pjmedia_codec_desc *codec_desc = NULL; 538 pjmedia_codec_default_param *p; 539 540 PJ_ASSERT_RETURN(mgr && info, PJ_EINVAL); 541 542 if (!pjmedia_codec_info_to_id(info, (char*)&codec_id, sizeof(codec_id))) 543 return PJ_EINVAL; 544 545 pj_mutex_lock(mgr->mutex); 546 547 /* Lookup codec desc */ 548 for (i=0; i < mgr->codec_cnt; ++i) { 549 if (pj_ansi_stricmp(codec_id, mgr->codec_desc[i].id) == 0) { 550 codec_desc = &mgr->codec_desc[i]; 551 break; 552 } 553 } 554 555 /* Codec not found */ 556 if (!codec_desc) { 557 pj_mutex_unlock(mgr->mutex); 558 return PJMEDIA_CODEC_EUNSUP; 559 } 560 561 /* If codec param is previously set, release codec param pool */ 562 if (codec_desc->param) { 563 pj_assert(codec_desc->param->pool); 564 pj_pool_release(codec_desc->param->pool); 565 codec_desc->param = NULL; 566 } 567 568 /* When param is set to NULL, i.e: setting default codec param to library 569 * default setting, just return PJ_SUCCESS. 570 */ 571 if (NULL == param) { 572 pj_mutex_unlock(mgr->mutex); 573 return PJ_SUCCESS; 574 } 575 576 /* Instantiate and initialize codec param */ 577 pool = pj_pool_create(mgr->pf, (char*)codec_id, 256, 256, NULL); 578 codec_desc->param = PJ_POOL_ZALLOC_T(pool, pjmedia_codec_default_param); 579 p = codec_desc->param; 580 p->pool = pool; 581 p->param = PJ_POOL_ZALLOC_T(pool, pjmedia_codec_param); 582 583 /* Update codec param */ 584 pj_memcpy(p->param, param, sizeof(pjmedia_codec_param)); 585 for (i = 0; i < param->setting.dec_fmtp.cnt; ++i) { 586 pj_strdup(pool, &p->param->setting.dec_fmtp.param[i].name, 587 ¶m->setting.dec_fmtp.param[i].name); 588 pj_strdup(pool, &p->param->setting.dec_fmtp.param[i].val, 589 ¶m->setting.dec_fmtp.param[i].val); 590 } 591 for (i = 0; i < param->setting.dec_fmtp.cnt; ++i) { 592 pj_strdup(pool, &p->param->setting.dec_fmtp.param[i].name, 593 ¶m->setting.dec_fmtp.param[i].name); 594 pj_strdup(pool, &p->param->setting.dec_fmtp.param[i].val, 595 ¶m->setting.dec_fmtp.param[i].val); 596 } 597 598 pj_mutex_unlock(mgr->mutex); 599 600 return PJ_SUCCESS; 405 601 } 406 602 -
pjproject/trunk/pjmedia/src/pjmedia/endpoint.c
r3075 r3078 128 128 129 129 /* Init codec manager. */ 130 status = pjmedia_codec_mgr_init(&endpt->codec_mgr );130 status = pjmedia_codec_mgr_init(&endpt->codec_mgr, endpt->pf); 131 131 if (status != PJ_SUCCESS) 132 132 goto on_error; … … 173 173 pj_ioqueue_destroy(endpt->ioqueue); 174 174 175 pjmedia_codec_mgr_destroy(&endpt->codec_mgr); 175 176 pjmedia_aud_subsys_shutdown(); 176 177 pj_pool_release(pool); -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
r3075 r3078 4484 4484 * 4485 4485 * @param codec_id Codec ID. 4486 * @param param Codec parameter to set. 4486 * @param param Codec parameter to set. Set to NULL to reset 4487 * codec parameter to library default settings. 4487 4488 * 4488 4489 * @return PJ_SUCCESS on success, or the appropriate error code. -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
r3075 r3078 3055 3055 * Set codec parameters. 3056 3056 */ 3057 PJ_DEF(pj_status_t) pjsua_codec_set_param( const pj_str_t * id,3057 PJ_DEF(pj_status_t) pjsua_codec_set_param( const pj_str_t *codec_id, 3058 3058 const pjmedia_codec_param *param) 3059 3059 { 3060 PJ_UNUSED_ARG(id); 3061 PJ_UNUSED_ARG(param); 3062 PJ_TODO(set_codec_param); 3063 return PJ_SUCCESS; 3064 } 3060 const pjmedia_codec_info *info[2]; 3061 pjmedia_codec_mgr *codec_mgr; 3062 unsigned count = 2; 3063 pj_status_t status; 3064 3065 codec_mgr = pjmedia_endpt_get_codec_mgr(pjsua_var.med_endpt); 3066 3067 status = pjmedia_codec_mgr_find_codecs_by_id(codec_mgr, codec_id, 3068 &count, info, NULL); 3069 if (status != PJ_SUCCESS) 3070 return status; 3071 3072 /* Codec ID should be specific, except for G.722.1 */ 3073 if (count > 1 && 3074 pj_strnicmp2(codec_id, "G7221/16", 8) != 0 && 3075 pj_strnicmp2(codec_id, "G7221/32", 8) != 0) 3076 { 3077 pj_assert(!"Codec ID is not specific"); 3078 return PJ_ETOOMANY; 3079 } 3080 3081 status = pjmedia_codec_mgr_set_default_param(codec_mgr, info[0], param); 3082 return status; 3083 }
Note: See TracChangeset
for help on using the changeset viewer.