fixup! Change focus pipe location (/tmp/ to /tmp/focus)
[platform/core/multimedia/libmm-sound.git] / mm_sound.c
index 0fc8598..96b98a2 100644 (file)
 #include "include/mm_sound_pa_client.h"
 #include "include/mm_sound_common.h"
 
-
-#define VOLUME_MAX_MULTIMEDIA  16
-#define VOLUME_MAX_BASIC               8
-#define VOLUME_MAX_SINGLE              1
-
-
 #define MASTER_VOLUME_MAX 100
 #define MASTER_VOLUME_MIN 0
 
@@ -60,40 +54,13 @@ static const char* _get_volume_str(volume_type_t type)
        return (type < VOLUME_TYPE_MAX) ? volume_type_str[type] : "Unknown";
 }
 
-static int _validate_volume(volume_type_t type, int value)
+static const char* _get_volume_str_internal(volume_type_internal_t type)
 {
-       if (value < 0)
-               return -1;
-
-       switch (type) {
-       case VOLUME_TYPE_CALL:
-       case VOLUME_TYPE_VOIP:
-               if (value >= VOLUME_MAX_BASIC) {
-                       return -1;
-               }
-               break;
-       case VOLUME_TYPE_SYSTEM:
-       case VOLUME_TYPE_MEDIA:
-       case VOLUME_TYPE_ALARM:
-       case VOLUME_TYPE_NOTIFICATION:
-       case VOLUME_TYPE_RINGTONE:
-       case VOLUME_TYPE_VOICE:
-               if (value >= VOLUME_MAX_MULTIMEDIA) {
-                       return -1;
-               }
-               break;
-       default:
-               return -1;
-               break;
-       }
-       return 0;
-}
+       static const char *volume_type_str[] = {
+               "BIXBY"
+       };
 
-EXPORT_API
-int mm_sound_volume_remove_callback(volume_type_t type)
-{
-       /* FIXME : Will be removed */
-       return MM_ERROR_NOT_SUPPORT_API;
+       return (type < (VOLUME_TYPE_BIXBY + 1)) ? volume_type_str[type] : "Unknown";
 }
 
 EXPORT_API
@@ -128,44 +95,127 @@ int mm_sound_remove_volume_changed_callback(unsigned int subs_id)
 }
 
 EXPORT_API
