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