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