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;
#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>
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;
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;
}
}
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);
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) {
u->module = m;
m->userdata = u;
- if (initialize_IPC(u)) {
+ if (initialize_ipc(u)) {
pa_log("Failed to initialize IPC");
goto fail;
}
if (u->rtpoll)
pa_rtpoll_free(u->rtpoll);
- deinitialize_IPC(u);
+ deinitialize_ipc(u);
if (u->msg_mutex) {
pa_mutex_free(u->msg_mutex);