Merge "apply tizen coding rules" into tizen
[platform/core/multimedia/libmm-player.git] / src / mm_player_ini.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>,
7  * Seungbae Shin <seungbae.shin@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23 #ifndef __MM_PLAYER_INI_C__
24 #define __MM_PLAYER_INI_C__
25
26 /* includes here */
27 #include <dlog.h>
28 #include <glib.h>
29 #include <stdlib.h>
30 #include "iniparser.h"
31 #include <mm_player_ini.h>
32 #include <mm_error.h>
33 #include <glib/gstdio.h>
34
35 /* internal functions, macros here */
36 #ifdef MM_PLAYER_DEFAULT_INI
37 static gboolean __generate_default_ini(void);
38 #endif
39 static void     __get_element_list(mm_player_ini_t* ini, gchar* str, int keyword_type);
40
41 static void __mm_player_ini_check_ini_status(void);
42
43 /* macro */
44 #define MMPLAYER_INI_GET_STRING(x_dict, x_item, x_ini, x_default) \
45 do { \
46         gchar* str = iniparser_getstring(x_dict, x_ini, x_default); \
47         if (str &&  \
48                 (strlen(str) > 0) && \
49                 (strlen(str) < PLAYER_INI_MAX_STRLEN)) \
50                 strncpy(x_item, str, PLAYER_INI_MAX_STRLEN-1); \
51         else \
52                 strncpy(x_item, x_default, PLAYER_INI_MAX_STRLEN-1); \
53 } while (0)
54
55 #define MMPLAYER_INI_GET_COLOR(x_dict, x_item, x_ini, x_default) \
56 do { \
57         gchar* str = iniparser_getstring(x_dict, x_ini, x_default); \
58         if (str &&  \
59                 (strlen(str) > 0) && \
60                 (strlen(str) < PLAYER_INI_MAX_STRLEN)) \
61                 x_item = (guint) strtoul(str, NULL, 16); \
62         else \
63                 x_item = (guint) strtoul(x_default, NULL, 16); \
64 } while (0)
65
66 /* x_ini is the list of index to set TRUE at x_list[index] */
67 #define MMPLAYER_INI_GET_BOOLEAN_FROM_LIST(x_dict, x_list, x_list_max, x_ini, x_default) \
68 do { \
69                 int index = 0; \
70                 const char *delimiters = " ,"; \
71                 char *usr_ptr = NULL; \
72                 char *token = NULL; \
73                 gchar temp_arr[PLAYER_INI_MAX_STRLEN] = {0}; \
74                 MMPLAYER_INI_GET_STRING(x_dict, temp_arr, x_ini, x_default); \
75                 token = strtok_r(temp_arr, delimiters, &usr_ptr); \
76                 while (token) { \
77                         index = atoi(token); \
78                         if (index < 0 || index > x_list_max -1) \
79                                 LOGW("%d is not valid index\n", index); \
80                         else \
81                                 x_list[index] = TRUE; \
82                         token = strtok_r(NULL, delimiters, &usr_ptr); \
83                 } \
84 } while (0)
85
86 /* x_ini is the list of value to be set at x_list[index] */
87 #define MMPLAYER_INI_GET_INT_FROM_LIST(x_dict, x_list, x_list_max, x_ini, x_default) \
88 do { \
89                 int index = 0; \
90                 int value = 0; \
91                 const char *delimiters = " ,"; \
92                 char *usr_ptr = NULL; \
93                 char *token = NULL; \
94                 gchar temp_arr[PLAYER_INI_MAX_STRLEN] = {0}; \
95                 MMPLAYER_INI_GET_STRING(x_dict, temp_arr, x_ini, x_default); \
96                 token = strtok_r(temp_arr, delimiters, &usr_ptr); \
97                 while (token) { \
98                         if (index > x_list_max -1) { \
99                                 LOGE("%d is not valid index\n", index); \
100                                 break; \
101                         } else { \
102                                 value = atoi(token); \
103                                 x_list[index] = value; \
104                                 index++; \
105                         } \
106                         token = strtok_r(NULL, delimiters, &usr_ptr); \
107                 } \
108 } while (0)
109
110 int
111 mm_player_ini_load(mm_player_ini_t* ini)
112 {
113         dictionary * dict = NULL;
114         gint idx = 0;
115
116         __mm_player_ini_check_ini_status();
117
118         /* first, try to load existing ini file */
119         dict = iniparser_load(MM_PLAYER_INI_DEFAULT_PATH);
120
121         /* if no file exists. create one with set of default values */
122         if (!dict) {
123 #ifdef MM_PLAYER_DEFAULT_INI
124                 LOGD("No inifile found. player will create default inifile.\n");
125                 if (FALSE == __generate_default_ini())
126                         LOGW("Creating default inifile failed. Player will use default values.\n");
127                 else
128                         dict = iniparser_load(MM_PLAYER_INI_DEFAULT_PATH);      /* load default ini */
129 #else
130                 LOGD("No ini file found. \n");
131                 return MM_ERROR_FILE_NOT_FOUND;
132 #endif
133         }
134
135         /* get ini values */
136         memset(ini, 0, sizeof(mm_player_ini_t));
137
138         if (dict) {
139                 /* if dict is available */
140                 /* general */
141                 ini->disable_segtrap = iniparser_getboolean(dict, "general:disable segtrap", DEFAULT_DISABLE_SEGTRAP);
142                 ini->skip_rescan = iniparser_getboolean(dict, "general:skip rescan", DEFAULT_SKIP_RESCAN);
143                 ini->generate_dot = iniparser_getboolean(dict, "general:generate dot", DEFAULT_GENERATE_DOT);
144                 ini->use_system_clock = iniparser_getboolean(dict, "general:use system clock", DEFAULT_USE_SYSTEM_CLOCK);
145                 ini->live_state_change_timeout = iniparser_getint(dict, "general:live state change timeout", DEFAULT_LIVE_STATE_CHANGE_TIMEOUT);
146                 ini->localplayback_state_change_timeout = iniparser_getint(dict, "general:localplayback state change timeout", DEFAULT_LOCALPLAYBACK_STATE_CHANGE_TIMEOUT);
147                 ini->eos_delay = iniparser_getint(dict, "general:eos delay", DEFAULT_EOS_DELAY);
148                 ini->async_start = iniparser_getboolean(dict, "general:async start", DEFAULT_ASYNC_START);
149                 ini->video_playback_supported = iniparser_getboolean(dict, "general:video playback supported", DEFAULT_VIDEO_PLAYBACK_SUPPORTED);
150                 ini->delay_before_repeat = iniparser_getint(dict, "general:delay before repeat", DEFAULT_DELAY_BEFORE_REPEAT);
151                 ini->pcm_buffer_size = iniparser_getint(dict, "general:pcm buffer size", DEFAULT_PCM_BUFFER_SIZE);
152                 ini->num_of_video_bo = iniparser_getint(dict, "general:video bo max", DEFAULT_NUM_OF_VIDEO_BO);
153                 ini->video_bo_timeout = iniparser_getint(dict, "general:video bo timeout", DEFAULT_TIMEOUT_OF_VIDEO_BO);
154
155                 MMPLAYER_INI_GET_STRING(dict, ini->videosink_element_overlay, "general:videosink element overlay", DEFAULT_VIDEOSINK_OVERLAY);
156                 MMPLAYER_INI_GET_STRING(dict, ini->videosink_element_evas, "general:videosink element evas", DEFAULT_VIDEOSINK_EVAS);
157                 MMPLAYER_INI_GET_STRING(dict, ini->videosink_element_fake, "general:videosink element fake", DEFAULT_VIDEOSINK_FAKE);
158                 MMPLAYER_INI_GET_STRING(dict, ini->audioresampler_element, "general:audio resampler element", DEFAULT_AUDIORESAMPLER);
159                 MMPLAYER_INI_GET_STRING(dict, ini->audiosink_element, "general:audiosink element", DEFAULT_AUDIOSINK);
160                 MMPLAYER_INI_GET_STRING(dict, ini->videocodec_element_hw, "general:video codec element hw", DEFAULT_VIDEOCODEC_HW);
161                 MMPLAYER_INI_GET_STRING(dict, ini->videoconverter_element, "general:video converter element", DEFAULT_VIDEO_CONVERTER);
162
163                 __get_element_list(ini,
164                         iniparser_getstring(dict, "general:element exclude keyword", DEFAULT_EXCLUDE_KEYWORD), KEYWORD_EXCLUDE);
165
166                 MMPLAYER_INI_GET_STRING(dict, ini->gst_param[0], "general:gstparam1", DEFAULT_GST_PARAM);
167                 MMPLAYER_INI_GET_STRING(dict, ini->gst_param[1], "general:gstparam2", DEFAULT_GST_PARAM);
168                 MMPLAYER_INI_GET_STRING(dict, ini->gst_param[2], "general:gstparam3", DEFAULT_GST_PARAM);
169                 MMPLAYER_INI_GET_STRING(dict, ini->gst_param[3], "general:gstparam4", DEFAULT_GST_PARAM);
170                 MMPLAYER_INI_GET_STRING(dict, ini->gst_param[4], "general:gstparam5", DEFAULT_GST_PARAM);
171
172                 /* http streaming */
173                 MMPLAYER_INI_GET_STRING(dict, ini->httpsrc_element, "http streaming:httpsrc element", DEFAULT_HTTPSRC);
174                 ini->http_use_file_buffer = iniparser_getboolean(dict, "http streaming:http use file buffer", DEFAULT_HTTP_USE_FILE_BUFFER);
175                 ini->http_ring_buffer_size = iniparser_getint(dict, "http streaming:http ring buffer size", DEFAULT_HTTP_RING_BUFFER_SIZE);
176                 ini->http_buffering_limit = iniparser_getdouble(dict, "http streaming:http buffering high limit", DEFAULT_HTTP_BUFFERING_LIMIT);
177                 ini->http_max_size_bytes = iniparser_getint(dict, "http streaming:http max size bytes", DEFAULT_HTTP_MAX_SIZE_BYTES);
178                 ini->http_buffering_time = iniparser_getdouble(dict, "http streaming:http buffering time", DEFAULT_HTTP_BUFFERING_TIME);
179                 ini->http_timeout = iniparser_getint(dict, "http streaming:http timeout", DEFAULT_HTTP_TIMEOUT);
180
181                 /* dump buffer for debug */
182                 __get_element_list(ini,
183                         iniparser_getstring(dict, "general:dump element keyword", DEFAULT_EXCLUDE_KEYWORD), KEYWORD_DUMP);
184
185                 MMPLAYER_INI_GET_STRING(dict, ini->dump_element_path, "general:dump element path", DEFAULT_DUMP_ELEMENT_PATH);
186         } else {
187                 /* if dict is not available just fill the structure with default value */
188                 LOGW("failed to load ini. using hardcoded default\n");
189
190                 /* general */
191                 ini->disable_segtrap = DEFAULT_DISABLE_SEGTRAP;
192                 ini->skip_rescan = DEFAULT_SKIP_RESCAN;
193                 strncpy(ini->videosink_element_overlay, DEFAULT_VIDEOSINK_OVERLAY, PLAYER_INI_MAX_STRLEN - 1);
194                 strncpy(ini->videosink_element_evas, DEFAULT_VIDEOSINK_EVAS, PLAYER_INI_MAX_STRLEN - 1);
195                 strncpy(ini->videosink_element_fake, DEFAULT_VIDEOSINK_FAKE, PLAYER_INI_MAX_STRLEN - 1);
196                 ini->generate_dot = DEFAULT_GENERATE_DOT;
197                 ini->use_system_clock = DEFAULT_USE_SYSTEM_CLOCK;
198                 ini->live_state_change_timeout = DEFAULT_LIVE_STATE_CHANGE_TIMEOUT;
199                 ini->localplayback_state_change_timeout = DEFAULT_LOCALPLAYBACK_STATE_CHANGE_TIMEOUT;
200                 ini->eos_delay = DEFAULT_EOS_DELAY;
201                 ini->async_start = DEFAULT_ASYNC_START;
202                 ini->delay_before_repeat = DEFAULT_DELAY_BEFORE_REPEAT;
203                 ini->video_playback_supported = DEFAULT_VIDEO_PLAYBACK_SUPPORTED;
204                 ini->pcm_buffer_size = DEFAULT_PCM_BUFFER_SIZE;
205                 ini->num_of_video_bo = DEFAULT_NUM_OF_VIDEO_BO;
206                 ini->video_bo_timeout = DEFAULT_TIMEOUT_OF_VIDEO_BO;
207
208                 strncpy(ini->audioresampler_element, DEFAULT_AUDIORESAMPLER, PLAYER_INI_MAX_STRLEN -1);
209                 strncpy(ini->audiosink_element, DEFAULT_AUDIOSINK, PLAYER_INI_MAX_STRLEN -1);
210                 strncpy(ini->videocodec_element_hw, DEFAULT_VIDEOCODEC_HW, PLAYER_INI_MAX_STRLEN - 1);
211                 strncpy(ini->videoconverter_element, DEFAULT_VIDEO_CONVERTER, PLAYER_INI_MAX_STRLEN -1);
212
213                 __get_element_list(ini, DEFAULT_EXCLUDE_KEYWORD, KEYWORD_EXCLUDE);
214
215                 strncpy(ini->gst_param[0], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1);
216                 strncpy(ini->gst_param[1], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1);
217                 strncpy(ini->gst_param[2], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1);
218                 strncpy(ini->gst_param[3], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1);
219                 strncpy(ini->gst_param[4], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1);
220
221                 /* http streaming */
222                 strncpy(ini->httpsrc_element, DEFAULT_HTTPSRC, PLAYER_INI_MAX_STRLEN - 1);
223                 ini->http_buffering_limit = DEFAULT_HTTP_BUFFERING_LIMIT;
224                 ini->http_use_file_buffer = DEFAULT_HTTP_USE_FILE_BUFFER;
225                 ini->http_ring_buffer_size = DEFAULT_HTTP_RING_BUFFER_SIZE;
226                 ini->http_max_size_bytes = DEFAULT_HTTP_MAX_SIZE_BYTES;
227                 ini->http_buffering_time = DEFAULT_HTTP_BUFFERING_TIME;
228                 ini->http_timeout = DEFAULT_HTTP_TIMEOUT;
229
230                 /* dump buffer for debug */
231                 __get_element_list(ini, DEFAULT_DUMP_ELEMENT_KEYWORD, KEYWORD_DUMP);
232                 strncpy(ini->dump_element_path, DEFAULT_DUMP_ELEMENT_PATH, PLAYER_INI_MAX_STRLEN - 1);
233         }
234
235         /* free dict as we got our own structure */
236         iniparser_freedict(dict);
237
238         /* dump structure */
239         LOGD("player settings -----------------------------------\n");
240
241         /* general */
242         LOGD("disable segtrap : %d\n", ini->disable_segtrap);
243         LOGD("skip rescan : %d\n", ini->skip_rescan);
244         LOGD("videosink element overlay: %s\n", ini->videosink_element_overlay);
245         LOGD("videosink element evas: %s\n", ini->videosink_element_evas);
246         LOGD("videosink element fake: %s\n", ini->videosink_element_fake);
247         LOGD("video converter element : %s\n", ini->videoconverter_element);
248         LOGD("video codec element(hw) : %s\n", ini->videocodec_element_hw);
249         LOGD("audio resampler element : %s\n", ini->audioresampler_element);
250         LOGD("audiosink element : %s\n", ini->audiosink_element);
251         LOGD("generate dot : %d\n", ini->generate_dot);
252         LOGD("use system clock(video only) : %d\n", ini->use_system_clock);
253         LOGD("live state change timeout(sec) : %d\n", ini->live_state_change_timeout);
254         LOGD("localplayback state change timeout(sec) : %d\n", ini->localplayback_state_change_timeout);
255         LOGD("eos_delay(msec) : %d\n", ini->eos_delay);
256         LOGD("delay before repeat(msec) : %d\n", ini->delay_before_repeat);
257         LOGD("async_start : %d\n", ini->async_start);
258         LOGD("video_playback_supported : %d\n", ini->video_playback_supported);
259         LOGD("pcm buffer size(bytes) : %d\n", ini->pcm_buffer_size);
260         LOGD("num of video bo : %d\n", ini->num_of_video_bo);
261         LOGD("video bo timeout : %d\n", ini->video_bo_timeout);
262         LOGD("gst param1 : %s\n", ini->gst_param[0]);
263         LOGD("gst param2 : %s\n", ini->gst_param[1]);
264         LOGD("gst param3 : %s\n", ini->gst_param[2]);
265         LOGD("gst param4 : %s\n", ini->gst_param[3]);
266         LOGD("gst param5 : %s\n", ini->gst_param[4]);
267
268         for (idx = 0; ini->exclude_element_keyword[idx][0] != '\0'; idx++)
269                 LOGD("exclude_element_keyword [%d] : %s\n", idx, ini->exclude_element_keyword[idx]);
270
271         for (idx = 0; ini->dump_element_keyword[idx][0] != '\0'; idx++)
272                 LOGD("dump_element_keyword [%d] : %s\n", idx, ini->dump_element_keyword[idx]);
273
274         /* http streaming */
275         LOGD("httpsrc element : %s\n", ini->httpsrc_element);
276         LOGD("http buffering limit : %f \n", ini->http_buffering_limit);
277         LOGD("http use file buffer : %d \n", ini->http_use_file_buffer);
278         LOGD("http ring buffer size : %d \n", ini->http_ring_buffer_size);
279         LOGD("http max_size bytes : %d \n", ini->http_max_size_bytes);
280         LOGD("http buffering time : %f \n", ini->http_buffering_time);
281         LOGD("http timeout : %d \n", ini->http_timeout);
282
283         return MM_ERROR_NONE;
284 }
285
286 int
287 mm_player_audio_effect_ini_load(mm_player_ini_t* ini)
288 {
289         dictionary * dict_audioeffect = NULL;
290
291         dict_audioeffect = iniparser_load(MM_PLAYER_INI_DEFAULT_AUDIOEFFECT_PATH);
292         if (!dict_audioeffect) {
293                 LOGE("No audio effect ini file found. \n");
294                 return MM_ERROR_FILE_NOT_FOUND;
295         }
296
297         /* audio effect element name */
298         MMPLAYER_INI_GET_STRING(dict_audioeffect, ini->audioeffect_element, "audio effect:audio effect element", DEFAULT_AUDIO_EFFECT_ELEMENT);
299         if (!ini->audioeffect_element[0]) {
300                 LOGW("could not parse name of audio effect. \n");
301                 iniparser_freedict(dict_audioeffect);
302                 /* NOTE : in this case, we are not going to create audio filter element */
303                 return MM_ERROR_NONE;
304         }
305
306         /* audio effect (Preset)*/
307         ini->use_audio_effect_preset = iniparser_getboolean(dict_audioeffect, "audio effect:audio effect preset", DEFAULT_USE_AUDIO_EFFECT_PRESET);
308         if (ini->use_audio_effect_preset) {
309                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST(dict_audioeffect, ini->audio_effect_preset_list, MM_AUDIO_EFFECT_PRESET_NUM,
310                                 "audio effect:audio effect preset list", DEFAULT_AUDIO_EFFECT_PRESET_LIST);
311                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST(dict_audioeffect, ini->audio_effect_preset_earphone_only_list, MM_AUDIO_EFFECT_PRESET_NUM,
312                                 "audio effect:audio effect preset earphone only", DEFAULT_AUDIO_EFFECT_PRESET_LIST_EARPHONE_ONLY);
313         }
314
315         /* audio effect user (EQ / Extension effects) */
316         ini->use_audio_effect_custom = iniparser_getboolean(dict_audioeffect, "audio effect:audio effect custom", DEFAULT_USE_AUDIO_EFFECT_CUSTOM);
317         if (ini->use_audio_effect_custom) {
318                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST(dict_audioeffect, ini->audio_effect_custom_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
319                                 "audio effect:audio effect custom list", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST);
320                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST(dict_audioeffect, ini->audio_effect_custom_earphone_only_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
321                                 "audio effect:audio effect custom earphone only", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST_EARPHONE_ONLY);
322
323                 /* audio effect custom : EQ */
324                 if (ini->audio_effect_custom_list[MM_AUDIO_EFFECT_CUSTOM_EQ]) {
325                         ini->audio_effect_custom_eq_band_num = iniparser_getint(dict_audioeffect, "audio effect:audio effect custom eq band num",
326                                         DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_NUM);
327                         if (ini->audio_effect_custom_eq_band_num < DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_NUM ||
328                                         ini->audio_effect_custom_eq_band_num > MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX) {
329                                 LOGE("audio_effect_custom_eq_band_num(%d) is not valid range(%d - %d), set the value %d",
330                                         ini->audio_effect_custom_eq_band_num, DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_NUM, MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX, DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_NUM);
331                                 ini->audio_effect_custom_eq_band_num = DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_NUM;
332
333                                 iniparser_freedict(dict_audioeffect);
334                                 return MM_ERROR_PLAYER_INTERNAL;
335                         } else {
336                                 if (ini->audio_effect_custom_eq_band_num) {
337                                         MMPLAYER_INI_GET_INT_FROM_LIST(dict_audioeffect, ini->audio_effect_custom_eq_band_width, MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX,
338                                                         "audio effect:audio effect custom eq band width", DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_WIDTH);
339                                         MMPLAYER_INI_GET_INT_FROM_LIST(dict_audioeffect, ini->audio_effect_custom_eq_band_freq, MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX,
340                                                         "audio effect:audio effect custom eq band freq", DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_FREQ);
341                                 }
342                         }
343                 }
344
345                 /* audio effect custom : Extension effects */
346                 ini->audio_effect_custom_ext_num = iniparser_getint(dict_audioeffect, "audio effect:audio effect custom ext num",
347                                 DEFAULT_AUDIO_EFFECT_CUSTOM_EXT_NUM);
348
349                 /* Min/Max value list of EQ / Extension effects */
350                 if (ini->audio_effect_custom_eq_band_num || ini->audio_effect_custom_ext_num) {
351                         MMPLAYER_INI_GET_INT_FROM_LIST(dict_audioeffect, ini->audio_effect_custom_min_level_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
352                                         "audio effect:audio effect custom min list", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST);
353                         MMPLAYER_INI_GET_INT_FROM_LIST(dict_audioeffect, ini->audio_effect_custom_max_level_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
354                                         "audio effect:audio effect custom max list", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST);
355                 }
356         }
357
358         /* audio effect element name */
359         MMPLAYER_INI_GET_STRING(dict_audioeffect, ini->audioeffect_element_custom, "audio effect:audio effect element custom", DEFAULT_AUDIO_EFFECT_ELEMENT);
360         if (!ini->audioeffect_element_custom[0])
361                 LOGW("no secondary audio effect \n");
362         else
363                 LOGD("audioeffect element custom : %s\n", ini->audioeffect_element_custom);
364
365         /* dump structure */
366         LOGD("audioeffect element : %s\n", ini->audioeffect_element);
367         LOGD("audio effect preset mode : %d\n", ini->use_audio_effect_preset);
368         LOGD("audio effect custom mode : %d\n", ini->use_audio_effect_custom);
369 #if 0 // debug
370         int i;
371         for (i = 0; i < MM_AUDIO_EFFECT_PRESET_NUM; i++)
372                 LOGD("audio_effect_preset_list: %d (is it for earphone only?(%d))\n", ini->audio_effect_preset_list[i], ini->audio_effect_preset_earphone_only_list[i]);
373
374         for (i = 0; i < MM_AUDIO_EFFECT_CUSTOM_NUM; i++)
375                 LOGD("audio_effect_custom_list : %d (is it for earphone only?(%d))\n", ini->audio_effect_custom_list[i], ini->audio_effect_custom_earphone_only_list[i]);
376         LOGD("audio_effect_custom : eq_band_num(%d), ext_num(%d)\n", ini->audio_effect_custom_eq_band_num, ini->audio_effect_custom_ext_num);
377         LOGD("audio_effect_custom_EQ : width(Hz) / central frequency(Hz)");
378         for (i = 0; i < ini->audio_effect_custom_eq_band_num; i++)
379                 LOGD("     EQ band index(%d) :  %8d / %8d", i, ini->audio_effect_custom_eq_band_width[i], ini->audio_effect_custom_eq_band_freq[i]);
380         for (i = 0; i < MM_AUDIO_EFFECT_CUSTOM_NUM; i++)
381                 LOGD("audio_effect_custom_level_min_max(idx:%d) : Min(%d), Max(%d)\n", i, ini->audio_effect_custom_min_level_list[i], ini->audio_effect_custom_max_level_list[i]);
382 #endif
383         iniparser_freedict(dict_audioeffect);
384
385         return MM_ERROR_NONE;
386
387 }
388
389 static
390 void __mm_player_ini_check_ini_status(void)
391 {
392         struct stat ini_buff;
393
394         if (g_stat(MM_PLAYER_INI_DEFAULT_PATH, &ini_buff) < 0) {
395                 LOGW("failed to get player ini status\n");
396         } else {
397                 if (ini_buff.st_size < 5) {
398                         LOGW("player.ini file size=%d, Corrupted!So, Removed\n", (int)ini_buff.st_size);
399
400                         if (g_remove(MM_PLAYER_INI_DEFAULT_PATH) == -1)
401                                 LOGE("failed to delete corrupted ini");
402                 }
403         }
404 }
405
406 #ifdef MM_PLAYER_DEFAULT_INI
407 static
408 gboolean __generate_default_ini(void)
409 {
410         FILE* fp = NULL;
411         gchar* default_ini = MM_PLAYER_DEFAULT_INI;
412
413
414         /* create new file */
415         fp = fopen(MM_PLAYER_INI_DEFAULT_PATH, "wt");
416
417         if (!fp)
418                 return FALSE;
419
420         /* writing default ini file */
421         if (strlen(default_ini) != fwrite(default_ini, 1, strlen(default_ini), fp)) {
422                 fclose(fp);
423                 return FALSE;
424         }
425
426         fclose(fp);
427         return TRUE;
428 }
429 #endif
430
431 static
432 void __get_element_list(mm_player_ini_t* ini, gchar* str, int keyword_type)
433 {
434         gchar** list = NULL;
435         gchar** walk = NULL;
436         gint i = 0;
437         gchar* strtmp = NULL;
438
439         if (!str)
440                 return;
441
442         if (strlen(str) < 1)
443                 return;
444
445         strtmp = g_strdup(str);
446
447         /* trimming. it works inplace */
448         g_strstrip(strtmp);
449
450
451         /* split */
452         list = g_strsplit(strtmp, ",", 10);
453
454         if (!list) {
455                 if (strtmp)
456                         g_free(strtmp);
457
458                 return;
459         }
460
461         /* copy list */
462         switch (keyword_type) {
463         case KEYWORD_EXCLUDE:
464         {
465                 for (walk = list; *walk; walk++) {
466                         strncpy(ini->exclude_element_keyword[i], *walk, (PLAYER_INI_MAX_STRLEN - 1));
467
468                         g_strstrip(ini->exclude_element_keyword[i]);
469
470                         ini->exclude_element_keyword[i][PLAYER_INI_MAX_STRLEN -1] = '\0';
471
472                         i++;
473                 }
474                 /* mark last item to NULL */
475                 ini->exclude_element_keyword[i][0] = '\0';
476
477                 break;
478         }
479         case KEYWORD_DUMP:
480         {
481                 for (walk = list; *walk; walk++) {
482                         strncpy(ini->dump_element_keyword[i], *walk, (PLAYER_INI_MAX_STRLEN - 1));
483
484                         g_strstrip(ini->dump_element_keyword[i]);
485
486                         ini->dump_element_keyword[i][PLAYER_INI_MAX_STRLEN -1] = '\0';
487
488                         i++;
489                 }
490                 /* mark last item to NULL */
491                 ini->dump_element_keyword[i][0] = '\0';
492
493                 break;
494         }
495         default:
496                 break;
497         }
498
499         g_strfreev(list);
500         if (strtmp)
501                 g_free(strtmp);
502 }
503
504 #endif