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