Changeset 2426 for pjproject/trunk


Ignore:
Timestamp:
Jan 20, 2009 6:05:58 PM (16 years ago)
Author:
nanang
Message:

Ticket #701: Updated PA callbacks to check their thread registration status using both: manual flag and actual/TLS status.

File:
1 edited

Legend:

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

    r2394 r2426  
    7373 
    7474    pj_bool_t            rec_thread_exited; 
    75     //pj_bool_t          rec_thread_initialized; 
     75    pj_bool_t            rec_thread_initialized; 
    7676    pj_thread_desc       rec_thread_desc; 
    7777    pj_thread_t         *rec_thread; 
    7878 
    7979    pj_bool_t            play_thread_exited; 
    80     //pj_bool_t          play_thread_initialized; 
     80    pj_bool_t            play_thread_initialized; 
    8181    pj_thread_desc       play_thread_desc; 
    8282    pj_thread_t         *play_thread; 
     
    119119        return paContinue; 
    120120 
    121     // Sometime the thread, where this callback called from, is changed 
    122     // (e.g: in MacOS this happens when plugging/unplugging headphone) 
    123     // if (stream->rec_thread_initialized == 0) { 
    124     if (!pj_thread_is_registered()) { 
     121    /* Known cases of callback's thread: 
     122     * - The thread may be changed in the middle of a session, e.g: in MacOS  
     123     *   it happens when plugging/unplugging headphone. 
     124     * - The same thread may be reused in consecutive sessions. The first 
     125     *   session will leave TLS set, but release the TLS data address, 
     126     *   so the second session must re-register the callback's thread. 
     127     */ 
     128    if (stream->rec_thread_initialized == 0 || !pj_thread_is_registered())  
     129    { 
    125130        status = pj_thread_register("pa_rec", stream->rec_thread_desc,  
    126131                                    &stream->rec_thread); 
    127         //stream->rec_thread_initialized = 1; 
     132        stream->rec_thread_initialized = 1; 
    128133        PJ_LOG(5,(THIS_FILE, "Recorder thread started")); 
    129134    } 
     
    215220        return paContinue; 
    216221 
    217     // Sometime the thread, where this callback called from, is changed 
    218     // (e.g: in MacOS this happens when plugging/unplugging headphone) 
    219     // if (stream->play_thread_initialized == 0) { 
    220     if (!pj_thread_is_registered()) { 
     222    /* Known cases of callback's thread: 
     223     * - The thread may be changed in the middle of a session, e.g: in MacOS  
     224     *   it happens when plugging/unplugging headphone. 
     225     * - The same thread may be reused in consecutive sessions. The first 
     226     *   session will leave TLS set, but release the TLS data address, 
     227     *   so the second session must re-register the callback's thread. 
     228     */ 
     229    if (stream->play_thread_initialized == 0 || !pj_thread_is_registered())  
     230    { 
    221231        status = pj_thread_register("portaudio", stream->play_thread_desc, 
    222232                                    &stream->play_thread); 
    223         //stream->play_thread_initialized = 1; 
     233        stream->play_thread_initialized = 1; 
    224234        PJ_LOG(5,(THIS_FILE, "Player thread started")); 
    225235    } 
     
    954964        err = Pa_StopStream(stream->rec_strm); 
    955965 
     966    stream->play_thread_initialized = 0; 
     967    stream->rec_thread_initialized = 0; 
     968 
    956969    PJ_LOG(5,(THIS_FILE, "Done, status=%d", err)); 
    957970 
Note: See TracChangeset for help on using the changeset viewer.