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;
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;
}