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