Pack several messages in one packet for efficiency 30/221730/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Tue, 7 Jan 2020 06:57:28 +0000 (15:57 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Tue, 7 Jan 2020 06:57:31 +0000 (15:57 +0900)
Change-Id: I572dd3e73270a05d0b2e2d1055096c1b401c641d

src/multi_assistant_dbus.c

index 72d3eda..a09d82d 100644 (file)
@@ -216,7 +216,8 @@ void masc_message_port_error(int error)
 
 int masc_dbus_send_streaming_audio_data(int pid, int event, unsigned char* data, unsigned int data_size)
 {
-       bundle *b = bundle_create();
+       static unsigned char pending_buffer[STREAMING_BUFFER_SIZE];
+       static unsigned int pending_buffer_size = 0;
 
        streaming_data_header header;
        header.streaming_data_type = 0;
@@ -236,12 +237,50 @@ int masc_dbus_send_streaming_audio_data(int pid, int event, unsigned char* data,
        memcpy(buffer + total_size, data, data_size);
        total_size += data_size;
 
-       bundle_add_byte(b, "content", buffer, total_size);
-       int ret = message_port_send_message(mas_get_client_appid_by_pid(pid), message_port, b);
-       if (MESSAGE_PORT_ERROR_NONE != ret)
-               masc_message_port_error(ret);
+       static int last_serial_waiting_for_flush = -1;
+       if (0 == header.streaming_data_serial % 50) {
+               last_serial_waiting_for_flush = header.streaming_data_serial;
+               MAS_LOGI("queueing streaming data, serial : %d", last_serial_waiting_for_flush);
+       }
+       if (pending_buffer_size + total_size > STREAMING_BUFFER_SIZE ||
+               MAS_SPEECH_STREAMING_EVENT_FINISH == event) {
+               bundle *b = bundle_create();
+               if (b) {
+                       bundle_add_byte(b, "content", pending_buffer, pending_buffer_size);
+                       int ret = message_port_send_message(
+                               mas_get_client_appid_by_pid(pid), message_port, b);
+                       if (MESSAGE_PORT_ERROR_NONE != ret)
+                               masc_message_port_error(ret);
+
+                       pending_buffer_size = 0;
+                       bundle_free(b);
+               } else {
+                       MAS_LOGE("Bundle creation failed!!!");
+               }
 
-       bundle_free(b);
+               if (-1 != last_serial_waiting_for_flush) {
+                       MAS_LOGI("flushing streaming data, serial : %d", last_serial_waiting_for_flush);
+                       last_serial_waiting_for_flush =  -1;
+               }
+       }
+
+       if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) {
+               bundle *b = bundle_create();
+               if (b) {
+                       bundle_add_byte(b, "content", buffer, total_size);
+                       int ret = message_port_send_message(
+                               mas_get_client_appid_by_pid(pid), message_port, b);
+                       if (MESSAGE_PORT_ERROR_NONE != ret)
+                               masc_message_port_error(ret);
+
+                       bundle_free(b);
+               } else {
+                       MAS_LOGE("Bundle creation failed!!!");
+               }
+       } else {
+               memcpy(pending_buffer + pending_buffer_size, buffer, total_size);
+               pending_buffer_size += total_size;
+       }
        return 0;
 }