Fix set_devices() to ensure resetting active devices info. before adding new device 21/56821/1
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 13 Jan 2016 01:53:32 +0000 (10:53 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 13 Jan 2016 01:53:32 +0000 (10:53 +0900)
Revise _do_route_reset() to update devices as its direction.
Remove unused verbs.

[Version] 0.2.15
[Profile] Mobile
[Issue Type] Bug fix

Change-Id: I6c79e1bffcdf98bee1155669a7634618e82f9ce7

packaging/audio-hal-wm5110.spec
tizen-audio-device.c
tizen-audio-internal.h
tizen-audio-ucm.c
tizen-audio.h

index 147ca1d4879eb9c5f6aa6109b2592a776cc25249..d6daaa474cd32e9b5d37905e466b5a4f2c3ab2fd 100644 (file)
@@ -1,6 +1,6 @@
 Name:       audio-hal-wm5110
 Summary:    TIZEN Audio HAL for WM5110
-Version:    0.2.14
+Version:    0.2.15
 Release:    0
 VCS:        adaptation/samsung_exynos/audio-hal-wm5110#a568942051241d60e37c6738466a2a5058f260c0
 Group:      System/Libraries
index 129ca7c8622841ac2e76f1070c5f818c9de6479a..5df61684d3728f42f9742e129cd9942b58e3e985 100644 (file)
@@ -48,6 +48,14 @@ static device_type_t inDeviceTypes[] = {
     { 0, 0 },
 };
 
+static const char* mode_to_verb_str[] = {
+    AUDIO_USE_CASE_VERB_HIFI,
+    AUDIO_USE_CASE_VERB_VOICECALL,
+};
+
+static int _voice_pcm_open(audio_hal_t *ah);
+static int _voice_pcm_close(audio_hal_t *ah, uint32_t direction);
+
 static uint32_t convert_device_string_to_enum(const char* device_str, uint32_t direction)
 {
     uint32_t device = 0;
@@ -87,6 +95,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;
@@ -94,23 +103,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;
@@ -133,12 +148,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)
@@ -167,7 +180,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);
@@ -178,7 +191,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);
@@ -213,11 +225,10 @@ static audio_return_t _do_route_ap_playback_capture(audio_hal_t *ah, audio_route
 
     return audio_ret;
 }
-audio_return_t _do_route_voicecall(audio_hal_t *ah, device_info_t *devices, int32_t num_of_devices)
+static audio_return_t _do_route_voicecall(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_VOICECALL;
+    const char *verb = mode_to_verb_str[VERB_VOICECALL];
 
     AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
     AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER);
@@ -230,17 +241,17 @@ audio_return_t _do_route_voicecall(audio_hal_t *ah, device_info_t *devices, int3
         return audio_ret;
     }
     /* FIXME. Get network info and configure rate in pcm device */
-    ah->device.mode = VERB_CALL;
+    ah->device.mode = VERB_VOICECALL;
     if (ah->device.active_out && ah->device.active_in)
         _voice_pcm_open(ah);
 
     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);
@@ -259,27 +270,52 @@ 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;
-
-    /* FIXME: If you need to reset, set verb inactive */
-    /* const char *verb = NULL; */
-    /* verb = AUDIO_USE_CASE_VERB_INACTIVE; */
+    const char *active_devices[MAX_DEVICES] = {NULL,};
+    int i = 0, dev_idx = 0;
 
     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);
+                }
+            }
+        }
     }
