Changeset 1985


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

Location:
pjproject/trunk/pjmedia
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/include/pjmedia/codec.h

    r1983 r1985  
    254254       unsigned    channel_cnt;         /**< Channel count.                 */ 
    255255       pj_uint32_t avg_bps;             /**< Average bandwidth in bits/sec  */ 
     256       pj_uint32_t max_bps;             /**< Maximum bandwidth in bits/sec  */ 
    256257       pj_uint16_t frm_ptime;           /**< Decoder frame ptime in msec.   */ 
    257258       pj_uint16_t enc_ptime;           /**< Encoder ptime, or zero if it's 
  • pjproject/trunk/pjmedia/src/pjmedia-codec/g722.c

    r1983 r1985  
    271271    attr->info.channel_cnt = 1; 
    272272    attr->info.avg_bps = 64000; 
     273    attr->info.max_bps = 64000; 
    273274    attr->info.pcm_bits_per_sample = 16; 
    274275    attr->info.frm_ptime = PTIME; 
  • pjproject/trunk/pjmedia/src/pjmedia-codec/gsm.c

    r1983 r1985  
    265265    attr->info.channel_cnt = 1; 
    266266    attr->info.avg_bps = 13200; 
     267    attr->info.max_bps = 13200; 
    267268    attr->info.pcm_bits_per_sample = 16; 
    268269    attr->info.frm_ptime = 20; 
  • pjproject/trunk/pjmedia/src/pjmedia-codec/ilbc.c

    r1983 r1985  
    265265    attr->info.channel_cnt = 1; 
    266266    attr->info.avg_bps = ilbc_factory.bps; 
     267    attr->info.max_bps = 15200; 
    267268    attr->info.pcm_bits_per_sample = 16; 
    268269    attr->info.frm_ptime = (short)ilbc_factory.mode; 
  • pjproject/trunk/pjmedia/src/pjmedia-codec/l16.c

    r1983 r1985  
    243243    attr->info.channel_cnt = id->channel_cnt; 
    244244    attr->info.avg_bps = id->clock_rate * id->channel_cnt * 16; 
     245    attr->info.max_bps = attr->info.avg_bps; 
    245246    attr->info.pcm_bits_per_sample = 16; 
    246247 
  • 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 
  • pjproject/trunk/pjmedia/src/pjmedia/codec.c

    r1417 r1985  
    386386 
    387387            status = (*factory->op->default_attr)(factory, info, param); 
    388             if (status == PJ_SUCCESS) 
     388            if (status == PJ_SUCCESS) { 
     389                /* Check for invalid max_bps. */ 
     390                if (param->info.max_bps < param->info.avg_bps) 
     391                    param->info.max_bps = param->info.avg_bps; 
     392 
    389393                return PJ_SUCCESS; 
     394            } 
    390395 
    391396        } 
  • pjproject/trunk/pjmedia/src/pjmedia/g711.c

    r1929 r1985  
    250250    attr->info.channel_cnt = 1; 
    251251    attr->info.avg_bps = G711_BPS; 
     252    attr->info.max_bps = G711_BPS; 
    252253    attr->info.pcm_bits_per_sample = 16; 
    253254    attr->info.frm_ptime = PTIME; 
  • pjproject/trunk/pjmedia/src/pjmedia/stream.c

    r1983 r1985  
    12641264 
    12651265    channel->out_pkt_size = sizeof(pjmedia_rtp_hdr) +  
    1266                             stream->codec_param.info.avg_bps/8 *  
     1266                            stream->codec_param.info.max_bps *  
    12671267                            PJMEDIA_MAX_FRAME_DURATION_MS /  
    1268                             1000; 
     1268                            8 / 1000; 
    12691269 
    12701270    if (channel->out_pkt_size > PJMEDIA_MAX_MTU) 
     
    13741374    } 
    13751375 
     1376    /* Check for invalid max_bps. */ 
     1377    if (stream->codec_param.info.max_bps < stream->codec_param.info.avg_bps) 
     1378        stream->codec_param.info.max_bps = stream->codec_param.info.avg_bps; 
     1379 
    13761380    /* Check for invalid frame per packet. */ 
    13771381    if (stream->codec_param.setting.frm_per_pkt < 1) 
     
    13851389                                          stream->codec_param.setting.frm_per_pkt / 
    13861390                                          1000; 
    1387     stream->port.info.bytes_per_frame = stream->codec_param.info.avg_bps/8 *  
     1391    stream->port.info.bytes_per_frame = stream->codec_param.info.max_bps *  
    13881392                                        stream->codec_param.info.frm_ptime * 
    13891393                                        stream->codec_param.setting.frm_per_pkt / 
    1390                                         1000; 
     1394                                        8 / 1000; 
     1395    if ((stream->codec_param.info.max_bps * stream->codec_param.info.frm_ptime * 
     1396        stream->codec_param.setting.frm_per_pkt) % 8000 != 0) 
     1397    { 
     1398        ++stream->port.info.bytes_per_frame; 
     1399    } 
    13911400 
    13921401    /* Open the codec: */ 
     
    14421451    } 
    14431452 
    1444     /* Get the frame size: */ 
    1445  
    1446     stream->frame_size = ((stream->codec_param.info.avg_bps + 7) / 8) *  
    1447                           stream->codec_param.info.frm_ptime / 1000; 
    1448  
     1453    /* Get the frame size */ 
     1454    stream->frame_size = stream->codec_param.info.max_bps *  
     1455                         stream->codec_param.info.frm_ptime / 8 / 1000; 
     1456    if ((stream->codec_param.info.max_bps * stream->codec_param.info.frm_ptime)  
     1457        % 8000 != 0) 
     1458    { 
     1459        ++stream->frame_size; 
     1460    } 
    14491461 
    14501462#if defined(PJMEDIA_HANDLE_G722_MPEG_BUG) && (PJMEDIA_HANDLE_G722_MPEG_BUG!=0) 
Note: See TracChangeset for help on using the changeset viewer.