Merge "es_playback: add buffer status signal connection in push mode" into tizen
[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 <glib.h>
28 #include <stdlib.h>
29 #include "iniparser.h"
30 #include <mm_player_ini.h>
31 #include "mm_debug.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                 strcpy ( x_item, str ); \
54         } \
55         else \
56         { \
57                 strcpy ( x_item, x_default ); \
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                                 debug_warning("%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                                 debug_error("%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                 debug_log("No inifile found. player will create default inifile.\n");
149                 if ( FALSE == __generate_default_ini() )
150                 {
151                         debug_warning("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                 debug_log("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->provide_clock_for_music = iniparser_getboolean(dict, "general:provide clock for music", DEFAULT_PROVIDE_CLOCK_FOR_MUSIC);
174                 ini->provide_clock_for_movie = iniparser_getboolean(dict, "general:provide clock for movie", DEFAULT_PROVIDE_CLOCK_FOR_MOVIE);
175                 ini->live_state_change_timeout = iniparser_getint(dict, "general:live state change timeout", DEFAULT_LIVE_STATE_CHANGE_TIMEOUT);
176                 ini->localplayback_state_change_timeout = iniparser_getint(dict, "general:localplayback state change timeout", DEFAULT_LOCALPLAYBACK_STATE_CHANGE_TIMEOUT);
177                 ini->eos_delay = iniparser_getint(dict, "general:eos delay", DEFAULT_EOS_DELAY);
178                 ini->async_start = iniparser_getboolean(dict, "general:async start", DEFAULT_ASYNC_START);
179
180                 ini->delay_before_repeat = iniparser_getint(dict, "general:delay before repeat", DEFAULT_DELAY_BEFORE_REPEAT);
181
182                 MMPLAYER_INI_GET_STRING(dict, ini->videosink_element_x, "general:videosink element x", DEFAULT_VIDEOSINK_X);
183                 MMPLAYER_INI_GET_STRING(dict, ini->videosink_element_evas, "general:videosink element evas", DEFAULT_VIDEOSINK_EVAS);
184                 MMPLAYER_INI_GET_STRING(dict, ini->videosink_element_fake, "general:videosink element fake", DEFAULT_VIDEOSINK_FAKE);
185                 MMPLAYER_INI_GET_STRING(dict, ini->videosink_element_remote, "general:videosink element remote", DEFAULT_VIDEOSINK_REMOTE);
186                 MMPLAYER_INI_GET_STRING(dict, ini->videosrc_element_remote, "general:videosrc element remote", DEFAULT_VIDEOSRC_REMOTE);
187                 MMPLAYER_INI_GET_STRING(dict, ini->name_of_audio_resampler, "general:audio resampler element", DEFAULT_AUDIORESAMPLER );
188                 MMPLAYER_INI_GET_STRING(dict, ini->name_of_audiosink, "general:audiosink element", DEFAULT_AUDIOSINK );
189                 MMPLAYER_INI_GET_STRING(dict, ini->name_of_video_converter, "general:video converter element", DEFAULT_VIDEO_CONVERTER );
190
191                 __get_element_list(ini,
192                         iniparser_getstring(dict, "general:element exclude keyword", DEFAULT_EXCLUDE_KEYWORD), KEYWORD_EXCLUDE);
193
194                 MMPLAYER_INI_GET_STRING(dict, ini->gst_param[0], "general:gstparam1", DEFAULT_GST_PARAM );
195                 MMPLAYER_INI_GET_STRING(dict, ini->gst_param[1], "general:gstparam2", DEFAULT_GST_PARAM );
196                 MMPLAYER_INI_GET_STRING(dict, ini->gst_param[2], "general:gstparam3", DEFAULT_GST_PARAM );
197                 MMPLAYER_INI_GET_STRING(dict, ini->gst_param[3], "general:gstparam4", DEFAULT_GST_PARAM );
198                 MMPLAYER_INI_GET_STRING(dict, ini->gst_param[4], "general:gstparam5", DEFAULT_GST_PARAM );
199
200                 /* http streaming */
201                 MMPLAYER_INI_GET_STRING( dict, ini->name_of_httpsrc, "http streaming:httpsrc element", DEFAULT_HTTPSRC );
202                 MMPLAYER_INI_GET_STRING( dict, ini->http_file_buffer_path, "http streaming:http file buffer path", DEFAULT_HTTP_FILE_BUFFER_PATH );
203                 ini->http_buffering_limit = iniparser_getdouble(dict, "http streaming:http buffering high limit", DEFAULT_HTTP_BUFFERING_LIMIT);
204                 ini->http_max_size_bytes = iniparser_getint(dict, "http streaming:http max size bytes", DEFAULT_HTTP_MAX_SIZE_BYTES);
205                 ini->http_buffering_time = iniparser_getdouble(dict, "http streaming:http buffering time", DEFAULT_HTTP_BUFFERING_TIME);
206                 ini->http_timeout = iniparser_getint(dict, "http streaming:http timeout", DEFAULT_HTTP_TIMEOUT);
207
208                 /* rtsp streaming */
209                 MMPLAYER_INI_GET_STRING( dict, ini->name_of_rtspsrc, "rtsp streaming:rtspsrc element", DEFAULT_RTSPSRC );
210                 ini->rtsp_buffering_time = iniparser_getint(dict, "rtsp streaming:rtsp buffering time", DEFAULT_RTSP_BUFFERING);
211                 ini->rtsp_rebuffering_time = iniparser_getint(dict, "rtsp streaming:rtsp rebuffering time", DEFAULT_RTSP_REBUFFERING);
212                 ini->rtsp_do_typefinding = iniparser_getboolean(dict, "rtsp streaming:rtsp do typefinding", DEFAULT_RTSP_DO_TYPEFINDING);
213
214                 /* dump buffer for debug */
215                 __get_element_list(ini,
216                         iniparser_getstring(dict, "general:dump element keyword", DEFAULT_EXCLUDE_KEYWORD), KEYWORD_DUMP);
217
218                 MMPLAYER_INI_GET_STRING(dict, ini->dump_element_path, "general:dump element path", DEFAULT_DUMP_ELEMENT_PATH);
219         }
220         else /* if dict is not available just fill the structure with default value */
221         {
222                 debug_warning("failed to load ini. using hardcoded default\n");
223
224                 /* general */
225                 ini->disable_segtrap = DEFAULT_DISABLE_SEGTRAP;
226                 ini->skip_rescan = DEFAULT_SKIP_RESCAN;
227                 strncpy( ini->videosink_element_x, DEFAULT_VIDEOSINK_X, PLAYER_INI_MAX_STRLEN - 1 );
228                 strncpy( ini->videosink_element_evas, DEFAULT_VIDEOSINK_EVAS, PLAYER_INI_MAX_STRLEN - 1 );
229                 strncpy( ini->videosink_element_fake, DEFAULT_VIDEOSINK_FAKE, PLAYER_INI_MAX_STRLEN - 1 );
230                 ini->generate_dot = DEFAULT_GENERATE_DOT;
231                 ini->provide_clock_for_music = DEFAULT_PROVIDE_CLOCK_FOR_MUSIC;
232                 ini->provide_clock_for_movie = DEFAULT_PROVIDE_CLOCK_FOR_MOVIE;
233                 ini->live_state_change_timeout = DEFAULT_LIVE_STATE_CHANGE_TIMEOUT;
234                 ini->localplayback_state_change_timeout = DEFAULT_LOCALPLAYBACK_STATE_CHANGE_TIMEOUT;
235                 ini->eos_delay = DEFAULT_EOS_DELAY;
236                 ini->async_start = DEFAULT_ASYNC_START;
237                 ini->delay_before_repeat = DEFAULT_DELAY_BEFORE_REPEAT;
238
239                 strncpy( ini->name_of_audio_resampler, DEFAULT_AUDIORESAMPLER, PLAYER_INI_MAX_STRLEN -1 );
240                 strncpy( ini->name_of_audiosink, DEFAULT_AUDIOSINK, PLAYER_INI_MAX_STRLEN -1 );
241                 strncpy( ini->name_of_video_converter, DEFAULT_VIDEO_CONVERTER, PLAYER_INI_MAX_STRLEN -1 );
242
243                 {
244                         __get_element_list(ini, DEFAULT_EXCLUDE_KEYWORD, KEYWORD_EXCLUDE);
245                 }
246
247
248                 strncpy( ini->gst_param[0], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1 );
249                 strncpy( ini->gst_param[1], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1 );
250                 strncpy( ini->gst_param[2], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1 );
251                 strncpy( ini->gst_param[3], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1 );
252                 strncpy( ini->gst_param[4], DEFAULT_GST_PARAM, PLAYER_INI_MAX_PARAM_STRLEN - 1 );
253
254                 /* http streaming */
255                 strncpy( ini->name_of_httpsrc, DEFAULT_HTTPSRC, PLAYER_INI_MAX_STRLEN - 1 );
256                 strncpy( ini->http_file_buffer_path, DEFAULT_HTTP_FILE_BUFFER_PATH, PLAYER_INI_MAX_STRLEN - 1 );
257                 ini->http_buffering_limit = DEFAULT_HTTP_BUFFERING_LIMIT;
258                 ini->http_max_size_bytes = DEFAULT_HTTP_MAX_SIZE_BYTES;
259                 ini->http_buffering_time = DEFAULT_HTTP_BUFFERING_TIME;
260                 ini->http_timeout = DEFAULT_HTTP_TIMEOUT;
261
262                 /* rtsp streaming */
263                 strncpy( ini->name_of_rtspsrc, DEFAULT_RTSPSRC, PLAYER_INI_MAX_STRLEN - 1 );
264                 ini->rtsp_buffering_time = DEFAULT_RTSP_BUFFERING;
265                 ini->rtsp_rebuffering_time = DEFAULT_RTSP_REBUFFERING;
266                 ini->rtsp_do_typefinding = DEFAULT_RTSP_DO_TYPEFINDING;
267
268                 /* dump buffer for debug */
269                 __get_element_list(ini, DEFAULT_DUMP_ELEMENT_KEYWORD, KEYWORD_DUMP);
270                 strncpy(ini->dump_element_path, DEFAULT_DUMP_ELEMENT_PATH, PLAYER_INI_MAX_STRLEN - 1);
271         }
272
273         /* free dict as we got our own structure */
274         iniparser_freedict (dict);
275
276         /* dump structure */
277         debug_log("player settings -----------------------------------\n");
278
279         /* general */
280         debug_log("disable_segtrap : %d\n", ini->disable_segtrap);
281         debug_log("skip rescan : %d\n", ini->skip_rescan);
282         debug_log("videosink element x: %s\n", ini->videosink_element_x);
283         debug_log("videosink element evas: %s\n", ini->videosink_element_evas);
284         debug_log("videosink element fake: %s\n", ini->videosink_element_fake);
285         debug_log("generate_dot : %d\n", ini->generate_dot);
286         debug_log("provide_clock for music : %d\n", ini->provide_clock_for_music);
287         debug_log("provide_clock for movie : %d\n", ini->provide_clock_for_movie);
288         debug_log("live_state_change_timeout(sec) : %d\n", ini->live_state_change_timeout);
289         debug_log("localplayback_state_change_timeout(sec) : %d\n", ini->localplayback_state_change_timeout);
290         debug_log("eos_delay(msec) : %d\n", ini->eos_delay);
291         debug_log("delay_before_repeat(msec) : %d\n", ini->delay_before_repeat);
292         debug_log("name_of_audioresampler : %s\n", ini->name_of_audio_resampler);
293         debug_log("name_of_audiosink : %s\n", ini->name_of_audiosink);
294         debug_log("name_of_video_converter : %s\n", ini->name_of_video_converter);
295         debug_log("async_start : %d\n", ini->async_start);
296
297         debug_log("gst_param1 : %s\n", ini->gst_param[0]);
298         debug_log("gst_param2 : %s\n", ini->gst_param[1]);
299         debug_log("gst_param3 : %s\n", ini->gst_param[2]);
300         debug_log("gst_param4 : %s\n", ini->gst_param[3]);
301         debug_log("gst_param5 : %s\n", ini->gst_param[4]);
302
303         for ( idx = 0; ini->exclude_element_keyword[idx][0] != '\0'; idx++ )
304         {
305                 debug_log("exclude_element_keyword [%d] : %s\n", idx, ini->exclude_element_keyword[idx]);
306         }
307
308         for ( idx = 0; ini->dump_element_keyword[idx][0] != '\0'; idx++ )
309         {
310                 debug_log("dump_element_keyword [%d] : %s\n", idx, ini->dump_element_keyword[idx]);
311         }
312
313         /* http streaming */
314         debug_log("name_of_httpsrc : %s\n", ini->name_of_httpsrc);
315         debug_log("http_file_buffer_path : %s \n", ini->http_file_buffer_path);
316         debug_log("http_buffering_limit : %f \n", ini->http_buffering_limit);
317         debug_log("http_max_size_bytes : %d \n", ini->http_max_size_bytes);
318         debug_log("http_buffering_time : %f \n", ini->http_buffering_time);
319         debug_log("http_timeout : %d \n", ini->http_timeout);
320
321         /* rtsp streaming */
322         debug_log("name_of_rtspsrc : %s\n", ini->name_of_rtspsrc);
323         debug_log("rtsp_buffering_time(msec) : %d\n", ini->rtsp_buffering_time);
324         debug_log("rtsp_rebuffering_time(msec) : %d\n", ini->rtsp_rebuffering_time);
325         debug_log("rtsp_do_typefinding : %d \n", ini->rtsp_do_typefinding);
326
327         return MM_ERROR_NONE;
328 }
329
330
331 int
332 mm_player_audio_effect_ini_load(mm_player_ini_t* ini)
333 {
334         dictionary * dict_audioeffect = NULL;
335
336         dict_audioeffect = iniparser_load(MM_PLAYER_INI_DEFAULT_AUDIOEFFECT_PATH);
337         if ( !dict_audioeffect )
338         {
339                 debug_error("No audio effect ini file found. \n");
340                 return MM_ERROR_FILE_NOT_FOUND;
341         }
342
343         /* audio effect element name */
344         MMPLAYER_INI_GET_STRING( dict_audioeffect, ini->name_of_audio_effect, "audio effect:audio effect element", DEFAULT_AUDIO_EFFECT_ELEMENT );
345         if (!ini->name_of_audio_effect[0])
346         {
347                 debug_warning("could not parse name of audio effect. \n");
348                 iniparser_freedict (dict_audioeffect);
349                 /* NOTE : in this case, we are not going to create audio filter element */
350                 return MM_ERROR_NONE;
351         }
352
353         /* audio effect (Preset)*/
354         ini->use_audio_effect_preset = iniparser_getboolean(dict_audioeffect, "audio effect:audio effect preset", DEFAULT_USE_AUDIO_EFFECT_PRESET);
355         if (ini->use_audio_effect_preset)
356         {
357                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST( dict_audioeffect, ini->audio_effect_preset_list, MM_AUDIO_EFFECT_PRESET_NUM,
358                                 "audio effect:audio effect preset list", DEFAULT_AUDIO_EFFECT_PRESET_LIST );
359                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST( dict_audioeffect, ini->audio_effect_preset_earphone_only_list, MM_AUDIO_EFFECT_PRESET_NUM,
360                                 "audio effect:audio effect preset earphone only", DEFAULT_AUDIO_EFFECT_PRESET_LIST_EARPHONE_ONLY );
361         }
362
363         /* audio effect custom (EQ / Extension effects) */
364         ini->use_audio_effect_custom = iniparser_getboolean(dict_audioeffect, "audio effect:audio effect custom", DEFAULT_USE_AUDIO_EFFECT_CUSTOM);
365         if (ini->use_audio_effect_custom)
366         {
367                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST( dict_audioeffect, ini->audio_effect_custom_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
368                                 "audio effect:audio effect custom list", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST );
369                 MMPLAYER_INI_GET_BOOLEAN_FROM_LIST( dict_audioeffect, ini->audio_effect_custom_earphone_only_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
370                                 "audio effect:audio effect custom earphone only", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST_EARPHONE_ONLY );
371
372                 /* audio effect custom : EQ */
373                 if (ini->audio_effect_custom_list[MM_AUDIO_EFFECT_CUSTOM_EQ])
374                 {
375                         ini->audio_effect_custom_eq_band_num = iniparser_getint(dict_audioeffect, "audio effect:audio effect custom eq band num",
376                                         DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_NUM);
377                         if (ini->audio_effect_custom_eq_band_num < DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_NUM ||
378                                         ini->audio_effect_custom_eq_band_num > MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX)
379                         {
380                                 debug_error("audio_effect_custom_eq_band_num(%d) is not valid range(%d - %d), set the value %d",
381                                         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);
382                                 ini->audio_effect_custom_eq_band_num = DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_NUM;
383
384                                 iniparser_freedict (dict_audioeffect);
385                                 return MM_ERROR_PLAYER_INTERNAL;
386                         }
387                         else
388                         {
389                                 if (ini->audio_effect_custom_eq_band_num)
390                                 {
391                                         MMPLAYER_INI_GET_INT_FROM_LIST( dict_audioeffect, ini->audio_effect_custom_eq_band_width, MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX,
392                                                         "audio effect:audio effect custom eq band width", DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_WIDTH );
393                                         MMPLAYER_INI_GET_INT_FROM_LIST( dict_audioeffect, ini->audio_effect_custom_eq_band_freq, MM_AUDIO_EFFECT_EQ_BAND_NUM_MAX,
394                                                         "audio effect:audio effect custom eq band freq", DEFAULT_AUDIO_EFFECT_CUSTOM_EQ_BAND_FREQ );
395                                 }
396                         }
397                 }
398
399                 /* audio effect custom : Extension effects */
400                 ini->audio_effect_custom_ext_num = iniparser_getint(dict_audioeffect, "audio effect:audio effect custom ext num",
401                                 DEFAULT_AUDIO_EFFECT_CUSTOM_EXT_NUM);
402
403                 /* Min/Max value list of EQ / Extension effects */
404                 if (ini->audio_effect_custom_eq_band_num || ini->audio_effect_custom_ext_num)
405                 {
406
407                         MMPLAYER_INI_GET_INT_FROM_LIST( dict_audioeffect, ini->audio_effect_custom_min_level_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
408                                         "audio effect:audio effect custom min list", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST );
409                         MMPLAYER_INI_GET_INT_FROM_LIST( dict_audioeffect, ini->audio_effect_custom_max_level_list, MM_AUDIO_EFFECT_CUSTOM_NUM,
410                                         "audio effect:audio effect custom max list", DEFAULT_AUDIO_EFFECT_CUSTOM_LIST );
411                 }
412         }
413
414         ini->use_audio_effect_square= iniparser_getboolean(dict_audioeffect, "audio effect:audio effect square", DEFAULT_USE_AUDIO_EFFECT_SQUARE);
415         if (ini->use_audio_effect_custom)
416         {
417                 ini->audio_effect_square_max_row= iniparser_getint(dict_audioeffect, "audio effect:audio effect square max row",
418                                 DEFAULT_AUDIO_EFFECT_SQUARE_ROW_MAX);
419                 ini->audio_effect_square_max_col= iniparser_getint(dict_audioeffect, "audio effect:audio effect square max col",
420                                 DEFAULT_AUDIO_EFFECT_SQUARE_COL_MAX);
421         }
422
423         /* audio effect element name */
424         MMPLAYER_INI_GET_STRING( dict_audioeffect, ini->name_of_audio_effect_sec, "audio effect:audio effect element sec", DEFAULT_AUDIO_EFFECT_ELEMENT );
425         if (!ini->name_of_audio_effect_sec[0])
426         {
427                 debug_warning("could not parse name of secondary audio effect. \n");
428         }
429
430         /* dump structure */
431         debug_log("name_of_audio_effect : %s\n", ini->name_of_audio_effect);
432         debug_log("use_audio_effect_preset : %d\n", ini->use_audio_effect_preset);
433         debug_log("use_audio_effect_custom : %d\n", ini->use_audio_effect_custom);
434         debug_log("name_of_audio_effect_sec : %s\n", ini->name_of_audio_effect_sec);
435         debug_log("Use_audio_effect_square : %d\n", ini->use_audio_effect_square);
436 #if 0
437         int i;
438         for (i=0; i<MM_AUDIO_EFFECT_PRESET_NUM; i++)
439         {
440                 debug_log("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]);
441         }
442         for (i=0; i<MM_AUDIO_EFFECT_CUSTOM_NUM; i++)
443         {
444                 debug_log("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]);
445         }
446         debug_log("audio_effect_custom : eq_band_num(%d), ext_num(%d)\n", ini->audio_effect_custom_eq_band_num, ini->audio_effect_custom_ext_num );
447         debug_log("audio_effect_custom_EQ : width(Hz) / central frequency(Hz)");
448         for (i=0; i<ini->audio_effect_custom_eq_band_num; i++)
449         {
450                 debug_log("     EQ band index(%d) :  %8d / %8d", i, ini->audio_effect_custom_eq_band_width[i], ini->audio_effect_custom_eq_band_freq[i]);
451         }
452         for (i=0; i<MM_AUDIO_EFFECT_CUSTOM_NUM; i++)
453         {
454                 debug_log("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]);
455         }
456 #endif
457         iniparser_freedict (dict_audioeffect);
458
459         return MM_ERROR_NONE;
460
461 }
462
463
464 static
465 void __mm_player_ini_check_ini_status(void)
466 {
467         struct stat ini_buff;
468
469         if ( g_stat(MM_PLAYER_INI_DEFAULT_PATH, &ini_buff) < 0 )
470         {
471                 debug_warning("failed to get player ini status\n");
472         }
473         else
474         {
475                 if ( ini_buff.st_size < 5 )
476                 {
477                         debug_warning("player.ini file size=%d, Corrupted! So, Removed\n", (int)ini_buff.st_size);
478
479                         if ( g_remove( MM_PLAYER_INI_DEFAULT_PATH ) == -1)
480                         {
481                                 debug_error("failed to delete corrupted ini");
482                         }
483                 }
484         }
485 }
486
487 #ifdef MM_PLAYER_DEFAULT_INI
488 static
489 gboolean __generate_default_ini(void)
490 {
491         FILE* fp = NULL;
492         gchar* default_ini = MM_PLAYER_DEFAULT_INI;
493
494
495         /* create new file */
496         fp = fopen(MM_PLAYER_INI_DEFAULT_PATH, "wt");
497
498         if ( !fp )
499         {
500                 return FALSE;
501         }
502
503         /* writing default ini file */
504         if ( strlen(default_ini) != fwrite(default_ini, 1, strlen(default_ini), fp) )
505         {
506                 fclose(fp);
507                 return FALSE;
508         }
509
510         fclose(fp);
511         return TRUE;
512 }
513 #endif
514
515 static
516 void    __get_element_list(mm_player_ini_t* ini, gchar* str, int keyword_type)
517 {
518         gchar** list = NULL;
519         gchar** walk = NULL;
520         gint i = 0;
521         gchar* strtmp = NULL;
522
523         if ( ! str )
524                 return;
525
526         if ( strlen( str ) < 1 )
527                 return;
528
529         strtmp = g_strdup (str);
530
531         /* trimming. it works inplace */
532         g_strstrip( strtmp );
533
534
535         /* split */
536         list = g_strsplit( strtmp, ",", 10 );
537
538         if ( !list )
539         {
540                 if (strtmp)
541                         g_free(strtmp);
542
543                 return;
544         }
545
546         /* copy list */
547         switch (keyword_type)
548         {
549                 case KEYWORD_EXCLUDE:
550                 {
551                         for( walk = list; *walk; walk++ )
552                         {
553                                 strncpy( ini->exclude_element_keyword[i], *walk, (PLAYER_INI_MAX_STRLEN - 1) );
554
555                                 g_strstrip( ini->exclude_element_keyword[i] );
556
557                                 ini->exclude_element_keyword[i][PLAYER_INI_MAX_STRLEN -1]= '\0';
558
559                                 i++;
560                         }
561                         /* mark last item to NULL */
562                         ini->exclude_element_keyword[i][0] = '\0';
563
564                         break;
565                 }
566                 case KEYWORD_DUMP:
567                 {
568                         for( walk = list; *walk; walk++ )
569                         {
570                                 strncpy( ini->dump_element_keyword[i], *walk, (PLAYER_INI_MAX_STRLEN - 1) );
571
572                                 g_strstrip( ini->dump_element_keyword[i] );
573
574                                 ini->dump_element_keyword[i][PLAYER_INI_MAX_STRLEN -1]= '\0';
575
576                                 i++;
577                         }
578                         /* mark last item to NULL */
579                         ini->dump_element_keyword[i][0] = '\0';
580
581                         break;
582                 }
583                 default:
584                         break;
585         }
586
587         g_strfreev( list );
588         if (strtmp)
589                 g_free (strtmp);
590 }
591
592 #endif
593
594
595