Ignore:
Timestamp:
Jan 4, 2008 6:00:11 PM (17 years ago)
Author:
bennylp
Message:

Fixed bug in sndtest: drift detection was wrong since it assumes that the drift value would be positive. Also added mutex protection just in case

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/samples/sndtest.c

    r974 r1663  
    8080    pj_bool_t running; 
    8181    pj_bool_t has_error; 
     82    pj_mutex_t *mutex; 
    8283 
    8384    struct stream_data capture_data; 
     
    137138    struct stream_data *strm_data = &test_data->playback_data; 
    138139 
     140    pj_mutex_lock(test_data->mutex); 
     141 
    139142    /* Skip frames when test is not started or test has finished */ 
    140143    if (!test_data->running) { 
    141144        pj_bzero(output, size); 
     145 
     146        pj_mutex_unlock(test_data->mutex); 
    142147        return PJ_SUCCESS; 
    143148    } 
     
    180185 
    181186    pj_bzero(output, size); 
     187 
     188    pj_mutex_unlock(test_data->mutex); 
     189 
    182190    return PJ_SUCCESS; 
    183191} 
     
    190198    struct stream_data *strm_data = &test_data->capture_data; 
    191199 
     200    pj_mutex_lock(test_data->mutex); 
     201 
    192202    PJ_UNUSED_ARG(input); 
    193203    PJ_UNUSED_ARG(size); 
     
    195205    /* Skip frames when test is not started or test has finished */ 
    196206    if (!test_data->running) { 
     207        pj_mutex_unlock(test_data->mutex); 
    197208        return PJ_SUCCESS; 
    198209    } 
     
    234245    } 
    235246 
     247    pj_mutex_unlock(test_data->mutex); 
    236248    return PJ_SUCCESS; 
    237249} 
     
    354366 
    355367 
    356 static int perform_test(int dev_id, pjmedia_dir dir, 
     368static int perform_test(pj_pool_t *pool, int dev_id, pjmedia_dir dir, 
    357369                        unsigned clock_rate, unsigned samples_per_frame,  
    358370                        unsigned nchannel, int verbose) 
     
    362374    struct test_data test_data; 
    363375    pjmedia_snd_stream_info si; 
    364  
    365  
     376     
    366377    /* 
    367378     * Init test parameters 
     
    372383    test_data.samples_per_frame = samples_per_frame; 
    373384    test_data.channel_count = nchannel; 
     385 
     386    pj_mutex_create_simple(pool, "sndtest", &test_data.mutex);  
    374387 
    375388    /* 
     
    467480        start_diff = test_data.capture_data.first_timestamp- 
    468481                      test_data.playback_data.first_timestamp; 
    469         drift = end_diff - start_diff; 
     482        drift = end_diff > start_diff? end_diff - start_diff : 
     483                start_diff - end_diff; 
    470484 
    471485        PJ_LOG(3,(THIS_FILE, "  Checking for clock drifts:")); 
     
    508522{ 
    509523    pj_caching_pool cp; 
     524    pj_pool_t *pool; 
    510525    pjmedia_endpt *med_endpt; 
    511526    int id = -1, verbose = 0; 
     
    533548    /* Must create a pool factory before we can allocate any memory. */ 
    534549    pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); 
     550 
     551    /* Also create pool for misc purposes */ 
     552    pool = pj_pool_create(&cp.factory, "sndtest", 1000, 1000, NULL); 
    535553 
    536554    /*  
     
    589607 
    590608 
    591     status = perform_test(id, PJMEDIA_DIR_CAPTURE_PLAYBACK,  
     609    status = perform_test(pool, id, PJMEDIA_DIR_CAPTURE_PLAYBACK,  
    592610                          clock_rate, frame, channel, verbose); 
    593     if (status != 0) 
    594         return 1; 
    595  
     611 
     612    pjmedia_endpt_destroy(med_endpt); 
     613    pj_pool_release(pool); 
     614    pj_caching_pool_destroy(&cp); 
     615    pj_shutdown(); 
    596616     
    597     return 0; 
     617    return status == PJ_SUCCESS ? 0 : 1; 
    598618} 
    599619 
Note: See TracChangeset for help on using the changeset viewer.