Mercurial > mplayer.hg
annotate codec-cfg.c @ 34578:948bec0f8df3
Cosmetic: Change some variable names.
author | ib |
---|---|
date | Thu, 09 Feb 2012 13:43:23 +0000 |
parents | 2a372b469420 |
children | 1ce075a9932b |
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}, | |
34565 | 191 {"444A", IMGFMT_444A}, |
34191 | 192 {"422P", IMGFMT_422P}, |
193 {"411P", IMGFMT_411P}, | |
194 {"440P", IMGFMT_440P}, | |
195 {"Y800", IMGFMT_Y800}, | |
196 {"Y8", IMGFMT_Y8}, | |
408 | 197 |
34191 | 198 {"YUY2", IMGFMT_YUY2}, |
199 {"UYVY", IMGFMT_UYVY}, | |
200 {"YVYU", IMGFMT_YVYU}, | |
408 | 201 |
34572 | 202 {"RGB64LE", IMGFMT_RGB64LE}, |
203 {"RGB64BE", IMGFMT_RGB64BE}, | |
34191 | 204 {"RGB48LE", IMGFMT_RGB48LE}, |
205 {"RGB48BE", IMGFMT_RGB48BE}, | |
206 {"RGB4", IMGFMT_RGB4}, | |
207 {"RGB8", IMGFMT_RGB8}, | |
208 {"RGB15", IMGFMT_RGB15}, | |
209 {"RGB16", IMGFMT_RGB16}, | |
210 {"RGB24", IMGFMT_RGB24}, | |
211 {"RGB32", IMGFMT_RGB32}, | |
34501 | 212 {"RGBA", IMGFMT_RGBA}, |
34191 | 213 {"BGR4", IMGFMT_BGR4}, |
214 {"BGR8", IMGFMT_BGR8}, | |
215 {"BGR15", IMGFMT_BGR15}, | |
216 {"BGR16", IMGFMT_BGR16}, | |
217 {"BGR24", IMGFMT_BGR24}, | |
218 {"BGR32", IMGFMT_BGR32}, | |
34509
bdca973d87a5
Fix 32-bit targa playback with current FFmpeg on big-endian.
cehoyos
parents:
34501
diff
changeset
|
219 {"BGRA", IMGFMT_BGRA}, |
34191 | 220 {"RGB1", IMGFMT_RGB1}, |
221 {"BGR1", IMGFMT_BGR1}, | |
222 {"GBR24P", IMGFMT_GBR24P}, | |
1871 | 223 |
34191 | 224 {"MPES", IMGFMT_MPEGPES}, |
225 {"ZRMJPEGNI", IMGFMT_ZRMJPEGNI}, | |
226 {"ZRMJPEGIT", IMGFMT_ZRMJPEGIT}, | |
227 {"ZRMJPEGIB", IMGFMT_ZRMJPEGIB}, | |
10316 | 228 |
34191 | 229 {"IDCT_MPEG2", IMGFMT_XVMC_IDCT_MPEG2}, |
230 {"MOCO_MPEG2", IMGFMT_XVMC_MOCO_MPEG2}, | |
10316 | 231 |
34191 | 232 {"VDPAU_MPEG1", IMGFMT_VDPAU_MPEG1}, |
233 {"VDPAU_MPEG2", IMGFMT_VDPAU_MPEG2}, | |
234 {"VDPAU_H264", IMGFMT_VDPAU_H264}, | |
235 {"VDPAU_WMV3", IMGFMT_VDPAU_WMV3}, | |
236 {"VDPAU_VC1", IMGFMT_VDPAU_VC1}, | |
237 {"VDPAU_MPEG4", IMGFMT_VDPAU_MPEG4}, | |
28516
79b0bd20433e
Add support for image formats and codecs used by VDPAU
reimar
parents:
27343
diff
changeset
|
238 |
31159 | 239 {NULL, 0} |
240 }; | |
408 | 241 |
607 | 242 |
4675 | 243 static int add_to_inout(char *sfmt, char *sflags, unsigned int *outfmt, |
31077 | 244 unsigned char *outflags) |
607 | 245 { |
246 | |
31077 | 247 static char *flagstr[] = { |
248 "flip", | |
249 "noflip", | |
250 "yuvhack", | |
251 "query", | |
252 "static", | |
253 NULL | |
254 }; | |
299 | 255 |
31077 | 256 int i, j, freeslots; |
257 unsigned char flags; | |
297 | 258 |
31077 | 259 for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++) |
260 /* NOTHING */; | |
261 freeslots = CODECS_MAX_OUTFMT - i; | |
262 if (!freeslots) | |
263 goto err_out_too_many; | |
297 | 264 |
31077 | 265 flags = 0; |
266 if(sflags) { | |
267 do { | |
268 for (j = 0; flagstr[j] != NULL; j++) | |
269 if (!strncmp(sflags, flagstr[j], | |
270 strlen(flagstr[j]))) | |
271 break; | |
272 if (flagstr[j] == NULL) | |
273 goto err_out_parse_error; | |
274 flags|=(1<<j); | |
275 sflags+=strlen(flagstr[j]); | |
276 } while (*(sflags++) == ','); | |
361 | 277 |
31077 | 278 if (*(--sflags) != '\0') |
279 goto err_out_parse_error; | |
280 } | |
297 | 281 |
31077 | 282 do { |
283 for (j = 0; fmt_table[j].name != NULL; j++) | |
284 if (!strncmp(sfmt, fmt_table[j].name, strlen(fmt_table[j].name))) | |
285 break; | |
286 if (fmt_table[j].name == NULL) | |
287 goto err_out_parse_error; | |
288 outfmt[i] = fmt_table[j].num; | |
289 outflags[i] = flags; | |
290 ++i; | |
291 sfmt+=strlen(fmt_table[j].name); | |
292 } while ((*(sfmt++) == ',') && --freeslots); | |
319 | 293 |
31077 | 294 if (!freeslots) |
295 goto err_out_too_many; | |
319 | 296 |
31077 | 297 if (*(--sfmt) != '\0') |
298 goto err_out_parse_error; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
299 |
31077 | 300 return 1; |
328 | 301 err_out_too_many: |
31077 | 302 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_TooManyOut); |
303 return 0; | |
361 | 304 err_out_parse_error: |
31077 | 305 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_ParseError); |
306 return 0; | |
297 | 307 } |
308 | |
7180
28677d779205
-afm/-vfm migration from ID (int) to NAME (string) - simplifies code and makes dlopen()'ing possible
arpi
parents:
6927
diff
changeset
|
309 #if 0 |
303 | 310 static short get_driver(char *s,int audioflag) |
297 | 311 { |
31077 | 312 static char *audiodrv[] = { |
313 "null", | |
314 "mp3lib", | |
315 "pcm", | |
316 "libac3", | |
317 "acm", | |
318 "alaw", | |
319 "msgsm", | |
320 "dshow", | |
321 "dvdpcm", | |
322 "hwac3", | |
323 "libvorbis", | |
324 "ffmpeg", | |
325 "libmad", | |
326 "msadpcm", | |
327 "liba52", | |
328 "g72x", | |
329 "imaadpcm", | |
330 "dk4adpcm", | |
331 "dk3adpcm", | |
332 "roqaudio", | |
333 "faad", | |
334 "realaud", | |
335 "libdv", | |
336 NULL | |
337 }; | |
338 static char *videodrv[] = { | |
339 "null", | |
340 "libmpeg2", | |
341 "vfw", | |
342 "dshow", | |
343 "ffmpeg", | |
344 "vfwex", | |
345 "raw", | |
346 "msrle", | |
347 "xanim", | |
348 "msvidc", | |
349 "fli", | |
350 "cinepak", | |
351 "qtrle", | |
352 "nuv", | |
353 "cyuv", | |
354 "qtsmc", | |
355 "ducktm1", | |
356 "roqvideo", | |
357 "qtrpza", | |
358 "mpng", | |
359 "ijpg", | |
360 "zlib", | |
361 "mpegpes", | |
362 "zrmjpeg", | |
363 "realvid", | |
364 "xvid", | |
365 "libdv", | |
366 NULL | |
367 }; | |
368 char **drv=audioflag?audiodrv:videodrv; | |
369 int i; | |
6863 | 370 |
31077 | 371 for(i=0;drv[i];i++) if(!strcmp(s,drv[i])) return i; |
301 | 372 |
31077 | 373 return -1; |
297 | 374 } |
7180
28677d779205
-afm/-vfm migration from ID (int) to NAME (string) - simplifies code and makes dlopen()'ing possible
arpi
parents:
6927
diff
changeset
|
375 #endif |
297 | 376 |
328 | 377 static int validate_codec(codecs_t *c, int type) |
319 | 378 { |
31077 | 379 unsigned int i; |
380 char *tmp_name = c->name; | |
328 | 381 |
31077 | 382 for (i = 0; i < strlen(tmp_name) && isalnum(tmp_name[i]); i++) |
383 /* NOTHING */; | |
3408 | 384 |
31077 | 385 if (i < strlen(tmp_name)) { |
386 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_InvalidCodecName, c->name); | |
387 return 0; | |
388 } | |
3408 | 389 |
31077 | 390 if (!c->info) |
391 c->info = strdup(c->name); | |
3408 | 392 |
393 #if 0 | |
31077 | 394 if (c->fourcc[0] == 0xffffffff) { |
395 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecLacksFourcc, c->name); | |
396 return 0; | |
397 } | |
13936
589b227e3367
fix crash when a "driver" line is missing in codecs.conf.
reimar
parents:
13807
diff
changeset
|
398 #endif |
3408 | 399 |
31077 | 400 if (!c->drv) { |
401 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecLacksDriver, c->name); | |
402 return 0; | |
403 } | |
3408 | 404 |
405 #if 0 | |
32394
914208d188b9
Remove #warning preprocessor directives or replace them by suitable comments.
diego
parents:
31409
diff
changeset
|
406 //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
|
407 //FIXME: Where are they defined ???????????? |
31077 | 408 if (!c->dll && (c->driver == 4 || |
409 (c->driver == 2 && type == TYPE_VIDEO))) { | |
410 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecNeedsDLL, c->name); | |
411 return 0; | |
412 } | |
32394
914208d188b9
Remove #warning preprocessor directives or replace them by suitable comments.
diego
parents:
31409
diff
changeset
|
413 // FIXME: Can guid.f1 be 0? How does one know that it was not given? |
31077 | 414 // if (!(codec->flags & CODECS_FLAG_AUDIO) && codec->driver == 4) |
328 | 415 |
31077 | 416 if (type == TYPE_VIDEO) |
417 if (c->outfmt[0] == 0xffffffff) { | |
418 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecNeedsOutfmt, c->name); | |
419 return 0; | |
420 } | |
329 | 421 #endif |
31077 | 422 return 1; |
319 | 423 } |
424 | |
425 static int add_comment(char *s, char **d) | |
426 { | |
31077 | 427 int pos; |
319 | 428 |
31077 | 429 if (!*d) |
430 pos = 0; | |
431 else { | |
432 pos = strlen(*d); | |
433 (*d)[pos++] = '\n'; | |
434 } | |
435 if (!(*d = realloc(*d, pos + strlen(s) + 1))) { | |
436 mp_msg(MSGT_CODECCFG,MSGL_FATAL,MSGTR_CantAllocateComment); | |
437 return 0; | |
438 } | |
439 strcpy(*d + pos, s); | |
440 return 1; | |
319 | 441 } |
297 | 442 |
361 | 443 static short get_cpuflags(char *s) |
444 { | |
31077 | 445 static char *flagstr[] = { |
446 "mmx", | |
447 "sse", | |
448 "3dnow", | |
449 NULL | |
450 }; | |
451 int i; | |
452 short flags = 0; | |
361 | 453 |
31077 | 454 do { |
455 for (i = 0; flagstr[i]; i++) | |
456 if (!strncmp(s, flagstr[i], strlen(flagstr[i]))) | |
457 break; | |
458 if (!flagstr[i]) | |
459 goto err_out_parse_error; | |
460 flags |= 1<<i; | |
461 s += strlen(flagstr[i]); | |
462 } while (*(s++) == ','); | |
361 | 463 |
31077 | 464 if (*(--s) != '\0') |
465 goto err_out_parse_error; | |
361 | 466 |
31077 | 467 return flags; |
361 | 468 err_out_parse_error: |
31077 | 469 return 0; |
361 | 470 } |
471 | |
328 | 472 static FILE *fp; |
473 static int line_num = 0; | |
474 static char *line; | |
475 static char *token[MAX_NR_TOKEN]; | |
6200
e604be87613d
codecs.conf versioning - patch by Joey Parrish <joey@yunamusic.com>
arpi
parents:
6103
diff
changeset
|
476 static int read_nextline = 1; |
328 | 477 |
478 static int get_token(int min, int max) | |
297 | 479 { |
31077 | 480 static int line_pos; |
481 int i; | |
482 char c; | |
328 | 483 |
31077 | 484 if (max >= MAX_NR_TOKEN) { |
485 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_GetTokenMaxNotLessThanMAX_NR_TOKEN); | |
486 goto out_eof; | |
487 } | |
328 | 488 |
31077 | 489 memset(token, 0x00, sizeof(*token) * max); |
328 | 490 |
31077 | 491 if (read_nextline) { |
492 if (!fgets(line, MAX_LINE_LEN, fp)) | |
493 goto out_eof; | |
494 line_pos = 0; | |
495 ++line_num; | |
496 read_nextline = 0; | |
497 } | |
498 for (i = 0; i < max; i++) { | |
499 while (isspace(line[line_pos])) | |
500 ++line_pos; | |
501 if (line[line_pos] == '\0' || line[line_pos] == '#' || | |
502 line[line_pos] == ';') { | |
503 read_nextline = 1; | |
504 if (i >= min) | |
505 goto out_ok; | |
506 goto out_eol; | |
507 } | |
508 token[i] = line + line_pos; | |
509 c = line[line_pos]; | |
510 if (c == '"' || c == '\'') { | |
511 token[i]++; | |
512 while (line[++line_pos] != c && line[line_pos]) | |
513 /* NOTHING */; | |
514 } else { | |
515 for (/* NOTHING */; !isspace(line[line_pos]) && | |
516 line[line_pos]; line_pos++) | |
517 /* NOTHING */; | |
518 } | |
519 if (!line[line_pos]) { | |
520 read_nextline = 1; | |
521 if (i >= min - 1) | |
522 goto out_ok; | |
523 goto out_eol; | |
524 } | |
525 line[line_pos] = '\0'; | |
526 line_pos++; | |
527 } | |
328 | 528 out_ok: |
31077 | 529 return i; |
328 | 530 out_eof: |
31077 | 531 read_nextline = 1; |
532 return RET_EOF; | |
328 | 533 out_eol: |
31077 | 534 return RET_EOL; |
328 | 535 } |
536 | |
537 static codecs_t *video_codecs=NULL; | |
538 static codecs_t *audio_codecs=NULL; | |
539 static int nr_vcodecs = 0; | |
540 static int nr_acodecs = 0; | |
541 | |
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
|
542 int parse_codec_cfg(const char *cfgfile) |
328 | 543 { |
31077 | 544 codecs_t *codec = NULL; // current codec |
545 codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs | |
546 char *endptr; // strtoul()... | |
547 int *nr_codecsp; | |
548 int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */ | |
549 int tmp, i; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
550 |
31077 | 551 // in case we call it a second time |
552 codecs_uninit_free(); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
553 |
31077 | 554 nr_vcodecs = 0; |
555 nr_acodecs = 0; | |
297 | 556 |
31077 | 557 if(cfgfile==NULL) { |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
558 #ifdef CODECS2HTML |
31077 | 559 return 0; |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
560 #else |
31077 | 561 video_codecs = builtin_video_codecs; |
562 audio_codecs = builtin_audio_codecs; | |
563 nr_vcodecs = sizeof(builtin_video_codecs)/sizeof(codecs_t); | |
564 nr_acodecs = sizeof(builtin_audio_codecs)/sizeof(codecs_t); | |
565 return 1; | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
566 #endif |
31077 | 567 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
568 |
33844
77bf38091051
Clarify console output when reading optional configuration files.
diego
parents:
33843
diff
changeset
|
569 mp_msg(MSGT_CODECCFG, MSGL_V, "Reading optional codecs config file %s: ", cfgfile); |
297 | 570 |
31077 | 571 if ((fp = fopen(cfgfile, "r")) == NULL) { |
33844
77bf38091051
Clarify console output when reading optional configuration files.
diego
parents:
33843
diff
changeset
|
572 mp_msg(MSGT_CODECCFG, MSGL_V, "%s\n", strerror(errno)); |
31077 | 573 return 0; |
574 } | |
297 | 575 |
31077 | 576 if ((line = malloc(MAX_LINE_LEN + 1)) == NULL) { |
577 mp_msg(MSGT_CODECCFG,MSGL_FATAL,MSGTR_CantGetMemoryForLine, strerror(errno)); | |
578 return 0; | |
579 } | |
580 read_nextline = 1; | |
297 | 581 |
31077 | 582 /* |
583 * this only catches release lines at the start of | |
584 * codecs.conf, before audiocodecs and videocodecs. | |
585 */ | |
586 while ((tmp = get_token(1, 1)) == RET_EOL) | |
587 /* NOTHING */; | |
588 if (tmp == RET_EOF) | |
589 goto out; | |
590 if (!strcmp(token[0], "release")) { | |
591 if (get_token(1, 2) < 0) | |
592 goto err_out_parse_error; | |
593 tmp = atoi(token[0]); | |
594 if (tmp < CODEC_CFG_MIN) | |
595 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
|
596 codecs_conf_release = tmp; |
31077 | 597 while ((tmp = get_token(1, 1)) == RET_EOL) |
598 /* NOTHING */; | |
599 if (tmp == RET_EOF) | |
600 goto out; | |
601 } else | |
602 goto err_out_release_num; | |
6200
e604be87613d
codecs.conf versioning - patch by Joey Parrish <joey@yunamusic.com>
arpi
parents:
6103
diff
changeset
|
603 |
31077 | 604 /* |
605 * check if the next block starts with 'audiocodec' or | |
606 * with 'videocodec' | |
607 */ | |
608 if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec")) | |
609 goto loop_enter; | |
610 goto err_out_parse_error; | |
328 | 611 |
31077 | 612 while ((tmp = get_token(1, 1)) != RET_EOF) { |
613 if (tmp == RET_EOL) | |
614 continue; | |
615 if (!strcmp(token[0], "audiocodec") || | |
616 !strcmp(token[0], "videocodec")) { | |
617 if (!validate_codec(codec, codec_type)) | |
618 goto err_out_not_valid; | |
619 loop_enter: | |
620 if (*token[0] == 'v') { | |
621 codec_type = TYPE_VIDEO; | |
622 nr_codecsp = &nr_vcodecs; | |
623 codecsp = &video_codecs; | |
624 } else if (*token[0] == 'a') { | |
625 codec_type = TYPE_AUDIO; | |
626 nr_codecsp = &nr_acodecs; | |
627 codecsp = &audio_codecs; | |
361 | 628 #ifdef DEBUG |
31077 | 629 } else { |
630 mp_msg(MSGT_CODECCFG,MSGL_ERR,"picsba\n"); | |
631 goto err_out; | |
361 | 632 #endif |
31077 | 633 } |
634 if (!(*codecsp = realloc(*codecsp, | |
635 sizeof(codecs_t) * (*nr_codecsp + 2)))) { | |
636 mp_msg(MSGT_CODECCFG,MSGL_FATAL,MSGTR_CantReallocCodecsp, strerror(errno)); | |
637 goto err_out; | |
638 } | |
639 codec=*codecsp + *nr_codecsp; | |
640 ++*nr_codecsp; | |
641 memset(codec,0,sizeof(codecs_t)); | |
642 memset(codec->fourcc, 0xff, sizeof(codec->fourcc)); | |
643 memset(codec->outfmt, 0xff, sizeof(codec->outfmt)); | |
644 memset(codec->infmt, 0xff, sizeof(codec->infmt)); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
645 |
31077 | 646 if (get_token(1, 1) < 0) |
647 goto err_out_parse_error; | |
648 for (i = 0; i < *nr_codecsp - 1; i++) { | |
649 if(( (*codecsp)[i].name!=NULL) && | |
650 (!strcmp(token[0], (*codecsp)[i].name)) ) { | |
651 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecNameNotUnique, token[0]); | |
652 goto err_out_print_linenum; | |
653 } | |
654 } | |
655 if (!(codec->name = strdup(token[0]))) { | |
656 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupName, strerror(errno)); | |
657 goto err_out; | |
658 } | |
659 } else if (!strcmp(token[0], "info")) { | |
660 if (codec->info || get_token(1, 1) < 0) | |
661 goto err_out_parse_error; | |
662 if (!(codec->info = strdup(token[0]))) { | |
663 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupInfo, strerror(errno)); | |
664 goto err_out; | |
665 } | |
666 } else if (!strcmp(token[0], "comment")) { | |
667 if (get_token(1, 1) < 0) | |
668 goto err_out_parse_error; | |
669 add_comment(token[0], &codec->comment); | |
670 } else if (!strcmp(token[0], "fourcc")) { | |
671 if (get_token(1, 2) < 0) | |
672 goto err_out_parse_error; | |
673 if (!add_to_fourcc(token[0], token[1], | |
674 codec->fourcc, | |
675 codec->fourccmap)) | |
676 goto err_out_print_linenum; | |
677 } else if (!strcmp(token[0], "format")) { | |
678 if (get_token(1, 2) < 0) | |
679 goto err_out_parse_error; | |
680 if (!add_to_format(token[0], token[1], | |
681 codec->fourcc,codec->fourccmap)) | |
682 goto err_out_print_linenum; | |
683 } else if (!strcmp(token[0], "driver")) { | |
684 if (get_token(1, 1) < 0) | |
685 goto err_out_parse_error; | |
686 if (!(codec->drv = strdup(token[0]))) { | |
687 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupDriver, strerror(errno)); | |
688 goto err_out; | |
689 } | |
690 } else if (!strcmp(token[0], "dll")) { | |
691 if (get_token(1, 1) < 0) | |
692 goto err_out_parse_error; | |
693 if (!(codec->dll = strdup(token[0]))) { | |
694 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CantStrdupDLL, strerror(errno)); | |
695 goto err_out; | |
696 } | |
697 } else if (!strcmp(token[0], "guid")) { | |
698 if (get_token(11, 11) < 0) | |
699 goto err_out_parse_error; | |
700 codec->guid.f1=strtoul(token[0],&endptr,0); | |
701 if ((*endptr != ',' || *(endptr + 1) != '\0') && | |
702 *endptr != '\0') | |
703 goto err_out_parse_error; | |
704 codec->guid.f2=strtoul(token[1],&endptr,0); | |
705 if ((*endptr != ',' || *(endptr + 1) != '\0') && | |
706 *endptr != '\0') | |
707 goto err_out_parse_error; | |
708 codec->guid.f3=strtoul(token[2],&endptr,0); | |
709 if ((*endptr != ',' || *(endptr + 1) != '\0') && | |
710 *endptr != '\0') | |
711 goto err_out_parse_error; | |
712 for (i = 0; i < 8; i++) { | |
713 codec->guid.f4[i]=strtoul(token[i + 3],&endptr,0); | |
714 if ((*endptr != ',' || *(endptr + 1) != '\0') && | |
715 *endptr != '\0') | |
716 goto err_out_parse_error; | |
717 } | |
718 } else if (!strcmp(token[0], "out")) { | |
719 if (get_token(1, 2) < 0) | |
720 goto err_out_parse_error; | |
721 if (!add_to_inout(token[0], token[1], codec->outfmt, | |
722 codec->outflags)) | |
723 goto err_out_print_linenum; | |
724 } else if (!strcmp(token[0], "in")) { | |
725 if (get_token(1, 2) < 0) | |
726 goto err_out_parse_error; | |
727 if (!add_to_inout(token[0], token[1], codec->infmt, | |
728 codec->inflags)) | |
729 goto err_out_print_linenum; | |
730 } else if (!strcmp(token[0], "flags")) { | |
731 if (get_token(1, 1) < 0) | |
732 goto err_out_parse_error; | |
733 if (!strcmp(token[0], "seekable")) | |
734 codec->flags |= CODECS_FLAG_SEEKABLE; | |
735 else | |
736 if (!strcmp(token[0], "align16")) | |
737 codec->flags |= CODECS_FLAG_ALIGN16; | |
738 else | |
739 goto err_out_parse_error; | |
740 } else if (!strcmp(token[0], "status")) { | |
741 if (get_token(1, 1) < 0) | |
742 goto err_out_parse_error; | |
743 if (!strcasecmp(token[0], "working")) | |
744 codec->status = CODECS_STATUS_WORKING; | |
745 else if (!strcasecmp(token[0], "crashing")) | |
746 codec->status = CODECS_STATUS_NOT_WORKING; | |
747 else if (!strcasecmp(token[0], "untested")) | |
748 codec->status = CODECS_STATUS_UNTESTED; | |
749 else if (!strcasecmp(token[0], "buggy")) | |
750 codec->status = CODECS_STATUS_PROBLEMS; | |
751 else | |
752 goto err_out_parse_error; | |
753 } else if (!strcmp(token[0], "cpuflags")) { | |
754 if (get_token(1, 1) < 0) | |
755 goto err_out_parse_error; | |
756 if (!(codec->cpuflags = get_cpuflags(token[0]))) | |
757 goto err_out_parse_error; | |
758 } else | |
759 goto err_out_parse_error; | |
760 } | |
761 if (!validate_codec(codec, codec_type)) | |
762 goto err_out_not_valid; | |
763 mp_msg(MSGT_CODECCFG,MSGL_INFO,MSGTR_AudioVideoCodecTotals, nr_acodecs, nr_vcodecs); | |
764 if(video_codecs) video_codecs[nr_vcodecs].name = NULL; | |
765 if(audio_codecs) audio_codecs[nr_acodecs].name = NULL; | |
297 | 766 out: |
31077 | 767 free(line); |
768 line=NULL; | |
769 fclose(fp); | |
770 return 1; | |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
771 |
328 | 772 err_out_parse_error: |
31077 | 773 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_ParseError); |
361 | 774 err_out_print_linenum: |
31077 | 775 PRINT_LINENUM; |
297 | 776 err_out: |
31077 | 777 codecs_uninit_free(); |
3798
d1e3ad5bcd8f
fixed few segfaults, make parse_codec_cfg() return int
iive
parents:
3787
diff
changeset
|
778 |
31077 | 779 free(line); |
780 line=NULL; | |
781 line_num = 0; | |
782 fclose(fp); | |
783 return 0; | |
328 | 784 err_out_not_valid: |
31077 | 785 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_CodecDefinitionIncorrect); |
786 goto err_out_print_linenum; | |
6200
e604be87613d
codecs.conf versioning - patch by Joey Parrish <joey@yunamusic.com>
arpi
parents:
6103
diff
changeset
|
787 err_out_release_num: |
31077 | 788 mp_msg(MSGT_CODECCFG,MSGL_ERR,MSGTR_OutdatedCodecsConf); |
789 goto err_out_print_linenum; | |
297 | 790 } |
791 | |
13807
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
792 static void codecs_free(codecs_t* codecs,int count) { |
31077 | 793 int i; |
794 for ( i = 0; i < count; i++) | |
795 if ( codecs[i].name ) { | |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
796 free(codecs[i].name); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
797 free(codecs[i].info); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
798 free(codecs[i].comment); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
799 free(codecs[i].dll); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
800 free(codecs[i].drv); |
31077 | 801 } |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32394
diff
changeset
|
802 free(codecs); |
13807
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
803 } |
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
804 |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17120
diff
changeset
|
805 void codecs_uninit_free(void) { |
31077 | 806 if (video_codecs) |
807 codecs_free(video_codecs,nr_vcodecs); | |
808 video_codecs=NULL; | |
809 if (audio_codecs) | |
810 codecs_free(audio_codecs,nr_acodecs); | |
811 audio_codecs=NULL; | |
13807
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
812 } |
b014091b4417
Memory Free function Fix, based on patch by Wei Jiang <jiangw98@yahoo.com>
faust3
parents:
13619
diff
changeset
|
813 |
332 | 814 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap, |
31077 | 815 codecs_t *start, int force) |
328 | 816 { |
31077 | 817 return find_codec(fourcc, fourccmap, start, 1, force); |
328 | 818 } |
819 | |
332 | 820 codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap, |
31077 | 821 codecs_t *start, int force) |
328 | 822 { |
31077 | 823 return find_codec(fourcc, fourccmap, start, 0, force); |
328 | 824 } |
825 | |
332 | 826 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap, |
31077 | 827 codecs_t *start, int audioflag, int force) |
328 | 828 { |
31077 | 829 int i, j; |
830 codecs_t *c; | |
328 | 831 |
628 | 832 #if 0 |
31077 | 833 if (start) { |
834 for (/* NOTHING */; start->name; start++) { | |
835 for (j = 0; j < CODECS_MAX_FOURCC; j++) { | |
836 if (start->fourcc[j] == fourcc) { | |
837 if (fourccmap) | |
838 *fourccmap = start->fourccmap[j]; | |
839 return start; | |
840 } | |
841 } | |
842 } | |
843 } else | |
628 | 844 #endif |
31077 | 845 { |
846 if (audioflag) { | |
847 i = nr_acodecs; | |
848 c = audio_codecs; | |
849 } else { | |
850 i = nr_vcodecs; | |
851 c = video_codecs; | |
852 } | |
853 if(!i) return NULL; | |
854 for (/* NOTHING */; i--; c++) { | |
855 if(start && c<=start) continue; | |
856 for (j = 0; j < CODECS_MAX_FOURCC; j++) { | |
857 // FIXME: do NOT hardwire 'null' name here: | |
858 if (c->fourcc[j]==fourcc || !strcmp(c->drv,"null")) { | |
859 if (fourccmap) | |
860 *fourccmap = c->fourccmap[j]; | |
861 return c; | |
862 } | |
863 } | |
864 if (force) return c; | |
865 } | |
866 } | |
867 return NULL; | |
303 | 868 } |
869 | |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
870 void stringset_init(stringset_t *set) { |
31077 | 871 *set = calloc(1, sizeof(char *)); |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
872 } |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
873 |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
874 void stringset_free(stringset_t *set) { |
31077 | 875 int count = 0; |
876 while ((*set)[count]) free((*set)[count++]); | |
877 free(*set); | |
878 *set = NULL; | |
7505 | 879 } |
880 | |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
881 void stringset_add(stringset_t *set, const char *str) { |
31077 | 882 int count = 0; |
883 while ((*set)[count]) count++; | |
884 count++; | |
885 *set = realloc(*set, sizeof(char *) * (count + 1)); | |
886 (*set)[count - 1] = strdup(str); | |
887 (*set)[count] = NULL; | |
25661
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
888 } |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
889 |
293aeec83153
Replace the persistent CODECS_FLAG_SELECTED by a local "stringset" with
reimar
parents:
25247
diff
changeset
|
890 int stringset_test(stringset_t *set, const char *str) { |
31077 | 891 stringset_t s; |
892 for (s = *set; *s; s++) | |
893 if (strcmp(*s, str) == 0) | |
894 return 1; | |
895 return 0; | |
5325
9c326f199060
tagging selected codec to avoid trying the same codec several times
arpi
parents:
5284
diff
changeset
|
896 } |
9c326f199060
tagging selected codec to avoid trying the same codec several times
arpi
parents:
5284
diff
changeset
|
897 |
1983 | 898 void list_codecs(int audioflag){ |
31077 | 899 int i; |
900 codecs_t *c; | |
1983 | 901 |
31077 | 902 if (audioflag) { |
903 i = nr_acodecs; | |
904 c = audio_codecs; | |
905 mp_msg(MSGT_CODECCFG,MSGL_INFO,"ac: afm: status: info: [lib/dll]\n"); | |
906 } else { | |
907 i = nr_vcodecs; | |
908 c = video_codecs; | |
909 mp_msg(MSGT_CODECCFG,MSGL_INFO,"vc: vfm: status: info: [lib/dll]\n"); | |
910 } | |
911 if(!i) return; | |
912 for (/* NOTHING */; i--; c++) { | |
913 char* s="unknown "; | |
914 switch(c->status){ | |
915 case CODECS_STATUS_WORKING: s="working ";break; | |
916 case CODECS_STATUS_PROBLEMS: s="problems";break; | |
917 case CODECS_STATUS_NOT_WORKING: s="crashing";break; | |
918 case CODECS_STATUS_UNTESTED: s="untested";break; | |
919 } | |
920 if(c->dll) | |
921 mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s %-9s %s %s [%s]\n",c->name,c->drv,s,c->info,c->dll); | |
922 else | |
923 mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s %-9s %s %s\n",c->name,c->drv,s,c->info); | |
924 } | |
1983 | 925 } |
926 | |
927 | |
607 | 928 #ifdef CODECS2HTML |
31408 | 929 static void wrapline(FILE *f2,char *s){ |
607 | 930 int c; |
931 if(!s){ | |
932 fprintf(f2,"-"); | |
933 return; | |
934 } | |
935 while((c=*s++)){ | |
936 if(c==',') fprintf(f2,"<br>"); else fputc(c,f2); | |
937 } | |
938 } | |
939 | |
31409 | 940 static void parsehtml(FILE *f1,FILE *f2,codecs_t *codec){ |
31077 | 941 int c,d; |
942 while((c=fgetc(f1))>=0){ | |
943 if(c!='%'){ | |
944 fputc(c,f2); | |
945 continue; | |
946 } | |
947 d=fgetc(f1); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
948 |
31077 | 949 switch(d){ |
950 case '.': | |
951 return; // end of section | |
952 case 'n': | |
953 wrapline(f2,codec->name); break; | |
954 case 'i': | |
955 wrapline(f2,codec->info); break; | |
956 case 'c': | |
957 wrapline(f2,codec->comment); break; | |
958 case 'd': | |
959 wrapline(f2,codec->dll); break; | |
960 case 'D': | |
961 fprintf(f2,"%c",!strcmp(codec->drv,"dshow")?'+':'-'); break; | |
962 case 'F': | |
963 for(d=0;d<CODECS_MAX_FOURCC;d++) | |
964 if(!d || codec->fourcc[d]!=0xFFFFFFFF) | |
965 fprintf(f2,"%s%.4s",d?"<br>":"",(codec->fourcc[d]==0xFFFFFFFF || codec->fourcc[d]<0x20202020)?!d?"-":"":(char*) &codec->fourcc[d]); | |
966 break; | |
967 case 'f': | |
968 for(d=0;d<CODECS_MAX_FOURCC;d++) | |
969 if(codec->fourcc[d]!=0xFFFFFFFF) | |
970 fprintf(f2,"%s0x%X",d?"<br>":"",codec->fourcc[d]); | |
971 break; | |
972 case 'Y': | |
973 for(d=0;d<CODECS_MAX_OUTFMT;d++) | |
974 if(codec->outfmt[d]!=0xFFFFFFFF){ | |
975 for (c=0; fmt_table[c].name; c++) | |
976 if(fmt_table[c].num==codec->outfmt[d]) break; | |
977 if(fmt_table[c].name) | |
978 fprintf(f2,"%s%s",d?"<br>":"",fmt_table[c].name); | |
979 } | |
980 break; | |
981 default: | |
982 fputc(c,f2); | |
983 fputc(d,f2); | |
607 | 984 } |
31077 | 985 } |
607 | 986 } |
987 | |
988 void skiphtml(FILE *f1){ | |
31077 | 989 int c,d; |
990 while((c=fgetc(f1))>=0){ | |
991 if(c!='%'){ | |
992 continue; | |
607 | 993 } |
31077 | 994 d=fgetc(f1); |
995 if(d=='.') return; // end of section | |
996 } | |
607 | 997 } |
998 | |
29115
1e78a310487e
Change type of first argument of the print_int_array function from int to
diego
parents:
28747
diff
changeset
|
999 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
|
1000 { |
31077 | 1001 printf("{ "); |
1002 while (size--) | |
1003 if(abs(*a)<256) | |
1004 printf("%d%s", *a++, size?", ":""); | |
1005 else | |
1006 printf("0x%X%s", *a++, size?", ":""); | |
1007 printf(" }"); | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1008 } |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1009 |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1010 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
|
1011 { |
31077 | 1012 printf("{ "); |
1013 while (size--) | |
1014 if((*a)<10) | |
1015 printf("%d%s", *a++, size?", ":""); | |
1016 else | |
1017 printf("0x%02x%s", *a++, size?", ":""); | |
1018 printf(" }"); | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1019 } |
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 static void print_string(const char* s) |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1022 { |
31077 | 1023 if (!s) printf("NULL"); |
1024 else printf("\"%s\"", s); | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1025 } |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1026 |
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1027 int main(int argc, char* argv[]) |
607 | 1028 { |
31077 | 1029 codecs_t *cl; |
1030 FILE *f1; | |
1031 FILE *f2; | |
1032 int c,d,i; | |
1033 int pos; | |
1034 int section=-1; | |
1035 int nr_codecs; | |
1036 int win32=-1; | |
1037 int dshow=-1; | |
1038 int win32ex=-1; | |
607 | 1039 |
31077 | 1040 /* |
1041 * Take path to codecs.conf from command line, or fall back on | |
1042 * etc/codecs.conf | |
1043 */ | |
1044 if (!(nr_codecs = parse_codec_cfg((argc>1)?argv[1]:"etc/codecs.conf"))) | |
1045 exit(1); | |
31406
0fd1b3f1fe69
Auto-update CODEC_CFG_MIN value to release value in etc/codecs.conf.
reimar
parents:
31159
diff
changeset
|
1046 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
|
1047 exit(1); |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1048 |
31077 | 1049 if (argc > 1) { |
1050 int i, j; | |
1051 const char* nm[2]; | |
1052 codecs_t* cod[2]; | |
1053 int nr[2]; | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1054 |
31077 | 1055 nm[0] = "builtin_video_codecs"; |
1056 cod[0] = video_codecs; | |
1057 nr[0] = nr_vcodecs; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1058 |
31077 | 1059 nm[1] = "builtin_audio_codecs"; |
1060 cod[1] = audio_codecs; | |
1061 nr[1] = nr_acodecs; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1062 |
31077 | 1063 printf("/* GENERATED FROM %s, DO NOT EDIT! */\n\n",argv[1]); |
31407 | 1064 printf("#include <stddef.h>\n"); |
1065 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
|
1066 printf("#define CODEC_CFG_MIN %i\n\n", codecs_conf_release); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1067 |
31077 | 1068 for (i=0; i<2; i++) { |
1069 printf("const codecs_t %s[] = {\n", nm[i]); | |
1070 for (j = 0; j < nr[i]; j++) { | |
1071 printf("{"); | |
8467
3ca9cc46df5c
Fallback to builtin (generated from etc/codecs.conf at compile time)
arpi
parents:
8211
diff
changeset
|
1072 |
31077 | 1073 print_int_array(cod[i][j].fourcc, CODECS_MAX_FOURCC); |
1074 printf(", /* fourcc */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1075 |
31077 | 1076 print_int_array(cod[i][j].fourccmap, CODECS_MAX_FOURCC); |
1077 printf(", /* fourccmap */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1078 |
31077 | 1079 print_int_array(cod[i][j].outfmt, CODECS_MAX_OUTFMT); |
1080 printf(", /* outfmt */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1081 |
31077 | 1082 print_char_array(cod[i][j].outflags, CODECS_MAX_OUTFMT); |
1083 printf(", /* outflags */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1084 |
31077 | 1085 print_int_array(cod[i][j].infmt, CODECS_MAX_INFMT); |
1086 printf(", /* infmt */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1087 |
31077 | 1088 print_char_array(cod[i][j].inflags, CODECS_MAX_INFMT); |
1089 printf(", /* inflags */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1090 |
31077 | 1091 print_string(cod[i][j].name); printf(", /* name */\n"); |
1092 print_string(cod[i][j].info); printf(", /* info */\n"); | |
1093 print_string(cod[i][j].comment); printf(", /* comment */\n"); | |
1094 print_string(cod[i][j].dll); printf(", /* dll */\n"); | |
1095 print_string(cod[i][j].drv); printf(", /* drv */\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1096 |
31077 | 1097 printf("{ 0x%08lx, %hu, %hu,", |
1098 cod[i][j].guid.f1, | |
1099 cod[i][j].guid.f2, | |
1100 cod[i][j].guid.f3); | |
1101 print_char_array(cod[i][j].guid.f4, sizeof(cod[i][j].guid.f4)); | |
1102 printf(" }, /* GUID */\n"); | |
1103 printf("%hd /* flags */, %hd /* status */, %hd /* cpuflags */ }\n", | |
1104 cod[i][j].flags, | |
1105 cod[i][j].status, | |
1106 cod[i][j].cpuflags); | |
1107 if (j < nr[i]) printf(",\n"); | |
607 | 1108 } |
31077 | 1109 printf("};\n\n"); |
1110 } | |
1111 exit(0); | |
1112 } | |
1113 | |
1114 f1=fopen("DOCS/tech/codecs-in.html","rb"); if(!f1) exit(1); | |
1115 f2=fopen("DOCS/codecs-status.html","wb"); if(!f2) exit(1); | |
1116 | |
1117 while((c=fgetc(f1))>=0){ | |
1118 if(c!='%'){ | |
1119 fputc(c,f2); | |
1120 continue; | |
1121 } | |
1122 d=fgetc(f1); | |
1123 if(d>='0' && d<='9'){ | |
1124 // begin section | |
1125 section=d-'0'; | |
1126 //printf("BEGIN %d\n",section); | |
1127 if(section>=5){ | |
1128 // audio | |
1129 cl = audio_codecs; | |
1130 nr_codecs = nr_acodecs; | |
1131 dshow=7;win32=4; | |
1132 } else { | |
1133 // video | |
1134 cl = video_codecs; | |
1135 nr_codecs = nr_vcodecs; | |
1136 dshow=4;win32=2;win32ex=6; | |
1137 } | |
1138 pos=ftell(f1); | |
1139 for(i=0;i<nr_codecs;i++){ | |
1140 fseek(f1,pos,SEEK_SET); | |
1141 switch(section){ | |
1142 case 0: | |
1143 case 5: | |
1144 if(cl[i].status==CODECS_STATUS_WORKING) | |
1145 // if(!(!strcmp(cl[i].drv,"vfw") || !strcmp(cl[i].drv,"dshow") || !strcmp(cl[i].drv,"vfwex") || !strcmp(cl[i].drv,"acm"))) | |
31409 | 1146 parsehtml(f1,f2,&cl[i]); |
31077 | 1147 break; |
8211 | 1148 #if 0 |
31077 | 1149 case 1: |
1150 case 6: | |
1151 if(cl[i].status==CODECS_STATUS_WORKING) | |
1152 if((!strcmp(cl[i].drv,"vfw") || !strcmp(cl[i].drv,"dshow") || !strcmp(cl[i].drv,"vfwex") || !strcmp(cl[i].drv,"acm"))) | |
31409 | 1153 parsehtml(f1,f2,&cl[i]); |
31077 | 1154 break; |
1155 #endif | |
1156 case 2: | |
1157 case 7: | |
1158 if(cl[i].status==CODECS_STATUS_PROBLEMS) | |
31409 | 1159 parsehtml(f1,f2,&cl[i]); |
31077 | 1160 break; |
1161 case 3: | |
1162 case 8: | |
1163 if(cl[i].status==CODECS_STATUS_NOT_WORKING) | |
31409 | 1164 parsehtml(f1,f2,&cl[i]); |
31077 | 1165 break; |
1166 case 4: | |
1167 case 9: | |
1168 if(cl[i].status==CODECS_STATUS_UNTESTED) | |
31409 | 1169 parsehtml(f1,f2,&cl[i]); |
31077 | 1170 break; |
1171 default: | |
1172 printf("Warning! unimplemented section: %d\n",section); | |
607 | 1173 } |
31077 | 1174 } |
1175 fseek(f1,pos,SEEK_SET); | |
1176 skiphtml(f1); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1177 |
31077 | 1178 continue; |
607 | 1179 } |
31077 | 1180 fputc(c,f2); |
1181 fputc(d,f2); | |
1182 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1183 |
31077 | 1184 fclose(f2); |
1185 fclose(f1); | |
1186 return 0; | |
607 | 1187 } |
1188 | |
1189 #endif | |
1190 | |
297 | 1191 #ifdef TESTING |
1192 int main(void) | |
1193 { | |
31077 | 1194 codecs_t *c; |
1195 int i,j, nr_codecs, state; | |
297 | 1196 |
31077 | 1197 if (!(parse_codec_cfg("etc/codecs.conf"))) |
1198 return 0; | |
1199 if (!video_codecs) | |
1200 printf("no videoconfig.\n"); | |
1201 if (!audio_codecs) | |
1202 printf("no audioconfig.\n"); | |
328 | 1203 |
31077 | 1204 printf("videocodecs:\n"); |
1205 c = video_codecs; | |
1206 nr_codecs = nr_vcodecs; | |
1207 state = 0; | |
328 | 1208 next: |
31077 | 1209 if (c) { |
1210 printf("number of %scodecs: %d\n", state==0?"video":"audio", | |
1211 nr_codecs); | |
1212 for(i=0;i<nr_codecs;i++, c++){ | |
1213 printf("\n============== %scodec %02d ===============\n", | |
1214 state==0?"video":"audio",i); | |
1215 printf("name='%s'\n",c->name); | |
1216 printf("info='%s'\n",c->info); | |
1217 printf("comment='%s'\n",c->comment); | |
1218 printf("dll='%s'\n",c->dll); | |
1219 /* printf("flags=%X driver=%d status=%d cpuflags=%d\n", | |
1220 c->flags, c->driver, c->status, c->cpuflags); */ | |
1221 printf("flags=%X status=%d cpuflags=%d\n", | |
1222 c->flags, c->status, c->cpuflags); | |
300 | 1223 |
31077 | 1224 for(j=0;j<CODECS_MAX_FOURCC;j++){ |
1225 if(c->fourcc[j]!=0xFFFFFFFF){ | |
1226 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],(char *) &c->fourcc[j],c->fourccmap[j],(char *) &c->fourccmap[j]); | |
1227 } | |
1228 } | |
328 | 1229 |
31077 | 1230 for(j=0;j<CODECS_MAX_OUTFMT;j++){ |
1231 if(c->outfmt[j]!=0xFFFFFFFF){ | |
1232 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],(char *) &c->outfmt[j],c->outflags[j]); | |
1233 } | |
1234 } | |
300 | 1235 |
31077 | 1236 for(j=0;j<CODECS_MAX_INFMT;j++){ |
1237 if(c->infmt[j]!=0xFFFFFFFF){ | |
1238 printf("infmt %02d: %08X (%.4s) flags: %d\n",j,c->infmt[j],(char *) &c->infmt[j],c->inflags[j]); | |
1239 } | |
1240 } | |
4676 | 1241 |
31077 | 1242 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3); |
1243 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]); | |
1244 printf("\n"); | |
300 | 1245 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29115
diff
changeset
|
1246 |
31077 | 1247 } |
1248 } | |
1249 if (!state) { | |
1250 printf("audiocodecs:\n"); | |
1251 c = audio_codecs; | |
1252 nr_codecs = nr_acodecs; | |
1253 state = 1; | |
1254 goto next; | |
1255 } | |
1256 return 0; | |
297 | 1257 } |
1258 | |
1259 #endif |