increase version up
[framework/multimedia/libmm-player.git] / src / mm_player_sndeffect.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 <mm_error.h>
22
23 #include "mm_player_sndeffect.h"
24 #include "mm_player_ini.h"
25 #include "mm_player_priv.h"
26 #include <mm_sound.h>
27
28
29 int
30 mm_player_get_foreach_present_supported_filter_type(MMHandleType player, MMAudioFilterType filter_type, mmplayer_supported_sound_filter_cb foreach_cb, void *user_data)
31 {
32         debug_fenter();
33         int result = MM_ERROR_NONE;
34         gboolean is_earphone = NULL;
35         int i = 0;
36
37         return_val_if_fail ( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
38
39         /* get status if earphone is activated */
40         result = mm_sound_is_route_available(MM_SOUND_ROUTE_OUT_WIRED_ACCESSORY, &is_earphone);
41         if ( result ) {
42                 debug_error("mm_sound_is_route_available() failed [%x]!!\n", result);
43                 return result;
44         }
45
46         /* preset */
47         if (filter_type == MM_AUDIO_FILTER_TYPE_PRESET)
48         {
49                 for ( i = 0; i < MM_AUDIO_FILTER_PRESET_NUM; i++ )
50                 {
51                         if (is_earphone) {
52                                 if (PLAYER_INI()->audio_filter_preset_list[i])
53                                 {
54                                         if (!foreach_cb(filter_type, i, user_data))
55                                         {
56                                                 goto CALLBACK_ERROR;
57                                         }
58                                 }
59                         }
60                         else
61                         {
62                                 if (PLAYER_INI()->audio_filter_preset_list[i] && !PLAYER_INI()->audio_filter_preset_earphone_only_list[i])
63                                 {
64                                         if (!foreach_cb(filter_type, i, user_data))
65                                         {
66                                                 goto CALLBACK_ERROR;
67                                         }
68                                 }
69
70                         }
71                 }
72         }
73         /* custom */
74         else if (filter_type == MM_AUDIO_FILTER_TYPE_CUSTOM)
75         {
76                 for ( i = 0; i < MM_AUDIO_FILTER_CUSTOM_NUM; i++ )
77                 {
78                         if (is_earphone)
79                         {
80                                 if (PLAYER_INI()->audio_filter_custom_list[i])
81                                 {
82                                         if (!foreach_cb(filter_type, i, user_data))
83                                         {
84                                                 goto CALLBACK_ERROR;
85                                         }
86                                 }
87                         }
88                         else
89                         {
90                                 if (PLAYER_INI()->audio_filter_custom_list[i] && !PLAYER_INI()->audio_filter_custom_earphone_only_list[i])
91                                 {
92                                         if (!foreach_cb(filter_type,i, user_data))
93                                         {
94                                                 goto CALLBACK_ERROR;
95                                         }
96                                 }
97                         }
98                 }
99         }
100         else
101         {
102                 debug_error("invalid filter type(%d)\n", filter_type);
103                 result = MM_ERROR_INVALID_ARGUMENT;
104         }
105
106         return result;
107
108 CALLBACK_ERROR:
109         debug_error("foreach cb returned error\n");
110         return MM_ERROR_PLAYER_INTERNAL;
111 }
112
113
114 int
115 __mmplayer_set_harmony_filter(mm_player_t *player, GstElement *filter_element)
116 {
117         debug_fenter();
118         gint *ext_filter_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         return_val_if_fail ( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
123         return_val_if_fail ( filter_element, MM_ERROR_INVALID_ARGUMENT );
124
125         /* Custom EQ */
126         if( PLAYER_INI()->audio_filter_custom_eq_num )
127         {
128                 debug_log("pass custom EQ level list to sound effect plugin\n");
129                 /* set custom-equalizer level list */
130                 g_object_set(filter_element, "custom-eq", player->audio_filter_info.custom_eq_level, NULL);
131         }
132         else
133         {
134                 debug_warning("no custom EQ\n");
135         }
136
137         /* Custom Extension filters */
138         if( PLAYER_INI()->audio_filter_custom_ext_num )
139         {
140                 debug_log("pass custom extension level list to sound effect plugin\n");
141                 ext_filter_level_list = player->audio_filter_info.custom_ext_level_for_plugin;
142                 if (!ext_filter_level_list) {
143                         ext_filter_level_list = (gint*) malloc (sizeof(gint)*PLAYER_INI()->audio_filter_custom_ext_num);
144                         if (!ext_filter_level_list)
145                         {
146                                 debug_error("memory allocation for extension filter list failed\n");
147                                 return MM_ERROR_OUT_OF_MEMORY;
148                         }
149                         else
150                         {
151                                 memset (ext_filter_level_list, 0, PLAYER_INI()->audio_filter_custom_ext_num);
152                         }
153                 }
154
155                 while ( count < MM_AUDIO_FILTER_CUSTOM_NUM )
156                 {
157                         if ( PLAYER_INI()->audio_filter_custom_list[count] )
158                         {
159                                 ext_filter_level_list[ext_level_index] = player->audio_filter_info.custom_ext_level[count-1];
160                                 ext_level_index++;
161                                 if (ext_level_index == PLAYER_INI()->audio_filter_custom_ext_num)
162                                 {
163                                         break;
164                                 }
165                         }
166                         count++;
167                 }
168
169                 /* set custom-extension filters level list */
170                 g_object_set(filter_element, "custom-ext", ext_filter_level_list, NULL);
171         }
172         else
173         {
174                 debug_warning("no custom extension fliter\n");
175         }
176
177         /* order action to sound effect plugin */
178         g_object_set(filter_element, "filter-action", MM_AUDIO_FILTER_TYPE_CUSTOM, NULL);
179         debug_log("filter-action = %d\n", MM_AUDIO_FILTER_TYPE_CUSTOM);
180
181         debug_fleave();
182
183         return result;
184 }
185
186
187 gboolean
188 __mmplayer_is_earphone_only_filter_type(mm_player_t *player, MMAudioFilterType filter_type, int filter)
189 {
190         gboolean result = FALSE;
191         int i = 0;
192         debug_fenter();
193
194         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
195
196         /* preset */
197         if (filter_type == MM_AUDIO_FILTER_TYPE_PRESET)
198         {
199                 if (PLAYER_INI()->audio_filter_preset_earphone_only_list[filter])
200                 {
201                         debug_msg("this preset filter(%d) is only available with earphone\n", filter);
202                         result = TRUE;
203                 }
204         }
205         /* custom */
206         else if (filter_type == MM_AUDIO_FILTER_TYPE_CUSTOM)
207         {
208                 for (i = 1; i < MM_AUDIO_FILTER_CUSTOM_NUM; i++) /* it starts from 1(except testing for EQ) */
209                 {
210                         if (PLAYER_INI()->audio_filter_custom_earphone_only_list[i])
211                         {
212                                 /* check if the earphone only custom filter was set */
213                                 if (player->audio_filter_info.custom_ext_level[i-1])
214                                 {
215                                         debug_msg("this custom filter(%d) is only available with earphone\n", i);
216                                         result = TRUE;
217                                 }
218                         }
219                 }
220         }
221         else
222         {
223                 debug_error("invalid filter type(%d)\n", filter_type);
224         }
225
226         return result;
227 }
228
229
230 gboolean
231 _mmplayer_is_supported_filter_type(MMAudioFilterType filter_type, int filter)
232 {
233         gboolean result = TRUE;
234
235         debug_fenter();
236
237         /* preset */
238         if (filter_type == MM_AUDIO_FILTER_TYPE_PRESET)
239         {
240                 if ( filter < MM_AUDIO_FILTER_PRESET_AUTO || filter >= MM_AUDIO_FILTER_PRESET_NUM )
241                 {
242                         debug_error("out of range, preset filter(%d)\n", filter);
243                         result = FALSE;
244                 }
245                 if (!PLAYER_INI()->audio_filter_preset_list[filter])
246                 {
247                         debug_error("this filter(%d) is not supported\n", filter);
248                         result = FALSE;
249                 }
250         }
251         /* custom */
252         else if (filter_type == MM_AUDIO_FILTER_TYPE_CUSTOM)
253         {
254                 if ( filter < MM_AUDIO_FILTER_CUSTOM_EQ || filter >= MM_AUDIO_FILTER_CUSTOM_NUM )
255                 {
256                         debug_error("out of range, custom filter(%d)\n", filter);
257                         result = FALSE;
258                 }
259                 if (!PLAYER_INI()->audio_filter_custom_list[filter])
260                 {
261                         debug_error("this custom filter(%d) is not supported\n", filter);
262                         result = FALSE;
263                 }
264         }
265         else
266         {
267                 debug_error("invalid filter type(%d)\n", filter_type);
268                 result = FALSE;
269         }
270
271         return result;
272 }
273
274
275 int
276 _mmplayer_sound_filter_preset_apply(mm_player_t *player, MMAudioFilterPresetType filter_type)
277 {
278         GstElement *filter_element = NULL;
279         int result = MM_ERROR_NONE;
280         int output_type = 0;
281         bool is_earphone = FALSE;
282         debug_fenter();
283
284         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
285
286         /* Music Player can set sound effect value before Audiobin is created. */
287         if ( !player->pipeline || !player->pipeline->audiobin )
288         {
289                 debug_warning("filter element is not created yet.\n");
290
291                 player->bypass_sound_effect = FALSE;
292
293                 /* store sound effect setting in order to apply it when audio filter is created */
294                 player->audio_filter_info.filter_type = MM_AUDIO_FILTER_TYPE_PRESET;
295                 player->audio_filter_info.preset = filter_type;
296         }
297         else
298         {
299                 return_val_if_fail( player->pipeline->audiobin, MM_ERROR_PLAYER_NOT_INITIALIZED );
300
301                 filter_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
302
303                 /* get status if earphone is activated */
304                 result = mm_sound_is_route_available(MM_SOUND_ROUTE_OUT_WIRED_ACCESSORY, &is_earphone);
305                 if ( result ) {
306                         debug_error("mm_sound_is_route_available() failed [%x]!!\n", result);
307                         return result;
308                 }
309
310                 if (is_earphone)
311                 {
312                         output_type = MM_AUDIO_FILTER_OUTPUT_EAR;
313                 }
314                 else
315                 {
316                         output_type = MM_AUDIO_FILTER_OUTPUT_SPK;
317                         if (__mmplayer_is_earphone_only_filter_type(player, MM_AUDIO_FILTER_TYPE_PRESET, filter_type))
318                         {
319                                 debug_error("earphone is not equipped, this filter will not be applied\n");
320                                 return MM_ERROR_PLAYER_SOUND_EFFECT_INVALID_STATUS;
321                         }
322                 }
323
324                 /* set filter output mode as SPEAKER or EARPHONE */
325                 g_object_set(filter_element, "filter-output-mode", output_type, NULL);
326                 debug_log("filter-output-mode = %d (0:spk,1:ear)\n", output_type);
327
328                 if (filter_type == MM_AUDIO_FILTER_PRESET_AUTO) {
329                         /* TODO: Add codes about auto selecting preset mode according to ID3 tag */
330                         /* set filter preset mode */
331                         g_object_set(filter_element, "preset-mode", 0, NULL); /* forced set to 0(normal) temporarily */
332                         debug_log("preset-mode = %d\n", filter_type);
333
334                 } else {
335                         /* set filter preset mode */
336                         g_object_set(filter_element, "preset-mode", filter_type-1, NULL); /* filter_type-1, because of _PRESET_AUTO in MSL/CAPI which does not exist in soundAlive plugin */
337                         debug_log("preset-mode = %d\n", filter_type);
338                 }
339
340                 /* order action to sound effect plugin */
341                 g_object_set(filter_element, "filter-action", MM_AUDIO_FILTER_TYPE_PRESET, NULL);
342                 debug_log("filter-action = %d\n", MM_AUDIO_FILTER_TYPE_PRESET);
343
344         }
345         debug_fleave();
346
347         return result;
348 }
349
350
351 int
352 _mmplayer_sound_filter_custom_apply(mm_player_t *player)
353 {
354         GstElement *filter_element = NULL;
355         int result = MM_ERROR_NONE;
356
357         debug_fenter();
358
359         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
360
361         /* Music Player can set sound effect value before Audiobin is created. */
362         if ( !player->pipeline || !player->pipeline->audiobin )
363         {
364                 debug_warning("filter element is not created yet.\n");
365
366                 player->bypass_sound_effect = FALSE;
367
368                 /* store sound effect setting in order to apply it when audio filter is created */
369                 player->audio_filter_info.filter_type = MM_AUDIO_FILTER_TYPE_CUSTOM;
370         }
371         else
372         {
373                 int output_type;
374                 bool is_earphone = FALSE;
375                 return_val_if_fail( player->pipeline->audiobin, MM_ERROR_PLAYER_NOT_INITIALIZED );
376
377                 filter_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
378
379                 /* get status if earphone is activated */
380                 result = mm_sound_is_route_available(MM_SOUND_ROUTE_OUT_WIRED_ACCESSORY, &is_earphone);
381                 if ( result ) {
382                         debug_error("mm_sound_is_route_available() failed [%x]!!\n", result);
383                         return result;
384                 }
385
386                 if (is_earphone)
387                 {
388                         output_type = MM_AUDIO_FILTER_OUTPUT_EAR;
389                 }
390                 else
391                 {
392                         output_type = MM_AUDIO_FILTER_OUTPUT_SPK;
393                         if (__mmplayer_is_earphone_only_filter_type(player, MM_AUDIO_FILTER_TYPE_CUSTOM, NULL))
394                         {
395                                 debug_error("earphone is not equipped, some custom filter should operate with earphone(%x)\n", result);
396                                 return MM_ERROR_PLAYER_SOUND_EFFECT_INVALID_STATUS;
397                         }
398                 }
399
400                 /* set filter output mode as SPEAKER or EARPHONE */
401                 g_object_set(filter_element, "filter-output-mode", output_type, NULL);
402                 debug_log("filter output mode = %d(0:spk,1:ear)\n", output_type);
403
404                 result = __mmplayer_set_harmony_filter(player, filter_element);
405                 if ( result )
406                 {
407                         debug_error("_set_harmony_filter() failed(%x)\n", result);
408                         return result;
409                 }
410         }
411         debug_fleave();
412
413         return result;
414 }
415
416
417 int
418 mm_player_sound_filter_custom_clear_eq_all(MMHandleType hplayer)
419 {
420         int result = MM_ERROR_NONE;
421         mm_player_t* player = (mm_player_t*)hplayer;
422         debug_fenter();
423
424         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
425
426         /* clear EQ custom filter */
427         memset(player->audio_filter_info.custom_eq_level, MM_AUDIO_FILTER_CUSTOM_LEVEL_INIT, sizeof(int)*MM_AUDIO_FILTER_EQ_BAND_MAX);
428
429         debug_msg("All the EQ bands clearing success\n");
430
431         return result;
432 }
433
434
435 int
436 mm_player_sound_filter_custom_clear_ext_all(MMHandleType hplayer)
437 {
438         int i;
439         int result = MM_ERROR_NONE;
440         mm_player_t* player = (mm_player_t*)hplayer;
441         debug_fenter();
442
443         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
444
445         /* clear ALL custom filters, except EQ */
446         for ( i = 0 ; i < MM_AUDIO_FILTER_CUSTOM_NUM - 1 ; i++ )
447         {
448                 player->audio_filter_info.custom_ext_level[i] = MM_AUDIO_FILTER_CUSTOM_LEVEL_INIT;
449         }
450
451         debug_msg("All the extension filters clearing success\n");
452
453         return result;
454 }
455
456
457 int
458 mm_player_is_supported_preset_filter_type(MMHandleType hplayer, MMAudioFilterPresetType filter)
459 {
460         mm_player_t* player = (mm_player_t*)hplayer;
461         int result = MM_ERROR_NONE;
462         debug_fenter();
463
464         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
465
466         if ( !_mmplayer_is_supported_filter_type( MM_AUDIO_FILTER_TYPE_PRESET, filter ) )
467         {
468                 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
469         }
470
471         return result;
472 }
473
474
475 int
476 mm_player_is_supported_custom_filter_type(MMHandleType hplayer, MMAudioFilterCustomType filter)
477 {
478         mm_player_t* player = (mm_player_t*)hplayer;
479         int result = MM_ERROR_NONE;
480         debug_fenter();
481
482         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
483
484         if ( !_mmplayer_is_supported_filter_type( MM_AUDIO_FILTER_TYPE_CUSTOM, filter ) )
485         {
486                 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
487         }
488
489         return result;
490 }
491
492
493 int
494 mm_player_sound_filter_preset_apply(MMHandleType hplayer, MMAudioFilterPresetType type)
495 {
496         mm_player_t* player = (mm_player_t*)hplayer;
497         int result = MM_ERROR_NONE;
498         debug_fenter();
499
500         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
501
502         if (!PLAYER_INI()->use_audio_filter_preset)
503         {
504                 debug_error("sound filter(preset) is not suppported\n", type);
505                 return MM_ERROR_NOT_SUPPORT_API;
506         }
507
508         if (type < MM_AUDIO_FILTER_PRESET_AUTO || type >= MM_AUDIO_FILTER_PRESET_NUM)
509         {
510                 debug_error("out of range, type(%d)\n", type);
511                 return MM_ERROR_INVALID_ARGUMENT;
512         }
513
514         /* check if this filter type is supported */
515         if ( !_mmplayer_is_supported_filter_type( MM_AUDIO_FILTER_TYPE_PRESET, type ) )
516         {
517                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
518         }
519
520         result = _mmplayer_sound_filter_preset_apply(player, type);
521
522         return result;
523 }
524
525
526 int
527 mm_player_sound_filter_custom_apply(MMHandleType hplayer)
528 {
529         mm_player_t* player = (mm_player_t*)hplayer;
530         int result = MM_ERROR_NONE;
531         debug_fenter();
532
533         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
534
535         if (!PLAYER_INI()->use_audio_filter_custom)
536         {
537                 debug_error("sound filter(custom) is not suppported\n");
538                 return MM_ERROR_NOT_SUPPORT_API;
539         }
540
541         result = _mmplayer_sound_filter_custom_apply(player);
542
543         return result;
544 }
545
546
547 int
548 mm_player_sound_filter_bypass (MMHandleType hplayer)
549 {
550         mm_player_t* player = (mm_player_t*)hplayer;
551         int result = MM_ERROR_NONE;
552         GstElement *filter_element = NULL;
553         debug_fenter();
554
555         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
556
557         if ( !PLAYER_INI()->use_audio_filter_preset && !PLAYER_INI()->use_audio_filter_custom )
558         {
559                 debug_error("sound filter(preset/custom) is not suppported\n");
560                 return MM_ERROR_NOT_SUPPORT_API;
561         }
562         if ( !player->pipeline || !player->pipeline->audiobin )
563         {
564                 debug_warning("filter element is not created yet.\n");
565         }
566         else
567         {
568                 return_val_if_fail( player->pipeline->audiobin, MM_ERROR_PLAYER_NOT_INITIALIZED );
569                 filter_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
570
571                 /* order action to sound effect plugin */
572                 g_object_set(filter_element, "filter-action", MM_AUDIO_FILTER_TYPE_NONE, NULL);
573                 debug_log("filter-action = %d\n", MM_AUDIO_FILTER_TYPE_NONE);
574         }
575
576         debug_fleave();
577         return result;
578 }
579
580
581 int
582 _mmplayer_sound_filter_custom_set_level_ext(mm_player_t *player, MMAudioFilterCustomType custom_filter_type, int level)
583 {
584         int filter_level_max = 0;
585         int filter_level_min = 0;
586         int count = 1;                  /* start from 1, because of excepting eq index */
587         int ext_level_index = 1;        /* start from 1, because of excepting eq index */
588         int result = MM_ERROR_NONE;
589
590         debug_fenter();
591
592         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
593
594         /* check if EQ is supported */
595         if ( !_mmplayer_is_supported_filter_type( MM_AUDIO_FILTER_TYPE_CUSTOM, custom_filter_type ) )
596         {
597                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
598         }
599
600         while ( count < MM_AUDIO_FILTER_CUSTOM_NUM )
601         {
602                 if ( PLAYER_INI()->audio_filter_custom_list[count] )
603                 {
604                         if ( count == custom_filter_type )
605                         {
606                                 filter_level_min = PLAYER_INI()->audio_filter_custom_min_level_list[ext_level_index];
607                                 filter_level_max = PLAYER_INI()->audio_filter_custom_max_level_list[ext_level_index];
608                                 debug_msg("level min value(%d), level max value(%d)\n", filter_level_min, filter_level_max);
609                                 break;
610                         }
611                         ext_level_index++;
612                         if (ext_level_index == PLAYER_INI()->audio_filter_custom_ext_num + 1)
613                         {
614                                 debug_error("could not find min, max value. maybe filter information in ini file is not proper for sound effect plugin\n");
615                                 break;
616                         }
617                 }
618                 count++;
619         }
620
621         if ( level < filter_level_min || level > filter_level_max )
622         {
623                 debug_error("out of range, level(%d)\n", level);
624                 result = MM_ERROR_INVALID_ARGUMENT;
625         }
626         else
627         {
628                 player->audio_filter_info.custom_ext_level[custom_filter_type-1] = level;
629                 debug_msg("set ext[%d] = %d\n", custom_filter_type-1, level);
630         }
631
632         debug_fleave();
633         return result;
634 }
635
636
637 int
638 _mmplayer_sound_filter_custom_set_level_eq(mm_player_t *player, int index, int level)
639 {
640         gint eq_level_max = 0;
641         gint eq_level_min = 0;
642         int result = MM_ERROR_NONE;
643         debug_fenter();
644
645         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
646
647         /* check if EQ is supported */
648         if ( !_mmplayer_is_supported_filter_type( MM_AUDIO_FILTER_TYPE_CUSTOM, MM_AUDIO_FILTER_CUSTOM_EQ ) )
649         {
650                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
651         }
652
653         if ( index < 0 || index > PLAYER_INI()->audio_filter_custom_eq_num - 1 )
654         {
655                 debug_error("out of range, index(%d)\n", index);
656                 result = MM_ERROR_INVALID_ARGUMENT;
657         }
658         else
659         {
660                 eq_level_min = PLAYER_INI()->audio_filter_custom_min_level_list[MM_AUDIO_FILTER_CUSTOM_EQ];
661                 eq_level_max = PLAYER_INI()->audio_filter_custom_max_level_list[MM_AUDIO_FILTER_CUSTOM_EQ];
662                 debug_msg("EQ level min value(%d), EQ level max value(%d)\n", eq_level_min, eq_level_max);
663
664                 if ( level < eq_level_min || level > eq_level_max )
665                 {
666                         debug_error("out of range, EQ level(%d)\n", level);
667                         result =  MM_ERROR_INVALID_ARGUMENT;
668                 }
669                 else
670                 {
671                         player->audio_filter_info.custom_eq_level[index] = level;
672                         debug_msg("set EQ[%d] = %d\n", index, level);
673                 }
674         }
675         debug_fleave();
676
677         return result;
678 }
679
680
681 /* NOTE : parameter eq_index is only used for _set_eq_level() */
682 int
683 mm_player_sound_filter_custom_set_level(MMHandleType hplayer, MMAudioFilterCustomType filter_custom_type, int eq_index, int level)
684 {
685         mm_player_t* player = (mm_player_t*)hplayer;
686         int result = MM_ERROR_NONE;
687         debug_fenter();
688
689         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
690
691         /* check if this filter type is supported */
692         if ( !_mmplayer_is_supported_filter_type( MM_AUDIO_FILTER_TYPE_CUSTOM, filter_custom_type ) )
693         {
694                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
695         }
696
697         if (filter_custom_type == MM_AUDIO_FILTER_CUSTOM_EQ)
698         {
699                 result = _mmplayer_sound_filter_custom_set_level_eq(player, eq_index, level);
700         }
701         else if (filter_custom_type > MM_AUDIO_FILTER_CUSTOM_EQ || filter_custom_type < MM_AUDIO_FILTER_CUSTOM_NUM)
702         {
703                 result = _mmplayer_sound_filter_custom_set_level_ext(player, filter_custom_type, level);
704         }
705         else
706         {
707                 debug_error("out of range, filter type(%d)\n", filter_custom_type);
708                 result = MM_ERROR_INVALID_ARGUMENT;
709         }
710         return result;
711 }
712
713
714 int
715 mm_player_sound_filter_custom_get_eq_bands_number(MMHandleType hplayer, int *bands)
716 {
717         mm_player_t* player = (mm_player_t*)hplayer;
718         int result = MM_ERROR_NONE;
719         debug_fenter();
720
721         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
722
723         /* check if EQ is supported */
724         if ( !_mmplayer_is_supported_filter_type( MM_AUDIO_FILTER_TYPE_CUSTOM, MM_AUDIO_FILTER_CUSTOM_EQ ) )
725         {
726                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
727         }
728
729         *bands = PLAYER_INI()->audio_filter_custom_eq_num;
730         debug_log("number of custom eq band = %d\n", *bands);
731
732         debug_fleave();
733
734         return result;
735 }
736
737
738 int
739 mm_player_sound_filter_custom_get_level(MMHandleType hplayer, MMAudioFilterCustomType type, int eq_index, int *level)
740 {
741         mm_player_t* player = (mm_player_t*)hplayer;
742         int result = MM_ERROR_NONE;
743
744         debug_fenter();
745
746         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
747         return_val_if_fail( level, MM_ERROR_PLAYER_NOT_INITIALIZED );
748
749         /* check if this filter type is supported */
750         if ( !_mmplayer_is_supported_filter_type( MM_AUDIO_FILTER_TYPE_CUSTOM, type ) )
751         {
752                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
753         }
754
755         if (type == MM_AUDIO_FILTER_CUSTOM_EQ)
756         {
757                 if ( eq_index < 0 || eq_index > PLAYER_INI()->audio_filter_custom_eq_num - 1 )
758                 {
759                         debug_error("out of range, eq index(%d)\n", eq_index);
760                         result = MM_ERROR_INVALID_ARGUMENT;
761                 }
762                 else
763                 {
764                         *level = player->audio_filter_info.custom_eq_level[eq_index];
765                         debug_log("EQ index = %d, level = %d\n", eq_index, *level);
766                 }
767         }
768         else if ( type > MM_AUDIO_FILTER_CUSTOM_EQ && type < MM_AUDIO_FILTER_CUSTOM_NUM )
769         {
770                 *level = player->audio_filter_info.custom_ext_level[type-1];
771                 debug_log("extention filter index = %d, level = %d\n", type, *level);
772         }
773         else
774         {
775                 debug_error("out of range, type(%d)\n", type);
776                 result = MM_ERROR_INVALID_ARGUMENT;
777         }
778
779         debug_fleave();
780
781         return result;
782 }
783
784
785 int
786 mm_player_sound_filter_custom_get_level_range(MMHandleType hplayer, MMAudioFilterCustomType type, int *min, int *max)
787 {
788         mm_player_t* player = (mm_player_t*)hplayer;
789         int result = MM_ERROR_NONE;
790         int count = 1;                  /* start from 1, because of excepting eq index */
791         int ext_level_index = 1;        /* start from 1, because of excepting eq index */
792
793         debug_fenter();
794
795         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
796         return_val_if_fail( min, MM_ERROR_PLAYER_NOT_INITIALIZED );
797         return_val_if_fail( max, MM_ERROR_PLAYER_NOT_INITIALIZED );
798
799         /* check if this filter type is supported */
800         if ( !_mmplayer_is_supported_filter_type( MM_AUDIO_FILTER_TYPE_CUSTOM, type ) )
801         {
802                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
803         }
804
805         if ( type == MM_AUDIO_FILTER_CUSTOM_EQ )
806         {
807                 *min = PLAYER_INI()->audio_filter_custom_min_level_list[MM_AUDIO_FILTER_CUSTOM_EQ];
808                 *max = PLAYER_INI()->audio_filter_custom_max_level_list[MM_AUDIO_FILTER_CUSTOM_EQ];
809                 debug_log("EQ min level = %d, max level = %d\n", *min, *max);
810         }
811         else
812         {
813                 while ( count < MM_AUDIO_FILTER_CUSTOM_NUM )
814                 {
815                         if ( PLAYER_INI()->audio_filter_custom_list[count] )
816                         {
817                                 if ( count == type )
818                                 {
819                                         *min = PLAYER_INI()->audio_filter_custom_min_level_list[ext_level_index];
820                                         *max = PLAYER_INI()->audio_filter_custom_max_level_list[ext_level_index];
821                                         debug_msg("Extension filter(%d) min level = %d, max level = %d\n", count, *min, *max);
822                                         break;
823                                 }
824                                 ext_level_index++;
825                                 if ( ext_level_index == PLAYER_INI()->audio_filter_custom_ext_num + 1 )
826                                 {
827                                         debug_error("could not find min, max value. maybe filter information in ini file is not proper for sound effect plugin\n");
828                                         break;
829                                 }
830                         }
831                         count++;
832                 }
833         }
834
835         debug_fleave();
836
837         return result;
838 }
839
840
841 int
842 mm_player_sound_filter_custom_set_level_eq_from_list(MMHandleType hplayer, int *level_list, int size)
843 {
844         mm_player_t *player = (mm_player_t*)hplayer;
845         gint i = 0;
846         gint eq_level_min = 0;
847         gint eq_level_max = 0;
848         int result = MM_ERROR_NONE;
849
850         debug_fenter();
851
852         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
853
854         /* check if EQ is supported */
855         if ( !_mmplayer_is_supported_filter_type( MM_AUDIO_FILTER_TYPE_CUSTOM, MM_AUDIO_FILTER_CUSTOM_EQ ) )
856         {
857                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
858         }
859
860         if ( size != PLAYER_INI()->audio_filter_custom_eq_num )
861         {
862                 debug_error("input size variable(%d) does not match with number of eq band(%d)\n", size, PLAYER_INI()->audio_filter_custom_eq_num);
863                 result = MM_ERROR_INVALID_ARGUMENT;
864         }
865         else
866         {
867                 eq_level_min = PLAYER_INI()->audio_filter_custom_min_level_list[MM_AUDIO_FILTER_CUSTOM_EQ];
868                 eq_level_max = PLAYER_INI()->audio_filter_custom_max_level_list[MM_AUDIO_FILTER_CUSTOM_EQ];
869
870                 for ( i = 0 ; i < size ; i++ )
871                 {
872                         if ( level_list[i] < eq_level_min || level_list[i] > eq_level_max)
873                         {
874                                 debug_error("out of range, level[%d]=%d\n", i, level_list[i]);
875                                 result = MM_ERROR_INVALID_ARGUMENT;
876                                 break;
877                         }
878                         player->audio_filter_info.custom_eq_level[i] = level_list[i];
879                 }
880         }
881         debug_fleave();
882
883         return result;
884 }