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