Changeset 2503


Ignore:
Timestamp:
Mar 11, 2009 11:28:44 AM (10 years ago)
Author:
nanang
Message:
  • updated delay statistic calculations to use pj_math_stat, also added

min, avg, dev of latency into the test result

  • fixed drift report
  • updated test result calculations to use division with rounding
Location:
pjproject/branches/projects/aps-direct
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia-audiodev/audiotest.h

    r2470 r2503  
    5858 
    5959    /**  
     60     * Average inter-frame arrival time, in milliseconds  
     61     */ 
     62    unsigned avg_interval; 
     63 
     64    /**  
     65     * Standard deviation of inter-frame arrival time, in milliseconds  
     66     */ 
     67    unsigned dev_interval; 
     68 
     69    /**  
    6070     * Maximum number of frame burst  
    6171     */ 
  • pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia-audiodev/audiotest.c

    r2468 r2503  
    3131#define SKIP_DURATION       1000 
    3232 
    33 /* Max frames per sec (to calculate number of delays to keep). */ 
    34 #define MAX_FRAMES_PER_SEC  100 
    35  
    36 /* Number of frame durations to keep */ 
    37 #define MAX_DELAY_COUNTER   (((DURATION/1000)+1)*MAX_FRAMES_PER_SEC) 
    38  
     33/* Division helper */ 
     34#define DIV_ROUND_UP(a,b) (((a) + ((b) - 1)) / (b)) 
     35#define DIV_ROUND(a,b) (((a) + ((b)/2 - 1)) / (b)) 
    3936 
    4037struct stream_data 
     
    4340    pj_uint32_t     last_timestamp; 
    4441    pj_timestamp    last_called; 
    45     unsigned        counter; 
    46     unsigned        min_delay; 
    47     unsigned        max_delay; 
    48     unsigned        delay[MAX_DELAY_COUNTER]; 
     42    pj_math_stat    delay; 
    4943}; 
    5044 
     
    5246{ 
    5347    pj_pool_t                      *pool; 
    54     const pjmedia_aud_param    *param; 
     48    const pjmedia_aud_param        *param; 
    5549    pjmedia_aud_test_results       *result; 
    5650    pj_bool_t                       running; 
     
    8074 
    8175    if (strm_data->last_called.u64 == 0) { 
     76        /* Init vars. */ 
    8277        pj_get_timestamp(&strm_data->last_called); 
    83         /* Init min_delay to one frame */ 
    84         strm_data->min_delay = test_data->param->samples_per_frame * 1000000 / 
    85                                test_data->param->clock_rate; 
     78        pj_math_stat_init(&strm_data->delay); 
    8679        strm_data->first_timestamp = frame->timestamp.u32.lo; 
    87  
    88     } else if (strm_data->counter <= MAX_DELAY_COUNTER) { 
     80    } else { 
    8981        pj_timestamp now; 
    9082        unsigned delay; 
    9183 
     84        /* Calculate frame interval */ 
    9285        pj_get_timestamp(&now); 
    93          
    94         /* Calculate frame interval */ 
    9586        delay = pj_elapsed_usec(&strm_data->last_called, &now); 
    96         if (delay < strm_data->min_delay) 
    97             strm_data->min_delay = delay; 
    98         if (delay > strm_data->max_delay) 
    99             strm_data->max_delay = delay; 
    100  
    10187        strm_data->last_called = now; 
    10288 
    103         /* Save the frame interval for later calculation */ 
    104         strm_data->delay[strm_data->counter] = delay; 
    105         ++strm_data->counter; 
    106  
    107     } else { 
    108  
    109         /* No space, can't take anymore frames */ 
    110         test_data->running = 0; 
    111  
     89        /* Update frame interval statistic */ 
     90        pj_math_stat_update(&strm_data->delay, delay); 
    11291    } 
    11392 
     
    136115 
    137116    if (strm_data->last_called.u64 == 0) { 
     117        /* Init vars. */ 
    138118        pj_get_timestamp(&strm_data->last_called); 
    139         /* Init min_delay to one frame */ 
    140         strm_data->min_delay = test_data->param->samples_per_frame * 1000000 / 
    141                                test_data->param->clock_rate; 
     119        pj_math_stat_init(&strm_data->delay); 
    142120        strm_data->first_timestamp = frame->timestamp.u32.lo; 
    143  
    144     } else if (strm_data->counter <= MAX_DELAY_COUNTER) { 
     121    } else { 
    145122        pj_timestamp now; 
    146123        unsigned delay; 
    147124 
     125        /* Calculate frame interval */ 
    148126        pj_get_timestamp(&now); 
    149  
    150         /* Calculate frame interval */ 
    151127        delay = pj_elapsed_usec(&strm_data->last_called, &now); 
    152         if (delay < strm_data->min_delay) 
    153             strm_data->min_delay = delay; 
    154         if (delay > strm_data->max_delay) 
    155             strm_data->max_delay = delay; 
    156  
    157128        strm_data->last_called = now; 
    158129 
    159         /* Save the frame interval for later calculation */ 
    160         strm_data->delay[strm_data->counter] = delay; 
    161         ++strm_data->counter; 
    162  
    163     } else { 
    164  
    165         /* No space, can't take anymore frames */ 
    166         test_data->running = 0; 
    167  
     130        /* Update frame interval statistic */ 
     131        pj_math_stat_update(&strm_data->delay, delay); 
    168132    } 
    169133 
     
    188152    pjmedia_aud_stream *strm; 
    189153    struct test_data test_data; 
     154    unsigned ptime, tmp; 
    190155     
    191156    /* 
     
    256221     * Gather results 
    257222     */ 
    258     result->rec.frame_cnt = test_data.capture_data.counter; 
    259     result->rec.min_interval = test_data.capture_data.min_delay / 1000; 
    260     result->rec.max_interval = test_data.capture_data.max_delay / 1000; 
    261     result->rec.max_burst = test_data.capture_data.max_delay / 1000 / 
    262                             (param->samples_per_frame * 1000 / param->clock_rate); 
    263  
    264     result->play.frame_cnt = test_data.playback_data.counter; 
    265     result->play.min_interval = test_data.playback_data.min_delay / 1000; 
    266     result->play.max_interval = test_data.playback_data.max_delay / 1000; 
    267     result->play.max_burst = test_data.playback_data.max_delay / 1000 / 
    268                              (param->samples_per_frame * 1000 / param->clock_rate); 
     223    ptime = param->samples_per_frame * 1000 / param->clock_rate; 
     224 
     225    tmp = pj_math_stat_get_stddev(&test_data.capture_data.delay); 
     226    result->rec.frame_cnt = test_data.capture_data.delay.n; 
     227    result->rec.min_interval = DIV_ROUND(test_data.capture_data.delay.min, 1000); 
     228    result->rec.max_interval = DIV_ROUND(test_data.capture_data.delay.max, 1000); 
     229    result->rec.avg_interval = DIV_ROUND(test_data.capture_data.delay.mean, 1000); 
     230    result->rec.dev_interval = DIV_ROUND(tmp, 1000); 
     231    result->rec.max_burst    = DIV_ROUND_UP(result->rec.max_interval, ptime); 
     232 
     233    tmp = pj_math_stat_get_stddev(&test_data.playback_data.delay); 
     234    result->play.frame_cnt = test_data.playback_data.delay.n; 
     235    result->play.min_interval = DIV_ROUND(test_data.playback_data.delay.min, 1000); 
     236    result->play.max_interval = DIV_ROUND(test_data.playback_data.delay.max, 1000); 
     237    result->play.avg_interval = DIV_ROUND(test_data.capture_data.delay.mean, 1000); 
     238    result->play.dev_interval = DIV_ROUND(tmp, 1000); 
     239    result->play.max_burst    = DIV_ROUND_UP(result->play.max_interval, ptime); 
    269240 
    270241    /* Check drifting */ 
  • pjproject/branches/projects/aps-direct/pjsip-apps/src/samples/auddemo.c

    r2468 r2503  
    193193            PJ_LOG(1,(THIS_FILE, "Error: no frames captured!")); 
    194194        } else { 
    195             PJ_LOG(3,(THIS_FILE, "  %-20s: max interval=%u, burst=%u", 
     195            PJ_LOG(3,(THIS_FILE, "  %-20s: interval (min/max/avg/dev)=%u/%u/%u/%u, burst=%u", 
    196196                      "Recording result", 
     197                      result.rec.min_interval, 
    197198                      result.rec.max_interval, 
     199                      result.rec.avg_interval, 
     200                      result.rec.dev_interval, 
    198201                      result.rec.max_burst)); 
    199202        } 
     
    204207            PJ_LOG(1,(THIS_FILE, "Error: no playback!")); 
    205208        } else { 
    206             PJ_LOG(3,(THIS_FILE, "  %-20s: max interval=%u, burst=%u", 
     209            PJ_LOG(3,(THIS_FILE, "  %-20s: interval (min/max/avg/dev)=%u/%u/%u/%u, burst=%u", 
    207210                      "Playback result", 
     211                      result.play.min_interval, 
    208212                      result.play.max_interval, 
     213                      result.play.avg_interval, 
     214                      result.play.dev_interval, 
    209215                      result.play.max_burst)); 
    210216        } 
     
    212218 
    213219    if (dir==PJMEDIA_DIR_CAPTURE_PLAYBACK) { 
    214         if (result.rec_drift_per_sec) { 
     220        if (result.rec_drift_per_sec == 0) { 
    215221            PJ_LOG(3,(THIS_FILE, " No clock drift detected")); 
    216222        } else { 
Note: See TracChangeset for help on using the changeset viewer.