void CPulseAudioClient::finalize() {
AUDIO_IO_LOGD("");
- if (__mIsInit == false) {
- return;
- }
- if (isInThread() == false)
+ if (__mpMainloop && isInThread() == false)
pa_threaded_mainloop_lock(__mpMainloop);
/* clear callbacks */
- if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK)
- pa_stream_set_write_callback(__mpStream, NULL, NULL);
- else
- pa_stream_set_read_callback(__mpStream, NULL, NULL);
- pa_stream_set_latency_update_callback(__mpStream, NULL, NULL);
- pa_stream_set_event_callback(__mpStream, NULL, NULL);
-
- if (isInThread() == false)
+ if (__mpStream) {
+ if (__mDirection == EStreamDirection::STREAM_DIRECTION_PLAYBACK)
+ pa_stream_set_write_callback(__mpStream, NULL, NULL);
+ else
+ pa_stream_set_read_callback(__mpStream, NULL, NULL);
+ pa_stream_set_latency_update_callback(__mpStream, NULL, NULL);
+ pa_stream_set_event_callback(__mpStream, NULL, NULL);
+ }
+
+ if (__mpMainloop && isInThread() == false)
pa_threaded_mainloop_unlock(__mpMainloop);
/* Wait for drain complete if draining before finalize */