4 * to compile test application:
5 * cc -I. -DTESTING -o codec-cfg-test codec-cfg.c mp_msg.o osdep/getch2.o -ltermcap
6 * to compile CODECS2HTML:
7 * gcc -DCODECS2HTML -o codecs2html codec-cfg.c mp_msg.o
9 * TODO: implement informat in CODECS2HTML too
11 * Copyright (C) 2001 Szabolcs Berecz <szabi@inf.elte.hu>
13 * This file is part of MPlayer.
15 * MPlayer is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * MPlayer is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License along
26 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
48 #define mp_tmsg mp_msg
50 #define mp_msg(t, l, m, args...) fprintf(stderr, m, ##args)
52 #define mp_msg(t, l, ...) fprintf(stderr, __VA_ARGS__)
57 #include "libmpcodecs/img_format.h"
58 #include "codec-cfg.h"
61 #include "codecs.conf.h"
64 #define mmioFOURCC( ch0, ch1, ch2, ch3 ) \
65 ( (uint32_t)(uint8_t)(ch0) | ( (uint32_t)(uint8_t)(ch1) << 8 ) | \
66 ( (uint32_t)(uint8_t)(ch2) << 16 ) | ( (uint32_t)(uint8_t)(ch3) << 24 ) )
68 #define PRINT_LINENUM mp_msg(MSGT_CODECCFG,MSGL_ERR," at line %d\n", line_num)
70 #define MAX_NR_TOKEN 16
72 #define MAX_LINE_LEN 1000
80 char * codecs_file
= NULL
;
82 static int add_to_fourcc(char *s
, char *alias
, unsigned int *fourcc
,
88 /* find first unused slot */
89 for (i
= 0; i
< CODECS_MAX_FOURCC
&& fourcc
[i
] != 0xffffffff; i
++)
91 freeslots
= CODECS_MAX_FOURCC
- i
;
93 goto err_out_too_many
;
96 tmp
= mmioFOURCC(s
[0], s
[1], s
[2], s
[3]);
97 for (j
= 0; j
< i
; j
++)
99 goto err_out_duplicated
;
101 map
[i
] = alias
? mmioFOURCC(alias
[0], alias
[1], alias
[2], alias
[3]) : tmp
;
104 } while ((*(s
++) == ',') && --freeslots
);
107 goto err_out_too_many
;
109 goto err_out_parse_error
;
112 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"duplicated FourCC");
115 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"too many FourCCs/formats...");
118 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"parse error");
122 static int add_to_format(char *s
, char *alias
,unsigned int *fourcc
, unsigned int *fourccmap
)
127 /* find first unused slot */
128 for (i
= 0; i
< CODECS_MAX_FOURCC
&& fourcc
[i
] != 0xffffffff; i
++)
130 if (i
== CODECS_MAX_FOURCC
) {
131 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"too many FourCCs/formats...");
135 fourcc
[i
]=strtoul(s
,&endptr
,0);
136 if (*endptr
!= '\0') {
137 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"parse error (format ID not a number?)");
142 fourccmap
[i
]=strtoul(alias
,&endptr
,0);
143 if (*endptr
!= '\0') {
144 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"parse error (format ID alias not a number?)");
148 fourccmap
[i
]=fourcc
[i
];
150 for (j
= 0; j
< i
; j
++)
151 if (fourcc
[j
] == fourcc
[i
]) {
152 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"duplicated format ID");
159 static const struct {
161 const unsigned int num
;
163 // note: due to parser deficiencies/simplicity, if one format
164 // name matches the beginning of another, the longer one _must_
165 // come first in this list.
166 {"YV12", IMGFMT_YV12
},
167 {"I420", IMGFMT_I420
},
168 {"IYUV", IMGFMT_IYUV
},
169 {"NV12", IMGFMT_NV12
},
170 {"NV21", IMGFMT_NV21
},
171 {"YVU9", IMGFMT_YVU9
},
172 {"IF09", IMGFMT_IF09
},
173 {"444P16LE", IMGFMT_444P16_LE
},
174 {"444P16BE", IMGFMT_444P16_BE
},
175 {"422P16LE", IMGFMT_422P16_LE
},
176 {"422P16BE", IMGFMT_422P16_BE
},
177 {"420P16LE", IMGFMT_420P16_LE
},
178 {"420P16BE", IMGFMT_420P16_BE
},
179 {"444P16", IMGFMT_444P16
},
180 {"422P16", IMGFMT_422P16
},
181 {"420P16", IMGFMT_420P16
},
182 {"420A", IMGFMT_420A
},
183 {"444P", IMGFMT_444P
},
184 {"422P", IMGFMT_422P
},
185 {"411P", IMGFMT_411P
},
186 {"440P", IMGFMT_440P
},
187 {"Y800", IMGFMT_Y800
},
190 {"YUY2", IMGFMT_YUY2
},
191 {"UYVY", IMGFMT_UYVY
},
192 {"YVYU", IMGFMT_YVYU
},
194 {"RGB48LE", IMGFMT_RGB48LE
},
195 {"RGB48BE", IMGFMT_RGB48BE
},
196 {"RGB4", IMGFMT_RGB4
},
197 {"RGB8", IMGFMT_RGB8
},
198 {"RGB15", IMGFMT_RGB15
},
199 {"RGB16", IMGFMT_RGB16
},
200 {"RGB24", IMGFMT_RGB24
},
201 {"RGB32", IMGFMT_RGB32
},
202 {"BGR4", IMGFMT_BGR4
},
203 {"BGR8", IMGFMT_BGR8
},
204 {"BGR15", IMGFMT_BGR15
},
205 {"BGR16", IMGFMT_BGR16
},
206 {"BGR24", IMGFMT_BGR24
},
207 {"BGR32", IMGFMT_BGR32
},
208 {"RGB1", IMGFMT_RGB1
},
209 {"BGR1", IMGFMT_BGR1
},
211 {"MPES", IMGFMT_MPEGPES
},
212 {"ZRMJPEGNI", IMGFMT_ZRMJPEGNI
},
213 {"ZRMJPEGIT", IMGFMT_ZRMJPEGIT
},
214 {"ZRMJPEGIB", IMGFMT_ZRMJPEGIB
},
216 {"IDCT_MPEG2",IMGFMT_XVMC_IDCT_MPEG2
},
217 {"MOCO_MPEG2",IMGFMT_XVMC_MOCO_MPEG2
},
219 {"VDPAU_MPEG1",IMGFMT_VDPAU_MPEG1
},
220 {"VDPAU_MPEG2",IMGFMT_VDPAU_MPEG2
},
221 {"VDPAU_H264",IMGFMT_VDPAU_H264
},
222 {"VDPAU_WMV3",IMGFMT_VDPAU_WMV3
},
223 {"VDPAU_VC1",IMGFMT_VDPAU_VC1
},
224 {"VDPAU_MPEG4",IMGFMT_VDPAU_MPEG4
},
230 static int add_to_inout(char *sfmt
, char *sflags
, unsigned int *outfmt
,
231 unsigned char *outflags
)
234 static char *flagstr
[] = {
246 for (i
= 0; i
< CODECS_MAX_OUTFMT
&& outfmt
[i
] != 0xffffffff; i
++)
248 freeslots
= CODECS_MAX_OUTFMT
- i
;
250 goto err_out_too_many
;
255 for (j
= 0; flagstr
[j
] != NULL
; j
++)
256 if (!strncmp(sflags
, flagstr
[j
],
259 if (flagstr
[j
] == NULL
)
260 goto err_out_parse_error
;
262 sflags
+=strlen(flagstr
[j
]);
263 } while (*(sflags
++) == ',');
265 if (*(--sflags
) != '\0')
266 goto err_out_parse_error
;
270 for (j
= 0; fmt_table
[j
].name
!= NULL
; j
++)
271 if (!strncmp(sfmt
, fmt_table
[j
].name
, strlen(fmt_table
[j
].name
)))
273 if (fmt_table
[j
].name
== NULL
)
274 goto err_out_parse_error
;
275 outfmt
[i
] = fmt_table
[j
].num
;
278 sfmt
+=strlen(fmt_table
[j
].name
);
279 } while ((*(sfmt
++) == ',') && --freeslots
);
282 goto err_out_too_many
;
284 if (*(--sfmt
) != '\0')
285 goto err_out_parse_error
;
289 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"too many out...");
292 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"parse error");
297 static short get_driver(char *s
,int audioflag
)
299 static char *audiodrv
[] = {
325 static char *videodrv
[] = {
355 char **drv
=audioflag
?audiodrv
:videodrv
;
358 for(i
=0;drv
[i
];i
++) if(!strcmp(s
,drv
[i
])) return i
;
364 static int validate_codec(codecs_t
*c
, int type
)
367 char *tmp_name
= c
->name
;
369 for (i
= 0; i
< strlen(tmp_name
) && isalnum(tmp_name
[i
]); i
++)
372 if (i
< strlen(tmp_name
)) {
373 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"\ncodec(%s) name is not valid!\n", c
->name
);
378 c
->info
= strdup(c
->name
);
381 if (c
->fourcc
[0] == 0xffffffff) {
382 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"\ncodec(%s) does not have FourCC/format!\n", c
->name
);
388 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"\ncodec(%s) does not have a driver!\n", c
->name
);
393 #warning codec->driver == 4;... <- this should not be put in here...
394 #warning Where are they defined ????????????
395 if (!c
->dll
&& (c
->driver
== 4 ||
396 (c
->driver
== 2 && type
== TYPE_VIDEO
))) {
397 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"\ncodec(%s) needs a 'dll'!\n", c
->name
);
400 #warning Can guid.f1 be 0? How does one know that it was not given?
401 // if (!(codec->flags & CODECS_FLAG_AUDIO) && codec->driver == 4)
403 if (type
== TYPE_VIDEO
)
404 if (c
->outfmt
[0] == 0xffffffff) {
405 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"\ncodec(%s) needs an 'outfmt'!\n", c
->name
);
412 static int add_comment(char *s
, char **d
)
422 if (!(*d
= realloc(*d
, pos
+ strlen(s
) + 1))) {
423 mp_tmsg(MSGT_CODECCFG
,MSGL_FATAL
,"Can't allocate memory for comment. ");
430 static short get_cpuflags(char *s
)
432 static char *flagstr
[] = {
442 for (i
= 0; flagstr
[i
]; i
++)
443 if (!strncmp(s
, flagstr
[i
], strlen(flagstr
[i
])))
446 goto err_out_parse_error
;
448 s
+= strlen(flagstr
[i
]);
449 } while (*(s
++) == ',');
452 goto err_out_parse_error
;
460 static int line_num
= 0;
462 static char *token
[MAX_NR_TOKEN
];
463 static int read_nextline
= 1;
465 static int get_token(int min
, int max
)
471 if (max
>= MAX_NR_TOKEN
) {
472 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"get_token(): max >= MAX_MR_TOKEN!");
476 memset(token
, 0x00, sizeof(*token
) * max
);
479 if (!fgets(line
, MAX_LINE_LEN
, fp
))
485 for (i
= 0; i
< max
; i
++) {
486 while (isspace(line
[line_pos
]))
488 if (line
[line_pos
] == '\0' || line
[line_pos
] == '#' ||
489 line
[line_pos
] == ';') {
495 token
[i
] = line
+ line_pos
;
497 if (c
== '"' || c
== '\'') {
499 while (line
[++line_pos
] != c
&& line
[line_pos
])
502 for (/* NOTHING */; !isspace(line
[line_pos
]) &&
503 line
[line_pos
]; line_pos
++)
506 if (!line
[line_pos
]) {
512 line
[line_pos
] = '\0';
524 static codecs_t
*video_codecs
=NULL
;
525 static codecs_t
*audio_codecs
=NULL
;
526 static int nr_vcodecs
= 0;
527 static int nr_acodecs
= 0;
529 int parse_codec_cfg(const char *cfgfile
)
531 codecs_t
*codec
= NULL
; // current codec
532 codecs_t
**codecsp
= NULL
;// points to audio_codecs or to video_codecs
533 char *endptr
; // strtoul()...
535 int codec_type
; /* TYPE_VIDEO/TYPE_AUDIO */
538 // in case we call it a second time
539 codecs_uninit_free();
548 video_codecs
= builtin_video_codecs
;
549 audio_codecs
= builtin_audio_codecs
;
550 nr_vcodecs
= sizeof(builtin_video_codecs
)/sizeof(codecs_t
);
551 nr_acodecs
= sizeof(builtin_audio_codecs
)/sizeof(codecs_t
);
556 mp_tmsg(MSGT_CODECCFG
,MSGL_V
,"Reading %s: ", cfgfile
);
558 if ((fp
= fopen(cfgfile
, "r")) == NULL
) {
559 mp_tmsg(MSGT_CODECCFG
,MSGL_V
,"Can't open '%s': %s\n", cfgfile
, strerror(errno
));
563 if ((line
= malloc(MAX_LINE_LEN
+ 1)) == NULL
) {
564 mp_tmsg(MSGT_CODECCFG
,MSGL_FATAL
,"Can't get memory for 'line': %s\n", strerror(errno
));
570 * this only catches release lines at the start of
571 * codecs.conf, before audiocodecs and videocodecs.
573 while ((tmp
= get_token(1, 1)) == RET_EOL
)
577 if (!strcmp(token
[0], "release")) {
578 if (get_token(1, 2) < 0)
579 goto err_out_parse_error
;
580 tmp
= atoi(token
[0]);
581 if (tmp
< CODEC_CFG_MIN
)
582 goto err_out_release_num
;
583 while ((tmp
= get_token(1, 1)) == RET_EOL
)
588 goto err_out_release_num
;
591 * check if the next block starts with 'audiocodec' or
594 if (!strcmp(token
[0], "audiocodec") || !strcmp(token
[0], "videocodec"))
596 goto err_out_parse_error
;
598 while ((tmp
= get_token(1, 1)) != RET_EOF
) {
601 if (!strcmp(token
[0], "audiocodec") ||
602 !strcmp(token
[0], "videocodec")) {
603 if (!validate_codec(codec
, codec_type
))
604 goto err_out_not_valid
;
606 if (*token
[0] == 'v') {
607 codec_type
= TYPE_VIDEO
;
608 nr_codecsp
= &nr_vcodecs
;
609 codecsp
= &video_codecs
;
610 } else if (*token
[0] == 'a') {
611 codec_type
= TYPE_AUDIO
;
612 nr_codecsp
= &nr_acodecs
;
613 codecsp
= &audio_codecs
;
616 mp_msg(MSGT_CODECCFG
,MSGL_ERR
,"picsba\n");
620 if (!(*codecsp
= realloc(*codecsp
,
621 sizeof(codecs_t
) * (*nr_codecsp
+ 2)))) {
622 mp_tmsg(MSGT_CODECCFG
,MSGL_FATAL
,"Can't realloc '*codecsp': %s\n", strerror(errno
));
625 codec
=*codecsp
+ *nr_codecsp
;
627 memset(codec
,0,sizeof(codecs_t
));
628 memset(codec
->fourcc
, 0xff, sizeof(codec
->fourcc
));
629 memset(codec
->outfmt
, 0xff, sizeof(codec
->outfmt
));
630 memset(codec
->infmt
, 0xff, sizeof(codec
->infmt
));
632 if (get_token(1, 1) < 0)
633 goto err_out_parse_error
;
634 for (i
= 0; i
< *nr_codecsp
- 1; i
++) {
635 if(( (*codecsp
)[i
].name
!=NULL
) &&
636 (!strcmp(token
[0], (*codecsp
)[i
].name
)) ) {
637 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"Codec name '%s' isn't unique.", token
[0]);
638 goto err_out_print_linenum
;
641 if (!(codec
->name
= strdup(token
[0]))) {
642 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"Can't strdup -> 'name': %s\n", strerror(errno
));
645 } else if (!strcmp(token
[0], "info")) {
646 if (codec
->info
|| get_token(1, 1) < 0)
647 goto err_out_parse_error
;
648 if (!(codec
->info
= strdup(token
[0]))) {
649 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"Can't strdup -> 'info': %s\n", strerror(errno
));
652 } else if (!strcmp(token
[0], "comment")) {
653 if (get_token(1, 1) < 0)
654 goto err_out_parse_error
;
655 add_comment(token
[0], &codec
->comment
);
656 } else if (!strcmp(token
[0], "fourcc")) {
657 if (get_token(1, 2) < 0)
658 goto err_out_parse_error
;
659 if (!add_to_fourcc(token
[0], token
[1],
662 goto err_out_print_linenum
;
663 } else if (!strcmp(token
[0], "format")) {
664 if (get_token(1, 2) < 0)
665 goto err_out_parse_error
;
666 if (!add_to_format(token
[0], token
[1],
667 codec
->fourcc
,codec
->fourccmap
))
668 goto err_out_print_linenum
;
669 } else if (!strcmp(token
[0], "driver")) {
670 if (get_token(1, 1) < 0)
671 goto err_out_parse_error
;
672 if (!(codec
->drv
= strdup(token
[0]))) {
673 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"Can't strdup -> 'driver': %s\n", strerror(errno
));
676 } else if (!strcmp(token
[0], "dll")) {
677 if (get_token(1, 1) < 0)
678 goto err_out_parse_error
;
679 if (!(codec
->dll
= strdup(token
[0]))) {
680 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"Can't strdup -> 'dll': %s", strerror(errno
));
683 } else if (!strcmp(token
[0], "guid")) {
684 if (get_token(11, 11) < 0)
685 goto err_out_parse_error
;
686 codec
->guid
.f1
=strtoul(token
[0],&endptr
,0);
687 if ((*endptr
!= ',' || *(endptr
+ 1) != '\0') &&
689 goto err_out_parse_error
;
690 codec
->guid
.f2
=strtoul(token
[1],&endptr
,0);
691 if ((*endptr
!= ',' || *(endptr
+ 1) != '\0') &&
693 goto err_out_parse_error
;
694 codec
->guid
.f3
=strtoul(token
[2],&endptr
,0);
695 if ((*endptr
!= ',' || *(endptr
+ 1) != '\0') &&
697 goto err_out_parse_error
;
698 for (i
= 0; i
< 8; i
++) {
699 codec
->guid
.f4
[i
]=strtoul(token
[i
+ 3],&endptr
,0);
700 if ((*endptr
!= ',' || *(endptr
+ 1) != '\0') &&
702 goto err_out_parse_error
;
704 } else if (!strcmp(token
[0], "out")) {
705 if (get_token(1, 2) < 0)
706 goto err_out_parse_error
;
707 if (!add_to_inout(token
[0], token
[1], codec
->outfmt
,
709 goto err_out_print_linenum
;
710 } else if (!strcmp(token
[0], "in")) {
711 if (get_token(1, 2) < 0)
712 goto err_out_parse_error
;
713 if (!add_to_inout(token
[0], token
[1], codec
->infmt
,
715 goto err_out_print_linenum
;
716 } else if (!strcmp(token
[0], "flags")) {
717 if (get_token(1, 1) < 0)
718 goto err_out_parse_error
;
719 if (!strcmp(token
[0], "seekable"))
720 codec
->flags
|= CODECS_FLAG_SEEKABLE
;
721 else if (!strcmp(token
[0], "align16"))
722 codec
->flags
|= CODECS_FLAG_ALIGN16
;
724 goto err_out_parse_error
;
725 } else if (!strcmp(token
[0], "status")) {
726 if (get_token(1, 1) < 0)
727 goto err_out_parse_error
;
728 if (!strcasecmp(token
[0], "working"))
729 codec
->status
= CODECS_STATUS_WORKING
;
730 else if (!strcasecmp(token
[0], "crashing"))
731 codec
->status
= CODECS_STATUS_NOT_WORKING
;
732 else if (!strcasecmp(token
[0], "untested"))
733 codec
->status
= CODECS_STATUS_UNTESTED
;
734 else if (!strcasecmp(token
[0], "buggy"))
735 codec
->status
= CODECS_STATUS_PROBLEMS
;
737 goto err_out_parse_error
;
738 } else if (!strcmp(token
[0], "cpuflags")) {
739 if (get_token(1, 1) < 0)
740 goto err_out_parse_error
;
741 if (!(codec
->cpuflags
= get_cpuflags(token
[0])))
742 goto err_out_parse_error
;
744 goto err_out_parse_error
;
746 if (!validate_codec(codec
, codec_type
))
747 goto err_out_not_valid
;
748 mp_tmsg(MSGT_CODECCFG
,MSGL_INFO
,"%d audio & %d video codecs\n", nr_acodecs
, nr_vcodecs
);
749 if(video_codecs
) video_codecs
[nr_vcodecs
].name
= NULL
;
750 if(audio_codecs
) audio_codecs
[nr_acodecs
].name
= NULL
;
758 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"parse error");
759 err_out_print_linenum
:
762 codecs_uninit_free();
770 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"Codec is not defined correctly.");
771 goto err_out_print_linenum
;
773 mp_tmsg(MSGT_CODECCFG
,MSGL_ERR
,"This codecs.conf is too old and incompatible with this MPlayer release!");
774 goto err_out_print_linenum
;
777 static void codecs_free(codecs_t
* codecs
,int count
) {
779 for ( i
= 0; i
< count
; i
++)
780 if ( codecs
[i
].name
) {
782 free(codecs
[i
].name
);
784 free(codecs
[i
].info
);
785 if( codecs
[i
].comment
)
786 free(codecs
[i
].comment
);
796 void codecs_uninit_free(void) {
798 codecs_free(video_codecs
,nr_vcodecs
);
801 codecs_free(audio_codecs
,nr_acodecs
);
805 codecs_t
*find_audio_codec(unsigned int fourcc
, unsigned int *fourccmap
,
806 codecs_t
*start
, int force
)
808 return find_codec(fourcc
, fourccmap
, start
, 1, force
);
811 codecs_t
*find_video_codec(unsigned int fourcc
, unsigned int *fourccmap
,
812 codecs_t
*start
, int force
)
814 return find_codec(fourcc
, fourccmap
, start
, 0, force
);
817 codecs_t
* find_codec(unsigned int fourcc
,unsigned int *fourccmap
,
818 codecs_t
*start
, int audioflag
, int force
)
825 for (/* NOTHING */; start
->name
; start
++) {
826 for (j
= 0; j
< CODECS_MAX_FOURCC
; j
++) {
827 if (start
->fourcc
[j
] == fourcc
) {
829 *fourccmap
= start
->fourccmap
[j
];
845 for (/* NOTHING */; i
--; c
++) {
846 if(start
&& c
<=start
) continue;
847 for (j
= 0; j
< CODECS_MAX_FOURCC
; j
++) {
848 // FIXME: do NOT hardwire 'null' name here:
849 if (c
->fourcc
[j
]==fourcc
|| !strcmp(c
->drv
,"null")) {
851 *fourccmap
= c
->fourccmap
[j
];
861 void stringset_init(stringset_t
*set
) {
862 *set
= calloc(1, sizeof(char *));
865 void stringset_free(stringset_t
*set
) {
867 while ((*set
)[count
]) free((*set
)[count
++]);
872 void stringset_add(stringset_t
*set
, const char *str
) {
874 while ((*set
)[count
]) count
++;
876 *set
= realloc(*set
, sizeof(char *) * (count
+ 1));
877 (*set
)[count
- 1] = strdup(str
);
878 (*set
)[count
] = NULL
;
881 int stringset_test(stringset_t
*set
, const char *str
) {
883 for (s
= *set
; *s
; s
++)
884 if (strcmp(*s
, str
) == 0)
889 void list_codecs(int audioflag
){
896 mp_msg(MSGT_CODECCFG
,MSGL_INFO
,"ac: afm: status: info: [lib/dll]\n");
900 mp_msg(MSGT_CODECCFG
,MSGL_INFO
,"vc: vfm: status: info: [lib/dll]\n");
903 for (/* NOTHING */; i
--; c
++) {
906 case CODECS_STATUS_WORKING
: s
="working ";break;
907 case CODECS_STATUS_PROBLEMS
: s
="problems";break;
908 case CODECS_STATUS_NOT_WORKING
: s
="crashing";break;
909 case CODECS_STATUS_UNTESTED
: s
="untested";break;
912 mp_msg(MSGT_CODECCFG
,MSGL_INFO
,"%-11s %-9s %s %s [%s]\n",c
->name
,c
->drv
,s
,c
->info
,c
->dll
);
914 mp_msg(MSGT_CODECCFG
,MSGL_INFO
,"%-11s %-9s %s %s\n",c
->name
,c
->drv
,s
,c
->info
);
920 void wrapline(FILE *f2
,char *s
){
927 if(c
==',') fprintf(f2
,"<br>"); else fputc(c
,f2
);
931 void parsehtml(FILE *f1
,FILE *f2
,codecs_t
*codec
,int section
,int dshow
){
933 while((c
=fgetc(f1
))>=0){
942 return; // end of section
944 wrapline(f2
,codec
->name
); break;
946 wrapline(f2
,codec
->info
); break;
948 wrapline(f2
,codec
->comment
); break;
950 wrapline(f2
,codec
->dll
); break;
952 fprintf(f2
,"%c",!strcmp(codec
->drv
,"dshow")?'+':'-'); break;
954 for(d
=0;d
<CODECS_MAX_FOURCC
;d
++)
955 if(!d
|| codec
->fourcc
[d
]!=0xFFFFFFFF)
956 fprintf(f2
,"%s%.4s",d
?"<br>":"",(codec
->fourcc
[d
]==0xFFFFFFFF || codec
->fourcc
[d
]<0x20202020)?!d
?"-":"":(char*) &codec
->fourcc
[d
]);
959 for(d
=0;d
<CODECS_MAX_FOURCC
;d
++)
960 if(codec
->fourcc
[d
]!=0xFFFFFFFF)
961 fprintf(f2
,"%s0x%X",d
?"<br>":"",codec
->fourcc
[d
]);
964 for(d
=0;d
<CODECS_MAX_OUTFMT
;d
++)
965 if(codec
->outfmt
[d
]!=0xFFFFFFFF){
966 for (c
=0; fmt_table
[c
].name
; c
++)
967 if(fmt_table
[c
].num
==codec
->outfmt
[d
]) break;
968 if(fmt_table
[c
].name
)
969 fprintf(f2
,"%s%s",d
?"<br>":"",fmt_table
[c
].name
);
979 void skiphtml(FILE *f1
){
981 while((c
=fgetc(f1
))>=0){
986 if(d
=='.') return; // end of section
990 static void print_int_array(const unsigned int* a
, int size
)
995 printf("%d%s", *a
++, size
?", ":"");
997 printf("0x%X%s", *a
++, size
?", ":"");
1001 static void print_char_array(const unsigned char* a
, int size
)
1006 printf("%d%s", *a
++, size
?", ":"");
1008 printf("0x%02x%s", *a
++, size
?", ":"");
1012 static void print_string(const char* s
)
1014 if (!s
) printf("NULL");
1015 else printf("\"%s\"", s
);
1018 int main(int argc
, char* argv
[])
1032 * Take path to codecs.conf from command line, or fall back on
1035 if (!(nr_codecs
= parse_codec_cfg((argc
>1)?argv
[1]:"etc/codecs.conf")))
1044 nm
[0] = "builtin_video_codecs";
1045 cod
[0] = video_codecs
;
1048 nm
[1] = "builtin_audio_codecs";
1049 cod
[1] = audio_codecs
;
1052 printf("/* GENERATED FROM %s, DO NOT EDIT! */\n\n",argv
[1]);
1053 printf("#include <stddef.h>\n");
1054 printf("#include \"codec-cfg.h\"\n\n");
1056 for (i
=0; i
<2; i
++) {
1057 printf("const codecs_t %s[] = {\n", nm
[i
]);
1058 for (j
= 0; j
< nr
[i
]; j
++) {
1061 print_int_array(cod
[i
][j
].fourcc
, CODECS_MAX_FOURCC
);
1062 printf(", /* fourcc */\n");
1064 print_int_array(cod
[i
][j
].fourccmap
, CODECS_MAX_FOURCC
);
1065 printf(", /* fourccmap */\n");
1067 print_int_array(cod
[i
][j
].outfmt
, CODECS_MAX_OUTFMT
);
1068 printf(", /* outfmt */\n");
1070 print_char_array(cod
[i
][j
].outflags
, CODECS_MAX_OUTFMT
);
1071 printf(", /* outflags */\n");
1073 print_int_array(cod
[i
][j
].infmt
, CODECS_MAX_INFMT
);
1074 printf(", /* infmt */\n");
1076 print_char_array(cod
[i
][j
].inflags
, CODECS_MAX_INFMT
);
1077 printf(", /* inflags */\n");
1079 print_string(cod
[i
][j
].name
); printf(", /* name */\n");
1080 print_string(cod
[i
][j
].info
); printf(", /* info */\n");
1081 print_string(cod
[i
][j
].comment
); printf(", /* comment */\n");
1082 print_string(cod
[i
][j
].dll
); printf(", /* dll */\n");
1083 print_string(cod
[i
][j
].drv
); printf(", /* drv */\n");
1085 printf("{ 0x%08lx, %hu, %hu,",
1089 print_char_array(cod
[i
][j
].guid
.f4
, sizeof(cod
[i
][j
].guid
.f4
));
1090 printf(" }, /* GUID */\n");
1091 printf("%hd /* flags */, %hd /* status */, %hd /* cpuflags */ }\n",
1094 cod
[i
][j
].cpuflags
);
1095 if (j
< nr
[i
]) printf(",\n");
1102 f1
=fopen("DOCS/tech/codecs-in.html","rb"); if(!f1
) exit(1);
1103 f2
=fopen("DOCS/codecs-status.html","wb"); if(!f2
) exit(1);
1105 while((c
=fgetc(f1
))>=0){
1111 if(d
>='0' && d
<='9'){
1114 //printf("BEGIN %d\n",section);
1118 nr_codecs
= nr_acodecs
;
1123 nr_codecs
= nr_vcodecs
;
1124 dshow
=4;win32
=2;win32ex
=6;
1127 for(i
=0;i
<nr_codecs
;i
++){
1128 fseek(f1
,pos
,SEEK_SET
);
1132 if(cl
[i
].status
==CODECS_STATUS_WORKING
)
1133 // if(!(!strcmp(cl[i].drv,"vfw") || !strcmp(cl[i].drv,"dshow") || !strcmp(cl[i].drv,"vfwex") || !strcmp(cl[i].drv,"acm")))
1134 parsehtml(f1
,f2
,&cl
[i
],section
,dshow
);
1139 if(cl
[i
].status
==CODECS_STATUS_WORKING
)
1140 if((!strcmp(cl
[i
].drv
,"vfw") || !strcmp(cl
[i
].drv
,"dshow") || !strcmp(cl
[i
].drv
,"vfwex") || !strcmp(cl
[i
].drv
,"acm")))
1141 parsehtml(f1
,f2
,&cl
[i
],section
,dshow
);
1146 if(cl
[i
].status
==CODECS_STATUS_PROBLEMS
)
1147 parsehtml(f1
,f2
,&cl
[i
],section
,dshow
);
1151 if(cl
[i
].status
==CODECS_STATUS_NOT_WORKING
)
1152 parsehtml(f1
,f2
,&cl
[i
],section
,dshow
);
1156 if(cl
[i
].status
==CODECS_STATUS_UNTESTED
)
1157 parsehtml(f1
,f2
,&cl
[i
],section
,dshow
);
1160 printf("Warning! unimplemented section: %d\n",section
);
1163 fseek(f1
,pos
,SEEK_SET
);
1165 //void parsehtml(FILE *f1,FILE *f2,codecs_t *codec,int section,int dshow){
1184 int i
,j
, nr_codecs
, state
;
1186 if (!(parse_codec_cfg("etc/codecs.conf")))
1189 printf("no videoconfig.\n");
1191 printf("no audioconfig.\n");
1193 printf("videocodecs:\n");
1195 nr_codecs
= nr_vcodecs
;
1199 printf("number of %scodecs: %d\n", state
==0?"video":"audio",
1201 for(i
=0;i
<nr_codecs
;i
++, c
++){
1202 printf("\n============== %scodec %02d ===============\n",
1203 state
==0?"video":"audio",i
);
1204 printf("name='%s'\n",c
->name
);
1205 printf("info='%s'\n",c
->info
);
1206 printf("comment='%s'\n",c
->comment
);
1207 printf("dll='%s'\n",c
->dll
);
1208 /* printf("flags=%X driver=%d status=%d cpuflags=%d\n",
1209 c->flags, c->driver, c->status, c->cpuflags); */
1210 printf("flags=%X status=%d cpuflags=%d\n",
1211 c
->flags
, c
->status
, c
->cpuflags
);
1213 for(j
=0;j
<CODECS_MAX_FOURCC
;j
++){
1214 if(c
->fourcc
[j
]!=0xFFFFFFFF){
1215 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j
,c
->fourcc
[j
],(char *) &c
->fourcc
[j
],c
->fourccmap
[j
],(char *) &c
->fourccmap
[j
]);
1219 for(j
=0;j
<CODECS_MAX_OUTFMT
;j
++){
1220 if(c
->outfmt
[j
]!=0xFFFFFFFF){
1221 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j
,c
->outfmt
[j
],(char *) &c
->outfmt
[j
],c
->outflags
[j
]);
1225 for(j
=0;j
<CODECS_MAX_INFMT
;j
++){
1226 if(c
->infmt
[j
]!=0xFFFFFFFF){
1227 printf("infmt %02d: %08X (%.4s) flags: %d\n",j
,c
->infmt
[j
],(char *) &c
->infmt
[j
],c
->inflags
[j
]);
1231 printf("GUID: %08lX %04X %04X",c
->guid
.f1
,c
->guid
.f2
,c
->guid
.f3
);
1232 for(j
=0;j
<8;j
++) printf(" %02X",c
->guid
.f4
[j
]);
1239 printf("audiocodecs:\n");
1241 nr_codecs
= nr_acodecs
;