Fix set_devices() to ensure resetting active devices info. before adding new device 24/56824/1
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 13 Jan 2016 02:30:48 +0000 (11:30 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 13 Jan 2016 02:32:55 +0000 (11:32 +0900)
Revise _do_route_reset() to update devices as its direction.
Remove unused verbs.

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

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

index b9248a15bc83b5e1dbaa22cc2d5e32cf7fa65d56..d52d422363109772e2c2e5d8ca174ff3371f8b6c 100644 (file)
@@ -1,6 +1,6 @@
 Name:       audio-hal-hawkp
 Summary:    TIZEN Audio HAL for Hawkp
-Version:    0.1.6
+Version:    0.1.7
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index fd17b205a9797419f34c816c4847b429e6efec89..49b01ee5b894f3e615a641312942dcea84693efc 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;
@@ -131,14 +142,11 @@ static audio_return_t set_devices(audio_hal_t *ah, const char *verb, device_info
 
 #ifdef USE_UCM
     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;
-    }
 #endif
 
     return audio_ret;
-
 }
 
 audio_return_t _audio_device_init(audio_hal_t *ah)
@@ -167,7 +175,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 +186,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);
@@ -209,11 +216,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);
@@ -232,9 +238,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; */
@@ -242,15 +250,43 @@ 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);
+                }
+            }
+        }
+    }
+
+    if (active_devices[0] == NULL) {
+        AUDIO_LOG_DEBUG("active device is NULL, no need to update.");
+        return AUDIO_RET_OK;
     }
 
-    /* TO DO: Set Inactive */
+#ifdef USE_UCM
+    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);
+#endif
+
     return audio_ret;
 }
 
@@ -280,7 +316,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 16e28e269c54f83c4d6cea34a9af77cb86570349..ccb296573dc392fcd8d49677cea703bfbd7f2390 100644 (file)
 #define AMIXER_AMP_MUTE_DEFAULT 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 |
@@ -103,10 +105,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 |
@@ -190,12 +192,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 {
@@ -208,7 +204,6 @@ typedef struct audio_hal_device {
     audio_route_mode_t mode;
 } audio_hal_device_t;
 
-
 /* Stream */
 #define AUDIO_VOLUME_LEVEL_MAX 16
 
@@ -313,9 +308,9 @@ 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_ucm_init(audio_hal_t *ah);
 
 #ifdef USE_UCM
+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);
 #define _audio_ucm_update_use_case _audio_ucm_set_use_case
index 83c604c3c44a56a1276be7d56cedead29eb64552..2c91e81cbec1754b2b7975a61558f59849fde013 100644 (file)
@@ -101,7 +101,9 @@ audio_return_t audio_deinit(void *audio_handle)
 
     _audio_device_deinit(ah);
     _audio_volume_deinit(ah);
+#ifdef USE_UCM
     _audio_ucm_deinit(ah);
+#endif
     _audio_util_deinit(ah);
     free(ah);
     ah = NULL;
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 */