4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>,YeJin Cho <cho.yejin@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 #include "mm_player_utils.h"
25 #include "mm_player_audioeffect.h"
26 #include "mm_player_ini.h"
27 #include "mm_player_priv.h"
32 mm_player_get_foreach_present_supported_effect_type(MMHandleType hplayer, MMAudioEffectType effect_type, mmplayer_supported_audio_effect_cb foreach_cb, void *user_data)
34 mm_player_t *player = NULL;
35 int result = MM_ERROR_NONE;
36 mm_sound_device_flags_e flags = MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG | MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG;
37 MMSoundDeviceList_t device_list = NULL;
38 MMSoundDevice_t device_h = NULL;
39 mm_sound_device_type_e device_type;
44 MMPLAYER_RETURN_VAL_IF_FAIL(hplayer, MM_ERROR_PLAYER_NOT_INITIALIZED);
46 player = MM_PLAYER_CAST(hplayer);
48 /* get status if speaker is activated */
49 /* (1) get current device list */
50 result = mm_sound_get_device_list(flags, &device_list);
51 if (result != MM_ERROR_NONE) {
52 LOGE("mm_sound_get_device_list() failed [%x]!!", result);
57 /* (2) get device handle of device list */
58 result = mm_sound_get_next_device(device_list, &device_h);
59 if (result != MM_ERROR_NONE) {
60 LOGE("mm_sound_get_next_device() failed [%x]!!", result);
64 /* (3) get device type */
65 result = mm_sound_get_device_type(device_h, &device_type);
66 if (result != MM_ERROR_NONE) {
67 LOGE("mm_sound_get_device_type() failed [%x]!!", result);
71 if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET) {
73 for (i = 0; i < MM_AUDIO_EFFECT_PRESET_NUM; i++) {
74 if (player->ini.audio_effect_preset_list[i]) {
75 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
76 player->ini.audio_effect_preset_earphone_only_list[i])
79 if (!foreach_cb(effect_type, i, user_data)) {
80 LOGE("foreach callback returned error");
81 result = MM_ERROR_PLAYER_INTERNAL;
86 } else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM) {
88 for (i = 0; i < MM_AUDIO_EFFECT_CUSTOM_NUM; i++) {
89 if (player->ini.audio_effect_custom_list[i]) {
90 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
91 player->ini.audio_effect_custom_earphone_only_list[i]) {
94 if (!foreach_cb(effect_type, i, user_data)) {
95 LOGE("foreach callback returned error");
96 result = MM_ERROR_PLAYER_INTERNAL;
102 LOGE("invalid effect type(%d)", effect_type);
103 result = MM_ERROR_INVALID_ARGUMENT;
108 mm_sound_free_device_list(device_list);
116 __mmplayer_set_harmony_effect(mm_player_t *player, GstElement *audio_effect_element)
118 gint *ext_effect_level_list = NULL;
119 int count = 1; /* start from 1, because of excepting eq index */
120 int ext_level_index = 0;
121 int result = MM_ERROR_NONE;
125 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
126 MMPLAYER_RETURN_VAL_IF_FAIL(audio_effect_element, MM_ERROR_INVALID_ARGUMENT);
129 if (player->ini.audio_effect_custom_eq_band_num) {
130 LOGD("pass custom EQ level list to audio effect plugin");
131 /* set custom-equalizer level list */
132 g_object_set(audio_effect_element, "custom-eq", player->audio_effect_info.custom_eq_level, NULL);
134 LOGW("no custom EQ");
137 /* Custom Extension effects */
138 if (player->ini.audio_effect_custom_ext_num) {
139 LOGD("pass custom extension level list to audio effect plugin");
140 ext_effect_level_list = player->audio_effect_info.custom_ext_level_for_plugin;
141 if (!ext_effect_level_list) {
142 ext_effect_level_list = (gint *)malloc(sizeof(gint) * player->ini.audio_effect_custom_ext_num);
143 if (!ext_effect_level_list) {
144 LOGE("memory allocation for extension effect list failed");
145 return MM_ERROR_OUT_OF_MEMORY;
147 memset(ext_effect_level_list, 0, player->ini.audio_effect_custom_ext_num);
149 /* associate it to player handle */
150 player->audio_effect_info.custom_ext_level_for_plugin = ext_effect_level_list;
154 while (count < MM_AUDIO_EFFECT_CUSTOM_NUM) {
155 if (player->ini.audio_effect_custom_list[count]) {
156 ext_effect_level_list[ext_level_index] = player->audio_effect_info.custom_ext_level[count - 1];
158 if (ext_level_index == player->ini.audio_effect_custom_ext_num)
164 /* set custom-extension effects level list */
165 g_object_set(audio_effect_element, "custom-ext", ext_effect_level_list, NULL);
167 LOGW("no custom extension effect");
170 /* order action to audio effect plugin */
171 g_object_set(audio_effect_element, "filter-action", MM_AUDIO_EFFECT_TYPE_CUSTOM, NULL);
172 LOGD("filter-action = %d", MM_AUDIO_EFFECT_TYPE_CUSTOM);
181 __mmplayer_is_earphone_only_effect_type(mm_player_t *player, MMAudioEffectType effect_type, int effect)
183 gboolean result = FALSE;
188 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
190 if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET) {
192 if (player->ini.audio_effect_preset_earphone_only_list[effect]) {
193 LOGI("this preset effect(%d) is only available with earphone", effect);
196 } else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM) {
198 for (i = 1; i < MM_AUDIO_EFFECT_CUSTOM_NUM; i++) {
199 /* it starts from 1(except testing for EQ) */
200 if (player->ini.audio_effect_custom_earphone_only_list[i]) {
201 /* check if the earphone only custom effect was set */
202 if (player->audio_effect_info.custom_ext_level[i - 1]) {
203 LOGI("this custom effect(%d) is only available with earphone", i);
209 LOGE("invalid effect type(%d)", effect_type);
218 __mmplayer_audio_set_output_type(mm_player_t *player, MMAudioEffectType effect_type, int effect)
220 GstElement *audio_effect_element = NULL;
221 mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
222 MMSoundDeviceList_t device_list = NULL;
223 MMSoundDevice_t device_h = NULL;
224 mm_sound_device_type_e device_type;
226 int result = MM_ERROR_NONE;
230 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
232 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
234 /* (1) get current device list */
235 result = mm_sound_get_device_list(flags, &device_list);
236 if (result != MM_ERROR_NONE) {
237 LOGE("mm_sound_get_device_list() failed [%x]!!", result);
242 /* (2) get device handle of device list */
243 result = mm_sound_get_next_device(device_list, &device_h);
244 if (result != MM_ERROR_NONE) {
245 LOGE("mm_sound_get_next_device() failed [%x]!!", result);
249 /* (3) get device type */
250 result = mm_sound_get_device_type(device_h, &device_type);
251 if (result != MM_ERROR_NONE) {
252 LOGE("mm_sound_get_device_type() failed [%x]!!", result);
257 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER) {
258 if (MM_AUDIO_EFFECT_TYPE_SQUARE != effect_type) {
259 if (__mmplayer_is_earphone_only_effect_type(player, effect_type, effect)) {
260 LOGE("earphone is not equipped, this filter will not be applied");
261 result = MM_ERROR_PLAYER_SOUND_EFFECT_INVALID_STATUS;
265 output_type = MM_AUDIO_EFFECT_OUTPUT_SPK;
266 } else if (device_type == MM_SOUND_DEVICE_TYPE_MIRRORING) {
267 output_type = MM_AUDIO_EFFECT_OUTPUT_OTHERS;
268 } else if (device_type == MM_SOUND_DEVICE_TYPE_HDMI) {
269 output_type = MM_AUDIO_EFFECT_OUTPUT_HDMI;
270 } else if (device_type == MM_SOUND_DEVICE_TYPE_BLUETOOTH) {
271 output_type = MM_AUDIO_EFFECT_OUTPUT_BT;
272 } else if (device_type == MM_SOUND_DEVICE_TYPE_USB_AUDIO) {
273 output_type = MM_AUDIO_EFFECT_OUTPUT_USB_AUDIO;
275 /* Other case, include WIRED_ACCESSORY */
276 output_type = MM_AUDIO_EFFECT_OUTPUT_EAR;
278 LOGW("output_type = %d (0:spk,1:ear,2:others)", output_type);
280 /* set filter output mode */
281 g_object_set(audio_effect_element, "filter-output-mode", output_type, NULL);
285 mm_sound_free_device_list(device_list);
292 _mmplayer_is_supported_effect_type(mm_player_t *player, MMAudioEffectType effect_type, int effect)
294 gboolean result = TRUE;
295 mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
296 MMSoundDeviceList_t device_list = NULL;
297 MMSoundDevice_t device_h = NULL;
298 mm_sound_device_type_e device_type;
299 int ret = MM_ERROR_NONE;
303 /* get status if speaker is activated */
304 /* (1) get current device list */
305 ret = mm_sound_get_device_list(flags, &device_list);
306 if (ret != MM_ERROR_NONE) {
308 LOGE("mm_sound_get_device_list() failed [%x]!!", ret);
312 /* (2) get device handle of device list */
313 ret = mm_sound_get_next_device(device_list, &device_h);
314 if (ret != MM_ERROR_NONE) {
315 LOGE("mm_sound_get_next_device() failed [%x]!!", ret);
319 /* (3) get device type */
320 ret = mm_sound_get_device_type(device_h, &device_type);
321 if (ret != MM_ERROR_NONE) {
322 LOGE("mm_sound_get_device_type() failed [%x]!!", ret);
327 if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET) {
328 if (effect < MM_AUDIO_EFFECT_PRESET_AUTO || effect >= MM_AUDIO_EFFECT_PRESET_NUM) {
329 LOGE("out of range, preset effect(%d)", effect);
332 if (!player->ini.audio_effect_preset_list[effect]) {
333 LOGE("this effect(%d) is not supported", effect);
336 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
337 player->ini.audio_effect_preset_earphone_only_list[effect]) {
342 } else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM) {
344 if (effect < MM_AUDIO_EFFECT_CUSTOM_EQ || effect >= MM_AUDIO_EFFECT_CUSTOM_NUM) {
345 LOGE("out of range, custom effect(%d)", effect);
348 if (!player->ini.audio_effect_custom_list[effect]) {
349 LOGE("this custom effect(%d) is not supported", effect);
352 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
353 player->ini.audio_effect_custom_earphone_only_list[effect])
357 } else if (effect_type == MM_AUDIO_EFFECT_TYPE_SQUARE) {
358 if (!player->ini.use_audio_effect_custom) {
359 LOGE("Square effect is not supported");
363 LOGE("invalid effect type(%d)", effect_type);
369 mm_sound_free_device_list(device_list);
376 _mmplayer_audio_effect_custom_apply(mm_player_t *player)
378 GstElement *audio_effect_element = NULL;
379 int result = MM_ERROR_NONE;
383 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
385 /* Music Player can set audio effect value before Audiobin is created. */
386 if (!player->pipeline || !player->pipeline->audiobin || !player->pipeline->audiobin[MMPLAYER_A_FILTER].gst) {
387 LOGW("effect element is not created yet.");
388 player->bypass_audio_effect = FALSE;
390 /* store audio effect setting in order to apply it when audio effect plugin is created */
391 player->audio_effect_info.effect_type = MM_AUDIO_EFFECT_TYPE_CUSTOM;
393 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
395 /* get status if speaker is activated */
396 result = __mmplayer_audio_set_output_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, 0);
397 if (result != MM_ERROR_NONE) {
398 LOGE("failed to set output mode");
403 result = __mmplayer_set_harmony_effect(player, audio_effect_element);
405 LOGE("_set_harmony_effect() failed(%x)", result);
410 player->set_mode.rich_audio = true;
418 _mmplayer_audio_effect_custom_update_level(mm_player_t *player)
420 GstElement *audio_effect_element = NULL;
421 int result = MM_ERROR_NONE;
422 int ext_level_index = 0;
425 gint *custom_eq = NULL;
426 gint *custom_ext_effect_level_list = NULL;
430 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
432 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
434 /* get custom eq effect */
435 g_object_get(audio_effect_element, "custom-eq", &custom_eq, NULL);
437 memcpy(player->audio_effect_info.custom_eq_level, custom_eq, sizeof(gint) * player->ini.audio_effect_custom_eq_band_num);
439 for (i = 0; i < player->ini.audio_effect_custom_eq_band_num; i++)
440 LOGD("updated custom-eq [%d] = %d", i, player->audio_effect_info.custom_eq_level[i]);
442 /* get custom ext effect */
443 g_object_get(audio_effect_element, "custom-ext", &custom_ext_effect_level_list, NULL);
445 while (count < MM_AUDIO_EFFECT_CUSTOM_NUM) {
446 if (player->ini.audio_effect_custom_list[count]) {
447 player->audio_effect_info.custom_ext_level[count - 1]
448 = custom_ext_effect_level_list[ext_level_index];
449 LOGD("updated custom-ext [%d] = %d", count, player->audio_effect_info.custom_ext_level[count - 1]);
461 mm_player_audio_effect_custom_clear_eq_all(MMHandleType hplayer)
463 int result = MM_ERROR_NONE;
464 mm_player_t *player = (mm_player_t *)hplayer;
468 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
470 /* clear EQ custom effect */
471 memset(player->audio_effect_info.custom_eq_level, MM_AUDIO_EFFECT_CUSTOM_LEVEL_INIT, sizeof(int) * MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX);
473 LOGI("All the EQ bands clearing success");
482 mm_player_audio_effect_custom_clear_ext_all(MMHandleType hplayer)
485 int result = MM_ERROR_NONE;
486 mm_player_t *player = (mm_player_t *)hplayer;
490 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
492 /* clear ALL custom effects, except EQ */
493 for (i = 0 ; i < MM_AUDIO_EFFECT_CUSTOM_NUM - 1 ; i++)
494 player->audio_effect_info.custom_ext_level[i] = MM_AUDIO_EFFECT_CUSTOM_LEVEL_INIT;
496 LOGI("All the extension effects clearing success");
505 mm_player_is_supported_preset_effect_type(MMHandleType hplayer, MMAudioEffectPresetType effect)
507 mm_player_t *player = (mm_player_t *)hplayer;
508 int result = MM_ERROR_NONE;
512 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
514 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_PRESET, effect))
515 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
524 mm_player_is_supported_custom_effect_type(MMHandleType hplayer, MMAudioEffectCustomType effect)
526 mm_player_t *player = (mm_player_t *)hplayer;
527 int result = MM_ERROR_NONE;
531 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
533 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, effect))
534 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
542 mm_player_audio_effect_custom_apply(MMHandleType hplayer)
544 mm_player_t *player = (mm_player_t *)hplayer;
545 int result = MM_ERROR_NONE;
549 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
551 if (!player->ini.use_audio_effect_custom) {
552 LOGE("audio effect(custom) is not supported");
554 return MM_ERROR_NOT_SUPPORT_API;
557 result = _mmplayer_audio_effect_custom_apply(player);
566 mm_player_audio_effect_bypass(MMHandleType hplayer)
568 mm_player_t *player = (mm_player_t *)hplayer;
569 int result = MM_ERROR_NONE;
570 GstElement *audio_effect_element = NULL;
574 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
576 if (!player->ini.use_audio_effect_preset && !player->ini.use_audio_effect_custom) {
577 LOGE("audio effect(preset/custom) is not supported");
579 return MM_ERROR_NOT_SUPPORT_API;
581 if (!player->pipeline || !player->pipeline->audiobin || !player->pipeline->audiobin[MMPLAYER_A_FILTER].gst) {
582 LOGW("effect element is not created yet.");
584 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
586 /* order action to audio effect plugin */
587 g_object_set(audio_effect_element, "filter-action", MM_AUDIO_EFFECT_TYPE_NONE, NULL);
588 LOGD("filter-action = %d", MM_AUDIO_EFFECT_TYPE_NONE);
598 _mmplayer_audio_effect_custom_set_level_ext(mm_player_t *player, MMAudioEffectCustomType custom_effect_type, int level)
600 int effect_level_max = 0;
601 int effect_level_min = 0;
602 int count = 1; /* start from 1, because of excepting eq index */
603 int ext_level_index = 1; /* start from 1, because of excepting eq index */
604 int result = MM_ERROR_NONE;
608 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
610 /* check if EQ is supported */
611 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, custom_effect_type)) {
613 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
616 while (count < MM_AUDIO_EFFECT_CUSTOM_NUM) {
617 if (player->ini.audio_effect_custom_list[count]) {
618 if (count == custom_effect_type) {
619 effect_level_min = player->ini.audio_effect_custom_min_level_list[ext_level_index];
620 effect_level_max = player->ini.audio_effect_custom_max_level_list[ext_level_index];
621 LOGI("level min value(%d), level max value(%d)", effect_level_min, effect_level_max);
625 if (ext_level_index == player->ini.audio_effect_custom_ext_num + 1) {
626 LOGE("could not find min, max value. maybe effect information in ini file is not proper for audio effect plugin");
633 if (level < effect_level_min || level > effect_level_max) {
634 LOGE("out of range, level(%d)", level);
635 result = MM_ERROR_INVALID_ARGUMENT;
637 player->audio_effect_info.custom_ext_level[custom_effect_type - 1] = level;
638 LOGI("set ext[%d] = %d", custom_effect_type-1, level);
648 _mmplayer_audio_effect_custom_set_level_eq(mm_player_t *player, int index, int level)
650 gint eq_level_max = 0;
651 gint eq_level_min = 0;
652 int result = MM_ERROR_NONE;
656 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
658 /* check if EQ is supported */
659 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
661 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
664 if (index < 0 || index > player->ini.audio_effect_custom_eq_band_num - 1) {
665 LOGE("out of range, index(%d)", index);
666 result = MM_ERROR_INVALID_ARGUMENT;
668 eq_level_min = player->ini.audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
669 eq_level_max = player->ini.audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
670 LOGI("EQ level min value(%d), EQ level max value(%d)", eq_level_min, eq_level_max);
672 if (level < eq_level_min || level > eq_level_max) {
673 LOGE("out of range, EQ level(%d)", level);
674 result = MM_ERROR_INVALID_ARGUMENT;
676 player->audio_effect_info.custom_eq_level[index] = level;
677 LOGI("set EQ[%d] = %d", index, level);
687 /* NOTE : parameter eq_index is only used for _set_eq_level() */
689 mm_player_audio_effect_custom_set_level(MMHandleType hplayer, MMAudioEffectCustomType effect_custom_type, int eq_index, int level)
691 mm_player_t *player = (mm_player_t *)hplayer;
692 int result = MM_ERROR_NONE;
696 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
698 /* check if this effect type is supported */
699 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, effect_custom_type)) {
700 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
702 if (effect_custom_type == MM_AUDIO_EFFECT_CUSTOM_EQ) {
703 result = _mmplayer_audio_effect_custom_set_level_eq(player, eq_index, level);
704 } else if (effect_custom_type > MM_AUDIO_EFFECT_CUSTOM_EQ && effect_custom_type < MM_AUDIO_EFFECT_CUSTOM_NUM) {
705 result = _mmplayer_audio_effect_custom_set_level_ext(player, effect_custom_type, level);
707 LOGE("out of range, effect type(%d)", effect_custom_type);
708 result = MM_ERROR_INVALID_ARGUMENT;
719 mm_player_audio_effect_custom_get_eq_bands_number(MMHandleType hplayer, int *bands)
721 mm_player_t *player = (mm_player_t *)hplayer;
722 int result = MM_ERROR_NONE;
726 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
728 /* check if EQ is supported */
729 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
731 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
734 *bands = player->ini.audio_effect_custom_eq_band_num;
735 LOGD("number of custom EQ band = %d", *bands);
744 mm_player_audio_effect_custom_get_eq_bands_width(MMHandleType hplayer, int band_idx, int *width)
746 mm_player_t *player = (mm_player_t *)hplayer;
747 int result = MM_ERROR_NONE;
748 unsigned int eq_num = 0;
752 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
754 /* check if EQ is supported */
755 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
757 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
760 eq_num = player->ini.audio_effect_custom_eq_band_num;
761 if (band_idx < 0 || band_idx > eq_num - 1) {
762 LOGE("out of range, invalid band_idx(%d)", band_idx);
763 result = MM_ERROR_INVALID_ARGUMENT;
765 /* set the width of EQ band */
766 *width = player->ini.audio_effect_custom_eq_band_width[band_idx];
767 LOGD("width of band_idx(%d) = %dHz", band_idx, *width);
777 mm_player_audio_effect_custom_get_eq_bands_freq(MMHandleType hplayer, int band_idx, int *freq)
779 mm_player_t *player = (mm_player_t *)hplayer;
780 int result = MM_ERROR_NONE;
781 unsigned int eq_num = 0;
785 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
787 /* check if EQ is supported */
788 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
790 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
793 eq_num = player->ini.audio_effect_custom_eq_band_num;
794 if (band_idx < 0 || band_idx > eq_num - 1) {
795 LOGE("out of range, invalid band_idx(%d)", band_idx);
796 result = MM_ERROR_INVALID_ARGUMENT;
798 /* set the frequency of EQ band */
799 *freq = player->ini.audio_effect_custom_eq_band_freq[band_idx];
800 LOGD("frequency of band_idx(%d) = %dHz", band_idx, *freq);
810 mm_player_audio_effect_custom_get_level(MMHandleType hplayer, MMAudioEffectCustomType type, int eq_index, int *level)
812 mm_player_t *player = (mm_player_t *)hplayer;
813 int result = MM_ERROR_NONE;
817 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
818 MMPLAYER_RETURN_VAL_IF_FAIL(level, MM_ERROR_PLAYER_NOT_INITIALIZED);
820 /* check if this effect type is supported */
821 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type)) {
823 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
826 if (type == MM_AUDIO_EFFECT_CUSTOM_EQ) {
827 if (eq_index < 0 || eq_index > player->ini.audio_effect_custom_eq_band_num - 1) {
828 LOGE("out of range, EQ index(%d)", eq_index);
829 result = MM_ERROR_INVALID_ARGUMENT;
831 *level = player->audio_effect_info.custom_eq_level[eq_index];
832 LOGD("EQ index = %d, level = %d", eq_index, *level);
834 } else if (type > MM_AUDIO_EFFECT_CUSTOM_EQ && type < MM_AUDIO_EFFECT_CUSTOM_NUM) {
835 *level = player->audio_effect_info.custom_ext_level[type - 1];
836 LOGD("extension effect index = %d, level = %d", type, *level);
838 LOGE("out of range, type(%d)", type);
839 result = MM_ERROR_INVALID_ARGUMENT;
849 mm_player_audio_effect_custom_get_level_range(MMHandleType hplayer, MMAudioEffectCustomType type, int *min, int *max)
851 mm_player_t *player = (mm_player_t *)hplayer;
852 int result = MM_ERROR_NONE;
853 int count = 1; /* start from 1, because of excepting eq index */
854 int ext_level_index = 1; /* start from 1, because of excepting eq index */
858 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
859 MMPLAYER_RETURN_VAL_IF_FAIL(min, MM_ERROR_PLAYER_NOT_INITIALIZED);
860 MMPLAYER_RETURN_VAL_IF_FAIL(max, MM_ERROR_PLAYER_NOT_INITIALIZED);
862 /* check if this effect type is supported */
863 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type)) {
865 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
868 if (type == MM_AUDIO_EFFECT_CUSTOM_EQ) {
869 *min = player->ini.audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
870 *max = player->ini.audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
871 LOGD("EQ min level = %d, max level = %d", *min, *max);
873 while (count < MM_AUDIO_EFFECT_CUSTOM_NUM) {
874 if (player->ini.audio_effect_custom_list[count]) {
876 *min = player->ini.audio_effect_custom_min_level_list[ext_level_index];
877 *max = player->ini.audio_effect_custom_max_level_list[ext_level_index];
878 LOGI("Extension effect(%d) min level = %d, max level = %d", count, *min, *max);
882 if (ext_level_index == player->ini.audio_effect_custom_ext_num + 1) {
883 LOGE("could not find min, max value. maybe effect information in ini file is not proper for audio effect plugin");
898 mm_player_audio_effect_custom_set_level_eq_from_list(MMHandleType hplayer, int *level_list, int size)
900 mm_player_t *player = (mm_player_t *)hplayer;
902 gint eq_level_min = 0;
903 gint eq_level_max = 0;
904 int result = MM_ERROR_NONE;
908 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
910 /* check if EQ is supported */
911 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
913 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
916 if (size != player->ini.audio_effect_custom_eq_band_num) {
917 LOGE("input size variable(%d) does not match with number of eq band(%d)", size, player->ini.audio_effect_custom_eq_band_num);
918 result = MM_ERROR_INVALID_ARGUMENT;
920 eq_level_min = player->ini.audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
921 eq_level_max = player->ini.audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
923 for (i = 0 ; i < size ; i++) {
924 if (level_list[i] < eq_level_min || level_list[i] > eq_level_max) {
925 LOGE("out of range, level[%d]=%d", i, level_list[i]);
926 result = MM_ERROR_INVALID_ARGUMENT;
929 player->audio_effect_info.custom_eq_level[i] = level_list[i];