acm: Request drain when sink state is changed to IDLE from RUNNING 59/207559/4
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 7 Jun 2019 06:46:56 +0000 (15:46 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 13 Jun 2019 06:23:32 +0000 (15:23 +0900)
[Version] 11.1.47
[Issue type] Improvement

Change-Id: I15affa5362992c325afb01ca589ab31f29afbe85
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/pulseaudio-modules-tizen.spec
src/acm.c

index 5fe0b00..f9155f2 100644 (file)
@@ -1,6 +1,6 @@
 Name:             pulseaudio-modules-tizen
 Summary:          Pulseaudio modules for Tizen
-Version:          11.1.46
+Version:          11.1.47
 Release:          0
 Group:            Multimedia/Audio
 License:          LGPL-2.1+
index f6023f2..e520ee9 100644 (file)
--- a/src/acm.c
+++ b/src/acm.c
@@ -88,7 +88,7 @@ struct userdata {
     char *msg_socket_path;
     int data_fd;
     int msg_fd;
-    bool msg_sent;
+    bool enough_data_sent;
     int initial_sent_size;
 
     pa_mutex *msg_mutex;
@@ -100,9 +100,8 @@ struct userdata {
 #endif
 };
 
-static int initialize_IPC(struct userdata *u);
-static void deinitialize_IPC(struct userdata *u);
 static int send_data(struct userdata *u, pa_memchunk *chunk);
+static void ipc_request_drain(struct userdata *u);
 
 #ifdef DUMP_PCM
 #include <time.h>
@@ -182,18 +181,25 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
 
     switch (code) {
 
-        case PA_SINK_MESSAGE_SET_STATE:
+        case PA_SINK_MESSAGE_SET_STATE: {
+            pa_sink_state_t new_state = PA_PTR_TO_UINT(data);
+
             if (pa_sink_get_state(u->sink) == PA_SINK_SUSPENDED || pa_sink_get_state(u->sink) == PA_SINK_INIT) {
-                if (PA_PTR_TO_UINT(data) == PA_SINK_RUNNING || PA_PTR_TO_UINT(data) == PA_SINK_IDLE)
+                if (new_state == PA_SINK_RUNNING || new_state == PA_SINK_IDLE)
                     u->timestamp = pa_rtclock_now();
             }
 #ifdef DUMP_PCM
-            if  (PA_PTR_TO_UINT(data) == PA_SINK_RUNNING)
+            if  (new_state == PA_SINK_RUNNING)
                 dump_open(u);
             else
                 dump_close(u);
 #endif
+            if (pa_sink_get_state(u->sink) == PA_SINK_RUNNING) {
+                if (new_state != PA_SINK_RUNNING)
+                    ipc_request_drain(u);
+            }
             break;
+        }
 
         case PA_SINK_MESSAGE_GET_LATENCY: {
             pa_usec_t now;
@@ -280,14 +286,14 @@ static int ipc_push_data(struct userdata *u, void *data, int size) {
         return -1;
     }
 
-    if (!u->msg_sent) {
+    if (!u->enough_data_sent) {
         u->initial_sent_size += sent;
         if (u->initial_sent_size > SOCKET_ENOUGH_DATA_SIZE ) {
             int msg_sent_len = 0;
             pa_log_info("send data enough message to ipc server");
             if ((msg_sent_len = send(u->msg_fd, MSG_DATA_ENOUGH, strlen(MSG_DATA_ENOUGH), 0)) < 0)
                 pa_log_error("send message was failed, msg(%s), msg_sent_len =%d", MSG_DATA_ENOUGH, msg_sent_len);
-            u->msg_sent = true;
+            u->enough_data_sent = true;
             u->initial_sent_size = 0;
         }
     }
@@ -300,7 +306,19 @@ static int ipc_push_data(struct userdata *u, void *data, int size) {
     return sent;
 }
 
-static int initialize_IPC(struct userdata *u) {
+static void ipc_request_drain(struct userdata *u) {
+    pa_assert(u);
+
+    if (u->msg_fd >= 0 && u->enough_data_sent) {
+        int msg_sent_len = 0;
+        if ((msg_sent_len = send(u->msg_fd, MSG_DRAIN_REQUEST, strlen(MSG_DRAIN_REQUEST), 0)) < 0)
+            pa_log_error("send message was failed, msg(%s), msg_sent_len =%d", MSG_DRAIN_REQUEST, msg_sent_len);
+
+        u->enough_data_sent = false;
+    }
+}
+
+static int initialize_ipc(struct userdata *u) {
     int retry = 10;
 
     pa_assert(u);
@@ -336,26 +354,17 @@ static int initialize_IPC(struct userdata *u) {
         return -1;
     }
 
-    u->msg_sent = false;
+    u->enough_data_sent = false;
     u->initial_sent_size = 0;
 
     return 0;
 }
 
-static void deinitialize_IPC(struct userdata *u) {
+static void deinitialize_ipc(struct userdata *u) {
     pa_assert(u);
 
-    if (u->msg_fd >= 0) {
-        int msg_sent_len = 0;
-        if ((msg_sent_len = send(u->msg_fd, MSG_DRAIN_REQUEST, strlen(MSG_DRAIN_REQUEST), 0)) < 0) {
-            pa_log_error("send message was failed, msg(%s), msg_sent_len =%d", MSG_DRAIN_REQUEST, msg_sent_len);
-        } else {
-            pa_log_info("msg cond wait for drain completed");
-            msg_cond_wait(u);
-        }
-    }
+    ipc_request_drain(u);
 
-    u->msg_sent = false;
     u->initial_sent_size = 0;
 
     if (u->data_fd >= 0) {
@@ -590,7 +599,7 @@ int pa_acm_init(pa_module *m, const char* const v_modargs[]) {
     u->module = m;
     m->userdata = u;
 
-    if (initialize_IPC(u)) {
+    if (initialize_ipc(u)) {
         pa_log("Failed to initialize IPC");
         goto fail;
     }
@@ -691,7 +700,7 @@ void pa_acm_done(pa_module *m) {
     if (u->rtpoll)
         pa_rtpoll_free(u->rtpoll);
 
-    deinitialize_IPC(u);
+    deinitialize_ipc(u);
 
     if (u->msg_mutex) {
         pa_mutex_free(u->msg_mutex);