Changeset 2914

Show
Ignore:
Timestamp:
11/10/99 18:00:40 (15 years ago)
Author:
ucacoxh
Message:
  • Revised skew adaptation. Now compares transit time in use with transit average, instead of monitoring playout buffer length which is tainted by packet losses.
  • Playout variable now refers to playout offset only. Formerly included difference between sources time and our time too.
Location:
rat/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • rat/trunk/MODS

    r2913 r2914  
    922922        - Tuples for mbus command switches in mbus_{control,engine,ui}. 
    923923        * 2 November 1999 
    924         - Added echo suppression back, it fell out of code base at some point. 
     924 
     925v4.1.2  - Added echo suppression back, it fell out of code base at some point. 
    925926        - Fix ui sending input and output gain values before it's got values 
    926927          from audio engine.  Was happening because scale widget invokes  
     
    930931        - Add back default port 5004. 
    931932        - Fix luigi_audio_drain to reset, sync, and trigger reading. 
    932         - Moved packet reception handling from rtp_callback to source_add_packet. 
     933        - Moved packet reception handling from rtp_callback to  
     934          source_add_packet. 
    933935        - Changed playout buffer length estimation to use transit times and  
    934           average transit.  Previously used observations of playout buffer lengths, 
    935           but this maybe unreliable due to packet losses. 
     936          average transit.  Previously used observations of playout buffer  
     937          lengths, but this maybe unreliable due to packet losses. 
     938        - Revised skew adaptation.  Now compares transit time in use with  
     939          transit average, instead of monitoring playout buffer length which  
     940          is tainted by packet losses. 
     941        - Playout variable now refers to playout offset only. 
    936942 
    937943TODO -- They're features not bugs dammit! 
  • rat/trunk/main_engine.c

    r2912 r2914  
    8282int main(int argc, char *argv[]) 
    8383{ 
    84         u_int32          cur_time, ntp_time; 
    85         int              seed, elapsed_time, alc, scnt; 
     84        u_int32          cur_time = 0, ntp_time = 0; 
     85        int              seed, elapsed_time, alc = 0, scnt = 0; 
    8686        session_t       *sp; 
    8787        struct timeval   time; 
     
    216216                                        pdb_entry_t *e; 
    217217                                        ts_t         two_secs, delta; 
     218                                        source_check_buffering(s); 
    218219                                        source_process(sp, s, sp->ms, sp->render_3d, sp->repair, sp->cur_ts, cush_ts); 
    219220                                        source_audit(s); 
     
    292293                /* Choke CPU usage */ 
    293294                if (!audio_is_ready(sp->audio_device)) { 
    294                         audio_wait_for(sp->audio_device, 10); 
     295                        audio_wait_for(sp->audio_device, 20); 
    295296                } 
    296297        } 
  • rat/trunk/playout_calc.c

    r2913 r2914  
    8080                e->transit     = transit; 
    8181                e->avg_transit = transit; 
    82                 e->playout = ts_add(transit, e->playout); 
    8382        } else { 
    8483                ts_t delta_transit; 
     
    9392                delta_transit = ts_abs_diff(transit, e->avg_transit); 
    9493                if (ts_gt(transit, e->avg_transit)) { 
    95                         e->avg_transit = ts_add(e->avg_transit, ts_div(delta_transit,8)); 
     94                        e->avg_transit = ts_add(e->avg_transit, ts_div(delta_transit,16)); 
    9695                } else { 
    97                         e->avg_transit = ts_sub(e->avg_transit, ts_div(delta_transit,8)); 
     96                        e->avg_transit = ts_sub(e->avg_transit, ts_div(delta_transit,16)); 
    9897                } 
    99 /*                debug_msg("transit using % 6d avg % 6d\n", e->transit.ticks, e->avg_transit.ticks); */ 
    10098        } 
    101  
    102         e->last_transit = transit; 
    10399 
    104100        return e->playout; 
  • rat/trunk/source.c

    r2913 r2914  
    4343#include "auddev.h" 
    4444 
    45 #define SKEW_OFFENSES_BEFORE_CONTRACTING_BUFFER  8  
    46 #define SKEW_OFFENSES_BEFORE_EXPANDING_BUFFER    3 
    47 #define SKEW_ADAPT_THRESHOLD       1000 
     45#define SKEW_ADAPT_THRESHOLD       5000 
    4846#define SOURCE_YOUNG_AGE             20 
    4947#define SOURCE_AUDIO_HISTORY_MS    1000 
     
    7876        skew_t                      skew; 
    7977        ts_t                        skew_adjust; 
    80         int32                       skew_offenses; 
    8178        /* b/w estimation variables                                          */ 
    8279        u_int32                     byte_count; 
     
    181178static ts_t history_ts;     /* How much old audio hang onto for repair usage */ 
    182179static ts_t bw_avg_period;  /* Average period for bandwidth estimate         */ 
     180static ts_t skew_thresh;    /* Significant size b4 consider playout adapt    */ 
     181static ts_t skew_limit;     /* Upper bound, otherwise clock reset.           */ 
    183182static int  time_constants_inited = FALSE; 
     183 
    184184 
    185185static void 
     
    191191        history_ts     = ts_map32(8000, 1000);  
    192192        bw_avg_period  = ts_map32(8000, 8000); 
     193        skew_thresh    = ts_map32(8000, 160); 
     194        skew_limit     = ts_map32(8000, 2000); 
    193195        time_constants_inited = TRUE; 
    194196} 
     
    232234        psrc->channel_state    = NULL;         
    233235        psrc->skew             = SOURCE_SKEW_NONE; 
    234         psrc->skew_offenses    = 0; 
    235236 
    236237        /* Allocate channel and media buffers                                */ 
     
    555556        e = src->pdbe; 
    556557 
     558/*        if (pktbuf_get_count(src->pktbuf) < 2) { 
     559                return; 
     560        } 
     561        */ 
    557562        while(pktbuf_dequeue(src->pktbuf, &p)) { 
    558563                adjust_playout = FALSE; 
     
    625630                        adjust_playout = TRUE; 
    626631                        e->cont_toged  = 0; 
     632                } else if (e->cont_toged != 0) { 
     633                        debug_msg("cont_toged %d\n", e->cont_toged); 
    627634                } 
    628635 
     
    648655 
    649656                playout = playout_calc(sp, e->ssrc, transit, adjust_playout); 
     657                playout = ts_add(e->transit, playout); 
    650658                playout = ts_add(src_ts, playout); 
     659 
     660                e->last_transit = transit; 
    651661 
    652662                /* If last_played is valid then enough audio is buffer for   */ 
     
    736746/* adaption..., might be better if threshold adapted with how much extra     */ 
    737747/* data we have buffered...                                                  */ 
    738 #define MATCH_THRESHOLD 70 
     748#define MATCH_THRESHOLD 1000 
    739749 
    740750static ts_t 
     
    828838source_check_buffering(source *src) 
    829839{ 
    830         ts_t actual, desired, low; 
     840        ts_t actual, desired, diff; 
    831841 
    832842        if (src->age < SOURCE_YOUNG_AGE) { 
     
    838848        actual  = source_get_audio_buffered(src); 
    839849        desired = source_get_playout_delay(src); 
    840         low     = ts_sub(desired, ts_div(desired, 3)); /* low = 2 / 3 desired */ 
    841  
    842         if (ts_gt(actual, desired)) { 
    843                 /* buffer maybe longer than anticipated, src clock is faster */ 
    844                 ts_t delta, igap; 
    845                 src->skew = SOURCE_SKEW_FAST; 
    846                 delta = ts_sub(actual, desired); 
    847                 igap  = ts_map32(get_freq(src->pdbe->clock), src->pdbe->inter_pkt_gap); 
    848                 if (ts_gt(delta, igap)) { 
    849                         src->skew_offenses++; 
    850                         src->skew = SOURCE_SKEW_FAST; 
    851                         src->skew_adjust = delta; 
    852                 } 
    853         } else if (ts_gt(low, actual)) { 
    854                 /* buffer is running dry so src clock is slower */ 
    855                 src->skew        = SOURCE_SKEW_SLOW; 
    856                 src->skew_adjust = ts_sub(desired, actual); 
    857                 if (src->skew_offenses > 0) { 
    858                         /* Reset offenses for faster operation    */ 
    859                         /* We care about not going dry.  We don't */ 
    860                         /* care quite so passionately about being */ 
    861                         /* over the desired level.                */ 
    862                         src->skew_offenses = 0; 
    863                 } 
    864                 src->skew_offenses--; 
    865         } else { 
    866                 src->skew = SOURCE_SKEW_NONE; 
    867                 if (src->skew_offenses != 0) { 
    868                         /* Retreat slowly from opinion */ 
    869                         if (src->skew_offenses > 0) { 
    870                                 src->skew_offenses--; 
    871                         } else { 
    872                                 src->skew_offenses++; 
    873                         } 
    874                 } 
    875         } 
    876  
    877         return TRUE; 
     850        diff    = ts_abs_diff(actual, desired); 
     851 
     852        if (ts_gt(diff, skew_thresh) && ts_gt(skew_limit, diff)) { 
     853                src->skew_adjust = diff; 
     854                if (ts_gt(actual, desired)) { 
     855                        /* We're accumulating audio, their clock faster   */ 
     856                        src->skew = SOURCE_SKEW_FAST;  
     857                } else { 
     858                        /* We're short of audio, so their clock is slower */ 
     859                        src->skew = SOURCE_SKEW_SLOW; 
     860                } 
     861                return TRUE; 
     862        } 
     863        src->skew = SOURCE_SKEW_NONE; 
     864        return FALSE; 
    878865} 
    879866 
     
    917904        /* taken place.                                                      */ 
    918905 
    919         if (src->skew == SOURCE_SKEW_FAST && 
    920             abs((int)src->skew_offenses) >= SKEW_OFFENSES_BEFORE_CONTRACTING_BUFFER /* &&  
    921                 2*e <=  src->mean_energy */) { 
     906        if (src->skew == SOURCE_SKEW_FAST/* && 
     907                (2*e <=  src->mean_energy || e < 200) */) { 
    922908                /* source is fast so we need to bring units forward. 
    923909                 * Should only move forward at most a single unit 
     
    930916                         * that best matches dropable by signal matching. 
    931917                         */ 
    932                         src->skew_offenses = 0; 
    933918                        return SOURCE_SKEW_NONE; 
    934919                } 
     
    936921                pb_shift_forward(src->media,   adjustment); 
    937922                pb_shift_forward(src->channel, adjustment); 
    938                 src->pdbe->playout = ts_sub(src->pdbe->playout, adjustment); 
    939                 src->pdbe->transit = ts_sub(src->pdbe->transit, adjustment); 
    940                 src->last_played   = ts_sub(src->last_played, adjustment); 
    941                 src->skew_offenses = 0; 
     923                src->pdbe->transit      = ts_sub(src->pdbe->transit,      adjustment); 
     924                src->pdbe->last_transit = ts_sub(src->pdbe->last_transit, adjustment); 
     925                src->pdbe->avg_transit  = ts_sub(src->pdbe->avg_transit,  adjustment); 
    942926 
    943927                if (ts_valid(src->last_repair)) { 
     
    959943 
    960944                return SOURCE_SKEW_FAST; 
    961         } else if (src->skew == SOURCE_SKEW_SLOW &&  
    962                    abs(src->skew_offenses) >= SKEW_OFFENSES_BEFORE_EXPANDING_BUFFER) { 
     945        } else if (src->skew == SOURCE_SKEW_SLOW) { 
    963946                adjustment = ts_map32(rate, samples); 
    964947                if (ts_gt(src->skew_adjust, adjustment)) { 
    965                         adjustment = ts_map32(rate, samples * 2); 
     948                        adjustment = ts_map32(rate, samples); 
    966949                } 
    967950                pb_shift_units_back_after(src->media,   playout, adjustment); 
    968951                pb_shift_units_back_after(src->channel, playout, adjustment); 
    969                 src->pdbe->playout = ts_add(src->pdbe->playout, adjustment); 
    970                 src->pdbe->transit = ts_add(src->pdbe->transit, adjustment); 
     952                src->pdbe->transit      = ts_add(src->pdbe->transit,      adjustment); 
     953                src->pdbe->last_transit = ts_add(src->pdbe->last_transit, adjustment); 
     954                src->pdbe->avg_transit  = ts_add(src->pdbe->avg_transit,  adjustment); 
    971955 
    972956                if (ts_gt(adjustment, src->skew_adjust)) { 
     
    975959                        src->skew_adjust = ts_sub(src->skew_adjust, adjustment); 
    976960                } 
    977                  
    978                 src->skew_offenses /= 2; 
     961 
    979962/* shouldn't have to make this adjustment since we are now adjusting 
    980963 * units in future only.  
     
    984967                } 
    985968                */ 
    986                 debug_msg("Playout buffer shift back %d. *-*-*\n", adjustment.ticks); 
     969                debug_msg("Playout buffer shift back %d (%d).\n", adjustment.ticks, src->last_played.ticks); 
    987970                src->skew = SOURCE_SKEW_NONE; 
    988971                return SOURCE_SKEW_SLOW; 
     
    11251108                                hold_repair += 2; /* 1 works, but 2 is probably better */ 
    11261109                        } 
     1110                        debug_msg("Repair\n"); 
    11271111                        success = pb_iterator_get_at(src->media_pos,  
    11281112                                                     (u_char**)&md,  
     
    12601244{ 
    12611245        /* Changes in avg_transit change amount of audio buffered. */ 
    1262         return ts_sub(src->pdbe->playout, src->pdbe->avg_transit); 
     1246        ts_t delta; 
     1247        delta = ts_sub(src->pdbe->transit, src->pdbe->avg_transit); 
     1248        return ts_add(src->pdbe->playout, delta); 
    12631249} 
    12641250 
     
    12661252source_get_playout_delay (source *src) 
    12671253{ 
    1268         return ts_sub(src->pdbe->playout, src->pdbe->transit); 
     1254        return src->pdbe->playout; 
     1255        /*  return ts_sub(src->pdbe->playout, src->pdbe->transit); */ 
    12691256} 
    12701257 
  • rat/trunk/ui_audiotool.tcl

    r2903 r2914  
    13041304        frame $win.df.reception 
    13051305        global CODEC DURATION BUFFER_SIZE PLAYOUT_DELAY PCKTS_RECV PCKTS_LOST PCKTS_MISO \ 
    1306                PCKTS_DUP LOSS_FROM_ME LOSS_TO_ME JITTER JIT_TOGED 
     1306               PCKTS_DUP LOSS_FROM_ME LOSS_TO_ME JITTER JIT_TOGED BUFFER_SIZE 
    13071307        stats_add_field $win.df.reception.1 "Audio encoding: "         CODEC($ssrc) 
    13081308        stats_add_field $win.df.reception.2 "Packet duration (ms): "   DURATION($ssrc) 
    1309         stats_add_field $win.df.reception.3 "Playout delay (ms): "     PLAYOUT_DELAY($ssrc) 
     1309        stats_add_field $win.df.reception.3 "Buffered audio (ms): "     BUFFER_SIZE($ssrc) 
    13101310        stats_add_field $win.df.reception.5 "Arrival jitter (ms): "    JITTER($ssrc) 
    13111311        stats_add_field $win.df.reception.6 "Loss from me (%): "       LOSS_FROM_ME($ssrc)