Tizen 2.1 base
[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 <mm_error.h>
22
23 #include "mm_player_audioeffect.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_effect_type(MMHandleType player, MMAudioEffectType effect_type, mmplayer_supported_audio_effect_cb foreach_cb, void *user_data)
31 {
32         int result = MM_ERROR_NONE;
33         mm_sound_device_in device_in;
34         mm_sound_device_out device_out;
35         int i = 0;
36
37         debug_fenter();
38
39         return_val_if_fail ( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
40
41         /* get status if speaker is activated */
42         result = mm_sound_get_active_device(&device_in, &device_out);
43         if ( result ) {
44                 debug_fleave();
45                 debug_error("mm_sound_get_active_device() failed [%x]!!", result);
46                 return result;
47         }
48
49         /* preset */
50         if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET)
51         {
52                 for ( i = 0; i < MM_AUDIO_EFFECT_PRESET_NUM; i++ )
53                 {
54                         if (PLAYER_INI()->audio_effect_preset_list[i] )
55                         {
56                                 if (device_out == MM_SOUND_DEVICE_OUT_SPEAKER &&
57                                         PLAYER_INI()->audio_effect_preset_earphone_only_list[i])
58                                 {
59                                         continue;
60                                 }
61                                 if (!foreach_cb(effect_type,i, user_data))
62                                 {
63                                         goto CALLBACK_ERROR;
64                                 }
65                         }
66                 }
67         }
68         /* custom */
69         else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM)
70         {
71                 for ( i = 0; i < MM_AUDIO_EFFECT_CUSTOM_NUM; i++ )
72                 {
73                         if (PLAYER_INI()->audio_effect_custom_list[i] )
74                         {
75                                 if (device_out == MM_SOUND_DEVICE_OUT_SPEAKER &&
76                                         PLAYER_INI()->audio_effect_custom_earphone_only_list[i])
77                                 {
78                                         continue;
79                                 }
80                                 if (!foreach_cb(effect_type,i, user_data))
81                                 {
82                                         goto CALLBACK_ERROR;
83                                 }
84                         }
85                 }
86         }
87         else
88         {
89                 debug_error("invalid effect type(%d)", effect_type);
90                 result = MM_ERROR_INVALID_ARGUMENT;
91         }
92
93         debug_fleave();
94
95         return result;
96
97 CALLBACK_ERROR:
98         debug_error("foreach callback returned error");
99         debug_fleave();
100         return MM_ERROR_PLAYER_INTERNAL;
101 }
102
103
104 int
105 __mmplayer_set_harmony_effect(mm_player_t *player, GstElement *audio_effect_element)
106 {
107         gint *ext_effect_level_list = NULL;
108         int count = 1;          /* start from 1, because of excepting eq index */
109         int ext_level_index = 0;
110         int result = MM_ERROR_NONE;
111
112         debug_fenter();
113
114         return_val_if_fail ( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
115         return_val_if_fail ( audio_effect_element, MM_ERROR_INVALID_ARGUMENT );
116
117         /* Custom EQ */
118         if( PLAYER_INI()->audio_effect_custom_eq_band_num )
119         {
120                 debug_log("pass custom EQ level list to audio effect plugin");
121                 /* set custom-equalizer level list */
122                 g_object_set(audio_effect_element, "custom-eq", player->audio_effect_info.custom_eq_level, NULL);
123         }
124         else
125         {
126                 debug_warning("no custom EQ");
127         }
128
129         /* Custom Extension effects */
130         if( PLAYER_INI()->audio_effect_custom_ext_num )
131         {
132                 debug_log("pass custom extension level list to audio effect plugin");
133                 ext_effect_level_list = player->audio_effect_info.custom_ext_level_for_plugin;
134                 if (!ext_effect_level_list) {
135                         ext_effect_level_list = (gint*) malloc (sizeof(gint)*PLAYER_INI()->audio_effect_custom_ext_num);
136                         if (!ext_effect_level_list)
137                         {
138                                 debug_error("memory allocation for extension effect list failed");
139                                 return MM_ERROR_OUT_OF_MEMORY;
140                         }
141                         else
142                         {
143                                 memset (ext_effect_level_list, 0, PLAYER_INI()->audio_effect_custom_ext_num);
144                         }
145                 }
146
147                 while ( count < MM_AUDIO_EFFECT_CUSTOM_NUM )
148                 {
149                         if ( PLAYER_INI()->audio_effect_custom_list[count] )
150                         {
151                                 ext_effect_level_list[ext_level_index] = player->audio_effect_info.custom_ext_level[count-1];
152                                 ext_level_index++;
153                                 if (ext_level_index == PLAYER_INI()->audio_effect_custom_ext_num)
154                                 {
155                                         break;
156                                 }
157                         }
158                         count++;
159                 }
160
161                 /* set custom-extension effects level list */
162                 g_object_set(audio_effect_element, "custom-ext", ext_effect_level_list, NULL);
163         }
164         else
165         {
166                 debug_warning("no custom extension effect");
167         }
168
169         /* order action to audio effect plugin */
170         g_object_set(audio_effect_element, "filter-action", MM_AUDIO_EFFECT_TYPE_CUSTOM, NULL);
171         debug_log("filter-action = %d", MM_AUDIO_EFFECT_TYPE_CUSTOM);
172
173         debug_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         debug_fenter();
186
187         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
188
189         /* preset */
190         if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET)
191         {
192                 if (PLAYER_INI()->audio_effect_preset_earphone_only_list[effect])
193                 {
194                         debug_msg("this preset effect(%d) is only available with earphone", effect);
195                         result = TRUE;
196                 }
197         }
198         /* custom */
199         else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM)
200         {
201                 for (i = 1; i < MM_AUDIO_EFFECT_CUSTOM_NUM; i++) /* it starts from 1(except testing for EQ) */
202                 {
203                         if (PLAYER_INI()->audio_effect_custom_earphone_only_list[i])
204                         {
205                                 /* check if the earphone only custom effect was set */
206                                 if (player->audio_effect_info.custom_ext_level[i-1])
207                                 {
208                                         debug_msg("this custom effect(%d) is only available with earphone", i);
209                                         result = TRUE;
210                                 }
211                         }
212                 }
213         }
214         else
215         {
216                 debug_error("invalid effect type(%d)", effect_type);
217         }
218
219         debug_fleave();
220
221         return result;
222 }
223
224
225 gboolean
226 _mmplayer_is_supported_effect_type(MMAudioEffectType effect_type, int effect)
227 {
228         gboolean result = TRUE;
229         mm_sound_device_in device_in;
230         mm_sound_device_out device_out;
231         int ret = MM_ERROR_NONE;
232
233         debug_fenter();
234
235         /* get status if speaker is activated */
236         ret = mm_sound_get_active_device(&device_in, &device_out);
237         if ( ret ) {
238                 debug_fleave();
239                 debug_error("mm_sound_get_active_device() failed [%x]!!", ret);
240                 result = FALSE;
241         }
242         else
243         {
244                 /* preset */
245                 if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET)
246                 {
247                         if ( effect < MM_AUDIO_EFFECT_PRESET_AUTO || effect >= MM_AUDIO_EFFECT_PRESET_NUM )
248                         {
249                                 debug_error("out of range, preset effect(%d)", effect);
250                                 result = FALSE;
251                         }
252                         if (!PLAYER_INI()->audio_effect_preset_list[effect])
253                         {
254                                 debug_error("this effect(%d) is not supported", effect);
255                                 result = FALSE;
256                         }
257                         else
258                         {
259                                 if (device_out == MM_SOUND_DEVICE_OUT_SPEAKER &&
260                                                 PLAYER_INI()->audio_effect_preset_earphone_only_list[effect])
261                                 {
262                                         result = FALSE;
263                                 }
264                         }
265                 }
266                 /* custom */
267                 else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM)
268                 {
269                         if ( effect < MM_AUDIO_EFFECT_CUSTOM_EQ || effect >= MM_AUDIO_EFFECT_CUSTOM_NUM )
270                         {
271                                 debug_error("out of range, custom effect(%d)", effect);
272                                 result = FALSE;
273                         }
274                         if (!PLAYER_INI()->audio_effect_custom_list[effect])
275                         {
276                                 debug_error("this custom effect(%d) is not supported", effect);
277                                 result = FALSE;
278                         }
279                         else
280                         {
281                                 if (device_out == MM_SOUND_DEVICE_OUT_SPEAKER &&
282                                                 PLAYER_INI()->audio_effect_custom_earphone_only_list[effect])
283                                 {
284                                         result = FALSE;
285                                 }
286                         }
287                 }
288                 else
289                 {
290                         debug_error("invalid effect type(%d)", effect_type);
291                         result = FALSE;
292                 }
293         }
294
295         debug_fleave();
296
297         return result;
298 }
299
300
301 int
302 _mmplayer_audio_effect_preset_apply(mm_player_t *player, MMAudioEffectPresetType effect_type)
303 {
304         GstElement *audio_effect_element = NULL;
305         int result = MM_ERROR_NONE;
306         int output_type = 0;
307         mm_sound_device_in device_in;
308         mm_sound_device_out device_out;
309
310         debug_fenter();
311
312         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
313
314         /* Music Player can set audio effect value before Audiobin is created. */
315         if ( !player->pipeline || !player->pipeline->audiobin )
316         {
317                 debug_warning("effect element is not created yet.");
318
319                 player->bypass_audio_effect = FALSE;
320
321                 /* store audio effect setting in order to apply it when audio effect plugin is created */
322                 player->audio_effect_info.effect_type = MM_AUDIO_EFFECT_TYPE_PRESET;
323                 player->audio_effect_info.preset = effect_type;
324         }
325         else
326         {
327                 return_val_if_fail( player->pipeline->audiobin, MM_ERROR_PLAYER_NOT_INITIALIZED );
328
329                 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
330
331                 /* get status if speaker is activated */
332                 result = mm_sound_get_active_device(&device_in, &device_out);
333                 if ( result ) {
334                         debug_error("mm_sound_get_active_device() failed [%x]!!", result);
335                         debug_fleave();
336                         return result;
337                 }
338
339                 /* SPEAKER case */
340                 if (device_out == MM_SOUND_DEVICE_OUT_SPEAKER)
341                 {
342                         output_type = MM_AUDIO_EFFECT_OUTPUT_SPK;
343                         if (__mmplayer_is_earphone_only_effect_type(player, MM_AUDIO_EFFECT_TYPE_PRESET, effect_type))
344                         {
345                                 debug_error("earphone is not equipped, this filter will not be applied");
346                                 debug_fleave();
347                                 return MM_ERROR_PLAYER_SOUND_EFFECT_INVALID_STATUS;
348                         }
349                 }
350                 /* Other case, include WIRED_ACCESSORY, BLUETOOTH, DOCK */
351                 else
352                 {
353                         output_type = MM_AUDIO_EFFECT_OUTPUT_EAR;
354                 }
355
356                 /* set filter output mode as SPEAKER or EARPHONE */
357                 g_object_set(audio_effect_element, "filter-output-mode", output_type, NULL);
358                 debug_log("filter-output-mode = %d (0:spk,1:ear)", output_type);
359
360                 if (effect_type == MM_AUDIO_EFFECT_PRESET_AUTO) {
361                         /* TODO: Add codes about auto selecting preset mode according to ID3 tag */
362                         /* set effect preset mode */
363                         g_object_set(audio_effect_element, "preset-mode", 0, NULL); /* forced set to 0(normal) temporarily */
364                         debug_log("preset-mode = %d", effect_type);
365
366                 } else {
367                         /* set effect preset mode */
368                         g_object_set(audio_effect_element, "preset-mode", effect_type-1, NULL); /* effect_type-1, because of _PRESET_AUTO in MSL/CAPI which does not exist in soundAlive plugin */
369                         debug_log("preset-mode = %d", effect_type);
370                 }
371
372                 /* order action to audio effect plugin */
373                 g_object_set(audio_effect_element, "filter-action", MM_AUDIO_EFFECT_TYPE_PRESET, NULL);
374                 debug_log("filter-action = %d", MM_AUDIO_EFFECT_TYPE_PRESET);
375
376         }
377
378         debug_fleave();
379
380         return result;
381 }
382
383
384 int
385 _mmplayer_audio_effect_custom_apply(mm_player_t *player)
386 {
387         GstElement *audio_effect_element = NULL;
388         int result = MM_ERROR_NONE;
389
390         debug_fenter();
391
392         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
393
394         /* Music Player can set audio effect value before Audiobin is created. */
395         if ( !player->pipeline || !player->pipeline->audiobin )
396         {
397                 debug_warning("effect element is not created yet.");
398
399                 player->bypass_audio_effect = FALSE;
400
401                 /* store audio effect setting in order to apply it when audio effect plugin is created */
402                 player->audio_effect_info.effect_type = MM_AUDIO_EFFECT_TYPE_CUSTOM;
403         }
404         else
405         {
406                 int output_type = 0;
407                 mm_sound_device_in device_in;
408                 mm_sound_device_out device_out;
409
410                 return_val_if_fail( player->pipeline->audiobin, MM_ERROR_PLAYER_NOT_INITIALIZED );
411
412                 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
413
414                 /* get status if speaker is activated */
415                 result = mm_sound_get_active_device(&device_in, &device_out);
416                 if ( result ) {
417                         debug_error("mm_sound_get_active_device() failed [%x]!!", result);
418                         debug_fleave();
419                         return result;
420                 }
421
422                 /* SPEAKER case */
423                 if (device_out == MM_SOUND_DEVICE_OUT_SPEAKER)
424                 {
425                         output_type = MM_AUDIO_EFFECT_OUTPUT_SPK;
426                         if (__mmplayer_is_earphone_only_effect_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, 0))
427                         {
428                                 debug_error("earphone is not equipped, some custom effect should operate with earphone");
429                                 debug_fleave();
430                                 return MM_ERROR_PLAYER_SOUND_EFFECT_INVALID_STATUS;
431                         }
432                 }
433                 /* Other case, include WIRED_ACCESSORY, BLUETOOTH, DOCK */
434                 else
435                 {
436                         output_type = MM_AUDIO_EFFECT_OUTPUT_EAR;
437                 }
438
439                 /* set filter output mode as SPEAKER or EARPHONE */
440                 g_object_set(audio_effect_element, "filter-output-mode", output_type, NULL);
441                 debug_log("filter-output-mode = %d (0:spk,1:ear)", output_type);
442
443                 result = __mmplayer_set_harmony_effect(player, audio_effect_element);
444                 if ( result )
445                 {
446                         debug_error("_set_harmony_effect() failed(%x)", result);
447                         debug_fleave();
448                         return result;
449                 }
450         }
451
452         debug_fleave();
453
454         return result;
455 }
456
457
458 int
459 mm_player_audio_effect_custom_clear_eq_all(MMHandleType hplayer)
460 {
461         int result = MM_ERROR_NONE;
462         mm_player_t* player = (mm_player_t*)hplayer;
463
464         debug_fenter();
465
466         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
467
468         /* clear EQ custom effect */
469         memset(player->audio_effect_info.custom_eq_level, MM_AUDIO_EFFECT_CUSTOM_LEVEL_INIT, sizeof(int)*MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX);
470
471         debug_msg("All the EQ bands clearing success");
472
473         debug_fleave();
474
475         return result;
476 }
477
478
479 int
480 mm_player_audio_effect_custom_clear_ext_all(MMHandleType hplayer)
481 {
482         int i;
483         int result = MM_ERROR_NONE;
484         mm_player_t* player = (mm_player_t*)hplayer;
485
486         debug_fenter();
487
488         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
489
490         /* clear ALL custom effects, except EQ */
491         for ( i = 0 ; i < MM_AUDIO_EFFECT_CUSTOM_NUM - 1 ; i++ )
492         {
493                 player->audio_effect_info.custom_ext_level[i] = MM_AUDIO_EFFECT_CUSTOM_LEVEL_INIT;
494         }
495
496         debug_msg("All the extension effects clearing success");
497
498         debug_fleave();
499
500         return result;
501 }
502
503
504 int
505 mm_player_is_supported_preset_effect_type(MMHandleType hplayer, MMAudioEffectPresetType effect)
506 {
507         mm_player_t* player = (mm_player_t*)hplayer;
508         int result = MM_ERROR_NONE;
509
510         debug_fenter();
511
512         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
513
514         if ( !_mmplayer_is_supported_effect_type( MM_AUDIO_EFFECT_TYPE_PRESET, effect ) )
515         {
516                 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
517         }
518
519         debug_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         debug_fenter();
532
533         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
534
535         if ( !_mmplayer_is_supported_effect_type( MM_AUDIO_EFFECT_TYPE_CUSTOM, effect ) )
536         {
537                 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
538         }
539
540         debug_fleave();
541
542         return result;
543 }
544
545
546 int
547 mm_player_audio_effect_preset_apply(MMHandleType hplayer, MMAudioEffectPresetType type)
548 {
549         mm_player_t* player = (mm_player_t*)hplayer;
550         int result = MM_ERROR_NONE;
551
552         debug_fenter();
553
554         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
555
556         if (!PLAYER_INI()->use_audio_effect_preset)
557         {
558                 debug_error("audio effect(preset) is not supported", type);
559                 debug_fleave();
560                 return MM_ERROR_NOT_SUPPORT_API;
561         }
562
563         if (type < MM_AUDIO_EFFECT_PRESET_AUTO || type >= MM_AUDIO_EFFECT_PRESET_NUM)
564         {
565                 debug_error("out of range, type(%d)", type);
566                 debug_fleave();
567                 return MM_ERROR_INVALID_ARGUMENT;
568         }
569
570         /* check if this effect type is supported */
571         if ( !_mmplayer_is_supported_effect_type( MM_AUDIO_EFFECT_TYPE_PRESET, type ) )
572         {
573                 debug_fleave();
574                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
575         }
576
577         result = _mmplayer_audio_effect_preset_apply(player, type);
578
579         debug_fleave();
580
581         return result;
582 }
583
584
585 int
586 mm_player_audio_effect_custom_apply(MMHandleType hplayer)
587 {
588         mm_player_t* player = (mm_player_t*)hplayer;
589         int result = MM_ERROR_NONE;
590
591         debug_fenter();
592
593         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
594
595         if (!PLAYER_INI()->use_audio_effect_custom)
596         {
597                 debug_error("audio effect(custom) is not supported");
598                 debug_fleave();
599                 return MM_ERROR_NOT_SUPPORT_API;
600         }
601
602         result = _mmplayer_audio_effect_custom_apply(player);
603
604         debug_fleave();
605
606         return result;
607 }
608
609
610 int
611 mm_player_audio_effect_bypass (MMHandleType hplayer)
612 {
613         mm_player_t* player = (mm_player_t*)hplayer;
614         int result = MM_ERROR_NONE;
615         GstElement *audio_effect_element = NULL;
616
617         debug_fenter();
618
619         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
620
621         if ( !PLAYER_INI()->use_audio_effect_preset && !PLAYER_INI()->use_audio_effect_custom )
622         {
623                 debug_error("audio effect(preset/custom) is not supported");
624                 debug_fleave();
625                 return MM_ERROR_NOT_SUPPORT_API;
626         }
627         if ( !player->pipeline || !player->pipeline->audiobin )
628         {
629                 debug_warning("effect element is not created yet.");
630         }
631         else
632         {
633                 return_val_if_fail( player->pipeline->audiobin, MM_ERROR_PLAYER_NOT_INITIALIZED );
634                 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
635
636                 /* order action to audio effect plugin */
637                 g_object_set(audio_effect_element, "filter-action", MM_AUDIO_EFFECT_TYPE_NONE, NULL);
638                 debug_log("filter-action = %d", MM_AUDIO_EFFECT_TYPE_NONE);
639         }
640
641         debug_fleave();
642
643         return result;
644 }
645
646
647 int
648 _mmplayer_audio_effect_custom_set_level_ext(mm_player_t *player, MMAudioEffectCustomType custom_effect_type, int level)
649 {
650         int effect_level_max = 0;
651         int effect_level_min = 0;
652         int count = 1;                  /* start from 1, because of excepting eq index */
653         int ext_level_index = 1;        /* start from 1, because of excepting eq index */
654         int result = MM_ERROR_NONE;
655
656         debug_fenter();
657
658         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
659
660         /* check if EQ is supported */
661         if ( !_mmplayer_is_supported_effect_type( MM_AUDIO_EFFECT_TYPE_CUSTOM, custom_effect_type ) )
662         {
663                 debug_fleave();
664                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
665         }
666
667         while ( count < MM_AUDIO_EFFECT_CUSTOM_NUM )
668         {
669                 if ( PLAYER_INI()->audio_effect_custom_list[count] )
670                 {
671                         if ( count == custom_effect_type )
672                         {
673                                 effect_level_min = PLAYER_INI()->audio_effect_custom_min_level_list[ext_level_index];
674                                 effect_level_max = PLAYER_INI()->audio_effect_custom_max_level_list[ext_level_index];
675                                 debug_msg("level min value(%d), level max value(%d)", effect_level_min, effect_level_max);
676                                 break;
677                         }
678                         ext_level_index++;
679                         if (ext_level_index == PLAYER_INI()->audio_effect_custom_ext_num + 1)
680                         {
681                                 debug_error("could not find min, max value. maybe effect information in ini file is not proper for audio effect plugin");
682                                 break;
683                         }
684                 }
685                 count++;
686         }
687
688         if ( level < effect_level_min || level > effect_level_max )
689         {
690                 debug_error("out of range, level(%d)", level);
691                 result = MM_ERROR_INVALID_ARGUMENT;
692         }
693         else
694         {
695                 player->audio_effect_info.custom_ext_level[custom_effect_type-1] = level;
696                 debug_msg("set ext[%d] = %d", custom_effect_type-1, level);
697         }
698
699         debug_fleave();
700
701         return result;
702 }
703
704
705 int
706 _mmplayer_audio_effect_custom_set_level_eq(mm_player_t *player, int index, int level)
707 {
708         gint eq_level_max = 0;
709         gint eq_level_min = 0;
710         int result = MM_ERROR_NONE;
711
712         debug_fenter();
713
714         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
715
716         /* check if EQ is supported */
717         if ( !_mmplayer_is_supported_effect_type( MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ ) )
718         {
719                 debug_fleave();
720                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
721         }
722
723         if ( index < 0 || index > PLAYER_INI()->audio_effect_custom_eq_band_num - 1 )
724         {
725                 debug_error("out of range, index(%d)", index);
726                 result = MM_ERROR_INVALID_ARGUMENT;
727         }
728         else
729         {
730                 eq_level_min = PLAYER_INI()->audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
731                 eq_level_max = PLAYER_INI()->audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
732                 debug_msg("EQ level min value(%d), EQ level max value(%d)", eq_level_min, eq_level_max);
733
734                 if ( level < eq_level_min || level > eq_level_max )
735                 {
736                         debug_error("out of range, EQ level(%d)", level);
737                         result =  MM_ERROR_INVALID_ARGUMENT;
738                 }
739                 else
740                 {
741                         player->audio_effect_info.custom_eq_level[index] = level;
742                         debug_msg("set EQ[%d] = %d", index, level);
743                 }
744         }
745
746         debug_fleave();
747
748         return result;
749 }
750
751
752 /* NOTE : parameter eq_index is only used for _set_eq_level() */
753 int
754 mm_player_audio_effect_custom_set_level(MMHandleType hplayer, MMAudioEffectCustomType effect_custom_type, int eq_index, int level)
755 {
756         mm_player_t* player = (mm_player_t*)hplayer;
757         int result = MM_ERROR_NONE;
758
759         debug_fenter();
760
761         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
762
763         /* check if this effect type is supported */
764         if ( !_mmplayer_is_supported_effect_type( MM_AUDIO_EFFECT_TYPE_CUSTOM, effect_custom_type ) )
765         {
766                 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
767         }
768         else
769         {
770                 if (effect_custom_type == MM_AUDIO_EFFECT_CUSTOM_EQ)
771                 {
772                         result = _mmplayer_audio_effect_custom_set_level_eq(player, eq_index, level);
773                 }
774                 else if (effect_custom_type > MM_AUDIO_EFFECT_CUSTOM_EQ || effect_custom_type < MM_AUDIO_EFFECT_CUSTOM_NUM)
775                 {
776                         result = _mmplayer_audio_effect_custom_set_level_ext(player, effect_custom_type, level);
777                 }
778                 else
779                 {
780                         debug_error("out of range, effect type(%d)", effect_custom_type);
781                         result = MM_ERROR_INVALID_ARGUMENT;
782                 }
783         }
784
785         debug_fleave();
786
787         return result;
788 }
789
790
791 int
792 mm_player_audio_effect_custom_get_eq_bands_number(MMHandleType hplayer, int *bands)
793 {
794         mm_player_t* player = (mm_player_t*)hplayer;
795         int result = MM_ERROR_NONE;
796
797         debug_fenter();
798
799         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
800
801         /* check if EQ is supported */
802         if ( !_mmplayer_is_supported_effect_type( MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ ) )
803         {
804                 debug_fleave();
805                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
806         }
807
808         *bands = PLAYER_INI()->audio_effect_custom_eq_band_num;
809         debug_log("number of custom EQ band = %d", *bands);
810
811         debug_fleave();
812
813         return result;
814 }
815
816
817 int
818 mm_player_audio_effect_custom_get_eq_bands_width(MMHandleType hplayer, int band_idx, int *width)
819 {
820         mm_player_t* player = (mm_player_t*)hplayer;
821         int result = MM_ERROR_NONE;
822         unsigned int eq_num = 0;
823
824         debug_fenter();
825
826         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
827
828         /* check if EQ is supported */
829         if ( !_mmplayer_is_supported_effect_type( MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ ) )
830         {
831                 debug_fleave();
832                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
833         }
834
835         return_val_if_fail( player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED );
836
837         eq_num = PLAYER_INI()->audio_effect_custom_eq_band_num;
838         if (band_idx < 0 || band_idx > eq_num-1)
839         {
840                 debug_error("out of range, invalid band_idx(%d)", band_idx);
841                 result = MM_ERROR_PLAYER_INTERNAL;
842         }
843         else
844         {
845                 /* set the width of EQ band */
846                 *width = PLAYER_INI()->audio_effect_custom_eq_band_width[band_idx];
847                 debug_log("width of band_idx(%d) = %dHz", band_idx, *width);
848         }
849
850         debug_fleave();
851
852         return result;
853 }
854
855
856 int
857 mm_player_audio_effect_custom_get_eq_bands_freq(MMHandleType hplayer, int band_idx, int *freq)
858 {
859         mm_player_t* player = (mm_player_t*)hplayer;
860         int result = MM_ERROR_NONE;
861         unsigned int eq_num = 0;
862
863         debug_fenter();
864
865         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
866
867         /* check if EQ is supported */
868         if ( !_mmplayer_is_supported_effect_type( MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ ) )
869         {
870                 debug_fleave();
871                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
872         }
873
874         return_val_if_fail( player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED );
875
876         eq_num = PLAYER_INI()->audio_effect_custom_eq_band_num;
877         if (band_idx < 0 || band_idx > eq_num-1)
878         {
879                 debug_error("out of range, invalid band_idx(%d)", band_idx);
880                 result = MM_ERROR_PLAYER_INTERNAL;
881         }
882         else
883         {
884                 /* set the frequency of EQ band */
885                 *freq = PLAYER_INI()->audio_effect_custom_eq_band_freq[band_idx];
886                 debug_log("frequency of band_idx(%d) = %dHz", band_idx, *freq);
887         }
888
889         debug_fleave();
890
891         return result;
892 }
893
894
895 int
896 mm_player_audio_effect_custom_get_level(MMHandleType hplayer, MMAudioEffectCustomType type, int eq_index, int *level)
897 {
898         mm_player_t* player = (mm_player_t*)hplayer;
899         int result = MM_ERROR_NONE;
900
901         debug_fenter();
902
903         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
904         return_val_if_fail( level, MM_ERROR_PLAYER_NOT_INITIALIZED );
905
906         /* check if this effect type is supported */
907         if ( !_mmplayer_is_supported_effect_type( MM_AUDIO_EFFECT_TYPE_CUSTOM, type ) )
908         {
909                 debug_fleave();
910                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
911         }
912
913         if (type == MM_AUDIO_EFFECT_CUSTOM_EQ)
914         {
915                 if ( eq_index < 0 || eq_index > PLAYER_INI()->audio_effect_custom_eq_band_num - 1 )
916                 {
917                         debug_error("out of range, EQ index(%d)", eq_index);
918                         result = MM_ERROR_INVALID_ARGUMENT;
919                 }
920                 else
921                 {
922                         *level = player->audio_effect_info.custom_eq_level[eq_index];
923                         debug_log("EQ index = %d, level = %d", eq_index, *level);
924                 }
925         }
926         else if ( type > MM_AUDIO_EFFECT_CUSTOM_EQ && type < MM_AUDIO_EFFECT_CUSTOM_NUM )
927         {
928                 *level = player->audio_effect_info.custom_ext_level[type-1];
929                 debug_log("extension effect index = %d, level = %d", type, *level);
930         }
931         else
932         {
933                 debug_error("out of range, type(%d)", type);
934                 result = MM_ERROR_INVALID_ARGUMENT;
935         }
936
937         debug_fleave();
938
939         return result;
940 }
941
942
943 int
944 mm_player_audio_effect_custom_get_level_range(MMHandleType hplayer, MMAudioEffectCustomType type, int *min, int *max)
945 {
946         mm_player_t* player = (mm_player_t*)hplayer;
947         int result = MM_ERROR_NONE;
948         int count = 1;                  /* start from 1, because of excepting eq index */
949         int ext_level_index = 1;        /* start from 1, because of excepting eq index */
950
951         debug_fenter();
952
953         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
954         return_val_if_fail( min, MM_ERROR_PLAYER_NOT_INITIALIZED );
955         return_val_if_fail( max, MM_ERROR_PLAYER_NOT_INITIALIZED );
956
957         /* check if this effect type is supported */
958         if ( !_mmplayer_is_supported_effect_type( MM_AUDIO_EFFECT_TYPE_CUSTOM, type ) )
959         {
960                 debug_fleave();
961                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
962         }
963
964         if ( type == MM_AUDIO_EFFECT_CUSTOM_EQ )
965         {
966                 *min = PLAYER_INI()->audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
967                 *max = PLAYER_INI()->audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
968                 debug_log("EQ min level = %d, max level = %d", *min, *max);
969         }
970         else
971         {
972                 while ( count < MM_AUDIO_EFFECT_CUSTOM_NUM )
973                 {
974                         if ( PLAYER_INI()->audio_effect_custom_list[count] )
975                         {
976                                 if ( count == type )
977                                 {
978                                         *min = PLAYER_INI()->audio_effect_custom_min_level_list[ext_level_index];
979                                         *max = PLAYER_INI()->audio_effect_custom_max_level_list[ext_level_index];
980                                         debug_msg("Extension effect(%d) min level = %d, max level = %d", count, *min, *max);
981                                         break;
982                                 }
983                                 ext_level_index++;
984                                 if ( ext_level_index == PLAYER_INI()->audio_effect_custom_ext_num + 1 )
985                                 {
986                                         debug_error("could not find min, max value. maybe effect information in ini file is not proper for audio effect plugin");
987                                         break;
988                                 }
989                         }
990                         count++;
991                 }
992         }
993
994         debug_fleave();
995
996         return result;
997 }
998
999
1000 int
1001 mm_player_audio_effect_custom_set_level_eq_from_list(MMHandleType hplayer, int *level_list, int size)
1002 {
1003         mm_player_t *player = (mm_player_t*)hplayer;
1004         gint i = 0;
1005         gint eq_level_min = 0;
1006         gint eq_level_max = 0;
1007         int result = MM_ERROR_NONE;
1008
1009         debug_fenter();
1010
1011         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
1012
1013         /* check if EQ is supported */
1014         if ( !_mmplayer_is_supported_effect_type( MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ ) )
1015         {
1016                 debug_fleave();
1017                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
1018         }
1019
1020         if ( size != PLAYER_INI()->audio_effect_custom_eq_band_num )
1021         {
1022                 debug_error("input size variable(%d) does not match with number of eq band(%d)", size, PLAYER_INI()->audio_effect_custom_eq_band_num);
1023                 result = MM_ERROR_INVALID_ARGUMENT;
1024         }
1025         else
1026         {
1027                 eq_level_min = PLAYER_INI()->audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
1028                 eq_level_max = PLAYER_INI()->audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
1029
1030                 for ( i = 0 ; i < size ; i++ )
1031                 {
1032                         if ( level_list[i] < eq_level_min || level_list[i] > eq_level_max)
1033                         {
1034                                 debug_error("out of range, level[%d]=%d", i, level_list[i]);
1035                                 result = MM_ERROR_INVALID_ARGUMENT;
1036                                 break;
1037                         }
1038                         player->audio_effect_info.custom_eq_level[i] = level_list[i];
1039                 }
1040         }
1041         debug_fleave();
1042
1043         return result;
1044 }