#define VOLUME_TYPE_LEN 64
-mm_sound_device_list_t *g_device_list;
+mm_sound_device_list_t g_device_list;
+pthread_mutex_t g_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
static int _check_for_valid_mask (int flags)
{
}
EXPORT_API
-int mm_sound_add_device_connected_callback(mm_sound_device_flags_e flags, mm_sound_device_connected_cb func, void *user_data, unsigned int *subs_id)
+int mm_sound_add_device_connected_callback(int flags, mm_sound_device_connected_cb func, void *user_data, unsigned int *id)
{
int ret = MM_ERROR_NONE;
- if (func == NULL || subs_id == NULL) {
+ if (func == NULL || id == NULL) {
debug_error("argument is not valid\n");
return MM_ERROR_INVALID_ARGUMENT;
}
ret = _check_for_valid_mask(flags);
if (ret == MM_ERROR_NONE) {
- ret = mm_sound_client_add_device_connected_callback(flags, func, user_data, subs_id);
+ ret = mm_sound_client_add_device_connected_callback(flags, func, user_data, id);
if (ret < 0) {
debug_error("Could not add device connected callback, ret = %x\n", ret);
}
}
EXPORT_API
-int mm_sound_remove_device_connected_callback(unsigned int subs_id)
+int mm_sound_remove_device_connected_callback(unsigned int id)
{
int ret = MM_ERROR_NONE;
- ret = mm_sound_client_remove_device_connected_callback(subs_id);
+ ret = mm_sound_client_remove_device_connected_callback(id);
if (ret < 0) {
debug_error("Could not remove device connected callback, ret = %x\n", ret);
}
}
EXPORT_API
-int mm_sound_add_device_information_changed_callback(mm_sound_device_flags_e flags, mm_sound_device_info_changed_cb func, void *user_data, unsigned int *subs_id)
+int mm_sound_add_device_information_changed_callback(int flags, mm_sound_device_info_changed_cb func, void *user_data, unsigned int *id)
{
int ret = MM_ERROR_NONE;
- if (func == NULL || subs_id == NULL) {
+ if (func == NULL || id == NULL) {
debug_error("argument is not valid\n");
return MM_ERROR_INVALID_ARGUMENT;
}
ret = _check_for_valid_mask(flags);
if (ret == MM_ERROR_NONE) {
- ret = mm_sound_client_add_device_info_changed_callback(flags, func, user_data, subs_id);
+ ret = mm_sound_client_add_device_info_changed_callback(flags, func, user_data, id);
if (ret < 0) {
debug_error("Could not add device information changed callback, ret = %x\n", ret);
}
}
EXPORT_API
-int mm_sound_remove_device_information_changed_callback(unsigned int subs_id)
+int mm_sound_remove_device_information_changed_callback(unsigned int id)
{
int ret = MM_ERROR_NONE;
- ret = mm_sound_client_remove_device_info_changed_callback(subs_id);
+ ret = mm_sound_client_remove_device_info_changed_callback(id);
if (ret < 0) {
debug_error("Could not remove device information changed callback, ret = %x\n", ret);
}
}
EXPORT_API
+int mm_sound_add_device_state_changed_callback(int flags, mm_sound_device_state_changed_cb func, void *user_data, unsigned int *id)
+{
+ int ret = MM_ERROR_NONE;
+
+ if (func == NULL || id == NULL) {
+ debug_error("argument is not valid\n");
+ return MM_ERROR_INVALID_ARGUMENT;
+ }
+ ret = _check_for_valid_mask(flags);
+ if (ret == MM_ERROR_NONE) {
+ ret = mm_sound_client_add_device_state_changed_callback(flags, func, user_data, id);
+ if (ret < 0) {
+ debug_error("Could not add device state changed callback, ret = %x\n", ret);
+ }
+ }
+
+ return ret;
+}
+
+EXPORT_API
+int mm_sound_remove_device_state_changed_callback(unsigned int id)
+{
+ int ret = MM_ERROR_NONE;
+
+ ret = mm_sound_client_remove_device_state_changed_callback(id);
+ if (ret < 0) {
+ debug_error("Could not remove device state changed callback, ret = %x\n", ret);
+ }
+
+ return ret;
+}
+
+
+EXPORT_API
int mm_sound_get_current_device_list(mm_sound_device_flags_e flags, MMSoundDeviceList_t *device_list)
{
int ret = MM_ERROR_NONE;
return ret;
}
- /* free previously allocated list */
- if (g_device_list != NULL)
- __free_device_list(g_device_list);
+ pthread_mutex_lock(&g_thread_mutex);
- if (!(g_device_list = g_malloc0(sizeof(mm_sound_device_list_t)))) {
- debug_error("[Client] Allocate device list failed");
- return MM_ERROR_SOUND_INTERNAL;
+ if (g_device_list.list != NULL) {
+ g_list_free_full(g_device_list.list, g_free);
+ g_device_list.list = NULL;
}
- g_device_list->is_new_device_list = true;
+ g_device_list.is_new_device_list = true;
- ret = mm_sound_client_get_current_connected_device_list(flags, g_device_list);
+ ret = mm_sound_client_get_current_connected_device_list(flags, &g_device_list);
if (ret < 0) {
debug_error("Could not get current connected device list, ret = %x\n", ret);
- g_free(g_device_list);
- g_device_list = NULL;
+ g_device_list.list = NULL;
} else {
- *device_list = g_device_list;
+ *device_list = &g_device_list;
}
+ pthread_mutex_unlock(&g_thread_mutex);
+
return ret;
}
}
EXPORT_API
+int mm_sound_free_device(MMSoundDevice_t device_h)
+{
+ if (device_h == NULL)
+ return MM_ERROR_INVALID_ARGUMENT;
+
+ g_free(device_h);
+
+ return MM_ERROR_NONE;
+}
+
+EXPORT_API
+int mm_sound_get_device_by_id(int device_id, MMSoundDevice_t *device_h)
+{
+ int ret = MM_ERROR_NONE;
+ mm_sound_device_t *device = NULL;
+
+ if (device_id < 1 || device_h == NULL)
+ return MM_ERROR_INVALID_ARGUMENT;
+
+ ret = mm_sound_client_get_device_by_id(device_id, &device);
+ if (ret < 0)
+ debug_error("Could not get device by id, ret = %x\n", ret);
+ else
+ *device_h = device;
+
+ return ret;
+}
+
+EXPORT_API
int mm_sound_get_next_device (MMSoundDeviceList_t device_list, MMSoundDevice_t *device)
{
int ret = MM_ERROR_NONE;
return MM_ERROR_NONE;
}
+EXPORT_API
+int mm_sound_is_stream_on_device(int stream_id, MMSoundDevice_t device_h, bool *is_on)
+{
+ int ret = MM_ERROR_NONE;
+ int i;
+ mm_sound_device_t *device = (mm_sound_device_t*)device_h;
+ bool _is_on = false;
+
+ if(!device || !is_on) {
+ debug_error("invalid argument\n");
+ return MM_ERROR_INVALID_ARGUMENT;
+ }
+
+ if (device->stream_num >= 0) {
+ debug_log("device_handle has stream id");
+ for (i = 0; i < device->stream_num; i++) {
+ if (device->stream_id[i] == stream_id) {
+ _is_on = true;
+ break;
+ }
+ }
+ } else {
+ debug_log("device_handle dosn't have stream id");
+ /* No information about stream in client-side, should ask to server-side */
+ if ((ret = mm_sound_client_is_stream_on_device(stream_id, device->id, &_is_on)) < 0) {
+ debug_error("Failed to query is stream on");
+ return MM_ERROR_SOUND_INTERNAL;
+ }
+ }
+
+ debug_log("device(%d) %s stream(%d)\n", device->id, _is_on ? "has" : "doesn't have", stream_id);
+ *is_on = _is_on;
+
+ return ret;
+}