4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungbae Shin <seungbae.shin@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
33 #include <semaphore.h>
38 #include "include/mm_sound.h"
39 #include "include/mm_sound_client.h"
40 #include "include/mm_sound_proxy.h"
41 #include "include/mm_sound_common.h"
42 #include "include/mm_sound_device.h"
43 #include "include/mm_sound_stream.h"
45 #include <mm_session.h>
46 #include <mm_session_private.h>
49 #if defined(__GSOURCE_CALLBACK__)
53 #define CLIENT_HANDLE_MAX 256
55 #define FOCUS_HANDLE_MAX 512
56 #define FOCUS_HANDLE_INIT_VAL -1
57 #define CONFIG_ENABLE_RETCB
59 #define VOLUME_TYPE_LEN 64
61 struct sigaction system_int_old_action;
62 struct sigaction system_abrt_old_action;
63 struct sigaction system_segv_old_action;
64 struct sigaction system_term_old_action;
65 struct sigaction system_sys_old_action;
66 struct sigaction system_xcpu_old_action;
68 struct callback_data {
75 typedef struct _FocusSource {
80 #define GET_CB_DATA(_cb_data, _func, _userdata, _extradata) \
82 _cb_data = (struct callback_data*) g_malloc0(sizeof(struct callback_data)); \
83 _cb_data->user_cb = _func; \
84 _cb_data->user_data = _userdata; \
85 _cb_data->extra_data = _extradata; \
97 GThread *focus_cb_thread;
98 GMainLoop *focus_loop;
99 mm_sound_focus_changed_cb focus_callback;
100 mm_sound_focus_changed_watch_cb watch_callback;
102 bool unset_watch_callback_requested;
104 /* will be removed when the session concept is completely left out*/
107 } focus_sound_info_t;
114 char stream_type[MAX_STREAM_TYPE_LEN];
115 char ext_info[MM_SOUND_NAME_NUM];
121 mm_sound_focus_session_interrupt_cb user_cb;
123 } focus_session_interrupt_info_t;
125 typedef gboolean(*focus_callback_handler_t)(gpointer user_data);
127 focus_sound_info_t g_focus_sound_handle[FOCUS_HANDLE_MAX];
128 focus_session_interrupt_info_t g_focus_session_interrupt_info = {-1, NULL, NULL};
129 static pthread_mutex_t g_index_mutex = PTHREAD_MUTEX_INITIALIZER;
130 static pthread_mutex_t g_event_mutex = PTHREAD_MUTEX_INITIALIZER;
131 guint g_focus_signal_handle;
132 guint g_idle_event_src;
135 gboolean g_need_emergent_exit = FALSE;
138 /* handle to watch end of playing */
140 /* subscription id to unsubscribe when handle ended */
142 } play_sound_end_callback_data_t;
144 typedef struct _focus_idle_event {
145 focus_idle_event_type_e type;
147 } focus_idle_event_t;
149 void mm_sound_client_cleanup(void)
151 int ret = MM_ERROR_NONE;
153 if (g_need_emergent_exit) {
154 ret = mm_sound_proxy_emergent_exit(getpid());
155 if (ret == MM_ERROR_NONE)
156 debug_msg("Success to emergnet_exit");
158 debug_error("Error occurred : 0x%x", ret);
162 void _system_signal_handler(int signo, siginfo_t *siginfo, void *context)
164 sigset_t old_mask, all_mask;
166 debug_warning("Got signal : signo(%d)", signo);
170 sigfillset(&all_mask);
171 sigprocmask(SIG_BLOCK, &all_mask, &old_mask);
173 mm_sound_client_cleanup();
175 sigprocmask(SIG_SETMASK, &old_mask, NULL);
180 if (system_int_old_action.sa_sigaction)
181 system_int_old_action.sa_sigaction(signo, siginfo, context);
183 sigaction(signo, &system_int_old_action, NULL);
186 if (system_abrt_old_action.sa_sigaction)
187 system_abrt_old_action.sa_sigaction(signo, siginfo, context);
189 sigaction(signo, &system_abrt_old_action, NULL);
192 if (system_segv_old_action.sa_sigaction)
193 system_segv_old_action.sa_sigaction(signo, siginfo, context);
195 sigaction(signo, &system_segv_old_action, NULL);
198 if (system_term_old_action.sa_sigaction)
199 system_term_old_action.sa_sigaction(signo, siginfo, context);
201 sigaction(signo, &system_term_old_action, NULL);
204 if (system_sys_old_action.sa_sigaction)
205 system_sys_old_action.sa_sigaction(signo, siginfo, context);
207 sigaction(signo, &system_sys_old_action, NULL);
210 if (system_xcpu_old_action.sa_sigaction)
211 system_xcpu_old_action.sa_sigaction(signo, siginfo, context);
213 sigaction(signo, &system_xcpu_old_action, NULL);
219 debug_warning("signal handling end");
223 static bool _is_dotnet_app(void)
225 char *is_dotnet = NULL;
227 is_dotnet = getenv("DOTNET_APP");
228 if (is_dotnet && atoi(is_dotnet) == 1)
235 int mm_sound_client_initialize(void)
237 int ret = MM_ERROR_NONE;
238 struct sigaction system_action;
242 mm_sound_proxy_initialize();
243 g_idle_event_src = 0;
246 if (_is_dotnet_app()) {
247 debug_warning("no signal handler for dotnet!!");
251 system_action.sa_sigaction = _system_signal_handler;
252 system_action.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
254 sigemptyset(&system_action.sa_mask);
256 sigaction(SIGINT, &system_action, &system_int_old_action);
257 sigaction(SIGABRT, &system_action, &system_abrt_old_action);
258 sigaction(SIGSEGV, &system_action, &system_segv_old_action);
259 sigaction(SIGTERM, &system_action, &system_term_old_action);
260 sigaction(SIGSYS, &system_action, &system_sys_old_action);
261 sigaction(SIGXCPU, &system_action, &system_xcpu_old_action);
267 int mm_sound_client_finalize(void)
269 int ret = MM_ERROR_NONE;
273 mm_sound_client_cleanup();
275 ret = mm_sound_proxy_finalize();
278 if (g_idle_event_src > 0) {
279 MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_event_mutex, MM_ERROR_SOUND_INTERNAL);
280 g_source_remove(g_idle_event_src);
281 MMSOUND_LEAVE_CRITICAL_SECTION(&g_event_mutex);
286 if (_is_dotnet_app()) {
287 debug_warning("no signal handler for dotnet!!");
292 sigaction(SIGINT, &system_int_old_action, NULL);
293 sigaction(SIGABRT, &system_abrt_old_action, NULL);
294 sigaction(SIGSEGV, &system_segv_old_action, NULL);
295 sigaction(SIGTERM, &system_term_old_action, NULL);
296 sigaction(SIGSYS, &system_sys_old_action, NULL);
297 sigaction(SIGXCPU, &system_xcpu_old_action, NULL);
303 void mm_sound_convert_volume_type_to_stream_type(int volume_type, char *stream_type)
305 switch (volume_type) {
306 case VOLUME_TYPE_SYSTEM:
307 MMSOUND_STRNCPY(stream_type, "system", MAX_STREAM_TYPE_LEN);
309 case VOLUME_TYPE_NOTIFICATION:
310 MMSOUND_STRNCPY(stream_type, "notification", MAX_STREAM_TYPE_LEN);
312 case VOLUME_TYPE_ALARM:
313 MMSOUND_STRNCPY(stream_type, "alarm", MAX_STREAM_TYPE_LEN);
315 case VOLUME_TYPE_RINGTONE:
316 MMSOUND_STRNCPY(stream_type, "ringtone-voip", MAX_STREAM_TYPE_LEN);
318 case VOLUME_TYPE_MEDIA:
319 MMSOUND_STRNCPY(stream_type, "media", MAX_STREAM_TYPE_LEN);
321 case VOLUME_TYPE_CALL:
322 MMSOUND_STRNCPY(stream_type, "call-voice", MAX_STREAM_TYPE_LEN);
324 case VOLUME_TYPE_VOIP:
325 MMSOUND_STRNCPY(stream_type, "voip", MAX_STREAM_TYPE_LEN);
327 case VOLUME_TYPE_VOICE:
328 MMSOUND_STRNCPY(stream_type, "voice-information", MAX_STREAM_TYPE_LEN);
331 MMSOUND_STRNCPY(stream_type, "media", MAX_STREAM_TYPE_LEN);
335 debug_msg("volume type (%d) converted to stream type (%s)", volume_type, stream_type);
339 /*****************************************************************************************
340 DBUS SUPPORTED FUNCTIONS
341 ******************************************************************************************/
343 void _mm_sound_client_focus_signal_callback(mm_sound_signal_name_t signal, int value, void *user_data)
345 int ret = MM_ERROR_NONE;
348 debug_msg("focus signal received, value = %d", value);
351 ret = mm_sound_proxy_clear_focus(getpid());
353 debug_error("clear focus failed ret = 0x%x", ret);
354 mm_sound_unsubscribe_signal(g_focus_signal_handle);
355 g_focus_signal_handle = 0;
360 int mm_sound_client_play_tone(int number, int volume_config, double volume,
361 int time, int *handle, bool enable_session)
363 int ret = MM_ERROR_NONE;
364 // int instance = -1; /* instance is unique to communicate with server : client message queue filter type */
365 int volume_type = MM_SOUND_VOLUME_CONFIG_TYPE(volume_config);
366 char stream_type[MAX_STREAM_TYPE_LEN] = {0, };
370 /* read session information */
371 int session_type = MM_SESSION_TYPE_MEDIA;
372 int session_options = 0;
373 int is_focus_registered = 0;
375 ret = mm_sound_get_signal_value(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &is_focus_registered);
377 debug_error("mm_sound_get_signal_value failed [0x%x]", ret);
378 return MM_ERROR_POLICY_INTERNAL;
381 if (is_focus_registered)
382 enable_session = false;
384 if (enable_session) {
385 if (MM_ERROR_NONE != _mm_session_util_read_information(-1, &session_type, &session_options)) {
386 debug_warning("Read Session Information failed. use default \"media\" type");
387 session_type = MM_SESSION_TYPE_MEDIA;
389 if (MM_ERROR_NONE != mm_session_init(session_type)) {
390 debug_critical("MMSessionInit() failed");
391 return MM_ERROR_POLICY_INTERNAL;
396 // instance = getpid();
397 //debug_log("pid for client ::: [%d]", instance);
400 debug_msg("Input number : %d", number);
401 /* Send req memory */
403 mm_sound_convert_volume_type_to_stream_type(volume_type, stream_type);
404 ret = mm_sound_proxy_play_tone(number, time, volume, volume_config,
405 session_type, session_options, getpid(), enable_session, handle, stream_type, -1);
407 if (enable_session && !g_focus_signal_handle) {
408 ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_focus_signal_handle,
409 _mm_sound_client_focus_signal_callback, NULL);
411 debug_error("mm_sound_subscribe_signal failed [0x%x]", ret);
412 return MM_ERROR_POLICY_INTERNAL;
421 int mm_sound_client_play_tone_with_stream_info(int tone, char *stream_type, int stream_id,
422 double volume, int duration, int *handle)
424 int ret = MM_ERROR_NONE;
428 ret = mm_sound_proxy_play_tone_with_stream_info(getpid(), tone, stream_type, stream_id, volume, duration, handle);
434 static void _mm_sound_stop_callback_wrapper_func(int ended_handle, void *userdata)
436 struct callback_data *cb_data = (struct callback_data*) userdata;
437 play_sound_end_callback_data_t *end_cb_data;
439 debug_log("ended_handle : %d", ended_handle);
441 if (cb_data == NULL) {
442 debug_warning("stop callback data null");
446 end_cb_data = (play_sound_end_callback_data_t*) cb_data->extra_data;
448 if (ended_handle == end_cb_data->watching_handle) {
449 debug_log("Interested playing handle end : %d", ended_handle);
450 ((mm_sound_stop_callback_func)(cb_data->user_cb))(cb_data->user_data, ended_handle);
451 if (mm_sound_proxy_remove_play_sound_end_callback(end_cb_data->subs_id) != MM_ERROR_NONE)
452 debug_error("mm_sound_client_dbus_remove_play_file_end_callback failed");
454 debug_log("Not interested playing handle : %d", ended_handle);
458 static void play_end_callback_data_free_func(void *data)
460 struct callback_data *cb_data = (struct callback_data*) data;
463 g_free(cb_data->extra_data);
468 int mm_sound_client_play_sound(MMSoundPlayParam *param, int tone, int *handle)
470 int ret = MM_ERROR_NONE;
471 int session_type = MM_SESSION_TYPE_MEDIA;
472 int session_options = 0;
473 int is_focus_registered = 0;
474 // int instance = -1; /* instance is unique to communicate with server : client message queue filter type */
475 int volume_type = MM_SOUND_VOLUME_CONFIG_TYPE(param->volume_config);
476 char stream_type[MAX_STREAM_TYPE_LEN] = {0, };
477 struct callback_data *cb_data = NULL;
478 play_sound_end_callback_data_t *end_cb_data;
482 /* read session information */
484 ret = mm_sound_get_signal_value(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &is_focus_registered);
486 debug_error("mm_sound_get_signal_value failed [0x%x]", ret);
487 return MM_ERROR_POLICY_INTERNAL;
490 if (is_focus_registered)
491 param->skip_session = true;
493 if (param->skip_session == false) {
494 if (MM_ERROR_NONE != _mm_session_util_read_information(-1, &session_type, &session_options)) {
495 debug_warning("Read MMSession Type failed. use default \"media\" type");
496 session_type = MM_SESSION_TYPE_MEDIA;
498 if (MM_ERROR_NONE != mm_session_init(session_type)) {
499 debug_critical("MMSessionInit() failed");
500 return MM_ERROR_POLICY_INTERNAL;
506 if ((param->mem_ptr && param->mem_size)) {
507 // Play memory, deprecated
508 return MM_ERROR_INVALID_ARGUMENT;
511 mm_sound_convert_volume_type_to_stream_type(volume_type, stream_type);
512 ret = mm_sound_proxy_play_sound(param->filename, tone, param->loop, param->volume, param->volume_config,
513 session_type, session_options, getpid(), param->skip_session, handle, stream_type, -1);
514 if (ret != MM_ERROR_NONE) {
515 debug_error("Play Sound Failed");
518 if (param->callback) {
519 end_cb_data = (play_sound_end_callback_data_t *) g_malloc0(sizeof(play_sound_end_callback_data_t));
520 end_cb_data->watching_handle = *handle;
521 GET_CB_DATA(cb_data, param->callback, param->data, end_cb_data);
523 ret = mm_sound_proxy_add_play_sound_end_callback(_mm_sound_stop_callback_wrapper_func, cb_data,
524 play_end_callback_data_free_func, &end_cb_data->subs_id);
525 if (ret != MM_ERROR_NONE)
526 debug_error("Add callback for play sound(%d) Failed", *handle);
529 if (!param->skip_session && !g_focus_signal_handle) {
530 ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_focus_signal_handle,
531 _mm_sound_client_focus_signal_callback, NULL);
533 debug_error("mm_sound_subscribe_signal failed [0x%x]", ret);
534 return MM_ERROR_POLICY_INTERNAL;
545 int mm_sound_client_play_sound_with_stream_info(MMSoundPlayParam *param, int *handle, char* stream_type, int stream_id)
547 int ret = MM_ERROR_NONE;
548 struct callback_data *cb_data = NULL;
549 play_sound_end_callback_data_t *end_cb_data;
551 ret = mm_sound_proxy_play_sound_with_stream_info(param->filename, param->loop, param->volume,
552 getpid(), handle, stream_type, stream_id);
553 if (ret != MM_ERROR_NONE) {
554 debug_error("Play Sound Failed");
557 if (param->callback) {
558 end_cb_data = (play_sound_end_callback_data_t *) g_malloc0(sizeof(play_sound_end_callback_data_t));
559 end_cb_data->watching_handle = *handle;
560 GET_CB_DATA(cb_data, param->callback, param->data, end_cb_data);
562 ret = mm_sound_proxy_add_play_sound_end_callback(_mm_sound_stop_callback_wrapper_func, cb_data,
563 play_end_callback_data_free_func, &end_cb_data->subs_id);
564 if (ret != MM_ERROR_NONE)
565 debug_error("Add callback for play sound(%d) Failed", *handle);
575 int mm_sound_client_stop_sound(int handle)
577 int ret = MM_ERROR_NONE;
580 if (handle < 0 || handle > CLIENT_HANDLE_MAX) {
581 ret = MM_ERROR_INVALID_ARGUMENT;
585 ret = mm_sound_proxy_stop_sound(handle);
591 static int _mm_sound_client_device_list_dump(GList *device_list)
593 int ret = MM_ERROR_NONE;
595 mm_sound_device_t *device_node = NULL;
598 debug_error("Device list NULL, cannot dump list");
599 return MM_ERROR_SOUND_INTERNAL;
602 debug_log("======================== device list : start ==========================");
603 for (list = device_list; list != NULL; list = list->next) {
604 device_node = (mm_sound_device_t *)list->data;
606 debug_log(" list idx[%d]: type[%17s], id[%02d], io_direction[%d], state[%d], name[%s]",
607 count++, device_node->type, device_node->id, device_node->io_direction,
608 device_node->state, device_node->name);
611 debug_log("======================== device list : end ============================");
616 int mm_sound_client_get_current_connected_device_list(int device_flags, mm_sound_device_list_t *device_list)
618 int ret = MM_ERROR_NONE;
622 debug_error("Device list NULL");
623 ret = MM_ERROR_COMMON_INVALID_ARGUMENT;
627 if ((ret = mm_sound_proxy_get_current_connected_device_list(device_flags, &device_list->list)) != MM_ERROR_NONE) {
628 debug_error("failed to get current connected device list with dbus, ret[0x%x]", ret);
631 if (!device_list->list) {
632 debug_error("Got device list null");
633 ret = MM_ERROR_SOUND_NO_DATA;
636 _mm_sound_client_device_list_dump(device_list->list);
643 int mm_sound_client_get_device_by_id(int device_id, mm_sound_device_t **device)
645 int ret = MM_ERROR_NONE;
649 if ((ret = mm_sound_proxy_get_device_by_id(device_id, device)) != MM_ERROR_NONE)
650 debug_error("failed to get device by id");
657 static bool device_is_match_direction(int direction, int mask)
659 if (mask == DEVICE_IO_DIRECTION_FLAGS || mask == 0)
662 if ((mask & MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG) && (direction & MM_SOUND_DEVICE_IO_DIRECTION_IN))
664 if ((mask & MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG) && (direction & MM_SOUND_DEVICE_IO_DIRECTION_OUT))
666 if ((mask & MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG) && (direction == MM_SOUND_DEVICE_IO_DIRECTION_BOTH))
672 static bool device_is_match_state(int state, int mask)
674 if (mask == DEVICE_STATE_FLAGS || mask == 0)
677 if ((mask & MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG) && (state == MM_SOUND_DEVICE_STATE_DEACTIVATED))
679 if ((mask & MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG) && (state == MM_SOUND_DEVICE_STATE_ACTIVATED))
685 static bool device_is_match_type(const char *type, int mask)
688 const char *builtin_prefix = "builtin";
690 if (mask == DEVICE_TYPE_FLAGS || mask == 0)
693 is_builtin = !strncmp(type, builtin_prefix, strlen(builtin_prefix));
695 if ((mask & MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG) && (is_builtin))
697 if ((mask & MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG) && (!is_builtin))
703 static bool device_is_match_with_mask(const char *type, int direction, int state, int mask)
705 if (mask == DEVICE_ALL_FLAG)
708 return (device_is_match_direction(direction, mask & DEVICE_IO_DIRECTION_FLAGS) &&
709 device_is_match_state(state, mask & DEVICE_STATE_FLAGS) &&
710 device_is_match_type(type, mask & DEVICE_TYPE_FLAGS));
713 static int _fill_sound_device(mm_sound_device_t *device_h, int device_id, const char *device_type,
714 int direction, int state, const char *name, int vendor_id, int product_id,
715 int *stream_id, int stream_num, bool is_running)
719 if (stream_num > 0 && stream_id == NULL) {
720 debug_error("stream_num is %d, but stream_id is NULL", stream_num);
724 if (stream_num > MAX_STREAM_ON_DEVICE) {
725 debug_error("too many streams on this device");
729 device_h->id = device_id;
730 device_h->io_direction = direction;
731 device_h->state = state;
732 MMSOUND_STRNCPY(device_h->name, name, MAX_DEVICE_NAME_NUM);
733 MMSOUND_STRNCPY(device_h->type, device_type, MAX_DEVICE_TYPE_STR_LEN);
734 device_h->vendor_id = vendor_id;
735 device_h->product_id = product_id;
736 device_h->is_running = is_running;
738 if (stream_num > 0) {
739 device_h->stream_num = stream_num;
740 debug_log("%d streams on this device", stream_num);
741 for (i = 0; i < stream_num; i++) {
742 debug_log(" stream_id : %d", stream_id[i]);
743 device_h->stream_id[i] = stream_id[i];
746 device_h->stream_num = 0;
747 debug_log("There is no stream on this device");
753 static void _mm_sound_device_connected_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
754 int state, const char *name, int vendor_id, int product_id, bool is_running,
755 int *stream_id, int stream_num, bool is_connected, void *userdata)
757 mm_sound_device_t device_h;
758 struct callback_data *cb_data = (struct callback_data*) userdata;
761 debug_log("[Device %s] id(%d) type(%s) direction(%d) state(%d) name(%s) is_running(%d) vendor-id(%04x) product-id(%04x)",
762 is_connected ? "Connected" : "Disconnected", device_id, device_type, io_direction, state, name,
763 is_running, vendor_id, product_id);
765 if (cb_data == NULL) {
766 debug_warning("device connected changed callback data null");
770 device_flags = (int) cb_data->extra_data;
771 if (!device_is_match_with_mask(device_type, io_direction, state, device_flags))
774 if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name,
775 vendor_id, product_id, stream_id, stream_num, is_running) < 0) {
776 debug_error("Failed to fill sound device");
780 ((mm_sound_device_connected_cb)(cb_data->user_cb))(&device_h, is_connected, cb_data->user_data);
783 int mm_sound_client_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func,
784 void* userdata, unsigned int *subs_id)
786 int ret = MM_ERROR_NONE;
787 struct callback_data *cb_data = NULL;
791 GET_CB_DATA(cb_data, func, userdata, (void*) device_flags);
793 ret = mm_sound_proxy_add_device_connected_callback(_mm_sound_device_connected_callback_wrapper_func,
794 cb_data, g_free, subs_id);
795 if (ret == MM_ERROR_NONE)
796 g_need_emergent_exit = TRUE;
802 int mm_sound_client_remove_device_connected_callback(unsigned int subs_id)
804 int ret = MM_ERROR_NONE;
807 ret = mm_sound_proxy_remove_device_connected_callback(subs_id);
813 static void _mm_sound_device_info_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
814 int state, const char *name, int vendor_id, int product_id, bool is_running,
815 int *stream_id, int stream_num, int changed_device_info_type, void *userdata)
817 mm_sound_device_t device_h;
818 struct callback_data *cb_data = (struct callback_data*) userdata;
821 debug_log("[Device Info Changed] id(%d) type(%s) direction(%d) state(%d) name(%s) is_running(%d) "
822 "vendor-id(%04x) product-id(%04x) changed_info_type(%d)",
823 device_id, device_type, io_direction, state, name, is_running, vendor_id, product_id, changed_device_info_type);
825 if (cb_data == NULL) {
826 debug_warning("device info changed callback data null");
830 device_flags = (int) cb_data->extra_data;
831 if (!device_is_match_with_mask(device_type, io_direction, state, device_flags))
834 if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name,
835 vendor_id, product_id, stream_id, stream_num, is_running) < 0) {
836 debug_error("Failed to fill sound device");
840 ((mm_sound_device_info_changed_cb)(cb_data->user_cb))(&device_h, changed_device_info_type, cb_data->user_data);
843 int mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func,
844 void *userdata, unsigned int *subs_id)
846 int ret = MM_ERROR_NONE;
847 struct callback_data *cb_data = (struct callback_data*) userdata;
851 GET_CB_DATA(cb_data, func, userdata, (void *) device_flags);
853 ret = mm_sound_proxy_add_device_info_changed_callback(_mm_sound_device_info_changed_callback_wrapper_func,
854 cb_data, g_free, subs_id);
860 int mm_sound_client_remove_device_info_changed_callback(unsigned int subs_id)
862 int ret = MM_ERROR_NONE;
865 ret = mm_sound_proxy_remove_device_info_changed_callback(subs_id);
872 static void _mm_sound_device_state_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
873 int state, const char *name, int vendor_id, int product_id,
874 bool is_running, int *stream_id, int stream_num, void *userdata)
876 mm_sound_device_t device_h;
877 struct callback_data *cb_data = (struct callback_data*) userdata;
880 debug_log("[Device State Changed] id(%d) type(%s) direction(%d) state(%d) name(%s) is_running(%d) vendor-id(%04x) product-id(%04x)",
881 device_id, device_type, io_direction, state, name, is_running, vendor_id, product_id);
883 if (cb_data == NULL) {
884 debug_warning("device state changed callback data null");
888 device_flags = (int) cb_data->extra_data;
890 if (!device_is_match_with_mask(device_type, io_direction, state, device_flags))
893 if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name,
894 vendor_id, product_id, stream_id, stream_num, is_running) < 0) {
895 debug_error("Failed to fill sound device");
899 ((mm_sound_device_state_changed_cb)(cb_data->user_cb))(&device_h, state, cb_data->user_data);
902 int mm_sound_client_add_device_state_changed_callback(int device_flags, mm_sound_device_state_changed_cb func,
903 void *userdata, unsigned int *id)
905 int ret = MM_ERROR_NONE;
906 struct callback_data *cb_data = (struct callback_data*) userdata;
910 GET_CB_DATA(cb_data, func, userdata, (void *) device_flags);
912 ret = mm_sound_proxy_add_device_state_changed_callback(_mm_sound_device_state_changed_callback_wrapper_func,
913 cb_data, g_free, id);
919 int mm_sound_client_remove_device_state_changed_callback(unsigned int id)
921 int ret = MM_ERROR_NONE;
924 ret = mm_sound_proxy_remove_device_state_changed_callback(id);
930 static void _mm_sound_device_running_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
931 int state, const char *name, int vendor_id, int product_id,
932 bool is_running, int *stream_id, int stream_num, void *userdata)
934 mm_sound_device_t device_h;
935 struct callback_data *cb_data = (struct callback_data*) userdata;
938 debug_log("[Device Running Changed] id(%d) type(%s) direction(%d) state(%d) name(%s) is_running(%d) vendor-id(%04x), product-id(%04x)",
939 device_id, device_type, io_direction, state, name, is_running, vendor_id, product_id);
941 if (cb_data == NULL) {
942 debug_warning("device running changed callback data null");
946 device_flags = (int) cb_data->extra_data;
948 if (!device_is_match_with_mask(device_type, io_direction, state, device_flags))
951 if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name,
952 vendor_id, product_id, stream_id, stream_num, is_running) < 0) {
953 debug_error("Failed to fill sound device");
957 ((mm_sound_device_running_changed_cb)(cb_data->user_cb))(&device_h, is_running, cb_data->user_data);
960 int mm_sound_client_add_device_running_changed_callback(int device_flags, mm_sound_device_running_changed_cb func,
961 void *userdata, unsigned int *id)
963 int ret = MM_ERROR_NONE;
964 struct callback_data *cb_data = (struct callback_data*) userdata;
968 GET_CB_DATA(cb_data, func, userdata, (void *) device_flags);
970 ret = mm_sound_proxy_add_device_running_changed_callback(_mm_sound_device_running_changed_callback_wrapper_func,
971 cb_data, g_free, id);
977 int mm_sound_client_remove_device_running_changed_callback(unsigned int id)
979 int ret = MM_ERROR_NONE;
982 ret = mm_sound_proxy_remove_device_running_changed_callback(id);
988 int mm_sound_client_is_stream_on_device(int stream_id, int device_id, bool *is_on)
990 int ret = MM_ERROR_NONE;
994 debug_error("Invalid Parameter");
995 ret = MM_ERROR_COMMON_INVALID_ARGUMENT;
999 if ((ret = mm_sound_proxy_is_stream_on_device(stream_id, device_id, is_on)) != MM_ERROR_NONE) {
1000 debug_error("failed to query is stream on device, ret[0x%x]", ret);
1009 int __convert_volume_type_to_str(int volume_type, char **volume_type_str)
1011 int ret = MM_ERROR_NONE;
1013 if (!volume_type_str)
1014 return MM_ERROR_COMMON_INVALID_ARGUMENT;
1016 switch (volume_type) {
1017 case VOLUME_TYPE_SYSTEM:
1018 *volume_type_str = "system";
1020 case VOLUME_TYPE_NOTIFICATION:
1021 *volume_type_str = "notification";
1023 case VOLUME_TYPE_ALARM:
1024 *volume_type_str = "alarm";
1026 case VOLUME_TYPE_RINGTONE:
1027 *volume_type_str = "ringtone";
1029 case VOLUME_TYPE_MEDIA:
1030 *volume_type_str = "media";
1032 case VOLUME_TYPE_CALL:
1033 *volume_type_str = "call";
1035 case VOLUME_TYPE_VOIP:
1036 *volume_type_str = "voip";
1038 case VOLUME_TYPE_VOICE:
1039 *volume_type_str = "voice";
1042 debug_error("unexpected volume type [%d]", volume_type);
1043 return MM_ERROR_SOUND_INTERNAL;
1045 if (!strncmp(*volume_type_str, "", VOLUME_TYPE_LEN)) {
1046 debug_error("could not find the volume_type[%d] in this switch case statement", volume_type);
1047 ret = MM_ERROR_SOUND_INTERNAL;
1049 debug_log("volume_type[%s]", *volume_type_str);
1054 static int __convert_volume_type_to_int(const char *volume_type_str, volume_type_t *volume_type)
1056 int ret = MM_ERROR_NONE;
1058 if (!volume_type || !volume_type_str)
1059 return MM_ERROR_COMMON_INVALID_ARGUMENT;
1061 if (!strncmp(volume_type_str, "system", VOLUME_TYPE_LEN)) {
1062 *volume_type = VOLUME_TYPE_SYSTEM;
1063 } else if (!strncmp(volume_type_str, "notification", VOLUME_TYPE_LEN)) {
1064 *volume_type = VOLUME_TYPE_NOTIFICATION;
1065 } else if (!strncmp(volume_type_str, "alarm", VOLUME_TYPE_LEN)) {
1066 *volume_type = VOLUME_TYPE_ALARM;
1067 } else if (!strncmp(volume_type_str, "ringtone", VOLUME_TYPE_LEN)) {
1068 *volume_type = VOLUME_TYPE_RINGTONE;
1069 } else if (!strncmp(volume_type_str, "media", VOLUME_TYPE_LEN)) {
1070 *volume_type = VOLUME_TYPE_MEDIA;
1071 } else if (!strncmp(volume_type_str, "call", VOLUME_TYPE_LEN)) {
1072 *volume_type = VOLUME_TYPE_CALL;
1073 } else if (!strncmp(volume_type_str, "voip", VOLUME_TYPE_LEN)) {
1074 *volume_type = VOLUME_TYPE_VOIP;
1075 } else if (!strncmp(volume_type_str, "voice", VOLUME_TYPE_LEN)) {
1076 *volume_type = VOLUME_TYPE_VOICE;
1078 debug_log("Invalid volume type : [%s]", volume_type_str);
1079 ret = MM_ERROR_SOUND_INTERNAL;
1085 int mm_sound_client_set_volume_by_type(const int volume_type, const unsigned int volume_level)
1087 int ret = MM_ERROR_NONE;
1088 char *type_str = NULL;
1091 if ((ret = __convert_volume_type_to_str(volume_type, &type_str)) != MM_ERROR_NONE) {
1092 debug_error("volume type convert failed");
1096 ret = mm_sound_proxy_set_volume_by_type(type_str, volume_level);
1103 static void _mm_sound_volume_changed_callback_wrapper_func(const char *direction, const char *volume_type_str,
1104 int volume_level, void *userdata)
1106 volume_type_t volume_type = 0;
1107 struct callback_data *cb_data = (struct callback_data *) userdata;
1109 debug_log("direction : %s, volume_type : %s, volume_level : %d",
1110 direction, volume_type_str, volume_level);
1112 if (cb_data == NULL) {
1113 debug_warning("volume changed callback data null");
1117 if (__convert_volume_type_to_int(volume_type_str, &volume_type) != MM_ERROR_NONE) {
1118 debug_error("volume type convert failed");
1121 debug_log("Call volume changed user cb, direction : %s, vol_type : %s(%d), level : %u",
1122 direction, volume_type_str, volume_type, volume_level);
1123 ((mm_sound_volume_changed_cb)(cb_data->user_cb))(volume_type, volume_level, cb_data->user_data);
1126 int mm_sound_client_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* userdata, unsigned int *subs_id)
1128 int ret = MM_ERROR_NONE;
1129 struct callback_data *cb_data = NULL;
1133 GET_CB_DATA(cb_data, func, userdata, NULL);
1135 ret = mm_sound_proxy_add_volume_changed_callback(_mm_sound_volume_changed_callback_wrapper_func, cb_data, g_free, subs_id);
1142 int mm_sound_client_remove_volume_changed_callback(unsigned int subs_id)
1144 int ret = MM_ERROR_NONE;
1147 ret = mm_sound_proxy_remove_volume_changed_callback(subs_id);
1153 int mm_sound_client_set_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_parameters, const char *filter_group)
1155 int ret = MM_ERROR_NONE;
1158 ret = mm_sound_proxy_set_filter_by_type(stream_type, filter_name, filter_parameters, filter_group);
1164 int mm_sound_client_unset_filter_by_type(const char *stream_type)
1166 int ret = MM_ERROR_NONE;
1169 ret = mm_sound_proxy_unset_filter_by_type(stream_type);
1175 int mm_sound_client_control_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_controls)
1177 int ret = MM_ERROR_NONE;
1180 ret = mm_sound_proxy_control_filter_by_type(stream_type, filter_name, filter_controls);
1187 static gboolean _interrupted_completed(gpointer *data)
1190 debug_error("data is null");
1193 if (!g_focus_session_interrupt_info.user_cb) {
1194 debug_error("user_cb is null");
1199 debug_msg("invoke user_cb(%p)", g_focus_session_interrupt_info.user_cb);
1200 (g_focus_session_interrupt_info.user_cb)(FOCUS_IS_RELEASED, (const char *)data, g_focus_session_interrupt_info.user_data);
1201 debug_msg("invoked");
1207 static void _session_interrupted_cb(int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state,
1208 const char *reason_for_change, const char *ext_info, void *user_data)
1210 debug_msg("id(%d), focus_type(%d), state(%d), reason(%s)", id, focus_type, state, reason_for_change);
1212 if (id != g_focus_session_interrupt_info.watch_cb_id) {
1213 debug_error("id is not valid(param id:%d, g_focus_session_interrupt_watch_cb_id:%d)",
1214 id, g_focus_session_interrupt_info.watch_cb_id);
1217 if (!g_focus_session_interrupt_info.user_cb) {
1218 debug_error("user callback is null");
1222 debug_msg(" >>> invoking session interrupt callback(%p)", g_focus_session_interrupt_info.user_cb);
1223 if (state == FOCUS_IS_RELEASED)
1224 (g_focus_session_interrupt_info.user_cb)(FOCUS_IS_ACQUIRED, reason_for_change, g_focus_session_interrupt_info.user_data);
1226 debug_msg("INTERRUPTED COMPLETED case, append it to idle");
1227 g_idle_add((GSourceFunc)_interrupted_completed, strdup(reason_for_change));
1229 debug_msg(" <<< session interrupt callback finished");
1232 int mm_sound_client_set_session_interrupt_callback(mm_sound_focus_session_interrupt_cb callback, void* user_data)
1234 int ret = MM_ERROR_NONE;
1239 return MM_ERROR_INVALID_ARGUMENT;
1241 /* add internal focus watch callback */
1242 if (g_focus_session_interrupt_info.watch_cb_id == -1) {
1243 if ((ret = mm_sound_client_set_focus_watch_callback(getpid(), FOCUS_FOR_BOTH, true, true, _session_interrupted_cb, NULL,
1244 &g_focus_session_interrupt_info.watch_cb_id))) {
1245 debug_error("failed to mm_sound_client_set_focus_watch_callback(), ret(0x%x)", ret);
1249 g_focus_session_interrupt_info.user_cb = callback;
1250 g_focus_session_interrupt_info.user_data = user_data;
1256 int mm_sound_client_unset_session_interrupt_callback(void)
1258 int ret = MM_ERROR_NONE;
1262 if (!g_focus_session_interrupt_info.user_cb || g_focus_session_interrupt_info.watch_cb_id == -1) {
1263 debug_error("no callback to unset");
1264 return MM_ERROR_SOUND_INTERNAL;
1267 /* remove internal focus watch callback */
1268 if ((ret = mm_sound_client_unset_focus_watch_callback(g_focus_session_interrupt_info.watch_cb_id))) {
1269 debug_error("failed to mm_sound_client_unset_focus_watch_callback(), id(%d), ret(0x%x)",
1270 g_focus_session_interrupt_info.watch_cb_id, ret);
1273 g_focus_session_interrupt_info.watch_cb_id = -1;
1274 g_focus_session_interrupt_info.user_cb = NULL;
1275 g_focus_session_interrupt_info.user_data = NULL;
1281 static gpointer _focus_thread_func(gpointer data)
1283 unsigned int thread_id = (unsigned int)pthread_self();
1284 GMainLoop *focus_loop = (GMainLoop*)data;
1286 debug_warning(">>> thread id(%u), mainloop[%p]", thread_id, focus_loop);
1288 g_main_loop_run(focus_loop);
1289 debug_warning("<<< quit : thread id(%u), mainloop[%p]", thread_id, focus_loop);
1294 static gboolean _focus_fd_prepare(GSource *source, gint *timeout)
1297 debug_warning("[ PREPARE : %p, (%p, %d)", source, timeout, timeout ? *timeout : -1);
1302 static gboolean _focus_fd_check(GSource * source)
1304 FocusSource* fsource = (FocusSource *)source;
1307 debug_error("GSource is null");
1311 debug_warning("CHECK : %p, 0x%x ]", source, fsource->pollfd.revents);
1313 if (fsource->poll_fd.revents & (POLLIN | POLLPRI))
1319 static gboolean _focus_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
1321 debug_warning("*** DISPATCH : %p, (%p, %p)", source, callback, user_data);
1322 return callback(user_data);
1325 static void _focus_fd_finalize(GSource *source)
1327 debug_warning("### FINALIZE : %p", source);
1330 static int _focus_find_index_by_handle(int handle)
1333 for (i = 0; i < FOCUS_HANDLE_MAX; i++) {
1334 if (g_focus_sound_handle[i].focus_callback && handle == g_focus_sound_handle[i].handle) {
1335 /* debug_msg("found index(%d) for handle(%d)", i, handle);*/
1336 return (handle == FOCUS_HANDLE_INIT_VAL) ? -1 : i;
1342 static int _focus_watch_find_index_by_handle(int handle)
1345 for (i = 0; i < FOCUS_HANDLE_MAX; i++) {
1346 if (g_focus_sound_handle[i].watch_callback && handle == g_focus_sound_handle[i].handle) {
1347 /* debug_msg("found index(%d) for watch handle(%d)", i, handle);*/
1348 return (handle == FOCUS_HANDLE_INIT_VAL) ? -1 : i;
1354 static gboolean _focus_callback_handler(gpointer user_data)
1356 focus_sound_info_t *focus_handle = (focus_sound_info_t *)user_data;
1360 focus_cb_data_lib cb_data;
1362 debug_log(">>> thread id(%u)", (unsigned int)pthread_self());
1364 if (!focus_handle) {
1365 debug_error("focus_handle is null");
1366 return G_SOURCE_CONTINUE;
1368 poll_fd = &focus_handle->fsrc->poll_fd;
1369 debug_log("focus_handle(%p), poll_fd(%p)", focus_handle, poll_fd);
1371 memset(&cb_data, 0, sizeof(focus_cb_data_lib));
1373 if (poll_fd->revents & (POLLIN | POLLPRI)) {
1374 int changed_state = -1;
1376 count = read(poll_fd->fd, &cb_data, sizeof(cb_data));
1378 char str_error[256];
1379 strerror_r(errno, str_error, sizeof(str_error));
1380 debug_error("GpollFD read fail, errno=%d(%s)", errno, str_error);
1381 return G_SOURCE_CONTINUE;
1383 changed_state = cb_data.state;
1385 g_mutex_lock(&focus_handle->focus_lock);
1387 tid = focus_handle->focus_tid;
1389 if (changed_state != -1) {
1390 debug_msg("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)",
1391 tid, cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type);
1392 if (focus_handle->focus_callback == NULL) {
1393 debug_error("focus callback is null..");
1394 g_mutex_unlock(&focus_handle->focus_lock);
1395 return G_SOURCE_CONTINUE;
1397 debug_msg("[CALLBACK(%p) START]", focus_handle->focus_callback);
1398 (focus_handle->focus_callback)(cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type,
1399 cb_data.option, cb_data.ext_info, focus_handle->user_data);
1400 debug_msg("[CALLBACK END]");
1402 #ifdef CONFIG_ENABLE_RETCB
1406 unsigned int buf = 0;
1407 char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", focus_handle->focus_tid, cb_data.handle);
1408 tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
1410 char str_error[256];
1411 strerror_r(errno, str_error, sizeof(str_error));
1412 debug_warning("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)",
1413 tid, tmpfd, filename2, errno, str_error);
1415 g_mutex_unlock(&focus_handle->focus_lock);
1416 return G_SOURCE_CONTINUE;
1418 /* buf contains data as below,
1419 * |<--12bits--><--4bits (reacquisition)--><--16bits (handle)-->| */
1420 buf = (unsigned int)((0x0000ffff & cb_data.handle) | (focus_handle->auto_reacquire << 16));
1421 rett = write(tmpfd, &buf, sizeof(buf));
1424 debug_msg("[RETCB] tid(%d) finishing CB (write=%d)", tid, rett);
1429 g_mutex_unlock(&focus_handle->focus_lock);
1433 return G_SOURCE_CONTINUE;
1436 static gboolean _focus_watch_callback_handler(gpointer user_data)
1438 focus_sound_info_t *focus_handle = (focus_sound_info_t *)user_data;
1442 focus_cb_data_lib cb_data;
1444 debug_log(">>> thread id(%u)", (unsigned int)pthread_self());
1446 if (!focus_handle) {
1447 debug_error("focus_handle is null");
1448 return G_SOURCE_CONTINUE;
1450 poll_fd = &focus_handle->fsrc->poll_fd;
1451 debug_log("focus_handle(%p), poll_fd(%p)", focus_handle, poll_fd);
1453 memset(&cb_data, 0, sizeof(focus_cb_data_lib));
1455 if (poll_fd->revents & (POLLIN | POLLPRI)) {
1456 count = read(poll_fd->fd, &cb_data, sizeof(cb_data));
1458 char str_error[256];
1459 strerror_r(errno, str_error, sizeof(str_error));
1460 debug_error("GpollFD read fail, errno=%d(%s)", errno, str_error);
1461 return G_SOURCE_CONTINUE;
1464 if (!focus_handle->is_used) {
1465 debug_warning("unsetting watch calllback has been already requested");
1466 goto SKIP_CB_AND_RET;
1469 g_mutex_lock(&focus_handle->focus_lock);
1471 tid = focus_handle->focus_tid;
1473 debug_msg("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)",
1474 tid, cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type);
1476 if (focus_handle->watch_callback == NULL) {
1477 debug_warning("watch callback is null..");
1478 goto SKIP_CB_AND_RET;
1480 if (focus_handle->unset_watch_callback_requested == true) {
1481 debug_warning("unset_watch_callback_requested..");
1482 goto SKIP_CB_AND_RET;
1485 debug_msg("[CALLBACK(%p) START]", focus_handle->watch_callback);
1486 (focus_handle->watch_callback)(cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type,
1487 cb_data.ext_info, focus_handle->user_data);
1488 debug_msg("[CALLBACK END]");
1491 #ifdef CONFIG_ENABLE_RETCB
1496 char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr", focus_handle->focus_tid, cb_data.handle);
1497 tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
1499 char str_error[256];
1500 strerror_r(errno, str_error, sizeof(str_error));
1501 debug_warning("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)",
1502 tid, tmpfd, filename2, errno, str_error);
1504 g_mutex_unlock(&focus_handle->focus_lock);
1505 return G_SOURCE_CONTINUE;
1507 buf = cb_data.handle;
1508 rett = write(tmpfd, &buf, sizeof(buf));
1511 debug_msg("[RETCB] tid(%d) finishing CB (write=%d)", tid, rett);
1516 if (focus_handle->is_used) {
1517 debug_msg("unlock focus_lock = %p", &focus_handle->focus_lock);
1518 g_mutex_unlock(&focus_handle->focus_lock);
1523 return G_SOURCE_CONTINUE;
1526 static void _focus_open_callback(int index, bool is_for_watching)
1533 if (index < 0 || index >= FOCUS_HANDLE_MAX) {
1534 debug_error("Invalid focus handle index [%d]", index);
1538 if (is_for_watching) {
1539 filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wch",
1540 g_focus_sound_handle[index].focus_tid,
1541 g_focus_sound_handle[index].handle);
1543 filename = g_strdup_printf("/tmp/FOCUS.%d.%d",
1544 g_focus_sound_handle[index].focus_tid,
1545 g_focus_sound_handle[index].handle);
1547 pre_mask = umask(0);
1548 if (mknod(filename, S_IFIFO|0666, 0))
1549 debug_error("mknod() failure, errno(%d)", errno);
1551 g_focus_sound_handle[index].focus_fd = open(filename, O_RDWR|O_NONBLOCK);
1552 if (g_focus_sound_handle[index].focus_fd == -1) {
1553 debug_error("Open fail : index(%d), file open error(%d)", index, errno);
1555 debug_log("Open success : index(%d), filename(%s), fd(%d)",
1556 index, filename, g_focus_sound_handle[index].focus_fd);
1561 #ifdef CONFIG_ENABLE_RETCB
1564 if (is_for_watching) {
1565 filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr",
1566 g_focus_sound_handle[index].focus_tid,
1567 g_focus_sound_handle[index].handle);
1569 filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr",
1570 g_focus_sound_handle[index].focus_tid,
1571 g_focus_sound_handle[index].handle);
1573 pre_mask = umask(0);
1574 if (mknod(filename2, S_IFIFO | 0666, 0))
1575 debug_error("mknod() failure, errno(%d)", errno);
1584 void _focus_close_callback(int index, bool is_for_watching)
1586 char *filename = NULL;
1590 if (index < 0 || index >= FOCUS_HANDLE_MAX) {
1591 debug_error("Invalid focus handle index [%d]", index);
1595 if (g_focus_sound_handle[index].focus_fd < 0) {
1596 debug_error("Close fail : index(%d)", index);
1598 close(g_focus_sound_handle[index].focus_fd);
1599 debug_log("Close Success : index(%d)", index);
1602 if (is_for_watching) {
1603 filename = g_strdup_printf("/tmp/FOCUS.%d.%d.wch",
1604 g_focus_sound_handle[index].focus_tid,
1605 g_focus_sound_handle[index].handle);
1607 filename = g_strdup_printf("/tmp/FOCUS.%d.%d",
1608 g_focus_sound_handle[index].focus_tid,
1609 g_focus_sound_handle[index].handle);
1611 if (remove(filename)) {
1612 debug_warning("remove(%s) failure (focus_server probably removed it in advance), errno(%d)",
1618 #ifdef CONFIG_ENABLE_RETCB
1621 if (is_for_watching) {
1622 filename2 = g_strdup_printf("/tmp/FOCUS.%d.%d.wchr",
1623 g_focus_sound_handle[index].focus_tid,
1624 g_focus_sound_handle[index].handle);
1626 filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr",
1627 g_focus_sound_handle[index].focus_tid,
1628 g_focus_sound_handle[index].handle);
1630 if (remove(filename2)) {
1631 debug_warning("remove(%s) failure (focus_server probably removed it in advance), errno(%d)",
1642 static GSourceFuncs event_funcs = {
1643 .prepare = _focus_fd_prepare,
1644 .check = _focus_fd_check,
1645 .dispatch = _focus_fd_dispatch,
1646 .finalize = _focus_fd_finalize,
1649 static bool _focus_add_sound_callback(int index, focus_callback_handler_t focus_cb_handler)
1651 FocusSource *fsrc = NULL;
1652 GSource *src = NULL;
1657 g_mutex_init(&g_focus_sound_handle[index].focus_lock);
1659 src = g_source_new(&event_funcs, sizeof(FocusSource));
1661 debug_error("failed to g_source_new for focus source");
1665 fsrc = (FocusSource*) src;
1667 fsrc->poll_fd.fd = g_focus_sound_handle[index].focus_fd;
1668 fsrc->poll_fd.events = (gushort)(POLLIN | POLLPRI);
1669 g_source_add_poll(src, &fsrc->poll_fd);
1671 g_source_set_callback(src, focus_cb_handler, (gpointer)&g_focus_sound_handle[index], NULL);
1673 debug_warning("fsrc(%p), src_funcs(%p), pollfd(%p), fd(%d)",
1674 fsrc, &event_funcs, &fsrc->poll_fd, fsrc->poll_fd.fd);
1676 fsrc_id = g_source_attach(src, g_main_loop_get_context(g_focus_sound_handle[index].focus_loop));
1678 debug_error("failed to attach the source to context");
1681 g_source_unref(src);
1683 g_focus_sound_handle[index].fsrc = fsrc;
1690 g_source_unref(src);
1695 static bool _focus_remove_sound_callback(int index)
1697 focus_sound_info_t *h = NULL;
1701 if (index < 0 || index >= FOCUS_HANDLE_MAX) {
1702 debug_error("Invalid focus handle index [%d]", index);
1706 h = &g_focus_sound_handle[index];
1708 g_source_destroy((GSource *)h->fsrc);
1712 h->focus_callback = NULL;
1713 h->watch_callback = NULL;
1715 g_mutex_clear(&h->focus_lock);
1722 static void _focus_add_callback(int index, bool is_for_watching)
1726 if (index < 0 || index >= FOCUS_HANDLE_MAX) {
1727 debug_error("Invalid focus handle index [%d]", index);
1731 if (!is_for_watching) {
1732 if (!_focus_add_sound_callback(index, _focus_callback_handler))
1733 debug_error("failed to _focus_add_sound_callback(%p)", _focus_callback_handler);
1734 } else { // need to check if it's necessary
1735 if (!_focus_add_sound_callback(index, _focus_watch_callback_handler))
1736 debug_error("failed to _focus_add_sound_callback(%p)", _focus_watch_callback_handler);
1741 static void _focus_remove_callback(int index)
1744 if (!_focus_remove_sound_callback(index))
1745 debug_error("failed to __focus_remove_sound_callback()");
1749 static void _focus_init_callback(int index, bool is_for_watching)
1752 _focus_open_callback(index, is_for_watching);
1753 _focus_add_callback(index, is_for_watching);
1757 static void _focus_deinit_callback(int index, bool is_for_watching)
1760 _focus_remove_callback(index);
1761 _focus_close_callback(index, is_for_watching);
1765 #define INTERVAL_MS 20
1766 static int _focus_loop_is_running_timed_wait(GMainLoop *focus_loop, int timeout_ms)
1768 int reduced_time_ms = timeout_ms;
1769 if (!focus_loop || timeout_ms < 0) {
1770 debug_error("invalid argument, focus_loop(%p), timeout_ms(%d)", focus_loop, timeout_ms);
1771 return MM_ERROR_INVALID_ARGUMENT;
1775 if (g_main_loop_is_running(focus_loop))
1776 return MM_ERROR_NONE;
1778 usleep(INTERVAL_MS * 1000);
1779 if (reduced_time_ms < timeout_ms)
1780 debug_warning("reduced_time_ms(%d)", reduced_time_ms);
1781 } while ((reduced_time_ms -= INTERVAL_MS) >= 0);
1783 debug_error("focus_loop is not running for timeout_ms(%d), focus_loop(%p) ", timeout_ms, focus_loop);
1785 return MM_ERROR_SOUND_INTERNAL;
1788 #define LOOP_RUNNING_WAIT_TIME_MS 200
1789 static int _focus_init_context(int index)
1791 int ret = MM_ERROR_NONE;
1792 GMainContext *focus_context;
1796 if (index < 0 || index >= FOCUS_HANDLE_MAX) {
1797 debug_error("index(%d) is not valid", index);
1798 return MM_ERROR_INVALID_ARGUMENT;
1801 focus_context = g_main_context_new();
1802 g_focus_sound_handle[index].focus_loop = g_main_loop_new(focus_context, FALSE);
1803 g_main_context_unref(focus_context);
1804 if (g_focus_sound_handle[index].focus_loop == NULL) {
1805 debug_error("could not create mainloop..");
1809 g_focus_sound_handle[index].focus_cb_thread = g_thread_new("focus-cb-thread",
1811 g_focus_sound_handle[index].focus_loop);
1812 if (g_focus_sound_handle[index].focus_cb_thread == NULL) {
1813 debug_error("could not create thread..");
1817 debug_warning("focus cb thread[%p] with mainloop[%p] is created for index(%d)",
1818 g_focus_sound_handle[index].focus_cb_thread, g_focus_sound_handle[index].focus_loop, index);
1820 if ((ret = _focus_loop_is_running_timed_wait(g_focus_sound_handle[index].focus_loop, LOOP_RUNNING_WAIT_TIME_MS))) {
1821 debug_error("failed to _focus_loop_is_running_timed_wait(), ret[0x%x]", ret);
1827 return MM_ERROR_NONE;
1830 if (g_focus_sound_handle[index].focus_loop) {
1831 g_main_loop_unref(g_focus_sound_handle[index].focus_loop);
1832 g_focus_sound_handle[index].focus_loop = NULL;
1834 return MM_ERROR_SOUND_INTERNAL;
1837 static void _focus_deinit_context(int index)
1841 if (index < 0 || index >= FOCUS_HANDLE_MAX) {
1842 debug_error("index(%d) is not valid", index);
1846 if (!g_focus_sound_handle[index].focus_loop || !g_focus_sound_handle[index].focus_cb_thread) {
1847 debug_error("focus_loop[%p] or focus_cb_thread[%p] is null",
1848 g_focus_sound_handle[index].focus_loop, g_focus_sound_handle[index].focus_cb_thread);
1852 g_main_loop_quit(g_focus_sound_handle[index].focus_loop);
1853 g_thread_join(g_focus_sound_handle[index].focus_cb_thread);
1854 debug_warning("after thread join, thread[%p], mainloop[%p] for index(%d)",
1855 g_focus_sound_handle[index].focus_cb_thread, g_focus_sound_handle[index].focus_loop, index);
1856 g_main_loop_unref(g_focus_sound_handle[index].focus_loop);
1857 g_focus_sound_handle[index].focus_loop = NULL;
1858 g_focus_sound_handle[index].focus_cb_thread = NULL;
1863 int mm_sound_client_get_unique_id(int *id)
1865 int ret = MM_ERROR_NONE;
1870 ret = MM_ERROR_INVALID_ARGUMENT;
1872 ret = mm_sound_proxy_get_unique_id(id);
1879 int mm_sound_client_is_focus_cb_thread(GThread *mine, bool *result)
1881 int ret = MM_ERROR_NONE;
1884 if (!mine || !result)
1885 ret = MM_ERROR_INVALID_ARGUMENT;
1888 for (i = 0; i < FOCUS_HANDLE_MAX; i++) {
1889 if (!g_focus_sound_handle[i].is_used)
1891 if (g_focus_sound_handle[i].focus_cb_thread == mine) {
1901 int mm_sound_client_register_focus(int id, int pid, const char *stream_type, bool is_for_session,
1902 mm_sound_focus_changed_cb callback, void* user_data)
1904 int ret = MM_ERROR_NONE;
1909 MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
1913 for (index = 0; index < FOCUS_HANDLE_MAX - 1; index++) {
1914 if (g_focus_sound_handle[index].is_used == false) {
1915 g_focus_sound_handle[index].is_used = true;
1920 g_focus_sound_handle[index].focus_tid = instance;
1921 g_focus_sound_handle[index].handle = id;
1922 g_focus_sound_handle[index].focus_callback = callback;
1923 g_focus_sound_handle[index].user_data = user_data;
1924 g_focus_sound_handle[index].is_for_session = is_for_session;
1925 g_focus_sound_handle[index].auto_reacquire = true;
1927 ret = mm_sound_proxy_register_focus(id, pid, stream_type, callback, is_for_session, user_data);
1928 if (ret == MM_ERROR_NONE) {
1929 debug_msg("Success to register focus");
1930 g_need_emergent_exit = TRUE;
1931 if (_focus_init_context(index)) {
1932 ret = MM_ERROR_SOUND_INTERNAL;
1936 debug_error("Error occurred : 0x%x", ret);
1940 _focus_init_callback(index, false);
1944 g_focus_sound_handle[index].is_used = false;
1946 MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
1952 int mm_sound_client_unregister_focus(int id)
1954 int ret = MM_ERROR_NONE;
1959 MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
1961 index = _focus_find_index_by_handle(id);
1963 debug_error("Could not find index");
1964 ret = MM_ERROR_INVALID_ARGUMENT;
1967 instance = g_focus_sound_handle[index].focus_tid;
1969 if (!g_mutex_trylock(&g_focus_sound_handle[index].focus_lock)) {
1970 debug_warning("maybe focus_callback is being called, try one more time..");
1971 usleep(2500000); // 2.5 sec
1972 if (g_mutex_trylock(&g_focus_sound_handle[index].focus_lock))
1973 debug_msg("finally got focus_lock");
1976 ret = mm_sound_proxy_unregister_focus(instance, id, g_focus_sound_handle[index].is_for_session);
1977 if (ret == MM_ERROR_NONE)
1978 debug_msg("Success to unregister focus");
1980 debug_error("Error occurred : 0x%x", ret);
1982 g_mutex_unlock(&g_focus_sound_handle[index].focus_lock);
1984 _focus_deinit_callback(index, false);
1985 g_focus_sound_handle[index].focus_fd = 0;
1986 g_focus_sound_handle[index].focus_tid = 0;
1987 g_focus_sound_handle[index].handle = 0;
1988 g_focus_sound_handle[index].is_used = false;
1989 _focus_deinit_context(index);
1993 MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
1998 int mm_sound_client_set_focus_reacquisition(int id, bool reacquisition, bool is_for_session)
2000 int ret = MM_ERROR_NONE;
2007 /* Since the muse server which uses this library for multiple handles executes requests from clients serially,
2008 * we can skip locking/unlocking the mutex for this case. */
2009 if (!is_for_session)
2010 MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
2012 index = _focus_find_index_by_handle(id);
2014 debug_error("Could not find index");
2015 ret = MM_ERROR_INVALID_ARGUMENT;
2018 instance = g_focus_sound_handle[index].focus_tid;
2020 ret = mm_sound_client_is_focus_cb_thread(g_thread_self(), &result);
2022 debug_error("mm_sound_client_is_focus_cb_thread failed");
2024 } else if (!result) {
2025 ret = mm_sound_proxy_set_focus_reacquisition(instance, id, reacquisition, is_for_session);
2026 if (ret == MM_ERROR_NONE) {
2027 debug_msg("Success to set focus reacquisition to [%d]", reacquisition);
2029 debug_error("Error occurred : 0x%x", ret);
2033 debug_warning("Inside the focus cb thread, set focus reacquisition to [%d]", reacquisition);
2036 g_focus_sound_handle[index].auto_reacquire = reacquisition;
2037 debug_msg("set focus reacquisition(%d) for id(%d)", reacquisition, id);
2040 if (!is_for_session)
2041 MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
2046 int mm_sound_client_get_focus_reacquisition(int id, bool *reacquisition)
2048 int ret = MM_ERROR_NONE;
2053 if (!reacquisition) {
2054 debug_error("Invalid parameter");
2055 return MM_ERROR_INVALID_ARGUMENT;
2058 MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
2060 index = _focus_find_index_by_handle(id);
2062 debug_error("Could not find index");
2063 ret = MM_ERROR_INVALID_ARGUMENT;
2067 *reacquisition = g_focus_sound_handle[index].auto_reacquire;
2068 debug_msg("get focus reacquisition(%d) for id(%d)", *reacquisition, id);
2071 MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
2076 int mm_sound_client_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
2078 int ret = MM_ERROR_NONE;
2079 char *stream_type_str = NULL;
2080 char *ext_info_str = NULL;
2084 ret = mm_sound_proxy_get_acquired_focus_stream_type(focus_type, &stream_type_str, option, &ext_info_str);
2085 if (ret == MM_ERROR_NONE) {
2086 debug_msg("Success to get stream type of acquired focus, stream_type(%s), ext_info(%s)",
2087 stream_type_str, ext_info_str);
2088 *stream_type = strdup(stream_type_str);
2089 *ext_info = strdup(ext_info_str);
2090 g_free(stream_type_str);
2091 g_free(ext_info_str);
2093 debug_error("Error occurred : 0x%x", ret);
2100 int mm_sound_client_acquire_focus(int id, mm_sound_focus_type_e type, int option, const char *ext_info)
2102 int ret = MM_ERROR_NONE;
2107 MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
2109 index = _focus_find_index_by_handle(id);
2111 debug_error("Could not find index");
2112 ret = MM_ERROR_INVALID_ARGUMENT;
2115 instance = g_focus_sound_handle[index].focus_tid;
2117 ret = mm_sound_proxy_acquire_focus(instance, id, type, option, ext_info, g_focus_sound_handle[index].is_for_session);
2118 if (ret == MM_ERROR_NONE)
2119 debug_msg("Success to acquire focus");
2121 debug_error("Error occurred : 0x%x", ret);
2124 MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
2129 int mm_sound_client_release_focus(int id, mm_sound_focus_type_e type, int option, const char *ext_info)
2131 int ret = MM_ERROR_NONE;
2136 MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
2138 index = _focus_find_index_by_handle(id);
2140 debug_error("Could not find index");
2141 ret = MM_ERROR_INVALID_ARGUMENT;
2144 instance = g_focus_sound_handle[index].focus_tid;
2146 ret = mm_sound_proxy_release_focus(instance, id, type, option, ext_info, g_focus_sound_handle[index].is_for_session);
2147 if (ret == MM_ERROR_NONE)
2148 debug_msg("Success to release focus");
2150 debug_error("Error occurred : 0x%x", ret);
2153 MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
2158 int mm_sound_client_update_stream_focus_status(int id, unsigned int status)
2160 int ret = MM_ERROR_NONE;
2163 if ((ret = mm_sound_proxy_update_stream_focus_status(id, status)) != MM_ERROR_NONE)
2164 debug_error("failed to update stream focus status, ret[0x%x]", ret);
2170 int mm_sound_client_deliver_focus(int pid, int src_id, int dst_id, mm_sound_focus_type_e focus_type)
2172 int ret = MM_ERROR_NONE;
2175 if ((ret = mm_sound_proxy_deliver_focus(pid, src_id, dst_id, focus_type)) != MM_ERROR_NONE)
2176 debug_error("failed to deliver focus, ret[0x%x]", ret);
2182 int mm_sound_client_set_focus_watch_callback(int pid, mm_sound_focus_type_e focus_type, bool is_for_session, bool is_for_monitor,
2183 mm_sound_focus_changed_watch_cb callback, void* user_data, int *id)
2185 int ret = MM_ERROR_NONE;
2192 return MM_ERROR_INVALID_ARGUMENT;
2194 //pthread_mutex_lock(&g_thread_mutex2);
2198 ret = mm_sound_proxy_get_unique_id(id);
2202 MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
2204 for (index = 0; index < FOCUS_HANDLE_MAX - 1; index++) {
2205 if (g_focus_sound_handle[index].is_used == false) {
2206 g_focus_sound_handle[index].is_used = true;
2211 g_focus_sound_handle[index].focus_tid = instance;
2212 g_focus_sound_handle[index].handle = *id;
2213 g_focus_sound_handle[index].watch_callback = callback;
2214 g_focus_sound_handle[index].user_data = user_data;
2215 g_focus_sound_handle[index].is_for_session = is_for_session;
2216 g_focus_sound_handle[index].is_for_monitor = is_for_monitor;
2217 g_focus_sound_handle[index].unset_watch_callback_requested = false;
2219 ret = mm_sound_proxy_set_focus_watch_callback(pid, g_focus_sound_handle[index].handle, focus_type,
2220 is_for_session, is_for_monitor, callback, user_data);
2222 if (ret == MM_ERROR_NONE) {
2223 debug_msg("Success to watch focus");
2224 g_need_emergent_exit = TRUE;
2225 if (_focus_init_context(index)) {
2226 ret = MM_ERROR_SOUND_INTERNAL;
2230 debug_error("Error occurred : 0x%x", ret);
2234 _focus_init_callback(index, true);
2238 g_focus_sound_handle[index].is_used = false;
2240 MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
2245 int mm_sound_client_request_unset_focus_watch_callback(int id)
2247 int ret = MM_ERROR_NONE;
2251 MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
2253 index = _focus_watch_find_index_by_handle(id);
2255 debug_error("Could not find index");
2256 ret = MM_ERROR_INVALID_ARGUMENT;
2259 g_focus_sound_handle[index].unset_watch_callback_requested = true;
2262 MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
2267 int mm_sound_client_unset_focus_watch_callback(int id)
2269 int ret = MM_ERROR_NONE;
2273 MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
2275 index = _focus_watch_find_index_by_handle(id);
2277 debug_error("Could not find index");
2278 ret = MM_ERROR_INVALID_ARGUMENT;
2282 g_mutex_lock(&g_focus_sound_handle[index].focus_lock);
2284 g_focus_sound_handle[index].is_used = false;
2286 ret = mm_sound_proxy_unset_focus_watch_callback(g_focus_sound_handle[index].focus_tid,
2287 g_focus_sound_handle[index].handle,
2288 g_focus_sound_handle[index].is_for_session);
2290 if (ret == MM_ERROR_NONE)
2291 debug_msg("Success to unwatch focus");
2293 debug_error("Error occurred : 0x%x", ret);
2296 g_mutex_unlock(&g_focus_sound_handle[index].focus_lock);
2298 _focus_deinit_callback(index, true);
2299 g_focus_sound_handle[index].focus_fd = 0;
2300 g_focus_sound_handle[index].focus_tid = 0;
2301 g_focus_sound_handle[index].handle = 0;
2302 _focus_deinit_context(index);
2305 MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
2310 static gboolean _idle_event_callback(void *data)
2312 focus_idle_event_t *idle_event_data = (focus_idle_event_t*)data;
2313 int ret = MM_ERROR_NONE;
2316 debug_error("data is null");
2320 debug_msg("idle_event_data(%p): type(%d), data(%d)",
2321 idle_event_data, idle_event_data->type, idle_event_data->data);
2323 switch (idle_event_data->type) {
2324 case IDLE_EVENT_TYPE_UNSET_FOCUS_WATCH_CB:
2325 if ((ret = mm_sound_client_unset_focus_watch_callback(idle_event_data->data)))
2326 debug_error("Could not unset focus watch callback, id(%d), ret = %x", idle_event_data->data, ret);
2328 case IDLE_EVENT_TYPE_UNREGISTER_FOCUS:
2329 if ((ret = mm_sound_client_unregister_focus(idle_event_data->data)))
2330 debug_error("Could not unregister focus, id(%d), ret = %x", idle_event_data->data, ret);
2333 debug_warning("invalid type(%d)", idle_event_data->type);
2337 g_free(idle_event_data);
2339 g_idle_event_src = 0;
2341 MMSOUND_LEAVE_CRITICAL_SECTION(&g_event_mutex);
2346 int mm_sound_client_execute_focus_func_in_main_context(focus_idle_event_type_e type, int data)
2348 focus_idle_event_t *idle_event_data = NULL;
2350 if (IDLE_EVENT_TYPE_MAX < type)
2351 return MM_ERROR_INVALID_ARGUMENT;
2353 MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_event_mutex, MM_ERROR_SOUND_INTERNAL);
2355 idle_event_data = g_new0(focus_idle_event_t, 1);
2356 idle_event_data->type = type;
2357 idle_event_data->data = data;
2359 g_idle_event_src = g_idle_add_full(G_PRIORITY_HIGH,
2360 (GSourceFunc)_idle_event_callback,
2361 (gpointer)idle_event_data,
2364 return MM_ERROR_NONE;
2369 int mm_sound_client_add_test_callback(mm_sound_test_cb func, void* user_data, unsigned int *subs_id)
2371 int ret = MM_ERROR_NONE;
2375 ret = mm_sound_proxy_add_test_callback(func, user_data, g_free, subs_id);
2381 int mm_sound_client_remove_test_callback(unsigned int subs_id)
2383 int ret = MM_ERROR_NONE;
2386 ret = mm_sound_proxy_remove_test_callback(subs_id);
2393 int mm_sound_client_test(int a, int b, int* getv)
2395 int ret = MM_ERROR_NONE;
2399 ret = mm_sound_proxy_test(a, b, getv);
2400 debug_log("%d * %d -> result : %d", a, b, *getv);