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