_cb_data->extra_data = _extradata; \
} while (0)
-
+#ifdef USE_FOCUS
typedef struct {
int focus_tid;
int handle;
int type;
int state;
char stream_type[MAX_STREAM_TYPE_LEN];
- char name[MM_SOUND_NAME_NUM];
+ char ext_info[MM_SOUND_NAME_NUM];
+ int option;
} focus_cb_data_lib;
typedef struct {
void* user_data;
} focus_session_interrupt_info_t;
-typedef struct {
- /* handle to watch end of playing */
- int watching_handle;
- /* subscription id to unsubscribe when handle ended */
- unsigned subs_id;
-} play_sound_end_callback_data_t;
-
typedef gboolean (*focus_gLoopPollHandler_t)(gpointer d);
GThread *g_focus_thread;
focus_sound_info_t g_focus_sound_handle[FOCUS_HANDLE_MAX];
focus_session_interrupt_info_t g_focus_session_interrupt_info = {NULL, NULL};
static pthread_mutex_t g_index_mutex = PTHREAD_MUTEX_INITIALIZER;
-
guint g_focus_signal_handle = 0;
+#endif
+
gboolean g_need_emergent_exit = FALSE;
+typedef struct {
+ /* handle to watch end of playing */
+ int watching_handle;
+ /* subscription id to unsubscribe when handle ended */
+ unsigned subs_id;
+} play_sound_end_callback_data_t;
+
void _system_signal_handler(int signo)
{
int ret = MM_ERROR_NONE;
sigset_t old_mask, all_mask;
- debug_error("Got signal : signo(%d)", signo);
+ debug_warning("Got signal : signo(%d)", signo);
/* signal block */
break;
}
- debug_error("signal handling end");
+ debug_warning("signal handling end");
}
int mm_sound_client_initialize(void)
break;
}
- debug_error("volume type (%d) converted to stream type (%s)", volume_type, stream_type);
+ debug_msg("volume type (%d) converted to stream type (%s)", volume_type, stream_type);
}
/*****************************************************************************************
DBUS SUPPORTED FUNCTIONS
******************************************************************************************/
-
+#ifdef USE_FOCUS
void _mm_sound_client_focus_signal_callback(mm_sound_signal_name_t signal, int value, void *user_data)
{
int ret = MM_ERROR_NONE;
debug_fenter();
- debug_error("focus signal received, value = %d", value);
+ debug_msg("focus signal received, value = %d", value);
if (value == 1) {
ret = mm_sound_proxy_clear_focus(getpid());
g_focus_signal_handle = 0;
}
}
+#endif
int mm_sound_client_play_tone(int number, int volume_config, double volume, int time, int *handle, bool enable_session)
{
mm_sound_convert_volume_type_to_stream_type(volume_type, stream_type);
ret = mm_sound_proxy_play_tone(number, time, volume, volume_config,
session_type, session_options, getpid(), enable_session, handle, stream_type, -1);
-
+#ifdef USE_FOCUS
if (enable_session && !g_focus_signal_handle) {
ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_focus_signal_handle, _mm_sound_client_focus_signal_callback, NULL);
if (ret) {
return MM_ERROR_POLICY_INTERNAL;
}
}
+#endif
debug_fleave();
return ret;
debug_error("Add callback for play sound(%d) Failed", *handle);
}
}
+#ifdef USE_FOCUS
if (!param->skip_session && !g_focus_signal_handle) {
ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_focus_signal_handle, _mm_sound_client_focus_signal_callback, NULL);
if (ret) {
return MM_ERROR_POLICY_INTERNAL;
}
}
+#endif
failed:
return ret;
}
-static bool is_device_match_flags(const char *device_type, int io_direction, int state, int device_flags)
+static bool device_is_match_direction(int direction, int mask)
{
- int io_direction_flag = device_flags & DEVICE_IO_DIRECTION_FLAGS;
- int state_flag = device_flags & DEVICE_STATE_FLAGS;
- int type_flag = device_flags & DEVICE_TYPE_FLAGS;
- char builtin_prefix[] = "builtin";
+ if (mask == DEVICE_IO_DIRECTION_FLAGS || mask == 0)
+ return true;
- if (device_flags == DEVICE_ALL_FLAG)
- return TRUE;
+ if ((mask & MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG) && (direction & MM_SOUND_DEVICE_IO_DIRECTION_IN))
+ return true;
+ if ((mask & MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG) && (direction & MM_SOUND_DEVICE_IO_DIRECTION_OUT))
+ return true;
+ if ((mask & MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG) && (direction == MM_SOUND_DEVICE_IO_DIRECTION_BOTH))
+ return true;
- switch (io_direction_flag) {
- case DEVICE_IO_DIRECTION_IN_FLAG:
- if (io_direction != DEVICE_IO_DIRECTION_IN)
- return FALSE;
- break;
- case DEVICE_IO_DIRECTION_OUT_FLAG:
- if (io_direction != DEVICE_IO_DIRECTION_OUT)
- return FALSE;
- break;
- case DEVICE_IO_DIRECTION_BOTH_FLAG:
- if (io_direction != DEVICE_IO_DIRECTION_BOTH)
- return FALSE;
- break;
- default:
- break;
+ return false;
+}
+
+static bool device_is_match_state(int state, int mask)
+{
+ if (mask == DEVICE_STATE_FLAGS || mask == 0)
+ return true;
+
+ if ((mask & MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG) && (state == MM_SOUND_DEVICE_STATE_DEACTIVATED))
+ return true;
+ if ((mask & MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG) && (state == MM_SOUND_DEVICE_STATE_ACTIVATED))
+ return true;
+
+ return false;
+}
+
+static bool device_is_match_type(const char *type, int mask)
+{
+ bool is_builtin;
+ const char *builtin_prefix = "builtin";
+
+ if (mask == DEVICE_TYPE_FLAGS || mask == 0)
+ return true;
+
+ is_builtin = !strncmp(type, builtin_prefix, strlen(builtin_prefix));
+
+ if ((mask & MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG) && (is_builtin))
+ return true;
+ if ((mask & MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG) && (!is_builtin))
+ return true;
+
+ return false;
+}
+
+static bool device_is_match_with_mask(const char *type, int direction, int state, int mask)
+{
+ if (mask == DEVICE_ALL_FLAG)
+ return true;
+
+ return (device_is_match_direction(direction, mask & DEVICE_IO_DIRECTION_FLAGS) &&
+ device_is_match_state(state, mask & DEVICE_STATE_FLAGS) &&
+ device_is_match_type(type, mask & DEVICE_TYPE_FLAGS));
+}
+
+static int _fill_sound_device(mm_sound_device_t *device_h, int device_id, const char *device_type,
+ int direction, int state, const char *name, int *stream_id, int stream_num)
+{
+ int i;
+
+ if (stream_num > 0 && stream_id == NULL) {
+ debug_error("stream_num is %d, but stream_id is NULL", stream_num);
+ return -1;
}
- switch (state_flag) {
- case DEVICE_STATE_DEACTIVATED_FLAG:
- if (state != DEVICE_STATE_DEACTIVATED)
- return FALSE;
- break;
- case DEVICE_STATE_ACTIVATED_FLAG:
- if (state != DEVICE_STATE_ACTIVATED)
- return FALSE;
- break;
- default:
- break;
+ if (stream_num > MAX_STREAM_ON_DEVICE) {
+ debug_error("too many streams on this device");
+ return -1;
}
- switch (type_flag) {
- case DEVICE_TYPE_INTERNAL_FLAG:
- if (strncmp(device_type, builtin_prefix, strlen(builtin_prefix)) != 0)
- return FALSE;
- break;
- case DEVICE_TYPE_EXTERNAL_FLAG:
- if (strncmp(device_type, builtin_prefix, strlen(builtin_prefix)) == 0)
- return FALSE;
- break;
- default:
- break;
+ device_h->id = device_id;
+ device_h->io_direction = direction;
+ device_h->state = state;
+ MMSOUND_STRNCPY(device_h->name, name, MAX_DEVICE_NAME_NUM);
+ MMSOUND_STRNCPY(device_h->type, device_type, MAX_DEVICE_TYPE_STR_LEN);
+
+ if (stream_num > 0) {
+ device_h->stream_num = stream_num;
+ debug_log("%d streams on this device", stream_num);
+ for (i = 0; i < stream_num; i++) {
+ debug_log(" stream_id : %d", stream_id[i]);
+ device_h->stream_id[i] = stream_id[i];
+ }
+ } else {
+ device_h->stream_num = 0;
+ debug_log("There is no stream on this device");
}
- return TRUE;
+ return 0;
}
-static void _mm_sound_device_connected_callback_wrapper_func(int device_id, const char *device_type, int io_direction, int state, const char *name, gboolean is_connected, void *userdata)
+static void _mm_sound_device_connected_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
+ int state, const char *name, int *stream_id, int stream_num, gboolean is_connected, void *userdata)
{
mm_sound_device_t device_h;
struct callback_data *cb_data = (struct callback_data*) userdata;
int device_flags;
- debug_log("[Wrapper CB][Device Connnected] device_id : %d, device_type : %s, direction : %d, state : %d, name : %s, is_connected : %d",
- device_id, device_type, io_direction, state, name, is_connected);
+ debug_log("[Device %s] id(%d) type(%s) direction(%d) state(%d) name(%s)",
+ is_connected ? "Connected" : "Disconnected", device_id, device_type, io_direction,
+ state, name, is_connected);
if (cb_data == NULL) {
debug_warning("device connected changed callback data null");
}
device_flags = (int) cb_data->extra_data;
-
- if (!is_device_match_flags(device_type, io_direction, state, device_flags))
+ if (!device_is_match_with_mask(device_type, io_direction, state, device_flags))
return;
- device_h.id = device_id;
- device_h.io_direction = io_direction;
- device_h.state = state;
- MMSOUND_STRNCPY(device_h.name, name, MAX_DEVICE_NAME_NUM);
- MMSOUND_STRNCPY(device_h.type, device_type, MAX_DEVICE_TYPE_STR_LEN);
+ if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name, stream_id, stream_num) < 0) {
+ debug_error("Failed to fill sound device");
+ return;
+ }
((mm_sound_device_connected_cb)(cb_data->user_cb))(&device_h, is_connected, cb_data->user_data);
}
return ret;
}
-static void _mm_sound_device_info_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction, int state, const char *name, int changed_device_info_type, void *userdata)
+static void _mm_sound_device_info_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
+ int state, const char *name, int *stream_id, int stream_num, int changed_device_info_type, void *userdata)
{
mm_sound_device_t device_h;
struct callback_data *cb_data = (struct callback_data*) userdata;
int device_flags;
- debug_log("[Wrapper CB][Device Info Changed] device_id : %d, device_type : %s, direction : %d, state : %d, name : %s, changed_info_type : %d",
+ debug_log("[Device Info Changed] id(%d) type(%s) direction(%d) state(%d) name(%s) changed_info_type(%d)",
device_id, device_type, io_direction, state, name, changed_device_info_type);
if (cb_data == NULL) {
}
device_flags = (int) cb_data->extra_data;
-
- if (!is_device_match_flags(device_type, io_direction, state, device_flags))
+ if (!device_is_match_with_mask(device_type, io_direction, state, device_flags))
return;
- device_h.id = device_id;
- device_h.io_direction = io_direction;
- device_h.state = state;
- MMSOUND_STRNCPY(device_h.name, name, MAX_DEVICE_NAME_NUM);
- MMSOUND_STRNCPY(device_h.type, device_type, MAX_DEVICE_TYPE_STR_LEN);
+ if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name, stream_id, stream_num) < 0) {
+ debug_error("Failed to fill sound device");
+ return;
+ }
((mm_sound_device_info_changed_cb)(cb_data->user_cb))(&device_h, changed_device_info_type, cb_data->user_data);
}
}
+static void _mm_sound_device_state_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
+ int state, const char *name, int *stream_id, int stream_num, void *userdata)
+{
+ mm_sound_device_t device_h;
+ struct callback_data *cb_data = (struct callback_data*) userdata;
+ int device_flags;
+
+ debug_log("[Device State Changed] id(%d) type(%s) direction(%d) state(%d) name(%s)",
+ device_id, device_type, io_direction, state, name);
+
+ if (cb_data == NULL) {
+ debug_warning("device state changed callback data null");
+ return;
+ }
+
+ device_flags = (int) cb_data->extra_data;
+
+ if (!device_is_match_with_mask(device_type, io_direction, state, device_flags))
+ return;
+
+ if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name, stream_id, stream_num) < 0) {
+ debug_error("Failed to fill sound device");
+ return;
+ }
+
+ ((mm_sound_device_state_changed_cb)(cb_data->user_cb))(&device_h, state, cb_data->user_data);
+}
+
+int mm_sound_client_add_device_state_changed_callback(int device_flags, mm_sound_device_state_changed_cb func, void *userdata, unsigned int *id)
+{
+ int ret = MM_ERROR_NONE;
+ struct callback_data *cb_data = (struct callback_data*) userdata;
+
+ debug_fenter();
+
+ GET_CB_DATA(cb_data, func, userdata, (void *) device_flags);
+
+ ret = mm_sound_proxy_add_device_state_changed_callback(device_flags, _mm_sound_device_state_changed_callback_wrapper_func, cb_data, g_free, id);
+
+ debug_fleave();
+ return ret;
+}
+
+int mm_sound_client_remove_device_state_changed_callback(unsigned int id)
+{
+ int ret = MM_ERROR_NONE;
+ debug_fenter();
+
+ ret = mm_sound_proxy_remove_device_state_changed_callback(id);
+
+ debug_fleave();
+ return ret;
+}
+
+int mm_sound_client_is_stream_on_device(int stream_id, int device_id, bool *is_on)
+{
+ int ret = MM_ERROR_NONE;
+ debug_fenter();
+
+ if (!is_on) {
+ debug_error("Invalid Parameter");
+ ret = MM_ERROR_COMMON_INVALID_ARGUMENT;
+ goto failed;
+ }
+
+ if ((ret = mm_sound_proxy_is_stream_on_device(stream_id, device_id, is_on)) != MM_ERROR_NONE) {
+ debug_error("[Client] failed to query is stream on device, ret[0x%x]", ret);
+ goto failed;
+ }
+
+failed:
+ debug_fleave();
+ return ret;
+}
+
int __convert_volume_type_to_str(int volume_type, char **volume_type_str)
{
int ret = MM_ERROR_NONE;
static gpointer _focus_thread_func(gpointer data)
{
- debug_log(">>> thread func..ID of this thread(%u)\n", (unsigned int)pthread_self());
- g_main_loop_run(g_focus_loop);
- debug_log("<<< quit thread func..\n");
+ unsigned int thread_id = (unsigned int)pthread_self();
+ debug_warning(">>> thread func..ID of this thread(%u), mainloop(%p)", thread_id, g_focus_loop);
+ if (g_focus_loop)
+ g_main_loop_run(g_focus_loop);
+
+ debug_warning("<<< quit thread func..(%u), mainloop(%p)", thread_id, g_focus_loop);
return NULL;
}
static int _focus_find_index_by_handle(int handle)
{
int i = 0;
- for(i = 0; i< FOCUS_HANDLE_MAX; i++) {
- if (handle == g_focus_sound_handle[i].handle) {
- //debug_msg("found index(%d) for handle(%d)", i, handle);
- if (handle == FOCUS_HANDLE_INIT_VAL) {
- return -1;
- }
- return i;
+ for (i = 0; i < FOCUS_HANDLE_MAX; i++) {
+ if (g_focus_sound_handle[i].focus_callback && handle == g_focus_sound_handle[i].handle) {
+ /* debug_msg("found index(%d) for handle(%d)", i, handle);*/
+ return (handle == FOCUS_HANDLE_INIT_VAL)? -1 : i;
+ }
+ }
+ return -1;
+}
+
+static int _focus_watch_find_index_by_handle(int handle)
+{
+ int i = 0;
+ for (i = 0; i < FOCUS_HANDLE_MAX; i++) {
+ if (g_focus_sound_handle[i].watch_callback && handle == g_focus_sound_handle[i].handle) {
+ /* debug_msg("found index(%d) for watch handle(%d)", i, handle);*/
+ return (handle == FOCUS_HANDLE_INIT_VAL)? -1 : i;
}
}
return -1;
tid = g_focus_sound_handle[focus_index].focus_tid;
if (changed_state != -1) {
- debug_error("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)", tid, cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type);
- if (g_focus_sound_handle[focus_index].focus_callback== NULL) {
+ debug_msg("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)", tid, cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type);
+ if (g_focus_sound_handle[focus_index].focus_callback == NULL) {
debug_error("callback is null..");
g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
return FALSE;
}
- debug_error("[CALLBACK(%p) START]",g_focus_sound_handle[focus_index].focus_callback);
- (g_focus_sound_handle[focus_index].focus_callback)(cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type, cb_data.name, g_focus_sound_handle[focus_index].user_data);
- debug_error("[CALLBACK END]");
+ debug_msg("[CALLBACK(%p) START]",g_focus_sound_handle[focus_index].focus_callback);
+ (g_focus_sound_handle[focus_index].focus_callback)(cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type, cb_data.option, cb_data.ext_info, g_focus_sound_handle[focus_index].user_data);
+ debug_msg("[CALLBACK END]");
if (g_focus_session_interrupt_info.user_cb) {
- debug_error("sending session interrupt callback(%p)", g_focus_session_interrupt_info.user_cb);
+ debug_msg("sending session interrupt callback(%p)", g_focus_session_interrupt_info.user_cb);
(g_focus_session_interrupt_info.user_cb)(cb_data.state, cb_data.stream_type, false, g_focus_session_interrupt_info.user_data);
}
}
#ifdef CONFIG_ENABLE_RETCB
-
- int rett = 0;
- int tmpfd = -1;
- unsigned int buf = 0;
- char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", g_focus_sound_handle[focus_index].focus_tid, cb_data.handle);
- tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
- if (tmpfd < 0) {
- char str_error[256];
- strerror_r(errno, str_error, sizeof(str_error));
- debug_error("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)\n", tid, tmpfd, filename2, errno, str_error);
- g_free(filename2);
- g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
- return FALSE;
- }
- buf = (unsigned int)((0x0000ffff & cb_data.handle) |(g_focus_sound_handle[focus_index].auto_reacquire << 16));
- rett = write(tmpfd, &buf, sizeof(buf));
- close(tmpfd);
+ {
+ int rett = 0;
+ int tmpfd = -1;
+ unsigned int buf = 0;
+ char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", g_focus_sound_handle[focus_index].focus_tid, cb_data.handle);
+ tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
+ if (tmpfd < 0) {
+ char str_error[256];
+ strerror_r(errno, str_error, sizeof(str_error));
+ debug_warning("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)\n", tid, tmpfd, filename2, errno, str_error);
g_free(filename2);
- debug_msg("[RETCB] tid(%d) finishing CB (write=%d)\n", tid, rett);
+ g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
+ return FALSE;
+ }
+ /* buf contains data as below,
+ * |<--12bits--><--4bits (reacquisition)--><--16bits (handle)-->| */
+ buf = (unsigned int)((0x0000ffff & cb_data.handle) | (g_focus_sound_handle[focus_index].auto_reacquire << 16));
+ rett = write(tmpfd, &buf, sizeof(buf));
+ close(tmpfd);
+ g_free(filename2);
+ debug_msg("[RETCB] tid(%d) finishing CB (write=%d)\n", tid, rett);
+ }
#endif
}
return FALSE;
}
- focus_index = _focus_find_index_by_handle(cb_data.handle);
+ focus_index = _focus_watch_find_index_by_handle(cb_data.handle);
if (focus_index == -1) {
debug_error("Could not find index");
return FALSE;
}
- debug_error("lock focus_lock = %p", &g_focus_sound_handle[focus_index].focus_lock);
+ if (!g_focus_sound_handle[focus_index].is_used) {
+ debug_warning("unsetting watch calllback has been already requested");
+ goto SKIP_CB_AND_RET;
+ }
+
+ debug_msg("lock focus_lock = %p", &g_focus_sound_handle[focus_index].focus_lock);
g_mutex_lock(&g_focus_sound_handle[focus_index].focus_lock);
tid = g_focus_sound_handle[focus_index].focus_tid;
- debug_error("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)", tid, cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type);
+ debug_msg("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)", tid, cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type);
if (g_focus_sound_handle[focus_index].watch_callback == NULL) {
debug_msg("callback is null..");
} else {
debug_msg("[CALLBACK(%p) START]",g_focus_sound_handle[focus_index].watch_callback);
- (g_focus_sound_handle[focus_index].watch_callback)(cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type, cb_data.name, g_focus_sound_handle[focus_index].user_data);
+ (g_focus_sound_handle[focus_index].watch_callback)(cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type, cb_data.ext_info, g_focus_sound_handle[focus_index].user_data);
debug_msg("[CALLBACK END]");
if (g_focus_session_interrupt_info.user_cb) {
- debug_error("sending session interrupt callback(%p)", g_focus_session_interrupt_info.user_cb);
+ debug_msg("sending session interrupt callback(%p)", g_focus_session_interrupt_info.user_cb);
(g_focus_session_interrupt_info.user_cb)(cb_data.state, cb_data.stream_type, true, g_focus_session_interrupt_info.user_data);
}
}
+SKIP_CB_AND_RET:
#ifdef CONFIG_ENABLE_RETCB
+ {
int rett = 0;
int tmpfd = -1;
int buf = -1;
if (tmpfd < 0) {
char str_error[256];
strerror_r(errno, str_error, sizeof(str_error));
- debug_error("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)\n", tid, tmpfd, filename2, errno, str_error);
+ debug_warning("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)\n", tid, tmpfd, filename2, errno, str_error);
g_free(filename2);
g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
return FALSE;
close(tmpfd);
g_free(filename2);
debug_msg("[RETCB] tid(%d) finishing CB (write=%d)\n", tid, rett);
-
+ }
#endif
-
}
- debug_error("unlock focus_lock = %p", &g_focus_sound_handle[focus_index].focus_lock);
- g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
+ if (g_focus_sound_handle[focus_index].is_used) {
+ debug_msg("unlock focus_lock = %p", &g_focus_sound_handle[focus_index].focus_lock);
+ g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
+ }
debug_fleave();
-
return TRUE;
}
if (g_focus_sound_handle[index].focus_fd == -1) {
debug_error("Open fail : index(%d), file open error(%d)", index, errno);
} else {
- debug_log("Open sucess : index(%d), filename(%s), fd(%d)", index, filename, g_focus_sound_handle[index].focus_fd);
+ debug_log("Open success : index(%d), filename(%s), fd(%d)", index, filename, g_focus_sound_handle[index].focus_fd);
}
g_free(filename);
filename = NULL;
debug_error("Close fail : index(%d)", index);
} else {
close(g_focus_sound_handle[index].focus_fd);
- debug_log("Close Sucess : index(%d)", index);
+ debug_log("Close Success : index(%d)", index);
}
if (is_for_watching) {
debug_error("failed to g_source_new for g_src");
goto ERROR;
}
- g_focus_sound_handle[index].focus_src = g_src;
- g_focus_sound_handle[index].g_src_funcs = g_src_funcs;
/* 2. add file description which used in g_loop() */
g_poll_fd = (GPollFD *)g_malloc(sizeof(GPollFD));
}
g_poll_fd->fd = fd;
g_poll_fd->events = events;
- g_focus_sound_handle[index].g_poll_fd = g_poll_fd;
/* 3. combine g_source object and file descriptor */
g_source_add_poll(g_src, g_poll_fd);
/* 4. set callback */
g_source_set_callback(g_src, p_gloop_poll_handler,(gpointer)g_poll_fd, NULL);
- debug_log("g_malloc : g_src_funcs(%x), g_poll_fd(%x)", g_src_funcs, g_poll_fd);
+ debug_log("g_malloc : g_src_funcs(%p), g_poll_fd(%p)", g_src_funcs, g_poll_fd);
+
+ /* 5. store to global handle */
+ g_focus_sound_handle[index].focus_src = g_src;
+ g_focus_sound_handle[index].g_src_funcs = g_src_funcs;
+ g_focus_sound_handle[index].g_poll_fd = g_poll_fd;
debug_fleave();
return true;
g_free(g_src_funcs);
if (g_poll_fd)
g_free(g_poll_fd);
- if (g_src_id)
- g_source_destroy(g_src);
if (g_src)
g_source_unref(g_src);
g_free(g_poll_fd);
g_poll_fd = NULL;
}
- if (g_focus_sound_handle[index].focus_src)
- g_source_unref(g_focus_sound_handle[index].focus_src);
g_focus_sound_handle[index].g_src_funcs = NULL;
g_focus_sound_handle[index].g_poll_fd = NULL;
GMainContext* focus_context = g_main_context_new ();
g_focus_loop = g_main_loop_new (focus_context, FALSE);
g_main_context_unref(focus_context);
- g_focus_thread = g_thread_new("focus-callback-thread", _focus_thread_func, NULL);
+ if (g_focus_loop == NULL) {
+ debug_error("could not create mainloop..");
+ ret = MM_ERROR_SOUND_INTERNAL;
+ goto cleanup;
+ }
+
+ g_focus_thread = g_thread_new("focus-cb-thread", _focus_thread_func, NULL);
if (g_focus_thread == NULL) {
- debug_error ("could not create thread..");
+ debug_error("could not create thread..");
g_main_loop_unref(g_focus_loop);
- g_focus_sound_handle[index].is_used = false;
ret = MM_ERROR_SOUND_INTERNAL;
goto cleanup;
}
+ } else {
+ debug_warning("focus thread(%p) with mainloop(%p) exists, skip thread creation",
+ g_focus_thread, g_focus_loop);
}
} else {
debug_error("[Client] Error occurred : 0x%x \n",ret);
- g_focus_sound_handle[index].is_used = false;
goto cleanup;
}
_focus_init_callback(index, false);
cleanup:
+
+ if (ret) {
+ g_focus_sound_handle[index].is_used = false;
+ }
+
MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
debug_fleave();
} else if (!result) {
ret = mm_sound_proxy_set_foucs_reacquisition(instance, id, reacquisition);
if (ret == MM_ERROR_NONE) {
- debug_msg("[Client] Success to set focus reacquisition\n");
+ debug_msg("[Client] Success to set focus reacquisition to [%d]\n", reacquisition);
} else {
debug_error("[Client] Error occurred : 0x%x \n",ret);
goto cleanup;
}
} else {
- debug_warning("[Client] Inside the focus cb thread, bypassing dbus method call");
+ debug_warning("[Client] Inside the focus cb thread, set focus reacquisition to [%d]\n", reacquisition);
}
g_focus_sound_handle[index].auto_reacquire = reacquisition;
return ret;
}
-int mm_sound_client_get_acquired_focus_stream_type(int focus_type, char **stream_type, char **additional_info)
+int mm_sound_client_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
{
int ret = MM_ERROR_NONE;
+ char *ext_str = NULL;
debug_fenter();
- ret = mm_sound_proxy_get_acquired_focus_stream_type(focus_type, stream_type, additional_info);
- if (ret == MM_ERROR_NONE)
- debug_msg("[Client] Success to get stream type of acquired focus, stream_type(%s), additional_info(%s)\n", *stream_type, *additional_info);
- else
+ ret = mm_sound_proxy_get_acquired_focus_stream_type(focus_type, stream_type, option, &ext_str);
+ if (ret == MM_ERROR_NONE) {
+ debug_msg("[Client] Success to get stream type of acquired focus, stream_type(%s), ext_info(%s)\n", *stream_type, ext_str);
+ *ext_info = strdup(ext_str);
+ g_free(ext_str);
+ } else {
debug_error("[Client] Error occurred : 0x%x \n",ret);
+ }
debug_fleave();
return ret;
}
-int mm_sound_client_acquire_focus(int id, mm_sound_focus_type_e type, const char *option)
+int mm_sound_client_acquire_focus(int id, mm_sound_focus_type_e type, int option, const char *ext_info)
{
int ret = MM_ERROR_NONE;
int instance;
}
instance = g_focus_sound_handle[index].focus_tid;
- ret = mm_sound_proxy_acquire_focus(instance, id, type, option, g_focus_sound_handle[index].is_for_session);
-
+ ret = mm_sound_proxy_acquire_focus(instance, id, type, option, ext_info, g_focus_sound_handle[index].is_for_session);
if (ret == MM_ERROR_NONE)
debug_msg("[Client] Success to acquire focus\n");
else
return ret;
}
-int mm_sound_client_release_focus(int id, mm_sound_focus_type_e type, const char *option)
+int mm_sound_client_release_focus(int id, mm_sound_focus_type_e type, int option, const char *ext_info)
{
int ret = MM_ERROR_NONE;
int instance;
}
instance = g_focus_sound_handle[index].focus_tid;
- ret = mm_sound_proxy_release_focus(instance, id, type, option, g_focus_sound_handle[index].is_for_session);
-
+ ret = mm_sound_proxy_release_focus(instance, id, type, option, ext_info, g_focus_sound_handle[index].is_for_session);
if (ret == MM_ERROR_NONE)
debug_msg("[Client] Success to release focus\n");
else
GMainContext* focus_context = g_main_context_new ();
g_focus_loop = g_main_loop_new (focus_context, FALSE);
g_main_context_unref(focus_context);
- g_focus_thread = g_thread_new("focus-callback-thread", _focus_thread_func, NULL);
+ if (g_focus_loop == NULL) {
+ debug_error("could not create mainloop..");
+ ret = MM_ERROR_SOUND_INTERNAL;
+ goto cleanup;
+ }
+
+ g_focus_thread = g_thread_new("focus-cb-thread", _focus_thread_func, NULL);
if (g_focus_thread == NULL) {
debug_error ("could not create thread..");
g_main_loop_unref(g_focus_loop);
ret = MM_ERROR_SOUND_INTERNAL;
goto cleanup;
}
+ } else {
+ debug_warning("focus thread(%p) with mainloop(%p) exists, skip thread creation",
+ g_focus_thread, g_focus_loop);
}
} else {
debug_error("[Client] Error occurred : 0x%x",ret);
debug_fenter();
MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
- index = _focus_find_index_by_handle(id);
+ index = _focus_watch_find_index_by_handle(id);
if (index == -1) {
debug_error("Could not find index");
ret = MM_ERROR_INVALID_ARGUMENT;
g_mutex_lock(&g_focus_sound_handle[index].focus_lock);
+ g_focus_sound_handle[index].is_used = false;
+
ret = mm_sound_proxy_unset_focus_watch_callback(g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle, g_focus_sound_handle[index].is_for_session);
if (ret == MM_ERROR_NONE)
g_focus_sound_handle[index].focus_fd = 0;
g_focus_sound_handle[index].focus_tid = 0;
g_focus_sound_handle[index].handle = 0;
- g_focus_sound_handle[index].is_used = false;
cleanup:
MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
debug_fleave();