Modify module-policy (including stream-manager.c/device-manager/hal-manager/communicator) 60/41960/3
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 19 Jun 2015 08:09:32 +0000 (17:09 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 24 Jun 2015 08:26:31 +0000 (01:26 -0700)
Apply initial volume level when initializing volume map
Rename APIs in device-manager.c
Add hal-manager APIs
Revise codes in stream-manager-volume.c
Ready for route option feature
Remove update_volume feature that is called when active device is changed in sound_server
Prepare interface for device information changed callback (communicator.c/device-manager.c/module-policy.c)
Change default booting sound

[Version] 0.5-9
[Profile] Common
[Issue Type] code refactorying

Change-Id: Iebf7e70c501be01b45888b217c60685d9094ecb6

16 files changed:
packaging/pulseaudio.spec
src/map-file
src/modules/module-sound-player.c
src/modules/tizen-audio.h
src/modules/tizen/communicator.h
src/modules/tizen/device-manager.c
src/modules/tizen/device-manager.h
src/modules/tizen/hal-manager.c
src/modules/tizen/hal-manager.h
src/modules/tizen/module-policy.c
src/modules/tizen/stream-manager-volume-priv.h
src/modules/tizen/stream-manager-volume.c
src/modules/tizen/stream-manager-volume.h
src/modules/tizen/stream-manager.c
src/pulse/ext-policy.c
src/pulse/ext-policy.h

index f955824..6e19df5 100644 (file)
@@ -11,7 +11,7 @@
 Name:             pulseaudio
 Summary:          Improved Linux sound server
 Version:          5.0
-Release:          8
+Release:          9
 Group:            Multimedia/Audio
 License:          GPL-2.0+ and LGPL-2.1+
 URL:              http://pulseaudio.org
index 2a3fd8d..457b6af 100644 (file)
@@ -196,7 +196,6 @@ pa_ext_policy_reset;
 pa_ext_policy_get_volume_level_max;
 pa_ext_policy_get_volume_level;
 pa_ext_policy_set_volume_level;
-pa_ext_policy_update_volume;
 pa_ext_policy_get_mute
 pa_ext_policy_set_mute;
 pa_ext_node_manager_test;
index 440c85c..3dac1a8 100644 (file)
@@ -177,6 +177,9 @@ static int _simple_play(struct userdata *u, const char *file_path, uint32_t volu
 
     p = pa_proplist_new();
 
+    /* Set role type of stream, temporarily fixed */
+    /* Later on, we need to get it from an argument */
+    pa_proplist_sets(p, PA_PROP_MEDIA_ROLE, "system");
     /* Set volume type of stream */
     pa_proplist_setf(p, PA_PROP_MEDIA_TIZEN_VOLUME_TYPE, "%d", volume_type);
     /* Set gain type of stream */
index 8fe4ee6..967e10a 100644 (file)
@@ -34,7 +34,6 @@
 
 typedef enum audio_return {
     AUDIO_RET_OK                        = 0,
-    AUDIO_RET_USE_HW_CONTROL            = (int32_t)0x40001000,
     AUDIO_ERR_UNDEFINED                 = (int32_t)0x80001000,
     AUDIO_ERR_RESOURCE                  = (int32_t)0x80001001,
     AUDIO_ERR_PARAMETER                 = (int32_t)0x80001002,
@@ -82,8 +81,8 @@ typedef enum audio_session_command {
 
 /* Direction */
 typedef enum audio_direction {
-    AUDIO_DIRECTION_OUT,                /**< Playback */
     AUDIO_DIRECTION_IN,                 /**< Capture */
+    AUDIO_DIRECTION_OUT,                /**< Playback */
 } audio_direction_t;
 
 
@@ -204,7 +203,7 @@ typedef struct device_info {
 
 typedef struct audio_route_info {
     char *role;
-    device_info_t **device_infos;
+    device_info_t *device_infos;
     uint32_t num_of_devices;
 } audio_route_info_t;
 
index 5e7a09d..763b520 100644 (file)
@@ -6,8 +6,8 @@ typedef enum pa_communicator_hook {
     PA_COMMUNICATOR_HOOK_SELECT_INIT_SINK_OR_SOURCE,
     PA_COMMUNICATOR_HOOK_CHANGE_ROUTE,
     PA_COMMUNICATOR_HOOK_UPDATE_ROUTE_OPTIONS,
-    PA_COMMUNICATOR_HOOK_DEVICE_CONNECTED,
-    PA_COMMUNICATOR_HOOK_DEVICE_DISCONNECTED,
+    PA_COMMUNICATOR_HOOK_DEVICE_CONNECTION_CHANGED,
+    PA_COMMUNICATOR_HOOK_DEVICE_INFORMATION_CHANGED,
     PA_COMMUNICATOR_HOOK_MAX
 } pa_communicator_hook_t;
 
index c78b4e5..d304064 100644 (file)
@@ -22,6 +22,7 @@
 #include <pulsecore/protocol-dbus.h>
 #endif
 
+#include "communicator.h"
 #include "device-manager.h"
 
 #define DEVICE_MAP_FILE                    "/etc/pulse/device-map.json"
@@ -1409,6 +1410,7 @@ static int user_device_list_remove_device(pa_idxset *user_device_list, user_devi
 static int device_list_add_device(pa_idxset *device_list, device_item *device, pa_device_manager *dm) {
     user_device_item *device_u;
     uint32_t active_profile;
+    pa_device_manager_hook_data_for_conn_changed conn_changed_info;
 
     pa_assert(device_list);
     pa_assert(device);
@@ -1427,7 +1429,10 @@ static int device_list_add_device(pa_idxset *device_list, device_item *device, p
     user_device_list_add_device(dm->user_device_list, device_u, dm);
 
     pa_log_debug("Notify Device connected");
-    pa_hook_fire(pa_communicator_hook(dm->comm, PA_COMMUNICATOR_HOOK_DEVICE_CONNECTED), device);
+
+    conn_changed_info.is_connected = TRUE;
+    conn_changed_info.device = device;
+    pa_hook_fire(pa_communicator_hook(dm->comm, PA_COMMUNICATOR_HOOK_DEVICE_CONNECTION_CHANGED), &conn_changed_info);
 
     return 0;
 }
@@ -1435,6 +1440,7 @@ static int device_list_add_device(pa_idxset *device_list, device_item *device, p
 static int device_list_remove_device(pa_idxset *device_list, device_item *device, pa_device_manager *dm) {
     user_device_item *device_u;
     uint32_t active_profile = 0, prev_active_profile;
+    pa_device_manager_hook_data_for_conn_changed conn_changed_info;
 
     pa_assert(device_list);
     pa_assert(device);
@@ -1458,9 +1464,13 @@ static int device_list_remove_device(pa_idxset *device_list, device_item *device
         }
     }
 
-    destroy_device_item(device);
     pa_log_debug("Notify Device disconnected");
-    pa_hook_fire(pa_communicator_hook(dm->comm, PA_COMMUNICATOR_HOOK_DEVICE_DISCONNECTED), device);
+
+    conn_changed_info.is_connected = FALSE;
+    conn_changed_info.device = device;
+    pa_hook_fire(pa_communicator_hook(dm->comm, PA_COMMUNICATOR_HOOK_DEVICE_CONNECTION_CHANGED), &conn_changed_info);
+
+    destroy_device_item(device);
 
     return 0;
 }
@@ -3019,7 +3029,7 @@ static void handle_load_sink(DBusConnection *conn, DBusMessage *msg, void *userd
                                        DBUS_TYPE_INT32, &role,
                                        DBUS_TYPE_INVALID));
 
-    device_manager_load_sink(device_type, role, dm);
+    pa_device_manager_load_sink(device_type, role, dm);
 }
 
 
@@ -3165,7 +3175,7 @@ static void dbus_deinit(pa_device_manager *dm) {
 #endif
 
 
-device_item* device_manager_get_device_item(pa_device_manager *dm, audio_device_t device_type) {
+device_item* pa_device_manager_get_device(pa_device_manager *dm, audio_device_t device_type) {
     device_item *device;
     uint32_t idx;
 
@@ -3179,7 +3189,7 @@ device_item* device_manager_get_device_item(pa_device_manager *dm, audio_device_
     return NULL;
 }
 
-device_item* device_manager_get_device_item_with_id(pa_device_manager *dm, uint32_t id) {
+device_item* pa_device_manager_get_device_by_id(pa_device_manager *dm, uint32_t id) {
     device_item *device;
     user_device_item *device_u;
     uint32_t idx;
@@ -3199,46 +3209,46 @@ device_item* device_manager_get_device_item_with_id(pa_device_manager *dm, uint3
     return NULL;
 }
 
-audio_device_t device_item_get_type(device_item *device) {
+pa_sink* pa_device_manager_get_sink(device_item *device, audio_device_role_t role) {
     pa_assert(device);
 
-    return device->type;
+    return pa_hashmap_get(device->playback_devices, PA_INT_TO_PTR(role));
 }
 
-audio_device_direction_t device_item_get_direction(device_item *device) {
+pa_source* pa_device_manager_get_source(device_item *device, audio_device_role_t role) {
     pa_assert(device);
 
-    return device->direction;
+    return pa_hashmap_get(device->capture_devices, PA_INT_TO_PTR(role));
 }
 
-pa_sink* device_item_get_sink(device_item *device, audio_device_role_t role) {
+void pa_device_manager_set_device_state(pa_device_manager *dm, device_item *device, audio_device_status_t state) {
+    pa_assert(dm);
     pa_assert(device);
 
-    return pa_hashmap_get(device->playback_devices, PA_INT_TO_PTR(role));
+    device->state = state;
+    send_device_info_changed_signal(device->device_u, AUDIO_DEVICE_CHANGED_INFO_STATE, dm);
 }
 
-pa_source* device_item_get_source(device_item *device, audio_device_role_t role) {
+audio_device_status_t pa_device_manager_get_device_state(pa_device_manager *dm, device_item *device) {
+    pa_assert(dm);
     pa_assert(device);
 
-    return pa_hashmap_get(device->capture_devices, PA_INT_TO_PTR(role));
+    return device->state;
 }
 
-void device_item_set_state(pa_device_manager *dm, device_item *device, audio_device_status_t state) {
-    pa_assert(dm);
+audio_device_t pa_device_manager_get_device_type(device_item *device) {
     pa_assert(device);
 
-    device->state = state;
-    send_device_info_changed_signal(device->device_u, AUDIO_DEVICE_CHANGED_INFO_STATE, dm);
+    return device->type;
 }
 
-audio_device_status_t device_item_get_state(pa_device_manager *dm, device_item *device) {
-    pa_assert(dm);
+audio_device_direction_t pa_device_manager_get_device_direction(device_item *device) {
     pa_assert(device);
 
-    return device->state;
+    return device->direction;
 }
 
-int device_manager_load_sink(audio_device_t device_type, audio_device_role_t role, pa_device_manager *dm) {
+int pa_device_manager_load_sink(audio_device_t device_type, audio_device_role_t role, pa_device_manager *dm) {
     const char *device_string, *params;
     struct device_type_prop *type_item;
     struct device_file_prop *file_item;
@@ -3292,7 +3302,7 @@ failed:
     return -1;
 }
 
-int device_manager_load_source(audio_device_t device_type, audio_device_role_t role, pa_device_manager *dm) {
+int pa_device_manager_load_source(audio_device_t device_type, audio_device_role_t role, pa_device_manager *dm) {
     const char *device_string, *params;
     struct device_type_prop *type_item;
     struct device_file_prop *file_item;
@@ -3345,7 +3355,7 @@ failed:
     return -1;
 }
 
-pa_device_manager* device_manager_init(pa_core *c) {
+pa_device_manager* pa_device_manager_init(pa_core *c) {
     pa_device_manager *dm;
 
     dm = pa_xnew0(pa_device_manager, 1);
@@ -3392,7 +3402,7 @@ pa_device_manager* device_manager_init(pa_core *c) {
     return dm;
 }
 
-void device_manager_done(pa_device_manager *dm) {
+void pa_device_manager_done(pa_device_manager *dm) {
     if (!dm)
         return;
 
index cb8dc27..c96397f 100644 (file)
@@ -1,6 +1,5 @@
 
 #include <pulsecore/core.h>
-#include "communicator.h"
 
 typedef enum audio_device_type {
     AUDIO_DEVICE_NONE,
@@ -35,7 +34,8 @@ typedef enum audio_device_direction_type {
 
 typedef enum audio_device_changed_into_type {
     AUDIO_DEVICE_CHANGED_INFO_STATE,
-    AUDIO_DEVICE_CHANGED_INFO_IO_DIRECTION
+    AUDIO_DEVICE_CHANGED_INFO_IO_DIRECTION,
+    AUDIO_DEVICE_CHANGED_INFO_SUB_TYPE,
 } audio_device_changed_info_t;
 
 typedef enum audio_device_status_type {
@@ -46,18 +46,28 @@ typedef enum audio_device_status_type {
 typedef struct pa_device_manager pa_device_manager;
 typedef struct device_item device_item;
 
-pa_device_manager* device_manager_init(pa_core* core);
-void device_manager_done(pa_device_manager *dm);
+typedef struct _hook_call_data_for_conn_changed {
+    pa_bool_t is_connected;
+    device_item *device;
+} pa_device_manager_hook_data_for_conn_changed;
 
-device_item* device_manager_get_device_item(pa_device_manager *dm, audio_device_t device_type);
-device_item* device_manager_get_device_item_with_id(pa_device_manager *dm, uint32_t id);
+typedef struct _hook_call_data_for_info_changed {
+    audio_device_changed_info_t changed_info;
+    device_item *device;
+} pa_device_manager_hook_data_for_info_changed;
 
-audio_device_t device_item_get_type(device_item *device);
-audio_device_direction_t device_item_get_direction(device_item *device);
-pa_sink* device_item_get_sink(device_item *device, audio_device_role_t role);
-pa_source* device_item_get_source(device_item *device, audio_device_role_t role);
-void device_item_set_state(pa_device_manager *dm, device_item *device, audio_device_status_t state);
-audio_device_status_t device_item_get_state(pa_device_manager *dm, device_item *device);
+pa_device_manager* pa_device_manager_init(pa_core* core);
+void pa_device_manager_done(pa_device_manager *dm);
 
-int device_manager_load_sink(audio_device_t device_type, audio_device_role_t role, pa_device_manager *dm);
-int device_manager_load_source(audio_device_t device_type, audio_device_role_t role, pa_device_manager *dm);
+device_item* pa_device_manager_get_device(pa_device_manager *dm, audio_device_t device_type);
+device_item* pa_device_manager_get_device_by_id(pa_device_manager *dm, uint32_t id);
+
+pa_sink* pa_device_manager_get_sink(device_item *device, audio_device_role_t role);
+pa_source* pa_device_manager_get_source(device_item *device, audio_device_role_t role);
+void pa_device_manager_set_device_state(pa_device_manager *dm, device_item *device, audio_device_status_t state);
+audio_device_status_t pa_device_manager_get_device_state(pa_device_manager *dm, device_item *device);
+audio_device_t pa_device_manager_get_device_type(device_item *device);
+audio_device_direction_t pa_device_manager_get_device_direction(device_item *device);
+
+int pa_device_manager_load_sink(audio_device_t device_type, audio_device_role_t role, pa_device_manager *dm);
+int pa_device_manager_load_source(audio_device_t device_type, audio_device_role_t role, pa_device_manager *dm);
index f5e2021..785e24f 100644 (file)
@@ -126,20 +126,136 @@ void pa_hal_manager_unref(pa_hal_manager *h) {
     pa_xfree(h);
 }
 
-audio_return_t pa_hal_get_buffer_attribute(pa_hal_manager *h, audio_latency_t latency, uint32_t samplerate, audio_sample_format_t format, uint32_t channels, uint32_t *maxlength, uint32_t *tlength, uint32_t *prebuf, uint32_t* minreq, uint32_t *fragsize) {
-    audio_return_t ret = AUDIO_RET_OK;
+int32_t pa_hal_manager_get_buffer_attribute(pa_hal_manager *h, audio_latency_t latency, pa_sink_input_new_data *new_data, uint32_t *maxlength, uint32_t *tlength, uint32_t *prebuf, uint32_t* minreq, uint32_t *fragsize) {
+    int32_t ret = 0;
+    audio_return_t hal_ret = AUDIO_RET_OK;
 
     pa_assert(h);
+    pa_assert(new_data);
 
-    pa_log_info("latency:%d, rate:%u, format:%d, channels:%u)", latency, samplerate, format, channels);
-    if (h->intf.get_buffer_attr) {
-        ret = h->intf.get_buffer_attr(h->data, latency, samplerate, format, channels, maxlength, tlength, prebuf, minreq, fragsize);
-        if (ret != AUDIO_RET_OK) {
-            pa_log_error("Failed get_buffer_attr() - ret:%d", ret);
-        } else {
-            pa_log_info("maxlength:%d, tlength:%d, prebuf:%d, minreq:%d, fragsize:%d", maxlength, tlength, prebuf, minreq, fragsize);
-        }
+    pa_log_info("latency:%d, rate:%u, format:%d, channels:%u", latency, new_data->sample_spec.rate, new_data->sample_spec.format, new_data->sample_spec.channels);
+
+    if (AUDIO_IS_ERROR(hal_ret = h->intf.get_buffer_attr(h->data, latency, new_data->sample_spec.rate, new_data->sample_spec.format, new_data->sample_spec.channels, maxlength, tlength, prebuf, minreq, fragsize))) {
+        pa_log_error("get_buffer_attr returns error:0x%x", hal_ret);
+        ret = -1;
+    } else
+        pa_log_info("maxlength:%d, tlength:%d, prebuf:%d, minreq:%d, fragsize:%d", *maxlength, *tlength, *prebuf, *minreq, *fragsize);
+
+    return ret;
+}
+
+int32_t pa_hal_manager_get_volume_level_max (pa_hal_manager *h, const char *volume_type, io_direction direction, uint32_t *level) {
+    int32_t ret = 0;
+    audio_return_t hal_ret = AUDIO_RET_OK;
+
+    pa_assert(h);
+    pa_assert(volume_type);
+    pa_assert(level);
+
+    if (AUDIO_IS_ERROR((hal_ret = h->intf.get_volume_level_max(h->data, volume_type, direction, level)))) {
+        pa_log_error("get_volume_level_max returns error:0x%x", hal_ret);
+        ret = -1;
     }
+    return ret;
+}
+
+int32_t pa_hal_manager_get_volume_level (pa_hal_manager *h, const char *volume_type, io_direction direction, uint32_t *level) {
+    int32_t ret = 0;
+    audio_return_t hal_ret = AUDIO_RET_OK;
 
+    pa_assert(h);
+    pa_assert(volume_type);
+    pa_assert(level);
+
+    if (AUDIO_IS_ERROR((hal_ret = h->intf.get_volume_level(h->data, volume_type, direction, level)))) {
+        pa_log_error("get_volume_level returns error:0x%x", hal_ret);
+        ret = -1;
+    }
+    return ret;
+}
+
+int32_t pa_hal_manager_set_volume_level (pa_hal_manager *h, const char *volume_type, io_direction direction, uint32_t level) {
+    int32_t ret = 0;
+    audio_return_t hal_ret = AUDIO_RET_OK;
+
+    pa_assert(h);
+    pa_assert(volume_type);
+
+    if (AUDIO_IS_ERROR((hal_ret = h->intf.set_volume_level(h->data, volume_type, direction, level)))) {
+        pa_log_error("set_volume_level returns error:0x%x", hal_ret);
+        ret = -1;
+    }
+    return ret;
+}
+
+int32_t pa_hal_manager_get_volume_value (pa_hal_manager *h, audio_info_t *info, const char *volume_type, io_direction direction, uint32_t level, double *value) {
+    int32_t ret = 0;
+    audio_return_t hal_ret = AUDIO_RET_OK;
+
+    pa_assert(h);
+    pa_assert(volume_type);
+    pa_assert(value);
+
+    if (AUDIO_IS_ERROR((hal_ret = h->intf.get_volume_value(h->data, NULL, volume_type, direction, level, value)))) {
+        pa_log_error("get_volume_value returns error:0x%x", hal_ret);
+        ret = -1;
+    }
+    return ret;
+}
+
+int32_t pa_hal_manager_get_mute (pa_hal_manager *h, const char *volume_type, io_direction direction, uint32_t *mute) {
+    int32_t ret = 0;
+    audio_return_t hal_ret = AUDIO_RET_OK;
+
+    pa_assert(h);
+    pa_assert(volume_type);
+    pa_assert(mute);
+
+    if (AUDIO_IS_ERROR(hal_ret = h->intf.get_mute(h->data, volume_type, direction, mute))) {
+        pa_log_error("get_mute returns error:0x%x", hal_ret);
+        ret = -1;
+    }
+    return ret;
+}
+
+int32_t pa_hal_manager_set_mute (pa_hal_manager *h, const char *volume_type, io_direction direction, uint32_t mute) {
+    int32_t ret = 0;
+    audio_return_t hal_ret = AUDIO_RET_OK;
+
+    pa_assert(h);
+    pa_assert(volume_type);
+
+    if (AUDIO_IS_ERROR(hal_ret = h->intf.set_mute(h->data, volume_type, direction, mute))) {
+        pa_log_error("set_mute returns error:0x%x", hal_ret);
+        ret = -1;
+    }
+    return ret;
+}
+
+int32_t pa_hal_manager_do_route (pa_hal_manager *h, hal_route_info_t *info) {
+    int32_t ret = 0;
+    audio_return_t hal_ret = AUDIO_RET_OK;
+
+    pa_assert(h);
+    pa_assert(info);
+
+    if (AUDIO_IS_ERROR(hal_ret = h->intf.do_route(&h->data, (audio_route_info_t*)info))) {
+        pa_log_error("do_route returns error:0x%x", hal_ret);
+        ret = -1;
+    }
+    return ret;
+}
+
+int32_t pa_hal_manager_update_route_option (pa_hal_manager *h, hal_route_option_t *option) {
+    int32_t ret = 0;
+    audio_return_t hal_ret = AUDIO_RET_OK;
+
+    pa_assert(h);
+    pa_assert(option);
+
+    if (AUDIO_IS_ERROR(hal_ret = h->intf.update_route_option(&h->data, (audio_route_option_t*)option))) {
+        pa_log_error("update_route_option returns error:0x%x", hal_ret);
+        ret = -1;
+    }
     return ret;
 }
index 5064945..9c1aeba 100644 (file)
@@ -2,6 +2,7 @@
 #define foohalmanagerfoo
 #include <dlfcn.h>
 #include <pulsecore/core.h>
+
 #include "tizen-audio.h"
 /* TODO : move below structure to hal-manager.c */
 struct _pa_hal_manager {
@@ -15,9 +16,40 @@ struct _pa_hal_manager {
 
 typedef struct _pa_hal_manager pa_hal_manager;
 
+typedef enum _io_direction {
+    DIRECTION_IN,
+    DIRECTION_OUT,
+} io_direction;
+
+typedef struct hal_device_info {
+    char *type;
+    uint32_t direction;
+    uint32_t id;
+} hal_device_info_t;
+
+typedef struct hal_route_info {
+    char *role;
+    hal_device_info_t *device_infos;
+    uint32_t num_of_devices;
+} hal_route_info_t;
+
+typedef struct hal_route_option {
+    char *role;
+    char **options;
+    uint32_t num_of_options;
+} hal_route_option_t;
+
 pa_hal_manager* pa_hal_manager_get(pa_core *core, void *user_data);
 pa_hal_manager* pa_hal_manager_ref(pa_hal_manager *h);
 void pa_hal_manager_unref(pa_hal_manager *h);
-audio_return_t pa_hal_get_buffer_attribute(pa_hal_manager *h, audio_latency_t latency, uint32_t samplerate, audio_sample_format_t format, uint32_t channels, uint32_t *maxlength, uint32_t *tlength, uint32_t *prebuf, uint32_t* minreq, uint32_t *fragsize);
+int32_t pa_hal_manager_get_buffer_attribute(pa_hal_manager *h, audio_latency_t latency, pa_sink_input_new_data *new_data, uint32_t *maxlength, uint32_t *tlength, uint32_t *prebuf, uint32_t* minreq, uint32_t *fragsize);
+int32_t pa_hal_manager_get_volume_level_max (pa_hal_manager *h, const char *volume_type, io_direction direction, uint32_t *level);
+int32_t pa_hal_manager_get_volume_level (pa_hal_manager *h, const char *volume_type, io_direction direction, uint32_t *level);
+int32_t pa_hal_manager_set_volume_level (pa_hal_manager *h, const char *volume_type, io_direction direction, uint32_t level);
+int32_t pa_hal_manager_get_volume_value (pa_hal_manager *h, audio_info_t *info, const char *volume_type, io_direction direction, uint32_t level, double *value);
+int32_t pa_hal_manager_get_mute (pa_hal_manager *h, const char *volume_type, io_direction direction, uint32_t *mute);
+int32_t pa_hal_manager_set_mute (pa_hal_manager *h, const char *volume_type, io_direction direction, uint32_t mute);
+int32_t pa_hal_manager_do_route (pa_hal_manager *h, hal_route_info_t *info);
+int32_t pa_hal_manager_update_route_option (pa_hal_manager *h, hal_route_option_t *option);
 
 #endif
index 4504777..4d3ee3b 100644 (file)
@@ -330,7 +330,7 @@ static pa_dbus_interface_info policy_interface_info = {
 /* check if this sink is bluez */
 
 /* Vconf Keys */
-#define DEFAULT_BOOTING_SOUND_PATH "/usr/share/keysound/poweron.wav"
+#define DEFAULT_BOOTING_SOUND_PATH "/usr/share/keysound/poweron.ogg"
 #define VCONF_BOOTING "memory/private/sound/booting"
 #ifdef BURST_SHOT
 #define VCONF_SOUND_BURSTSHOT "memory/private/sound/burstshot"
@@ -432,8 +432,10 @@ struct userdata {
         pa_hook_slot *comm_hook_select_proper_sink_or_source_slot;
         pa_hook_slot *comm_hook_change_route_slot;
         pa_hook_slot *comm_hook_update_route_options_slot;
-        pa_hook_slot *comm_hook_device_connected_slot;
-        pa_hook_slot *comm_hook_device_disconnected_slot;
+#ifdef DEVICE_MANAGER
+        pa_hook_slot *comm_hook_device_connection_changed_slot;
+        pa_hook_slot *comm_hook_device_information_changed_slot;
+#endif
     } communicator;
 
     pa_stream_manager *stream_manager;
@@ -466,7 +468,6 @@ enum {
     SUBCOMMAND_GET_VOLUME_LEVEL_MAX,
     SUBCOMMAND_GET_VOLUME_LEVEL,
     SUBCOMMAND_SET_VOLUME_LEVEL,
-    SUBCOMMAND_UPDATE_VOLUME,
     SUBCOMMAND_GET_MUTE,
     SUBCOMMAND_SET_MUTE,
     SUBCOMMAND_IS_AVAILABLE_HIGH_LATENCY,
@@ -1951,6 +1952,7 @@ static void __play_audio_sample_timeout_cb(pa_mainloop_api *m, pa_time_event *e,
     pa_mutex_unlock(u->audio_sample_userdata.mutex);
 }
 
+/* It will be moved to module-sound-player */
 static audio_return_t policy_play_sample_continuously(struct userdata *u, pa_native_connection *c, const char *name, pa_usec_t interval,
     uint32_t volume_type, uint32_t gain_type, uint32_t volume_level, uint32_t *stream_idx)
 {
@@ -1969,6 +1971,7 @@ static audio_return_t policy_play_sample_continuously(struct userdata *u, pa_nat
     pa_memchunk silence;
     pa_cvolume r;
     pa_usec_t now = 0ULL;
+    const char *volume_str = NULL;
 
     if (!u->audio_sample_userdata.mutex)
         u->audio_sample_userdata.mutex = pa_mutex_new(false, false);
@@ -1994,11 +1997,10 @@ static audio_return_t policy_play_sample_continuously(struct userdata *u, pa_nat
 
     /* FIXME : Add gain_type parameter to API like volume_type */
     audio_info.stream.gain_type = gain_type;
-    /* it will be removed soon */
-    if (AUDIO_IS_ERROR((audio_ret = u->hal_manager->intf.get_volume_value(u->hal_manager->data, &audio_info, volume_type, STREAM_SINK_INPUT, volume_level, &volume_linear)))) {
-        pa_log_warn("get_volume_value returns error:0x%x", audio_ret);
+    __convert_volume_type_to_string(volume_type, &volume_str);
+    if (pa_hal_manager_get_volume_value(u->hal_manager, &audio_info, volume_str, STREAM_SINK_INPUT, volume_level, &volume_linear))
         goto exit;
-    }
+    pa_log_debug("play_sample_continuously volume_type:%d volume_str:%s", volume_type, volume_str);
 
    /*
     1. load cam-shutter sample
@@ -2105,6 +2107,7 @@ static void  policy_stop_sample_continuously(struct userdata *u)
 }
 
 #endif
+/* It will be moved to module-sound-player */
 static audio_return_t policy_play_sample(struct userdata *u, pa_native_connection *c, const char *name, uint32_t volume_type, uint32_t gain_type, uint32_t volume_level, uint32_t *stream_idx)
 {
     audio_return_t audio_ret = AUDIO_RET_OK;
@@ -2118,6 +2121,7 @@ static audio_return_t policy_play_sample(struct userdata *u, pa_native_connectio
     char* booting = NULL;
     const char* file_to_add = NULL;
     int sample_ret = 0;
+    const char *volume_str = NULL;
 
     memset(&audio_info, 0x00, sizeof(audio_info_t));
 
@@ -2138,11 +2142,9 @@ static audio_return_t policy_play_sample(struct userdata *u, pa_native_connectio
 
     /* FIXME : Add gain_type parameter to API like volume_type */
     audio_info.stream.gain_type = gain_type;
-    /* it will be removed soon */
-    if (AUDIO_IS_ERROR((audio_ret = u->hal_manager->intf.get_volume_value(u->hal_manager->data, &audio_info, volume_type, STREAM_SINK_INPUT, volume_level, &volume_linear)))) {
-        pa_log_warn("get_volume_value returns error:0x%x", audio_ret);
+    __convert_volume_type_to_string(volume_type, &volume_str);
+    if (pa_hal_manager_get_volume_value(u->hal_manager, &audio_info, volume_str, STREAM_SINK_INPUT, volume_level, &volume_linear))
         goto exit;
-    }
 
     pa_log_debug("play_sample volume_type:%d gain_type:%d volume_linear:%f", volume_type, gain_type, volume_linear);
 
@@ -2179,6 +2181,7 @@ exit:
     return audio_ret;
 }
 
+/* It will be removed soon */
 static audio_return_t policy_reset(struct userdata *u)
 {
     audio_return_t audio_ret = AUDIO_RET_OK;
@@ -2357,7 +2360,7 @@ static audio_return_t policy_set_active_device(struct userdata *u, uint32_t devi
     }
     /* it will be removed soon */
     if (u->hal_manager->intf.set_route) {
-        audio_return_t audio_ret = AUDIO_RET_OK;
+        int32_t audio_ret = 0;
         const char *device_switching_str;
         uint32_t device_switching = 0;
 #ifdef PA_SLEEP_DURING_UCM
@@ -2369,7 +2372,8 @@ static audio_return_t policy_set_active_device(struct userdata *u, uint32_t devi
             if ((device_switching_str = pa_proplist_gets(si->proplist, "module-policy.device_switching"))) {
                 pa_atou(device_switching_str, &device_switching);
                 if (device_switching) {
-                    if (AUDIO_IS_ERROR((audio_ret = pa_stream_manager_volume_set_mute_by_idx(u->stream_manager, STREAM_SINK_INPUT, si->index, 1)))) {
+                    audio_ret = pa_stream_manager_volume_set_mute_by_idx(u->stream_manager, STREAM_SINK_INPUT, si->index, 1);
+                    if (audio_ret) {
                         pa_log_warn("pa_stream_manager_volume_set_mute_by_idx(1) for stream[%d] returns error:0x%x", si->index, audio_ret);
                     }
 #ifdef PA_SLEEP_DURING_UCM
@@ -2396,7 +2400,8 @@ static audio_return_t policy_set_active_device(struct userdata *u, uint32_t devi
 //                    if (AUDIO_IS_ERROR((audio_ret = __update_volume(u, si->index, (uint32_t)-1, (uint32_t)-1)))) {
 //                        pa_log_warn("__update_volume for stream[%d] returns error:0x%x", si->index, audio_ret);
 //                    }
-                    if (AUDIO_IS_ERROR((audio_ret = pa_stream_manager_volume_set_mute_by_idx(u->stream_manager, STREAM_SINK_INPUT, si->index, 0)))) {
+                    audio_ret = pa_stream_manager_volume_set_mute_by_idx(u->stream_manager, STREAM_SINK_INPUT, si->index, 0);
+                    if (audio_ret) {
                         pa_log_warn("pa_stream_manager_volume_set_mute_by_idx(0) for stream[%d] returns error:0x%x", si->index, audio_ret);
                     }
                 }
@@ -2436,38 +2441,6 @@ static audio_return_t policy_set_active_device(struct userdata *u, uint32_t devi
     return AUDIO_RET_OK;
 }
 
-#ifndef WILL_BE_DEPRECATED
-static audio_return_t policy_update_volume(struct userdata *u) {
-    uint32_t volume_type;
-    uint32_t volume_level = 0;
-    const char *volume_str = NULL;
-
-    pa_log_info("update_volume");
-    /* it will be removed soon */
-    for (volume_type = 0; volume_type < AUDIO_VOLUME_TYPE_MAX; volume_type++) {
-        if (u->hal_manager->intf.get_volume_level) {
-            __convert_volume_type_to_string(volume_type, volume_str);
-            u->hal_manager->intf.get_volume_level(u->hal_manager->data, volume_str, STREAM_SINK_INPUT, &volume_level);
-        }
-//        __update_volume(u, (uint32_t)-1, volume_type, volume_level);
-#ifdef WEARABLE_FIX // commit : update call mute status after changing audio pathupdate call mute status after changing audio path
-        /* workaround for updating call mute after setting call path */
-        if (u->session == AUDIO_SESSION_VOICECALL) {
-            uint32_t call_muted = 0;
-            if (u->hal_manager->intf.get_mute) {
-                u->hal_manager->intf.get_mute(u->hal_manager->data, "call", AUDIO_DIRECTION_IN, &call_muted);
-                if (u->call_muted != (int)call_muted && u->hal_manager->intf.set_mute) {
-                    u->hal_manager->intf.set_mute(u->hal_manager->data, "call", AUDIO_DIRECTION_IN, u->call_muted);
-                }
-            }
-        }
-#endif
-    }
-
-    return AUDIO_RET_OK;
-}
-#endif
-
 static pa_bool_t policy_is_available_high_latency(struct userdata *u)
 {
     pa_sink_input *si = NULL;
@@ -2520,373 +2493,100 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
         pa_tagstruct_putu32(reply, EXT_VERSION);
         break;
     }
+    /* it will be removed soon */
+    case SUBCOMMAND_GET_VOLUME_LEVEL_MAX: {
+        uint32_t volume_type = 0;
+        uint32_t volume_level = 0;
+        const char *volume_str = NULL;
 
-    case SUBCOMMAND_MONO: {
-
-        bool enable;
-
-        if (pa_tagstruct_get_boolean(t, &enable) < 0)
-            goto fail;
-
-        pa_log_debug ("[POLICY][%s] new mono value = %d\n", __func__, enable);
-        if (enable == u->is_mono) {
-            pa_log_debug ("[POLICY][%s] No changes in mono value = %d", __func__, u->is_mono);
-            break;
-        }
-
-        u->is_mono = enable;
-
-        /* Move current sink-input to proper mono sink */
-        PA_IDXSET_FOREACH(si, u->core->sink_inputs, idx) {
-            const char *policy = NULL;
-
-            /* Skip this if it is already in the process of being moved
-             * anyway */
-            if (!si->sink)
-                continue;
-
-            /* It might happen that a stream and a sink are set up at the
-               same time, in which case we want to make sure we don't
-               interfere with that */
-            if (!PA_SINK_INPUT_IS_LINKED(pa_sink_input_get_state(si)))
-                continue;
-
-            /* Get role (if role is filter, skip it) */
-            if (policy_is_filter(si))
-                continue;
+        pa_tagstruct_getu32(t, &volume_type);
 
-            /* Check policy, if no policy exists, treat as AUTO */
-            if (!(policy = pa_proplist_gets(si->proplist, PA_PROP_MEDIA_POLICY))) {
-                pa_log_debug("[POLICY] set policy of sink-input[%d] from [%s] to [auto]", si->index, "null");
-                policy  = POLICY_AUTO;
-            }
-            pa_log_debug("[POLICY] Policy of sink input [%d] = %s", si->index, policy);
+        __convert_volume_type_to_string(volume_type, &volume_str);
+        pa_stream_manager_volume_get_level_max(u->stream_manager, STREAM_SINK_INPUT, volume_str, &volume_level);
 
-            /* Select sink to move and move to it */
-            sink_to_move = policy_select_proper_sink (u, policy, si, u->is_mono);
-            if (sink_to_move) {
-                pa_log_debug("[POLICY][%s] Moving sink-input[%d] from [%s] to [%s]", __func__, si->index, si->sink->name, sink_to_move->name);
-                pa_sink_input_move_to(si, sink_to_move, false);
-            } else {
-                pa_log_debug("[POLICY][%s] Can't move sink-input....", __func__);
-            }
-        }
+        pa_tagstruct_putu32(reply, volume_level);
         break;
     }
+    /* it will be removed soon */
+    case SUBCOMMAND_GET_VOLUME_LEVEL: {
+        uint32_t stream_idx = PA_INVALID_INDEX;
+        uint32_t volume_type = 0;
+        uint32_t volume_level = 0;
+        const char *volume_str = NULL;
 
-    case SUBCOMMAND_BALANCE: {
-        float balance;
-        pa_cvolume cvol;
-        pa_channel_map map;
-
-        if (pa_tagstruct_get_cvolume(t, &cvol) < 0)
-            goto fail;
-
-        pa_channel_map_init_stereo(&map);
-        balance = pa_cvolume_get_balance(&cvol, &map);
-
-        pa_log_debug ("[POLICY][%s] new balance value = [%f]\n", __func__, balance);
-
-        if (balance == u->balance) {
-            pa_log_debug ("[POLICY][%s] No changes in balance value = [%f]", __func__, u->balance);
-            break;
-        }
+        pa_tagstruct_getu32(t, &stream_idx);
+        pa_tagstruct_getu32(t, &volume_type);
 
-        u->balance = balance;
+        __convert_volume_type_to_string(volume_type, &volume_str);
+        pa_stream_manager_volume_get_level(u->stream_manager, STREAM_SINK_INPUT, volume_str, &volume_level);
 
-        /* Apply balance value to each Sinks */
-        PA_IDXSET_FOREACH(s, u->core->sinks, idx) {
-            pa_cvolume* cvol = pa_sink_get_volume (s, false);
-            pa_cvolume_set_balance (cvol, &s->channel_map, u->balance);
-            pa_sink_set_volume(s, cvol, true, true);
-        }
+        pa_tagstruct_putu32(reply, volume_level);
         break;
     }
+    /* it will be removed soon */
+    case SUBCOMMAND_SET_VOLUME_LEVEL: {
+        uint32_t stream_idx = PA_INVALID_INDEX;
+        uint32_t volume_type = 0;
+        uint32_t volume_level = 0;
+        const char *volume_str = NULL;
+
+        pa_tagstruct_getu32(t, &stream_idx);
+        pa_tagstruct_getu32(t, &volume_type);
+        pa_tagstruct_getu32(t, &volume_level);
+
+        __convert_volume_type_to_string(volume_type, &volume_str);
+        pa_stream_manager_volume_set_level(u->stream_manager, STREAM_SINK_INPUT, volume_str, volume_level);
+        break;
+    }
+    /* it will be removed soon */
+    case SUBCOMMAND_GET_MUTE: {
+        uint32_t stream_idx = PA_INVALID_INDEX;
+        uint32_t volume_type = 0;
+        uint32_t direction = 0;
+        uint32_t mute = 0;
+        const char *volume_str = NULL;
 
-   case SUBCOMMAND_PLAY_SAMPLE: {
-            const char *name;
-            uint32_t volume_type = 0;
-            uint32_t gain_type = 0;
-            uint32_t volume_level = 0;
-            uint32_t stream_idx = PA_INVALID_INDEX;
-
-            if (pa_tagstruct_gets(t, &name) < 0 ||
-                pa_tagstruct_getu32(t, &volume_type) < 0 ||
-                pa_tagstruct_getu32(t, &gain_type) < 0 ||
-                pa_tagstruct_getu32(t, &volume_level) < 0 ||
-                !pa_tagstruct_eof(t)) {
-                pa_log_error("protocol error");
-                goto fail;
-            }
-
-            policy_play_sample(u, c, name, volume_type, gain_type, volume_level, &stream_idx);
-
-            pa_tagstruct_putu32(reply, stream_idx);
-            break;
-        }
-#ifdef BURST_SHOT
-
-        case SUBCOMMAND_PLAY_SAMPLE_CONTINUOUSLY: {
-            const char *name;
-            pa_bool_t start;
-            uint32_t volume_type = 0;
-            uint32_t gain_type = 0;
-            uint32_t volume_level = 0;
-            uint32_t stream_idx = PA_INVALID_INDEX;
-            pa_usec_t interval;
-
-            if (pa_tagstruct_gets(t, &name) < 0 ||
-                pa_tagstruct_get_boolean(t, &start) < 0 ||
-                pa_tagstruct_getu32(t, &volume_type) < 0 ||
-                pa_tagstruct_getu32(t, &gain_type) < 0 ||
-                pa_tagstruct_getu32(t, &volume_level) < 0 ||
-                pa_tagstruct_get_usec(t, &interval) < 0 ||
-                !pa_tagstruct_eof(t)) {
-                pa_log_error("protocol error");
-                goto fail;
-            }
-            /*When play sample continuous is in running state another instance is not allowed*/
-            if (start == true) {
-                if (u->audio_sample_userdata.is_running == false) {
-                    /* Now it is time to prepare burstshot...set burstshot vconf */
-                    vconf_set_int (VCONF_SOUND_BURSTSHOT, 1);
-
-                    pa_log_warn("play_sample_continuously start. name(%s), vol_type(%d), gain_type(%d), vol_level(%d), interval(%lu ms)",
-                        name, volume_type, gain_type, volume_level, (unsigned long) (interval / PA_USEC_PER_MSEC));
-                    policy_play_sample_continuously(u, c, name, interval, volume_type, gain_type, volume_level, &stream_idx);
-
-                    /* Running false after start means, start failed....unset burstshot vconf */
-                    if (u->audio_sample_userdata.is_running == false) {
-                        vconf_set_int (VCONF_SOUND_BURSTSHOT, 0);
-                    }
-                } else {
-                    pa_log_warn("play_sample_continuously is in running state - do nothing");
-                }
-            } else if ((start == false) && (u->audio_sample_userdata.is_running == true)) {
-                pa_log_warn("play_sample_continuously end.");
-                policy_stop_sample_continuously(u);
-            } else {
-                pa_log_error("play sample continuously unknown command. name(%s), start(%d)", name, start);
-            }
-
-            pa_tagstruct_putu32(reply, stream_idx);
-            break;
-        }
-
-#endif
-        case SUBCOMMAND_MUTEALL: {
-            const char *si_gain_type_str;
-            pa_bool_t enable;
-            unsigned i;
-            uint32_t gain_type;
-#if 0
-            pa_cvolume cvol ;
-            pa_cvolume* scvol ;
-#endif
-
-            if (pa_tagstruct_get_boolean(t, &enable) < 0)
-                goto fail;
-
-            pa_log_debug ("new muteall value = %d\n", enable);
-            if (enable == u->muteall) {
-                pa_log_debug ("No changes in muteall value = %d", u->muteall);
-                break;
-            }
-
-            u->muteall = enable;
-
-/* Use mute instead of volume for muteall */
-#if 1 /* volume feature will be moved to stream-manager */
-#ifdef TIZEM_MICRO
-            /* Special case. Set mute for call volume type in B3. */
-            //policy_set_mute(u, (-1), AUDIO_VOLUME_TYPE_CALL, AUDIO_DIRECTION_OUT, u->muteall);
-#else
-            for (i = 0; i < AUDIO_VOLUME_TYPE_MAX; i++) {
-                //policy_set_mute(u, (-1), i, AUDIO_DIRECTION_OUT, u->muteall);
-            }
-#endif
-            PA_IDXSET_FOREACH(si, u->core->sink_inputs, idx) {
-                /* Skip booting sound for power off mute streams policy. */
-                if (u->muteall && (si_gain_type_str = pa_proplist_gets(si->proplist, PA_PROP_MEDIA_TIZEN_GAIN_TYPE))) {
-                    pa_atou(si_gain_type_str, &gain_type);
-                    if (gain_type == AUDIO_GAIN_TYPE_BOOTING)
-                        continue;
-                }
-                pa_sink_input_set_mute(si, u->muteall, true);
-            }
-#else
-            /* Apply new volume  value to each Sink_input */
-            if (u->muteall) {
-                PA_IDXSET_FOREACH(si, u->core->sink_inputs, idx) {
-                    scvol = pa_sink_input_get_volume (si, &cvol,true);
-                    for (i = 0; i < scvol->channels; i++) {
-                        scvol->values[i] = 0;
-                    }
-                    pa_sink_input_set_volume(si,scvol,true,true);
-                }
-            } else {
-                PA_IDXSET_FOREACH(si, u->core->sink_inputs, idx) {
-                    if (pa_streq(si->module->name,"module-remap-sink")) {
-                        scvol = pa_sink_input_get_volume (si, &cvol,true);
-                        for (i = 0; i < scvol->channels; i++) {
-                            scvol->values[i] = MAX_VOLUME_FOR_MONO;
-                        }
-                        pa_sink_input_set_volume(si,scvol,true,true);
-                    }
-                }
-            }
-#endif
-            break;
-        }
-#ifndef WILL_BE_DEPRECATED
-        case SUBCOMMAND_SET_USE_CASE: {
-            break;
-        }
-        /* it will be removed soon */
-        case SUBCOMMAND_SET_SESSION: {
-            uint32_t session = 0;
-            uint32_t start = 0;
-
-            pa_tagstruct_getu32(t, &session);
-            pa_tagstruct_getu32(t, &start);
-
-            policy_set_session(u, session, start);
-            break;
-        }
-        /* it will be removed soon */
-        case SUBCOMMAND_SET_SUBSESSION: {
-            uint32_t subsession = 0;
-            uint32_t subsession_opt = 0;
-
-            pa_tagstruct_getu32(t, &subsession);
-            pa_tagstruct_getu32(t, &subsession_opt);
-
-            policy_set_subsession(u, subsession, subsession_opt);
-            break;
-        }
-        /* it will be removed soon */
-        case SUBCOMMAND_SET_ACTIVE_DEVICE: {
-            uint32_t device_in = 0;
-            uint32_t device_out = 0;
-            uint32_t need_update = false;
-
-            pa_tagstruct_getu32(t, &device_in);
-            pa_tagstruct_getu32(t, &device_out);
-
-            policy_set_active_device(u, device_in, device_out, &need_update);
-            pa_tagstruct_putu32(reply, need_update);
-            break;
-        }
-        /* it will be removed soon */
-        case SUBCOMMAND_RESET: {
-
-            policy_reset(u);
-
-            break;
-        }
-#endif
-        /* it will be removed soon */
-        case SUBCOMMAND_GET_VOLUME_LEVEL_MAX: {
-            uint32_t volume_type = 0;
-            uint32_t volume_level = 0;
-            const char *volume_str = NULL;
-
-            pa_tagstruct_getu32(t, &volume_type);
-
-            __convert_volume_type_to_string(volume_type, &volume_str);
-            pa_stream_manager_volume_get_level_max(u->stream_manager, STREAM_SINK_INPUT, volume_str, &volume_level);
-
-            pa_tagstruct_putu32(reply, volume_level);
-            break;
-        }
-        /* it will be removed soon */
-        case SUBCOMMAND_GET_VOLUME_LEVEL: {
-            uint32_t stream_idx = PA_INVALID_INDEX;
-            uint32_t volume_type = 0;
-            uint32_t volume_level = 0;
-            const char *volume_str = NULL;
-
-            pa_tagstruct_getu32(t, &stream_idx);
-            pa_tagstruct_getu32(t, &volume_type);
-
-            __convert_volume_type_to_string(volume_type, &volume_str);
-            pa_stream_manager_volume_get_current_level(u->stream_manager, STREAM_SINK_INPUT, volume_str, &volume_level);
+        pa_tagstruct_getu32(t, &stream_idx);
+        pa_tagstruct_getu32(t, &volume_type);
+        pa_tagstruct_getu32(t, &direction);
 
-            pa_tagstruct_putu32(reply, volume_level);
-            break;
-        }
-        /* it will be removed soon */
-        case SUBCOMMAND_SET_VOLUME_LEVEL: {
-            uint32_t stream_idx = PA_INVALID_INDEX;
-            uint32_t volume_type = 0;
-            uint32_t volume_level = 0;
-            const char *volume_str = NULL;
-
-            pa_tagstruct_getu32(t, &stream_idx);
-            pa_tagstruct_getu32(t, &volume_type);
-            pa_tagstruct_getu32(t, &volume_level);
-
-            __convert_volume_type_to_string(volume_type, &volume_str);
-            pa_stream_manager_volume_set_level(u->stream_manager, STREAM_SINK_INPUT, volume_str, volume_level);
-            break;
-        }
+        __convert_volume_type_to_string(volume_type, &volume_str);
+        pa_stream_manager_volume_get_mute(u, STREAM_SINK_INPUT, volume_str, &mute);
 
-#ifndef WILL_BE_DEPRECATED
-        /* need to check if it is sure to be removed, it is  */
-        case SUBCOMMAND_UPDATE_VOLUME: {
-            policy_update_volume(u);
-            break;
-        }
-#endif
-        /* it will be removed soon */
-        case SUBCOMMAND_GET_MUTE: {
-            uint32_t stream_idx = PA_INVALID_INDEX;
-            uint32_t volume_type = 0;
-            uint32_t direction = 0;
-            uint32_t mute = 0;
-            const char *volume_str = NULL;
-
-            pa_tagstruct_getu32(t, &stream_idx);
-            pa_tagstruct_getu32(t, &volume_type);
-            pa_tagstruct_getu32(t, &direction);
-
-            __convert_volume_type_to_string(volume_type, &volume_str);
-            pa_stream_manager_volume_get_mute(u, STREAM_SINK_INPUT, volume_str, &mute);
-
-            pa_tagstruct_putu32(reply, mute);
-            break;
-        }
-        /* it will be removed soon */
-        case SUBCOMMAND_SET_MUTE: {
-            uint32_t stream_idx = PA_INVALID_INDEX;
-            uint32_t volume_type = 0;
-            uint32_t direction = 0;
-            uint32_t mute = 0;
-            const char *volume_str = NULL;
-
-            pa_tagstruct_getu32(t, &stream_idx);
-            pa_tagstruct_getu32(t, &volume_type);
-            pa_tagstruct_getu32(t, &direction);
-            pa_tagstruct_getu32(t, &mute);
-
-            __convert_volume_type_to_string(volume_type, &volume_str);
-            pa_stream_manager_volume_set_mute(u, STREAM_SINK_INPUT, volume_str, mute);
-            break;
-        }
-        case SUBCOMMAND_IS_AVAILABLE_HIGH_LATENCY: {
-            pa_bool_t available = false;
+        pa_tagstruct_putu32(reply, mute);
+        break;
+    }
+    /* it will be removed soon */
+    case SUBCOMMAND_SET_MUTE: {
+        uint32_t stream_idx = PA_INVALID_INDEX;
+        uint32_t volume_type = 0;
+        uint32_t direction = 0;
+        uint32_t mute = 0;
+        const char *volume_str = NULL;
+
+        pa_tagstruct_getu32(t, &stream_idx);
+        pa_tagstruct_getu32(t, &volume_type);
+        pa_tagstruct_getu32(t, &direction);
+        pa_tagstruct_getu32(t, &mute);
+
+        __convert_volume_type_to_string(volume_type, &volume_str);
+        pa_stream_manager_volume_set_mute(u, STREAM_SINK_INPUT, volume_str, mute);
+        break;
+    }
+    case SUBCOMMAND_IS_AVAILABLE_HIGH_LATENCY: {
+        pa_bool_t available = false;
 
-            available = policy_is_available_high_latency(u);
+        available = policy_is_available_high_latency(u);
 
-            pa_tagstruct_putu32(reply, (uint32_t)available);
-            break;
-        }
-        case SUBCOMMAND_UNLOAD_HDMI: {
-            break;
-        }
+        pa_tagstruct_putu32(reply, (uint32_t)available);
+        break;
+    }
+    case SUBCOMMAND_UNLOAD_HDMI: {
+        break;
+    }
 
-        default:
-            goto fail;
+    default:
+        goto fail;
   }
 
   pa_pstream_send_tagstruct(pa_native_connection_get_pstream(c), reply);
@@ -2899,6 +2599,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
 
   return -1;
 }
+
 static void __set_sink_input_role_type(pa_proplist *p, int gain_type)
 {
     const char* role = NULL;
@@ -2991,10 +2692,7 @@ static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_n
 
         // set role type
         __set_sink_input_role_type(new_data->proplist, audio_info.stream.gain_type);
-        /* it will be removed soon */
-        if (u->hal_manager->intf.get_volume_level) {
-            u->hal_manager->intf.get_volume_level(u->hal_manager->data, audio_info.stream.volume_type, STREAM_SINK_INPUT, &volume_level);
-        }
+        pa_hal_manager_get_volume_level(u->hal_manager, audio_info.stream.volume_type, STREAM_SINK_INPUT, &volume_level);
 
         pa_strbuf_printf(s, "[%s] policy[%s] ch[%d] rate[%d] volume&gain[%d,%d] level[%d]",
                 audio_info.stream.name, policy, audio_info.stream.channels, audio_info.stream.samplerate,
@@ -3407,7 +3105,8 @@ static pa_hook_result_t sink_unlink_post_hook_callback(pa_core *c, pa_sink *sink
 }
 
 static pa_hook_result_t sink_input_move_start_cb(pa_core *core, pa_sink_input *i, struct userdata *u) {
-    audio_return_t audio_ret = AUDIO_RET_OK;
+    int32_t audio_ret = 0;
+
     pa_core_assert_ref(core);
     pa_sink_input_assert_ref(i);
 
@@ -3418,7 +3117,8 @@ static pa_hook_result_t sink_input_move_start_cb(pa_core *core, pa_sink_input *i
     pa_log_debug ("------- sink-input [%d] was sink [%s][%d] : Trying to mute!!!",
             i->index, i->sink->name, i->sink->index);
 
-    if (AUDIO_IS_ERROR((audio_ret = pa_stream_manager_volume_set_mute_by_idx(u->stream_manager, STREAM_SINK_INPUT, i->index, 1)))) {
+    audio_ret = pa_stream_manager_volume_set_mute_by_idx(u->stream_manager, STREAM_SINK_INPUT, i->index, 1);
+    if (audio_ret) {
         pa_log_warn("policy_set_mute(1) for stream[%d] returns error:0x%x", i->index, audio_ret);
     }
 
@@ -3426,7 +3126,8 @@ static pa_hook_result_t sink_input_move_start_cb(pa_core *core, pa_sink_input *i
 }
 
 static pa_hook_result_t sink_input_move_finish_cb(pa_core *core, pa_sink_input *i, struct userdata *u) {
-    audio_return_t audio_ret = AUDIO_RET_OK;
+    int32_t audio_ret = 0;
+
     pa_core_assert_ref(core);
     pa_sink_input_assert_ref(i);
 
@@ -3444,7 +3145,8 @@ static pa_hook_result_t sink_input_move_finish_cb(pa_core *core, pa_sink_input *
 //        if (AUDIO_IS_ERROR((audio_ret = __update_volume(u, i->index, (uint32_t)-1, (uint32_t)-1)))) {
 //            pa_log_debug("__update_volume for stream[%d] returns error:0x%x", i->index, audio_ret);
 //        }
-        if (AUDIO_IS_ERROR((audio_ret = pa_stream_manager_volume_set_mute_by_idx(u->stream_manager, STREAM_SINK_INPUT, i->index, 0)))) {
+        audio_ret = pa_stream_manager_volume_set_mute_by_idx(u->stream_manager, STREAM_SINK_INPUT, i->index, 0);
+        if (audio_ret) {
             pa_log_debug("policy_set_mute(0) for stream[%d] returns error:0x%x", i->index, audio_ret);
         }
     }
@@ -3625,6 +3327,14 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou
     return PA_HOOK_OK;
 }
 
+/* Set the proper sink(source) according to the data from argument.     */
+/* 1. Get all the activate devices from device manager.                 */
+/* 2. Find and set the matched device.                                  */
+/*   - ROUTE_TYPE_AUTO(_ALL)                                            */
+/*     : Just set an activate device to the proper_sink(source).        */
+/*   - ROUTE_TYPE_MANUAL                                                */
+/*     : If found the matched sink(source), then set it.                */
+/*     : If not, set it to null sink(source).                           */
 static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stream_manager_hook_data_for_select *data, struct userdata *u) {
     pa_log("select_proper_sink_or_source_hook_cb is called. (%p), stream_type(%d), stream_role(%s), route_type(%d)",
             data, data->stream_type, data->stream_role, data->route_type);
@@ -3633,20 +3343,32 @@ static pa_hook_result_t select_proper_sink_or_source_hook_cb(pa_core *c, pa_stre
     const char *device_type = NULL;
     /* devices */
     if ((data->route_type == STREAM_ROUTE_TYPE_AUTO || data->route_type == STREAM_ROUTE_TYPE_AUTO_ALL) && data->avail_devices) {
-        /* In case of AUTO routing, use idxset for avail device */
+        /* In case of AUTO routing, use idxset for avail devices */
         PA_IDXSET_FOREACH(device_type, data->avail_devices, idx) {
             pa_log("-- device[%u] : type(%s)", idx, device_type);
+            /* query by device type */
         }
     } else if (data->route_type == STREAM_ROUTE_TYPE_MANUAL && data->manual_devices) {
         /* In case of MANUAL routing, use hashmap for manual_devices */
         device *device = NULL;
         PA_HASHMAP_FOREACH(device, data->manual_devices, state) {
             pa_log("-- device: type(%s), id(%i)", device->type, device->id);
+            /* query by device id */
         }
     }
     return PA_HOOK_OK;
 }
 
+/* Change the route setting according to the data from argument.               */
+/* 1. Get all the connected devices from device manager.                       */
+/* 2. Apply the proper route setting.(Call HAL API to apply routing)           */
+/*   - ROUTE_TYPE_AUTO                                                         */
+/*     : Need to check the priority of the device list by order of precedence. */
+/*   - ROUTE_TYPE_AUTO_ALL                                                     */
+/*     : Set all the connected devices that are in the device list.            */
+/*   - ROUTE_TYPE_MANUAL                                                       */
+/*     : Set all the connected devices that are in the device list.            */
+/*     : If a device in the device list is not connected, return error.        */
 static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_data_for_route *data, struct userdata *u) {
     pa_log("route_change_hook_cb is called. (%p), stream_type(%d), stream_role(%s), route_type(%d)",
             data, data->stream_type, data->stream_role, data->route_type);
@@ -3663,10 +3385,11 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_
     }
     /* devices */
     if ((data->route_type == STREAM_ROUTE_TYPE_AUTO || data->route_type == STREAM_ROUTE_TYPE_AUTO_ALL) && data->avail_devices) {
-        /* In case of AUTO routing, use idxset for avail device */
+        /* In case of AUTO routing, use idxset for avail devices */
         state = NULL;
         PA_IDXSET_FOREACH(device_type, data->avail_devices, idx) {
             pa_log("-- device[%u]: type(%s)", idx, device_type);
+            /* query by device type */
         }
     } else if (data->route_type == STREAM_ROUTE_TYPE_MANUAL && data->manual_devices) {
         /* In case of MANUAL routing, use hashmap for manual_devices */
@@ -3674,23 +3397,10 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_
         device *device = NULL;
         PA_HASHMAP_FOREACH(device, data->manual_devices, state) {
             pa_log("-- device: type(%s), id(%i)", device->type, device->id);
+            /* query by device id */
         }
     }
 
-#if 0
-    typedef struct device_info {
-        int32_t type;
-        int32_t direction;
-        int32_t id;
-    } device_info_t;
-
-    /* to hal manager */
-    typedef struct audio_route_info {
-        char *role;
-        device_info_t *device_infos;
-        int32_t num_of_devices;
-    } audio_route_info_t;
-#endif
     audio_route_info_t route_info;
     route_info.role = data->stream_role;
     if (u->hal_manager->intf.do_route) {
@@ -3702,6 +3412,7 @@ static pa_hook_result_t route_change_hook_cb(pa_core *c, pa_stream_manager_hook_
     return PA_HOOK_OK;
 }
 
+/* Forward routing options to HAL */
 static pa_hook_result_t route_options_update_hook_cb(pa_core *c, pa_stream_manager_hook_data_for_options *data, struct userdata *u) {
     pa_log("route_options_update_hook_cb is called. (%p), stream_role(%s), route_options(%p), num_of_options(%d)",
             data, data->stream_role, data->route_options, pa_idxset_size(data->route_options));
@@ -3709,22 +3420,38 @@ static pa_hook_result_t route_options_update_hook_cb(pa_core *c, pa_stream_manag
     const char *option_name = NULL;
     int i = 0;
 
+    hal_route_option_t route_option;
+    char **options = NULL;
+    route_option.role = data->stream_role;
+    route_option.num_of_options = pa_idxset_size(data->route_options);
+    if (route_option.num_of_options)
+        route_option.options = pa_xmalloc(sizeof(char*)*route_option.num_of_options);
+
     while (data->route_options && (option_name = pa_idxset_iterate(data->route_options, &state, NULL))) {
         pa_log("-- option : %s", option_name);
+        route_option.options[i++] = option_name;
     }
 
+    if(pa_hal_manager_update_route_option (u->hal_manager, &route_option))
+        pa_log_error("Failed to pa_hal_manager_update_route_option()");
+    pa_xfree(route_option.options);
+
     return PA_HOOK_OK;
 }
 
-static pa_hook_result_t device_connected_hook_cb(pa_core *c, struct device_item *device, struct userdata *u) {
-    pa_log_debug("Device connected hook");
+#ifdef DEVICE_MANAGER
+/* Reorganize routing when a device has been connected or disconnected */
+static pa_hook_result_t device_connection_changed_hook_cb(pa_core *c, pa_device_manager_hook_data_for_conn_changed *conn, struct userdata *u) {
+    pa_log_debug("device_connection_changed_hook_cb is called. conn(%p), is_connected(%d), device(%p)", conn, conn->is_connected, conn->device);
     return PA_HOOK_OK;
 }
 
-static pa_hook_result_t device_disconnected_hook_cb(pa_core *c, struct device_item *device, struct userdata *u) {
-    pa_log_debug("Device disconnected hook");
+/* Reorganize routing when the information(STATE/IO/SUB_TYPE) of a device has been changed */
+static pa_hook_result_t device_information_changed_hook_cb(pa_core *c, pa_device_manager_hook_data_for_info_changed *info, struct userdata *u) {
+    pa_log_debug("device_information_changed_hook_cb is called. info(%p), changed_info(%d), device(%p)", info, info->changed_info, info->device);
     return PA_HOOK_OK;
 }
+#endif
 
 #ifdef HAVE_DBUS
 static void _do_something1(char* arg1, int arg2, void *data)
@@ -4349,15 +4076,17 @@ int pa__init(pa_module *m)
                     PA_HOOK_EARLY, (pa_hook_cb_t) route_change_hook_cb, u);
         u->communicator.comm_hook_update_route_options_slot = pa_hook_connect(pa_communicator_hook(u->communicator.comm,PA_COMMUNICATOR_HOOK_UPDATE_ROUTE_OPTIONS),
                     PA_HOOK_EARLY, (pa_hook_cb_t) route_options_update_hook_cb, u);
-        u->communicator.comm_hook_device_connected_slot = pa_hook_connect(pa_communicator_hook(u->communicator.comm,PA_COMMUNICATOR_HOOK_DEVICE_CONNECTED),
-                    PA_HOOK_EARLY, (pa_hook_cb_t) device_connected_hook_cb, u);
-        u->communicator.comm_hook_device_disconnected_slot = pa_hook_connect(pa_communicator_hook(u->communicator.comm,PA_COMMUNICATOR_HOOK_DEVICE_DISCONNECTED),
-                    PA_HOOK_EARLY, (pa_hook_cb_t) device_disconnected_hook_cb, u);
+#ifdef DEVICE_MANAGER
+        u->communicator.comm_hook_device_connection_changed_slot = pa_hook_connect(pa_communicator_hook(u->communicator.comm,PA_COMMUNICATOR_HOOK_DEVICE_CONNECTION_CHANGED),
+                    PA_HOOK_EARLY, (pa_hook_cb_t) device_connection_changed_hook_cb, u);
+        u->communicator.comm_hook_device_information_changed_slot = pa_hook_connect(pa_communicator_hook(u->communicator.comm,PA_COMMUNICATOR_HOOK_DEVICE_INFORMATION_CHANGED),
+                    PA_HOOK_EARLY, (pa_hook_cb_t) device_information_changed_hook_cb, u);
+#endif
     }
     u->stream_manager = pa_stream_manager_init(u->core);
 
 #ifdef DEVICE_MANAGER
-    u->device_manager = device_manager_init(u->core);
+    u->device_manager = pa_device_manager_init(u->core);
 #endif
 
     __load_dump_config(u);
@@ -4395,7 +4124,7 @@ void pa__done(pa_module *m)
 #endif
 #ifdef DEVICE_MANAGER
     if (u->device_manager)
-        device_manager_done(u->device_manager);
+        pa_device_manager_done(u->device_manager);
 #endif
 
     if (u->sink_input_new_hook_slot)
@@ -4429,9 +4158,12 @@ void pa__done(pa_module *m)
             pa_hook_slot_free(u->communicator.comm_hook_change_route_slot);
         if (u->communicator.comm_hook_change_route_slot)
             pa_hook_slot_free(u->communicator.comm_hook_update_route_options_slot);
-            pa_hook_slot_free(u->communicator.comm_hook_device_connected_slot);
-        if (u->communicator.comm_hook_device_disconnected_slot)
-            pa_hook_slot_free(u->communicator.comm_hook_device_disconnected_slot);
+#ifdef DEVICE_MANAGER
+        if (u->communicator.comm_hook_device_connection_changed_slot)
+            pa_hook_slot_free(u->communicator.comm_hook_device_connection_changed_slot);
+        if (u->communicator.comm_hook_device_information_changed_slot)
+            pa_hook_slot_free(u->communicator.comm_hook_device_information_changed_slot);
+#endif
         pa_communicator_unref(u->communicator.comm);
     }
 
index b85334f..4dfd764 100644 (file)
@@ -3,6 +3,12 @@
 
 #include "stream-manager.h"
 
+#include <vconf.h>
+#include <vconf-keys.h>
+
+#define VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE "memory/private/sound/PrimaryVolumetype"
+#define VCONFKEY_OUT_VOLUME_PREFIX         "file/private/sound/volume/"
+
 int init_volume_map (pa_stream_manager *m);
 void deinit_volume_map (pa_stream_manager *m);
 int set_volume_level_by_idx(pa_stream_manager *m, stream_type stream_type, uint32_t idx, uint32_t volume_level);
index dd5216e..0aa7c05 100644 (file)
@@ -154,21 +154,13 @@ static int is_hal_volume_by_type(pa_stream_manager *m, const char *volume_type,
     pa_assert(m);
     pa_assert(is_hal_volume);
 
-    if (stream_type == STREAM_SINK_INPUT) {
-        if (m->volume_map.out_volumes) {
-            v = pa_hashmap_get(m->volume_map.out_volumes, volume_type);
-            if (v)
-                *is_hal_volume = v->is_hal_volume_type;
-        } else
-            return -1;
-    } else if (stream_type == STREAM_SOURCE_OUTPUT) {
-        if (m->volume_map.in_volumes) {
-            v = pa_hashmap_get(m->volume_map.in_volumes, volume_type);
-            if (v)
-                *is_hal_volume = v->is_hal_volume_type;
-        } else
-            return -1;
-    }
+    if ((stream_type==STREAM_SINK_INPUT)?m->volume_map.out_volumes:m->volume_map.in_volumes) {
+        v = pa_hashmap_get((stream_type==STREAM_SINK_INPUT)?m->volume_map.out_volumes:m->volume_map.in_volumes, volume_type);
+        if (v)
+            *is_hal_volume = v->is_hal_volume_type;
+    } else
+        return -1;
+
     return 0;
 }
 
@@ -264,7 +256,6 @@ exit:
 #endif
 
 static int get_volume_value(pa_stream_manager *m, stream_type stream_type, pa_bool_t is_hal_volume, const char *volume_type, uint32_t volume_level, double *volume_value) {
-    audio_return_t audio_ret = AUDIO_RET_OK;
     int ret = 0;
     double volume_linear = 1.0f;
 
@@ -273,10 +264,11 @@ static int get_volume_value(pa_stream_manager *m, stream_type stream_type, pa_bo
     pa_assert(volume_value);
 
     /* Get volume value by type & level */
-    if (is_hal_volume && m->hal->intf.get_volume_value) {
+    if (is_hal_volume) {
         /* Get value from HAL */
-        if (AUDIO_IS_ERROR((audio_ret = m->hal->intf.get_volume_value(m->hal->data, NULL, volume_type, stream_type, volume_level, &volume_linear)))) {
-            pa_log_warn("get_volume_value() returns error:0x%x", audio_ret);
+        if (pa_hal_manager_get_volume_value(m->hal, NULL, volume_type, (stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN, volume_level, &volume_linear)) {
+            ret = -1;
+            goto FAILURE;
         }
     } else {
         volume_info *v = NULL;
@@ -289,11 +281,13 @@ static int get_volume_value(pa_stream_manager *m, stream_type stream_type, pa_bo
                 volume_linear = *value;
             else {
                 pa_log_error("failed to pa_idxset_get_by_index()");
-                return -1;
+                ret = -1;
+                goto FAILURE;
             }
         } else {
             pa_log_error("could not get volume value for type[%s],level[%u]", volume_type, volume_level);
-            return -1;
+            ret = -1;
+            goto FAILURE;
         }
     }
 
@@ -301,13 +295,11 @@ static int get_volume_value(pa_stream_manager *m, stream_type stream_type, pa_bo
 
     pa_log_debug("get_volume_value() : stream_type[%d], volume_type[%s], level[%u], value[%f]",
             stream_type, volume_type, volume_level, volume_linear);
-
-    return 0;
+FAILURE:
+    return ret;
 }
 
-static audio_return_t set_volume_level_by_type(pa_stream_manager *m, stream_type stream_type, const char *volume_type, uint32_t volume_level) {
-    audio_return_t audio_ret = AUDIO_RET_OK;
-    int ret = 0;
+static int32_t set_volume_level_by_type(pa_stream_manager *m, stream_type stream_type, const char *volume_type, uint32_t volume_level) {
     pa_bool_t is_hal_volume = FALSE;
     volume_info *v = NULL;
     double volume_linear = 1.0f;
@@ -318,23 +310,21 @@ static audio_return_t set_volume_level_by_type(pa_stream_manager *m, stream_type
     pa_assert(volume_type);
 
     /* Check if it is related to HAL volume */
-    ret = is_hal_volume_by_type(m, volume_type, stream_type, &is_hal_volume);
-    if (ret) {
-        pa_log_error("failed to is_hal_volume_by_type(), stream_type(%d), volume_type(%s), ret(0x%x)", stream_type, volume_type, ret);
-        /* need to fix it */
-        return AUDIO_ERR_UNDEFINED;
+    if (is_hal_volume_by_type(m, volume_type, stream_type, &is_hal_volume)) {
+        pa_log_error("failed to is_hal_volume_by_type(), stream_type(%d), volume_type(%s)", stream_type, volume_type);
+        return -1;
      }
 
-    if (is_hal_volume && m->hal->intf.set_volume_level)
-        if (AUDIO_IS_ERROR((audio_ret = m->hal->intf.set_volume_level(m->hal->data, volume_type, stream_type, volume_level))))
-            pa_log_error("HAL set_volume_level returns error:0x%x", audio_ret);
+    if (is_hal_volume)
+        if (pa_hal_manager_set_volume_level(m->hal, volume_type, (stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN, volume_level))
+            return -1;
 
-    ret = get_volume_value(m, stream_type, is_hal_volume, volume_type, volume_level, &volume_linear);
-    if (!ret) {
-        v = pa_hashmap_get((stream_type==STREAM_SINK_INPUT)?m->volume_map.out_volumes:m->volume_map.in_volumes, volume_type);
-        if (v && (v->current_level != volume_level))
-            v->current_level = volume_level;
-    }
+    if (get_volume_value(m, stream_type, is_hal_volume, volume_type, volume_level, &volume_linear))
+        return -1;;
+
+    v = pa_hashmap_get((stream_type==STREAM_SINK_INPUT)?m->volume_map.out_volumes:m->volume_map.in_volumes, volume_type);
+    if (v && (v->current_level != volume_level))
+        v->current_level = volume_level;
 
     PA_IDXSET_FOREACH(s, stream_type==STREAM_SINK_INPUT?m->core->sink_inputs:m->core->source_outputs, idx) {
         if ((volume_type_str = pa_proplist_gets(stream_type==STREAM_SINK_INPUT?((pa_sink_input*)s)->proplist:((pa_source_output*)s)->proplist, PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
@@ -346,9 +336,9 @@ static audio_return_t set_volume_level_by_type(pa_stream_manager *m, stream_type
         if (pa_streq(volume_type_str, volume_type)) {
             pa_cvolume cv;
             pa_cvolume_set(&cv, stream_type==STREAM_SINK_INPUT?((pa_sink_input*)s)->sample_spec.channels:((pa_source_output*)s)->sample_spec.channels, pa_sw_volume_from_linear(volume_linear));
-            if (stream_type==STREAM_SINK_INPUT)
+            if (stream_type == STREAM_SINK_INPUT)
                 pa_sink_input_set_volume((pa_sink_input*)s, &cv, TRUE, TRUE);
-            else if (stream_type==STREAM_SOURCE_OUTPUT)
+            else if (stream_type == STREAM_SOURCE_OUTPUT)
                 pa_source_output_set_volume((pa_source_output*)s, &cv, TRUE, TRUE);
         }
     }
@@ -356,12 +346,10 @@ static audio_return_t set_volume_level_by_type(pa_stream_manager *m, stream_type
     pa_log_debug("set_volume_level_by_type() : stream_type[%d], volume_type[%s], level[%u], value[%f]",
             stream_type, volume_type, volume_level, volume_linear);
 
-    return audio_ret;
+    return 0;
 }
 
-int set_volume_level_by_idx(pa_stream_manager *m, stream_type stream_type, uint32_t idx, uint32_t volume_level) {
-    audio_return_t audio_ret = AUDIO_RET_OK;
-    int ret = 0;
+int32_t set_volume_level_by_idx(pa_stream_manager *m, stream_type stream_type, uint32_t idx, uint32_t volume_level) {
     pa_bool_t is_hal_volume = FALSE;
     void *s = NULL;
     pa_cvolume cv;
@@ -374,54 +362,48 @@ int set_volume_level_by_idx(pa_stream_manager *m, stream_type stream_type, uint3
     if ((volume_type_str = pa_proplist_gets(stream_type==STREAM_SINK_INPUT?((pa_sink_input*)s)->proplist:((pa_source_output*)s)->proplist, PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
         /* do nothing */
     } else
-        return AUDIO_ERR_UNDEFINED;
+        return -1;
 
     /* Check if it is related to HAL volume */
-    ret = is_hal_volume_by_type(m, volume_type_str, stream_type, &is_hal_volume);
-    if (ret) {
-        pa_log_error("failed to is_hal_volume_by_type(), stream_type(%d), volume_type(%s), ret(0x%x)", stream_type, volume_type_str, ret);
-        /* need to fix it */
-        return AUDIO_ERR_UNDEFINED;
+    if (is_hal_volume_by_type(m, volume_type_str, stream_type, &is_hal_volume)) {
+        pa_log_error("failed to is_hal_volume_by_type(), stream_type(%d), volume_type(%s)", stream_type, volume_type_str);
+        return -1;
      }
 
-    if (is_hal_volume && m->hal->intf.set_volume_level)
-        if (AUDIO_IS_ERROR((audio_ret = m->hal->intf.set_volume_level(m->hal->data, volume_type_str, stream_type, volume_level))))
-            pa_log_error("HAL set_volume_level returns error:0x%x", audio_ret);
+    if (is_hal_volume)
+        if (pa_hal_manager_set_volume_level(m->hal, volume_type_str, (stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN, volume_level))
+            return -1;
 
-    ret = get_volume_value(m, stream_type, is_hal_volume, volume_type_str, volume_level, &volume_linear);
-    if (!ret) {
+    if (!get_volume_value(m, stream_type, is_hal_volume, volume_type_str, volume_level, &volume_linear)) {
         pa_cvolume_set(&cv, (stream_type==STREAM_SINK_INPUT)?((pa_sink_input*)s)->sample_spec.channels:((pa_source_output*)s)->sample_spec.channels, pa_sw_volume_from_linear(volume_linear));
-        if (stream_type==STREAM_SINK_INPUT)
+        if (stream_type == STREAM_SINK_INPUT)
             pa_sink_input_set_volume((pa_sink_input*)s, &cv, TRUE, TRUE);
-        else if (stream_type==STREAM_SOURCE_OUTPUT)
+        else if (stream_type == STREAM_SOURCE_OUTPUT)
             pa_source_output_set_volume((pa_source_output*)s, &cv, TRUE, TRUE);
     }
     pa_log_debug("set_volume_level_by_idx() : stream_type[%d], idx[%u]=>volume_type[%s], level[%u], value[%f]",
             stream_type, idx, volume_type_str, volume_level, volume_linear);
 
-    return AUDIO_RET_OK;
+    return 0;
 }
 
-static audio_return_t get_volume_level_by_type(pa_stream_manager *m, pa_volume_get_command_t command, stream_type stream_type, const char *volume_type, uint32_t *volume_level) {
-    audio_return_t audio_ret = AUDIO_RET_OK;
-    int ret = 0;
+static int32_t get_volume_level_by_type(pa_stream_manager *m, pa_volume_get_command_t command, stream_type stream_type, const char *volume_type, uint32_t *volume_level) {
+    int32_t ret = 0;
     pa_bool_t is_hal_volume = FALSE;
     pa_assert(m);
     pa_assert(volume_type);
 
     /* Check if it is related to HAL volume */
-    ret = is_hal_volume_by_type(m, volume_type, stream_type, &is_hal_volume);
-    if (ret) {
-        pa_log_error("failed to is_hal_volume_by_type(), stream_type(%d), volume_type(%s), ret(0x%x)", stream_type, volume_type, ret);
-        /* need to fix it */
-        return AUDIO_ERR_UNDEFINED;
+    if (is_hal_volume_by_type(m, volume_type, stream_type, &is_hal_volume)) {
+        pa_log_error("failed to is_hal_volume_by_type(), stream_type(%d), volume_type(%s)", stream_type, volume_type);
+        return -1;
      }
 
     if (command == GET_VOLUME_CURRENT_LEVEL) {
-        if (is_hal_volume && m->hal->intf.get_volume_level) {
+        if (is_hal_volume) {
             /* Get level from HAL */
-            if (AUDIO_IS_ERROR((audio_ret = m->hal->intf.get_volume_level(m->hal->data, volume_type, stream_type, volume_level))))
-                pa_log_error("get_volume_level returns error:0x%x", audio_ret);
+            if (pa_hal_manager_get_volume_level(m->hal, volume_type, (stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN, volume_level))
+                ret = -1;
         } else {
             /* Get level from stream-manager */
             volume_info *v = pa_hashmap_get((stream_type==STREAM_SINK_INPUT)?m->volume_map.out_volumes:m->volume_map.in_volumes, volume_type);
@@ -429,10 +411,10 @@ static audio_return_t get_volume_level_by_type(pa_stream_manager *m, pa_volume_g
                 *volume_level = v->current_level;
         }
     } else if (command == GET_VOLUME_MAX_LEVEL) {
-        if (is_hal_volume && m->hal->intf.get_volume_level_max) {
+        if (is_hal_volume) {
             /* Get level from HAL */
-            if (AUDIO_IS_ERROR((audio_ret = m->hal->intf.get_volume_level_max(m->hal->data, volume_type, stream_type, volume_level))))
-                pa_log_error("get_volume_level_max returns error:0x%x", audio_ret);
+            if (pa_hal_manager_get_volume_level_max(m->hal, volume_type, (stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN, volume_level))
+                ret = -1;
         } else {
             /* Get level from stream-manager */
             volume_info *v = pa_hashmap_get((stream_type==STREAM_SINK_INPUT)?m->volume_map.out_volumes:m->volume_map.in_volumes, volume_type);
@@ -441,7 +423,7 @@ static audio_return_t get_volume_level_by_type(pa_stream_manager *m, pa_volume_g
         }
     }
 
-    return audio_ret;
+    return ret;
 }
 
 static void dump_volume_map (pa_stream_manager *m) {
@@ -490,6 +472,7 @@ static void dump_volume_map (pa_stream_manager *m) {
 
 int init_volume_map (pa_stream_manager *m) {
     int ret = 0;
+    int i = 0;
     void *state = NULL;
     stream_info *s = NULL;
     volume_info *v = NULL;
@@ -500,38 +483,23 @@ int init_volume_map (pa_stream_manager *m) {
 
     if(m->stream_map) {
         PA_HASHMAP_FOREACH(s, m->stream_map, state) {
-            if (s->volume_type[STREAM_DIRECTION_IN]) {
-                v = pa_hashmap_get(m->volume_map.in_volumes, s->volume_type[STREAM_DIRECTION_IN]);
-                if (v) {
-                    if (s->is_hal_volume[STREAM_DIRECTION_IN])
-                        v->is_hal_volume_type = s->is_hal_volume[STREAM_DIRECTION_IN];
-                } else {
-                    v = pa_xmalloc0(sizeof(volume_info));
-                    if (v) {
-                        v->is_hal_volume_type = s->is_hal_volume[STREAM_DIRECTION_IN];
-                        v->idx_volume_values = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
-                        pa_hashmap_put(m->volume_map.in_volumes, s->volume_type[STREAM_DIRECTION_IN], v);
-                    } else {
-                        pa_log_error("failed to pa_xmalloc0()");
-                        ret = -1;
-                        goto FAILURE;
-                    }
-                }
-            } else if (s->volume_type[STREAM_DIRECTION_OUT]) {
-                v = pa_hashmap_get(m->volume_map.out_volumes, s->volume_type[STREAM_DIRECTION_OUT]);
-                if (v) {
-                    if (s->is_hal_volume[STREAM_DIRECTION_OUT])
-                        v->is_hal_volume_type = s->is_hal_volume[STREAM_DIRECTION_OUT];
-                } else {
-                    v = pa_xmalloc0(sizeof(volume_info));
+            for (i = STREAM_DIRECTION_IN; i < STREAM_DIRECTION_MAX; i++) {
+                if (s->volume_type[i]) {
+                    v = pa_hashmap_get((i==STREAM_DIRECTION_IN)?m->volume_map.in_volumes:m->volume_map.out_volumes, s->volume_type[i]);
                     if (v) {
-                        v->is_hal_volume_type = s->is_hal_volume[STREAM_DIRECTION_OUT];
-                        v->idx_volume_values = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
-                        pa_hashmap_put(m->volume_map.out_volumes, s->volume_type[STREAM_DIRECTION_OUT], v);
+                        if (s->is_hal_volume[i])
+                            v->is_hal_volume_type = s->is_hal_volume[i];
                     } else {
-                        pa_log_error("failed to pa_xmalloc0()");
-                        ret = -1;
-                        goto FAILURE;
+                        v = pa_xmalloc0(sizeof(volume_info));
+                        if (v) {
+                            v->is_hal_volume_type = s->is_hal_volume[i];
+                            v->idx_volume_values = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
+                            pa_hashmap_put((i==STREAM_DIRECTION_IN)?m->volume_map.in_volumes:m->volume_map.out_volumes, s->volume_type[i], v);
+                        } else {
+                            pa_log_error("failed to pa_xmalloc0()");
+                            ret = -1;
+                            goto FAILURE;
+                        }
                     }
                 }
             }
@@ -546,6 +514,24 @@ int init_volume_map (pa_stream_manager *m) {
 
     dump_volume_map(m);
 
+    /* Apply initial output volume level from vconf volume level */
+    {
+        #define VCONF_ADDR_LEN 64
+        const char *volume_type = NULL;
+        void *state = NULL;
+        while ((v = pa_hashmap_iterate(m->volume_map.out_volumes, &state, &volume_type))) {
+            int level = 5;
+            char vconf_vol_type_addr[VCONF_ADDR_LEN] = {0,};
+            pa_snprintf(vconf_vol_type_addr, VCONF_ADDR_LEN, "%s%s", VCONFKEY_OUT_VOLUME_PREFIX, volume_type);
+            if (vconf_get_int(vconf_vol_type_addr, &level))
+            pa_log_error("failed to get volume level of the vconf[%s]",vconf_vol_type_addr);
+            set_volume_level_by_type(m, STREAM_SINK_INPUT, volume_type, (uint32_t)level);
+            pa_log_debug("type(%s), current level(%u)", volume_type, v->current_level);
+        }
+    }
+#ifdef PRIMARY_VOLUME
+    vconf_set_int (VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE, -1);
+#endif
 FAILURE:
     return ret;
 }
@@ -590,44 +576,43 @@ void deinit_volume_map (pa_stream_manager *m) {
     return;
 }
 
-audio_return_t pa_stream_manager_volume_get_level_max(pa_stream_manager *m, stream_type stream_type, const char *volume_type, uint32_t *volume_level) {
-    audio_return_t audio_ret = AUDIO_RET_OK;
+int32_t pa_stream_manager_volume_get_level_max(pa_stream_manager *m, stream_type stream_type, const char *volume_type, uint32_t *volume_level) {
+    int32_t ret = 0;
     pa_assert(m);
     pa_assert(volume_type);
 
-    audio_ret = get_volume_level_by_type(m, GET_VOLUME_MAX_LEVEL, stream_type, volume_type, volume_level);
-
     pa_log_info("pa_stream_manager_volume_get_level_max, type:%s level:%u", volume_type, *volume_level);
-    return AUDIO_RET_OK;
+
+    ret = get_volume_level_by_type(m, GET_VOLUME_MAX_LEVEL, stream_type, volume_type, volume_level);
+
+    return ret;
 }
 
-audio_return_t pa_stream_manager_volume_get_current_level(pa_stream_manager *m, stream_type stream_type, const char *volume_type, uint32_t *volume_level) {
-    audio_return_t audio_ret = AUDIO_RET_OK;
+int32_t pa_stream_manager_volume_get_level(pa_stream_manager *m, stream_type stream_type, const char *volume_type, uint32_t *volume_level) {
+    int32_t ret = 0;
     pa_assert(m);
     pa_assert(volume_type);
 
     pa_log_info("pa_stream_manager_volume_get_current_level, type:%s level:%u", volume_type, *volume_level);
 
-    audio_ret = get_volume_level_by_type(m, GET_VOLUME_CURRENT_LEVEL, stream_type, volume_type, volume_level);
+    ret = get_volume_level_by_type(m, GET_VOLUME_CURRENT_LEVEL, stream_type, volume_type, volume_level);
 
-    return audio_ret;
+    return ret;
 }
 
-audio_return_t pa_stream_manager_volume_set_level(pa_stream_manager *m, stream_type stream_type, const char *volume_type, uint32_t volume_level) {
-    audio_return_t audio_ret = AUDIO_RET_OK;
+int32_t pa_stream_manager_volume_set_level(pa_stream_manager *m, stream_type stream_type, const char *volume_type, uint32_t volume_level) {
+    int32_t ret = 0;
     pa_assert(m);
     pa_assert(volume_type);
 
     pa_log_info("pa_stream_manager_volume_set_level, type:%s level:%u", volume_type, volume_level);
 
-    audio_ret = set_volume_level_by_type(m, stream_type, volume_type, volume_level);
+    ret = set_volume_level_by_type(m, stream_type, volume_type, volume_level);
 
-    return audio_ret;
+    return ret;
 }
 
-audio_return_t pa_stream_manager_volume_get_mute(pa_stream_manager *m, stream_type stream_type, const char *volume_type, pa_bool_t *mute) {
-    audio_return_t audio_ret = AUDIO_RET_OK;
-    int ret = 0;
+int32_t pa_stream_manager_volume_get_mute(pa_stream_manager *m, stream_type stream_type, const char *volume_type, pa_bool_t *mute) {
     pa_bool_t is_hal_volume = FALSE;
     pa_sink_input *si = NULL;
     pa_source_output *so = NULL;
@@ -635,22 +620,14 @@ audio_return_t pa_stream_manager_volume_get_mute(pa_stream_manager *m, stream_ty
     const char *volume_type_str;
 
     /* Check if it is related to HAL volume */
-    ret = is_hal_volume_by_type(m, volume_type, stream_type, &is_hal_volume);
-    if (ret) {
-        pa_log_error("failed to is_hal_volume_by_type(), stream_type(%d), volume_type(%s), ret(0x%x)", stream_type, volume_type, ret);
-        /* need to fix it */
-        return AUDIO_ERR_UNDEFINED;
+    if (is_hal_volume_by_type(m, volume_type, stream_type, &is_hal_volume)) {
+        pa_log_error("failed to is_hal_volume_by_type(), stream_type(%d), volume_type(%s)", stream_type, volume_type);
+        return -1;
      }
 
-    if (is_hal_volume && m->hal->intf.get_mute) {
-        audio_ret = m->hal->intf.get_mute(m->hal->data, volume_type, stream_type, mute);
-        if (audio_ret == AUDIO_RET_USE_HW_CONTROL)
-            pa_log_info("HAL get_mute returns error:0x%x mute:%d", audio_ret, *mute);
-        else {
-            pa_log_error("HAL get_mute returns error:0x%x", audio_ret);
-            return audio_ret;
-        }
-    }
+    if (is_hal_volume)
+        if (pa_hal_manager_get_mute(m->hal, volume_type, (stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN, (uint32_t*)mute))
+            return -1;
 
     if (stream_type == STREAM_SINK_INPUT) {
         PA_IDXSET_FOREACH(si, m->core->sink_inputs, idx) {
@@ -681,160 +658,109 @@ audio_return_t pa_stream_manager_volume_get_mute(pa_stream_manager *m, stream_ty
     }
 
     pa_log_info("get mute stream_type:%d, volume_type:%s mute:%d", stream_type, volume_type, *mute);
-    return audio_ret;
+    return 0;
 }
 
-audio_return_t pa_stream_manager_volume_set_mute(pa_stream_manager *m, stream_type stream_type, const char *volume_type, pa_bool_t mute) {
-    audio_return_t audio_ret = AUDIO_RET_OK;
-    int ret = 0;
+int32_t pa_stream_manager_volume_set_mute(pa_stream_manager *m, stream_type stream_type, const char *volume_type, pa_bool_t mute) {
     pa_bool_t is_hal_volume = FALSE;
-    pa_sink_input *si = NULL;
-    pa_source_output *so = NULL;
+    void *s = NULL;
     uint32_t idx;
     const char *volume_type_str;
 
     /* Check if it is related to HAL volume */
-    ret = is_hal_volume_by_type(m, volume_type, stream_type, &is_hal_volume);
-    if (ret) {
-        pa_log_error("failed to is_hal_volume_by_type(), stream_type(%d), volume_type(%s), ret(0x%x)", stream_type, volume_type, ret);
-        /* need to fix it */
-        return AUDIO_ERR_UNDEFINED;
+    if (is_hal_volume_by_type(m, volume_type, stream_type, &is_hal_volume)) {
+        pa_log_error("failed to is_hal_volume_by_type(), stream_type(%d), volume_type(%s)", stream_type, volume_type);
+        return -1;
      }
 
-    if (is_hal_volume && m->hal->intf.set_mute) {
-        audio_ret = m->hal->intf.set_mute(m->hal->data, volume_type, stream_type, mute);
-        if (audio_ret == AUDIO_RET_USE_HW_CONTROL) {
-            pa_log_info("HAL set_mute returns error:0x%x mute:%d", audio_ret, mute);
-        } else if (AUDIO_IS_ERROR(audio_ret)) {
-            pa_log_error("HAL set_mute returns error:0x%x", audio_ret);
-        }
-    }
+    if (is_hal_volume)
+        if (pa_hal_manager_set_mute(m->hal, volume_type, (stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN, (uint32_t)mute))
+            return -1;
 
-    if (stream_type == STREAM_SINK_INPUT) {
-        PA_IDXSET_FOREACH(si, m->core->sink_inputs, idx) {
-            if ((volume_type_str = pa_proplist_gets(si->proplist, PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
-                /* do nothing */
-            } else {
-                continue;
-            }
-            /* Update mute of stream if it has requested the volume type */
-            if (pa_streq(volume_type_str, volume_type))
-                pa_sink_input_set_mute(si, mute, TRUE);
-        }
-    } else if (stream_type == STREAM_SOURCE_OUTPUT) {
-        PA_IDXSET_FOREACH(so, m->core->source_outputs, idx) {
-            if ((volume_type_str = pa_proplist_gets(so->proplist, PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
-                /* do nothing */
-            } else {
-                continue;
-            }
-            /* Update mute of stream if it has requested the volume type */
-            if (pa_streq(volume_type_str, volume_type))
-                pa_source_output_set_mute(so, mute, TRUE);
+    PA_IDXSET_FOREACH(s, (stream_type==STREAM_SINK_INPUT)?m->core->sink_inputs:m->core->source_outputs, idx) {
+        if ((volume_type_str = pa_proplist_gets((stream_type==STREAM_SINK_INPUT)?((pa_sink_input*)s)->proplist:((pa_source_output*)s)->proplist, PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
+            /* do nothing */
+        } else {
+            continue;
         }
+        /* Update mute of stream if it has requested the volume type */
+        if (pa_streq(volume_type_str, volume_type))
+            if (stream_type == STREAM_SINK_INPUT)
+                pa_sink_input_set_mute((pa_sink_input*)s, mute, TRUE);
+            else if (stream_type == STREAM_SOURCE_OUTPUT)
+                pa_source_output_set_mute((pa_source_output*)s, mute, TRUE);
     }
 
     pa_log_info("set mute stream_type:%d, volume_type:%s, mute:%d", stream_type, volume_type, mute);
-    return audio_ret;
+
+    return 0;
 }
 
-audio_return_t pa_stream_manager_volume_get_mute_by_idx(pa_stream_manager *m, stream_type stream_type, uint32_t stream_idx, pa_bool_t *mute) {
-    audio_return_t audio_ret = AUDIO_RET_OK;
-    pa_log_info("get mute stream_type:%d stream_idx:%u mute:%d", stream_type, stream_idx, *mute);
-    return audio_ret;
+int32_t pa_stream_manager_volume_get_mute_by_idx(pa_stream_manager *m, stream_type stream_type, uint32_t stream_idx, pa_bool_t *mute) {
+    int32_t ret = 0;
+    void *s = NULL;
+    uint32_t idx = 0;
+
+    PA_IDXSET_FOREACH(s, (stream_type==STREAM_SINK_INPUT)?m->core->sink_inputs:m->core->source_outputs, idx) {
+        /* Update mute of the stream if it has requested idx */
+        if (stream_idx == idx) {
+            if (stream_type == STREAM_SINK_INPUT)
+                *mute = ((pa_sink_input*)s)->muted;
+            else if (stream_type == STREAM_SOURCE_OUTPUT)
+                *mute = ((pa_source_output*)s)->muted;
+            break;
+        }
+    }
+    if (!s)
+        ret = -1;
+
+    pa_log_info("get mute stream_type:%d stream_idx:%u mute:%d, ret:%d", stream_type, stream_idx, *mute, ret);
+
+    return ret;
 }
 
-audio_return_t pa_stream_manager_volume_set_mute_by_idx(pa_stream_manager *m, stream_type stream_type, uint32_t stream_idx, pa_bool_t mute) {
-    audio_return_t audio_ret = AUDIO_RET_OK;
-    int ret = 0;
+int32_t pa_stream_manager_volume_set_mute_by_idx(pa_stream_manager *m, stream_type stream_type, uint32_t stream_idx, pa_bool_t mute) {
     pa_bool_t is_hal_volume = FALSE;
-    pa_sink_input *si = NULL;
-    pa_source_output *so = NULL;
+    void *s = NULL;
     uint32_t idx = 0;
-    audio_info_t audio_info;
-    uint32_t volume_type;
     const char *volume_type_str;
 
     pa_log_info("set mute stream_type:%d stream_idx:%u mute:%d", stream_type, stream_idx, mute);
 
-    if (stream_type == STREAM_SINK_INPUT) {
-        if (stream_idx != (uint32_t)-1) {
-            if ((si = pa_idxset_get_by_index(m->core->sink_inputs, stream_idx))) {
-                if ((volume_type_str = pa_proplist_gets(si->proplist, PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
-                    /* do nothing */
-                } else {
-                    pa_log_debug("stream[%d] doesn't have volume type", stream_idx);
-                    return AUDIO_ERR_UNDEFINED;
-                }
+    if (stream_idx != (uint32_t)-1) {
+        if ((s = pa_idxset_get_by_index((stream_type==STREAM_SINK_INPUT)?m->core->sink_inputs:m->core->source_outputs, stream_idx))) {
+            if ((volume_type_str = pa_proplist_gets((stream_type==STREAM_SINK_INPUT)?((pa_sink_input*)s)->proplist:((pa_source_output*)s)->proplist, PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
+                /* do nothing */
             } else {
-                pa_log_warn("stream[%u] doesn't exist", stream_idx);
-                return AUDIO_ERR_PARAMETER;
+                pa_log_debug("stream[%d] doesn't have volume type", stream_idx);
+                return -1;
             }
+        } else {
+            pa_log_warn("stream[%u] doesn't exist", stream_idx);
+            return -1;
         }
+    }
 
-        /* Check if it is related to HAL volume */
-        ret = is_hal_volume_by_type(m, volume_type_str, stream_type, &is_hal_volume);
-        if (ret) {
-            pa_log_error("failed to is_hal_volume_by_type(), stream_type(%d), volume_type(%s), ret(0x%x)", stream_type, volume_type, ret);
-            /* need to fix it */
-            return AUDIO_ERR_UNDEFINED;
-         }
-
-        if (is_hal_volume && m->hal->intf.set_mute) {
-            audio_ret = m->hal->intf.set_mute(m->hal->data, volume_type, stream_type, mute);
-            if (audio_ret == AUDIO_RET_USE_HW_CONTROL) {
-                pa_log_info("HAL set_mute returns error:0x%x mute:%d", audio_ret, mute);
-            } else if (AUDIO_IS_ERROR(audio_ret)) {
-                pa_log_error("HAL set_mute returns error:0x%x", audio_ret);
-            }
-        }
-        PA_IDXSET_FOREACH(si, m->core->sink_inputs, idx) {
-            /* Update mute of the stream if it has requested idx */
-            if (stream_idx == idx) {
-                pa_sink_input_set_mute(si, mute, TRUE);
-                break;
-            }
-        }
+    /* Check if it is related to HAL volume */
+    if (is_hal_volume_by_type(m, volume_type_str, stream_type, &is_hal_volume)) {
+        pa_log_error("failed to is_hal_volume_by_type(), stream_type(%d), volume_type(%s)", stream_type, volume_type_str);
+        return -1;
+     }
 
-    } else if (stream_type == STREAM_SOURCE_OUTPUT) {
-        if (stream_idx != (uint32_t)-1) {
-            if ((so = pa_idxset_get_by_index(m->core->source_outputs, stream_idx))) {
-                if ((volume_type_str = pa_proplist_gets(so->proplist, PA_PROP_MEDIA_TIZEN_VOLUME_TYPE))) {
-                    /* do nothing */
-                } else {
-                    pa_log_debug("stream[%d] doesn't have volume type", stream_idx);
-                    return AUDIO_ERR_UNDEFINED;
-                }
-            } else {
-                pa_log_warn("stream[%u] doesn't exist", stream_idx);
-                return AUDIO_ERR_PARAMETER;
-            }
-        }
+    if (is_hal_volume)
+        if (pa_hal_manager_set_mute(m->hal, volume_type_str, (stream_type==STREAM_SINK_INPUT)?DIRECTION_OUT:DIRECTION_IN, mute))
+            return -1;
 
-        /* Check if it is related to HAL volume */
-        ret = is_hal_volume_by_type(m, volume_type_str, stream_type, &is_hal_volume);
-        if (ret) {
-            pa_log_error("failed to is_hal_volume_by_type(), stream_type(%d), volume_type(%s), ret(0x%x)", stream_type, volume_type, ret);
-            /* need to fix it */
-            return AUDIO_ERR_UNDEFINED;
-         }
-
-        if (is_hal_volume && m->hal->intf.set_mute) {
-            audio_ret = m->hal->intf.set_mute(m->hal->data, volume_type, stream_type, mute);
-            if (audio_ret == AUDIO_RET_USE_HW_CONTROL) {
-                pa_log_info("HAL set_mute returns error:0x%x mute:%d", audio_ret, mute);
-            } else if (AUDIO_IS_ERROR(audio_ret)) {
-                pa_log_error("HAL set_mute returns error:0x%x", audio_ret);
-            }
-        }
-        PA_IDXSET_FOREACH(so, m->core->sink_inputs, idx) {
-            /* Update mute of the stream if it has requested idx */
-            if (stream_idx == idx) {
-                pa_sink_input_set_mute(so, mute, TRUE);
-                break;
-            }
+    PA_IDXSET_FOREACH(s, (stream_type==STREAM_SINK_INPUT)?m->core->sink_inputs:m->core->source_outputs, idx) {
+        /* Update mute of the stream if it has requested idx */
+        if (stream_idx == idx) {
+            if (stream_type == STREAM_SINK_INPUT)
+                pa_sink_input_set_mute((pa_sink_input*)s, mute, TRUE);
+            else if (stream_type == STREAM_SOURCE_OUTPUT)
+                pa_source_output_set_mute((pa_source_output*)s, mute, TRUE);
+            break;
         }
     }
 
-    return audio_ret;
+    return 0;
 }
index 2bc41cb..e4ca7f9 100644 (file)
@@ -5,17 +5,13 @@
 #include "tizen-audio.h"
 
 #include "stream-manager.h"
-#include <vconf.h>
-#include <vconf-keys.h>
 
-#define VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE "memory/private/sound/PrimaryVolumetype"
-
-audio_return_t pa_stream_manager_volume_get_level_max(pa_stream_manager *m, stream_type stream_type, const char *volume_type, uint32_t *volume_level);
-audio_return_t pa_stream_manager_volume_get_current_level(pa_stream_manager *m, stream_type stream_type, const char *volume_type, uint32_t *volume_level);
-audio_return_t pa_stream_manager_volume_set_level(pa_stream_manager *m, stream_type stream_type, const char *volume_type, uint32_t volume_level);
-audio_return_t pa_stream_manager_volume_get_mute(pa_stream_manager *m, stream_type stream_type, const char *volume_type, pa_bool_t *mute);
-audio_return_t pa_stream_manager_volume_set_mute(pa_stream_manager *m, stream_type stream_type, const char *volume_type, pa_bool_t mute);
-audio_return_t pa_stream_manager_volume_get_mute_by_idx(pa_stream_manager *m, stream_type stream_type, uint32_t stream_idx, pa_bool_t *mute);
-audio_return_t pa_stream_manager_volume_set_mute_by_idx(pa_stream_manager *m, stream_type stream_type, uint32_t stream_idx, pa_bool_t mute);
+int32_t pa_stream_manager_volume_get_level_max(pa_stream_manager *m, stream_type stream_type, const char *volume_type, uint32_t *volume_level);
+int32_t pa_stream_manager_volume_get_level(pa_stream_manager *m, stream_type stream_type, const char *volume_type, uint32_t *volume_level);
+int32_t pa_stream_manager_volume_set_level(pa_stream_manager *m, stream_type stream_type, const char *volume_type, uint32_t volume_level);
+int32_t pa_stream_manager_volume_get_mute(pa_stream_manager *m, stream_type stream_type, const char *volume_type, pa_bool_t *mute);
+int32_t pa_stream_manager_volume_set_mute(pa_stream_manager *m, stream_type stream_type, const char *volume_type, pa_bool_t mute);
+int32_t pa_stream_manager_volume_get_mute_by_idx(pa_stream_manager *m, stream_type stream_type, uint32_t stream_idx, pa_bool_t *mute);
+int32_t pa_stream_manager_volume_set_mute_by_idx(pa_stream_manager *m, stream_type stream_type, uint32_t stream_idx, pa_bool_t mute);
 
 #endif
index 4184b5e..41c8b87 100644 (file)
@@ -808,7 +808,7 @@ static pa_bool_t check_role_to_skip(const char *role, pa_stream_manager *m) {
             ret = FALSE;
     }
 
-    pa_log_info("role is %s, skip(%d)", role, ret);
+    pa_log_info("role is [%s], skip(%d)", role, ret);
 
     return ret;
 }
@@ -929,7 +929,7 @@ static pa_bool_t update_the_highest_priority_stream(stream_type type, void *mine
         cur_max_stream = m->cur_highest_priority.source_output;
     }
 
-    pa_log_error("stream : type(%d), role(%s), priority(%d) ", type, role, priority);
+    pa_log_info("update_the_highest_priority_stream(), stream_type(%d), role(%s), priority(%d)", type, role, priority);
     if (priority != -1) {
         if (cur_max_stream == NULL) {
             *need_to_update = TRUE;
@@ -1258,7 +1258,7 @@ static pa_process_stream_result_t process_stream(stream_type type, void *stream,
             /* set default value for role and priority */
             #define DEFAULT_ROLE "media"
             pa_proplist_sets(type==STREAM_SINK_INPUT?((pa_sink_input_new_data *)stream)->proplist:((pa_source_output_new_data *)stream)->proplist, PA_PROP_MEDIA_ROLE, DEFAULT_ROLE);
-            pa_log_error("role is null, set default to (%s)", DEFAULT_ROLE);
+            pa_log_error("role is null, set default to [%s]", DEFAULT_ROLE);
         } else {
             /* skip roles */
             if (check_role_to_skip(role, m))
@@ -1271,9 +1271,7 @@ static pa_process_stream_result_t process_stream(stream_type type, void *stream,
     } else {
         role = pa_proplist_gets(type==STREAM_SINK_INPUT?((pa_sink_input*)stream)->proplist:((pa_source_output*)stream)->proplist, PA_PROP_MEDIA_ROLE);
         if (command == PROCESS_COMMAND_START) {
-            pa_log_debug("stream(%s) is about to be started", role);
             int32_t priority = 0;
-            pa_log_error("role is (%s)", role);
 
             /* skip roles */
             if (check_role_to_skip(role, m))
@@ -1315,7 +1313,6 @@ static pa_process_stream_result_t process_stream(stream_type type, void *stream,
                 do_notify(NOTIFY_COMMAND_CHANGE_ROUTE, type, m, NULL);
 
         } else if (command == PROCESS_COMMAND_END) {
-            pa_log_debug("stream(%s) is about to be ended", role);
             if (role) {
                 /* skip roles */
                 if (check_role_to_skip(role, m))
@@ -1352,8 +1349,8 @@ static pa_bool_t is_good_to_process(stream_type type, void *stream) {
     /* Later on it could be changed if it is possible to get notified via  */
     /* input/output state change cb.                                       */
     const char *name = pa_proplist_gets(type==STREAM_SINK_INPUT?((pa_sink_input*)stream)->proplist:((pa_source_output*)stream)->proplist, PA_PROP_MEDIA_NAME);
-    if (strncmp (name, STREAM_PROCESSED_USING_PUT_UNLINK_1, strlen(STREAM_PROCESSED_USING_PUT_UNLINK_1)) ||
-        strncmp (name, STREAM_PROCESSED_USING_PUT_UNLINK_2, strlen(STREAM_PROCESSED_USING_PUT_UNLINK_2)) ) {
+    if (!strncmp (name, STREAM_PROCESSED_USING_PUT_UNLINK_1, strlen(STREAM_PROCESSED_USING_PUT_UNLINK_1)) ||
+        !strncmp (name, STREAM_PROCESSED_USING_PUT_UNLINK_2, strlen(STREAM_PROCESSED_USING_PUT_UNLINK_2)) ) {
         return TRUE;
     }
     return FALSE;
@@ -1382,9 +1379,7 @@ static void update_buffer_attribute(pa_hal_manager *h, pa_sink_input_new_data *n
     if(pa_atoi(audio_latency, &latency))
         return;
 
-    pa_log_info(" - latency:%d, rate:%u, format:%d, channels:%u)", latency, new_data->sample_spec.rate, new_data->sample_spec.format, new_data->sample_spec.channels);
-    ret = pa_hal_get_buffer_attribute(h, latency, new_data->sample_spec.rate, new_data->sample_spec.format, new_data->sample_spec.channels, &maxlength, &tlength, &prebuf, &minreq, &fragsize);
-    if (ret == AUDIO_RET_OK) {
+    if (!pa_hal_manager_get_buffer_attribute(h, latency, new_data, &maxlength, &tlength, &prebuf, &minreq, &fragsize)) {
         pa_log_info(" - maxlength:%d, tlength:%d, prebuf:%d, minreq:%d, fragsize:%d", maxlength, tlength, prebuf, minreq, fragsize);
         pa_proplist_setf(new_data->proplist, "maxlength", "%d", maxlength);
         pa_proplist_setf(new_data->proplist, "tlength",   "%d", tlength);
@@ -1425,7 +1420,7 @@ static pa_hook_result_t sink_input_new_cb(pa_core *core, pa_sink_input_new_data
 #endif
 
     /* Update buffer attributes from HAL */
-    update_buffer_attribute(m, new_data);
+    update_buffer_attribute(m->hal, new_data);
 
     return PA_HOOK_OK;
 }
@@ -1544,7 +1539,7 @@ static pa_hook_result_t source_output_new_cb(pa_core *core, pa_source_output_new
     process_result = process_stream(STREAM_SOURCE_OUTPUT, new_data, PROCESS_COMMAND_PREPARE, m);
 
     /* Update buffer attributes from HAL */
-    update_buffer_attribute(m, new_data);
+    update_buffer_attribute(m->hal, new_data);
 
     return PA_HOOK_OK;
 }
@@ -1777,10 +1772,6 @@ pa_stream_manager* pa_stream_manager_init(pa_core *c) {
 
     m->comm = pa_communicator_get(c);
 
-#ifdef PRIMARY_VOLUME
-    vconf_set_int (VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE, -1);
-#endif
-
     return m;
 
 fail:
index 77fe4a6..afb74bd 100644 (file)
@@ -49,7 +49,6 @@ enum {
     SUBCOMMAND_GET_VOLUME_LEVEL_MAX,
     SUBCOMMAND_GET_VOLUME_LEVEL,
     SUBCOMMAND_SET_VOLUME_LEVEL,
-    SUBCOMMAND_UPDATE_VOLUME,
     SUBCOMMAND_GET_MUTE,
     SUBCOMMAND_SET_MUTE,
     SUBCOMMAND_IS_AVAILABLE_HIGH_LATENCY,
@@ -738,35 +737,6 @@ pa_operation *pa_ext_policy_set_volume_level (
     return o;
 }
 
-pa_operation *pa_ext_policy_update_volume (
-        pa_context *c,
-        pa_context_success_cb_t cb,
-        void *userdata) {
-
-    uint32_t tag;
-    pa_operation *o = NULL;
-    pa_tagstruct *t = NULL;
-
-    pa_assert(c);
-    pa_assert(PA_REFCNT_VALUE(c) >= 1);
-
-    PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
-    PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
-    PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED);
-
-    o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
-
-    t = pa_tagstruct_command(c, PA_COMMAND_EXTENSION, &tag);
-    pa_tagstruct_putu32(t, PA_INVALID_INDEX);
-    pa_tagstruct_puts(t, "module-policy");
-    pa_tagstruct_putu32(t, SUBCOMMAND_UPDATE_VOLUME);
-
-    pa_pstream_send_tagstruct(c->pstream, t);
-    pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
-
-    return o;
-}
-
 static void ext_policy_get_mute_cb(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata)
 {
     pa_operation *o = userdata;
index 5a36c30..ac1e7d8 100644 (file)
@@ -246,11 +246,6 @@ pa_operation *pa_ext_policy_set_volume_level (
         pa_context_success_cb_t cb,
         void *userdata);
 
-pa_operation *pa_ext_policy_update_volume (
-        pa_context *c,
-        pa_context_success_cb_t cb,
-        void *userdata);
-
 /** Callback prototype for pa_ext_policy_get_mute(). \since 0.9.21 */
 typedef void (*pa_ext_policy_get_mute_cb_t)(
         pa_context *c,