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-codec/gsm.c

    r438 r457  
    2121#include <pjmedia/errno.h> 
    2222#include <pjmedia/endpoint.h> 
     23#include <pjmedia/plc.h> 
    2324#include <pjmedia/port.h> 
     25#include <pjmedia/silencedet.h> 
    2426#include <pj/assert.h> 
    2527#include <pj/pool.h> 
     
    6971                                      unsigned output_buf_len,  
    7072                                      struct pjmedia_frame *output); 
     73static pj_status_t  gsm_codec_recover(pjmedia_codec *codec, 
     74                                      unsigned output_buf_len, 
     75                                      struct pjmedia_frame *output); 
    7176 
    7277/* Definition for GSM codec operations. */ 
     
    7883    &gsm_codec_parse, 
    7984    &gsm_codec_encode, 
    80     &gsm_codec_decode 
     85    &gsm_codec_decode, 
     86    &gsm_codec_recover 
    8187}; 
    8288 
     
    101107} gsm_codec_factory; 
    102108 
     109 
    103110/* GSM codec private data. */ 
    104111struct gsm_data 
    105112{ 
    106     void    *encoder; 
    107     void    *decoder; 
     113    void                *encoder; 
     114    void                *decoder; 
     115    pj_bool_t            plc_enabled; 
     116    pjmedia_plc         *plc; 
     117    pj_bool_t            vad_enabled; 
     118    pjmedia_silence_det *vad; 
    108119}; 
    109120 
     
    240251 
    241252    attr->setting.frm_per_pkt = 1; 
    242  
    243     /* Default all flag bits disabled. */ 
     253    attr->setting.vad = 1; 
     254    attr->setting.plc = 1; 
     255 
     256    /* Default all other flag bits disabled. */ 
    244257 
    245258    return PJ_SUCCESS; 
     
    277290    pjmedia_codec *codec; 
    278291    struct gsm_data *gsm_data; 
     292    pj_status_t status; 
    279293 
    280294    PJ_ASSERT_RETURN(factory && id && p_codec, PJ_EINVAL); 
     
    298312                                  sizeof(struct gsm_data)); 
    299313        codec->codec_data = gsm_data; 
     314 
     315        /* Create PLC */ 
     316        status = pjmedia_plc_create(gsm_codec_factory.pool, 8000,  
     317                                    160, 0, &gsm_data->plc); 
     318        if (status != PJ_SUCCESS) { 
     319            pj_mutex_unlock(gsm_codec_factory.mutex); 
     320            return status; 
     321        } 
     322 
     323        /* Create silence detector */ 
     324        status = pjmedia_silence_det_create(gsm_codec_factory.pool, 
     325                                            8000, 160, 
     326                                            &gsm_data->vad); 
     327        if (status != PJ_SUCCESS) { 
     328            pj_mutex_unlock(gsm_codec_factory.mutex); 
     329            return status; 
     330        } 
    300331    } 
    301332 
     
    361392    if (!gsm_data->decoder) 
    362393        return PJMEDIA_CODEC_EFAILED; 
     394 
     395    gsm_data->vad_enabled = (attr->setting.vad != 0); 
     396    gsm_data->plc_enabled = (attr->setting.plc != 0); 
    363397 
    364398    return PJ_SUCCESS; 
     
    438472        return PJMEDIA_CODEC_EPCMTOOSHORT; 
    439473 
     474    /* Detect silence */ 
     475    if (gsm_data->vad_enabled) { 
     476        pj_bool_t is_silence; 
     477 
     478        is_silence = pjmedia_silence_det_detect(gsm_data->vad,  
     479                                                input->buf, 
     480                                                input->size / 2, 
     481                                                NULL); 
     482        if (is_silence) { 
     483            output->type = PJMEDIA_FRAME_TYPE_NONE; 
     484            output->buf = NULL; 
     485            output->size = 0; 
     486            output->timestamp.u64 = input->timestamp.u64; 
     487            return PJ_SUCCESS; 
     488        } 
     489    } 
     490 
     491    /* Encode */ 
    440492    gsm_encode(gsm_data->encoder, (short*)input->buf,  
    441493               (unsigned char*)output->buf); 
     
    473525    output->type = PJMEDIA_FRAME_TYPE_AUDIO; 
    474526 
     527    if (gsm_data->plc_enabled) 
     528        pjmedia_plc_save( gsm_data->plc, output->buf); 
     529 
     530    return PJ_SUCCESS; 
     531} 
     532 
     533 
     534/* 
     535 * Recover lost frame. 
     536 */ 
     537static pj_status_t  gsm_codec_recover(pjmedia_codec *codec, 
     538                                      unsigned output_buf_len, 
     539                                      struct pjmedia_frame *output) 
     540{ 
     541    struct gsm_data *gsm_data = codec->codec_data; 
     542 
     543    PJ_ASSERT_RETURN(gsm_data->plc_enabled, PJ_EINVALIDOP); 
     544 
     545    PJ_ASSERT_RETURN(output_buf_len >= 320, PJMEDIA_CODEC_EPCMTOOSHORT); 
     546 
     547    pjmedia_plc_generate(gsm_data->plc, output->buf); 
     548    output->size = 320; 
     549 
    475550    return PJ_SUCCESS; 
    476551} 
Note: See TracChangeset for help on using the changeset viewer.