From: Jeongho Mok Date: Tue, 30 May 2017 04:44:18 +0000 (+0900) Subject: Get device by id X-Git-Tag: accepted/tizen/unified/20170605.150759~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=65ee5d546202dd60b16dc12526022a2203e28f12;p=platform%2Fcore%2Fmultimedia%2Flibmm-sound.git Get device by id [Version] 0.11.3 [Profile] Common [Issue Type] Enhancement Change-Id: I140885278aa8bab3d5fabc5c0a0860b38d6fde9a --- diff --git a/common/mm_sound_dbus.c b/common/mm_sound_dbus.c index bbd357a..9e63056 100644 --- a/common/mm_sound_dbus.c +++ b/common/mm_sound_dbus.c @@ -81,6 +81,9 @@ const mm_sound_dbus_method_info_t g_methods[AUDIO_METHOD_MAX] = { [AUDIO_METHOD_GET_CONNECTED_DEVICE_LIST] = { .name = "GetConnectedDeviceList", }, + [AUDIO_METHOD_GET_DEVICE_BY_ID] = { + .name = "GetDeviceById", + }, [AUDIO_METHOD_IS_STREAM_ON_DEVICE] = { .name = "IsStreamOnDevice", }, diff --git a/include/mm_sound.h b/include/mm_sound.h index 2691676..67deb68 100644 --- a/include/mm_sound.h +++ b/include/mm_sound.h @@ -1019,7 +1019,9 @@ int mm_sound_remove_device_state_changed_callback(unsigned int id); int mm_sound_get_current_device_list(mm_sound_device_flags_e device_mask, MMSoundDeviceList_t *device_list); int mm_sound_get_device_list(int device_mask, MMSoundDeviceList_t *device_list); +int mm_sound_get_device_by_id(int device_id, MMSoundDevice_t **device); int mm_sound_free_device_list(MMSoundDeviceList_t device_list); +int mm_sound_free_device(MMSoundDevice_t *device); int mm_sound_get_next_device (MMSoundDeviceList_t device_list, MMSoundDevice_t *device); int mm_sound_get_prev_device (MMSoundDeviceList_t device_list, MMSoundDevice_t *device); int mm_sound_get_device_type(MMSoundDevice_t device_h, mm_sound_device_type_e *type); diff --git a/include/mm_sound_client.h b/include/mm_sound_client.h index b14b708..57da8b5 100644 --- a/include/mm_sound_client.h +++ b/include/mm_sound_client.h @@ -49,6 +49,7 @@ int mm_sound_client_set_filter_by_type(const char *stream_type, const char *filt int mm_sound_client_unset_filter_by_type(const char *stream_type); int mm_sound_client_control_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_controls); int mm_sound_client_get_current_connected_device_list(int device_flgas, mm_sound_device_list_t *device_list); +int mm_sound_client_get_device_by_id(int device_id, mm_sound_device_t **device); int mm_sound_client_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func, void* user_data, unsigned int *subs_id); int mm_sound_client_remove_device_connected_callback(unsigned int subs_id); int mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func, void* user_data, unsigned int *subs_id); diff --git a/include/mm_sound_intf.h b/include/mm_sound_intf.h index bf4a8b5..a231505 100644 --- a/include/mm_sound_intf.h +++ b/include/mm_sound_intf.h @@ -54,6 +54,7 @@ typedef enum audio_method { AUDIO_METHOD_GET_BT_A2DP_STATUS, AUDIO_METHOD_SET_PATH_FOR_ACTIVE_DEVICE, AUDIO_METHOD_GET_CONNECTED_DEVICE_LIST, + AUDIO_METHOD_GET_DEVICE_BY_ID, AUDIO_METHOD_IS_STREAM_ON_DEVICE, AUDIO_METHOD_GET_AUDIO_PATH, AUDIO_METHOD_SET_VOLUME_LEVEL, diff --git a/include/mm_sound_proxy.h b/include/mm_sound_proxy.h index 16b845c..36cc4c0 100644 --- a/include/mm_sound_proxy.h +++ b/include/mm_sound_proxy.h @@ -53,6 +53,7 @@ int mm_sound_proxy_clear_focus(int pid); // Not original focus feature, only for int mm_sound_proxy_add_play_sound_end_callback(mm_sound_stop_callback_wrapper_func func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id); int mm_sound_proxy_remove_play_sound_end_callback(unsigned subs_id); int mm_sound_proxy_get_current_connected_device_list(int device_flags, GList** device_list); +int mm_sound_proxy_get_device_by_id(int device_id, mm_sound_device_t **device); int mm_sound_proxy_add_device_connected_callback(int device_flags, mm_sound_device_connected_wrapper_cb func, void *userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id); int mm_sound_proxy_remove_device_connected_callback(unsigned subs_id); int mm_sound_proxy_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_wrapper_cb func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id); diff --git a/mm_sound_client.c b/mm_sound_client.c index c386cdb..1f1acbf 100644 --- a/mm_sound_client.c +++ b/mm_sound_client.c @@ -604,6 +604,20 @@ failed: return ret; } +int mm_sound_client_get_device_by_id(int device_id, mm_sound_device_t **device) +{ + int ret = MM_ERROR_NONE; + + debug_fenter(); + + if ((ret = mm_sound_proxy_get_device_by_id(device_id, device)) != MM_ERROR_NONE) + debug_error("[Client] failed to get device by id"); + + debug_fleave(); + + return ret; +} + static bool device_is_match_direction(int direction, int mask) { if (mask == DEVICE_IO_DIRECTION_FLAGS || mask == 0) diff --git a/mm_sound_device.c b/mm_sound_device.c index da59a1e..9073281 100644 --- a/mm_sound_device.c +++ b/mm_sound_device.c @@ -287,6 +287,31 @@ int mm_sound_free_device_list(MMSoundDeviceList_t device_list) } EXPORT_API +int mm_sound_free_device(MMSoundDevice_t *device) +{ + if (device == NULL) + return MM_ERROR_INVALID_ARGUMENT; + g_free(device); + + return MM_ERROR_NONE; +} + +EXPORT_API +int mm_sound_get_device_by_id(int device_id, MMSoundDevice_t **device) +{ + int ret = MM_ERROR_NONE; + + if (device_id < 1 || device == NULL) + return MM_ERROR_INVALID_ARGUMENT; + + ret = mm_sound_client_get_device_by_id(device_id, (mm_sound_device_t**)device); + if (ret < 0) + debug_error("Could not get device by id, ret = %x\n", ret); + + return ret; +} + +EXPORT_API int mm_sound_get_next_device (MMSoundDeviceList_t device_list, MMSoundDevice_t *device) { int ret = MM_ERROR_NONE; diff --git a/mm_sound_proxy.c b/mm_sound_proxy.c index d36e7ea..f560397 100644 --- a/mm_sound_proxy.c +++ b/mm_sound_proxy.c @@ -390,6 +390,61 @@ cleanup: return ret; } +int mm_sound_proxy_get_device_by_id(int device_id, mm_sound_device_t **device) +{ + int ret = MM_ERROR_NONE; + GVariant *params = NULL, *result = NULL; + mm_sound_device_t* device_item = NULL; + const gchar *device_name_tmp = NULL, *device_type_tmp = NULL; + + debug_fenter(); + + if (!device || device_id < 1) { + debug_error("Invalid Parameter, device null or improper device id"); + return MM_ERROR_INVALID_ARGUMENT; + } + + if ((params = g_variant_new("(i)", device_id)) == NULL) { + debug_error("Construct Param for get device by id failed"); + return MM_ERROR_SOUND_INTERNAL; + } + + if ((ret = mm_sound_dbus_method_call_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_METHOD_GET_DEVICE_BY_ID, params, &result)) != MM_ERROR_NONE) { + debug_error("get device by id failed"); + ret = MM_ERROR_SOUND_NO_DATA; + goto cleanup; + } + + if (result) { + if ((device_item = g_malloc0(sizeof(mm_sound_device_t))) == NULL) { + debug_error("Alloc device handle failed"); + ret = MM_ERROR_SOUND_INTERNAL; + goto cleanup; + } + + g_variant_get(result, "(i&sii&s)", + &device_item->id, &device_type_tmp, &device_item->io_direction, + &device_item->state, &device_name_tmp); + MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM); + MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN); + debug_log("Get device id(%d) type(%17s) direction(%d) state(%d) name(%s)", + device_item->id, device_item->type, device_item->io_direction, + device_item->state, device_item->name); + device_item->stream_num = -1; + *device = device_item; + } else { + debug_error("reply null"); + ret = MM_ERROR_SOUND_INTERNAL; + } + +cleanup: + if (result) + g_variant_unref(result); + + debug_fleave(); + return ret; +} + int mm_sound_proxy_add_device_connected_callback(int device_flags, mm_sound_device_connected_wrapper_cb func, void *userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id) { int ret = MM_ERROR_NONE; diff --git a/packaging/libmm-sound.spec b/packaging/libmm-sound.spec index c05ae53..417f274 100644 --- a/packaging/libmm-sound.spec +++ b/packaging/libmm-sound.spec @@ -1,6 +1,6 @@ Name: libmm-sound Summary: MMSound Package contains client lib and sound_server binary -Version: 0.11.2 +Version: 0.11.3 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/testsuite/mm_sound_testsuite_simple.c b/testsuite/mm_sound_testsuite_simple.c index 208289c..554976e 100755 --- a/testsuite/mm_sound_testsuite_simple.c +++ b/testsuite/mm_sound_testsuite_simple.c @@ -257,11 +257,12 @@ static void displaymenu() g_print("Z : VideoCall start \t"); g_print("N : Notification start \n"); g_print("n : VOIP start \t"); - g_print("v : Session end \t"); + g_print("v : Session end \n"); g_print("==================================================================\n"); g_print(" Audio device APIs\n"); g_print("==================================================================\n"); g_print("L : Get current list of connected devices \n"); + g_print("I : Get device by id \n"); g_print("C : Add device connected callback \t"); g_print("D : Remove device connected callback \n"); g_print("Q : Add device info. changed callback \t"); @@ -1355,6 +1356,48 @@ static void interpret (char *cmd) } } + else if(strncmp(cmd, "I", 1) == 0) { + int ret = 0; + MMSoundDevice_t device_h = NULL; + mm_sound_device_type_e device_type = 0; + mm_sound_device_io_direction_e io_direction = 0; + mm_sound_device_state_e state = 0; + char *name; + int id = 0, input_id = 0; + char input_string[128]; + + fflush(stdin); + g_print ("> Input id : "); + + if (fgets(input_string, sizeof(input_string)-1, stdin)) { + input_id = atoi(input_string); + + ret = mm_sound_get_device_by_id(input_id, &device_h); + if (ret == MM_ERROR_NONE) { + ret = mm_sound_get_device_type(device_h, &device_type); + if (ret) + g_print("failed to mm_sound_get_device_type()\n"); + ret = mm_sound_get_device_io_direction(device_h, &io_direction); + if (ret) + g_print("failed to mm_sound_get_device_io_direction()\n"); + ret = mm_sound_get_device_state(device_h, &state); + if (ret) + g_print("failed to mm_sound_get_device_state()\n"); + ret = mm_sound_get_device_id(device_h, &id); + if (ret) + g_print("failed to mm_sound_get_device_id()\n"); + ret = mm_sound_get_device_name(device_h, &name); + if (ret) + g_print("failed to mm_sound_get_device_name()\n"); + g_print("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name); + } else { + g_print("failed to mm_sound_get_device_by_id()\n"); + } + } else { + g_print("### fgets return NULL\n"); + } + } + else if(strncmp(cmd, "C", 1) == 0) { int ret = 0; char input_string[128];