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