From: Sangchul Lee Date: Thu, 15 Jun 2017 05:48:05 +0000 (+0900) Subject: Add new internal APIs to get device vendor id/product id X-Git-Tag: submit/tizen/20170615.073353~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=21e457df4b2693621997f9c739b45bff96f51bc4;p=platform%2Fcore%2Fapi%2Fsound-manager.git Add new internal APIs to get device vendor id/product id - sound_manager_get_device_vendor_id() - sound_manager_get_device_product_id() [Version] 0.4.7 [Issue Type] New internal API Change-Id: I22979338683b1d0b5462984f2bf7f2d38ccfba82 Signed-off-by: Sangchul Lee --- diff --git a/include/sound_manager_internal.h b/include/sound_manager_internal.h index 93da0ef..a21ec4d 100644 --- a/include/sound_manager_internal.h +++ b/include/sound_manager_internal.h @@ -462,6 +462,60 @@ int sound_manager_unset_filter(sound_stream_type_e stream_type); */ int sound_manager_set_filter_preset(sound_stream_type_e stream_type, sound_filter_e filter, sound_filter_preset_e preset); +/** + * @internal + * @brief Gets the vendor id of the device. + * @since_tizen 4.0 + * + * @remarks It works only with USB audio device. Otherwise, #SOUND_MANAGER_ERROR_NOT_SUPPORTED will be returned.\n + * + * @param[in] device The device item + * @param[out] vendor_id The vendor id of the device + * @return @c 0 on success, + * otherwise a negative error value + * @retval #SOUND_MANAGER_ERROR_NONE Success + * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SOUND_MANAGER_ERROR_NOT_SUPPORTED Not supported + * @see sound_manager_get_device_list() + * @see sound_manager_get_next_device() + * @see sound_manager_get_prev_device() + * @see sound_manager_get_device_type() + * @see sound_manager_get_device_io_direction() + * @see sound_manager_get_device_name() + * @see sound_manager_get_device_state() + * @see sound_manager_get_device_id() + * @see sound_manager_get_device_product_id() + * @see sound_manager_free_device_list() + */ +int sound_manager_get_device_vendor_id(sound_device_h device, int *vendor_id); + +/** + * @internal + * @brief Gets the product id of the device. + * @since_tizen 4.0 + * + * @remarks It works only with USB audio device. Otherwise, #SOUND_MANAGER_ERROR_NOT_SUPPORTED will be returned.\n + * + * @param[in] device The device item + * @param[out] product_id The product id of the device + * @return @c 0 on success, + * otherwise a negative error value + * @retval #SOUND_MANAGER_ERROR_NONE Success + * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SOUND_MANAGER_ERROR_NOT_SUPPORTED Not supported + * @see sound_manager_get_device_list() + * @see sound_manager_get_next_device() + * @see sound_manager_get_prev_device() + * @see sound_manager_get_device_type() + * @see sound_manager_get_device_io_direction() + * @see sound_manager_get_device_name() + * @see sound_manager_get_device_state() + * @see sound_manager_get_device_id() + * @see sound_manager_get_device_vendor_id() + * @see sound_manager_free_device_list() + */ +int sound_manager_get_device_product_id(sound_device_h device, int *product_id); + /** * @} */ diff --git a/packaging/capi-media-sound-manager.spec b/packaging/capi-media-sound-manager.spec index 92cecae..aedba9c 100644 --- a/packaging/capi-media-sound-manager.spec +++ b/packaging/capi-media-sound-manager.spec @@ -1,6 +1,6 @@ Name: capi-media-sound-manager Summary: Sound Manager library -Version: 0.4.6 +Version: 0.4.7 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/sound_manager_internal.c b/src/sound_manager_internal.c index 9cc1f3b..bc4618c 100644 --- a/src/sound_manager_internal.c +++ b/src/sound_manager_internal.c @@ -448,3 +448,50 @@ int sound_manager_set_filter_preset(sound_stream_type_e stream_type, sound_filte LEAVE: return _convert_sound_manager_error_code(__func__, ret); } + +int sound_manager_get_device_vendor_id(sound_device_h device, int *vendor_id) +{ + int ret = MM_ERROR_NONE; + mm_sound_device_type_e type; + + LOGI(">> enter"); + + SM_INSTANCE_CHECK(device); + SM_NULL_ARG_CHECK(vendor_id); + + if ((ret = mm_sound_get_device_type(device, &type))) + return _convert_sound_manager_error_code(__func__, ret); + + if (type != MM_SOUND_DEVICE_TYPE_USB_AUDIO) { + LOGE("device type is not USB audio device, device_type[%d]", type); + return SOUND_MANAGER_ERROR_NOT_SUPPORTED; + } + + ret = mm_sound_get_device_vendor_id(device, vendor_id); + + return _convert_sound_manager_error_code(__func__, ret); +} + +int sound_manager_get_device_product_id(sound_device_h device, int *product_id) +{ + int ret = MM_ERROR_NONE; + mm_sound_device_type_e type; + + LOGI(">> enter"); + + SM_INSTANCE_CHECK(device); + SM_NULL_ARG_CHECK(product_id); + + if ((ret = mm_sound_get_device_type(device, &type))) + return _convert_sound_manager_error_code(__func__, ret); + + if (type != MM_SOUND_DEVICE_TYPE_USB_AUDIO) { + LOGE("device type is not USB audio device, device_type[%d]", type); + return SOUND_MANAGER_ERROR_NOT_SUPPORTED; + } + + ret = mm_sound_get_device_product_id(device, product_id); + + return _convert_sound_manager_error_code(__func__, ret); +} + diff --git a/test/sound_manager_test.c b/test/sound_manager_test.c index 0321611..93628b2 100644 --- a/test/sound_manager_test.c +++ b/test/sound_manager_test.c @@ -593,28 +593,36 @@ void _set_session_interrupted_cb(sound_session_interrupted_code_e code, void *us /* If failed to get some property, just give some default value */ void _get_device_props_simple(sound_device_h device, int *id, char **type, char **name, - const char **direc, const char **state) + const char **direc, const char **state, int *vendor_id, int *product_id) { int ret; sound_device_type_e _type; sound_device_io_direction_e _direc; sound_device_state_e _state; + *id = -1; + *vendor_id = -1; + *product_id = -1; + if ((ret = sound_manager_get_device_type(device, &_type))) g_print("failed to get device type, ret[0x%x]\n", ret); else _convert_device_type_enum_to_str(_type, type); - if ((ret = sound_manager_get_device_id(device, id))) { + if ((ret = sound_manager_get_device_id(device, id))) g_print("failed to get device id, ret[0x%x]\n", ret); - *id = -1; - } if (_type == SOUND_DEVICE_BLUETOOTH_MEDIA || _type == SOUND_DEVICE_BLUETOOTH_VOICE || _type == SOUND_DEVICE_USB_AUDIO) { if ((ret = sound_manager_get_device_name(device, name))) { g_print("failed to get device name, ret[0x%x]\n", ret); *name = NOT_AVAIL; } + if (_type == SOUND_DEVICE_USB_AUDIO) { + if ((ret = sound_manager_get_device_vendor_id(device, vendor_id))) + g_print("failed to get device vendor id, ret[0x%x]\n", ret); + if ((ret = sound_manager_get_device_product_id(device, product_id))) + g_print("failed to get device product id, ret[0x%x]\n", ret); + } } else { *name = ""; } @@ -637,39 +645,45 @@ void _get_device_props_simple(sound_device_h device, int *id, char **type, char void _set_device_connected_cb(sound_device_h device, bool is_connected, void *user_data) { int id = -1; + int vendor_id = -1; + int product_id = -1; char *type, *name; const char *direc, *state; - _get_device_props_simple(device, &id, &type, &name, &direc, &state); + _get_device_props_simple(device, &id, &type, &name, &direc, &state, &vendor_id, &product_id); g_print("[ Device #%d %s %s ] %s\n", id, type, name, is_connected ? "Connected" : "Disconnected"); - g_print(" Direc[ %-4s ] State[ %-12s ]\n", direc, state); + g_print(" Direc[ %-4s ] State[ %-12s ] VendorID[ %04x ], ProductID[ %04x ]\n", direc, state, vendor_id, product_id); } void _set_device_info_changed_cb(sound_device_h device, sound_device_changed_info_e changed_info, void *user_data) { int id = -1; + int vendor_id = -1; + int product_id = -1; char *type, *name; const char *direc, *state; const char *changed_info_str[] = {"State", "Direction", "Avail-Mode"}; - _get_device_props_simple(device, &id, &type, &name, &direc, &state); + _get_device_props_simple(device, &id, &type, &name, &direc, &state, &vendor_id, &product_id); g_print("[Device #%d %s %s] %s changed\n", id, type, name, changed_info_str[changed_info]); - g_print(" Direc[ %-4s ] State[ %-12s ]\n", direc, state); + g_print(" Direc[ %-4s ] State[ %-12s ] VendorID[ %04x ], ProductID[ %04x ]\n", direc, state, vendor_id, product_id); } void _device_state_changed_cb(sound_device_h device, sound_device_state_e state, void *user_data) { int id = -1; + int vendor_id = -1; + int product_id = -1; char *type, *name; const char *direc, *_state; - _get_device_props_simple(device, &id, &type, &name, &direc, &_state); + _get_device_props_simple(device, &id, &type, &name, &direc, &_state, &vendor_id, &product_id); g_print("[Device #%d %s %s] state changed\n", id, type, name); - g_print(" Direc[ %-4s ] State(%d)[ %-12s ]\n", direc, state, _state); + g_print(" Direc[ %-4s ] State(%d)[ %-12s ] VendorID[ %04x ], ProductID[ %04x ]\n", direc, state, _state, vendor_id, product_id); } void reset_menu_state(void) @@ -1001,6 +1015,8 @@ static void interpret(char *cmd) sound_device_h device; int ret = SOUND_MANAGER_ERROR_NONE; int id = -1; + int vendor_id = -1; + int product_id = -1; char *type; char *name; const char *direc; @@ -1008,9 +1024,9 @@ static void interpret(char *cmd) if (!(ret = sound_manager_get_device_list(g_device_mask, &device_list))) { g_print("success to get current device list\n"); while (!sound_manager_get_next_device(device_list, &device)) { - _get_device_props_simple(device, &id, &type, &name, &direc, &state); + _get_device_props_simple(device, &id, &type, &name, &direc, &state, &vendor_id, &product_id); g_print("[ Device #%d %s %s ]\n", id, type, name); - g_print(" Direc[ %-4s ] State[ %-12s ]\n", direc, state); + g_print(" Direc[ %-4s ] State[ %-12s ] VendorID[ %04x ], ProductID[ %04x ]\n", direc, state, vendor_id, product_id); } } else { g_print("fail to get current device list, ret[0x%x]\n", ret);