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