Fix set_devices() to ensure resetting active devices info. before adding new device 23/56823/2
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 13 Jan 2016 02:18:01 +0000 (11:18 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 13 Jan 2016 02:38:09 +0000 (11:38 +0900)
Revise _do_route_reset() to update devices as its direction.
Remove unused verbs.

[Version] 0.2.14
[Profile] TV
[Issue Type] Bug fix

Change-Id: I5c34eb902165d2e917b0656d8e3094797e97ed6f
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/audio-hal-max98090.spec
tizen-audio-device.c
tizen-audio-internal.h
tizen-audio.h

index d1a745a..db53dbb 100644 (file)
@@ -1,6 +1,6 @@
 Name:       audio-hal-max98090
 Summary:    TIZEN Audio HAL for MAX98090
-Version:    0.2.13
+Version:    0.2.14
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index b39790a..25de3cb 100644 (file)
@@ -46,6 +46,10 @@ static device_type_t inDeviceTypes[] = {
     { 0, 0 },
 };
 
+static const char* mode_to_verb_str[] = {
+    AUDIO_USE_CASE_VERB_HIFI,
+};
+
 static uint32_t convert_device_string_to_enum(const char* device_str, uint32_t direction)
 {
     uint32_t device = 0;
@@ -84,6 +88,7 @@ static audio_return_t set_devices(audio_hal_t *ah, const char *verb, device_info
 
     AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
     AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER);
+    AUDIO_RETURN_VAL_IF_FAIL(num_of_devices, AUDIO_ERR_PARAMETER);
 
     if (num_of_devices > MAX_DEVICES) {
         num_of_devices = MAX_DEVICES;
@@ -91,23 +96,29 @@ static audio_return_t set_devices(audio_hal_t *ah, const char *verb, device_info
         return AUDIO_ERR_PARAMETER;
     }
 
-    if ((devices[0].direction == AUDIO_DIRECTION_OUT) && ah->device.active_in) {
-        /* check the active in devices */
-        for (j = 0; j < inDeviceTypes[j].type; j++) {
-            if (((ah->device.active_in & (~0x80000000)) & inDeviceTypes[j].type))
-                active_devices[dev_idx++] = inDeviceTypes[j].name;
+    if (devices[0].direction == AUDIO_DIRECTION_OUT) {
+        ah->device.active_out &= 0x0;
+        if (ah->device.active_in) {
+            /* check the active in devices */
+            for (j = 0; j < inDeviceTypes[j].type; j++) {
+                if (((ah->device.active_in & (~AUDIO_DEVICE_IN)) & inDeviceTypes[j].type))
+                    active_devices[dev_idx++] = inDeviceTypes[j].name;
+            }
         }
-    } else if ((devices[0].direction == AUDIO_DIRECTION_IN) && ah->device.active_out) {
-        /* check the active out devices */
-        for (j = 0; j < outDeviceTypes[j].type; j++) {
-            if (ah->device.active_out & outDeviceTypes[j].type)
-                active_devices[dev_idx++] = outDeviceTypes[j].name;
+    } else if (devices[0].direction == AUDIO_DIRECTION_IN) {
+        ah->device.active_in &= 0x0;
+        if (ah->device.active_out) {
+            /* check the active out devices */
+            for (j = 0; j < outDeviceTypes[j].type; j++) {
+                if (ah->device.active_out & outDeviceTypes[j].type)
+                    active_devices[dev_idx++] = outDeviceTypes[j].name;
+            }
         }
     }
 
     for (i = 0; i < num_of_devices; i++) {
         new_device = convert_device_string_to_enum(devices[i].type, devices[i].direction);
-        if (new_device & 0x80000000) {
+        if (new_device & AUDIO_DEVICE_IN) {
             for (j = 0; j < inDeviceTypes[j].type; j++) {
                 if (new_device == inDeviceTypes[j].type) {
                     active_devices[dev_idx++] = inDeviceTypes[j].name;
@@ -130,12 +141,10 @@ static audio_return_t set_devices(audio_hal_t *ah, const char *verb, device_info
     }
 
     audio_ret = _audio_ucm_set_devices(ah, verb, active_devices);
-    if (audio_ret) {
+    if (audio_ret)
         AUDIO_LOG_ERROR("Failed to set device: error = %d", audio_ret);
-        return audio_ret;
-    }
-    return audio_ret;
 
+    return audio_ret;
 }
 
 audio_return_t _audio_device_init(audio_hal_t *ah)
@@ -164,7 +173,7 @@ static audio_return_t _do_route_ap_playback_capture(audio_hal_t *ah, audio_route
 {
     audio_return_t audio_ret = AUDIO_RET_OK;
     device_info_t *devices = NULL;
-    const char *verb = NULL;
+    const char *verb = mode_to_verb_str[VERB_NORMAL];
 
     AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
     AUDIO_RETURN_VAL_IF_FAIL(route_info, AUDIO_ERR_PARAMETER);
@@ -175,7 +184,6 @@ static audio_return_t _do_route_ap_playback_capture(audio_hal_t *ah, audio_route
     /* int mod_idx = 0; */
     /* const char *modifiers[MAX_MODIFIERS] = {NULL,}; */
 
-    verb = AUDIO_USE_CASE_VERB_HIFI;
     AUDIO_LOG_INFO("do_route_ap_playback_capture++ ");
 
     audio_ret = set_devices(ah, verb, devices, route_info->num_of_devices);
@@ -206,11 +214,10 @@ static audio_return_t _do_route_ap_playback_capture(audio_hal_t *ah, audio_route
     return audio_ret;
 }
 
-audio_return_t _do_route_voip(audio_hal_t *ah, device_info_t *devices, int32_t num_of_devices)
+static audio_return_t _do_route_voip(audio_hal_t *ah, device_info_t *devices, int32_t num_of_devices)
 {
     audio_return_t audio_ret = AUDIO_RET_OK;
-    const char *verb = NULL;
-    verb = AUDIO_USE_CASE_VERB_HIFI;
+    const char *verb = mode_to_verb_str[VERB_NORMAL];
 
     AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
     AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER);
@@ -229,9 +236,11 @@ audio_return_t _do_route_voip(audio_hal_t *ah, device_info_t *devices, int32_t n
     return audio_ret;
 }
 
-audio_return_t _do_route_reset(audio_hal_t *ah, uint32_t direction)
+static audio_return_t _do_route_reset(audio_hal_t *ah, uint32_t direction)
 {
     audio_return_t audio_ret = AUDIO_RET_OK;
+    const char *active_devices[MAX_DEVICES] = {NULL,};
+    int i = 0, dev_idx = 0;
 
     /* FIXME: If you need to reset, set verb inactive */
     /* const char *verb = NULL; */
@@ -239,15 +248,41 @@ audio_return_t _do_route_reset(audio_hal_t *ah, uint32_t direction)
 
     AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
 
-    AUDIO_LOG_INFO("do_route_reset++, direction(%p)", direction);
+    AUDIO_LOG_INFO("do_route_reset++, direction(0x%x)", direction);
 
     if (direction == AUDIO_DIRECTION_OUT) {
         ah->device.active_out &= 0x0;
+        if (ah->device.active_in) {
+            /* check the active in devices */
+            for (i = 0; i < inDeviceTypes[i].type; i++) {
+                if (((ah->device.active_in & (~AUDIO_DEVICE_IN)) & inDeviceTypes[i].type)) {
+                    active_devices[dev_idx++] = inDeviceTypes[i].name;
+                    AUDIO_LOG_INFO("added for in : %s", inDeviceTypes[i].name);
+                }
+            }
+        }
     } else {
         ah->device.active_in &= 0x0;
+        if (ah->device.active_out) {
+            /* check the active out devices */
+            for (i = 0; i < outDeviceTypes[i].type; i++) {
+                if (ah->device.active_out & outDeviceTypes[i].type) {
+                    active_devices[dev_idx++] = outDeviceTypes[i].name;
+                    AUDIO_LOG_INFO("added for out : %s", outDeviceTypes[i].name);
+                }
+            }
+        }
     }
 
-    /* TO DO: Set Inactive */
+    if (active_devices[0] == NULL) {
+        AUDIO_LOG_DEBUG("active device is NULL, no need to update.");
+        return AUDIO_RET_OK;
+    }
+
+    audio_ret = _audio_ucm_set_devices(ah, mode_to_verb_str[ah->device.mode], active_devices);
+    if (audio_ret)
+        AUDIO_LOG_ERROR("Failed to set device: error = %d", audio_ret);
+
     return audio_ret;
 }
 
@@ -262,6 +297,8 @@ audio_return_t audio_do_route(void *audio_handle, audio_route_info_t *info)
 
     AUDIO_LOG_INFO("role:%s", info->role);
 
+    devices = info->device_infos;
+
     if (!strncmp("voip", info->role, MAX_NAME_LEN)) {
         audio_ret = _do_route_voip(ah, devices, info->num_of_devices);
         if (AUDIO_IS_ERROR(audio_ret)) {
@@ -275,7 +312,6 @@ audio_return_t audio_do_route(void *audio_handle, audio_route_info_t *info)
     } else {
         /* need to prepare for "alarm","notification","emergency","voice-information","voice-recognition","ringtone" */
         audio_ret = _do_route_ap_playback_capture(ah, info);
-
         if (AUDIO_IS_ERROR(audio_ret)) {
             AUDIO_LOG_WARN("set playback route return 0x%x", audio_ret);
         }
index c9fadb7..382d039 100644 (file)
 } while (0)
 
 /* Devices : Normal  */
+#define AUDIO_DEVICE_OUT               0x00000000
+#define AUDIO_DEVICE_IN                0x80000000
 enum audio_device_type {
     AUDIO_DEVICE_NONE                 = 0,
 
     /* output devices */
-    AUDIO_DEVICE_OUT_SPEAKER          = 0x00000001,
-    AUDIO_DEVICE_OUT_RECEIVER         = 0x00000002,
-    AUDIO_DEVICE_OUT_JACK             = 0x00000004,
-    AUDIO_DEVICE_OUT_BT_SCO           = 0x00000008,
-    AUDIO_DEVICE_OUT_AUX              = 0x00000010,
-    AUDIO_DEVICE_OUT_HDMI             = 0x00000020,
+    AUDIO_DEVICE_OUT_SPEAKER          = AUDIO_DEVICE_OUT | 0x00000001,
+    AUDIO_DEVICE_OUT_RECEIVER         = AUDIO_DEVICE_OUT | 0x00000002,
+    AUDIO_DEVICE_OUT_JACK             = AUDIO_DEVICE_OUT | 0x00000004,
+    AUDIO_DEVICE_OUT_BT_SCO           = AUDIO_DEVICE_OUT | 0x00000008,
+    AUDIO_DEVICE_OUT_AUX              = AUDIO_DEVICE_OUT | 0x00000010,
+    AUDIO_DEVICE_OUT_HDMI             = AUDIO_DEVICE_OUT | 0x00000020,
     AUDIO_DEVICE_OUT_ALL              = (AUDIO_DEVICE_OUT_SPEAKER |
                                          AUDIO_DEVICE_OUT_RECEIVER |
                                          AUDIO_DEVICE_OUT_JACK |
@@ -93,10 +95,10 @@ enum audio_device_type {
                                          AUDIO_DEVICE_OUT_AUX |
                                          AUDIO_DEVICE_OUT_HDMI),
     /* input devices */
-    AUDIO_DEVICE_IN_MAIN_MIC          = 0x80000001,
-    AUDIO_DEVICE_IN_SUB_MIC           = 0x80000002,
-    AUDIO_DEVICE_IN_JACK              = 0x80000004,
-    AUDIO_DEVICE_IN_BT_SCO            = 0x80000008,
+    AUDIO_DEVICE_IN_MAIN_MIC          = AUDIO_DEVICE_IN | 0x00000001,
+    AUDIO_DEVICE_IN_SUB_MIC           = AUDIO_DEVICE_IN | 0x00000002,
+    AUDIO_DEVICE_IN_JACK              = AUDIO_DEVICE_IN | 0x00000004,
+    AUDIO_DEVICE_IN_BT_SCO            = AUDIO_DEVICE_IN | 0x00000008,
     AUDIO_DEVICE_IN_ALL               = (AUDIO_DEVICE_IN_MAIN_MIC |
                                          AUDIO_DEVICE_IN_SUB_MIC |
                                          AUDIO_DEVICE_IN_JACK |
@@ -178,12 +180,6 @@ typedef struct audio_device_info {
 
 typedef enum audio_route_mode {
     VERB_NORMAL,
-
-/* Add verb mode if you need */
-
-/*   VERB_CALL, */
-/*   VERB_VOIP */
-
 } audio_route_mode_t;
 
 typedef struct audio_hal_device {
@@ -196,7 +192,6 @@ typedef struct audio_hal_device {
     audio_route_mode_t mode;
 } audio_hal_device_t;
 
-
 /* Stream */
 #define AUDIO_VOLUME_LEVEL_MAX 16
 
@@ -299,7 +294,7 @@ audio_return_t _audio_volume_init(audio_hal_t *ah);
 audio_return_t _audio_volume_deinit(audio_hal_t *ah);
 
 audio_return_t _audio_device_init(audio_hal_t *ah);
-audio_return_t _audio_device_deinit(audio_hal_t * ah);
+audio_return_t _audio_device_deinit(audio_hal_t *ah);
 audio_return_t _audio_ucm_init(audio_hal_t *ah);
 audio_return_t _audio_ucm_deinit(audio_hal_t *ah);
 void _audio_ucm_get_device_name(audio_hal_t *ah, const char *use_case, audio_direction_t direction, const char **value);
index a0427fc..dcc95da 100644 (file)
@@ -75,15 +75,18 @@ typedef struct audio_stream_info {
 typedef struct audio_interface {
     audio_return_t (*init)(void **audio_handle);
     audio_return_t (*deinit)(void *audio_handle);
+    /* Volume */
     audio_return_t (*get_volume_level_max)(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
     audio_return_t (*get_volume_level)(void *audio_handle, audio_volume_info_t *info, uint32_t *level);
     audio_return_t (*set_volume_level)(void *audio_handle, audio_volume_info_t *info, uint32_t level);
     audio_return_t (*get_volume_value)(void *audio_handle, audio_volume_info_t *info, uint32_t level, double *value);
     audio_return_t (*get_volume_mute)(void *audio_handle, audio_volume_info_t *info, uint32_t *mute);
     audio_return_t (*set_volume_mute)(void *audio_handle, audio_volume_info_t *info, uint32_t mute);
+    /* Routing */
     audio_return_t (*do_route)(void *audio_handle, audio_route_info_t *info);
     audio_return_t (*update_route_option)(void *audio_handle, audio_route_option_t *option);
     audio_return_t (*update_stream_connection_info) (void *audio_handle, audio_stream_info_t *info, uint32_t is_connected);
+    /* Buffer Attribute */
     audio_return_t (*get_buffer_attr)(void *audio_handle, uint32_t direction, const char *latency, uint32_t samplerate, int format, uint32_t channels,
                                       uint32_t *maxlength, uint32_t *tlength, uint32_t *prebuf, uint32_t* minreq, uint32_t *fragsize);
     /* Interface of PCM device */