annotate Gui/win32/wincfg.c @ 21500:e7e7f397f991

Fix memleaks caused by missing vorbis/theora_info/comment_clear calls. Code still seems wrong to me for multiple audio tracks, since there is only one vorbis comment/info entry for the demuxer, not one per track?
author reimar
date Wed, 06 Dec 2006 10:46:50 +0000
parents d450ec82ae57
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18914
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
1 /*
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
2 MPlayer Gui for win32
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
3 Copyright (c) 2003 Sascha Sommer <saschasommer@freenet.de>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
4 Copyright (c) 2006 Erik Augustson <erik_27can@yahoo.com>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
5 Copyright (c) 2006 Gianluigi Tiesi <sherpya@netfarm.it>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
6
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
7 This program is free software; you can redistribute it and/or modify
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
9 the Free Software Foundation; either version 2 of the License, or
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
10 (at your option) any later version.
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
11
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
12 This program is distributed in the hope that it will be useful,
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
15 GNU General Public License for more details.
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
16
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
18 along with this program; if not, write to the Free Software
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
20 */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
21
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
22 #include <stdlib.h>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
23 #include <string.h>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
24
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
25 #include <mp_msg.h>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
26 #include <help_mp.h>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
27
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
28 #include <m_config.h>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
29 #include <m_option.h>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
30 #include <libvo/video_out.h>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
31 #include <mixer.h>
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
32 #include "wincfg.h"
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
33 #include "interface.h"
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
34
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
35 /* params */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
36 int gtkAONorm = 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
37 int gtkAOExtraStereo = 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
38 float gtkAOExtraStereoMul = 1.0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
39 int gtkCacheOn = 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
40 int gtkCacheSize = 2048;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
41 int gtkAutoSyncOn = 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
42 int gtkAutoSync = 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
43
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
44 int sub_window = 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
45 int console = 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
46
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
47 int gui_save_pos = 1;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
48 int gui_main_pos_x = -2;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
49 int gui_main_pos_y = -2;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
50 int gui_sub_pos_x = -1;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
51 int gui_sub_pos_y = -1;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
52
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
53 /* External functions */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
54 extern int frame_dropping;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
55 extern char *proc_priority;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
56 extern int m_config_parse_config_file(m_config_t *config, char *conffile);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
57
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
58 static m_config_t *gui_conf;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
59 static m_option_t gui_opts[] =
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
60 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
61 { "priority", &proc_priority, CONF_TYPE_STRING, 0, 0, 0, NULL},
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
62 { "vo_driver", &video_driver_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
63 { "v_framedrop", &frame_dropping, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
64 { "vo_doublebuffering", &vo_doublebuffering, CONF_TYPE_FLAG, 0, 0, 1, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
65 { "vo_direct_render", &vo_directrendering, CONF_TYPE_FLAG, 0, 0, 1, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
66 { "ao_driver", &audio_driver_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
67 { "ao_volnorm", &gtkAONorm, CONF_TYPE_FLAG, 0, 0, 1, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
68 { "softvol", &soft_vol, CONF_TYPE_FLAG, 0, 0, 1, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
69 { "ao_extra_stereo", &gtkAOExtraStereo, CONF_TYPE_FLAG, 0, 0, 1, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
70 { "ao_extra_stereo_coefficient", &gtkAOExtraStereoMul, CONF_TYPE_FLOAT, CONF_RANGE, -10, 10, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
71 { "delay", &audio_delay, CONF_TYPE_FLOAT, CONF_RANGE, -100.0, 100.0, NULL},
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
72 { "dvd_device", &dvd_device, CONF_TYPE_STRING, 0, 0, 0, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
73 { "cdrom_device", &cdrom_device, CONF_TYPE_STRING, 0, 0, 0, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
74 { "osd_level", &osd_level, CONF_TYPE_INT, CONF_RANGE, 0, 3, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
75 { "cache", &gtkCacheOn, CONF_TYPE_FLAG, 0, 0, 1, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
76 { "cache_size", &gtkCacheSize, CONF_TYPE_INT, CONF_RANGE, -1, 65535, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
77 { "autosync", &gtkAutoSyncOn, CONF_TYPE_FLAG, 0, 0, 1, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
78 { "autosync_size", &gtkAutoSync, CONF_TYPE_INT, CONF_RANGE, 0, 10000, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
79 { "gui_skin", &skinName, CONF_TYPE_STRING, 0, 0, 0, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
80 { "gui_main_pos_x", &gui_main_pos_x, CONF_TYPE_INT, 0, 0, 0, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
81 { "gui_main_pos_y", &gui_main_pos_y, CONF_TYPE_INT, 0, 0, 0, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
82 { "gui_sub_pos_x", &gui_sub_pos_x, CONF_TYPE_INT, 0, 0, 0, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
83 { "gui_sub_pos_y", &gui_sub_pos_y, CONF_TYPE_INT, 0, 0, 0, NULL },
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
84 { "sub_window", &sub_window, CONF_TYPE_FLAG, 0, 0, 1, NULL},
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
85 { "console", &console, CONF_TYPE_FLAG, 0, 0, 1, NULL},
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
86 { NULL, NULL, 0, 0, 0, 0, NULL }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
87 };
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
88
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
89 char *gfgets(char *str, int size, FILE *f)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
90 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
91 char *s = fgets(str, size, f);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
92 char c;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
93 if(s)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
94 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
95 c = s[strlen(s) - 1];
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
96 if ((c == '\n') || (c == '\r'))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
97 s[strlen(s) - 1]=0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
98 c = s[strlen(s) - 1];
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
99 if ((c == '\n') || (c == '\r'))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
100 s[strlen(s) - 1]=0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
101 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
102 return s;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
103 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
104
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
105 int cfg_read(void)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
106 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
107 char *cfg = get_path("gui.conf");
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
108
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
109 /* read configuration */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
110 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] [cfg] reading config file: %s\n", cfg);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
111 gui_conf = m_config_new();
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
112 m_config_register_options(gui_conf, gui_opts);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
113 if (m_config_parse_config_file(gui_conf, cfg) < 0)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
114 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_ConfigFileError);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
115 free(cfg);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
116 return 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
117 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
118
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
119 int cfg_write(void)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
120 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
121 char *cfg = get_path("gui.conf");
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
122 FILE *f;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
123 int i;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
124
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
125 /* save configuration */
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
126 if ((f = fopen(cfg, "wt+")))
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
127 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
128 for (i=0; gui_opts[i].name; i++)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
129 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
130 char *v = m_option_print(&gui_opts[i], gui_opts[i].p);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
131 if(v)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
132 {
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
133 fprintf(f, "%s = \"%s\"\n", gui_opts[i].name, v);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
134 free(v);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
135 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
136 else if((int) v == -1)
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
137 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_UnableToSaveOption, gui_opts[i].name);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
138 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
139 fclose(f);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
140 }
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
141 free(cfg);
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
142 return 0;
d450ec82ae57 Initial win32 gui release.
vayne
parents:
diff changeset
143 }