[0.6.62] fix mem leak
[platform/core/multimedia/libmm-player.git] / src / mm_player_audioeffect.c
1 /*
2  * libmm-player
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>,YeJin Cho <cho.yejin@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21 #include <dlog.h>
22 #include <mm_error.h>
23
24 #include "mm_player_utils.h"
25 #include "mm_player_audioeffect.h"
26 #include "mm_player_ini.h"
27 #include "mm_player_priv.h"
28 #include <mm_sound.h>
29
30
31 int
32 mm_player_get_foreach_present_supported_effect_type(MMHandleType hplayer, MMAudioEffectType effect_type, mmplayer_supported_audio_effect_cb foreach_cb, void *user_data)
33 {
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;
40         int i = 0;
41
42         MMPLAYER_FENTER();
43
44         MMPLAYER_RETURN_VAL_IF_FAIL(hplayer, MM_ERROR_PLAYER_NOT_INITIALIZED);
45
46         player = MM_PLAYER_CAST(hplayer);
47
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);
53                 MMPLAYER_FLEAVE();
54                 return result;
55         }
56
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);
61                 goto EXIT;
62         }
63
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);
68                 goto EXIT;
69         }
70
71         if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET) {
72                 /* 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])
77                                         continue;
78
79                                 if (!foreach_cb(effect_type, i, user_data)) {
80                                         LOGE("foreach callback returned error");
81                                         result = MM_ERROR_PLAYER_INTERNAL;
82                                         goto EXIT;
83                                 }
84                         }
85                 }
86         } else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM) {
87                 /* 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]) {
92                                         continue;
93                                 }
94                                 if (!foreach_cb(effect_type, i, user_data)) {
95                                         LOGE("foreach callback returned error");
96                                         result = MM_ERROR_PLAYER_INTERNAL;
97                                         goto EXIT;
98                                 }
99                         }
100                 }
101         } else {
102                 LOGE("invalid effect type(%d)", effect_type);
103                 result = MM_ERROR_INVALID_ARGUMENT;
104         }
105
106 EXIT:
107         if (device_list)
108                 mm_sound_free_device_list(device_list);
109
110         MMPLAYER_FLEAVE();
111         return result;
112 }
113
114
115 int
116 __mmplayer_set_harmony_effect(mm_player_t *player, GstElement *audio_effect_element)
117 {
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;
122
123         MMPLAYER_FENTER();
124
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);
127
128         /* Custom EQ */
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);
133         } else {
134                 LOGW("no custom EQ");
135         }
136
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;
146                         } else {
147                                 memset(ext_effect_level_list, 0, player->ini.audio_effect_custom_ext_num);
148
149                                 /* associate it to player handle */
150                                 player->audio_effect_info.custom_ext_level_for_plugin = ext_effect_level_list;
151                         }
152                 }
153
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];
157                                 ext_level_index++;
158                                 if (ext_level_index == player->ini.audio_effect_custom_ext_num)
159                                         break;
160                         }
161                         count++;
162                 }
163
164                 /* set custom-extension effects level list */
165                 g_object_set(audio_effect_element, "custom-ext", ext_effect_level_list, NULL);
166         } else
167                 LOGW("no custom extension effect");
168
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);
172
173         MMPLAYER_FLEAVE();
174
175         return result;
176 }
177
178
179 gboolean
180 __mmplayer_is_earphone_only_effect_type(mm_player_t *player, MMAudioEffectType effect_type, int effect)
181 {
182         gboolean result = FALSE;
183         int i = 0;
184
185         MMPLAYER_FENTER();
186
187         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
188
189         if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET) {
190                 /* preset */
191                 if (player->ini.audio_effect_preset_earphone_only_list[effect]) {
192                         LOGI("this preset effect(%d) is only available with earphone", effect);
193                         result = TRUE;
194                 }
195         } else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM) {
196                 /* 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);
203                                         result = TRUE;
204                                 }
205                         }
206                 }
207         } else
208                 LOGE("invalid effect type(%d)", effect_type);
209
210         MMPLAYER_FLEAVE();
211
212         return result;
213 }
214
215 int
216 __mmplayer_audio_set_output_type(mm_player_t *player, MMAudioEffectType effect_type, int effect)
217 {
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;
223         int output_type = 0;
224         int result = MM_ERROR_NONE;
225
226         MMPLAYER_FENTER();
227
228         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
229
230         audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
231
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);
236                 MMPLAYER_FLEAVE();
237                 return result;
238         }
239
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);
244                 goto EXIT;
245         }
246
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);
251                 goto EXIT;
252         }
253
254         /* SPEAKER case */
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;
260                                 goto EXIT;
261                         }
262                 }
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;
272         } else {
273                 /* Other case, include WIRED_ACCESSORY */
274                 output_type = MM_AUDIO_EFFECT_OUTPUT_EAR;
275         }
276         LOGW("output_type = %d (0:spk,1:ear,2:others)", output_type);
277
278         /* set filter output mode */
279         g_object_set(audio_effect_element, "filter-output-mode", output_type, NULL);
280
281 EXIT:
282         if (device_list)
283                 mm_sound_free_device_list(device_list);
284
285         MMPLAYER_FLEAVE();
286         return result;
287 }
288
289 gboolean
290 _mmplayer_is_supported_effect_type(mm_player_t* player, MMAudioEffectType effect_type, int effect)
291 {
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;
298
299         MMPLAYER_FENTER();
300
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) {
305                 MMPLAYER_FLEAVE();
306                 LOGE("mm_sound_get_device_list() failed [%x]!!", ret);
307                 return FALSE;
308         }
309
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);
314                 goto EXIT;
315         }
316
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);
321                 goto EXIT;
322         }
323
324         /* preset */
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);
328                         result = FALSE;
329                 } else {
330                         if (!player->ini.audio_effect_preset_list[effect]) {
331                                 LOGE("this effect(%d) is not supported", effect);
332                                 result = FALSE;
333                         } else {
334                                 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
335                                                 player->ini.audio_effect_preset_earphone_only_list[effect]) {
336                                         result = FALSE;
337                                 }
338                         }
339                 }
340         } else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM) {
341                 /* custom */
342                 if (effect < MM_AUDIO_EFFECT_CUSTOM_EQ || effect >= MM_AUDIO_EFFECT_CUSTOM_NUM) {
343                         LOGE("out of range, custom effect(%d)", effect);
344                         result = FALSE;
345                 } else {
346                         if (!player->ini.audio_effect_custom_list[effect]) {
347                                 LOGE("this custom effect(%d) is not supported", effect);
348                                 result = FALSE;
349                         } else {
350                                 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
351                                                 player->ini.audio_effect_custom_earphone_only_list[effect]) {
352                                         result = FALSE;
353                                 }
354                         }
355                 }
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");
359                         result = FALSE;
360                 }
361         } else {
362                 LOGE("invalid effect type(%d)", effect_type);
363                 result = FALSE;
364         }
365
366 EXIT:
367         if (device_list)
368                 mm_sound_free_device_list(device_list);
369
370         MMPLAYER_FLEAVE();
371         return result;
372 }
373
374 int
375 _mmplayer_audio_effect_custom_apply(mm_player_t *player)
376 {
377         GstElement *audio_effect_element = NULL;
378         int result = MM_ERROR_NONE;
379
380         MMPLAYER_FENTER();
381
382         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
383
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;
388
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;
391         } else {
392                 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
393
394                 /* get status if speaker is activated */
395                 result = __mmplayer_audio_set_output_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, 0);
396
397                 if (result != MM_ERROR_NONE) {
398                         LOGE("failed to set output mode");
399                         MMPLAYER_FLEAVE();
400                         return result;
401                 }
402
403                 result = __mmplayer_set_harmony_effect(player, audio_effect_element);
404                 if (result) {
405                         LOGE("_set_harmony_effect() failed(%x)", result);
406                         MMPLAYER_FLEAVE();
407                         return result;
408                 }
409         }
410         player->set_mode.rich_audio = TRUE;
411
412         MMPLAYER_FLEAVE();
413
414         return result;
415 }
416
417 int
418 _mmplayer_audio_effect_custom_update_level(mm_player_t *player)
419 {
420         GstElement *audio_effect_element = NULL;
421         int result = MM_ERROR_NONE;
422         int ext_level_index = 0;
423         int count = 1;
424         int i = 0;
425         gint *custom_eq = NULL;
426         gint *custom_ext_effect_level_list = NULL;
427
428         MMPLAYER_FENTER();
429
430         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
431
432         audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
433
434         /* get custom eq effect */
435         g_object_get(audio_effect_element, "custom-eq", &custom_eq, NULL);
436
437         memcpy(player->audio_effect_info.custom_eq_level, custom_eq, sizeof(gint) * player->ini.audio_effect_custom_eq_band_num);
438
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]);
441
442         /* get custom ext effect */
443
444         g_object_get(audio_effect_element, "custom-ext", &custom_ext_effect_level_list, NULL);
445
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]);
451                         ext_level_index++;
452                 }
453                 count++;
454         }
455
456
457         MMPLAYER_FLEAVE();
458         return result;
459 }
460
461
462 int
463 mm_player_audio_effect_custom_clear_eq_all(MMHandleType hplayer)
464 {
465         int result = MM_ERROR_NONE;
466         mm_player_t* player = (mm_player_t*)hplayer;
467
468         MMPLAYER_FENTER();
469
470         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
471
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);
474
475         LOGI("All the EQ bands clearing success");
476
477         MMPLAYER_FLEAVE();
478
479         return result;
480 }
481
482
483 int
484 mm_player_audio_effect_custom_clear_ext_all(MMHandleType hplayer)
485 {
486         int i;
487         int result = MM_ERROR_NONE;
488         mm_player_t* player = (mm_player_t*)hplayer;
489
490         MMPLAYER_FENTER();
491
492         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
493
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;
497
498         LOGI("All the extension effects clearing success");
499
500         MMPLAYER_FLEAVE();
501
502         return result;
503 }
504
505
506 int
507 mm_player_is_supported_preset_effect_type(MMHandleType hplayer, MMAudioEffectPresetType effect)
508 {
509         mm_player_t* player = (mm_player_t*)hplayer;
510         int result = MM_ERROR_NONE;
511
512         MMPLAYER_FENTER();
513
514         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
515
516         if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_PRESET, effect))
517                 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
518
519         MMPLAYER_FLEAVE();
520
521         return result;
522 }
523
524
525 int
526 mm_player_is_supported_custom_effect_type(MMHandleType hplayer, MMAudioEffectCustomType effect)
527 {
528         mm_player_t* player = (mm_player_t*)hplayer;
529         int result = MM_ERROR_NONE;
530
531         MMPLAYER_FENTER();
532
533         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
534
535         if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, effect))
536                 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
537
538         MMPLAYER_FLEAVE();
539
540         return result;
541 }
542
543 int
544 mm_player_audio_effect_custom_apply(MMHandleType hplayer)
545 {
546         mm_player_t* player = (mm_player_t*)hplayer;
547         int result = MM_ERROR_NONE;
548
549         MMPLAYER_FENTER();
550
551         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
552
553         if (!player->ini.use_audio_effect_custom) {
554                 LOGE("audio effect(custom) is not supported");
555                 MMPLAYER_FLEAVE();
556                 return MM_ERROR_NOT_SUPPORT_API;
557         }
558
559         result = _mmplayer_audio_effect_custom_apply(player);
560
561         MMPLAYER_FLEAVE();
562
563         return result;
564 }
565
566
567 int
568 mm_player_audio_effect_bypass(MMHandleType hplayer)
569 {
570         mm_player_t* player = (mm_player_t*)hplayer;
571         int result = MM_ERROR_NONE;
572         GstElement *audio_effect_element = NULL;
573
574         MMPLAYER_FENTER();
575
576         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
577
578         if (!player->ini.use_audio_effect_preset && !player->ini.use_audio_effect_custom) {
579                 LOGE("audio effect(preset/custom) is not supported");
580                 MMPLAYER_FLEAVE();
581                 return MM_ERROR_NOT_SUPPORT_API;
582         }
583         if (!player->pipeline || !player->pipeline->audiobin || !player->pipeline->audiobin[MMPLAYER_A_FILTER].gst) {
584                 LOGW("effect element is not created yet.");
585         } else {
586                 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
587
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);
591         }
592
593         MMPLAYER_FLEAVE();
594
595         return result;
596 }
597
598
599 int
600 _mmplayer_audio_effect_custom_set_level_ext(mm_player_t *player, MMAudioEffectCustomType custom_effect_type, int level)
601 {
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;
607
608         MMPLAYER_FENTER();
609
610         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
611
612         /* check if EQ is supported */
613         if (!_mmplayer_is_supported_effect_type(player,  MM_AUDIO_EFFECT_TYPE_CUSTOM, custom_effect_type)) {
614                 MMPLAYER_FLEAVE();
615                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
616         }
617
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);
624                                 break;
625                         }
626                         ext_level_index++;
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");
629                                 break;
630                         }
631                 }
632                 count++;
633         }
634
635         if (level < effect_level_min || level > effect_level_max) {
636                 LOGE("out of range, level(%d)", level);
637                 result = MM_ERROR_INVALID_ARGUMENT;
638         } else {
639                 player->audio_effect_info.custom_ext_level[custom_effect_type-1] = level;
640                 LOGI("set ext[%d] = %d", custom_effect_type-1, level);
641         }
642
643         MMPLAYER_FLEAVE();
644
645         return result;
646 }
647
648
649 int
650 _mmplayer_audio_effect_custom_set_level_eq(mm_player_t *player, int index, int level)
651 {
652         gint eq_level_max = 0;
653         gint eq_level_min = 0;
654         int result = MM_ERROR_NONE;
655
656         MMPLAYER_FENTER();
657
658         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
659
660         /* check if EQ is supported */
661         if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
662                 MMPLAYER_FLEAVE();
663                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
664         }
665
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;
669         } else {
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);
673
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;
677                 } else {
678                         player->audio_effect_info.custom_eq_level[index] = level;
679                         LOGI("set EQ[%d] = %d", index, level);
680                 }
681         }
682
683         MMPLAYER_FLEAVE();
684
685         return result;
686 }
687
688
689 /* NOTE : parameter eq_index is only used for _set_eq_level() */
690 int
691 mm_player_audio_effect_custom_set_level(MMHandleType hplayer, MMAudioEffectCustomType effect_custom_type, int eq_index, int level)
692 {
693         mm_player_t* player = (mm_player_t*)hplayer;
694         int result = MM_ERROR_NONE;
695
696         MMPLAYER_FENTER();
697
698         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
699
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;
703         } else {
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);
708                 } else {
709                         LOGE("out of range, effect type(%d)", effect_custom_type);
710                         result = MM_ERROR_INVALID_ARGUMENT;
711                 }
712         }
713
714         MMPLAYER_FLEAVE();
715
716         return result;
717 }
718
719
720 int
721 mm_player_audio_effect_custom_get_eq_bands_number(MMHandleType hplayer, int *bands)
722 {
723         mm_player_t* player = (mm_player_t*)hplayer;
724         int result = MM_ERROR_NONE;
725
726         MMPLAYER_FENTER();
727
728         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
729
730         /* check if EQ is supported */
731         if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
732                 MMPLAYER_FLEAVE();
733                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
734         }
735
736         *bands = player->ini.audio_effect_custom_eq_band_num;
737         LOGD("number of custom EQ band = %d", *bands);
738
739         MMPLAYER_FLEAVE();
740
741         return result;
742 }
743
744
745 int
746 mm_player_audio_effect_custom_get_eq_bands_width(MMHandleType hplayer, int band_idx, int *width)
747 {
748         mm_player_t* player = (mm_player_t*)hplayer;
749         int result = MM_ERROR_NONE;
750         unsigned int eq_num = 0;
751
752         MMPLAYER_FENTER();
753
754         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
755
756         /* check if EQ is supported */
757         if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
758                 MMPLAYER_FLEAVE();
759                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
760         }
761
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;
766         } else {
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);
770         }
771
772         MMPLAYER_FLEAVE();
773
774         return result;
775 }
776
777
778 int
779 mm_player_audio_effect_custom_get_eq_bands_freq(MMHandleType hplayer, int band_idx, int *freq)
780 {
781         mm_player_t* player = (mm_player_t*)hplayer;
782         int result = MM_ERROR_NONE;
783         unsigned int eq_num = 0;
784
785         MMPLAYER_FENTER();
786
787         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
788
789         /* check if EQ is supported */
790         if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
791                 MMPLAYER_FLEAVE();
792                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
793         }
794
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;
799         } else {
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);
803         }
804
805         MMPLAYER_FLEAVE();
806
807         return result;
808 }
809
810
811 int
812 mm_player_audio_effect_custom_get_level(MMHandleType hplayer, MMAudioEffectCustomType type, int eq_index, int *level)
813 {
814         mm_player_t* player = (mm_player_t*)hplayer;
815         int result = MM_ERROR_NONE;
816
817         MMPLAYER_FENTER();
818
819         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
820         MMPLAYER_RETURN_VAL_IF_FAIL(level, MM_ERROR_PLAYER_NOT_INITIALIZED);
821
822         /* check if this effect type is supported */
823         if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type)) {
824                 MMPLAYER_FLEAVE();
825                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
826         }
827
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;
832                 } else {
833                         *level = player->audio_effect_info.custom_eq_level[eq_index];
834                         LOGD("EQ index = %d, level = %d", eq_index, *level);
835                 }
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);
839         } else {
840                 LOGE("out of range, type(%d)", type);
841                 result = MM_ERROR_INVALID_ARGUMENT;
842         }
843
844         MMPLAYER_FLEAVE();
845
846         return result;
847 }
848
849
850 int
851 mm_player_audio_effect_custom_get_level_range(MMHandleType hplayer, MMAudioEffectCustomType type, int *min, int *max)
852 {
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 */
857
858         MMPLAYER_FENTER();
859
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);
863
864         /* check if this effect type is supported */
865         if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type)) {
866                 MMPLAYER_FLEAVE();
867                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
868         }
869
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);
874         } else {
875                 while (count < MM_AUDIO_EFFECT_CUSTOM_NUM) {
876                         if (player->ini.audio_effect_custom_list[count]) {
877                                 if (count == type) {
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);
881                                         break;
882                                 }
883                                 ext_level_index++;
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");
886                                         break;
887                                 }
888                         }
889                         count++;
890                 }
891         }
892
893         MMPLAYER_FLEAVE();
894
895         return result;
896 }
897
898
899 int
900 mm_player_audio_effect_custom_set_level_eq_from_list(MMHandleType hplayer, int *level_list, int size)
901 {
902         mm_player_t *player = (mm_player_t*)hplayer;
903         gint i = 0;
904         gint eq_level_min = 0;
905         gint eq_level_max = 0;
906         int result = MM_ERROR_NONE;
907
908         MMPLAYER_FENTER();
909
910         MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
911
912         /* check if EQ is supported */
913         if (!_mmplayer_is_supported_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ)) {
914                 MMPLAYER_FLEAVE();
915                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
916         }
917
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;
921         } else {
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];
924
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;
929                                 break;
930                         }
931                         player->audio_effect_info.custom_eq_level[i] = level_list[i];
932                 }
933         }
934         MMPLAYER_FLEAVE();
935
936         return result;
937 }