From e091f91d910309e787c51159aefba7509389e4d0 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 23 Jul 2021 12:18:21 +0900 Subject: [PATCH] Add minimum flush time constraint Change-Id: If353d23ae3995f7e9e945053da82debc4b6672fe --- src/service_ipc_dbus.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/service_ipc_dbus.cpp b/src/service_ipc_dbus.cpp index a816966..a0973f6 100644 --- a/src/service_ipc_dbus.cpp +++ b/src/service_ipc_dbus.cpp @@ -19,6 +19,8 @@ #include #include +#include + #include "service_common.h" #include "service_main.h" #include "service_ipc_dbus.h" @@ -206,6 +208,16 @@ static void masc_message_port_error(int error) "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(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) { @@ -234,13 +246,19 @@ int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data, 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); -- 2.7.4