Ignore:
Timestamp:
Apr 28, 2006 2:48:02 PM (18 years ago)
Author:
bennylp
Message:

Added Packet Lost Concealment (PLC) framework, with two backend algorithms (simple replay and G.711 Appendix I)

File:
1 edited

Legend:

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

    r415 r417  
    1919#include <pjmedia/sound_port.h> 
    2020#include <pjmedia/errno.h> 
     21#include <pjmedia/plc.h> 
    2122#include <pj/assert.h> 
    2223#include <pj/log.h> 
     
    2526 
    2627 
    27 //#define SIMULATE_LOST_PCT   10 
     28//#define SIMULATE_LOST_PCT   20 
    2829 
    2930 
     
    3536}; 
    3637 
    37 #define DEFAULT_OPTIONS PJMEDIA_PLC_ENABLED 
    38  
     38//#define DEFAULT_OPTIONS       PJMEDIA_PLC_ENABLED 
     39#define DEFAULT_OPTIONS     0 
    3940 
    4041 
     
    4849    unsigned             options; 
    4950 
    50     void                *last_frame; 
    51     unsigned             last_frame_size; 
    52     unsigned             last_replay_count; 
     51    pjmedia_plc         *plc; 
    5352 
    5453    unsigned             clock_rate; 
     
    104103#endif 
    105104 
    106     /* Keep frame if PLC is enabled. */ 
    107     if (snd_port->options & PJMEDIA_PLC_ENABLED) { 
    108         /* Must have the same length as last_frame_size */ 
    109         pj_assert(frame.size == snd_port->last_frame_size); 
    110  
    111         /* Copy frame to last_frame */ 
    112         pj_memcpy(snd_port->last_frame, output, snd_port->last_frame_size); 
    113  
    114         snd_port->last_replay_count = 0; 
    115     } 
     105    if (snd_port->plc) 
     106        pjmedia_plc_save(snd_port->plc, output); 
    116107 
    117108    return PJ_SUCCESS; 
     
    119110no_frame: 
    120111 
    121     /* Replay last frame if PLC is enabled */ 
    122     if ((snd_port->options & PJMEDIA_PLC_ENABLED) && 
    123         snd_port->last_replay_count < 8)  
    124     { 
    125  
    126         /* Must have the same length as last_frame_size */ 
    127         pj_assert(size == snd_port->last_frame_size); 
    128  
    129         /* Replay last frame */ 
    130         pj_memcpy(output, snd_port->last_frame, snd_port->last_frame_size); 
    131  
    132         /* Reduce replay frame signal level to half */ 
    133         if (snd_port->bits_per_sample == 16) { 
    134             unsigned i, count; 
    135             pj_int16_t *samp; 
    136  
    137             count = snd_port->last_frame_size / 2; 
    138             samp = (pj_int16_t *) snd_port->last_frame; 
    139  
    140             for (i=0; i<count; ++i) 
    141                 samp[i] = (pj_int16_t) (samp[i] >> 2); 
    142  
    143         } 
    144  
     112    /* Apply PLC */ 
     113    if (snd_port->plc) { 
     114 
     115        pjmedia_plc_generate(snd_port->plc, output); 
    145116#ifdef SIMULATE_LOST_PCT 
    146         PJ_LOG(4,(THIS_FILE, "Frame replayed")); 
     117        PJ_LOG(4,(THIS_FILE, "Lost frame generated")); 
    147118#endif 
    148  
    149         ++snd_port->last_replay_count; 
    150  
    151     } else { 
    152  
    153         /* Just zero the frame */ 
    154         pj_memset(output, 0, size); 
    155  
    156119    } 
    157120 
     
    255218        (snd_port->options & PJMEDIA_PLC_ENABLED))  
    256219    { 
    257  
    258         snd_port->last_frame_size = snd_port->samples_per_frame * 
    259                                     snd_port->channel_count * 
    260                                     snd_port->bits_per_sample / 8; 
    261         snd_port->last_frame = pj_pool_zalloc(pool,  
    262                                               snd_port->last_frame_size); 
     220        status = pjmedia_plc_create(pool, snd_port->clock_rate,  
     221                                    snd_port->samples_per_frame *  
     222                                        snd_port->channel_count, 
     223                                    0, &snd_port->plc); 
     224        if (status != PJ_SUCCESS) 
     225            snd_port->plc = NULL; 
    263226    } 
    264227 
Note: See TracChangeset for help on using the changeset viewer.