Fix SVACE defects
[platform/core/multimedia/libmm-sound.git] / mm_sound_pa_client.c
index 104ee66..e1ed46a 100644 (file)
  *
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/shm.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/msg.h>
-#include <assert.h>
-#include <errno.h>
 
 #include <mm_error.h>
 #include <mm_debug.h>
 
-#include <mm_session.h>
-#include <mm_session_private.h>
 #include <mm_sound_pa_client.h>
 
 #include <glib.h>
-#include <pulse/simple.h>
-#include <pulse/proplist.h>
-
-#include "include/mm_sound.h"
-#include "include/mm_sound_private.h"
-#include "include/mm_sound_utils.h"
-#include "include/mm_sound_common.h"
 
 #define MM_SOUND_CHANNEL_MIN                1
 #define MM_SOUND_CHANNEL_MAX                6
 
-#define MEDIA_POLICY_AUTO                   "auto"
-#define MEDIA_POLICY_PHONE                  "phone"
-#define MEDIA_POLICY_ALL                    "all"
-#define MEDIA_POLICY_VOIP                   "voip"
-#define MEDIA_POLICY_MIRRORING              "mirroring"
-#define MEDIA_POLICY_HIGH_LATENCY           "high-latency"
-
 typedef struct _mm_sound_handle_t {
     uint32_t handle;
 
     int mode;
-    int policy;
     int volume_type;
     int gain_type;
     int rate;
@@ -68,11 +45,10 @@ typedef struct _mm_sound_handle_t {
 
     int period; /* open api retrun value.*/
 
-    int stream_idx;
+    unsigned int stream_idx;
     int source_type;
 } mm_sound_handle_t;
 
-#define MM_SOUND_HANDLE_MAX                 32
 static struct {
     uint32_t handle_count; /* use amotic operations */
     GList* handles;
@@ -91,14 +67,6 @@ static struct {
         } \
     } while(0);
 
-#define CHECK_VOLUME_TYPE_RANGE(x) \
-    do { \
-        if(x < VOLUME_TYPE_SYSTEM || x >= VOLUME_TYPE_MAX) { \
-            debug_msg("invalid volume type(%d)", x); \
-            return MM_ERROR_INVALID_ARGUMENT; \
-        } \
-    } while(0);
-
 #define ATOMIC_INC(l, x) \
     do { \
         pthread_mutex_lock(l); \
@@ -120,32 +88,6 @@ static struct {
     } while(0);
 
 
-#define CHECK_CONNECT_TO_PULSEAUDIO()   __mm_sound_pa_connect_to_pa()
-
-// should be call after pa_ext function.
-#define WAIT_PULSEAUDIO_OPERATION(x, y) \
-    do { \
-        while (pa_operation_get_state(y) == PA_OPERATION_RUNNING) { \
-            debug_msg("waiting.................."); \
-            pa_threaded_mainloop_wait(x.mainloop); \
-            debug_msg("waiting DONE"); \
-        } \
-    } while(0);
-
-static const pa_tizen_volume_type_t mm_sound_volume_type_to_pa[VOLUME_TYPE_MAX] = {
-       [VOLUME_TYPE_SYSTEM] = PA_TIZEN_VOLUME_TYPE_SYSTEM,
-       [VOLUME_TYPE_NOTIFICATION] = PA_TIZEN_VOLUME_TYPE_NOTIFICATION,
-       [VOLUME_TYPE_ALARM] = PA_TIZEN_VOLUME_TYPE_ALARM,
-       [VOLUME_TYPE_RINGTONE] = PA_TIZEN_VOLUME_TYPE_RINGTONE,
-       [VOLUME_TYPE_MEDIA] = PA_TIZEN_VOLUME_TYPE_MEDIA,
-       [VOLUME_TYPE_CALL] = PA_TIZEN_VOLUME_TYPE_CALL,
-       [VOLUME_TYPE_VOIP] = PA_TIZEN_VOLUME_TYPE_VOIP,
-       [VOLUME_TYPE_VOICE] = PA_TIZEN_VOLUME_TYPE_VOICE,
-       [VOLUME_TYPE_FIXED] = PA_TIZEN_VOLUME_TYPE_FIXED,
-};
-
-#define PA_SIMPLE_FADE_INTERVAL_USEC                                           20000
-
 #define PA_SIMPLE_SAMPLES_PER_PERIOD_DEFAULT                           1536    /* frames */
 #define PA_SIMPLE_PERIODS_PER_BUFFER_FASTMODE                          4
 #define PA_SIMPLE_PERIODS_PER_BUFFER_DEFAULT                           6
@@ -158,13 +100,8 @@ static const pa_tizen_volume_type_t mm_sound_volume_type_to_pa[VOLUME_TYPE_MAX]
 #define PA_SIMPLE_PERIOD_TIME_FOR_LOW_LATENCY_MSEC                     25
 #define PA_SIMPLE_PERIOD_TIME_FOR_MID_LATENCY_MSEC                     50
 #define PA_SIMPLE_PERIOD_TIME_FOR_HIGH_LATENCY_MSEC                    75
-#define PA_SIMPLE_PERIOD_TIME_FOR_VERY_HIGH_LATENCY_MSEC               150
 #define PA_SIMPLE_PERIOD_TIME_FOR_VOIP_LATENCY_MSEC                    20
 
-#define IS_INPUT_HANDLE(x) \
-    if( x == HANDLE_MODE_INPUT || x == HANDLE_MODE_INPUT_HIGH_LATENCY || \
-        x == HANDLE_MODE_INPUT_LOW_LATENCY || x == HANDLE_MODE_INPUT_AP_CALL )
-
 __attribute__ ((constructor)) void __mm_sound_pa_init(void)
 {
     memset(&mm_sound_handle_mgr, 0, sizeof(mm_sound_handle_mgr));
@@ -205,38 +142,31 @@ gint __mm_sound_handle_comparefunc(gconstpointer a, gconstpointer b)
 }
 
 EXPORT_API
-int mm_sound_pa_open(MMSoundHandleMode mode, mm_sound_handle_route_info *route_info, MMSoundHandlePriority priority, int volume_config, pa_sample_spec* ss, pa_channel_map* channel_map, int* size, char *stream_type, int stream_index)
+int mm_sound_pa_open(MMSoundHandleMode mode, int volume_config, pa_sample_spec* ss, pa_channel_map* channel_map, int* size, char *stream_type, int stream_index)
 {
     pa_simple *s = NULL;
     pa_channel_map maps;
     pa_buffer_attr attr;
 
-    int vol_conf_type, vol_conf_gain;
-    int prop_vol_type, prop_gain_type;
+    int prop_vol_type = 0;
+    int prop_gain_type = VOLUME_GAIN_DEFAULT;
 
     int err = MM_ERROR_SOUND_INTERNAL;
     int period_time = PA_SIMPLE_PERIOD_TIME_FOR_MID_LATENCY_MSEC;
     int samples_per_period = PA_SIMPLE_SAMPLES_PER_PERIOD_DEFAULT;
     int periods_per_buffer = PA_SIMPLE_PERIODS_PER_BUFFER_DEFAULT;
 
-    const char *prop_policy = NULL;
-
-    unsigned long latency = 0;
     int handle_mode = mode;
-    int handle_inout = HANDLE_DIRECTION_NONE;
     int sample_size = 0;
-    pa_proplist *proplist = pa_proplist_new();
+    pa_proplist *proplist = NULL;
 
     mm_sound_handle_t* handle = NULL;
-    MMSoundHandleRoutePolicy policy = HANDLE_ROUTE_POLICY_DEFAULT;
-
-    if(route_info) {
-        policy = route_info->policy;
-    }
 
     if (ss->channels < MM_SOUND_CHANNEL_MIN || ss->channels > MM_SOUND_CHANNEL_MAX)
         return MM_ERROR_INVALID_ARGUMENT;
 
+    proplist = pa_proplist_new();
+
     if(channel_map == NULL) {
         pa_channel_map_init_auto(&maps, ss->channels, PA_CHANNEL_MAP_ALSA);
         channel_map = &maps;
@@ -258,81 +188,13 @@ int mm_sound_pa_open(MMSoundHandleMode mode, mm_sound_handle_route_info *route_i
     /* Set volume type of stream */
     if(volume_config > 0) {
         debug_log("setting gain type");
-        vol_conf_type = volume_config & 0x000000FF;
-        prop_vol_type = mm_sound_volume_type_to_pa[vol_conf_type];
-//          pa_proplist_setf(proplist, PA_PROP_MEDIA_TIZEN_VOLUME_TYPE, "%d", prop_vol_type);
+        prop_vol_type = 0; /* not used, set it system(0) temporarily */
 
         /* Set gain type of stream */
         prop_gain_type = (volume_config >> 8) & 0x000000FF;
 
         pa_proplist_setf(proplist, PA_PROP_MEDIA_TIZEN_GAIN_TYPE, "%d", prop_gain_type);
     }
-#if 0
-    IS_INPUT_HANDLE(handle_mode) {
-        handle_inout = HANDLE_DIRECTION_IN;
-
-        if (policy == HANDLE_ROUTE_POLICY_IN_MIRRORING) {
-            prop_policy = MEDIA_POLICY_MIRRORING;
-        } else if (policy == HANDLE_ROUTE_POLICY_IN_VOIP) {
-            prop_policy = MEDIA_POLICY_VOIP;
-            handle_mode = HANDLE_MODE_INPUT_AP_CALL;
-        }
-    } else {
-        handle_inout = HANDLE_DIRECTION_OUT;
-
-        /* Set policy property*/
-        if (policy == HANDLE_ROUTE_POLICY_OUT_HANDSET) {
-            prop_policy = MEDIA_POLICY_PHONE;
-
-        } else if (policy == HANDLE_ROUTE_POLICY_OUT_ALL) {
-            prop_policy = MEDIA_POLICY_ALL;
-        }
-    }
-
-    /* If not set any yet, set based on volume type */
-    if (prop_policy == NULL) {
-        /* check stream type (vol type) */
-        switch (vol_conf_type)
-        {
-        case VOLUME_TYPE_NOTIFICATION:
-        case VOLUME_TYPE_ALARM:
-            prop_policy = MEDIA_POLICY_ALL;
-            break;
-
-        case VOLUME_TYPE_MEDIA:
-            /* Set High-Latency for Music stream */
-            if (handle_mode == HANDLE_MODE_OUTPUT_CLOCK) {
-                latency = PA_SIMPLE_PERIOD_TIME_FOR_VERY_HIGH_LATENCY_MSEC;
-                prop_policy = MEDIA_POLICY_HIGH_LATENCY;
-            } else {
-                prop_policy = MEDIA_POLICY_AUTO;
-            }
-            break;
-
-        case VOLUME_TYPE_CALL:
-        case VOLUME_TYPE_RINGTONE:
-        case VOLUME_TYPE_FIXED: /* Used for Emergency */
-            prop_policy = MEDIA_POLICY_PHONE;
-            break;
-
-        case VOLUME_TYPE_VOIP:
-            prop_policy = MEDIA_POLICY_VOIP;
-
-            if(handle_inout == HANDLE_DIRECTION_OUT)
-                handle_mode = HANDLE_MODE_OUTPUT_AP_CALL; /* need to move to session */
-            else
-                debug_error("VOLUME_TYPE_VOIP unknown handle_inout(%d)", handle_inout);
-
-            break;
-
-        default:
-            prop_policy = MEDIA_POLICY_AUTO;
-            break;
-        }
-    }
-    pa_proplist_sets(proplist, PA_PROP_MEDIA_POLICY, prop_policy);
-
-#endif
 
     if (stream_index != -1) {
         char stream_index_s[11];
@@ -417,12 +279,12 @@ int mm_sound_pa_open(MMSoundHandleMode mode, mm_sound_handle_route_info *route_i
         break;
 
     case HANDLE_MODE_OUTPUT_CLOCK:
-        period_time = (!latency) ? PA_SIMPLE_PERIOD_TIME_FOR_HIGH_LATENCY_MSEC : latency;
+        period_time = PA_SIMPLE_PERIOD_TIME_FOR_HIGH_LATENCY_MSEC;
         samples_per_period = (ss->rate * period_time) / 1000;
         periods_per_buffer = PA_SIMPLE_PERIODS_PER_BUFFER_PLAYBACK;
         attr.prebuf = -1;
         attr.minreq = -1;
-        attr.tlength = (!latency) ? (uint32_t)-1 : periods_per_buffer * samples_per_period * pa_sample_size(ss);
+        attr.tlength = (uint32_t)-1;
         attr.maxlength = -1;
         attr.fragsize = 0;
 
@@ -476,14 +338,9 @@ int mm_sound_pa_open(MMSoundHandleMode mode, mm_sound_handle_route_info *route_i
         s = pa_simple_new_proplist(NULL, "MM_SOUND_PA_CLIENT", PA_STREAM_RECORD, NULL, "VoIP CAPTURE", ss, channel_map, &attr, proplist, &err);
 #endif
         break;
-    case HANDLE_MODE_CALL_OUT:
-    case HANDLE_MODE_CALL_IN:
-        debug_error("Does not support call device handling\n");
-        assert(0);
-        break;
     default:
-        return MM_ERROR_SOUND_INTERNAL;
-        assert(0);
+        err = MM_ERROR_SOUND_INTERNAL;
+        goto fail;
         break;
     }
 
@@ -498,9 +355,8 @@ int mm_sound_pa_open(MMSoundHandleMode mode, mm_sound_handle_route_info *route_i
     }
 
     handle = (mm_sound_handle_t*)malloc(sizeof(mm_sound_handle_t));
-
+    memset(handle, 0, sizeof(mm_sound_handle_t));
     handle->mode = mode;
-    handle->policy = policy;
     handle->volume_type = prop_vol_type;
     handle->gain_type = prop_gain_type;
     handle->rate = ss->rate;
@@ -516,18 +372,19 @@ int mm_sound_pa_open(MMSoundHandleMode mode, mm_sound_handle_route_info *route_i
         err = MM_ERROR_SOUND_INTERNAL;
         goto fail;
     }
-    g_list_append(mm_sound_handle_mgr.handles, handle);
+    mm_sound_handle_mgr.handles = g_list_append(mm_sound_handle_mgr.handles, handle);
 
     if(handle->handle == 0) {
         debug_msg("out of range. handle(%d)\n", handle->handle);
         goto fail;
     }
 
-    mm_sound_pa_set_mute(handle->handle, prop_vol_type, handle_inout, 0);
+    debug_msg("created handle[%d]. mode(%d), volumetype(%d), gain(%d), rate(%d), channels(%d), format(%d), stream_idx(%d), s(%x), source_type(%d)",
+        handle->handle, handle->mode, handle->volume_type, handle->gain_type,
+        handle->rate, handle->channels, ss->format, handle->stream_idx, handle->s, handle->source_type);
 
-    debug_msg("created handle[%d]. mode(%d), policy(%d), volumetype(%d), gain(%d), rate(%d), channels(%d), format(%d), stream_idx(%d), s(%x), source_type(%d) handle_inout(%d)",
-        handle->handle, handle->mode, handle->policy, handle->volume_type, handle->gain_type,
-        handle->rate, handle->channels, ss->format, handle->stream_idx, handle->s, handle->source_type, handle_inout);
+    if (proplist)
+        pa_proplist_free(proplist);
 
     return handle->handle;
 
@@ -543,38 +400,6 @@ fail:
 }
 
 EXPORT_API
-int mm_sound_pa_read(const int handle, void* buf, const int size)
-{
-    mm_sound_handle_t* phandle = NULL;
-    int err = MM_ERROR_NONE;
-
-#ifdef __STREAM_DEBUG__
-    debug_msg("handle(%d), buf(%p), size(%d)", handle, buf, size);
-#endif
-    if (buf == NULL)
-        return MM_ERROR_INVALID_ARGUMENT;
-
-    if (size < 0)
-        return MM_ERROR_INVALID_ARGUMENT;
-    else if (size == 0)
-        return size;
-
-    CHECK_HANDLE_RANGE(handle);
-    GET_HANDLE_DATA(phandle, mm_sound_handle_mgr.handles, &handle, __mm_sound_handle_comparefunc);
-    if(phandle == NULL) {
-        debug_msg("phandle is null");
-        return MM_ERROR_SOUND_INTERNAL;
-    }
-
-    if (0 > pa_simple_read(phandle->s, buf, size, &err)) {
-        debug_error("pa_simple_read() failed with %s", pa_strerror(err));
-        return MM_ERROR_SOUND_INTERNAL;
-    }
-
-    return size;
-}
-
-EXPORT_API
 int mm_sound_pa_write(const int handle, void* buf, const int size)
 {
     mm_sound_handle_t* phandle = NULL;
@@ -646,7 +471,7 @@ int mm_sound_pa_close(const int handle)
 
     debug_msg("leave: handle[%d] stream_index[%d]\n", handle, phandle->stream_idx);
 
-    g_list_remove(mm_sound_handle_mgr.handles, phandle);
+    mm_sound_handle_mgr.handles = g_list_remove(mm_sound_handle_mgr.handles, phandle);
     if(phandle != NULL) {
         free(phandle);
         phandle = NULL;
@@ -657,27 +482,6 @@ int mm_sound_pa_close(const int handle)
 }
 
 EXPORT_API
-int mm_sound_pa_cork(const int handle, const int cork)
-{
-    mm_sound_handle_t* phandle = NULL;
-    int err = MM_ERROR_NONE;
-
-       CHECK_HANDLE_RANGE(handle);
-    GET_HANDLE_DATA(phandle, mm_sound_handle_mgr.handles, &handle, __mm_sound_handle_comparefunc);
-    if(phandle == NULL) {
-        debug_msg("phandle is null");
-        return MM_ERROR_SOUND_INTERNAL;
-    }
-
-    if (0 > pa_simple_cork(phandle->s, cork, &err)) {
-        debug_error("pa_simple_cork() failed with %s\n", pa_strerror(err));
-        err = MM_ERROR_SOUND_INTERNAL;
-    }
-
-       return err;
-}
-
-EXPORT_API
 int mm_sound_pa_drain(const int handle)
 {
     mm_sound_handle_t* phandle = NULL;
@@ -696,316 +500,3 @@ int mm_sound_pa_drain(const int handle)
        return err;
 }
 
-EXPORT_API
-int mm_sound_pa_flush(const int handle)
-{
-    mm_sound_handle_t* phandle = NULL;
-    int err = MM_ERROR_NONE;
-
-    CHECK_HANDLE_RANGE(handle);
-    GET_HANDLE_DATA(phandle, mm_sound_handle_mgr.handles, &handle, __mm_sound_handle_comparefunc);
-    if(phandle == NULL)
-        return MM_ERROR_SOUND_INTERNAL;
-
-    if (0 > pa_simple_flush(phandle->s, &err)) {
-        debug_error("pa_simple_flush() failed with %s\n", pa_strerror(err));
-        err = MM_ERROR_SOUND_INTERNAL;
-    }
-
-    return err;
-}
-
-EXPORT_API
-int mm_sound_pa_get_latency(const int handle, int* latency)
-{
-    mm_sound_handle_t* phandle = NULL;
-    int err = MM_ERROR_NONE;
-    pa_usec_t latency_time = 0;
-
-       CHECK_HANDLE_RANGE(handle);
-    GET_HANDLE_DATA(phandle, mm_sound_handle_mgr.handles, &handle, __mm_sound_handle_comparefunc);
-    if(phandle == NULL) {
-        debug_msg("phandle is null");
-        return MM_ERROR_SOUND_INTERNAL;
-    }
-
-    latency_time = pa_simple_get_final_latency(phandle->s, &err);
-    if (err > 0 && latency_time == 0) {
-        debug_error("pa_simple_get_latency() failed with %s\n", pa_strerror(err));
-        err = MM_ERROR_SOUND_INTERNAL;
-    }
-    *latency = latency_time / 1000; // usec to msec
-
-    return err;
-}
-
-static void __mm_sound_pa_state_cb(pa_context *c, void *userdata)
-{
-    pa_threaded_mainloop *mainloop = userdata;
-
-    switch (pa_context_get_state(c)) {
-    case PA_CONTEXT_READY:
-        pa_threaded_mainloop_signal(mainloop, 0);
-        break;
-    case PA_CONTEXT_TERMINATED:
-    case PA_CONTEXT_FAILED:
-        pa_threaded_mainloop_signal(mainloop, 0);
-        break;
-
-    case PA_CONTEXT_UNCONNECTED:
-    case PA_CONTEXT_CONNECTING:
-    case PA_CONTEXT_AUTHORIZING:
-    case PA_CONTEXT_SETTING_NAME:
-        break;
-    }
-}
-
-static void __mm_sound_pa_connect_to_pa()
-{
-    if(mm_sound_handle_mgr.state)
-        return;
-
-    if (!(mm_sound_handle_mgr.mainloop = pa_threaded_mainloop_new())) {
-        debug_error("mainloop create failed");
-    }
-
-    if (!(mm_sound_handle_mgr.context = pa_context_new(pa_threaded_mainloop_get_api(mm_sound_handle_mgr.mainloop), NULL))) {
-        debug_error("context create failed");
-    }
-
-    pa_threaded_mainloop_lock(mm_sound_handle_mgr.mainloop);
-    pa_context_set_state_callback(mm_sound_handle_mgr.context, __mm_sound_pa_state_cb, (void *)mm_sound_handle_mgr.mainloop);
-
-    if(pa_threaded_mainloop_start(mm_sound_handle_mgr.mainloop) < 0) {
-        debug_error("mainloop start failed");
-    }
-
-    if (pa_context_connect(mm_sound_handle_mgr.context, NULL, 0, NULL) < 0) {
-        debug_error("context connect failed");
-    }
-
-    while (TRUE) {
-        pa_context_state_t state = pa_context_get_state(mm_sound_handle_mgr.context);
-
-        if (!PA_CONTEXT_IS_GOOD (state)) {
-            break;
-        }
-
-        if (state == PA_CONTEXT_READY) {
-            break;
-        }
-
-        debug_msg("waiting..................");
-        pa_threaded_mainloop_wait(mm_sound_handle_mgr.mainloop);
-        debug_msg("waiting DONE. check again...");
-    }
-
-    mm_sound_handle_mgr.state = TRUE;
-
-    pa_threaded_mainloop_unlock(mm_sound_handle_mgr.mainloop);
-
-}
-
-static void __mm_sound_pa_success_cb(pa_context *c, int success, void *userdata)
-{
-       pa_threaded_mainloop *mainloop = (pa_threaded_mainloop *)userdata;
-
-       if (!success) {
-               debug_error("pa control failed: %s\n", pa_strerror(pa_context_errno(c)));
-       } else {
-               debug_msg("pa control success\n");
-       }
-       pa_threaded_mainloop_signal(mainloop, 0);
-}
-
-EXPORT_API
-int mm_sound_pa_set_call_mute(const int type, const int mute, int direction)
-{
-    pa_operation *o = NULL;
-
-    CHECK_VOLUME_TYPE_RANGE(type);
-    CHECK_CONNECT_TO_PULSEAUDIO();
-
-    pa_threaded_mainloop_lock(mm_sound_handle_mgr.mainloop);
-
-    o = pa_ext_policy_set_mute(mm_sound_handle_mgr.context, -1, type, direction, mute, __mm_sound_pa_success_cb, (void *)mm_sound_handle_mgr.mainloop);
-    WAIT_PULSEAUDIO_OPERATION(mm_sound_handle_mgr, o);
-
-    if(o)
-        pa_operation_unref(o);
-
-    pa_threaded_mainloop_unlock(mm_sound_handle_mgr.mainloop);
-
-    return MM_ERROR_NONE;
-}
-
-typedef struct _get_volume_max_userdata_t
-{
-    pa_threaded_mainloop* mainloop;
-    int value;
-} get_volume_max_userdata_t;
-
-static void __mm_sound_pa_get_cb(pa_context *c, uint32_t value, void *userdata)
-{
-    get_volume_max_userdata_t* u = (get_volume_max_userdata_t*)userdata;
-
-    assert(c);
-    assert(u);
-
-    u->value = value;
-
-    pa_threaded_mainloop_signal(u->mainloop, 0);
-}
-
-
-EXPORT_API
-int mm_sound_pa_get_volume_level(int handle, const int type, int* level)
-{
-    mm_sound_handle_t* phandle = NULL;
-    get_volume_max_userdata_t userdata;
-    pa_operation *o = NULL;
-
-    CHECK_HANDLE_RANGE(handle);
-    CHECK_VOLUME_TYPE_RANGE(type);
-    CHECK_CONNECT_TO_PULSEAUDIO();
-
-    GET_HANDLE_DATA(phandle, mm_sound_handle_mgr.handles, &handle, __mm_sound_handle_comparefunc);
-    if(phandle == NULL) {
-        debug_msg("phandle is null");
-        return MM_ERROR_SOUND_INTERNAL;
-    }
-
-    pa_threaded_mainloop_lock(mm_sound_handle_mgr.mainloop);
-
-    userdata.mainloop = mm_sound_handle_mgr.mainloop;
-    userdata.value = -1;
-
-    o = pa_ext_policy_get_volume_level(mm_sound_handle_mgr.context, phandle->stream_idx, type, __mm_sound_pa_get_cb, (void *)&userdata);
-    WAIT_PULSEAUDIO_OPERATION(mm_sound_handle_mgr, o);
-
-    if(userdata.value < 0) {
-        debug_error("pa_ext_policy_get_volume_level() failed");
-        *level = -1;
-        pa_threaded_mainloop_unlock(mm_sound_handle_mgr.mainloop);
-        return MM_ERROR_SOUND_INTERNAL;
-    } else
-        pa_operation_unref(o);
-
-
-    *level = userdata.value;
-
-    pa_threaded_mainloop_unlock(mm_sound_handle_mgr.mainloop);
-
-}
-
-EXPORT_API
-int mm_sound_pa_set_volume_level(int handle, const int type, int level)
-{
-    mm_sound_handle_t* phandle = NULL;
-    pa_operation *o = NULL;
-
-    CHECK_HANDLE_RANGE(handle);
-    CHECK_VOLUME_TYPE_RANGE(type);
-    CHECK_CONNECT_TO_PULSEAUDIO();
-
-    GET_HANDLE_DATA(phandle, mm_sound_handle_mgr.handles, &handle, __mm_sound_handle_comparefunc);
-    if(phandle == NULL) {
-        debug_msg("phandle is null");
-        return MM_ERROR_SOUND_INTERNAL;
-    }
-
-    pa_threaded_mainloop_lock(mm_sound_handle_mgr.mainloop);
-
-    o = pa_ext_policy_set_volume_level(mm_sound_handle_mgr.context, phandle->stream_idx, type, level, __mm_sound_pa_success_cb, (void *)mm_sound_handle_mgr.mainloop);
-    WAIT_PULSEAUDIO_OPERATION(mm_sound_handle_mgr, o);
-
-    if(o)
-        pa_operation_unref(o);
-
-    pa_threaded_mainloop_unlock(mm_sound_handle_mgr.mainloop);
-}
-
-EXPORT_API
-int mm_sound_pa_get_mute(int handle, const int type, int direction, int* mute)
-{
-    mm_sound_handle_t* phandle = NULL;
-    get_volume_max_userdata_t userdata;
-    pa_operation *o = NULL;
-
-    CHECK_HANDLE_RANGE(handle);
-    CHECK_VOLUME_TYPE_RANGE(type);
-    CHECK_CONNECT_TO_PULSEAUDIO();
-
-    GET_HANDLE_DATA(phandle, mm_sound_handle_mgr.handles, &handle, __mm_sound_handle_comparefunc);
-    if(phandle == NULL) {
-        debug_msg("phandle is null");
-        return MM_ERROR_SOUND_INTERNAL;
-    }
-
-    pa_threaded_mainloop_lock(mm_sound_handle_mgr.mainloop);
-
-    userdata.mainloop = mm_sound_handle_mgr.mainloop;
-    userdata.value = -1;
-
-    o = pa_ext_policy_get_mute(mm_sound_handle_mgr.context, phandle->stream_idx, type, direction, __mm_sound_pa_get_cb, (void *)&userdata);
-    WAIT_PULSEAUDIO_OPERATION(mm_sound_handle_mgr, o);
-
-    if(userdata.value < 0) {
-        debug_error("mm_sound_pa_get_mute() failed");
-        *mute = -1;
-        pa_threaded_mainloop_unlock(mm_sound_handle_mgr.mainloop);
-        return MM_ERROR_SOUND_INTERNAL;
-    } else
-        pa_operation_unref(o);
-
-    pa_threaded_mainloop_unlock(mm_sound_handle_mgr.mainloop);
-}
-
-EXPORT_API
-int mm_sound_pa_set_mute(int handle, const int type, int direction, int mute)
-{
-    mm_sound_handle_t* phandle = NULL;
-    pa_operation *o = NULL;
-
-    CHECK_HANDLE_RANGE(handle);
-    CHECK_VOLUME_TYPE_RANGE(type);
-    CHECK_CONNECT_TO_PULSEAUDIO();
-
-    GET_HANDLE_DATA(phandle, mm_sound_handle_mgr.handles, &handle, __mm_sound_handle_comparefunc);
-    if(phandle == NULL) {
-        debug_msg("phandle is null");
-        return MM_ERROR_SOUND_INTERNAL;
-    }
-
-    pa_threaded_mainloop_lock(mm_sound_handle_mgr.mainloop);
-
-    o = pa_ext_policy_set_mute(mm_sound_handle_mgr.context, phandle->stream_idx, type, direction, mute, __mm_sound_pa_success_cb, (void *)mm_sound_handle_mgr.mainloop);
-    WAIT_PULSEAUDIO_OPERATION(mm_sound_handle_mgr, o);
-
-    if(o)
-        pa_operation_unref(o);
-
-    pa_threaded_mainloop_unlock(mm_sound_handle_mgr.mainloop);
-
-}
-
-EXPORT_API
-int mm_sound_pa_corkall(int cork)
-{
-    pa_operation *o = NULL;
-
-    CHECK_CONNECT_TO_PULSEAUDIO();
-
-    pa_threaded_mainloop_lock(mm_sound_handle_mgr.mainloop);
-
-    o = pa_context_set_cork_all(mm_sound_handle_mgr.context, cork, __mm_sound_pa_success_cb, (void *)mm_sound_handle_mgr.mainloop);
-    WAIT_PULSEAUDIO_OPERATION(mm_sound_handle_mgr, o);
-
-    if(o)
-        pa_operation_unref(o);
-
-    pa_threaded_mainloop_unlock(mm_sound_handle_mgr.mainloop);
-
-    return MM_ERROR_NONE;
-}
-