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