Changeset 417


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)

Location:
pjproject/trunk/pjmedia
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/build/Makefile

    r413 r417  
    6767                        clock_thread.o codec.o conference.o endpoint.o errno.o \ 
    6868                        wav_player.o wav_writer.o g711.o jbuf.o \ 
    69                         master_port.o null_port.o port.o resample.o \ 
     69                        master_port.o null_port.o plc_common.o plc_g711.o \ 
     70                        port.o resample.o \ 
    7071                        resample_port.o rtcp.o rtp.o sdp.o sdp_cmp.o sdp_neg.o \ 
    7172                        session.o silencedet.o sound_port.o stream.o wave.o \ 
  • pjproject/trunk/pjmedia/build/pjmedia.dsp

    r411 r417  
    136136# Begin Source File 
    137137 
     138SOURCE=..\src\pjmedia\plc_common.c 
     139# End Source File 
     140# Begin Source File 
     141 
     142SOURCE=..\src\pjmedia\plc_g711.c 
     143# End Source File 
     144# Begin Source File 
     145 
    138146SOURCE=..\src\pjmedia\port.c 
    139147# End Source File 
     
    245253 
    246254SOURCE=..\include\pjmedia.h 
     255# End Source File 
     256# Begin Source File 
     257 
     258SOURCE=..\include\pjmedia\plc.h 
    247259# End Source File 
    248260# Begin Source File 
  • pjproject/trunk/pjmedia/include/pjmedia.h

    r411 r417  
    3535#include <pjmedia/master_port.h> 
    3636#include <pjmedia/null_port.h> 
     37#include <pjmedia/plc.h> 
    3738#include <pjmedia/port.h> 
    3839#include <pjmedia/resample.h> 
  • pjproject/trunk/pjmedia/include/pjmedia/config.h

    r394 r417  
    118118 
    119119 
     120/** 
     121 * G.711 Appendix I Packet Lost Concealment (PLC). 
     122 * Enabled only when floating point is enabled. 
     123 */ 
     124#ifndef PJMEDIA_HAS_G711_PLC 
     125#   define PJMEDIA_HAS_G711_PLC                 PJ_HAS_FLOATING_POINT 
     126#endif 
     127 
     128 
     129 
    120130#endif  /* __PJMEDIA_CONFIG_H__ */ 
    121131 
  • 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.