fixed building failure
[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->audioresampler_element, "general:audio resampler element", DEFAULT_AUDIORESAMPLER);
156                 MMPLAYER_INI_GET_STRING(dict, ini->audiocodec_element_hw, "general:audio codec element hw", DEFAULT_CODEC_HW);
157                 MMPLAYER_INI_GET_STRING(dict, ini->audiosink_element, "general:audiosink element", DEFAULT_AUDIOSINK);
158
159                 MMPLAYER_INI_GET_STRING(dict, ini->videosink_element_overlay, "general:videosink element overlay", DEFAULT_VIDEOSINK_OVERLAY);
160                 MMPLAYER_INI_GET_STRING(dict, ini->videosink_element_fake, "general:videosink element fake", DEFAULT_VIDEOSINK_FAKE);
161                 MMPLAYER_INI_GET_STRING(dict, ini->videocodec_element_hw, "general:video codec element hw", DEFAULT_CODEC_HW);
162                 MMPLAYER_INI_GET_STRING(dict, ini->videoconverter_element, "general:video converter element", DEFAULT_VIDEO_CONVERTER);
163
164                 __get_element_list(ini,
165                         iniparser_getstring(dict, "general:audio codec element sw", DEFAULT_CODEC_SW), KEYWORD_A_SW_CODEC);
166
167                 __get_element_list(ini,
168                         iniparser_getstring(dict, "general:video codec element sw", DEFAULT_CODEC_SW), KEYWORD_V_SW_CODEC);
169
170                 __get_element_list(ini,
171                         iniparser_getstring(dict, "general:element exclude keyword", DEFAULT_EXCLUDE_KEYWORD), KEYWORD_EXCLUDE);
172
173                 MMPLAYER_INI_GET_STRING(dict, ini->gst_param[0], "general:gstparam1", DEFAULT_GST_PARAM);
174                 MMPLAYER_INI_GET_STRING(dict, ini->gst_param[1], "general:gstparam2", DEFAULT_GST_PARAM);
175                 MMPLAYER_INI_GET_STRING(dict, ini->gst_param[2], "general:gstparam3", DEFAULT_GST_PARAM);
176                 MMPLAYER_INI_GET_STRING(dict, ini->gst_param[3], "general:gstparam4", DEFAULT_GST_PARAM);
177                 MMPLAYER_INI_GET_STRING(dict, ini->gst_param[4], "general:gstparam5", DEFAULT_GST_PARAM);
178
179                 /* http streaming */
180                 MMPLAYER_INI_GET_STRING(dict, ini->httpsrc_element, "http streaming:httpsrc element", DEFAULT_HTTPSRC);
181                 ini->http_use_file_buffer = iniparser_getboolean(dict, "http streaming:http use file buffer", DEFAULT_HTTP_USE_FILE_BUFFER);
182                 ini->http_ring_buffer_size = iniparser_getint(dict, "http streaming:http ring buffer size", DEFAULT_HTTP_RING_BUFFER_SIZE);
183                 ini->http_buffering_limit = iniparser_getdouble(dict, "http streaming:http buffering high limit", DEFAULT_HTTP_BUFFERING_LIMIT);
184                 ini->http_max_size_bytes = iniparser_getint(dict, "http streaming:http max size bytes", DEFAULT_HTTP_MAX_SIZE_BYTES);
185                 ini->http_buffering_time = (gint)(iniparser_getdouble(dict, "http streaming:http buffering time", DEFAULT_HTTP_BUFFERING_TIME) * 1000);
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\n");
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
224                 strncpy(ini->gst_param[0], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1);
225                 strncpy(ini->gst_param[1], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1);
226                 strncpy(ini->gst_param[2], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1);
227                 strncpy(ini->gst_param[3], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1);
228                 strncpy(ini->gst_param[4], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1);
229
230                 /* http streaming */
231                 strncpy(ini->httpsrc_element, DEFAULT_HTTPSRC, PLAYER_INI_MAX_STRLEN - 1);
232                 ini->http_buffering_limit = DEFAULT_HTTP_BUFFERING_LIMIT;
233                 ini->http_use_file_buffer = DEFAULT_HTTP_USE_FILE_BUFFER;
234                 ini->http_ring_buffer_size = DEFAULT_HTTP_RING_BUFFER_SIZE;
235                 ini->http_max_size_bytes = DEFAULT_HTTP_MAX_SIZE_BYTES;
236                 ini->http_buffering_time = (gint)(DEFAULT_HTTP_BUFFERING_TIME*1000);
237                 ini->http_timeout = DEFAULT_HTTP_TIMEOUT;
238
239                 /* dump buffer for debug */
240                 __get_element_list(ini, DEFAULT_DUMP_ELEMENT_KEYWORD, KEYWORD_DUMP);
241                 strncpy(ini->dump_element_path, DEFAULT_DUMP_ELEMENT_PATH, PLAYER_INI_MAX_STRLEN - 1);
242         }
243
244         /* free dict as we got our own structure */
245         iniparser_freedict(dict);
246
247         /* dump structure */
248         LOGD("player settings -----------------------------------\n");
249
250         /* general */
251         LOGD("disable segtrap : %d\n", ini->disable_segtrap);
252         LOGD("skip rescan : %d\n", ini->skip_rescan);
253         LOGD("videosink element overlay: %s\n", ini->videosink_element_overlay);
254         LOGD("videosink element fake: %s\n", ini->videosink_element_fake);
255         LOGD("video converter element : %s\n", ini->videoconverter_element);
256         LOGD("video codec element(hw) : %s\n", ini->videocodec_element_hw);
257         for (idx = 0; ini->videocodec_element_sw[idx][0] != '\0'; idx++)
258                 LOGD("video codec element(sw%d) %s\n", idx, ini->videocodec_element_sw[idx]);
259         LOGD("audio codec element(hw) : %s\n", ini->audiocodec_element_hw);
260         for (idx = 0; ini->audiocodec_element_sw[idx][0] != '\0'; idx++)
261                 LOGD("audio codec element(sw%d) %s\n", idx, ini->audiocodec_element_sw[idx]);
262         LOGD("audio resampler element : %s\n", ini->audioresampler_element);
263         LOGD("audiosink element : %s\n", ini->audiosink_element);
264         LOGD("generate dot : %d\n", ini->generate_dot);
265         LOGD("use system clock(video only) : %d\n", ini->use_system_clock);
266         LOGD("live state change timeout(sec) : %d\n", ini->live_state_change_timeout);
267         LOGD("localplayback state change timeout(sec) : %d\n", ini->localplayback_state_change_timeout);
268         LOGD("eos_delay(msec) : %d\n", ini->eos_delay);
269         LOGD("delay before repeat(msec) : %d\n", ini->delay_before_repeat);
270         LOGD("async_start : %d\n", ini->async_start);
271         LOGD("video_playback_supported : %d\n", ini->video_playback_supported);
272         LOGD("pcm buffer size(bytes) : %d\n", ini->pcm_buffer_size);
273         LOGD("num of video bo : %d\n", ini->num_of_video_bo);
274         LOGD("video bo timeout : %d\n", ini->video_bo_timeout);
275         LOGD("gst param1 : %s\n", ini->gst_param[0]);
276         LOGD("gst param2 : %s\n", ini->gst_param[1]);
277         LOGD("gst param3 : %s\n", ini->gst_param[2]);
278         LOGD("gst param4 : %s\n", ini->gst_param[3]);
279         LOGD("gst param5 : %s\n", ini->gst_param[4]);
280
281         for (idx = 0; ini->exclude_element_keyword[idx][0] != '\0'; idx++)
282                 LOGD("exclude_element_keyword [%d] : %s\n", idx, ini->exclude_element_keyword[idx]);
283
284         for (idx = 0; ini->dump_element_keyword[idx][0] != '\0'; idx++)
285                 LOGD("dump_element_keyword [%d] : %s\n", idx, ini->dump_element_keyword[idx]);
286
287         /* http streaming */
288         LOGD("httpsrc element : %s\n", ini->httpsrc_element);
289         LOGD("http buffering limit : %f \n", ini->http_buffering_limit);
290         LOGD("http use file buffer : %d \n", ini->http_use_file_buffer);
291         LOGD("http ring buffer size : %d \n", ini->http_ring_buffer_size);
292         LOGD("http max_size bytes : %d \n", ini->http_max_size_bytes);
293         LOGD("http buffering time : %d \n", ini->http_buffering_time);
294         LOGD("http timeout : %d \n", ini->http_timeout);
295
296         return MM_ERROR_NONE;
297 }
298
299 int
300 mm_player_audio_effect_ini_load(mm_player_ini_t* ini)
301 {
302         dictionary * dict_audioeffect = NULL;
303
304         dict_audioeffect = iniparser_load(MM_PLAYER_INI_DEFAULT_AUDIOEFFECT_PATH);
305         if (!dict_audioeffect) {
306                 LOGE("No audio effect ini file found. \n");
307                 return MM_ERROR_FILE_NOT_FOUND;
308         }
309
310         /* audio effect element name */
311         MMPLAYER_INI_GET_STRING(dict_audioeffect, ini->audioeffect_element, "audio effect:audio effect element", DEFAULT_AUDIO_EFFECT_ELEMENT);
312         if (!ini->audioeffect_element[0]) {
313                 LOGW("could not parse name of audio effect. \n");
314                 iniparser_freedict(dict_audioeffect);
315                 /* NOTE : in this case, we are not going to create audio filter element */
316                 return MM_ERROR_NONE;
317         }
318
319         /* audio effect (Preset)*/
320         ini->use_audio_effect_preset = iniparser_getboolean(dict_audioeffect, "audio effect:audio effect preset", DEFAULT_USE_AUDIO_EFFECT_PRESET);
321         if (ini->use_audio_effect_preset) {
322                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST(dict_audioeffect, ini->audio_effect_preset_list, MM_AUDIO_EFFECT_PRESET_NUM,
323                                 "audio effect:audio effect preset list", DEFAULT_AUDIO_EFFECT_PRESET_LIST);
324                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST(dict_audioeffect, ini->audio_effect_preset_earphone_only_list, MM_AUDIO_EFFECT_PRESET_NUM,
325                                 "audio effect:audio effect preset earphone only", DEFAULT_AUDIO_EFFECT_PRESET_LIST_EARPHONE_ONLY);
326         }
327
328         /* audio effect user (EQ / Extension effects) */
329         ini->use_audio_effect_custom = iniparser_getboolean(dict_audioeffect, "audio effect:audio effect custom", DEFAULT_USE_AUDIO_EFFECT_CUSTOM);
330         if (ini->use_audio_effect_custom) {
331                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST(dict_audioeffect, ini->audio_effect_custom_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
332                                 "audio effect:audio effect custom list", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST);
333                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST(dict_audioeffect, ini->audio_effect_custom_earphone_only_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
334                                 "audio effect:audio effect custom earphone only", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST_EARPHONE_ONLY);
335
336                 /* audio effect custom : EQ */
337                 if (ini->audio_effect_custom_list[MM_AUDIO_EFFECT_CUSTOM_EQ]) {
338                         ini->audio_effect_custom_eq_band_num = iniparser_getint(dict_audioeffect, "audio effect:audio effect custom eq band num",
339                                         DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_NUM);
340                         if (ini->audio_effect_custom_eq_band_num < DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_NUM ||
341                                         ini->audio_effect_custom_eq_band_num > MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX) {
342                                 LOGE("audio_effect_custom_eq_band_num(%d) is not valid range(%d - %d), set the value %d",
343                                         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);
344                                 ini->audio_effect_custom_eq_band_num = DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_NUM;
345
346                                 iniparser_freedict(dict_audioeffect);
347                                 return MM_ERROR_PLAYER_INTERNAL;
348                         } else {
349                                 if (ini->audio_effect_custom_eq_band_num) {
350                                         MMPLAYER_INI_GET_INT_FROM_LIST(dict_audioeffect, ini->audio_effect_custom_eq_band_width, MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX,
351                                                         "audio effect:audio effect custom eq band width", DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_WIDTH);
352                                         MMPLAYER_INI_GET_INT_FROM_LIST(dict_audioeffect, ini->audio_effect_custom_eq_band_freq, MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX,
353                                                         "audio effect:audio effect custom eq band freq", DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_FREQ);
354                                 }
355                         }
356                 }
357
358                 /* audio effect custom : Extension effects */
359                 ini->audio_effect_custom_ext_num = iniparser_getint(dict_audioeffect, "audio effect:audio effect custom ext num",
360                                 DEFAULT_AUDIO_EFFECT_CUSTOM_EXT_NUM);
361
362                 /* Min/Max value list of EQ / Extension effects */
363                 if (ini->audio_effect_custom_eq_band_num || ini->audio_effect_custom_ext_num) {
364                         MMPLAYER_INI_GET_INT_FROM_LIST(dict_audioeffect, ini->audio_effect_custom_min_level_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
365                                         "audio effect:audio effect custom min list", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST);
366                         MMPLAYER_INI_GET_INT_FROM_LIST(dict_audioeffect, ini->audio_effect_custom_max_level_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
367                                         "audio effect:audio effect custom max list", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST);
368                 }
369         }
370
371         /* audio effect element name */
372         MMPLAYER_INI_GET_STRING(dict_audioeffect, ini->audioeffect_element_custom, "audio effect:audio effect element custom", DEFAULT_AUDIO_EFFECT_ELEMENT);
373         if (!ini->audioeffect_element_custom[0])
374                 LOGW("no secondary audio effect \n");
375         else
376                 LOGD("audioeffect element custom : %s\n", ini->audioeffect_element_custom);
377
378         /* dump structure */
379         LOGD("audioeffect element : %s\n", ini->audioeffect_element);
380         LOGD("audio effect preset mode : %d\n", ini->use_audio_effect_preset);
381         LOGD("audio effect custom mode : %d\n", ini->use_audio_effect_custom);
382 #if 0 // debug
383         int i;
384         for (i = 0; i < MM_AUDIO_EFFECT_PRESET_NUM; i++)
385                 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]);
386
387         for (i = 0; i < MM_AUDIO_EFFECT_CUSTOM_NUM; i++)
388                 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]);
389         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);
390         LOGD("audio_effect_custom_EQ : width(Hz) / central frequency(Hz)");
391         for (i = 0; i < ini->audio_effect_custom_eq_band_num; i++)
392                 LOGD("     EQ band index(%d) :  %8d / %8d", i, ini->audio_effect_custom_eq_band_width[i], ini->audio_effect_custom_eq_band_freq[i]);
393         for (i = 0; i < MM_AUDIO_EFFECT_CUSTOM_NUM; i++)
394                 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]);
395 #endif
396         iniparser_freedict(dict_audioeffect);
397
398         return MM_ERROR_NONE;
399
400 }
401
402 static
403 void __mm_player_ini_check_ini_status(void)
404 {
405         struct stat ini_buff;
406
407         if (g_stat(MM_PLAYER_INI_DEFAULT_PATH, &ini_buff) < 0) {
408                 LOGW("failed to get player ini status\n");
409         } else {
410                 if (ini_buff.st_size < 5) {
411                         LOGW("player.ini file size=%d, Corrupted!So, Removed\n", (int)ini_buff.st_size);
412
413                         if (g_remove(MM_PLAYER_INI_DEFAULT_PATH) == -1)
414                                 LOGE("failed to delete corrupted ini");
415                 }
416         }
417 }
418
419 #ifdef MM_PLAYER_DEFAULT_INI
420 static
421 gboolean __generate_default_ini(void)
422 {
423         FILE* fp = NULL;
424         gchar* default_ini = MM_PLAYER_DEFAULT_INI;
425
426
427         /* create new file */
428         fp = fopen(MM_PLAYER_INI_DEFAULT_PATH, "wt");
429
430         if (!fp)
431                 return FALSE;
432
433         /* writing default ini file */
434         if (strlen(default_ini) != fwrite(default_ini, 1, strlen(default_ini), fp)) {
435                 fclose(fp);
436                 return FALSE;
437         }
438
439         fclose(fp);
440         return TRUE;
441 }
442 #endif
443
444 static
445 void __get_element_list(mm_player_ini_t* ini, gchar* str, int keyword_type)
446 {
447         gchar** list = NULL;
448         gchar** walk = NULL;
449         gint i = 0;
450         gchar* strtmp = NULL;
451
452         if (!str)
453                 return;
454
455         if (strlen(str) < 1)
456                 return;
457
458         strtmp = g_strdup(str);
459
460         /* trimming. it works inplace */
461         g_strstrip(strtmp);
462
463
464         /* split */
465         list = g_strsplit(strtmp, ",", 10);
466
467         if (!list) {
468                 if (strtmp)
469                         g_free(strtmp);
470
471                 return;
472         }
473
474         /* copy list */
475         switch (keyword_type) {
476         case KEYWORD_EXCLUDE:
477         {
478                 for (walk = list; *walk; walk++) {
479                         strncpy(ini->exclude_element_keyword[i], *walk, (PLAYER_INI_MAX_STRLEN - 1));
480
481                         g_strstrip(ini->exclude_element_keyword[i]);
482
483                         ini->exclude_element_keyword[i][PLAYER_INI_MAX_STRLEN -1] = '\0';
484
485                         i++;
486                 }
487                 /* mark last item to NULL */
488                 ini->exclude_element_keyword[i][0] = '\0';
489
490                 break;
491         }
492         case KEYWORD_DUMP:
493         {
494                 for (walk = list; *walk; walk++) {
495                         strncpy(ini->dump_element_keyword[i], *walk, (PLAYER_INI_MAX_STRLEN - 1));
496
497                         g_strstrip(ini->dump_element_keyword[i]);
498
499                         ini->dump_element_keyword[i][PLAYER_INI_MAX_STRLEN -1] = '\0';
500
501                         i++;
502                 }
503                 /* mark last item to NULL */
504                 ini->dump_element_keyword[i][0] = '\0';
505
506                 break;
507         }
508         case KEYWORD_V_SW_CODEC:
509         {
510                 for (walk = list; *walk; walk++) {
511                         strncpy(ini->videocodec_element_sw[i], *walk, (PLAYER_INI_MAX_STRLEN - 1));
512
513                         g_strstrip(ini->videocodec_element_sw[i]);
514
515                         ini->videocodec_element_sw[i][PLAYER_INI_MAX_STRLEN -1] = '\0';
516
517                         i++;
518                 }
519                 /* mark last item to NULL */
520                 ini->videocodec_element_sw[i][0] = '\0';
521                 break;
522         }
523         case KEYWORD_A_SW_CODEC:
524         {
525                 for (walk = list; *walk; walk++) {
526                         strncpy(ini->audiocodec_element_sw[i], *walk, (PLAYER_INI_MAX_STRLEN - 1));
527
528                         g_strstrip(ini->audiocodec_element_sw[i]);
529
530                         ini->audiocodec_element_sw[i][PLAYER_INI_MAX_STRLEN -1] = '\0';
531
532                         i++;
533                 }
534                 /* mark last item to NULL */
535                 ini->audiocodec_element_sw[i][0] = '\0';
536                 break;
537         }
538
539         default:
540                 break;
541         }
542
543         g_strfreev(list);
544         if (strtmp)
545                 g_free(strtmp);
546 }
547
548 #endif