-    if (ah->device.mode == VERB_CALL) {
+    if (ah->device.mode == VERB_VOICECALL) {
         _voice_pcm_close(ah, direction);
     }
-    /* 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;
 }
 
@@ -314,7 +350,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);
         }
@@ -410,7 +445,7 @@ error:
     return -1;
 }
 
-int _voice_pcm_open(audio_hal_t *ah)
+static int _voice_pcm_open(audio_hal_t *ah)
 {
     int err, ret = 0;
 
@@ -438,7 +473,7 @@ int _voice_pcm_open(audio_hal_t *ah)
     return ret;
 }
 
-int _voice_pcm_close(audio_hal_t *ah, uint32_t direction)
+static int _voice_pcm_close(audio_hal_t *ah, uint32_t direction)
 {
     AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
 
@@ -454,7 +489,7 @@ int _voice_pcm_close(audio_hal_t *ah, uint32_t direction)
         AUDIO_LOG_INFO("voice pcm_in handle close success");
     }
 
-    return 0;
+    return AUDIO_RET_OK;
 }
 
 #ifdef __USE_TINYALSA__
index 7c2f1d732431040e8fc9d07b701413efef6242ae..0a468145732faa7af6f728a0d3a754ae0e6b7c55 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 |
@@ -113,7 +115,6 @@ typedef struct device_type {
 #define AUDIO_USE_CASE_VERB_HIFI                    "HiFi"
 #define AUDIO_USE_CASE_VERB_VOICECALL               "VoiceCall"
 #define AUDIO_USE_CASE_VERB_LOOPBACK                "Loopback"
-#define AUDIO_USE_CASE_VERB_FMRADIO                 "FM_Radio"
 
 /* Modifiers */
 #define AUDIO_USE_CASE_MODIFIER_VOICESEARCH              "VoiceSearch"
@@ -184,8 +185,7 @@ typedef struct audio_device_info {
 
 typedef enum audio_route_mode {
     VERB_NORMAL,
-    VERB_CALL,
-    VERB_VOIP
+    VERB_VOICECALL,
 } audio_route_mode_t;
 
 typedef struct audio_hal_device {
@@ -198,7 +198,6 @@ typedef struct audio_hal_device {
     audio_route_mode_t mode;
 } audio_hal_device_t;
 
-
 /* Stream */
 #define AUDIO_VOLUME_LEVEL_MAX 16
 
@@ -310,8 +309,6 @@ audio_return_t _audio_ucm_set_use_case(audio_hal_t *ah, const char *verb, const
 audio_return_t _audio_ucm_set_devices(audio_hal_t *ah, const char *verb, const char *devices[]);
 audio_return_t _audio_ucm_set_modifiers(audio_hal_t *ah, const char *verb, const char *modifiers[]);
 int _audio_ucm_fill_device_info_list(audio_hal_t *ah, audio_device_info_t *device_info_list, const char *verb);
-int _voice_pcm_open(audio_hal_t *ah);
-int _voice_pcm_close(audio_hal_t *ah, uint32_t direction);
 audio_return_t _audio_ucm_get_verb(audio_hal_t *ah, const char **value);
 audio_return_t _audio_ucm_reset_use_case(audio_hal_t *ah);
 audio_return_t _audio_util_init(audio_hal_t *ah);
index 71615390ca966adc803997f724339be1662288e3..3356ba4ba5d11ebbf2b2758ab9b6929408143b10 100644 (file)
@@ -123,14 +123,11 @@ int _audio_ucm_fill_device_info_list(audio_hal_t *ah, audio_device_info_t *devic
     }
 
     /* prepare destination */
-    /*If the devices are VOICECALL LOOPBACK or FMRADIO then pulseaudio need not get the device notification*/
+    /*If the devices are VOICECALL LOOPBACK then pulseaudio need not get the device notification*/
     if (verb) {
         if (strncmp(verb, AUDIO_USE_CASE_VERB_VOICECALL, strlen(AUDIO_USE_CASE_VERB_VOICECALL)) &&
             strncmp(verb, AUDIO_USE_CASE_VERB_LOOPBACK, strlen(AUDIO_USE_CASE_VERB_LOOPBACK))) {
             __add_ucm_device_info(ah, verb, AUDIO_DIRECTION_IN, device_info_list, &device_info_count);
-            if (strncmp(verb, AUDIO_USE_CASE_VERB_FMRADIO, strlen(AUDIO_USE_CASE_VERB_FMRADIO))) {
-                __add_ucm_device_info(ah, verb, AUDIO_DIRECTION_OUT, device_info_list, &device_info_count);
-            }
         }
 
         if (curr_verb)
index a0427fc305ed75f3c09cbbbd98f6a7a58da1477d..dcc95da6307b5dceb6e3110b5238fc12df4efc54 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 */