#include <dlfcn.h>
#include <message_port.h>
+#include <chrono>
+
#include "service_common.h"
#include "service_main.h"
#include "service_ipc_dbus.h"
"MESSAGE_PORT_ERROR_UNKNOWN");
}
+static long long get_current_milliseconds_after_epoch()
+{
+ auto now = std::chrono::steady_clock::now();
+ auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
+ /* number of milliseconds since the epoch of system_clock */
+ auto value = now_ms.time_since_epoch();
+
+ return value.count();
+}
+
int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data, unsigned int data_size)
{
if (nullptr == mClientManager) {
memcpy(buffer + total_size, data, data_size);
total_size += data_size;
+ const long long minimum_flush_interval = 20;
+ static long long last_flush_time = get_current_milliseconds_after_epoch();
+ long long current_time = get_current_milliseconds_after_epoch();
+
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) {
+ MAS_SPEECH_STREAMING_EVENT_FINISH == event ||
+ current_time - last_flush_time > minimum_flush_interval) {
+ last_flush_time = current_time;
bundle *b = bundle_create();
if (b) {
bundle_add_byte(b, "content", pending_buffer, pending_buffer_size);