Add internal API to set preferred device id 43/212243/4 accepted/tizen/unified/20190821.064540 submit/tizen/20190820.081105
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 19 Aug 2019 07:40:38 +0000 (16:40 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 20 Aug 2019 05:37:35 +0000 (14:37 +0900)
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 <sc11.lee@samsung.com>
include/sound_manager_internal.h
include/sound_manager_internal_tv.h
include/sound_manager_private.h
packaging/capi-media-sound-manager.spec
src/sound_manager_internal.c
src/sound_manager_private.c
test/sound_manager_test.c

index db40ebe655988f67dd26d40c8778c5221940851b..2be7d68ad9f6b161c7a85e039af203aaa2312917 100644 (file)
@@ -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.
index 879e3b403f06e46fcbb6ccf172f4782f896e8f1c..6b9b68da6f2d8fe6f61565c99d7396436e2e8461 100644 (file)
@@ -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.
index e2f97dbfc125e63593ac72430cd2a1b9d2c1ae4a..7792769113770fc1a1aa39571c73e6db0b11fdf2 100644 (file)
@@ -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
index 8257c2ef6f658058ba827d94a64b05d954d45b6f..3faed0dc08673215222d51a985d1c17d1c0cb56f 100644 (file)
@@ -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
index 106fe935e1b0d360ae3b1bd3c659968c181105eb..eee36b478b6f14d73efff481bafd718f59bed99f 100644 (file)
@@ -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;
index 0ca908855e464cbe4ffda42a9282b98cbb2829ce..98aa32638e5ed145271f5abe9210ba718f63f2bc 100644 (file)
@@ -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);
index c3c4776b502939f538e51d488142ad3b8dde1734..130995076d6e79aa857fe34aec9d756dce61ee40 100644 (file)
@@ -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;