add NOTICE file and change file permission
[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>, YoungHwan An <younghwan_.an@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #ifndef __MM_PLAYER_INI_C__
23 #define __MM_PLAYER_INI_C__
24
25 /* includes here */
26 #include <glib.h>
27 #include <stdlib.h>
28 #include "iniparser.h"
29 #include <mm_player_ini.h>
30 #include "mm_debug.h"
31 #include <mm_error.h>
32 #include <glib/gstdio.h>
33
34 /* global variables here */
35 static mm_player_ini_t g_player_ini;
36
37 /* internal functions, macros here */
38 static gboolean __generate_default_ini(void);
39 static void     __get_string_list(gchar** out_list, gchar* str);
40 static void __mm_player_ini_check_ini_status(void);
41
42 /* macro */
43 #define MMPLAYER_INI_GET_STRING( x_dict, x_item, x_ini, x_default ) \
44 do \
45 { \
46         gchar* str = iniparser_getstring(x_dict, x_ini, x_default); \
47  \
48         if ( str &&  \
49                 ( strlen( str ) > 0 ) && \
50                 ( strlen( str ) < PLAYER_INI_MAX_STRLEN ) ) \
51         { \
52                 strcpy ( x_item, str ); \
53         } \
54         else \
55         { \
56                 strcpy ( x_item, x_default ); \
57         } \
58 }while(0)
59
60 /* x_ini is the list of index to set TRUE at x_list[index] */
61 #define MMPLAYER_INI_GET_BOOLEAN_FROM_LIST( x_dict, x_list, x_list_max, x_ini, x_default ) \
62 do \
63 { \
64                 int index = 0; \
65                 const char *delimiters = " ,"; \
66                 char *usr_ptr = NULL; \
67                 char *token = NULL; \
68                 gchar temp_arr[PLAYER_INI_MAX_STRLEN] = {0}; \
69                 MMPLAYER_INI_GET_STRING( x_dict, temp_arr, x_ini, x_default); \
70                 token = strtok_r( temp_arr, delimiters, &usr_ptr ); \
71                 while (token) \
72                 { \
73                         index = atoi(token); \
74                         if (index < 0 || index > x_list_max -1) \
75                         { \
76                                 debug_warning("%d is not valid index\n", index); \
77                         } \
78                         else \
79                         { \
80                                 x_list[index] = TRUE; \
81                         } \
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 { \
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                 { \
100                         if ( index > x_list_max -1) \
101                         { \
102                                 debug_error("%d is not valid index\n", index); \
103                                 break; \
104                         } \
105                         else \
106                         { \
107                                 value = atoi(token); \
108                                 x_list[index] = value; \
109                                 index++; \
110                         } \
111                         token = strtok_r( NULL, delimiters, &usr_ptr ); \
112                 } \
113 }while(0)
114
115 int 
116 mm_player_ini_load(void)
117 {
118         static gboolean loaded = FALSE;
119         dictionary * dict = NULL;
120         gint idx = 0;
121
122         if ( loaded )
123                 return MM_ERROR_NONE;
124
125         /* disabling ini parsing for launching */
126 #if 1 //debianize
127         /* get player ini status because system will be crashed 
128          * if ini file is corrupted. 
129          */
130         /* FIXIT : the api actually deleting illregular ini. but the function name said it's just checking. */
131         __mm_player_ini_check_ini_status();
132
133         /* first, try to load existing ini file */
134         dict = iniparser_load(MM_PLAYER_INI_DEFAULT_PATH);
135
136         /* if no file exists. create one with set of default values */
137         if ( !dict )
138         {
139                 #if 0
140                 debug_log("No inifile found. player will create default inifile.\n");
141                 if ( FALSE == __generate_default_ini() )
142                 {       
143                         debug_warning("Creating default inifile failed. Player will use default values.\n");
144                 }
145                 else
146                 {
147                         /* load default ini */
148                         dict = iniparser_load(MM_PLAYER_INI_DEFAULT_PATH);      
149                 }
150                 #else
151                 debug_log("No inifile found. \n");
152
153                 return MM_ERROR_FILE_NOT_FOUND;
154                 #endif
155         }
156 #endif
157
158         /* get ini values */
159         memset( &g_player_ini, 0, sizeof(mm_player_ini_t) );
160
161         if ( dict ) /* if dict is available */
162         {
163                 /* general */
164                 g_player_ini.use_decodebin = iniparser_getboolean(dict, "general:use decodebin", DEFAULT_USE_DECODEBIN);
165                 g_player_ini.disable_segtrap = iniparser_getboolean(dict, "general:disable segtrap", DEFAULT_DISABLE_SEGTRAP);
166                 g_player_ini.skip_rescan = iniparser_getboolean(dict, "general:skip rescan", DEFAULT_SKIP_RESCAN);
167                 g_player_ini.generate_dot = iniparser_getboolean(dict, "general:generate dot", DEFAULT_GENERATE_DOT);
168                 g_player_ini.provide_clock= iniparser_getboolean(dict, "general:provide clock", DEFAULT_PROVIDE_CLOCK);
169                 g_player_ini.live_state_change_timeout = iniparser_getint(dict, "general:live state change timeout", DEFAULT_LIVE_STATE_CHANGE_TIMEOUT);
170                 g_player_ini.localplayback_state_change_timeout = iniparser_getint(dict, "general:localplayback state change timeout", DEFAULT_LOCALPLAYBACK_STATE_CHANGE_TIMEOUT);
171                 g_player_ini.eos_delay = iniparser_getint(dict, "general:eos delay", DEFAULT_EOS_DELAY);
172                 g_player_ini.async_start = iniparser_getboolean(dict, "general:async start", DEFAULT_ASYNC_START);
173                 g_player_ini.multiple_codec_supported = iniparser_getboolean(dict, "general:multiple codec supported", DEFAULT_MULTIPLE_CODEC_SUPPORTED);
174
175                 g_player_ini.delay_before_repeat = iniparser_getint(dict, "general:delay before repeat", DEFAULT_DELAY_BEFORE_REPEAT);
176
177                 MMPLAYER_INI_GET_STRING(dict, g_player_ini.videosink_element_x, "general:videosink element x", DEFAULT_VIDEOSINK_X);
178                 MMPLAYER_INI_GET_STRING(dict, g_player_ini.videosink_element_evas, "general:videosink element evas", DEFAULT_VIDEOSINK_EVAS);
179                 MMPLAYER_INI_GET_STRING(dict, g_player_ini.videosink_element_fake, "general:videosink element fake", DEFAULT_VIDEOSINK_FAKE);
180                 MMPLAYER_INI_GET_STRING(dict, g_player_ini.name_of_drmsrc, "general:drmsrc element", DEFAULT_DRMSRC );
181                 MMPLAYER_INI_GET_STRING(dict, g_player_ini.name_of_audiosink, "general:audiosink element", DEFAULT_AUDIOSINK );
182                 MMPLAYER_INI_GET_STRING(dict, g_player_ini.name_of_video_converter, "general:video converter element", DEFAULT_VIDEO_CONVERTER );
183
184                 __get_string_list( (gchar**) g_player_ini.exclude_element_keyword, 
185                         iniparser_getstring(dict, "general:element exclude keyword", DEFAULT_EXCLUDE_KEYWORD));
186
187                 MMPLAYER_INI_GET_STRING(dict, g_player_ini.gst_param[0], "general:gstparam1", DEFAULT_GST_PARAM );
188                 MMPLAYER_INI_GET_STRING(dict, g_player_ini.gst_param[1], "general:gstparam2", DEFAULT_GST_PARAM );
189                 MMPLAYER_INI_GET_STRING(dict, g_player_ini.gst_param[2], "general:gstparam3", DEFAULT_GST_PARAM );
190                 MMPLAYER_INI_GET_STRING(dict, g_player_ini.gst_param[3], "general:gstparam4", DEFAULT_GST_PARAM );
191                 MMPLAYER_INI_GET_STRING(dict, g_player_ini.gst_param[4], "general:gstparam5", DEFAULT_GST_PARAM );
192
193                 /* http streaming */
194                 MMPLAYER_INI_GET_STRING( dict, g_player_ini.name_of_httpsrc, "http streaming:httpsrc element", DEFAULT_HTTPSRC );
195                 MMPLAYER_INI_GET_STRING( dict, g_player_ini.http_file_buffer_path, "http streaming:http file buffer path", DEFAULT_HTTP_FILE_BUFFER_PATH );
196                 g_player_ini.http_buffering_limit = iniparser_getdouble(dict, "http streaming:http buffering high limit", DEFAULT_HTTP_BUFFERING_LIMIT);
197                 g_player_ini.http_max_size_bytes = iniparser_getint(dict, "http streaming:http max size bytes", DEFAULT_HTTP_MAX_SIZE_BYTES);
198                 g_player_ini.http_buffering_time = iniparser_getdouble(dict, "http streaming:http buffering time", DEFAULT_HTTP_BUFFERING_TIME);                
199                 g_player_ini.http_timeout = iniparser_getint(dict, "http streaming:http timeout", DEFAULT_HTTP_TIMEOUT);
200
201                 /* rtsp streaming */
202                 MMPLAYER_INI_GET_STRING( dict, g_player_ini.name_of_rtspsrc, "rtsp streaming:rtspsrc element", DEFAULT_RTSPSRC );
203                 g_player_ini.rtsp_buffering_time = iniparser_getint(dict, "rtsp streaming:rtsp buffering time", DEFAULT_RTSP_BUFFERING);
204                 g_player_ini.rtsp_rebuffering_time = iniparser_getint(dict, "rtsp streaming:rtsp rebuffering time", DEFAULT_RTSP_REBUFFERING);
205                 g_player_ini.rtsp_do_typefinding = iniparser_getboolean(dict, "rtsp streaming:rtsp do typefinding", DEFAULT_RTSP_DO_TYPEFINDING);
206                 g_player_ini.rtsp_error_concealment = iniparser_getboolean(dict, "rtsp streaming:rtsp error concealment", DEFAULT_RTSP_ERROR_CONCEALMENT);
207         }       
208         else /* if dict is not available just fill the structure with default value */
209         {
210                 debug_warning("failed to load ini. using hardcoded default\n");
211
212                 /* general */
213                 g_player_ini.use_decodebin = DEFAULT_USE_DECODEBIN;
214                 g_player_ini.disable_segtrap = DEFAULT_DISABLE_SEGTRAP;
215                 g_player_ini.skip_rescan = DEFAULT_SKIP_RESCAN;
216                 strncpy( g_player_ini.videosink_element_x, DEFAULT_VIDEOSINK_X, PLAYER_INI_MAX_STRLEN - 1 );
217                 strncpy( g_player_ini.videosink_element_evas, DEFAULT_VIDEOSINK_EVAS, PLAYER_INI_MAX_STRLEN - 1 );
218                 strncpy( g_player_ini.videosink_element_fake, DEFAULT_VIDEOSINK_FAKE, PLAYER_INI_MAX_STRLEN - 1 );
219                 g_player_ini.generate_dot = DEFAULT_GENERATE_DOT;
220                 g_player_ini.provide_clock= DEFAULT_PROVIDE_CLOCK;
221                 g_player_ini.live_state_change_timeout = DEFAULT_LIVE_STATE_CHANGE_TIMEOUT;
222                 g_player_ini.localplayback_state_change_timeout = DEFAULT_LOCALPLAYBACK_STATE_CHANGE_TIMEOUT;
223                 g_player_ini.eos_delay = DEFAULT_EOS_DELAY;
224                 g_player_ini.multiple_codec_supported = DEFAULT_MULTIPLE_CODEC_SUPPORTED;
225                 g_player_ini.async_start = DEFAULT_ASYNC_START;
226                 g_player_ini.delay_before_repeat = DEFAULT_DELAY_BEFORE_REPEAT;
227
228
229                 strncpy( g_player_ini.name_of_drmsrc, DEFAULT_DRMSRC, PLAYER_INI_MAX_STRLEN - 1 );
230                 strncpy( g_player_ini.name_of_audiosink, DEFAULT_AUDIOSINK, PLAYER_INI_MAX_STRLEN -1 );
231                 strncpy( g_player_ini.name_of_video_converter, DEFAULT_VIDEO_CONVERTER, PLAYER_INI_MAX_STRLEN -1 );
232
233                 {
234                         __get_string_list( (gchar**) g_player_ini.exclude_element_keyword, DEFAULT_EXCLUDE_KEYWORD);
235                 }
236
237
238                 strncpy( g_player_ini.gst_param[0], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1 );
239                 strncpy( g_player_ini.gst_param[1], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1 );
240                 strncpy( g_player_ini.gst_param[2], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1 );
241                 strncpy( g_player_ini.gst_param[3], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1 );
242                 strncpy( g_player_ini.gst_param[4], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1 );
243
244                 /* http streaming */
245                 strncpy( g_player_ini.name_of_httpsrc, DEFAULT_HTTPSRC, PLAYER_INI_MAX_STRLEN - 1 );
246                 strncpy( g_player_ini.http_file_buffer_path, DEFAULT_HTTP_FILE_BUFFER_PATH, PLAYER_INI_MAX_STRLEN - 1 );
247                 g_player_ini.http_buffering_limit = DEFAULT_HTTP_BUFFERING_LIMIT;
248                 g_player_ini.http_max_size_bytes = DEFAULT_HTTP_MAX_SIZE_BYTES;
249                 g_player_ini.http_buffering_time = DEFAULT_HTTP_BUFFERING_TIME;         
250                 g_player_ini.http_timeout = DEFAULT_HTTP_TIMEOUT;
251                 
252                 /* rtsp streaming */
253                 strncpy( g_player_ini.name_of_rtspsrc, DEFAULT_RTSPSRC, PLAYER_INI_MAX_STRLEN - 1 );
254                 g_player_ini.rtsp_buffering_time = DEFAULT_RTSP_BUFFERING;
255                 g_player_ini.rtsp_rebuffering_time = DEFAULT_RTSP_REBUFFERING;
256                 g_player_ini.rtsp_do_typefinding = DEFAULT_RTSP_DO_TYPEFINDING;
257                 g_player_ini.rtsp_error_concealment = DEFAULT_RTSP_ERROR_CONCEALMENT;
258         }
259
260         /* free dict as we got our own structure */
261         iniparser_freedict (dict);
262
263         loaded = TRUE;
264
265         /* dump structure */
266         debug_log("player settings -----------------------------------\n");
267
268         /* general */
269         debug_log("use_decodebin : %d\n", g_player_ini.use_decodebin);
270         debug_log("disable_segtrap : %d\n", g_player_ini.disable_segtrap);
271         debug_log("skip rescan : %d\n", g_player_ini.skip_rescan);
272         debug_log("videosink element x: %s\n", g_player_ini.videosink_element_x);
273         debug_log("videosink element evas: %s\n", g_player_ini.videosink_element_evas);
274         debug_log("videosink element fake: %s\n", g_player_ini.videosink_element_fake);
275         debug_log("generate_dot : %d\n", g_player_ini.generate_dot);
276         debug_log("provide_clock : %d\n", g_player_ini.provide_clock);
277         debug_log("live_state_change_timeout(sec) : %d\n", g_player_ini.live_state_change_timeout);
278         debug_log("localplayback_state_change_timeout(sec) : %d\n", g_player_ini.localplayback_state_change_timeout);   
279         debug_log("eos_delay(msec) : %d\n", g_player_ini.eos_delay);
280         debug_log("delay_before_repeat(msec) : %d\n", g_player_ini.delay_before_repeat);
281         debug_log("name_of_drmsrc : %s\n", g_player_ini.name_of_drmsrc);
282         debug_log("name_of_audiosink : %s\n", g_player_ini.name_of_audiosink);
283         debug_log("name_of_video_converter : %s\n", g_player_ini.name_of_video_converter);
284         debug_log("async_start : %d\n", g_player_ini.async_start);
285         debug_log("multiple_codec_supported : %d\n", g_player_ini.multiple_codec_supported);    
286
287         debug_log("gst_param1 : %s\n", g_player_ini.gst_param[0]);
288         debug_log("gst_param2 : %s\n", g_player_ini.gst_param[1]);
289         debug_log("gst_param3 : %s\n", g_player_ini.gst_param[2]);
290         debug_log("gst_param4 : %s\n", g_player_ini.gst_param[3]);
291         debug_log("gst_param5 : %s\n", g_player_ini.gst_param[4]);
292
293         for ( idx = 0; g_player_ini.exclude_element_keyword[idx][0] != '\0'; idx++ )
294         {
295                 debug_log("exclude_element_keyword [%d] : %s\n", idx, g_player_ini.exclude_element_keyword[idx]);
296         }
297         
298         /* http streaming */
299         debug_log("name_of_httpsrc : %s\n", g_player_ini.name_of_httpsrc);
300         debug_log("http_file_buffer_path : %s \n", g_player_ini.http_file_buffer_path);
301         debug_log("http_buffering_limit : %f \n", g_player_ini.http_buffering_limit);
302         debug_log("http_max_size_bytes : %d \n", g_player_ini.http_max_size_bytes);
303         debug_log("http_buffering_time : %f \n", g_player_ini.http_buffering_time);
304         debug_log("http_timeout : %d \n", g_player_ini.http_timeout);
305         
306         /* rtsp streaming */
307         debug_log("name_of_rtspsrc : %s\n", g_player_ini.name_of_rtspsrc);
308         debug_log("rtsp_buffering_time(msec) : %d\n", g_player_ini.rtsp_buffering_time);
309         debug_log("rtsp_rebuffering_time(msec) : %d\n", g_player_ini.rtsp_rebuffering_time);
310         debug_log("rtsp_do_typefinding : %d \n", g_player_ini.rtsp_do_typefinding);
311         debug_log("rtsp_error_concealment : %d \n", g_player_ini.rtsp_error_concealment);
312
313         debug_log("---------------------------------------------------\n");     
314
315         return MM_ERROR_NONE;
316 }
317
318
319 int
320 mm_player_audio_effect_ini_load(void)
321 {
322         static gboolean loaded_audioeffect = FALSE;
323         dictionary * dict_audioeffect = NULL;
324
325         if ( loaded_audioeffect )
326                 return MM_ERROR_NONE;
327
328         dict_audioeffect = iniparser_load(MM_PLAYER_INI_DEFAULT_AUDIOEFFECT_PATH);
329         if ( !dict_audioeffect )
330         {
331                 debug_warning("No audio effect ini file found. \n");
332                 //return MM_ERROR_FILE_NOT_FOUND;
333         }
334
335         /* audio effect element name */
336         MMPLAYER_INI_GET_STRING( dict_audioeffect, g_player_ini.name_of_audio_effect, "audio effect:audio effect element", DEFAULT_AUDIO_EFFECT_ELEMENT );
337         if (!g_player_ini.name_of_audio_effect)
338         {
339                 debug_error("could not parse name of audio effect. \n");
340                 iniparser_freedict (dict_audioeffect);
341                 return MM_ERROR_PLAYER_INTERNAL;
342         }
343
344         /* audio effect (Preset)*/
345         g_player_ini.use_audio_effect_preset = iniparser_getboolean(dict_audioeffect, "audio effect:audio effect preset", DEFAULT_USE_AUDIO_EFFECT_PRESET);
346         if (g_player_ini.use_audio_effect_preset)
347         {
348                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST( dict_audioeffect, g_player_ini.audio_effect_preset_list, MM_AUDIO_EFFECT_PRESET_NUM,
349                                 "audio effect:audio effect preset list", DEFAULT_AUDIO_EFFECT_PRESET_LIST );
350                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST( dict_audioeffect, g_player_ini.audio_effect_preset_earphone_only_list, MM_AUDIO_EFFECT_PRESET_NUM,
351                                 "audio effect:audio effect preset earphone only", DEFAULT_AUDIO_EFFECT_PRESET_LIST_EARPHONE_ONLY );
352         }
353
354         /* audio effect custom (EQ / Extension effects) */
355         g_player_ini.use_audio_effect_custom = iniparser_getboolean(dict_audioeffect, "audio effect:audio effect custom", DEFAULT_USE_AUDIO_EFFECT_CUSTOM);
356         if (g_player_ini.use_audio_effect_custom)
357         {
358                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST( dict_audioeffect, g_player_ini.audio_effect_custom_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
359                                 "audio effect:audio effect custom list", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST );
360                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST( dict_audioeffect, g_player_ini.audio_effect_custom_earphone_only_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
361                                 "audio effect:audio effect custom earphone only", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST_EARPHONE_ONLY );
362
363                 /* audio effect custom : EQ */
364                 if (g_player_ini.audio_effect_custom_list[MM_AUDIO_EFFECT_CUSTOM_EQ])
365                 {
366                         g_player_ini.audio_effect_custom_eq_band_num = iniparser_getint(dict_audioeffect, "audio effect:audio effect custom eq band num",
367                                         DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_NUM);
368                         if (g_player_ini.audio_effect_custom_eq_band_num < DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_NUM ||
369                                         g_player_ini.audio_effect_custom_eq_band_num > MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX)
370                         {
371                                 debug_error("audio_effect_custom_eq_band_num(%d) is not valid range(%d - %d), set the value %d",
372                                         g_player_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);
373                                 g_player_ini.audio_effect_custom_eq_band_num = DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_NUM;
374
375                                 iniparser_freedict (dict_audioeffect);
376                                 return MM_ERROR_PLAYER_INTERNAL;
377                         }
378                         else
379                         {
380                                 if (g_player_ini.audio_effect_custom_eq_band_num)
381                                 {
382                                         MMPLAYER_INI_GET_INT_FROM_LIST( dict_audioeffect, g_player_ini.audio_effect_custom_eq_band_width, MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX,
383                                                         "audio effect:audio effect custom eq band width", DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_WIDTH );
384                                         MMPLAYER_INI_GET_INT_FROM_LIST( dict_audioeffect, g_player_ini.audio_effect_custom_eq_band_freq, MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX,
385                                                         "audio effect:audio effect custom eq band freq", DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_FREQ );
386                                 }
387                         }
388                 }
389
390                 /* audio effect custom : Extension effects */
391                 g_player_ini.audio_effect_custom_ext_num = iniparser_getint(dict_audioeffect, "audio effect:audio effect custom ext num",
392                                 DEFAULT_AUDIO_EFFECT_CUSTOM_EXT_NUM);
393
394                 /* Min/Max value list of EQ / Extension effects */
395                 if (g_player_ini.audio_effect_custom_eq_band_num || g_player_ini.audio_effect_custom_ext_num)
396                 {
397
398                         MMPLAYER_INI_GET_INT_FROM_LIST( dict_audioeffect, g_player_ini.audio_effect_custom_min_level_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
399                                         "audio effect:audio effect custom min list", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST );
400                         MMPLAYER_INI_GET_INT_FROM_LIST( dict_audioeffect, g_player_ini.audio_effect_custom_max_level_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
401                                         "audio effect:audio effect custom max list", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST );
402                 }
403         }
404
405         /* dump structure */
406         debug_log("player audio-effect settings ----------------------\n");
407         debug_log("name_of_audio_effect : %s\n", g_player_ini.name_of_audio_effect);
408         debug_log("use_audio_effect_preset : %d\n", g_player_ini.use_audio_effect_preset);
409         debug_log("use_audio_effect_custom : %d\n", g_player_ini.use_audio_effect_custom);
410 #if 0
411         int i;
412         for (i=0; i<MM_AUDIO_EFFECT_PRESET_NUM; i++)
413         {
414                 debug_log("audio_effect_preset_list: %d (is it for earphone only?(%d))\n", g_player_ini.audio_effect_preset_list[i], g_player_ini.audio_effect_preset_earphone_only_list[i]);
415         }
416         for (i=0; i<MM_AUDIO_EFFECT_CUSTOM_NUM; i++)
417         {
418                 debug_log("audio_effect_custom_list : %d (is it for earphone only?(%d))\n", g_player_ini.audio_effect_custom_list[i], g_player_ini.audio_effect_custom_earphone_only_list[i]);
419         }
420         debug_log("audio_effect_custom : eq_band_num(%d), ext_num(%d)\n", g_player_ini.audio_effect_custom_eq_band_num, g_player_ini.audio_effect_custom_ext_num );
421         debug_log("audio_effect_custom_EQ : width(Hz) / central frequency(Hz)");
422         for (i=0; i<g_player_ini.audio_effect_custom_eq_band_num; i++)
423         {
424                 debug_log("     EQ band index(%d) :  %8d / %8d", i, g_player_ini.audio_effect_custom_eq_band_width[i], g_player_ini.audio_effect_custom_eq_band_freq[i]);
425         }
426         for (i=0; i<MM_AUDIO_EFFECT_CUSTOM_NUM; i++)
427         {
428                 debug_log("audio_effect_custom_level_min_max(idx:%d) : Min(%d), Max(%d)\n", i, g_player_ini.audio_effect_custom_min_level_list[i], g_player_ini.audio_effect_custom_max_level_list[i]);
429         }
430 #endif
431         debug_log("---------------------------------------------------\n");
432
433         iniparser_freedict (dict_audioeffect);
434
435         loaded_audioeffect = TRUE;
436
437         return MM_ERROR_NONE;
438
439 }
440
441
442 static
443 void __mm_player_ini_check_ini_status(void)
444 {
445         struct stat ini_buff;
446         
447         if ( g_stat(MM_PLAYER_INI_DEFAULT_PATH, &ini_buff) < 0 )
448         {
449                 debug_warning("failed to get player ini status\n");
450         }
451         else
452         {
453                 if ( ini_buff.st_size < 5 )
454                 {
455                         debug_warning("player.ini file size=%d, Corrupted! So, Removed\n", (int)ini_buff.st_size);
456                         
457                         if ( g_remove( MM_PLAYER_INI_DEFAULT_PATH ) == -1)
458                         {
459                                 debug_error("failed to delete corrupted ini");
460                         }
461                 }
462         }
463 }
464
465 mm_player_ini_t* 
466 mm_player_ini_get_structure(void)
467 {
468         return &g_player_ini;
469 }
470
471 static 
472 gboolean __generate_default_ini(void)
473 {
474         FILE* fp = NULL;
475         gchar* default_ini = MM_PLAYER_DEFAULT_INI;
476
477
478         /* create new file */
479         fp = fopen(MM_PLAYER_INI_DEFAULT_PATH, "wt");
480
481         if ( !fp )
482         {
483                 return FALSE;
484         }
485
486         /* writing default ini file */
487         if ( strlen(default_ini) != fwrite(default_ini, 1, strlen(default_ini), fp) )
488         {
489                 fclose(fp);
490                 return FALSE;
491         }
492
493         fclose(fp);
494         return TRUE;
495 }
496
497 static 
498 void    __get_string_list(gchar** out_list, gchar* str)
499 {
500         gchar** list = NULL;
501         gchar** walk = NULL;
502         gint i = 0;
503         gchar* strtmp = NULL;
504
505
506         if ( ! str )
507                 return;
508
509         if ( strlen( str ) < 1 )
510                 return;
511
512         strtmp = g_strdup (str);
513
514         /* trimming. it works inplace */
515         g_strstrip( strtmp );
516
517
518         /* split */
519         list = g_strsplit( strtmp, ",", 10 );
520
521         if ( !list )
522         {
523                 if (strtmp)
524                         g_free(strtmp);
525
526                 return;
527         }
528
529         /* copy list */
530         for( walk = list; *walk; walk++ )
531         {
532                 strncpy( g_player_ini.exclude_element_keyword[i], *walk, (PLAYER_INI_MAX_STRLEN - 1) );
533
534                 g_strstrip( g_player_ini.exclude_element_keyword[i] );
535
536                 g_player_ini.exclude_element_keyword[i][PLAYER_INI_MAX_STRLEN - 1] = '\0';
537
538                 i++;
539         }
540
541         /* mark last item to NULL */
542         g_player_ini.exclude_element_keyword[i][0] = '\0';
543
544         g_strfreev( list );
545         if (strtmp)
546                 g_free (strtmp);
547 }
548
549 #endif
550
551
552