Changeset 2010 for pjproject


Ignore:
Timestamp:
Jun 12, 2008 4:54:48 PM (16 years ago)
Author:
nanang
Message:

More ticket #542: updated dsound.c to adapt with latency setting

File:
1 edited

Legend:

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

    r2007 r2010  
    4444#define BYTES_PER_SAMPLE    (BITS_PER_SAMPLE/8) 
    4545 
    46 #define MAX_PACKET_BUFFER_COUNT     PJMEDIA_SOUND_BUFFER_COUNT 
    47 #define DEFAULT_BUFFER_COUNT        PJMEDIA_SOUND_BUFFER_COUNT 
     46#define MAX_PACKET_BUFFER_COUNT     50 
     47#define MIN_PACKET_BUFFER_COUNT     2 
    4848 
    4949#define MAX_HARDWARE                16 
     
    8888    DWORD                   dwDsBufferSize; 
    8989    pj_timestamp            timestamp; 
     90    unsigned                latency; 
    9091}; 
    9192 
     
    239240    ds_strm->dwDsBufferSize = buffer_count * bytes_per_frame; 
    240241    ds_strm->timestamp.u64 = 0; 
    241  
     242    ds_strm->latency = buffer_count * samples_per_frame * 1000 / clock_rate /  
     243                       channel_count; 
    242244 
    243245    /* Done setting up play device. */ 
     
    345347    ds_strm->timestamp.u64 = 0; 
    346348    ds_strm->dwDsBufferSize = buffer_count * bytes_per_frame; 
     349    ds_strm->latency = buffer_count * samples_per_frame * 1000 / clock_rate /  
     350                       channel_count; 
    347351 
    348352    /* Done setting up recorder device. */ 
     
    727731    pjmedia_snd_stream *strm; 
    728732    pj_status_t status; 
    729  
    730733 
    731734    /* Make sure sound subsystem has been initialized with 
     
    762765    /* Create player stream */ 
    763766    if (dir & PJMEDIA_DIR_PLAYBACK) { 
     767        unsigned buffer_count; 
     768         
     769        /* Calculate buffer count, in frame unit */ 
     770        buffer_count = clock_rate * snd_output_latency / samples_per_frame / 
     771                       1000; 
     772        if (buffer_count < MIN_PACKET_BUFFER_COUNT) 
     773            buffer_count = MIN_PACKET_BUFFER_COUNT; 
     774        if (buffer_count > MAX_PACKET_BUFFER_COUNT) 
     775            buffer_count = MAX_PACKET_BUFFER_COUNT; 
     776 
    764777        status = init_player_stream( &strm->play_strm, play_id, clock_rate, 
    765778                                     channel_count, samples_per_frame, 
    766                                      DEFAULT_BUFFER_COUNT ); 
     779                                     buffer_count ); 
    767780        if (status != PJ_SUCCESS) { 
    768781            pjmedia_snd_stream_close(strm); 
     
    773786    /* Create capture stream */ 
    774787    if (dir & PJMEDIA_DIR_CAPTURE) { 
     788        unsigned buffer_count; 
     789         
     790        /* Calculate buffer count, in frame unit */ 
     791        buffer_count = clock_rate * snd_input_latency / samples_per_frame / 
     792                       1000; 
     793        if (buffer_count < MIN_PACKET_BUFFER_COUNT) 
     794            buffer_count = MIN_PACKET_BUFFER_COUNT; 
     795        if (buffer_count > MAX_PACKET_BUFFER_COUNT) 
     796            buffer_count = MAX_PACKET_BUFFER_COUNT; 
     797 
    775798        status = init_capture_stream( &strm->rec_strm, rec_id, clock_rate, 
    776799                                      channel_count, samples_per_frame, 
    777                                       DEFAULT_BUFFER_COUNT); 
     800                                      buffer_count); 
    778801        if (status != PJ_SUCCESS) { 
    779802            pjmedia_snd_stream_close(strm); 
     
    872895    pi->samples_per_frame = strm->samples_per_frame; 
    873896    pi->bits_per_sample = strm->bits_per_sample; 
    874     pi->rec_latency = 0; 
    875     pi->play_latency = 0; 
     897    pi->rec_latency = strm->rec_strm.latency; 
     898    pi->play_latency = strm->play_strm.latency; 
    876899 
    877900    return PJ_SUCCESS; 
     
    9971020                                            unsigned output_latency) 
    9981021{ 
    999     PJ_TODO(APPLY_LATENCY_SETTINGS_ON_DSOUND); 
    1000  
    10011022    snd_input_latency  = (input_latency == 0)?  
    10021023                         PJMEDIA_SND_DEFAULT_REC_LATENCY : input_latency; 
Note: See TracChangeset for help on using the changeset viewer.