summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2009-01-20 18:05:58 +0000
committerNanang Izzuddin <nanang@teluu.com>2009-01-20 18:05:58 +0000
commite017703bb0c939e9aeeccea02a3fccc5f4df8f71 (patch)
tree1ae3c2e7468ee0d13481323dd4909d0e3ed9d91a
parent336ed3dc927b4c30484d381f799995afb4c40fee (diff)
Ticket #701: Updated PA callbacks to check their thread registration status using both: manual flag and actual/TLS status.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2426 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjmedia/src/pjmedia/pasound.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/pjmedia/src/pjmedia/pasound.c b/pjmedia/src/pjmedia/pasound.c
index 97fedd71..a004008d 100644
--- a/pjmedia/src/pjmedia/pasound.c
+++ b/pjmedia/src/pjmedia/pasound.c
@@ -72,12 +72,12 @@ struct pjmedia_snd_stream
pj_bool_t quit_flag;
pj_bool_t rec_thread_exited;
- //pj_bool_t rec_thread_initialized;
+ pj_bool_t rec_thread_initialized;
pj_thread_desc rec_thread_desc;
pj_thread_t *rec_thread;
pj_bool_t play_thread_exited;
- //pj_bool_t play_thread_initialized;
+ pj_bool_t play_thread_initialized;
pj_thread_desc play_thread_desc;
pj_thread_t *play_thread;
@@ -118,13 +118,18 @@ static int PaRecorderCallback(const void *input,
if (input == NULL)
return paContinue;
- // Sometime the thread, where this callback called from, is changed
- // (e.g: in MacOS this happens when plugging/unplugging headphone)
- // if (stream->rec_thread_initialized == 0) {
- if (!pj_thread_is_registered()) {
+ /* Known cases of callback's thread:
+ * - The thread may be changed in the middle of a session, e.g: in MacOS
+ * it happens when plugging/unplugging headphone.
+ * - The same thread may be reused in consecutive sessions. The first
+ * session will leave TLS set, but release the TLS data address,
+ * so the second session must re-register the callback's thread.
+ */
+ if (stream->rec_thread_initialized == 0 || !pj_thread_is_registered())
+ {
status = pj_thread_register("pa_rec", stream->rec_thread_desc,
&stream->rec_thread);
- //stream->rec_thread_initialized = 1;
+ stream->rec_thread_initialized = 1;
PJ_LOG(5,(THIS_FILE, "Recorder thread started"));
}
@@ -214,13 +219,18 @@ static int PaPlayerCallback( const void *input,
if (output == NULL)
return paContinue;
- // Sometime the thread, where this callback called from, is changed
- // (e.g: in MacOS this happens when plugging/unplugging headphone)
- // if (stream->play_thread_initialized == 0) {
- if (!pj_thread_is_registered()) {
+ /* Known cases of callback's thread:
+ * - The thread may be changed in the middle of a session, e.g: in MacOS
+ * it happens when plugging/unplugging headphone.
+ * - The same thread may be reused in consecutive sessions. The first
+ * session will leave TLS set, but release the TLS data address,
+ * so the second session must re-register the callback's thread.
+ */
+ if (stream->play_thread_initialized == 0 || !pj_thread_is_registered())
+ {
status = pj_thread_register("portaudio", stream->play_thread_desc,
&stream->play_thread);
- //stream->play_thread_initialized = 1;
+ stream->play_thread_initialized = 1;
PJ_LOG(5,(THIS_FILE, "Player thread started"));
}
@@ -953,6 +963,9 @@ PJ_DEF(pj_status_t) pjmedia_snd_stream_stop(pjmedia_snd_stream *stream)
if (stream->rec_strm && stream->rec_strm != stream->play_strm)
err = Pa_StopStream(stream->rec_strm);
+ stream->play_thread_initialized = 0;
+ stream->rec_thread_initialized = 0;
+
PJ_LOG(5,(THIS_FILE, "Done, status=%d", err));
return err ? PJMEDIA_ERRNO_FROM_PORTAUDIO(err) : PJ_SUCCESS;