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