1. Sync 2.4 code to 3.0
[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_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         /* preset */
219         if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET)
220         {
221                 if (player->ini.audio_effect_preset_earphone_only_list[effect])
222                 {
223                         debug_msg("this preset effect(%d) is only available with earphone", effect);
224                         result = TRUE;
225                 }
226         }
227         /* custom */
228         else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM)
229         {
230                 for (i = 1; i < MM_AUDIO_EFFECT_CUSTOM_NUM; i++) /* it starts from 1(except testing for EQ) */
231                 {
232                         if (player->ini.audio_effect_custom_earphone_only_list[i])
233                         {
234                                 /* check if the earphone only custom effect was set */
235                                 if (player->audio_effect_info.custom_ext_level[i-1])
236                                 {
237                                         debug_msg("this custom effect(%d) is only available with earphone", i);
238                                         result = TRUE;
239                                 }
240                         }
241                 }
242         }
243         else
244         {
245                 debug_error("invalid effect type(%d)", effect_type);
246         }
247
248         MMPLAYER_FLEAVE();
249
250         return result;
251 }
252
253 int
254 __mmplayer_audio_set_output_type (mm_player_t *player, MMAudioEffectType effect_type, int effect)
255 {
256         GstElement *audio_effect_element = NULL;
257         mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
258         MMSoundDeviceList_t device_list;
259         MMSoundDevice_t device_h = NULL;
260         mm_sound_device_type_e device_type;
261         int output_type = 0;
262         int result = MM_ERROR_NONE;
263
264         MMPLAYER_FENTER();
265
266         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
267
268         audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
269
270         /* (1) get current device list */
271         result = mm_sound_get_current_device_list(flags, &device_list);
272
273         if ( result ) {
274                 debug_error("mm_sound_get_current_device_list() failed [%x]!!", result);
275                 MMPLAYER_FLEAVE();
276                 return result;
277         }
278
279         /* (2) get device handle of device list */
280         result = mm_sound_get_next_device (device_list, &device_h);
281
282         if ( result ) {
283                 debug_error("mm_sound_get_next_device() failed [%x]!!", result);
284                 MMPLAYER_FLEAVE();
285                 return result;
286         }
287
288         /* (3) get device type */
289         result = mm_sound_get_device_type(device_h, &device_type);
290
291         if ( result ) {
292                 debug_error("mm_sound_get_device_type() failed [%x]!!", result);
293                 MMPLAYER_FLEAVE();
294                 return result;
295         }
296
297         /* SPEAKER case */
298         if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER)
299         {
300                 if ( MM_AUDIO_EFFECT_TYPE_SQUARE != effect_type ) {
301                         if (__mmplayer_is_earphone_only_effect_type(player, effect_type, effect))
302                         {
303                                 debug_error("earphone is not equipped, this filter will not be applied");
304                                 MMPLAYER_FLEAVE();
305                                 return MM_ERROR_PLAYER_SOUND_EFFECT_INVALID_STATUS;
306                         }
307                 }
308
309                 output_type = MM_AUDIO_EFFECT_OUTPUT_SPK;
310         }
311         else if (device_type == MM_SOUND_DEVICE_TYPE_MIRRORING)
312         {
313                 output_type = MM_AUDIO_EFFECT_OUTPUT_OTHERS;
314         }
315         else if (device_type == MM_SOUND_DEVICE_TYPE_HDMI)
316         {
317                 output_type = MM_AUDIO_EFFECT_OUTPUT_HDMI;
318         }
319         else if (device_type == MM_SOUND_DEVICE_TYPE_BLUETOOTH)
320         {
321                 output_type = MM_AUDIO_EFFECT_OUTPUT_BT;
322         }
323         else if (device_type == MM_SOUND_DEVICE_TYPE_USB_AUDIO)
324         {
325                 output_type = MM_AUDIO_EFFECT_OUTPUT_USB_AUDIO;
326         }
327         /* Other case, include WIRED_ACCESSORY */
328         else
329         {
330                 output_type = MM_AUDIO_EFFECT_OUTPUT_EAR;
331         }
332         debug_warning("output_type = %d (0:spk,1:ear,2:others)", output_type);
333
334         /* set filter output mode */
335         g_object_set(audio_effect_element, "filter-output-mode", output_type, NULL);
336
337         return result;
338 }
339
340 gboolean
341 _mmplayer_is_supported_effect_type(mm_player_t* player, MMAudioEffectType effect_type, int effect)
342 {
343         gboolean result = TRUE;
344         mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
345         MMSoundDeviceList_t device_list;
346         MMSoundDevice_t device_h = NULL;
347         mm_sound_device_type_e device_type;
348         int ret = MM_ERROR_NONE;
349
350         MMPLAYER_FENTER();
351
352         /* get status if speaker is activated */
353         /* (1) get current device list */
354         ret = mm_sound_get_current_device_list(flags, &device_list);
355         if (ret) {
356                 MMPLAYER_FLEAVE();
357                 debug_error("mm_sound_get_current_device_list() failed [%x]!!", ret);
358                 return FALSE;
359         }
360
361         /* (2) get device handle of device list */
362         ret = mm_sound_get_next_device (device_list, &device_h);
363
364         if (ret) {
365                 debug_error("mm_sound_get_next_device() failed [%x]!!", ret);
366                 MMPLAYER_FLEAVE();
367                 return FALSE;
368         }
369
370         /* (3) get device type */
371         ret = mm_sound_get_device_type(device_h, &device_type);
372
373         if (ret) {
374                 debug_error("mm_sound_get_device_type() failed [%x]!!", ret);
375                 MMPLAYER_FLEAVE();
376                 return FALSE;
377         }
378
379         /* preset */
380         if (effect_type == MM_AUDIO_EFFECT_TYPE_PRESET)
381         {
382                 if ( effect < MM_AUDIO_EFFECT_PRESET_AUTO || effect >= MM_AUDIO_EFFECT_PRESET_NUM )
383                 {
384                         debug_error("out of range, preset effect(%d)", effect);
385                         result = FALSE;
386                 }
387                 else
388                 {
389                         if (!player->ini.audio_effect_preset_list[effect])
390                         {
391                                 debug_error("this effect(%d) is not supported", effect);
392                                 result = FALSE;
393                         }
394                         else
395                         {
396                                 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
397                                                 player->ini.audio_effect_preset_earphone_only_list[effect])
398                                 {
399                                         result = FALSE;
400                                 }
401                         }
402                 }
403         }
404         /* custom */
405         else if (effect_type == MM_AUDIO_EFFECT_TYPE_CUSTOM)
406         {
407                 if ( effect < MM_AUDIO_EFFECT_CUSTOM_EQ || effect >= MM_AUDIO_EFFECT_CUSTOM_NUM )
408                 {
409                         debug_error("out of range, custom effect(%d)", effect);
410                         result = FALSE;
411                 }
412                 else
413                 {
414                         if (!player->ini.audio_effect_custom_list[effect])
415                         {
416                                 debug_error("this custom effect(%d) is not supported", effect);
417                                 result = FALSE;
418                         }
419                         else
420                         {
421                                 if (device_type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER &&
422                                                 player->ini.audio_effect_custom_earphone_only_list[effect])
423                                 {
424                                         result = FALSE;
425                                 }
426                         }
427                 }
428         }
429         else if (effect_type == MM_AUDIO_EFFECT_TYPE_SQUARE)
430         {
431                 if (!player->ini.use_audio_effect_custom)
432                 {
433                         debug_error("Square effect is not supported");
434                         result = FALSE;
435                 }
436         }
437         else
438         {
439                 debug_error("invalid effect type(%d)", effect_type);
440                 result = FALSE;
441         }
442
443
444         MMPLAYER_FLEAVE();
445
446         return result;
447 }
448
449 int
450 _mmplayer_audio_effect_custom_apply(mm_player_t *player)
451 {
452         GstElement *audio_effect_element = NULL;
453         int result = MM_ERROR_NONE;
454
455         MMPLAYER_FENTER();
456
457         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
458
459         /* Music Player can set audio effect value before Audiobin is created. */
460         if ( !player->pipeline || !player->pipeline->audiobin || !player->pipeline->audiobin[MMPLAYER_A_FILTER].gst )
461         {
462                 debug_warning("effect element is not created yet.");
463
464                 player->bypass_audio_effect = FALSE;
465
466                 /* store audio effect setting in order to apply it when audio effect plugin is created */
467                 player->audio_effect_info.effect_type = MM_AUDIO_EFFECT_TYPE_CUSTOM;
468         }
469         else
470         {
471                 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
472
473                 /* get status if speaker is activated */
474                 result = __mmplayer_audio_set_output_type(player, MM_AUDIO_EFFECT_TYPE_CUSTOM, 0);
475
476                 if ( result != MM_ERROR_NONE) {
477                         debug_error("failed to set output mode");
478                         MMPLAYER_FLEAVE();
479                         return result;
480                 }
481
482                 result = __mmplayer_set_harmony_effect(player, audio_effect_element);
483                 if ( result )
484                 {
485                         debug_error("_set_harmony_effect() failed(%x)", result);
486                         MMPLAYER_FLEAVE();
487                         return result;
488                 }
489         }
490         player->set_mode.rich_audio = TRUE;
491
492         MMPLAYER_FLEAVE();
493
494         return result;
495 }
496
497 int
498 _mmplayer_audio_effect_custom_update_level(mm_player_t *player)
499 {
500         GstElement *audio_effect_element = NULL;
501         int result = MM_ERROR_NONE;
502         int ext_level_index = 0;
503         int count = 1;
504         int i = 0;
505         gint *custom_eq = NULL;
506         gint *custom_ext_effect_level_list = NULL;
507
508         MMPLAYER_FENTER();
509
510         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
511
512         audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
513
514         /* get custom eq effect */
515         g_object_get(audio_effect_element, "custom-eq", &custom_eq, NULL);
516
517         memcpy(player->audio_effect_info.custom_eq_level, custom_eq, sizeof(gint) * player->ini.audio_effect_custom_eq_band_num);
518
519         for (i=0; i<player->ini.audio_effect_custom_eq_band_num;i++)
520         {
521                 debug_log("updated custom-eq [%d] = %d", i, player->audio_effect_info.custom_eq_level[i]);
522         }
523
524         /* get custom ext effect */
525
526         g_object_get(audio_effect_element, "custom-ext", &custom_ext_effect_level_list, NULL);
527
528         while ( count < MM_AUDIO_EFFECT_CUSTOM_NUM )
529         {
530                 if ( player->ini.audio_effect_custom_list[count] )
531                 {
532                         player->audio_effect_info.custom_ext_level[count-1]
533                                 = custom_ext_effect_level_list[ext_level_index];
534                         debug_log("updated custom-ext [%d] = %d", count, player->audio_effect_info.custom_ext_level[count-1]);
535                         ext_level_index++;
536                 }
537                 count++;
538         }
539
540
541         MMPLAYER_FLEAVE();
542         return result;
543 }
544
545
546 int
547 mm_player_audio_effect_custom_clear_eq_all(MMHandleType hplayer)
548 {
549         int result = MM_ERROR_NONE;
550         mm_player_t* player = (mm_player_t*)hplayer;
551
552         MMPLAYER_FENTER();
553
554         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
555
556         /* clear EQ custom effect */
557         memset(player->audio_effect_info.custom_eq_level, MM_AUDIO_EFFECT_CUSTOM_LEVEL_INIT, sizeof(int)*MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX);
558
559         debug_msg("All the EQ bands clearing success");
560
561         MMPLAYER_FLEAVE();
562
563         return result;
564 }
565
566
567 int
568 mm_player_audio_effect_custom_clear_ext_all(MMHandleType hplayer)
569 {
570         int i;
571         int result = MM_ERROR_NONE;
572         mm_player_t* player = (mm_player_t*)hplayer;
573
574         MMPLAYER_FENTER();
575
576         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
577
578         /* clear ALL custom effects, except EQ */
579         for ( i = 0 ; i < MM_AUDIO_EFFECT_CUSTOM_NUM - 1 ; i++ )
580         {
581                 player->audio_effect_info.custom_ext_level[i] = MM_AUDIO_EFFECT_CUSTOM_LEVEL_INIT;
582         }
583
584         debug_msg("All the extension effects clearing success");
585
586         MMPLAYER_FLEAVE();
587
588         return result;
589 }
590
591
592 int
593 mm_player_is_supported_preset_effect_type(MMHandleType hplayer, MMAudioEffectPresetType effect)
594 {
595         mm_player_t* player = (mm_player_t*)hplayer;
596         int result = MM_ERROR_NONE;
597
598         MMPLAYER_FENTER();
599
600         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
601
602         if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_PRESET, effect ) )
603         {
604                 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
605         }
606
607         MMPLAYER_FLEAVE();
608
609         return result;
610 }
611
612
613 int
614 mm_player_is_supported_custom_effect_type(MMHandleType hplayer, MMAudioEffectCustomType effect)
615 {
616         mm_player_t* player = (mm_player_t*)hplayer;
617         int result = MM_ERROR_NONE;
618
619         MMPLAYER_FENTER();
620
621         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
622
623         if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, effect ) )
624         {
625                 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
626         }
627
628         MMPLAYER_FLEAVE();
629
630         return result;
631 }
632
633 int
634 mm_player_audio_effect_custom_apply(MMHandleType hplayer)
635 {
636         mm_player_t* player = (mm_player_t*)hplayer;
637         int result = MM_ERROR_NONE;
638
639         MMPLAYER_FENTER();
640
641         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
642
643         if (!player->ini.use_audio_effect_custom)
644         {
645                 debug_error("audio effect(custom) is not supported");
646                 MMPLAYER_FLEAVE();
647                 return MM_ERROR_NOT_SUPPORT_API;
648         }
649
650         result = _mmplayer_audio_effect_custom_apply(player);
651
652         MMPLAYER_FLEAVE();
653
654         return result;
655 }
656
657
658 int
659 mm_player_audio_effect_bypass (MMHandleType hplayer)
660 {
661         mm_player_t* player = (mm_player_t*)hplayer;
662         int result = MM_ERROR_NONE;
663         GstElement *audio_effect_element = NULL;
664
665         MMPLAYER_FENTER();
666
667         return_val_if_fail(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
668
669         if ( !player->ini.use_audio_effect_preset && !player->ini.use_audio_effect_custom )
670         {
671                 debug_error("audio effect(preset/custom) is not supported");
672                 MMPLAYER_FLEAVE();
673                 return MM_ERROR_NOT_SUPPORT_API;
674         }
675         if ( !player->pipeline || !player->pipeline->audiobin || !player->pipeline->audiobin[MMPLAYER_A_FILTER].gst )
676         {
677                 debug_warning("effect element is not created yet.");
678         }
679         else
680         {
681                 audio_effect_element = player->pipeline->audiobin[MMPLAYER_A_FILTER].gst;
682
683                 /* order action to audio effect plugin */
684                 g_object_set(audio_effect_element, "filter-action", MM_AUDIO_EFFECT_TYPE_NONE, NULL);
685                 debug_log("filter-action = %d", MM_AUDIO_EFFECT_TYPE_NONE);
686         }
687
688         MMPLAYER_FLEAVE();
689
690         return result;
691 }
692
693
694 int
695 _mmplayer_audio_effect_custom_set_level_ext(mm_player_t *player, MMAudioEffectCustomType custom_effect_type, int level)
696 {
697         int effect_level_max = 0;
698         int effect_level_min = 0;
699         int count = 1;                  /* start from 1, because of excepting eq index */
700         int ext_level_index = 1;        /* start from 1, because of excepting eq index */
701         int result = MM_ERROR_NONE;
702
703         MMPLAYER_FENTER();
704
705         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
706
707         /* check if EQ is supported */
708         if ( !_mmplayer_is_supported_effect_type( player,  MM_AUDIO_EFFECT_TYPE_CUSTOM, custom_effect_type ) )
709         {
710                 MMPLAYER_FLEAVE();
711                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
712         }
713
714         while ( count < MM_AUDIO_EFFECT_CUSTOM_NUM )
715         {
716                 if ( player->ini.audio_effect_custom_list[count] )
717                 {
718                         if ( count == custom_effect_type )
719                         {
720                                 effect_level_min = player->ini.audio_effect_custom_min_level_list[ext_level_index];
721                                 effect_level_max = player->ini.audio_effect_custom_max_level_list[ext_level_index];
722                                 debug_msg("level min value(%d), level max value(%d)", effect_level_min, effect_level_max);
723                                 break;
724                         }
725                         ext_level_index++;
726                         if (ext_level_index == player->ini.audio_effect_custom_ext_num + 1)
727                         {
728                                 debug_error("could not find min, max value. maybe effect information in ini file is not proper for audio effect plugin");
729                                 break;
730                         }
731                 }
732                 count++;
733         }
734
735         if ( level < effect_level_min || level > effect_level_max )
736         {
737                 debug_error("out of range, level(%d)", level);
738                 result = MM_ERROR_INVALID_ARGUMENT;
739         }
740         else
741         {
742                 player->audio_effect_info.custom_ext_level[custom_effect_type-1] = level;
743                 debug_msg("set ext[%d] = %d", custom_effect_type-1, level);
744         }
745
746         MMPLAYER_FLEAVE();
747
748         return result;
749 }
750
751
752 int
753 _mmplayer_audio_effect_custom_set_level_eq(mm_player_t *player, int index, int level)
754 {
755         gint eq_level_max = 0;
756         gint eq_level_min = 0;
757         int result = MM_ERROR_NONE;
758
759         MMPLAYER_FENTER();
760
761         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
762
763         /* check if EQ is supported */
764         if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ ) )
765         {
766                 MMPLAYER_FLEAVE();
767                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
768         }
769
770         if ( index < 0 || index > player->ini.audio_effect_custom_eq_band_num - 1 )
771         {
772                 debug_error("out of range, index(%d)", index);
773                 result = MM_ERROR_INVALID_ARGUMENT;
774         }
775         else
776         {
777                 eq_level_min = player->ini.audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
778                 eq_level_max = player->ini.audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
779                 debug_msg("EQ level min value(%d), EQ level max value(%d)", eq_level_min, eq_level_max);
780
781                 if ( level < eq_level_min || level > eq_level_max )
782                 {
783                         debug_error("out of range, EQ level(%d)", level);
784                         result =  MM_ERROR_INVALID_ARGUMENT;
785                 }
786                 else
787                 {
788                         player->audio_effect_info.custom_eq_level[index] = level;
789                         debug_msg("set EQ[%d] = %d", index, level);
790                 }
791         }
792
793         MMPLAYER_FLEAVE();
794
795         return result;
796 }
797
798
799 /* NOTE : parameter eq_index is only used for _set_eq_level() */
800 int
801 mm_player_audio_effect_custom_set_level(MMHandleType hplayer, MMAudioEffectCustomType effect_custom_type, int eq_index, int level)
802 {
803         mm_player_t* player = (mm_player_t*)hplayer;
804         int result = MM_ERROR_NONE;
805
806         MMPLAYER_FENTER();
807
808         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
809
810         /* check if this effect type is supported */
811         if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, effect_custom_type ) )
812         {
813                 result = MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
814         }
815         else
816         {
817                 if (effect_custom_type == MM_AUDIO_EFFECT_CUSTOM_EQ)
818                 {
819                         result = _mmplayer_audio_effect_custom_set_level_eq(player, eq_index, level);
820                 }
821                 else if (effect_custom_type > MM_AUDIO_EFFECT_CUSTOM_EQ && effect_custom_type < MM_AUDIO_EFFECT_CUSTOM_NUM)
822                 {
823                         result = _mmplayer_audio_effect_custom_set_level_ext(player, effect_custom_type, level);
824                 }
825                 else
826                 {
827                         debug_error("out of range, effect type(%d)", effect_custom_type);
828                         result = MM_ERROR_INVALID_ARGUMENT;
829                 }
830         }
831
832         MMPLAYER_FLEAVE();
833
834         return result;
835 }
836
837
838 int
839 mm_player_audio_effect_custom_get_eq_bands_number(MMHandleType hplayer, int *bands)
840 {
841         mm_player_t* player = (mm_player_t*)hplayer;
842         int result = MM_ERROR_NONE;
843
844         MMPLAYER_FENTER();
845
846         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
847
848         /* check if EQ is supported */
849         if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ ) )
850         {
851                 MMPLAYER_FLEAVE();
852                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
853         }
854
855         *bands = player->ini.audio_effect_custom_eq_band_num;
856         debug_log("number of custom EQ band = %d", *bands);
857
858         MMPLAYER_FLEAVE();
859
860         return result;
861 }
862
863
864 int
865 mm_player_audio_effect_custom_get_eq_bands_width(MMHandleType hplayer, int band_idx, int *width)
866 {
867         mm_player_t* player = (mm_player_t*)hplayer;
868         int result = MM_ERROR_NONE;
869         unsigned int eq_num = 0;
870
871         MMPLAYER_FENTER();
872
873         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
874
875         /* check if EQ is supported */
876         if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ ) )
877         {
878                 MMPLAYER_FLEAVE();
879                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
880         }
881
882         eq_num = player->ini.audio_effect_custom_eq_band_num;
883         if (band_idx < 0 || band_idx > eq_num-1)
884         {
885                 debug_error("out of range, invalid band_idx(%d)", band_idx);
886                 result = MM_ERROR_INVALID_ARGUMENT;
887         }
888         else
889         {
890                 /* set the width of EQ band */
891                 *width = player->ini.audio_effect_custom_eq_band_width[band_idx];
892                 debug_log("width of band_idx(%d) = %dHz", band_idx, *width);
893         }
894
895         MMPLAYER_FLEAVE();
896
897         return result;
898 }
899
900
901 int
902 mm_player_audio_effect_custom_get_eq_bands_freq(MMHandleType hplayer, int band_idx, int *freq)
903 {
904         mm_player_t* player = (mm_player_t*)hplayer;
905         int result = MM_ERROR_NONE;
906         unsigned int eq_num = 0;
907
908         MMPLAYER_FENTER();
909
910         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
911
912         /* check if EQ is supported */
913         if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ ) )
914         {
915                 MMPLAYER_FLEAVE();
916                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
917         }
918
919         eq_num = player->ini.audio_effect_custom_eq_band_num;
920         if (band_idx < 0 || band_idx > eq_num-1)
921         {
922                 debug_error("out of range, invalid band_idx(%d)", band_idx);
923                 result = MM_ERROR_INVALID_ARGUMENT;
924         }
925         else
926         {
927                 /* set the frequency of EQ band */
928                 *freq = player->ini.audio_effect_custom_eq_band_freq[band_idx];
929                 debug_log("frequency of band_idx(%d) = %dHz", band_idx, *freq);
930         }
931
932         MMPLAYER_FLEAVE();
933
934         return result;
935 }
936
937
938 int
939 mm_player_audio_effect_custom_get_level(MMHandleType hplayer, MMAudioEffectCustomType type, int eq_index, int *level)
940 {
941         mm_player_t* player = (mm_player_t*)hplayer;
942         int result = MM_ERROR_NONE;
943
944         MMPLAYER_FENTER();
945
946         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
947         return_val_if_fail( level, MM_ERROR_PLAYER_NOT_INITIALIZED );
948
949         /* check if this effect type is supported */
950         if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type ) )
951         {
952                 MMPLAYER_FLEAVE();
953                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
954         }
955
956         if (type == MM_AUDIO_EFFECT_CUSTOM_EQ)
957         {
958                 if ( eq_index < 0 || eq_index > player->ini.audio_effect_custom_eq_band_num - 1 )
959                 {
960                         debug_error("out of range, EQ index(%d)", eq_index);
961                         result = MM_ERROR_INVALID_ARGUMENT;
962                 }
963                 else
964                 {
965                         *level = player->audio_effect_info.custom_eq_level[eq_index];
966                         debug_log("EQ index = %d, level = %d", eq_index, *level);
967                 }
968         }
969         else if ( type > MM_AUDIO_EFFECT_CUSTOM_EQ && type < MM_AUDIO_EFFECT_CUSTOM_NUM )
970         {
971                 *level = player->audio_effect_info.custom_ext_level[type-1];
972                 debug_log("extension effect index = %d, level = %d", type, *level);
973         }
974         else
975         {
976                 debug_error("out of range, type(%d)", type);
977                 result = MM_ERROR_INVALID_ARGUMENT;
978         }
979
980         MMPLAYER_FLEAVE();
981
982         return result;
983 }
984
985
986 int
987 mm_player_audio_effect_custom_get_level_range(MMHandleType hplayer, MMAudioEffectCustomType type, int *min, int *max)
988 {
989         mm_player_t* player = (mm_player_t*)hplayer;
990         int result = MM_ERROR_NONE;
991         int count = 1;                  /* start from 1, because of excepting eq index */
992         int ext_level_index = 1;        /* start from 1, because of excepting eq index */
993
994         MMPLAYER_FENTER();
995
996         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
997         return_val_if_fail( min, MM_ERROR_PLAYER_NOT_INITIALIZED );
998         return_val_if_fail( max, MM_ERROR_PLAYER_NOT_INITIALIZED );
999
1000         /* check if this effect type is supported */
1001         if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, type ) )
1002         {
1003                 MMPLAYER_FLEAVE();
1004                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
1005         }
1006
1007         if ( type == MM_AUDIO_EFFECT_CUSTOM_EQ )
1008         {
1009                 *min = player->ini.audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
1010                 *max = player->ini.audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
1011                 debug_log("EQ min level = %d, max level = %d", *min, *max);
1012         }
1013         else
1014         {
1015                 while ( count < MM_AUDIO_EFFECT_CUSTOM_NUM )
1016                 {
1017                         if ( player->ini.audio_effect_custom_list[count] )
1018                         {
1019                                 if ( count == type )
1020                                 {
1021                                         *min = player->ini.audio_effect_custom_min_level_list[ext_level_index];
1022                                         *max = player->ini.audio_effect_custom_max_level_list[ext_level_index];
1023                                         debug_msg("Extension effect(%d) min level = %d, max level = %d", count, *min, *max);
1024                                         break;
1025                                 }
1026                                 ext_level_index++;
1027                                 if ( ext_level_index == player->ini.audio_effect_custom_ext_num + 1 )
1028                                 {
1029                                         debug_error("could not find min, max value. maybe effect information in ini file is not proper for audio effect plugin");
1030                                         break;
1031                                 }
1032                         }
1033                         count++;
1034                 }
1035         }
1036
1037         MMPLAYER_FLEAVE();
1038
1039         return result;
1040 }
1041
1042
1043 int
1044 mm_player_audio_effect_custom_set_level_eq_from_list(MMHandleType hplayer, int *level_list, int size)
1045 {
1046         mm_player_t *player = (mm_player_t*)hplayer;
1047         gint i = 0;
1048         gint eq_level_min = 0;
1049         gint eq_level_max = 0;
1050         int result = MM_ERROR_NONE;
1051
1052         MMPLAYER_FENTER();
1053
1054         return_val_if_fail( player, MM_ERROR_PLAYER_NOT_INITIALIZED );
1055
1056         /* check if EQ is supported */
1057         if ( !_mmplayer_is_supported_effect_type( player, MM_AUDIO_EFFECT_TYPE_CUSTOM, MM_AUDIO_EFFECT_CUSTOM_EQ ) )
1058         {
1059                 MMPLAYER_FLEAVE();
1060                 return MM_ERROR_PLAYER_SOUND_EFFECT_NOT_SUPPORTED_FILTER;
1061         }
1062
1063         if ( size != player->ini.audio_effect_custom_eq_band_num )
1064         {
1065                 debug_error("input size variable(%d) does not match with number of eq band(%d)", size, player->ini.audio_effect_custom_eq_band_num);
1066                 result = MM_ERROR_INVALID_ARGUMENT;
1067         }
1068         else
1069         {
1070                 eq_level_min = player->ini.audio_effect_custom_min_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
1071                 eq_level_max = player->ini.audio_effect_custom_max_level_list[MM_AUDIO_EFFECT_CUSTOM_EQ];
1072
1073                 for ( i = 0 ; i < size ; i++ )
1074                 {
1075                         if ( level_list[i] < eq_level_min || level_list[i] > eq_level_max)
1076                         {
1077                                 debug_error("out of range, level[%d]=%d", i, level_list[i]);
1078                                 result = MM_ERROR_INVALID_ARGUMENT;
1079                                 break;
1080                         }
1081                         player->audio_effect_info.custom_eq_level[i] = level_list[i];
1082                 }
1083         }
1084         MMPLAYER_FLEAVE();
1085
1086         return result;
1087 }