Ignore:
Timestamp:
Aug 4, 2006 6:27:19 PM (18 years ago)
Author:
bennylp
Message:

More work on the AEC (including changes in PJSUA), embed the AEC in sound_port, reduce DirectSound? buffer from 32 to 16, and fixed ARM compilation for MSVC WinCE target.

File:
1 edited

Legend:

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

    r646 r648  
    3535 
    3636//#define SIMULATE_LOST_PCT   20 
    37 #define AEC_TAIL    500     /* in ms */ 
     37#define AEC_TAIL    128     /* default AEC length in ms */ 
    3838 
    3939#define THIS_FILE           "sound_port.c" 
     
    5858 
    5959    pjmedia_aec         *aec; 
     60    unsigned             aec_tail_len; 
    6061    pjmedia_plc         *plc; 
    6162 
     
    136137 
    137138 
    138     if (snd_port->aec) { 
    139         pjmedia_aec_playback(snd_port->aec, output); 
    140     } 
    141  
    142139    return PJ_SUCCESS; 
    143140} 
     
    156153    pjmedia_port *port; 
    157154    pjmedia_frame frame; 
    158  
    159     /* Cancel echo */ 
    160     if (snd_port->aec) { 
    161         pjmedia_aec_capture(snd_port->aec, input, 0); 
    162     } 
    163155 
    164156    /* We're risking accessing the port without holding any mutex. 
     
    171163    if (port == NULL) 
    172164        return PJ_SUCCESS; 
     165 
     166    /* Cancel echo */ 
     167    if (snd_port->aec) { 
     168        pjmedia_aec_capture(snd_port->aec, input, 0); 
     169    } 
    173170 
    174171    frame.buf = (void*)input; 
     
    247244                                        snd_port->channel_count, 
    248245                                    0, &snd_port->plc); 
    249         if (status != PJ_SUCCESS) 
     246        if (status != PJ_SUCCESS) { 
     247            PJ_LOG(4,(THIS_FILE, "Unable to create PLC")); 
    250248            snd_port->plc = NULL; 
     249        } 
    251250    } 
    252251 
    253252    /* Create AEC only when direction is full duplex */ 
    254253    if (snd_port->dir == PJMEDIA_DIR_CAPTURE_PLAYBACK) { 
    255         status = pjmedia_aec_create(pool, snd_port->clock_rate,  
    256                                     snd_port->samples_per_frame,  
    257                                     snd_port->clock_rate * AEC_TAIL / 1000, 
    258                                     0, &snd_port->aec); 
    259         if (status != PJ_SUCCESS) 
     254        status = pjmedia_snd_port_set_aec(snd_port, pool, AEC_TAIL); 
     255        if (status != PJ_SUCCESS) { 
     256            PJ_LOG(4,(THIS_FILE, "Unable to create AEC")); 
    260257            snd_port->aec = NULL; 
     258        } 
    261259    } 
    262260 
     
    433431 
    434432/* 
     433 * Enable AEC 
     434 */ 
     435PJ_DEF(pj_status_t) pjmedia_snd_port_set_aec( pjmedia_snd_port *snd_port, 
     436                                              pj_pool_t *pool, 
     437                                              unsigned tail_ms) 
     438{ 
     439    pj_status_t status; 
     440 
     441    /* Sound must be opened in full-duplex mode */ 
     442    PJ_ASSERT_RETURN(snd_port &&  
     443                     snd_port->dir == PJMEDIA_DIR_CAPTURE_PLAYBACK, 
     444                     PJ_EINVALIDOP); 
     445 
     446    /* Destroy AEC */ 
     447    if (snd_port->aec) { 
     448        pjmedia_aec_destroy(snd_port->aec); 
     449        snd_port->aec = NULL; 
     450    } 
     451 
     452    snd_port->aec_tail_len = tail_ms; 
     453 
     454    if (tail_ms != 0) { 
     455        status = pjmedia_aec_create(pool, snd_port->clock_rate,  
     456                                    snd_port->samples_per_frame,  
     457                                    snd_port->clock_rate * tail_ms / 1000, 
     458                                    0, &snd_port->aec); 
     459        if (status != PJ_SUCCESS) 
     460            snd_port->aec = NULL; 
     461    } else { 
     462        status = PJ_SUCCESS; 
     463    } 
     464 
     465    return status; 
     466} 
     467 
     468 
     469/* Get AEC tail length */ 
     470PJ_DEF(pj_status_t) pjmedia_snd_port_get_aec_tail( pjmedia_snd_port *snd_port, 
     471                                                   unsigned *p_length) 
     472{ 
     473    PJ_ASSERT_RETURN(snd_port && p_length, PJ_EINVAL); 
     474    *p_length =  snd_port->aec ? snd_port->aec_tail_len : 0; 
     475    return PJ_SUCCESS; 
     476} 
     477 
     478 
     479 
     480/* 
    435481 * Connect a port. 
    436482 */ 
Note: See TracChangeset for help on using the changeset viewer.