Mercurial > mplayer.hg
annotate codec-cfg.c @ 34446:09020543b462
Remove file that was checked in accidentally (it was missing the .md5 part).
author | reimar |
---|---|
date | Sun, 08 Jan 2012 13:46:29 +0000 |
parents | 8a96cf601e57 |
children | 24d759ba7d5e |
rev | line source |
---|---|
319 | 1 /* |
2 * codec.conf parser | |
4676 | 3 * |
22501 | 4 * to compile test application: |
5 * cc -I. -DTESTING -o codec-cfg-test codec-cfg.c mp_msg.o osdep/getch2.o -ltermcap | |
15303 | 6 * to compile CODECS2HTML: |
33246 | 7 * gcc -DCODECS2HTML -o codecs2html codec-cfg.c |
4676 | 8 * |
9 * TODO: implement informat in CODECS2HTML too | |
30429
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
10 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
11 * Copyright (C) 2001 Szabolcs Berecz <szabi@inf.elte.hu> |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
12 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
13 * This file is part of MPlayer. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
14 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
15 * MPlayer is free software; you can redistribute it and/or modify |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
16 * it under the terms of the GNU General Public License as published by |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
17 * the Free Software Foundation; either version 2 of the License, or |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
18 * (at your option) any later version. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
19 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
20 * MPlayer is distributed in the hope that it will be useful, |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
23 * GNU General Public License for more details. |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
24 * |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
25 * You should have received a copy of the GNU General Public License along |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
26 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
c1a3f1bbba26
Add license header to all top-level files missing them.
diego
parents:
30115
diff
changeset
|
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
319 | 28 */ |
303 | 29 |
319 | 30 #define DEBUG |
303 | 31 |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
32 //disable asserts |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
33 #define NDEBUG |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
34 |
297 | 35 #include <stdio.h> |
36 #include <stdlib.h> | |
37 #include <fcntl.h> | |
38 #include <unistd.h> | |
39 #include <errno.h> | |
40 #include <ctype.h> | |
41 #include <assert.h> | |
42 #include <string.h> | |
43 | |
5284
0a58c2ef1da1
added missing #include config.h, removed LIBVO2 ifdef.
arpi
parents:
5263
diff
changeset
|
44 #include "config.h" |
5937 | 45 #include "mp_msg.h" |
17841
73db10d5f2e3
remove mp_msg.c dependency when compiling codec-cfg binary.
reimar
parents:
17763
diff
changeset
|
46 #ifdef CODECS2HTML |
73db10d5f2e3
remove mp_msg.c dependency when compiling codec-cfg binary.
reimar
parents:
17763
diff
changeset
|
47 #ifdef __GNUC__ |
73db10d5f2e3
remove mp_msg.c dependency when compiling codec-cfg binary.
reimar
parents:
17763
diff
changeset
|
48 #define mp_msg(t, l, m, args...) fprintf(stderr, m, ##args) |
73db10d5f2e3
remove mp_msg.c dependency when compiling codec-cfg binary.
reimar
parents:
17763
diff
changeset
|
49 #else |
23910
8fcfdfcd6c41
C99 varargs in macros can not be empty, adjust definition so it compiles
reimar
parents:
23806
diff
changeset
|
50 #define mp_msg(t, l, ...) fprintf(stderr, __VA_ARGS__) |
17841
73db10d5f2e3
remove mp_msg.c dependency when compiling codec-cfg binary.
reimar
parents:
17763
diff
changeset
|
51 #endif |
73db10d5f2e3
remove mp_msg.c dependency when compiling codec-cfg binary.
reimar
parents:
17763
diff
changeset
|
52 #endif |
5284
0a58c2ef1da1
added missing #include config.h, removed LIBVO2 ifdef.
arpi
parents:
5263
diff
changeset
|
53 |
13619 | 54 #include "help_mp.h" |
55 | |
33561
1ff6737f2177
Avoid including aviheader.h only for mmioFOURCC, it has too many
reimar
parents:
33364
diff
changeset
|
56 #include "libavutil/avutil.h" |
15305 | 57 #include "libmpcodecs/img_format.h" |
297 | 58 #include "codec-cfg.h" |
59 | |
31406
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
60 #ifdef CODECS2HTML |
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
61 #define CODEC_CFG_MIN 20100000 |
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
62 #else |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
63 #include "codecs.conf.h" |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
64 #endif |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
65 |
5937 | 66 #define PRINT_LINENUM mp_msg(MSGT_CODECCFG,MSGL_ERR," at line %d\n", line_num) |
328 | 67 |
31077 | 68 #define MAX_NR_TOKEN 16 |
297 | 69 |
31077 | 70 #define MAX_LINE_LEN 1000 |
297 | 71 |
31077 | 72 #define RET_EOF -1 |
73 #define RET_EOL -2 | |
297 | 74 |
31077 | 75 #define TYPE_VIDEO 0 |
76 #define TYPE_AUDIO 1 | |
297 | 77 |
31406
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
78 static int codecs_conf_release; |
11759
29eea271490e
add -codecs-file for selecting a specific codecs.conf on the comand line
attila
parents:
11388
diff
changeset
|
79 char * codecs_file = NULL; |
29eea271490e
add -codecs-file for selecting a specific codecs.conf on the comand line
attila
parents:
11388
diff
changeset
|
80 |
303 | 81 static int add_to_fourcc(char *s, char *alias, unsigned int *fourcc, |
31077 | 82 unsigned int *map) |
297 | 83 { |
31077 | 84 int i, j, freeslots; |
85 unsigned int tmp; | |
319 | 86 |
31077 | 87 /* find first unused slot */ |
88 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) | |
89 /* NOTHING */; | |
90 freeslots = CODECS_MAX_FOURCC - i; | |
91 if (!freeslots) | |
92 goto err_out_too_many; | |
319 | 93 |
31077 | 94 do { |
33561
1ff6737f2177
Avoid including aviheader.h only for mmioFOURCC, it has too many
reimar
parents:
33364
diff
changeset
|
95 tmp = MKTAG(s[0], s[1], s[2], s[3]); |
31077 | 96 for (j = 0; j < i; j++) |
97 if (tmp == fourcc[j]) | |
98 goto err_out_duplicated; | |
99 fourcc[i] = tmp; | |
33561
1ff6737f2177
Avoid including aviheader.h only for mmioFOURCC, it has too many
reimar
parents:
33364
diff
changeset
|
100 map[i] = alias ? MKTAG(alias[0], alias[1], alias[2], alias[3]) : tmp; |
31077 | 101 s += 4; |
102 i++; | |
103 } while ((*(s++) == ',') && --freeslots); | |
319 | 104 |
31077 | 105 if (!freeslots) |
106 goto err_out_too_many; | |
107 if (*(--s) != '\0') | |
108 goto err_out_parse_error; | |
109 return 1; | |
328 | 110 err_out_duplicated: |
31077 | 111 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_DuplicateFourcc); |
112 return 0; | |
328 | 113 err_out_too_many: |
31077 | 114 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_TooManyFourccs); |
115 return 0; | |
361 | 116 err_out_parse_error: |
31077 | 117 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_ParseError); |
118 return 0; | |
319 | 119 } |
120 | |
7770 | 121 static int add_to_format(char *s, char *alias,unsigned int *fourcc, unsigned int *fourccmap) |
319 | 122 { |
31077 | 123 int i, j; |
124 char *endptr; | |
297 | 125 |
31077 | 126 /* find first unused slot */ |
127 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++) | |
128 /* NOTHING */; | |
129 if (i == CODECS_MAX_FOURCC) { | |
130 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_TooManyFourccs); | |
131 return 0; | |
132 } | |
297 | 133 |
31077 | 134 fourcc[i]=strtoul(s,&endptr,0); |
135 if (*endptr != '\0') { | |
136 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_ParseErrorFIDNotNumber); | |
137 return 0; | |
138 } | |
7770 | 139 |
31077 | 140 if(alias){ |
141 fourccmap[i]=strtoul(alias,&endptr,0); | |
142 if (*endptr != '\0') { | |
143 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_ParseErrorFIDAliasNotNumber); | |
144 return 0; | |
145 } | |
146 } else | |
147 fourccmap[i]=fourcc[i]; | |
7770 | 148 |
31077 | 149 for (j = 0; j < i; j++) |
150 if (fourcc[j] == fourcc[i]) { | |
151 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_DuplicateFID); | |
152 return 0; | |
153 } | |
300 | 154 |
31077 | 155 return 1; |
297 | 156 } |
157 | |
31159 | 158 static const struct { |
159 const char *name; | |
160 const unsigned int num; | |
161 } fmt_table[] = { | |
162 // note: due to parser deficiencies/simplicity, if one format | |
163 // name matches the beginning of another, the longer one _must_ | |
164 // come first in this list. | |
34191 | 165 {"YV12", IMGFMT_YV12}, |
166 {"I420", IMGFMT_I420}, | |
167 {"IYUV", IMGFMT_IYUV}, | |
168 {"NV12", IMGFMT_NV12}, | |
169 {"NV21", IMGFMT_NV21}, | |
170 {"YVU9", IMGFMT_YVU9}, | |
171 {"IF09", IMGFMT_IF09}, | |
172 {"444P16LE", IMGFMT_444P16_LE}, | |
173 {"444P16BE", IMGFMT_444P16_BE}, | |
174 {"444P10LE", IMGFMT_444P10_LE}, | |
175 {"444P10BE", IMGFMT_444P10_BE}, | |
176 {"422P16LE", IMGFMT_422P16_LE}, | |
177 {"422P16BE", IMGFMT_422P16_BE}, | |
178 {"420P16LE", IMGFMT_420P16_LE}, | |
179 {"420P16BE", IMGFMT_420P16_BE}, | |
180 {"444P16", IMGFMT_444P16}, | |
181 {"444P10", IMGFMT_444P10}, | |
182 {"444P9", IMGFMT_444P9}, | |
183 {"422P16", IMGFMT_422P16}, | |
184 {"422P10", IMGFMT_422P10}, | |
34436 | 185 {"422P9", IMGFMT_422P9}, |
34191 | 186 {"420P16", IMGFMT_420P16}, |
187 {"420P10", IMGFMT_420P10}, | |
188 {"420P9", IMGFMT_420P9}, | |
189 {"420A", IMGFMT_420A}, | |
190 {"444P", IMGFMT_444P}, | |
191 {"422P", IMGFMT_422P}, | |
192 {"411P", IMGFMT_411P}, | |
193 {"440P", IMGFMT_440P}, | |
194 {"Y800", IMGFMT_Y800}, | |
195 {"Y8", IMGFMT_Y8}, | |
408 | 196 |
34191 | 197 {"YUY2", IMGFMT_YUY2}, |
198 {"UYVY", IMGFMT_UYVY}, | |
199 {"YVYU", IMGFMT_YVYU}, | |
408 | 200 |
34191 | 201 {"RGB48LE", IMGFMT_RGB48LE}, |
202 {"RGB48BE", IMGFMT_RGB48BE}, | |
203 {"RGB4", IMGFMT_RGB4}, | |
204 {"RGB8", IMGFMT_RGB8}, | |
205 {"RGB15", IMGFMT_RGB15}, | |
206 {"RGB16", IMGFMT_RGB16}, | |
207 {"RGB24", IMGFMT_RGB24}, | |
208 {"RGB32", IMGFMT_RGB32}, | |
209 {"BGR4", IMGFMT_BGR4}, | |
210 {"BGR8", IMGFMT_BGR8}, | |
211 {"BGR15", IMGFMT_BGR15}, | |
212 {"BGR16", IMGFMT_BGR16}, | |
213 {"BGR24", IMGFMT_BGR24}, | |
214 {"BGR32", IMGFMT_BGR32}, | |
215 {"RGB1", IMGFMT_RGB1}, | |
216 {"BGR1", IMGFMT_BGR1}, | |
217 {"GBR24P", IMGFMT_GBR24P}, | |
1871 | 218 |
34191 | 219 {"MPES", IMGFMT_MPEGPES}, |
220 {"ZRMJPEGNI", IMGFMT_ZRMJPEGNI}, | |
221 {"ZRMJPEGIT", IMGFMT_ZRMJPEGIT}, | |
222 {"ZRMJPEGIB", IMGFMT_ZRMJPEGIB}, | |
10316 | 223 |
34191 | 224 {"IDCT_MPEG2", IMGFMT_XVMC_IDCT_MPEG2}, |
225 {"MOCO_MPEG2", IMGFMT_XVMC_MOCO_MPEG2}, | |
10316 | 226 |
34191 | 227 {"VDPAU_MPEG1", IMGFMT_VDPAU_MPEG1}, |
228 {"VDPAU_MPEG2", IMGFMT_VDPAU_MPEG2}, | |
229 {"VDPAU_H264", IMGFMT_VDPAU_H264}, | |
230 {"VDPAU_WMV3", IMGFMT_VDPAU_WMV3}, | |
231 {"VDPAU_VC1", IMGFMT_VDPAU_VC1}, | |
232 {"VDPAU_MPEG4", IMGFMT_VDPAU_MPEG4}, | |
28516
79b0bd20433e
Add support for image formats and codecs used by VDPAU
reimar
parents:
27343
diff
changeset
|
233 |
31159 | 234 {NULL, 0} |
235 }; | |
408 | 236 |
607 | 237 |
4675 | 238 static int add_to_inout(char *sfmt, char *sflags, unsigned int *outfmt, |
31077 | 239 unsigned char *outflags) |
607 | 240 { |
241 | |
31077 | 242 static char *flagstr[] = { |
243 "flip", | |
244 "noflip", | |
245 "yuvhack", | |
246 "query", | |
247 "static", | |
248 NULL | |
249 }; | |
299 | 250 |
31077 | 251 int i, j, freeslots; |
252 unsigned char flags; | |
297 | 253 |
31077 | 254 for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++) |
255 /* NOTHING */; | |
256 freeslots = CODECS_MAX_OUTFMT - i; | |
257 if (!freeslots) | |
258 goto err_out_too_many; | |
297 | 259 |
31077 | 260 flags = 0; |
261 if(sflags) { | |
262 do { | |
263 for (j = 0; flagstr[j] != NULL; j++) | |
264 if (!strncmp(sflags, flagstr[j], | |
265 strlen(flagstr[j]))) | |
266 break; | |
267 if (flagstr[j] == NULL) | |
268 goto err_out_parse_error; | |
269 flags|=(1<<j); | |
270 sflags+=strlen(flagstr[j]); | |
271 } while (*(sflags++) == ','); | |
361 | 272 |
31077 | 273 if (*(--sflags) != '\0') |
274 goto err_out_parse_error; | |
275 } | |
297 | 276 |
31077 | 277 do { |
278 for (j = 0; fmt_table[j].name != NULL; j++) | |
279 if (!strncmp(sfmt, fmt_table[j].name, strlen(fmt_table[j].name))) | |
280 break; | |
281 if (fmt_table[j].name == NULL) | |
282 goto err_out_parse_error; | |
283 outfmt[i] = fmt_table[j].num; | |
284 outflags[i] = flags; | |
285 ++i; | |
286 sfmt+=strlen(fmt_table[j].name); | |
287 } while ((*(sfmt++) == ',') && --freeslots); | |
319 | 288 |
31077 | 289 if (!freeslots) |
290 goto err_out_too_many; | |
319 | 291 |
31077 | 292 if (*(--sfmt) != '\0') |
293 goto err_out_parse_error; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
294 |
31077 | 295 return 1; |
328 | 296 err_out_too_many: |
31077 | 297 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_TooManyOut); |
298 return 0; | |
361 | 299 err_out_parse_error: |
31077 | 300 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_ParseError); |
301 return 0; | |
297 | 302 } |
303 | |
7180
28677d779205
-afm/-vfm migration from ID (int) to NAME (string) - simplifies code and makes dlopen()'ing possible
arpi
parents:
6927
diff
changeset
|
304 #if 0 |
303 | 305 static short get_driver(char *s,int audioflag) |
297 | 306 { |
31077 | 307 static char *audiodrv[] = { |
308 "null", | |
309 "mp3lib", | |
310 "pcm", | |
311 "libac3", | |
312 "acm", | |
313 "alaw", | |
314 "msgsm", | |
315 "dshow", | |
316 "dvdpcm", | |
317 "hwac3", | |
318 "libvorbis", | |
319 "ffmpeg", | |
320 "libmad", | |
321 "msadpcm", | |
322 "liba52", | |
323 "g72x", | |
324 "imaadpcm", | |
325 "dk4adpcm", | |
326 "dk3adpcm", | |
327 "roqaudio", | |
328 "faad", | |
329 "realaud", | |
330 "libdv", | |
331 NULL | |
332 }; | |
333 static char *videodrv[] = { | |
334 "null", | |
335 "libmpeg2", | |
336 "vfw", | |
337 "dshow", | |
338 "ffmpeg", | |
339 "vfwex", | |
340 "raw", | |
341 "msrle", | |
342 "xanim", | |
343 "msvidc", | |
344 "fli", | |
345 "cinepak", | |
346 "qtrle", | |
347 "nuv", | |
348 "cyuv", | |
349 "qtsmc", | |
350 "ducktm1", | |
351 "roqvideo", | |
352 "qtrpza", | |
353 "mpng", | |
354 "ijpg", | |
355 "zlib", | |
356 "mpegpes", | |
357 "zrmjpeg", | |
358 "realvid", | |
359 "xvid", | |
360 "libdv", | |
361 NULL | |
362 }; | |
363 char **drv=audioflag?audiodrv:videodrv; | |
364 int i; | |
6863 | 365 |
31077 | 366 for(i=0;drv[i];i++) if(!strcmp(s,drv[i])) return i; |
301 | 367 |
31077 | 368 return -1; |
297 | 369 } |
7180
28677d779205
-afm/-vfm migration from ID (int) to NAME (string) - simplifies code and makes dlopen()'ing possible
arpi
parents:
6927
diff
changeset
|
370 #endif |
297 | 371 |
328 | 372 static int validate_codec(codecs_t *c, int type) |
319 | 373 { |
31077 | 374 unsigned int i; |
375 char *tmp_name = c->name; | |
328 | 376 |
31077 | 377 for (i = 0; i < strlen(tmp_name) && isalnum(tmp_name[i]); i++) |
378 /* NOTHING */; | |
3408 | 379 |
31077 | 380 if (i < strlen(tmp_name)) { |
381 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_InvalidCodecName, c->name); | |
382 return 0; | |
383 } | |
3408 | 384 |
31077 | 385 if (!c->info) |
386 c->info = strdup(c->name); | |
3408 | 387 |
388 #if 0 | |
31077 | 389 if (c->fourcc[0] == 0xffffffff) { |
390 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecLacksFourcc, c->name); | |
391 return 0; | |
392 } | |
13936
589b227e3367
fix crash when a "driver" line is missing in codecs.conf.
reimar
parents:
13807
diff
changeset
|
393 #endif |
3408 | 394 |
31077 | 395 if (!c->drv) { |
396 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecLacksDriver, c->name); | |
397 return 0; | |
398 } | |
3408 | 399 |
400 #if 0 | |
32394
914208d188b9
Remove #warning preprocessor directives or replace them by suitable comments.
diego
parents:
31409
diff
changeset
|
401 //FIXME: codec->driver == 4;... <- this should not be put in here... |
914208d188b9
Remove #warning preprocessor directives or replace them by suitable comments.
diego
parents:
31409
diff
changeset
|
402 //FIXME: Where are they defined ???????????? |
31077 | 403 if (!c->dll && (c->driver == 4 || |
404 (c->driver == 2 && type == TYPE_VIDEO))) { | |
405 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecNeedsDLL, c->name); | |
406 return 0; | |
407 } | |
32394
914208d188b9
Remove #warning preprocessor directives or replace them by suitable comments.
diego
parents:
31409
diff
changeset
|
408 // FIXME: Can guid.f1 be 0? How does one know that it was not given? |
31077 | 409 // if (!(codec->flags & CODECS_FLAG_AUDIO) && codec->driver == 4) |
328 | 410 |
31077 | 411 if (type == TYPE_VIDEO) |
412 if (c->outfmt[0] == 0xffffffff) { | |
413 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecNeedsOutfmt, c->name); | |
414 return 0; | |
415 } | |
329 | 416 #endif |
31077 | 417 return 1; |
319 | 418 } |
419 | |
420 static int add_comment(char *s, char **d) | |
421 { | |
31077 | 422 int pos; |
319 | 423 |
31077 | 424 if (!*d) |
425 pos = 0; | |
426 else { | |
427 pos = strlen(*d); | |
428 (*d)[pos++] = '\n'; | |
429 } | |
430 if (!(*d = realloc(*d, pos + strlen(s) + 1))) { | |
431 mp_msg(MSGT_CODECCFG,MSGL_FATAL,MSGTR_CantAllocateComment); | |
432 return 0; | |
433 } | |
434 strcpy(*d + pos, s); | |
435 return 1; | |
319 | 436 } |
297 | 437 |
361 | 438 static short get_cpuflags(char *s) |
439 { | |
31077 | 440 static char *flagstr[] = { |
441 "mmx", | |
442 "sse", | |
443 "3dnow", | |
444 NULL | |
445 }; | |
446 int i; | |
447 short flags = 0; | |
361 | 448 |
31077 | 449 do { |
450 for (i = 0; flagstr[i]; i++) | |
451 if (!strncmp(s, flagstr[i], strlen(flagstr[i]))) | |
452 break; | |
453 if (!flagstr[i]) | |
454 goto err_out_parse_error; | |
455 flags |= 1<<i; | |
456 s += strlen(flagstr[i]); | |
457 } while (*(s++) == ','); | |
361 | 458 |
31077 | 459 if (*(--s) != '\0') |
460 goto err_out_parse_error; | |
361 | 461 |
31077 | 462 return flags; |
361 | 463 err_out_parse_error: |
31077 | 464 return 0; |
361 | 465 } |
466 | |
328 | 467 static FILE *fp; |
468 static int line_num = 0; | |
469 static char *line; | |
470 static char *token[MAX_NR_TOKEN]; | |
6200
e604be87613d
codecs.conf versioning - patch by Joey Parrish <joey@yunamusic.com>
arpi
parents:
6103
diff
changeset
|
471 static int read_nextline = 1; |
328 | 472 |
473 static int get_token(int min, int max) | |
297 | 474 { |
31077 | 475 static int line_pos; |
476 int i; | |
477 char c; | |
328 | 478 |
31077 | 479 if (max >= MAX_NR_TOKEN) { |
480 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_GetTokenMaxNotLessThanMAX_NR_TOKEN); | |
481 goto out_eof; | |
482 } | |
328 | 483 |
31077 | 484 memset(token, 0x00, sizeof(*token) * max); |
328 | 485 |
31077 | 486 if (read_nextline) { |
487 if (!fgets(line, MAX_LINE_LEN, fp)) | |
488 goto out_eof; | |
489 line_pos = 0; | |
490 ++line_num; | |
491 read_nextline = 0; | |
492 } | |
493 for (i = 0; i < max; i++) { | |
494 while (isspace(line[line_pos])) | |
495 ++line_pos; | |
496 if (line[line_pos] == '\0' || line[line_pos] == '#' || | |
497 line[line_pos] == ';') { | |
498 read_nextline = 1; | |
499 if (i >= min) | |
500 goto out_ok; | |
501 goto out_eol; | |
502 } | |
503 token[i] = line + line_pos; | |
504 c = line[line_pos]; | |
505 if (c == '"' || c == '\'') { | |
506 token[i]++; | |
507 while (line[++line_pos] != c && line[line_pos]) | |
508 /* NOTHING */; | |
509 } else { | |
510 for (/* NOTHING */; !isspace(line[line_pos]) && | |
511 line[line_pos]; line_pos++) | |
512 /* NOTHING */; | |
513 } | |
514 if (!line[line_pos]) { | |
515 read_nextline = 1; | |
516 if (i >= min - 1) | |
517 goto out_ok; | |
518 goto out_eol; | |
519 } | |
520 line[line_pos] = '\0'; | |
521 line_pos++; | |
522 } | |
328 | 523 out_ok: |
31077 | 524 return i; |
328 | 525 out_eof: |
31077 | 526 read_nextline = 1; |
527 return RET_EOF; | |
328 | 528 out_eol: |
31077 | 529 return RET_EOL; |
328 | 530 } |
531 | |
532 static codecs_t *video_codecs=NULL; | |
533 static codecs_t *audio_codecs=NULL; | |
534 static int nr_vcodecs = 0; | |
535 static int nr_acodecs = 0; | |
536 | |
18980
ed69754aa58d
Marks several string parameters as const when they are not modified in the function, Patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents:
18034
diff
changeset
|
537 int parse_codec_cfg(const char *cfgfile) |
328 | 538 { |
31077 | 539 codecs_t *codec = NULL; // current codec |
540 codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs | |
541 char *endptr; // strtoul()... | |
542 int *nr_codecsp; | |
543 int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */ | |
544 int tmp, i; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
545 |
31077 | 546 // in case we call it a second time |
547 codecs_uninit_free(); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
548 |
31077 | 549 nr_vcodecs = 0; |
550 nr_acodecs = 0; | |
297 | 551 |
31077 | 552 if(cfgfile==NULL) { |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
553 #ifdef CODECS2HTML |
31077 | 554 return 0; |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
555 #else |
31077 | 556 video_codecs = builtin_video_codecs; |
557 audio_codecs = builtin_audio_codecs; | |
558 nr_vcodecs = sizeof(builtin_video_codecs)/sizeof(codecs_t); | |
559 nr_acodecs = sizeof(builtin_audio_codecs)/sizeof(codecs_t); | |
560 return 1; | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
561 #endif |
31077 | 562 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
563 |
33844
77bf38091051
Clarify console output when reading optional configuration files.
diego
parents:
33843
diff
changeset
|
564 mp_msg(MSGT_CODECCFG, MSGL_V, "Reading optional codecs config file %s: ", cfgfile); |
297 | 565 |
31077 | 566 if ((fp = fopen(cfgfile, "r")) == NULL) { |
33844
77bf38091051
Clarify console output when reading optional configuration files.
diego
parents:
33843
diff
changeset
|
567 mp_msg(MSGT_CODECCFG, MSGL_V, "%s\n", strerror(errno)); |
31077 | 568 return 0; |
569 } | |
297 | 570 |
31077 | 571 if ((line = malloc(MAX_LINE_LEN + 1)) == NULL) { |
572 mp_msg(MSGT_CODECCFG,MSGL_FATAL,MSGTR_CantGetMemoryForLine, strerror(errno)); | |
573 return 0; | |
574 } | |
575 read_nextline = 1; | |
297 | 576 |
31077 | 577 /* |
578 * this only catches release lines at the start of | |
579 * codecs.conf, before audiocodecs and videocodecs. | |
580 */ | |
581 while ((tmp = get_token(1, 1)) == RET_EOL) | |
582 /* NOTHING */; | |
583 if (tmp == RET_EOF) | |
584 goto out; | |
585 if (!strcmp(token[0], "release")) { | |
586 if (get_token(1, 2) < 0) | |
587 goto err_out_parse_error; | |
588 tmp = atoi(token[0]); | |
589 if (tmp < CODEC_CFG_MIN) | |
590 goto err_out_release_num; | |
31406
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
591 codecs_conf_release = tmp; |
31077 | 592 while ((tmp = get_token(1, 1)) == RET_EOL) |
593 /* NOTHING */; | |
594 if (tmp == RET_EOF) | |
595 goto out; | |
596 } else | |
597 goto err_out_release_num; | |
6200
e604be87613d
codecs.conf versioning - patch by Joey Parrish <joey@yunamusic.com>
arpi
parents:
6103
diff
changeset
|
598 |
31077 | 599 /* |
600 * check if the next block starts with 'audiocodec' or | |
601 * with 'videocodec' | |
602 */ | |
603 if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec")) | |
604 goto loop_enter; | |
605 goto err_out_parse_error; | |
328 | 606 |
31077 | 607 while ((tmp = get_token(1, 1)) != RET_EOF) { |
608 if (tmp == RET_EOL) | |
609 continue; | |
610 if (!strcmp(token[0], "audiocodec") || | |
611 !strcmp(token[0], "videocodec")) { | |
612 if (!validate_codec(codec, codec_type)) | |
613 goto err_out_not_valid; | |
614 loop_enter: | |
615 if (*token[0] == 'v') { | |
616 codec_type = TYPE_VIDEO; | |
617 nr_codecsp = &nr_vcodecs; | |
618 codecsp = &video_codecs; | |
619 } else if (*token[0] == 'a') { | |
620 codec_type = TYPE_AUDIO; | |
621 nr_codecsp = &nr_acodecs; | |
622 codecsp = &audio_codecs; | |
361 | 623 #ifdef DEBUG |
31077 | 624 } else { |
625 mp_msg(MSGT_CODECCFG,MSGL_ERR,"picsba\n"); | |
626 goto err_out; | |
361 | 627 #endif |
31077 | 628 } |
629 if (!(*codecsp = realloc(*codecsp, | |
630 sizeof(codecs_t) * (*nr_codecsp + 2)))) { | |
631 mp_msg(MSGT_CODECCFG,MSGL_FATAL,MSGTR_CantReallocCodecsp, strerror(errno)); | |
632 goto err_out; | |
633 } | |
634 codec=*codecsp + *nr_codecsp; | |
635 ++*nr_codecsp; | |
636 memset(codec,0,sizeof(codecs_t)); | |
637 memset(codec->fourcc, 0xff, sizeof(codec->fourcc)); | |
638 memset(codec->outfmt, 0xff, sizeof(codec->outfmt)); | |
639 memset(codec->infmt, 0xff, sizeof(codec->infmt)); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
640 |
31077 | 641 if (get_token(1, 1) < 0) |
642 goto err_out_parse_error; | |
643 for (i = 0; i < *nr_codecsp - 1; i++) { | |
644 if(( (*codecsp)[i].name!=NULL) && | |
645 (!strcmp(token[0], (*codecsp)[i].name)) ) { | |
646 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecNameNotUnique, token[0]); | |
647 goto err_out_print_linenum; | |
648 } | |
649 } | |
650 if (!(codec->name = strdup(token[0]))) { | |
651 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupName, strerror(errno)); | |
652 goto err_out; | |
653 } | |
654 } else if (!strcmp(token[0], "info")) { | |
655 if (codec->info || get_token(1, 1) < 0) | |
656 goto err_out_parse_error; | |
657 if (!(codec->info = strdup(token[0]))) { | |
658 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupInfo, strerror(errno)); | |
659 goto err_out; | |
660 } | |
661 } else if (!strcmp(token[0], "comment")) { | |
662 if (get_token(1, 1) < 0) | |
663 goto err_out_parse_error; | |
664 add_comment(token[0], &codec->comment); | |
665 } else if (!strcmp(token[0], "fourcc")) { | |
666 if (get_token(1, 2) < 0) | |
667 goto err_out_parse_error; | |
668 if (!add_to_fourcc(token[0], token[1], | |
669 codec->fourcc, | |
670 codec->fourccmap)) | |
671 goto err_out_print_linenum; | |
672 } else if (!strcmp(token[0], "format")) { | |
673 if (get_token(1, 2) < 0) | |
674 goto err_out_parse_error; | |
675 if (!add_to_format(token[0], token[1], | |
676 codec->fourcc,codec->fourccmap)) | |
677 goto err_out_print_linenum; | |
678 } else if (!strcmp(token[0], "driver")) { | |
679 if (get_token(1, 1) < 0) | |
680 goto err_out_parse_error; | |
681 if (!(codec->drv = strdup(token[0]))) { | |
682 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupDriver, strerror(errno)); | |
683 goto err_out; | |
684 } | |
685 } else if (!strcmp(token[0], "dll")) { | |
686 if (get_token(1, 1) < 0) | |
687 goto err_out_parse_error; | |
688 if (!(codec->dll = strdup(token[0]))) { | |
689 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupDLL, strerror(errno)); | |
690 goto err_out; | |
691 } | |
692 } else if (!strcmp(token[0], "guid")) { | |
693 if (get_token(11, 11) < 0) | |
694 goto err_out_parse_error; | |
695 codec->guid.f1=strtoul(token[0],&endptr,0); | |
696 if ((*endptr != ',' || *(endptr + 1) != '\0') && | |
697 *endptr != '\0') | |
698 goto err_out_parse_error; | |
699 codec->guid.f2=strtoul(token[1],&endptr,0); | |
700 if ((*endptr != ',' || *(endptr + 1) != '\0') && | |
701 *endptr != '\0') | |
702 goto err_out_parse_error; | |
703 codec->guid.f3=strtoul(token[2],&endptr,0); | |
704 if ((*endptr != ',' || *(endptr + 1) != '\0') && | |
705 *endptr != '\0') | |
706 goto err_out_parse_error; | |
707 for (i = 0; i < 8; i++) { | |
708 codec->guid.f4[i]=strtoul(token[i + 3],&endptr,0); | |
709 if ((*endptr != ',' || *(endptr + 1) != '\0') && | |
710 *endptr != '\0') | |
711 goto err_out_parse_error; | |
712 } | |
713 } else if (!strcmp(token[0], "out")) { | |
714 if (get_token(1, 2) < 0) | |
715 goto err_out_parse_error; | |
716 if (!add_to_inout(token[0], token[1], codec->outfmt, | |
717 codec->outflags)) | |
718 goto err_out_print_linenum; | |
719 } else if (!strcmp(token[0], "in")) { | |
720 if (get_token(1, 2) < 0) | |
721 goto err_out_parse_error; | |
722 if (!add_to_inout(token[0], token[1], codec->infmt, | |
723 codec->inflags)) | |
724 goto err_out_print_linenum; | |
725 } else if (!strcmp(token[0], "flags")) { | |
726 if (get_token(1, 1) < 0) | |
727 goto err_out_parse_error; | |
728 if (!strcmp(token[0], "seekable")) | |
729 codec->flags |= CODECS_FLAG_SEEKABLE; | |
730 else | |
731 if (!strcmp(token[0], "align16")) | |
732 codec->flags |= CODECS_FLAG_ALIGN16; | |
733 else | |
734 goto err_out_parse_error; | |
735 } else if (!strcmp(token[0], "status")) { | |
736 if (get_token(1, 1) < 0) | |
737 goto err_out_parse_error; | |
738 if (!strcasecmp(token[0], "working")) | |
739 codec->status = CODECS_STATUS_WORKING; | |
740 else if (!strcasecmp(token[0], "crashing")) | |
741 codec->status = CODECS_STATUS_NOT_WORKING; | |
742 else if (!strcasecmp(token[0], "untested")) | |
743 codec->status = CODECS_STATUS_UNTESTED; | |
744 else if (!strcasecmp(token[0], "buggy")) | |
745 codec->status = CODECS_STATUS_PROBLEMS; | |
746 else | |
747 goto err_out_parse_error; | |
748 } else if (!strcmp(token[0], "cpuflags")) { | |
749 if (get_token(1, 1) < 0) | |
750 goto err_out_parse_error; | |
751 if (!(codec->cpuflags = get_cpuflags(token[0]))) | |
752 goto err_out_parse_error; | |
753 } else | |
754 goto err_out_parse_error; | |
755 } | |
756 if (!validate_codec(codec, codec_type)) | |
757 goto err_out_not_valid; | |
758 mp_msg(MSGT_CODECCFG,MSGL_INFO,MSGTR_AudioVideoCodecTotals, nr_acodecs, nr_vcodecs); | |
759 if(video_codecs) video_codecs[nr_vcodecs].name = NULL; | |
760 if(audio_codecs) audio_codecs[nr_acodecs].name = NULL; | |
297 | 761 out: |
31077 | 762 free(line); |
763 line=NULL; | |
764 fclose(fp); | |
765 return 1; | |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
766 |
328 | 767 err_out_parse_error: |
31077 | 768 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_ParseError); |
361 | 769 err_out_print_linenum: |
31077 | 770 PRINT_LINENUM; |
297 | 771 err_out: |
31077 | 772 codecs_uninit_free(); |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
773 |
31077 | 774 free(line); |
775 line=NULL; | |
776 line_num = 0; | |
777 fclose(fp); | |
778 return 0; | |
328 | 779 err_out_not_valid: |
31077 | 780 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecDefinitionIncorrect); |
781 goto err_out_print_linenum; | |
6200
e604be87613d
codecs.conf versioning - patch by Joey Parrish <joey@yunamusic.com>
arpi
parents:
6103
diff
changeset
|
782 err_out_release_num: |
31077 | 783 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_OutdatedCodecsConf); |
784 goto err_out_print_linenum; | |
297 | 785 } |
786 | |
13807
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
787 static void codecs_free(codecs_t* codecs,int count) { |
31077 | 788 int i; |
789 for ( i = 0; i < count; i++) | |
790 if ( codecs[i].name ) { | |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
791 free(codecs[i].name); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
792 free(codecs[i].info); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
793 free(codecs[i].comment); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
794 free(codecs[i].dll); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
795 free(codecs[i].drv); |
31077 | 796 } |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
797 free(codecs); |
13807
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
798 } |
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
799 |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17120
diff
changeset
|
800 void codecs_uninit_free(void) { |
31077 | 801 if (video_codecs) |
802 codecs_free(video_codecs,nr_vcodecs); | |
803 video_codecs=NULL; | |
804 if (audio_codecs) | |
805 codecs_free(audio_codecs,nr_acodecs); | |
806 audio_codecs=NULL; | |
13807
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
807 } |
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
808 |
332 | 809 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap, |
31077 | 810 codecs_t *start, int force) |
328 | 811 { |
31077 | 812 return find_codec(fourcc, fourccmap, start, 1, force); |
328 | 813 } |
814 | |
332 | 815 codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap, |
31077 | 816 codecs_t *start, int force) |
328 | 817 { |
31077 | 818 return find_codec(fourcc, fourccmap, start, 0, force); |
328 | 819 } |
820 | |
332 | 821 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap, |
31077 | 822 codecs_t *start, int audioflag, int force) |
328 | 823 { |
31077 | 824 int i, j; |
825 codecs_t *c; | |
328 | 826 |
628 | 827 #if 0 |
31077 | 828 if (start) { |
829 for (/* NOTHING */; start->name; start++) { | |
830 for (j = 0; j < CODECS_MAX_FOURCC; j++) { | |
831 if (start->fourcc[j] == fourcc) { | |
832 if (fourccmap) | |
833 *fourccmap = start->fourccmap[j]; | |
834 return start; | |
835 } | |
836 } | |
837 } | |
838 } else | |
628 | 839 #endif |
31077 | 840 { |
841 if (audioflag) { | |
842 i = nr_acodecs; | |
843 c = audio_codecs; | |
844 } else { | |
845 i = nr_vcodecs; | |
846 c = video_codecs; | |
847 } | |
848 if(!i) return NULL; | |
849 for (/* NOTHING */; i--; c++) { | |
850 if(start && c<=start) continue; | |
851 for (j = 0; j < CODECS_MAX_FOURCC; j++) { | |
852 // FIXME: do NOT hardwire 'null' name here: | |
853 if (c->fourcc[j]==fourcc || !strcmp(c->drv,"null")) { | |
854 if (fourccmap) | |
855 *fourccmap = c->fourccmap[j]; | |
856 return c; | |
857 } | |
858 } | |
859 if (force) return c; | |
860 } | |
861 } | |
862 return NULL; | |
303 | 863 } |
864 | |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
865 void stringset_init(stringset_t *set) { |
31077 | 866 *set = calloc(1, sizeof(char *)); |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
867 } |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
868 |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
869 void stringset_free(stringset_t *set) { |
31077 | 870 int count = 0; |
871 while ((*set)[count]) free((*set)[count++]); | |
872 free(*set); | |
873 *set = NULL; | |
7505 | 874 } |
875 | |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
876 void stringset_add(stringset_t *set, const char *str) { |
31077 | 877 int count = 0; |
878 while ((*set)[count]) count++; | |
879 count++; | |
880 *set = realloc(*set, sizeof(char *) * (count + 1)); | |
881 (*set)[count - 1] = strdup(str); | |
882 (*set)[count] = NULL; | |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
883 } |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
884 |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
885 int stringset_test(stringset_t *set, const char *str) { |
31077 | 886 stringset_t s; |
887 for (s = *set; *s; s++) | |
888 if (strcmp(*s, str) == 0) | |
889 return 1; | |
890 return 0; | |
5325
9c326f199060
tagging selected codec to avoid trying the same codec several times
arpi
parents:
5284
diff
changeset
|
891 } |
9c326f199060
tagging selected codec to avoid trying the same codec several times
arpi
parents:
5284
diff
changeset
|
892 |
1983 | 893 void list_codecs(int audioflag){ |
31077 | 894 int i; |
895 codecs_t *c; | |
1983 | 896 |
31077 | 897 if (audioflag) { |
898 i = nr_acodecs; | |
899 c = audio_codecs; | |
900 mp_msg(MSGT_CODECCFG,MSGL_INFO,"ac: afm: status: info: [lib/dll]\n"); | |
901 } else { | |
902 i = nr_vcodecs; | |
903 c = video_codecs; | |
904 mp_msg(MSGT_CODECCFG,MSGL_INFO,"vc: vfm: status: info: [lib/dll]\n"); | |
905 } | |
906 if(!i) return; | |
907 for (/* NOTHING */; i--; c++) { | |
908 char* s="unknown "; | |
909 switch(c->status){ | |
910 case CODECS_STATUS_WORKING: s="working ";break; | |
911 case CODECS_STATUS_PROBLEMS: s="problems";break; | |
912 case CODECS_STATUS_NOT_WORKING: s="crashing";break; | |
913 case CODECS_STATUS_UNTESTED: s="untested";break; | |
914 } | |
915 if(c->dll) | |
916 mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s %-9s %s %s [%s]\n",c->name,c->drv,s,c->info,c->dll); | |
917 else | |
918 mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s %-9s %s %s\n",c->name,c->drv,s,c->info); | |
919 } | |
1983 | 920 } |
921 | |
922 | |
607 | 923 #ifdef CODECS2HTML |
31408 | 924 static void wrapline(FILE *f2,char *s){ |
607 | 925 int c; |
926 if(!s){ | |
927 fprintf(f2,"-"); | |
928 return; | |
929 } | |
930 while((c=*s++)){ | |
931 if(c==',') fprintf(f2,"<br>"); else fputc(c,f2); | |
932 } | |
933 } | |
934 | |
31409 | 935 static void parsehtml(FILE *f1,FILE *f2,codecs_t *codec){ |
31077 | 936 int c,d; |
937 while((c=fgetc(f1))>=0){ | |
938 if(c!='%'){ | |
939 fputc(c,f2); | |
940 continue; | |
941 } | |
942 d=fgetc(f1); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
943 |
31077 | 944 switch(d){ |
945 case '.': | |
946 return; // end of section | |
947 case 'n': | |
948 wrapline(f2,codec->name); break; | |
949 case 'i': | |
950 wrapline(f2,codec->info); break; | |
951 case 'c': | |
952 wrapline(f2,codec->comment); break; | |
953 case 'd': | |
954 wrapline(f2,codec->dll); break; | |
955 case 'D': | |
956 fprintf(f2,"%c",!strcmp(codec->drv,"dshow")?'+':'-'); break; | |
957 case 'F': | |
958 for(d=0;d<CODECS_MAX_FOURCC;d++) | |
959 if(!d || codec->fourcc[d]!=0xFFFFFFFF) | |
960 fprintf(f2,"%s%.4s",d?"<br>":"",(codec->fourcc[d]==0xFFFFFFFF || codec->fourcc[d]<0x20202020)?!d?"-":"":(char*) &codec->fourcc[d]); | |
961 break; | |
962 case 'f': | |
963 for(d=0;d<CODECS_MAX_FOURCC;d++) | |
964 if(codec->fourcc[d]!=0xFFFFFFFF) | |
965 fprintf(f2,"%s0x%X",d?"<br>":"",codec->fourcc[d]); | |
966 break; | |
967 case 'Y': | |
968 for(d=0;d<CODECS_MAX_OUTFMT;d++) | |
969 if(codec->outfmt[d]!=0xFFFFFFFF){ | |
970 for (c=0; fmt_table[c].name; c++) | |
971 if(fmt_table[c].num==codec->outfmt[d]) break; | |
972 if(fmt_table[c].name) | |
973 fprintf(f2,"%s%s",d?"<br>":"",fmt_table[c].name); | |
974 } | |
975 break; | |
976 default: | |
977 fputc(c,f2); | |
978 fputc(d,f2); | |
607 | 979 } |
31077 | 980 } |
607 | 981 } |
982 | |
983 void skiphtml(FILE *f1){ | |
31077 | 984 int c,d; |
985 while((c=fgetc(f1))>=0){ | |
986 if(c!='%'){ | |
987 continue; | |
607 | 988 } |
31077 | 989 d=fgetc(f1); |
990 if(d=='.') return; // end of section | |
991 } | |
607 | 992 } |
993 | |
29115
1e78a310487e
Change type of first argument of the print_int_array function from int to
diego
parents:
28747
diff
changeset
|
994 static void print_int_array(const unsigned int* a, int size) |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
995 { |
31077 | 996 printf("{ "); |
997 while (size--) | |
998 if(abs(*a)<256) | |
999 printf("%d%s", *a++, size?", ":""); | |
1000 else | |
1001 printf("0x%X%s", *a++, size?", ":""); | |
1002 printf(" }"); | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1003 } |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1004 |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1005 static void print_char_array(const unsigned char* a, int size) |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1006 { |
31077 | 1007 printf("{ "); |
1008 while (size--) | |
1009 if((*a)<10) | |
1010 printf("%d%s", *a++, size?", ":""); | |
1011 else | |
1012 printf("0x%02x%s", *a++, size?", ":""); | |
1013 printf(" }"); | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1014 } |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1015 |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1016 static void print_string(const char* s) |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1017 { |
31077 | 1018 if (!s) printf("NULL"); |
1019 else printf("\"%s\"", s); | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1020 } |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1021 |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1022 int main(int argc, char* argv[]) |
607 | 1023 { |
31077 | 1024 codecs_t *cl; |
1025 FILE *f1; | |
1026 FILE *f2; | |
1027 int c,d,i; | |
1028 int pos; | |
1029 int section=-1; | |
1030 int nr_codecs; | |
1031 int win32=-1; | |
1032 int dshow=-1; | |
1033 int win32ex=-1; | |
607 | 1034 |
31077 | 1035 /* |
1036 * Take path to codecs.conf from command line, or fall back on | |
1037 * etc/codecs.conf | |
1038 */ | |
1039 if (!(nr_codecs = parse_codec_cfg((argc>1)?argv[1]:"etc/codecs.conf"))) | |
1040 exit(1); | |
31406
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
1041 if (codecs_conf_release < CODEC_CFG_MIN) |
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
1042 exit(1); |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1043 |
31077 | 1044 if (argc > 1) { |
1045 int i, j; | |
1046 const char* nm[2]; | |
1047 codecs_t* cod[2]; | |
1048 int nr[2]; | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1049 |
31077 | 1050 nm[0] = "builtin_video_codecs"; |
1051 cod[0] = video_codecs; | |
1052 nr[0] = nr_vcodecs; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1053 |
31077 | 1054 nm[1] = "builtin_audio_codecs"; |
1055 cod[1] = audio_codecs; | |
1056 nr[1] = nr_acodecs; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1057 |
31077 | 1058 printf("/* GENERATED FROM %s, DO NOT EDIT! */\n\n",argv[1]); |
31407 | 1059 printf("#include <stddef.h>\n"); |
1060 printf("#include \"codec-cfg.h\"\n\n"); | |
31406
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
1061 printf("#define CODEC_CFG_MIN %i\n\n", codecs_conf_release); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1062 |
31077 | 1063 for (i=0; i<2; i++) { |
1064 printf("const codecs_t %s[] = {\n", nm[i]); | |
1065 for (j = 0; j < nr[i]; j++) { | |
1066 printf("{"); | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1067 |
31077 | 1068 print_int_array(cod[i][j].fourcc, CODECS_MAX_FOURCC); |
1069 printf(", /* fourcc */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1070 |
31077 | 1071 print_int_array(cod[i][j].fourccmap, CODECS_MAX_FOURCC); |
1072 printf(", /* fourccmap */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1073 |
31077 | 1074 print_int_array(cod[i][j].outfmt, CODECS_MAX_OUTFMT); |
1075 printf(", /* outfmt */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1076 |
31077 | 1077 print_char_array(cod[i][j].outflags, CODECS_MAX_OUTFMT); |
1078 printf(", /* outflags */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1079 |
31077 | 1080 print_int_array(cod[i][j].infmt, CODECS_MAX_INFMT); |
1081 printf(", /* infmt */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1082 |
31077 | 1083 print_char_array(cod[i][j].inflags, CODECS_MAX_INFMT); |
1084 printf(", /* inflags */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1085 |
31077 | 1086 print_string(cod[i][j].name); printf(", /* name */\n"); |
1087 print_string(cod[i][j].info); printf(", /* info */\n"); | |
1088 print_string(cod[i][j].comment); printf(", /* comment */\n"); | |
1089 print_string(cod[i][j].dll); printf(", /* dll */\n"); | |
1090 print_string(cod[i][j].drv); printf(", /* drv */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1091 |
31077 | 1092 printf("{ 0x%08lx, %hu, %hu,", |
1093 cod[i][j].guid.f1, | |
1094 cod[i][j].guid.f2, | |
1095 cod[i][j].guid.f3); | |
1096 print_char_array(cod[i][j].guid.f4, sizeof(cod[i][j].guid.f4)); | |
1097 printf(" }, /* GUID */\n"); | |
1098 printf("%hd /* flags */, %hd /* status */, %hd /* cpuflags */ }\n", | |
1099 cod[i][j].flags, | |
1100 cod[i][j].status, | |
1101 cod[i][j].cpuflags); | |
1102 if (j < nr[i]) printf(",\n"); | |
607 | 1103 } |
31077 | 1104 printf("};\n\n"); |
1105 } | |
1106 exit(0); | |
1107 } | |
1108 | |
1109 f1=fopen("DOCS/tech/codecs-in.html","rb"); if(!f1) exit(1); | |
1110 f2=fopen("DOCS/codecs-status.html","wb"); if(!f2) exit(1); | |
1111 | |
1112 while((c=fgetc(f1))>=0){ | |
1113 if(c!='%'){ | |
1114 fputc(c,f2); | |
1115 continue; | |
1116 } | |
1117 d=fgetc(f1); | |
1118 if(d>='0' && d<='9'){ | |
1119 // begin section | |
1120 section=d-'0'; | |
1121 //printf("BEGIN %d\n",section); | |
1122 if(section>=5){ | |
1123 // audio | |
1124 cl = audio_codecs; | |
1125 nr_codecs = nr_acodecs; | |
1126 dshow=7;win32=4; | |
1127 } else { | |
1128 // video | |
1129 cl = video_codecs; | |
1130 nr_codecs = nr_vcodecs; | |
1131 dshow=4;win32=2;win32ex=6; | |
1132 } | |
1133 pos=ftell(f1); | |
1134 for(i=0;i<nr_codecs;i++){ | |
1135 fseek(f1,pos,SEEK_SET); | |
1136 switch(section){ | |
1137 case 0: | |
1138 case 5: | |
1139 if(cl[i].status==CODECS_STATUS_WORKING) | |
1140 // if(!(!strcmp(cl[i].drv,"vfw") || !strcmp(cl[i].drv,"dshow") || !strcmp(cl[i].drv,"vfwex") || !strcmp(cl[i].drv,"acm"))) | |
31409 | 1141 parsehtml(f1,f2,&cl[i]); |
31077 | 1142 break; |
8211 | 1143 #if 0 |
31077 | 1144 case 1: |
1145 case 6: | |
1146 if(cl[i].status==CODECS_STATUS_WORKING) | |
1147 if((!strcmp(cl[i].drv,"vfw") || !strcmp(cl[i].drv,"dshow") || !strcmp(cl[i].drv,"vfwex") || !strcmp(cl[i].drv,"acm"))) | |
31409 | 1148 parsehtml(f1,f2,&cl[i]); |
31077 | 1149 break; |
1150 #endif | |
1151 case 2: | |
1152 case 7: | |
1153 if(cl[i].status==CODECS_STATUS_PROBLEMS) | |
31409 | 1154 parsehtml(f1,f2,&cl[i]); |
31077 | 1155 break; |
1156 case 3: | |
1157 case 8: | |
1158 if(cl[i].status==CODECS_STATUS_NOT_WORKING) | |
31409 | 1159 parsehtml(f1,f2,&cl[i]); |
31077 | 1160 break; |
1161 case 4: | |
1162 case 9: | |
1163 if(cl[i].status==CODECS_STATUS_UNTESTED) | |
31409 | 1164 parsehtml(f1,f2,&cl[i]); |
31077 | 1165 break; |
1166 default: | |
1167 printf("Warning! unimplemented section: %d\n",section); | |
607 | 1168 } |
31077 | 1169 } |
1170 fseek(f1,pos,SEEK_SET); | |
1171 skiphtml(f1); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1172 |
31077 | 1173 continue; |
607 | 1174 } |
31077 | 1175 fputc(c,f2); |
1176 fputc(d,f2); | |
1177 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1178 |
31077 | 1179 fclose(f2); |
1180 fclose(f1); | |
1181 return 0; | |
607 | 1182 } |
1183 | |
1184 #endif | |
1185 | |
297 | 1186 #ifdef TESTING |
1187 int main(void) | |
1188 { | |
31077 | 1189 codecs_t *c; |
1190 int i,j, nr_codecs, state; | |
297 | 1191 |
31077 | 1192 if (!(parse_codec_cfg("etc/codecs.conf"))) |
1193 return 0; | |
1194 if (!video_codecs) | |
1195 printf("no videoconfig.\n"); | |
1196 if (!audio_codecs) | |
1197 printf("no audioconfig.\n"); | |
328 | 1198 |
31077 | 1199 printf("videocodecs:\n"); |
1200 c = video_codecs; | |
1201 nr_codecs = nr_vcodecs; | |
1202 state = 0; | |
328 | 1203 next: |
31077 | 1204 if (c) { |
1205 printf("number of %scodecs: %d\n", state==0?"video":"audio", | |
1206 nr_codecs); | |
1207 for(i=0;i<nr_codecs;i++, c++){ | |
1208 printf("\n============== %scodec %02d ===============\n", | |
1209 state==0?"video":"audio",i); | |
1210 printf("name='%s'\n",c->name); | |
1211 printf("info='%s'\n",c->info); | |
1212 printf("comment='%s'\n",c->comment); | |
1213 printf("dll='%s'\n",c->dll); | |
1214 /* printf("flags=%X driver=%d status=%d cpuflags=%d\n", | |
1215 c->flags, c->driver, c->status, c->cpuflags); */ | |
1216 printf("flags=%X status=%d cpuflags=%d\n", | |
1217 c->flags, c->status, c->cpuflags); | |
300 | 1218 |
31077 | 1219 for(j=0;j<CODECS_MAX_FOURCC;j++){ |
1220 if(c->fourcc[j]!=0xFFFFFFFF){ | |
1221 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],(char *) &c->fourcc[j],c->fourccmap[j],(char *) &c->fourccmap[j]); | |
1222 } | |
1223 } | |
328 | 1224 |
31077 | 1225 for(j=0;j<CODECS_MAX_OUTFMT;j++){ |
1226 if(c->outfmt[j]!=0xFFFFFFFF){ | |
1227 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],(char *) &c->outfmt[j],c->outflags[j]); | |
1228 } | |
1229 } | |
300 | 1230 |
31077 | 1231 for(j=0;j<CODECS_MAX_INFMT;j++){ |
1232 if(c->infmt[j]!=0xFFFFFFFF){ | |
1233 printf("infmt %02d: %08X (%.4s) flags: %d\n",j,c->infmt[j],(char *) &c->infmt[j],c->inflags[j]); | |
1234 } | |
1235 } | |
4676 | 1236 |
31077 | 1237 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3); |
1238 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]); | |
1239 printf("\n"); | |
300 | 1240 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1241 |
31077 | 1242 } |
1243 } | |
1244 if (!state) { | |
1245 printf("audiocodecs:\n"); | |
1246 c = audio_codecs; | |
1247 nr_codecs = nr_acodecs; | |
1248 state = 1; | |
1249 goto next; | |
1250 } | |
1251 return 0; | |
297 | 1252 } |
1253 | |
1254 #endif |