Changeset 1509 for pjproject


Ignore:
Timestamp:
Oct 20, 2007 11:58:23 PM (17 years ago)
Author:
bennylp
Message:

Fixed bug in pjmedia clock_thread.c: busy loop when clock thread is stopped

File:
1 edited

Legend:

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

    r1378 r1509  
    2828 * Implementation of media clock with OS thread. 
    2929 */ 
    30 #define MAX_JUMP    500 
    3130 
    3231struct pjmedia_clock 
     
    3837    unsigned                 samples_per_frame; 
    3938    unsigned                 options; 
     39    pj_uint64_t              max_jump; 
    4040    pjmedia_clock_callback  *cb; 
    4141    void                    *user_data; 
     
    4949static int clock_thread(void *arg); 
    5050 
     51#define MAX_JUMP_MSEC   500 
    5152 
    5253/* 
     
    7778    clock->next_tick.u64 = 0; 
    7879    clock->timestamp.u64 = 0; 
     80    clock->max_jump = MAX_JUMP_MSEC * clock->freq.u64 / 1000; 
    7981    clock->samples_per_frame = samples_per_frame; 
    8082    clock->options = options; 
     
    143145 
    144146 
     147/* Calculate next tick */ 
     148PJ_INLINE(void) clock_calc_next_tick(pjmedia_clock *clock, 
     149                                     pj_timestamp *now) 
     150{ 
     151    if (clock->next_tick.u64+clock->max_jump < now->u64) { 
     152        /* Timestamp has made large jump, adjust next_tick */ 
     153        clock->next_tick.u64 = now->u64; 
     154    } 
     155    clock->next_tick.u64 += clock->interval.u64; 
     156 
     157} 
     158 
    145159/* 
    146160 * Poll the clock.  
     
    185199 
    186200    /* Calculate next tick */ 
    187     if (clock->next_tick.u64+MAX_JUMP < now.u64) { 
    188         /* Timestamp has made large jump, adjust next_tick */ 
    189         clock->next_tick.u64 = now.u64; 
    190     } 
    191     clock->next_tick.u64 += clock->interval.u64; 
     201    clock_calc_next_tick(clock, &now); 
    192202 
    193203    /* Done */ 
     
    221231 
    222232        /* Skip if not running */ 
    223         if (!clock->running) 
     233        if (!clock->running) { 
     234            /* Calculate next tick */ 
     235            clock_calc_next_tick(clock, &now); 
    224236            continue; 
     237        } 
    225238 
    226239        pj_lock_acquire(clock->lock); 
     
    234247 
    235248        /* Calculate next tick */ 
    236         if (clock->next_tick.u64+MAX_JUMP < now.u64) { 
    237             /* Timestamp has made large jump, adjust next_tick */ 
    238             clock->next_tick.u64 = now.u64; 
    239         } 
    240         clock->next_tick.u64 += clock->interval.u64; 
     249        clock_calc_next_tick(clock, &now); 
    241250 
    242251        pj_lock_release(clock->lock); 
Note: See TracChangeset for help on using the changeset viewer.