[0.6.228] Add log for debug
[platform/core/multimedia/libmm-player.git] / src / mm_player_audioeffect.c
index 0129d25..ea50869 100644 (file)
@@ -49,7 +49,7 @@ mm_player_get_foreach_present_supported_effect_type(MMHandleType hplayer, mm_aud
        /* (1) get current device list */
        result = mm_sound_get_device_list(flags, &device_list);
        if (result != MM_ERROR_NONE) {
-               LOGE("mm_sound_get_device_list() failed [%x]!!", result);
+               LOGE("mm_sound_get_device_list() failed [0x%x]!!", result);
                MMPLAYER_FLEAVE();
                return result;
        }
@@ -57,14 +57,14 @@ mm_player_get_foreach_present_supported_effect_type(MMHandleType hplayer, mm_aud
        /* (2) get device handle of device list */
        result = mm_sound_get_next_device(device_list, &device_h);
        if (result != MM_ERROR_NONE) {
-               LOGE("mm_sound_get_next_device() failed [%x]!!", result);
+               LOGE("mm_sound_get_next_device() failed [0x%x]!!", result);
                goto EXIT;
        }
 
        /* (3) get device type */
        result = mm_sound_get_device_type(device_h, &device_type);
        if (result != MM_ERROR_NONE) {
-               LOGE("mm_sound_get_device_type() failed [%x]!!", result);
+               LOGE("mm_sound_get_device_type() failed [0x%x]!!", result);
                goto EXIT;
        }
 
@@ -234,7 +234,7 @@ __mmplayer_audio_set_output_type(mmplayer_t *player, mm_audio_effect_type_e effe
        /* (1) get current device list */
        result = mm_sound_get_device_list(flags, &device_list);
        if (result != MM_ERROR_NONE) {
-               LOGE("mm_sound_get_device_list() failed [%x]!!", result);
+               LOGE("mm_sound_get_device_list() failed [0x%x]!!", result);
                MMPLAYER_FLEAVE();
                return result;
        }
@@ -242,14 +242,14 @@ __mmplayer_audio_set_output_type(mmplayer_t *player, mm_audio_effect_type_e effe
        /* (2) get device handle of device list */
        result = mm_sound_get_next_device(device_list, &device_h);
        if (result != MM_ERROR_NONE) {
-               LOGE("mm_sound_get_next_device() failed [%x]!!", result);
+               LOGE("mm_sound_get_next_device() failed [0x%x]!!", result);
                goto EXIT;
        }
 
        /* (3) get device type */
        result = mm_sound_get_device_type(device_h, &device_type);
        if (result != MM_ERROR_NONE) {
-               LOGE("mm_sound_get_device_type() failed [%x]!!", result);
+               LOGE("mm_sound_get_device_type() failed [0x%x]!!", result);
                goto EXIT;
        }
 
@@ -305,21 +305,21 @@ __mmplayer_is_supported_effect_type(mmplayer_t *player, mm_audio_effect_type_e e
        ret = mm_sound_get_device_list(flags, &device_list);
        if (ret != MM_ERROR_NONE) {
                MMPLAYER_FLEAVE();
-               LOGE("mm_sound_get_device_list() failed [%x]!!", ret);
+               LOGE("mm_sound_get_device_list() failed [0x%x]!!", ret);
                return FALSE;
        }
 
        /* (2) get device handle of device list */
        ret = mm_sound_get_next_device(device_list, &device_h);
        if (ret != MM_ERROR_NONE) {
-               LOGE("mm_sound_get_next_device() failed [%x]!!", ret);
+               LOGE("mm_sound_get_next_device() failed [0x%x]!!", ret);
                goto EXIT;
        }
 
        /* (3) get device type */
        ret = mm_sound_get_device_type(device_h, &device_type);
        if (ret != MM_ERROR_NONE) {
-               LOGE("mm_sound_get_device_type() failed [%x]!!", ret);
+               LOGE("mm_sound_get_device_type() failed [0x%x]!!", ret);
                goto EXIT;
        }
 
@@ -372,6 +372,33 @@ EXIT:
        return result;
 }
 
+static int
+__mmplayer_audio_effect_check_condition(mmplayer_t *player, mm_audio_effect_type_e effect_type, int effect)
+{
+       int ret = MM_ERROR_NONE;
+       int enabled = 0;
+       bool available = false;
+
+       MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+       mm_attrs_get_int_by_name(player->attrs, MM_PLAYER_AUDIO_OFFLOAD, &enabled);
+       if (enabled) {
+               LOGW("audio offload is enabled.");
+               return MM_ERROR_PLAYER_SOUND_EFFECT_INVALID_STATUS;
+       }
+
+       ret = _mmplayer_is_audio_control_available((MMHandleType)player, MM_PLAYER_AUDIO_CONTROL_OPT_EFFECT, &available);
+       if (ret != MM_ERROR_NONE || !available)
+               return MM_ERROR_PLAYER_SOUND_EFFECT_INVALID_STATUS;
+
+       if (!__mmplayer_is_supported_effect_type(player, effect_type, effect)) {
+               LOGW("not supported effect filter %d %d", effect_type, effect);
+               return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
+       }
+
+       return MM_ERROR_NONE;
+}
+
 int
 _mmplayer_audio_effect_custom_apply(mmplayer_t *player)
 {
@@ -402,7 +429,7 @@ _mmplayer_audio_effect_custom_apply(mmplayer_t *player)
 
                result = __mmplayer_set_harmony_effect(player, audio_effect_element);
                if (result) {
-                       LOGE("_set_harmony_effect() failed(%x)", result);
+                       LOGE("_set_harmony_effect() failed(0x%x)", result);
                        MMPLAYER_FLEAVE();
                        return result;
                }
@@ -500,42 +527,43 @@ mm_player_audio_effect_custom_clear_ext_all(MMHandleType hplayer)
        return result;
 }
 
-
 int
-mm_player_is_supported_preset_effect_type(MMHandleType hplayer, mm_audio_effect_preset_type_e effect)
+mm_player_is_available_preset_effect(MMHandleType hplayer, mm_audio_effect_preset_type_e effect, bool *available)
 {
        mmplayer_t *player = (mmplayer_t *)hplayer;
-       int result = MM_ERROR_NONE;
 
        MMPLAYER_FENTER();
 
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       MMPLAYER_RETURN_VAL_IF_FAIL(available, MM_ERROR_INVALID_ARGUMENT);
 
-       if (!__mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_PRESET, effect))
-               result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
+       if (__mmplayer_audio_effect_check_condition(player, MM_AUDIO_EFFECT_TYPE_PRESET, effect) == MM_ERROR_NONE)
+               *available = true;
+       else
+               *available = false;
 
        MMPLAYER_FLEAVE();
 
-       return result;
+       return MM_ERROR_NONE;
 }
 
-
 int
-mm_player_is_supported_custom_effect_type(MMHandleType hplayer, mm_audio_effect_custom_type_e effect)
+mm_player_is_available_custom_effect(MMHandleType hplayer, mm_audio_effect_custom_type_e effect, bool *available)
 {
        mmplayer_t *player = (mmplayer_t *)hplayer;
-       int result = MM_ERROR_NONE;
 
        MMPLAYER_FENTER();
-
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+       MMPLAYER_RETURN_VAL_IF_FAIL(available, MM_ERROR_INVALID_ARGUMENT);
 
-       if (!__mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, effect))
-               result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
+       if (__mmplayer_audio_effect_check_condition(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, effect) == MM_ERROR_NONE)
+               *available = true;
+       else
+               *available = false;
 
        MMPLAYER_FLEAVE();
 
-       return result;
+       return MM_ERROR_NONE;
 }
 
 int
@@ -608,9 +636,10 @@ __mmplayer_audio_effect_custom_set_level_ext(mmplayer_t *player, mm_audio_effect
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        /* check if EQ is supported */
-       if (!__mmplayer_is_supported_effect_type(player,  MM_AUDIO_EFFECT_TYPE_CUSTOM, custom_effect_type)) {
+       result = __mmplayer_audio_effect_check_condition(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, custom_effect_type);
+       if (result != MM_ERROR_NONE) {
                MMPLAYER_FLEAVE();
-               return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
+               return result;
        }
 
        while (count < MM_AUDIO_EFFECT_CUSTOM_NUM) {
@@ -643,7 +672,6 @@ __mmplayer_audio_effect_custom_set_level_ext(mmplayer_t *player, mm_audio_effect
        return result;
 }
 
-
 static int
 __mmplayer_audio_effect_custom_set_level_eq(mmplayer_t *player, int index, int level)
 {
@@ -656,9 +684,10 @@ __mmplayer_audio_effect_custom_set_level_eq(mmplayer_t *player, int index, int l
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        /* check if EQ is supported */
-       if (!__mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
+       result = __mmplayer_audio_effect_check_condition(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ);
+       if (result != MM_ERROR_NONE) {
                MMPLAYER_FLEAVE();
-               return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
+               return result;
        }
 
        if (index < 0 || index > player->ini.audio_effect_custom_eq_band_num - 1) {
@@ -696,17 +725,19 @@ mm_player_audio_effect_custom_set_level(MMHandleType hplayer, mm_audio_effect_cu
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        /* check if this effect type is supported */
-       if (!__mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, effect_custom_type)) {
-               result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
+       result = __mmplayer_audio_effect_check_condition(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, effect_custom_type);
+       if (result != MM_ERROR_NONE) {
+               MMPLAYER_FLEAVE();
+               return result;
+       }
+
+       if (effect_custom_type == MM_AUDIO_EFFECT_CUSTOM_EQ) {
+               result = __mmplayer_audio_effect_custom_set_level_eq(player, eq_index, level);
+       } else if (effect_custom_type > MM_AUDIO_EFFECT_CUSTOM_EQ && effect_custom_type < MM_AUDIO_EFFECT_CUSTOM_NUM) {
+               result = __mmplayer_audio_effect_custom_set_level_ext(player, effect_custom_type, level);
        } else {
-               if (effect_custom_type == MM_AUDIO_EFFECT_CUSTOM_EQ) {
-                       result = __mmplayer_audio_effect_custom_set_level_eq(player, eq_index, level);
-               } else if (effect_custom_type > MM_AUDIO_EFFECT_CUSTOM_EQ && effect_custom_type < MM_AUDIO_EFFECT_CUSTOM_NUM) {
-                       result = __mmplayer_audio_effect_custom_set_level_ext(player, effect_custom_type, level);
-               } else {
-                       LOGE("out of range, effect type(%d)", effect_custom_type);
-                       result = MM_ERROR_INVALID_ARGUMENT;
-               }
+               LOGE("out of range, effect type(%d)", effect_custom_type);
+               result = MM_ERROR_INVALID_ARGUMENT;
        }
 
        MMPLAYER_FLEAVE();
@@ -726,9 +757,10 @@ mm_player_audio_effect_custom_get_eq_bands_number(MMHandleType hplayer, int *ban
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        /* check if EQ is supported */
-       if (!__mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
+       result = __mmplayer_audio_effect_check_condition(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ);
+       if (result != MM_ERROR_NONE) {
                MMPLAYER_FLEAVE();
-               return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
+               return result;
        }
 
        *bands = player->ini.audio_effect_custom_eq_band_num;
@@ -752,9 +784,10 @@ mm_player_audio_effect_custom_get_eq_bands_width(MMHandleType hplayer, int band_
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        /* check if EQ is supported */
-       if (!__mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
+       result = __mmplayer_audio_effect_check_condition(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ);
+       if (result != MM_ERROR_NONE) {
                MMPLAYER_FLEAVE();
-               return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
+               return result;
        }
 
        eq_num = player->ini.audio_effect_custom_eq_band_num;
@@ -785,9 +818,10 @@ mm_player_audio_effect_custom_get_eq_bands_freq(MMHandleType hplayer, int band_i
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        /* check if EQ is supported */
-       if (!__mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
+       result = __mmplayer_audio_effect_check_condition(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ);
+       if (result != MM_ERROR_NONE) {
                MMPLAYER_FLEAVE();
-               return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
+               return result;
        }
 
        eq_num = player->ini.audio_effect_custom_eq_band_num;
@@ -818,9 +852,10 @@ mm_player_audio_effect_custom_get_level(MMHandleType hplayer, mm_audio_effect_cu
        MMPLAYER_RETURN_VAL_IF_FAIL(level, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        /* check if this effect type is supported */
-       if (!__mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type)) {
+       result = __mmplayer_audio_effect_check_condition(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type);
+       if (result != MM_ERROR_NONE) {
                MMPLAYER_FLEAVE();
-               return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
+               return result;
        }
 
        if (type == MM_AUDIO_EFFECT_CUSTOM_EQ) {
@@ -860,9 +895,10 @@ mm_player_audio_effect_custom_get_level_range(MMHandleType hplayer, mm_audio_eff
        MMPLAYER_RETURN_VAL_IF_FAIL(max, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        /* check if this effect type is supported */
-       if (!__mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type)) {
+       result = __mmplayer_audio_effect_check_condition(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type);
+       if (result != MM_ERROR_NONE) {
                MMPLAYER_FLEAVE();
-               return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
+               return result;
        }
 
        if (type == MM_AUDIO_EFFECT_CUSTOM_EQ) {
@@ -908,9 +944,10 @@ mm_player_audio_effect_custom_set_level_eq_from_list(MMHandleType hplayer, int *
        MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
 
        /* check if EQ is supported */
-       if (!__mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
+       result = __mmplayer_audio_effect_check_condition(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ);
+       if (result != MM_ERROR_NONE) {
                MMPLAYER_FLEAVE();
-               return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
+               return result;
        }
 
        if (size != player->ini.audio_effect_custom_eq_band_num) {