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