From: Jaechul Lee Date: Fri, 31 Mar 2023 02:41:46 +0000 (+0900) Subject: tizen-sink2/source2: Fix abort when disconnecting USB devices X-Git-Tag: accepted/tizen/unified/20230531.034435~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ca2e53d49b13af39f12c9609318b23ed67edcdba;p=platform%2Fcore%2Fmultimedia%2Fpulseaudio-modules-tizen.git tizen-sink2/source2: Fix abort when disconnecting USB devices [Version] 15.0.37 [Issue Type] Bug Change-Id: I79b5e88f7c2595c436d2863241c6d52b3687ad6b Signed-off-by: Jaechul Lee --- diff --git a/src/tizenaudio-sink2.c b/src/tizenaudio-sink2.c index 9741901..04c217f 100644 --- a/src/tizenaudio-sink2.c +++ b/src/tizenaudio-sink2.c @@ -115,12 +115,17 @@ static int build_pollfd(struct userdata *u) { static int suspend(struct userdata *u) { int32_t ret; pa_assert(u); - pa_assert(u->pcm_handle); - ret = pa_hal_interface_pcm_close(u->hal_interface, u->pcm_handle); - if (ret) { - pa_log_error("Error closing PCM device %x", ret); + /* suspend could be called by set_state function while waiting for PA_MESSAGE_SHUTDOWN */ + if (!u->pcm_handle) { + pa_log_error("pcm_handle is null. PCM is going to be shutdown due to the recovering failure"); + return 0; } + + ret = pa_hal_interface_pcm_close(u->hal_interface, u->pcm_handle); + if (ret) + pa_log_error("Error closing PCM device. rtpoll will be stopped anyway"); + u->pcm_handle = NULL; if (u->rtpoll_item) { @@ -130,7 +135,7 @@ static int suspend(struct userdata *u) { pa_log_info("Device suspended..."); - return 0; + return ret; } /* Called from IO context */ @@ -368,8 +373,21 @@ static void thread_func(void *userdata) { pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL); revents = pollfd->revents; if (revents & ~POLLOUT) { - pa_log_debug("Poll error 0x%x occured, try recover.", revents); - pa_hal_interface_pcm_recover(u->hal_interface, u->pcm_handle, revents); + pa_log_error("Poll error 0x%x occured, try recover.", revents); + + if (pa_hal_interface_pcm_recover(u->hal_interface, u->pcm_handle, revents)) { + pa_log_warn("Try to suspend and unsuspend for recovering the pcm device"); + + if (suspend(u)) { + pa_log_error("Failed to suspend!. This thread is going to shutdown."); + goto fail; + } + if (unsuspend(u)) { + pa_log_error("Failed to unsuspend!. This thread is going to shutdown."); + goto fail; + } + } + u->first = true; revents = 0; } diff --git a/src/tizenaudio-source2.c b/src/tizenaudio-source2.c index 41bc90e..05c5f76 100644 --- a/src/tizenaudio-source2.c +++ b/src/tizenaudio-source2.c @@ -118,12 +118,17 @@ static int build_pollfd(struct userdata *u) { static int suspend(struct userdata *u) { int32_t ret; pa_assert(u); - pa_assert(u->pcm_handle); - ret = pa_hal_interface_pcm_close(u->hal_interface, u->pcm_handle); - if (ret) { - pa_log_error("Error closing PCM device %x", ret); + /* suspend could be called by set_state function while waiting for PA_MESSAGE_SHUTDOWN */ + if (!u->pcm_handle) { + pa_log_error("pcm_handle is null. PCM is going to be shutdown due to the recovering failure"); + return 0; } + + ret = pa_hal_interface_pcm_close(u->hal_interface, u->pcm_handle); + if (ret) + pa_log_error("Error closing PCM device. rtpoll will be stopped anyway"); + u->pcm_handle = NULL; if (u->rtpoll_item) { @@ -133,7 +138,7 @@ static int suspend(struct userdata *u) { pa_log_info("Device suspended..."); - return 0; + return ret; } /* Called from IO context */ @@ -371,8 +376,21 @@ static void thread_func(void *userdata) { pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL); revents = pollfd->revents; if (revents & ~POLLIN) { - pa_log_debug("Poll error 0x%x occured, try recover.", revents); - pa_hal_interface_pcm_recover(u->hal_interface, u->pcm_handle, revents); + pa_log_error("Poll error 0x%x occured, try recover.", revents); + + if (pa_hal_interface_pcm_recover(u->hal_interface, u->pcm_handle, revents)) { + pa_log_warn("Try to suspend and unsuspend for recovering the pcm device"); + + if (suspend(u)) { + pa_log_error("Failed to suspend!. This thread is going to shutdown."); + goto fail; + } + if (unsuspend(u)) { + pa_log_error("Failed to unsuspend!. This thread is going to shutdown."); + goto fail; + } + } + u->first = true; revents = 0; }