tizen-sink2/source2: Fix abort when disconnecting USB devices 97/290697/2
authorJaechul Lee <jcsing.lee@samsung.com>
Fri, 31 Mar 2023 02:41:46 +0000 (11:41 +0900)
committerJaechul Lee <jcsing.lee@samsung.com>
Mon, 3 Apr 2023 05:40:00 +0000 (14:40 +0900)
[Version] 15.0.37
[Issue Type] Bug

Change-Id: I79b5e88f7c2595c436d2863241c6d52b3687ad6b
Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
src/tizenaudio-sink2.c
src/tizenaudio-source2.c

index 97419017ed6f2493f5e82cb42d374c175a1389aa..04c217f76deee1a4e2a1b28c92607a9b6e9060ca 100644 (file)
@@ -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;
                 }
index 41bc90e80dd4053754206bd16b9bd1773b65768c..05c5f7617e9af6e80460f392c0e6282324e03299 100644 (file)
@@ -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;
                 }