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");
169 /* order action to audio effect plugin */
170 g_object_set(audio_effect_element, "filter-action", MM_AUDIO_EFFECT_TYPE_CUSTOM, NULL);
171 LOGD("filter-action = %d", MM_AUDIO_EFFECT_TYPE_CUSTOM);
180 __mmplayer_is_earphone_only_effect_type(mm_player_t *player, MMAudioEffectType effect_type, int effect)
182 gboolean result = FALSE;
187 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
189 if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET) {
191 if (player->ini.audio_effect_preset_earphone_only_list[effect]) {
192 LOGI("this preset effect(%d) is only available with earphone", effect);
195 } else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM) {
197 for (i = 1; i < MM_AUDIO_EFFECT_CUSTOM_NUM; i++) {
198 /* it starts from 1(except testing for EQ) */
199 if (player->ini.audio_effect_custom_earphone_only_list[i]) {
200 /* check if the earphone only custom effect was set */
201 if (player->audio_effect_info.custom_ext_level[i-1]) {
202 LOGI("this custom effect(%d) is only available with earphone", i);
208 LOGE("invalid effect type(%d)", effect_type);
216 __mmplayer_audio_set_output_type(mm_player_t *player, MMAudioEffectType effect_type, int effect)
218 GstElement *audio_effect_element = NULL;
219 mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
220 MMSoundDeviceList_t device_list = NULL;
221 MMSoundDevice_t device_h = NULL;
222 mm_sound_device_type_e device_type;
224 int result = MM_ERROR_NONE;
228 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
230 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
232 /* (1) get current device list */
233 result = mm_sound_get_device_list(flags, &device_list);
234 if (result != MM_ERROR_NONE) {
235 LOGE("mm_sound_get_device_list() failed [%x]!!", result);
240 /* (2) get device handle of device list */
241 result = mm_sound_get_next_device(device_list, &device_h);
242 if (result != MM_ERROR_NONE) {
243 LOGE("mm_sound_get_next_device() failed [%x]!!", result);
247 /* (3) get device type */
248 result = mm_sound_get_device_type(device_h, &device_type);
249 if (result != MM_ERROR_NONE) {
250 LOGE("mm_sound_get_device_type() failed [%x]!!", result);
255 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER) {
256 if (MM_AUDIO_EFFECT_TYPE_SQUARE != effect_type) {
257 if (__mmplayer_is_earphone_only_effect_type(player, effect_type, effect)) {
258 LOGE("earphone is not equipped, this filter will not be applied");
259 result = MM_ERROR_PLAYER_SOUND_EFFECT_INVALID_STATUS;
263 output_type = MM_AUDIO_EFFECT_OUTPUT_SPK;
264 } else if (device_type == MM_SOUND_DEVICE_TYPE_MIRRORING) {
265 output_type = MM_AUDIO_EFFECT_OUTPUT_OTHERS;
266 } else if (device_type == MM_SOUND_DEVICE_TYPE_HDMI) {
267 output_type = MM_AUDIO_EFFECT_OUTPUT_HDMI;
268 } else if (device_type == MM_SOUND_DEVICE_TYPE_BLUETOOTH) {
269 output_type = MM_AUDIO_EFFECT_OUTPUT_BT;
270 } else if (device_type == MM_SOUND_DEVICE_TYPE_USB_AUDIO) {
271 output_type = MM_AUDIO_EFFECT_OUTPUT_USB_AUDIO;
273 /* Other case, include WIRED_ACCESSORY */
274 output_type = MM_AUDIO_EFFECT_OUTPUT_EAR;
276 LOGW("output_type = %d (0:spk,1:ear,2:others)", output_type);
278 /* set filter output mode */
279 g_object_set(audio_effect_element, "filter-output-mode", output_type, NULL);
283 mm_sound_free_device_list(device_list);
290 _mmplayer_is_supported_effect_type(mm_player_t* player, MMAudioEffectType effect_type, int effect)
292 gboolean result = TRUE;
293 mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
294 MMSoundDeviceList_t device_list = NULL;
295 MMSoundDevice_t device_h = NULL;
296 mm_sound_device_type_e device_type;
297 int ret = MM_ERROR_NONE;
301 /* get status if speaker is activated */
302 /* (1) get current device list */
303 ret = mm_sound_get_device_list(flags, &device_list);
304 if (ret != MM_ERROR_NONE) {
306 LOGE("mm_sound_get_device_list() failed [%x]!!", ret);
310 /* (2) get device handle of device list */
311 ret = mm_sound_get_next_device(device_list, &device_h);
312 if (ret != MM_ERROR_NONE) {
313 LOGE("mm_sound_get_next_device() failed [%x]!!", ret);
317 /* (3) get device type */
318 ret = mm_sound_get_device_type(device_h, &device_type);
319 if (ret != MM_ERROR_NONE) {
320 LOGE("mm_sound_get_device_type() failed [%x]!!", ret);
325 if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET) {
326 if (effect < MM_AUDIO_EFFECT_PRESET_AUTO || effect >= MM_AUDIO_EFFECT_PRESET_NUM) {
327 LOGE("out of range, preset effect(%d)", effect);
330 if (!player->ini.audio_effect_preset_list[effect]) {
331 LOGE("this effect(%d) is not supported", effect);
334 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
335 player->ini.audio_effect_preset_earphone_only_list[effect]) {
340 } else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM) {
342 if (effect < MM_AUDIO_EFFECT_CUSTOM_EQ || effect >= MM_AUDIO_EFFECT_CUSTOM_NUM) {
343 LOGE("out of range, custom effect(%d)", effect);
346 if (!player->ini.audio_effect_custom_list[effect]) {
347 LOGE("this custom effect(%d) is not supported", effect);
350 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
351 player->ini.audio_effect_custom_earphone_only_list[effect]) {
356 } else if (effect_type == MM_AUDIO_EFFECT_TYPE_SQUARE) {
357 if (!player->ini.use_audio_effect_custom) {
358 LOGE("Square effect is not supported");
362 LOGE("invalid effect type(%d)", effect_type);
368 mm_sound_free_device_list(device_list);
375 _mmplayer_audio_effect_custom_apply(mm_player_t *player)
377 GstElement *audio_effect_element = NULL;
378 int result = MM_ERROR_NONE;
382 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
384 /* Music Player can set audio effect value before Audiobin is created. */
385 if (!player->pipeline || !player->pipeline->audiobin || !player->pipeline->audiobin[MMPLAYER_A_FILTER].gst) {
386 LOGW("effect element is not created yet.");
387 player->bypass_audio_effect = FALSE;
389 /* store audio effect setting in order to apply it when audio effect plugin is created */
390 player->audio_effect_info.effect_type = MM_AUDIO_EFFECT_TYPE_CUSTOM;
392 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
394 /* get status if speaker is activated */
395 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 */
444 g_object_get(audio_effect_element, "custom-ext", &custom_ext_effect_level_list, NULL);
446 while (count < MM_AUDIO_EFFECT_CUSTOM_NUM) {
447 if (player->ini.audio_effect_custom_list[count]) {
448 player->audio_effect_info.custom_ext_level[count-1]
449 = custom_ext_effect_level_list[ext_level_index];
450 LOGD("updated custom-ext [%d] = %d", count, player->audio_effect_info.custom_ext_level[count-1]);
463 mm_player_audio_effect_custom_clear_eq_all(MMHandleType hplayer)
465 int result = MM_ERROR_NONE;
466 mm_player_t* player = (mm_player_t*)hplayer;
470 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
472 /* clear EQ custom effect */
473 memset(player->audio_effect_info.custom_eq_level, MM_AUDIO_EFFECT_CUSTOM_LEVEL_INIT, sizeof(int)*MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX);
475 LOGI("All the EQ bands clearing success");
484 mm_player_audio_effect_custom_clear_ext_all(MMHandleType hplayer)
487 int result = MM_ERROR_NONE;
488 mm_player_t* player = (mm_player_t*)hplayer;
492 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
494 /* clear ALL custom effects, except EQ */
495 for (i = 0 ; i < MM_AUDIO_EFFECT_CUSTOM_NUM - 1 ; i++)
496 player->audio_effect_info.custom_ext_level[i] = MM_AUDIO_EFFECT_CUSTOM_LEVEL_INIT;
498 LOGI("All the extension effects clearing success");
507 mm_player_is_supported_preset_effect_type(MMHandleType hplayer, MMAudioEffectPresetType effect)
509 mm_player_t* player = (mm_player_t*)hplayer;
510 int result = MM_ERROR_NONE;
514 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
516 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_PRESET, effect))
517 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
526 mm_player_is_supported_custom_effect_type(MMHandleType hplayer, MMAudioEffectCustomType effect)
528 mm_player_t* player = (mm_player_t*)hplayer;
529 int result = MM_ERROR_NONE;
533 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
535 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, effect))
536 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
544 mm_player_audio_effect_custom_apply(MMHandleType hplayer)
546 mm_player_t* player = (mm_player_t*)hplayer;
547 int result = MM_ERROR_NONE;
551 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
553 if (!player->ini.use_audio_effect_custom) {
554 LOGE("audio effect(custom) is not supported");
556 return MM_ERROR_NOT_SUPPORT_API;
559 result = _mmplayer_audio_effect_custom_apply(player);
568 mm_player_audio_effect_bypass(MMHandleType hplayer)
570 mm_player_t* player = (mm_player_t*)hplayer;
571 int result = MM_ERROR_NONE;
572 GstElement *audio_effect_element = NULL;
576 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
578 if (!player->ini.use_audio_effect_preset && !player->ini.use_audio_effect_custom) {
579 LOGE("audio effect(preset/custom) is not supported");
581 return MM_ERROR_NOT_SUPPORT_API;
583 if (!player->pipeline || !player->pipeline->audiobin || !player->pipeline->audiobin[MMPLAYER_A_FILTER].gst) {
584 LOGW("effect element is not created yet.");
586 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
588 /* order action to audio effect plugin */
589 g_object_set(audio_effect_element, "filter-action", MM_AUDIO_EFFECT_TYPE_NONE, NULL);
590 LOGD("filter-action = %d", MM_AUDIO_EFFECT_TYPE_NONE);
600 _mmplayer_audio_effect_custom_set_level_ext(mm_player_t *player, MMAudioEffectCustomType custom_effect_type, int level)
602 int effect_level_max = 0;
603 int effect_level_min = 0;
604 int count = 1; /* start from 1, because of excepting eq index */
605 int ext_level_index = 1; /* start from 1, because of excepting eq index */
606 int result = MM_ERROR_NONE;
610 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
612 /* check if EQ is supported */
613 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, custom_effect_type)) {
615 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
618 while (count < MM_AUDIO_EFFECT_CUSTOM_NUM) {
619 if (player->ini.audio_effect_custom_list[count]) {
620 if (count == custom_effect_type) {
621 effect_level_min = player->ini.audio_effect_custom_min_level_list[ext_level_index];
622 effect_level_max = player->ini.audio_effect_custom_max_level_list[ext_level_index];
623 LOGI("level min value(%d), level max value(%d)", effect_level_min, effect_level_max);
627 if (ext_level_index == player->ini.audio_effect_custom_ext_num + 1) {
628 LOGE("could not find min, max value. maybe effect information in ini file is not proper for audio effect plugin");
635 if (level < effect_level_min || level > effect_level_max) {
636 LOGE("out of range, level(%d)", level);
637 result = MM_ERROR_INVALID_ARGUMENT;
639 player->audio_effect_info.custom_ext_level[custom_effect_type-1] = level;
640 LOGI("set ext[%d] = %d", custom_effect_type-1, level);
650 _mmplayer_audio_effect_custom_set_level_eq(mm_player_t *player, int index, int level)
652 gint eq_level_max = 0;
653 gint eq_level_min = 0;
654 int result = MM_ERROR_NONE;
658 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
660 /* check if EQ is supported */
661 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
663 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
666 if (index < 0 || index > player->ini.audio_effect_custom_eq_band_num - 1) {
667 LOGE("out of range, index(%d)", index);
668 result = MM_ERROR_INVALID_ARGUMENT;
670 eq_level_min = player->ini.audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
671 eq_level_max = player->ini.audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
672 LOGI("EQ level min value(%d), EQ level max value(%d)", eq_level_min, eq_level_max);
674 if (level < eq_level_min || level > eq_level_max) {
675 LOGE("out of range, EQ level(%d)", level);
676 result = MM_ERROR_INVALID_ARGUMENT;
678 player->audio_effect_info.custom_eq_level[index] = level;
679 LOGI("set EQ[%d] = %d", index, level);
689 /* NOTE : parameter eq_index is only used for _set_eq_level() */
691 mm_player_audio_effect_custom_set_level(MMHandleType hplayer, MMAudioEffectCustomType effect_custom_type, int eq_index, int level)
693 mm_player_t* player = (mm_player_t*)hplayer;
694 int result = MM_ERROR_NONE;
698 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
700 /* check if this effect type is supported */
701 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, effect_custom_type)) {
702 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
704 if (effect_custom_type == MM_AUDIO_EFFECT_CUSTOM_EQ) {
705 result = _mmplayer_audio_effect_custom_set_level_eq(player, eq_index, level);
706 } else if (effect_custom_type > MM_AUDIO_EFFECT_CUSTOM_EQ && effect_custom_type < MM_AUDIO_EFFECT_CUSTOM_NUM) {
707 result = _mmplayer_audio_effect_custom_set_level_ext(player, effect_custom_type, level);
709 LOGE("out of range, effect type(%d)", effect_custom_type);
710 result = MM_ERROR_INVALID_ARGUMENT;
721 mm_player_audio_effect_custom_get_eq_bands_number(MMHandleType hplayer, int *bands)
723 mm_player_t* player = (mm_player_t*)hplayer;
724 int result = MM_ERROR_NONE;
728 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
730 /* check if EQ is supported */
731 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
733 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
736 *bands = player->ini.audio_effect_custom_eq_band_num;
737 LOGD("number of custom EQ band = %d", *bands);
746 mm_player_audio_effect_custom_get_eq_bands_width(MMHandleType hplayer, int band_idx, int *width)
748 mm_player_t* player = (mm_player_t*)hplayer;
749 int result = MM_ERROR_NONE;
750 unsigned int eq_num = 0;
754 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
756 /* check if EQ is supported */
757 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
759 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
762 eq_num = player->ini.audio_effect_custom_eq_band_num;
763 if (band_idx < 0 || band_idx > eq_num-1) {
764 LOGE("out of range, invalid band_idx(%d)", band_idx);
765 result = MM_ERROR_INVALID_ARGUMENT;
767 /* set the width of EQ band */
768 *width = player->ini.audio_effect_custom_eq_band_width[band_idx];
769 LOGD("width of band_idx(%d) = %dHz", band_idx, *width);
779 mm_player_audio_effect_custom_get_eq_bands_freq(MMHandleType hplayer, int band_idx, int *freq)
781 mm_player_t* player = (mm_player_t*)hplayer;
782 int result = MM_ERROR_NONE;
783 unsigned int eq_num = 0;
787 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
789 /* check if EQ is supported */
790 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
792 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
795 eq_num = player->ini.audio_effect_custom_eq_band_num;
796 if (band_idx < 0 || band_idx > eq_num-1) {
797 LOGE("out of range, invalid band_idx(%d)", band_idx);
798 result = MM_ERROR_INVALID_ARGUMENT;
800 /* set the frequency of EQ band */
801 *freq = player->ini.audio_effect_custom_eq_band_freq[band_idx];
802 LOGD("frequency of band_idx(%d) = %dHz", band_idx, *freq);
812 mm_player_audio_effect_custom_get_level(MMHandleType hplayer, MMAudioEffectCustomType type, int eq_index, int *level)
814 mm_player_t* player = (mm_player_t*)hplayer;
815 int result = MM_ERROR_NONE;
819 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
820 MMPLAYER_RETURN_VAL_IF_FAIL(level, MM_ERROR_PLAYER_NOT_INITIALIZED);
822 /* check if this effect type is supported */
823 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type)) {
825 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
828 if (type == MM_AUDIO_EFFECT_CUSTOM_EQ) {
829 if (eq_index < 0 || eq_index > player->ini.audio_effect_custom_eq_band_num - 1) {
830 LOGE("out of range, EQ index(%d)", eq_index);
831 result = MM_ERROR_INVALID_ARGUMENT;
833 *level = player->audio_effect_info.custom_eq_level[eq_index];
834 LOGD("EQ index = %d, level = %d", eq_index, *level);
836 } else if (type > MM_AUDIO_EFFECT_CUSTOM_EQ && type < MM_AUDIO_EFFECT_CUSTOM_NUM) {
837 *level = player->audio_effect_info.custom_ext_level[type-1];
838 LOGD("extension effect index = %d, level = %d", type, *level);
840 LOGE("out of range, type(%d)", type);
841 result = MM_ERROR_INVALID_ARGUMENT;
851 mm_player_audio_effect_custom_get_level_range(MMHandleType hplayer, MMAudioEffectCustomType type, int *min, int *max)
853 mm_player_t* player = (mm_player_t*)hplayer;
854 int result = MM_ERROR_NONE;
855 int count = 1; /* start from 1, because of excepting eq index */
856 int ext_level_index = 1; /* start from 1, because of excepting eq index */
860 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
861 MMPLAYER_RETURN_VAL_IF_FAIL(min, MM_ERROR_PLAYER_NOT_INITIALIZED);
862 MMPLAYER_RETURN_VAL_IF_FAIL(max, MM_ERROR_PLAYER_NOT_INITIALIZED);
864 /* check if this effect type is supported */
865 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type)) {
867 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
870 if (type == MM_AUDIO_EFFECT_CUSTOM_EQ) {
871 *min = player->ini.audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
872 *max = player->ini.audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
873 LOGD("EQ min level = %d, max level = %d", *min, *max);
875 while (count < MM_AUDIO_EFFECT_CUSTOM_NUM) {
876 if (player->ini.audio_effect_custom_list[count]) {
878 *min = player->ini.audio_effect_custom_min_level_list[ext_level_index];
879 *max = player->ini.audio_effect_custom_max_level_list[ext_level_index];
880 LOGI("Extension effect(%d) min level = %d, max level = %d", count, *min, *max);
884 if (ext_level_index == player->ini.audio_effect_custom_ext_num + 1) {
885 LOGE("could not find min, max value. maybe effect information in ini file is not proper for audio effect plugin");
900 mm_player_audio_effect_custom_set_level_eq_from_list(MMHandleType hplayer, int *level_list, int size)
902 mm_player_t *player = (mm_player_t*)hplayer;
904 gint eq_level_min = 0;
905 gint eq_level_max = 0;
906 int result = MM_ERROR_NONE;
910 MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
912 /* check if EQ is supported */
913 if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
915 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
918 if (size != player->ini.audio_effect_custom_eq_band_num) {
919 LOGE("input size variable(%d) does not match with number of eq band(%d)", size, player->ini.audio_effect_custom_eq_band_num);
920 result = MM_ERROR_INVALID_ARGUMENT;
922 eq_level_min = player->ini.audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
923 eq_level_max = player->ini.audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
925 for (i = 0 ; i < size ; i++) {
926 if (level_list[i] < eq_level_min || level_list[i] > eq_level_max) {
927 LOGE("out of range, level[%d]=%d", i, level_list[i]);
928 result = MM_ERROR_INVALID_ARGUMENT;
931 player->audio_effect_info.custom_eq_level[i] = level_list[i];