-int mm_sound_volume_set_value(volume_type_t volume_type, const unsigned int volume_level)
+int mm_sound_volume_set_value(volume_type_t type, const unsigned int value)
 {
        int ret = MM_ERROR_NONE;
 
-       debug_msg("type = (%d)%s, value = %d", volume_type, _get_volume_str(volume_type), volume_level);
+       /* request daemon to set volume */
+       ret = mm_sound_client_set_volume_by_type(type, value);
+       if (ret)
+               debug_error("can not set volume, type(%s), value(%d), ret=0x%x", _get_volume_str(type), value, ret);
+       else
+               debug_msg("set (%s) volume to (%d)",  _get_volume_str(type), value);
 
-       /* Check input param */
-       if (0 > _validate_volume(volume_type, (int)volume_level)) {
-               debug_error("invalid volume type %d, value %u", volume_type, volume_level);
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_volume_get_value(volume_type_t type, unsigned int *value)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_sound_client_get_volume_by_type(type, value);
+       if (ret)
+               debug_error("can not get volume, type(%s), ret=0x%x", _get_volume_str(type), ret);
+       else
+               debug_msg("(%s) volume : %d",  _get_volume_str(type), *value);
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_add_volume_changed_callback_internal(mm_sound_volume_changed_cb_internal func, void* user_data, unsigned int *subs_id)
+{
+       int ret = MM_ERROR_NONE;
+
+       if (func == NULL || subs_id == NULL) {
+               debug_error("argument is not valid");
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
+       ret = mm_sound_client_add_volume_changed_callback_internal(func, user_data, subs_id);
+       if (ret < 0)
+               debug_error("Can not add internal volume changed callback, ret = %x", ret);
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_remove_volume_changed_callback_internal(unsigned int subs_id)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_sound_client_remove_volume_changed_callback(subs_id);
+       if (ret < 0)
+               debug_error("Can not remove internal volume changed callback, ret = %x", ret);
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_volume_set_value_internal(volume_type_internal_t type, const unsigned int value)
+{
+       int ret = MM_ERROR_NONE;
+
        /* request daemon to set volume */
-       ret = mm_sound_client_set_volume_by_type(volume_type, volume_level);
-       if (MM_ERROR_NONE != ret)
-               debug_error("Can not set volume, ret=0x%x", ret);
+       ret = mm_sound_client_set_volume_by_internal_type(type, value);
+       if (ret)
+               debug_error("can not set internal volume, type(%s), value(%d), ret=0x%x", _get_volume_str_internal(type), value, ret);
+       else
+               debug_msg("set (%s) volume to (%d)",  _get_volume_str_internal(type), value);
 
        return ret;
 }
 
 EXPORT_API
-int mm_sound_volume_get_value(volume_type_t type, unsigned int *value)
+int mm_sound_volume_get_value_internal(volume_type_internal_t type, unsigned int *value)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_sound_client_get_volume_by_internal_type(type, value);
+       if (ret)
+               debug_error("can not get internal volume, type(%s), ret=0x%x", _get_volume_str_internal(type), ret);
+       else
+               debug_msg("(%s) volume : %d",  _get_volume_str_internal(type), *value);
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_set_mute(volume_type_t type, bool mute)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_sound_client_set_mute_by_type(type, mute);
+       if (ret)
+               debug_error("can not set mute, type(%s), mute(%d), ret=0x%x", _get_volume_str(type), mute, ret);
+       else
+               debug_msg("set (%s) mute to (%d)",  _get_volume_str(type), mute);
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_get_mute(volume_type_t type, bool  *muted)
 {
        int ret = MM_ERROR_NONE;
 
        /* Check input param */
-       if (value == NULL) {
+       if (!muted) {
                debug_error("invalid argument");
                return MM_ERROR_INVALID_ARGUMENT;
        }
-       if (type >= VOLUME_TYPE_MAX) {
+       if (type > VOLUME_TYPE_VOICE) {
                debug_error("invalid volume type value %d", type);
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = mm_sound_util_volume_get_value_by_type(type, value);
+       ret = mm_sound_client_get_mute_by_type(type, muted);
+       if (ret)
+               debug_error("can not get mute, type(%s), ret=0x%x", _get_volume_str(type), ret);
+       else
+               debug_msg("(%s) mute state : %d",  _get_volume_str(type), *muted);
 
-       debug_msg("returned %s = %d", _get_volume_str(type), *value);
        return ret;
 }
 
@@ -216,127 +266,36 @@ int mm_sound_control_filter(const char *stream_type, const char *filter_name, co
 }
 
 ///////////////////////////////////
-////     MMSOUND PLAY APIs
-///////////////////////////////////
-EXPORT_API
-int mm_sound_play_sound_with_stream_info(const char *filename, char *stream_type, int stream_id, unsigned int loop, mm_sound_stop_callback_func callback, void *data, int *handle)
-{
-       MMSoundPlayParam param = { 0, };
-       int err;
-
-       param.filename = filename;
-       param.volume = 0; //volume value dose not effect anymore
-       param.callback = callback;
-       param.data = data;
-
-       if (loop == 0)
-               param.loop = -1;
-       else
-               param.loop = loop;
-
-       err = mm_sound_client_play_sound_with_stream_info(&param, handle, stream_type, stream_id);
-       if (err < 0) {
-               debug_error("Failed to play sound");
-               return err;
-       }
-
-       debug_warning("success : handle=[%p]", handle);
-
-       return MM_ERROR_NONE;
-
-}
-
-
-EXPORT_API
-int mm_sound_stop_sound(int handle)
-{
-       int err;
-
-       debug_warning("enter : handle=[%d]", handle);
-       /* Stop sound */
-       err = mm_sound_client_stop_sound(handle);
-       if (err < 0) {
-               debug_error("Fail to stop sound");
-               return err;
-       }
-       debug_warning("success : handle=[%d]", handle);
-
-       return MM_ERROR_NONE;
-}
-
-///////////////////////////////////
-////     MMSOUND TONE APIs
-///////////////////////////////////
-EXPORT_API
-int mm_sound_play_tone_with_stream_info(MMSoundTone_t tone, char *stream_type, int stream_id, const double volume, const int duration, int *handle)
-{
-
-       int err = MM_ERROR_NONE;
-
-       err = mm_sound_client_play_tone_with_stream_info(tone, stream_type, stream_id, volume, duration, handle);
-       if (err < 0) {
-               debug_error("Failed to play sound");
-               return err;
-       }
-
-       return err;
-
-}
-
-///////////////////////////////////
 ////     MMSOUND ROUTING APIs
 ///////////////////////////////////
 
 EXPORT_API
-int mm_sound_test(int a, int b, int* getv)
-{
-       int ret = MM_ERROR_NONE;
-
-       debug_log("mm_sound_test enter");
-       if (!getv) {
-               debug_error("argu null");
-               return MM_ERROR_INVALID_ARGUMENT;
-       }
-       ret = mm_sound_client_test(a, b, getv);
-       if (ret < 0) {
-               debug_error("Can not mm sound test, ret = %x", ret);
-       }
-       debug_log("mm_sound_test leave");
-
-       return ret;
-}
-
-EXPORT_API
-int mm_sound_add_test_callback(mm_sound_test_cb func, void *user_data, unsigned int *subs_id)
+int mm_sound_add_ducking_state_changed_callback(mm_sound_ducking_state_changed_cb func, void *user_data, unsigned int *subs_id)
 {
        int ret = MM_ERROR_NONE;
 
-       debug_log("enter");
-       if (!func || !subs_id) {
+       if (func == NULL || subs_id == NULL) {
                debug_error("argument is not valid");
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = mm_sound_client_add_test_callback(func, user_data, subs_id);
+       ret = mm_sound_client_add_ducking_state_changed_callback(func, user_data, subs_id);
        if (ret < 0) {
-               debug_error("Can not add test callback, ret = %x", ret);
+               debug_error("Can not add ducking state changed callback, ret = %x", ret);
        }
-       debug_log("leave");
 
        return ret;
 }
 
 EXPORT_API
-int mm_sound_remove_test_callback(unsigned int subs_id)
+int mm_sound_remove_ducking_state_changed_callback(unsigned int subs_id)
 {
        int ret = MM_ERROR_NONE;
 
-       debug_log("enter");
-       ret = mm_sound_client_remove_test_callback(subs_id);
+       ret = mm_sound_client_remove_ducking_state_changed_callback(subs_id);
        if (ret < 0) {
-               debug_error("Can not remove test callback, ret = %x", ret);
+               debug_error("Can not remove ducking state changed callback, ret = %x", ret);
        }
-       debug_log("leave");
 
        return ret;
 }