Ignore:
Timestamp:
Jun 6, 2008 12:15:23 PM (16 years ago)
Author:
nanang
Message:

Added field maximum bitrate to codec param, this is useful for providing safer frame size calculation, especially when peer's bitrate is unknown

File:
1 edited

Legend:

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

    r1983 r1985  
    122122    int              framesize;         /* Frame size for current mode.     */ 
    123123    int              bitrate;           /* Bit rate for current mode.       */ 
     124    int              max_bitrate;       /* Max bit rate for current mode.   */ 
    124125}; 
    125126 
     
    161162        return PJMEDIA_CODEC_EFAILED; 
    162163 
    163     /* We have to get maximum bitrate, so let's set maximum quality */ 
    164     tmp = 10; 
    165     speex_encoder_ctl(state, SPEEX_SET_QUALITY, &tmp); 
     164    /* Set the quality */ 
     165    if (p->quality != -1) 
     166        speex_encoder_ctl(state, SPEEX_SET_QUALITY, &p->quality); 
    166167 
    167168    /* Sampling rate. */ 
     
    179180    speex_encoder_ctl(state, SPEEX_GET_FRAME_SIZE, &p->samples_per_frame); 
    180181 
    181     /* Now get the the averate bitrate */ 
     182    /* Now get the average bitrate */ 
    182183    speex_encoder_ctl(state, SPEEX_GET_BITRATE, &p->bitrate); 
    183184 
    184185    /* Calculate framesize. */ 
    185186    p->framesize = p->bitrate * 20 / 1000; 
     187 
     188    /* Now get the maximum bitrate by using maximum quality (=10) */ 
     189    tmp = 10; 
     190    speex_encoder_ctl(state, SPEEX_SET_QUALITY, &tmp); 
     191    speex_encoder_ctl(state, SPEEX_GET_BITRATE, &p->max_bitrate); 
    186192 
    187193    /* Destroy encoder. */ 
     
    238244        ((options & PJMEDIA_SPEEX_NO_NB) == 0); 
    239245    spx_factory.speex_param[PARAM_NB].pt = PJMEDIA_RTP_PT_SPEEX_NB; 
    240     spx_factory.speex_param[PARAM_NB].mode = &speex_nb_mode; 
     246    spx_factory.speex_param[PARAM_NB].mode = speex_lib_get_mode(SPEEX_MODEID_NB); 
    241247    spx_factory.speex_param[PARAM_NB].clock_rate = 8000; 
    242248    spx_factory.speex_param[PARAM_NB].quality = quality; 
     
    246252        ((options & PJMEDIA_SPEEX_NO_WB) == 0); 
    247253    spx_factory.speex_param[PARAM_WB].pt = PJMEDIA_RTP_PT_SPEEX_WB; 
    248     spx_factory.speex_param[PARAM_WB].mode = &speex_wb_mode; 
     254    spx_factory.speex_param[PARAM_WB].mode = speex_lib_get_mode(SPEEX_MODEID_WB); 
    249255    spx_factory.speex_param[PARAM_WB].clock_rate = 16000; 
    250256    spx_factory.speex_param[PARAM_WB].quality = quality; 
     
    254260        ((options & PJMEDIA_SPEEX_NO_UWB) == 0); 
    255261    spx_factory.speex_param[PARAM_UWB].pt = PJMEDIA_RTP_PT_SPEEX_UWB; 
    256     spx_factory.speex_param[PARAM_UWB].mode = &speex_uwb_mode; 
     262    spx_factory.speex_param[PARAM_UWB].mode = speex_lib_get_mode(SPEEX_MODEID_UWB); 
    257263    spx_factory.speex_param[PARAM_UWB].clock_rate = 32000; 
    258264    spx_factory.speex_param[PARAM_UWB].quality = quality; 
     
    438444        attr->info.clock_rate = spx_factory.speex_param[PARAM_NB].clock_rate; 
    439445        attr->info.avg_bps = spx_factory.speex_param[PARAM_NB].bitrate; 
     446        attr->info.max_bps = spx_factory.speex_param[PARAM_NB].max_bitrate; 
    440447 
    441448    } else if (id->clock_rate <= 16000) { 
    442449        attr->info.clock_rate = spx_factory.speex_param[PARAM_WB].clock_rate; 
    443450        attr->info.avg_bps = spx_factory.speex_param[PARAM_WB].bitrate; 
     451        attr->info.max_bps = spx_factory.speex_param[PARAM_WB].max_bitrate; 
    444452 
    445453    } else { 
     
    447455        attr->info.clock_rate = spx_factory.speex_param[PARAM_UWB].clock_rate; 
    448456        attr->info.avg_bps = spx_factory.speex_param[PARAM_UWB].bitrate; 
     457        attr->info.max_bps = spx_factory.speex_param[PARAM_UWB].max_bitrate; 
    449458    } 
    450459 
Note: See TracChangeset for help on using the changeset viewer.