From: Sangchul Lee Date: Mon, 19 Aug 2019 07:40:38 +0000 (+0900) Subject: Add internal API to set preferred device id X-Git-Tag: submit/tizen/20190820.081105^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F43%2F212243%2F4;p=platform%2Fcore%2Fapi%2Fsound-manager.git Add internal API to set preferred device id It'll be used in CSharp API. (Tizen.Multimedia.AudioStreamPolicy) [Version] 0.5.36 [Issue Type] New internal API Change-Id: Ib5d21b430b411662e151fee1845a57af66f4927c Signed-off-by: Sangchul Lee --- diff --git a/include/sound_manager_internal.h b/include/sound_manager_internal.h index db40ebe..2be7d68 100644 --- a/include/sound_manager_internal.h +++ b/include/sound_manager_internal.h @@ -339,6 +339,39 @@ int sound_manager_add_device_id_for_stream_routing(sound_stream_info_h stream_in */ int sound_manager_remove_device_id_for_stream_routing(sound_stream_info_h stream_info, int device_id); +/** + * @internal + * @brief Sets the preferred built-in device id for the stream routing. + * @since_tizen 5.5 + * + * @remarks This function is to set a specific built-in device id when the system has multiple devices of the same built-in device type. + * When there's only one device for a built-in device type in the system, nothing will happen even if this function succeeds in operation. + * If the device type of @a device_id is not supported by @a stream_info, #SOUND_MANAGER_ERROR_POLICY will be returned. + * + * @param[in] stream_info The handle of stream information + * @param[in] io_direction The IO direction of the device + * @param[in] device_id The preferred device id (this can be #SOUND_MANAGER_STREAM_NO_PREFERRED_DEVICE to unset) + * @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_POLICY Noncompliance with the sound system policy + * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system + * @pre Call sound_manager_create_stream_information() before calling this function. + * @pre Get a device by calling sound_manager_get_device_list() and sound_manager_get_next_device(). + * @pre Get a device id by calling sound_manager_get_device_id(). + * @post You can get preferred devices by calling sound_manager_get_stream_preferred_device(). + * @post Call sound_manager_free_device_list() to free the devices. + * @see sound_manager_get_stream_preferred_device() + * @see sound_manager_create_stream_information() + * @see sound_manager_destroy_stream_information() + * @see sound_manager_get_device_list() + * @see sound_manager_get_next_device() + * @see sound_manager_get_device_id() + * @see sound_manager_free_device_list() + */ +int sound_manager_set_stream_preferred_device_id(sound_stream_info_h stream_info, sound_device_io_direction_e io_direction, int device_id); + /** * @internal * @brief Gets the state of the device by id. diff --git a/include/sound_manager_internal_tv.h b/include/sound_manager_internal_tv.h index 879e3b4..6b9b68d 100644 --- a/include/sound_manager_internal_tv.h +++ b/include/sound_manager_internal_tv.h @@ -294,6 +294,39 @@ int sound_manager_add_device_id_for_stream_routing(sound_stream_info_h stream_in */ int sound_manager_remove_device_id_for_stream_routing(sound_stream_info_h stream_info, int device_id); +/** + * @internal + * @brief Sets the preferred built-in device id for the stream routing. + * @since_tizen 5.5 + * + * @remarks This function is to set a specific built-in device id when the system has multiple devices of the same built-in device type. + * When there's only one device for a built-in device type in the system, nothing will happen even if this function succeeds in operation. + * If the device type of @a device_id is not supported by @a stream_info, #SOUND_MANAGER_ERROR_POLICY will be returned. + * + * @param[in] stream_info The handle of stream information + * @param[in] io_direction The IO direction of the device + * @param[in] device_id The preferred device id (this can be #SOUND_MANAGER_STREAM_NO_PREFERRED_DEVICE to unset) + * @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_POLICY Noncompliance with the sound system policy + * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system + * @pre Call sound_manager_create_stream_information() before calling this function. + * @pre Get a device by calling sound_manager_get_device_list() and sound_manager_get_next_device(). + * @pre Get a device id by calling sound_manager_get_device_id(). + * @post You can get preferred devices by calling sound_manager_get_stream_preferred_device(). + * @post Call sound_manager_free_device_list() to free the devices. + * @see sound_manager_get_stream_preferred_device() + * @see sound_manager_create_stream_information() + * @see sound_manager_destroy_stream_information() + * @see sound_manager_get_device_list() + * @see sound_manager_get_next_device() + * @see sound_manager_get_device_id() + * @see sound_manager_free_device_list() + */ +int sound_manager_set_stream_preferred_device_id(sound_stream_info_h stream_info, sound_device_io_direction_e io_direction, int device_id); + /** * @internal * @brief Gets the state of the device by id. diff --git a/include/sound_manager_private.h b/include/sound_manager_private.h index e2f97db..7792769 100644 --- a/include/sound_manager_private.h +++ b/include/sound_manager_private.h @@ -374,6 +374,8 @@ int _get_ducking_state(uint32_t stream_index, bool *is_ducked); int _set_preferred_device(sound_stream_info_s *stream_info, sound_device_io_direction_e direction, sound_device_h device); +int _set_preferred_device_id(sound_stream_info_s *stream_info, sound_device_io_direction_e direction, int device_id); + int _get_preferred_device(sound_stream_info_s *stream_info, int *in_device_id, int *out_device_id); #ifdef __cplusplus diff --git a/packaging/capi-media-sound-manager.spec b/packaging/capi-media-sound-manager.spec index 8257c2e..3faed0d 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.5.35 +Version: 0.5.36 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/sound_manager_internal.c b/src/sound_manager_internal.c index 106fe93..eee36b4 100644 --- a/src/sound_manager_internal.c +++ b/src/sound_manager_internal.c @@ -212,6 +212,18 @@ int sound_manager_remove_device_id_for_stream_routing(sound_stream_info_h stream return _convert_sound_manager_error_code(__func__, ret); } +int sound_manager_set_stream_preferred_device_id(sound_stream_info_h stream_info, sound_device_io_direction_e io_direction, int device_id) +{ + int ret = MM_ERROR_NONE; + sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info; + + SM_NULL_ARG_CHECK(stream_h); + + ret = _set_preferred_device_id(stream_h, io_direction, device_id); + + return _convert_sound_manager_error_code(__func__, ret); +} + int sound_manager_get_device_state_by_id(int device_id, sound_device_state_e *state) { int ret = MM_ERROR_NONE; diff --git a/src/sound_manager_private.c b/src/sound_manager_private.c index 0ca9088..98aa326 100644 --- a/src/sound_manager_private.c +++ b/src/sound_manager_private.c @@ -2885,8 +2885,7 @@ LEAVE: return ret; } - -int _set_preferred_device(sound_stream_info_s *stream_info, sound_device_io_direction_e direction, sound_device_h device) +static int __invoke_ipc_set_preferred_device_id(sound_stream_info_s *stream_info, int device_id, sound_device_io_direction_e io_direction, sound_device_io_direction_e req_direction) { int ret = MM_ERROR_NONE; GVariant *result = NULL; @@ -2894,43 +2893,19 @@ int _set_preferred_device(sound_stream_info_s *stream_info, sound_device_io_dire GError *err = NULL; const gchar *dbus_ret = NULL; const gchar *direction_str; - bool available = false; - int device_id = 0; - mm_sound_device_io_direction_e io_direction; int i; SM_INSTANCE_CHECK_FOR_PRIV(stream_info); - /* allow only auto route type */ - if ((ret = __check_auto_route_type(stream_info))) - return ret; - - /* check if this device belongs to available devices of the stream info */ - /* In case device is null, it's for unsetting preferred device, device_id will be 0. */ - if (device) { - if ((ret = __is_available_device(stream_info, device, &available))) - return ret; - if (!available) - return MM_ERROR_POLICY_INTERNAL; - if ((ret = mm_sound_get_device_id(device, &device_id))) - return ret; - if ((ret = mm_sound_get_device_io_direction(device, &io_direction))) - return ret; - if (!(io_direction & (direction + 1)) || ((int)io_direction < (int)(direction + 1))) { - LOGE("device direction(0x%x), request direction(0x%x)", io_direction, (direction + 1)); - return MM_ERROR_INVALID_ARGUMENT; - } - } - if ((ret = __get_dbus_connection(&conn))) return ret; for (i = SOUND_DEVICE_IO_DIRECTION_IN; i < SOUND_DEVICE_IO_DIRECTION_BOTH; i++) { - if (device) { + if (device_id) { if (!(io_direction & (i + 1))) continue; } else { - if (!((direction + 1) & (i + 1))) + if (!((req_direction + 1) & (i + 1))) continue; } direction_str = (i == SOUND_DEVICE_IO_DIRECTION_IN) ? "in" : "out"; @@ -2979,10 +2954,84 @@ int _set_preferred_device(sound_stream_info_s *stream_info, sound_device_io_dire LEAVE: g_object_unref(conn); - return ret; } +int _set_preferred_device(sound_stream_info_s *stream_info, sound_device_io_direction_e direction, sound_device_h device) +{ + int ret = MM_ERROR_NONE; + bool available = false; + int device_id = 0; + mm_sound_device_io_direction_e io_direction = MM_SOUND_DEVICE_IO_DIRECTION_IN; + + SM_INSTANCE_CHECK_FOR_PRIV(stream_info); + + /* allow only auto route type */ + if ((ret = __check_auto_route_type(stream_info))) + return ret; + + /* check if this device belongs to available devices of the stream info */ + /* In case device is null, it's for unsetting preferred device, device_id will be 0. */ + if (device) { + if ((ret = __is_available_device(stream_info, device, &available))) + return ret; + if (!available) + return MM_ERROR_POLICY_INTERNAL; + if ((ret = mm_sound_get_device_id(device, &device_id))) + return ret; + if ((ret = mm_sound_get_device_io_direction(device, &io_direction))) + return ret; + if (!(io_direction & (direction + 1)) || ((int)io_direction < (int)(direction + 1))) { + LOGE("device direction(0x%x), request direction(0x%x)", io_direction, (direction + 1)); + return MM_ERROR_INVALID_ARGUMENT; + } + } + + return __invoke_ipc_set_preferred_device_id(stream_info, device_id, io_direction, direction); +} + +int _set_preferred_device_id(sound_stream_info_s *stream_info, sound_device_io_direction_e direction, int device_id) +{ + int ret = MM_ERROR_NONE; + bool available = false; + mm_sound_device_io_direction_e io_direction = MM_SOUND_DEVICE_IO_DIRECTION_IN; + + SM_INSTANCE_CHECK_FOR_PRIV(stream_info); + + /* allow only auto route type */ + if ((ret = __check_auto_route_type(stream_info))) + return ret; + + /* check if this device belongs to available devices of the stream info */ + /* In case device_id is 0, it's for unsetting preferred device. */ + if (device_id) { + MMSoundDevice_t device = NULL; + + if ((ret = mm_sound_get_device_by_id(device_id, &device))) { + LOGE("failed to mm_sound_get_device_by_id()"); + return ret; + } + if ((ret = __is_available_device(stream_info, (sound_device_h)device, &available))) + goto device_free; + if (!available) { + ret = MM_ERROR_POLICY_INTERNAL; + goto device_free; + } + if ((ret = mm_sound_get_device_io_direction(device, &io_direction))) + goto device_free; + if (!(io_direction & (direction + 1)) || ((int)io_direction < (int)(direction + 1))) { + LOGE("device direction(0x%x), request direction(0x%x)", io_direction, (direction + 1)); + ret = MM_ERROR_INVALID_ARGUMENT; + } +device_free: + mm_sound_free_device(device); + if (ret) + return ret; + } + + return __invoke_ipc_set_preferred_device_id(stream_info, device_id, io_direction, direction); +} + int _get_preferred_device(sound_stream_info_s *stream_info, int *in_device_id, int *out_device_id) { SM_INSTANCE_CHECK_FOR_PRIV(stream_info); diff --git a/test/sound_manager_test.c b/test/sound_manager_test.c index c3c4776..1309950 100644 --- a/test/sound_manager_test.c +++ b/test/sound_manager_test.c @@ -68,6 +68,7 @@ enum { CURRENT_STATUS_REMOVE_DEVICE_ID_FOR_STREAM_ROUTING, CURRENT_STATUS_APPLY_STREAM_ROUTING, CURRENT_STATUS_SET_STREAM_PREFERRED_DEVICE, + CURRENT_STATUS_SET_STREAM_PREFERRED_DEVICE_ID, CURRENT_STATUS_GET_STREAM_PREFERRED_DEVICE, CURRENT_STATUS_SET_STREAM_ROUTING_OPTION, CURRENT_STATUS_ACQUIRE_FOCUS, @@ -282,6 +283,8 @@ void _interpret_main_menu(char *cmd) g_menu_state = CURRENT_STATUS_SET_STREAM_ROUTING_OPTION; else if (strncmp(cmd, "spd", MAX_CMD_LEN) == 0) g_menu_state = CURRENT_STATUS_SET_STREAM_PREFERRED_DEVICE; + else if (strncmp(cmd, "spi", MAX_CMD_LEN) == 0) + g_menu_state = CURRENT_STATUS_SET_STREAM_PREFERRED_DEVICE_ID; else if (strncmp(cmd, "gpd", MAX_CMD_LEN) == 0) g_menu_state = CURRENT_STATUS_GET_STREAM_PREFERRED_DEVICE; else if (strncmp(cmd, "afc", MAX_CMD_LEN) == 0) @@ -425,6 +428,7 @@ void display_sub_basic() g_print("aps. Apply devices for Stream Routing\t"); g_print("rad. Remove all devices for Stream Routing\n"); g_print("spd. Set preferred device\t"); + g_print("spi. *Set preferred device id\t"); g_print("gpd. Get preferred device\n"); g_print("afc. Acquire Focus\t"); g_print("rfc. Release Focus\t"); @@ -544,7 +548,11 @@ static void displaymenu() g_print("*** press enter to apply devices for stream routing\n"); else if (g_menu_state == CURRENT_STATUS_SET_STREAM_PREFERRED_DEVICE) g_print("*** input direction to set preferred device (0:out, 1:in, 2:both)\n"); - else if (g_menu_state == CURRENT_STATUS_GET_STREAM_PREFERRED_DEVICE) + else if (g_menu_state == CURRENT_STATUS_SET_STREAM_PREFERRED_DEVICE_ID) { + if (flag == 0) + g_print("*** input preferred device id(0:unset, 1 ~: device_id) and direction(0:out, 1:in, 2:both)\n"); + flag = 1; + } else if (g_menu_state == CURRENT_STATUS_GET_STREAM_PREFERRED_DEVICE) g_print("*** press enter to get preferred device\n"); else if (g_menu_state == CURRENT_STATUS_SET_STREAM_ROUTING_OPTION) g_print("*** input option(name/value) for routing (0:option_1/0, 1:option_1/1, 2:option_2/0, 3:option_2:1)\n"); @@ -1703,6 +1711,41 @@ static void interpret(char *cmd) reset_menu_state(); break; } + case CURRENT_STATUS_SET_STREAM_PREFERRED_DEVICE_ID: { + int ret = SOUND_MANAGER_ERROR_NONE; + static int cnt = 0; + static int preferred_device_id = 0; + sound_device_io_direction_e direction; + + if (cnt == 0) { + preferred_device_id = atoi(cmd); + cnt++; + } else if (cnt == 1) { + switch ( atoi(cmd)) { + case 0: + direction = SOUND_DEVICE_IO_DIRECTION_OUT; + break; + case 1: + direction = SOUND_DEVICE_IO_DIRECTION_IN; + break; + case 2: + direction = SOUND_DEVICE_IO_DIRECTION_BOTH; + break; + default: + g_print("invalid argument, try again..\n"); + reset_menu_state(); + goto end; + } + cnt = 0; + + ret = sound_manager_set_stream_preferred_device_id(g_stream_info_h, direction, preferred_device_id); + if (ret) + g_print("failed to sound_manager_set_stream_preferred_device_id(), ret(0x%x)\n", ret); + + reset_menu_state(); + } + break; + } case CURRENT_STATUS_GET_STREAM_PREFERRED_DEVICE: { int ret = SOUND_MANAGER_ERROR_NONE; int in_device_id = 0;