Ignore:
Timestamp:
May 19, 2006 3:58:13 PM (18 years ago)
Author:
bennylp
Message:

Install VAD in g711, gsm, and speex, and add the DTX support in stream.c. Also changed the way the silence detector works, and changed default speex quality/complexity to 10

File:
1 edited

Legend:

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

    r438 r457  
    2525#include <pjmedia/port.h> 
    2626#include <pjmedia/plc.h> 
     27#include <pjmedia/silencedet.h> 
    2728#include <pj/pool.h> 
    2829#include <pj/string.h> 
     
    122123struct g711_private 
    123124{ 
    124     unsigned        pt; 
    125     pj_bool_t       plc_enabled; 
    126     pjmedia_plc    *plc; 
     125    unsigned             pt; 
     126    pj_bool_t            plc_enabled; 
     127    pjmedia_plc         *plc; 
     128    pj_bool_t            vad_enabled; 
     129    pjmedia_silence_det *vad; 
    127130}; 
    128131 
     
    251254    attr->setting.plc = 1; 
    252255 
    253     /* Default all flag bits disabled. */ 
     256    /* Enable VAD by default. */ 
     257    attr->setting.vad = 1; 
     258 
     259    /* Default all other flag bits disabled. */ 
    254260 
    255261    return PJ_SUCCESS; 
     
    303309 
    304310        codec = pj_pool_alloc(g711_factory.pool, sizeof(pjmedia_codec)); 
    305         codec_priv = pj_pool_alloc(g711_factory.pool,  
    306                                    sizeof(struct g711_private)); 
     311        codec_priv = pj_pool_zalloc(g711_factory.pool,  
     312                                    sizeof(struct g711_private)); 
    307313        if (!codec || !codec_priv) { 
    308314            pj_mutex_unlock(g711_factory.mutex); 
     
    321327        } 
    322328 
     329        /* Create VAD */ 
     330        status = pjmedia_silence_det_create(g711_factory.pool, 
     331                                            8000, 80, 
     332                                            &codec_priv->vad); 
     333        if (status != PJ_SUCCESS) { 
     334            pj_mutex_unlock(g711_factory.mutex); 
     335            return status; 
     336        } 
     337 
    323338        codec->factory = factory; 
    324339        codec->op = &g711_op; 
     
    379394    priv->pt = attr->info.pt; 
    380395    priv->plc_enabled = (attr->setting.plc != 0); 
     396    priv->vad_enabled = (attr->setting.vad != 0); 
    381397    return PJ_SUCCESS; 
    382398} 
     
    429445    if (output_buf_len < input->size / 2) 
    430446        return PJMEDIA_CODEC_EFRMTOOSHORT; 
     447 
     448    /* Detect silence if VAD is enabled */ 
     449    if (priv->vad_enabled) { 
     450        pj_bool_t is_silence; 
     451 
     452        is_silence = pjmedia_silence_det_detect(priv->vad, input->buf,  
     453                                                input->size / 2, NULL); 
     454        if (is_silence) { 
     455            output->type = PJMEDIA_FRAME_TYPE_NONE; 
     456            output->buf = NULL; 
     457            output->size = 0; 
     458            output->timestamp.u64 = input->timestamp.u64; 
     459            return PJ_SUCCESS; 
     460        } 
     461    } 
    431462 
    432463    /* Encode */ 
Note: See TracChangeset for help on using the changeset viewer.