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