#include "ma_main.h"
#include "ma_client.h"
+#include <message_port.h>
static int g_waiting_time = 3000;
extern int __ma_cb_audio_streaming_data_section_changed(ma_audio_streaming_data_section_e section);
extern int __ma_cb_preprocessing_result_received(bool result);
+#define STREAMING_BUFFER_SIZE 4096
+
+typedef enum {
+ streaming_data_type_audio_data,
+ streaming_data_type_streaming_section
+} streaming_data_type_e;
+
+typedef struct {
+ unsigned int streaming_data_size;
+ int streaming_data_type;
+ int streaming_data_serial;
+} streaming_data_header;
+
+typedef struct {
+ int event;
+ unsigned int data_size;
+} streaming_data_audio_data_header;
+
+typedef struct {
+ int section;
+} streaming_data_streaming_section_header;
+
+const char *message_port = "ma_streaming_port";
+static int g_local_port_id = -1;
+
+static void message_port_cb(int local_port_id,
+ const char *remote_app_id, const char *remote_port,
+ bool trusted_remote_port, bundle *message, void *user_data)
+{
+ static char pending_buffer[STREAMING_BUFFER_SIZE * 2];
+ static unsigned int pending_buffer_size = 0;
+
+ char buffer[STREAMING_BUFFER_SIZE];
+ size_t size;
+
+ unsigned char *v = NULL;
+ bundle_get_byte(message, "content", (void**)(&v), &size);
+
+ if (size > STREAMING_BUFFER_SIZE) {
+ MA_SLOGE("[ERROR] bundle contains data bigger than %d : %d", STREAMING_BUFFER_SIZE, size);
+ return;
+ } else {
+ memcpy(buffer, v, size);
+ }
+
+ memcpy(pending_buffer + pending_buffer_size, buffer, size);
+ pending_buffer_size += size;
+
+ if (pending_buffer_size >= sizeof(streaming_data_header)) {
+ streaming_data_header header;
+ memcpy(&header, pending_buffer, sizeof(streaming_data_header));
+ if (pending_buffer_size >= header.streaming_data_size) {
+ static int last_serial = 0;
+ if (header.streaming_data_serial != last_serial + 1) {
+ MA_SLOGE("[ERROR] SERIAL MISMATCH in [%d] : %d => %d",
+ header.streaming_data_type, last_serial, header.streaming_data_serial);
+ }
+ last_serial = header.streaming_data_serial;
+
+ if (streaming_data_type_audio_data == header.streaming_data_type) {
+ streaming_data_audio_data_header audio_data_header;
+ memcpy(&audio_data_header, pending_buffer + sizeof(streaming_data_header),
+ sizeof(streaming_data_audio_data_header));
+
+ __ma_cb_audio_streaming(audio_data_header.event,
+ pending_buffer + sizeof(streaming_data_header) + sizeof(streaming_data_audio_data_header),
+ audio_data_header.data_size);
+ } else if (streaming_data_type_streaming_section == header.streaming_data_type) {
+ streaming_data_streaming_section_header streaming_section_header;
+ memcpy(&streaming_section_header, pending_buffer + sizeof(streaming_data_header),
+ sizeof(streaming_data_streaming_section_header));
+
+ __ma_cb_audio_streaming_data_section_changed(streaming_section_header.section);
+ }
+
+ memmove(pending_buffer + header.streaming_data_size, pending_buffer,
+ sizeof(pending_buffer) - header.streaming_data_size);
+ pending_buffer_size -= header.streaming_data_size;
+ }
+ }
+}
+
+static int streaming_ipc_initialize()
+{
+ int port_id = message_port_register_local_port(message_port, message_port_cb, NULL);
+ if (port_id < 0) {
+ MA_SLOGD("Port register error: %d", port_id);
+ } else {
+ MA_SLOGD("port_id: %d", port_id);
+ g_local_port_id = port_id;
+ }
+
+ return 0;
+}
+
+static int streaming_ipc_deinitialize()
+{
+ if (-1 != g_local_port_id) message_port_unregister_local_port(g_local_port_id);
+ g_local_port_id = -1;
+ return 0;
+}
+
static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler* fd_handler)
{
if (NULL == g_conn_listener)
int len;
static int count = 0;
static bool start_received = false;
-
dbus_message_get_args(msg, &err,
DBUS_TYPE_INT32, &event,
DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
return MA_ERROR_OPERATION_FAILED;
}
+ streaming_ipc_initialize();
+
return 0;
}
int ma_dbus_close_connection()
{
+ streaming_ipc_deinitialize();
+
DBusError err;
dbus_error_init(&err);