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