From: Ji-hoon Lee Date: Fri, 23 Jul 2021 03:18:21 +0000 (+0900) Subject: Add minimum flush time constraint X-Git-Tag: submit/tizen/20210803.074409~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F85%2F262085%2F1;p=platform%2Fcore%2Fuifw%2Fmulti-assistant-service.git Add minimum flush time constraint Change-Id: If353d23ae3995f7e9e945053da82debc4b6672fe --- 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);