cleanup: remove XvMC remains, reformat img_format.c
[mplayer.git] / codec-cfg.c
blobb1096e7de6ebb21c22ceb49218cf63ec1291252a
1 /*
2 * codecs.conf parser
4 * Copyright (C) 2001 Szabolcs Berecz <szabi@inf.elte.hu>
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <fcntl.h>
26 #include <unistd.h>
27 #include <errno.h>
28 #include <ctype.h>
29 #include <assert.h>
30 #include <string.h>
31 #include <stdint.h>
33 #include "config.h"
34 #include "mp_msg.h"
35 #include "libmpcodecs/img_format.h"
36 #include "codec-cfg.h"
37 #include "bstr.h"
38 #include "stream/stream.h"
39 #include "path.h"
41 static const char embedded_file[] =
42 #include "codecs.conf.h"
44 static const struct bstr builtin_codecs_conf = {
45 .start = (char *)embedded_file, .len = sizeof(embedded_file) - 1
48 #define mmioFOURCC( ch0, ch1, ch2, ch3 ) \
49 ( (uint32_t)(uint8_t)(ch0) | ( (uint32_t)(uint8_t)(ch1) << 8 ) | \
50 ( (uint32_t)(uint8_t)(ch2) << 16 ) | ( (uint32_t)(uint8_t)(ch3) << 24 ) )
52 #define PRINT_LINENUM mp_msg(MSGT_CODECCFG,MSGL_ERR," at line %d\n", line_num)
54 #define MAX_NR_TOKEN 16
56 #define RET_EOF -1
57 #define RET_EOL -2
59 #define TYPE_VIDEO 0
60 #define TYPE_AUDIO 1
62 static int codecs_conf_release;
63 char * codecs_file = NULL;
65 static int add_to_fourcc(char *s, char *alias, unsigned int *fourcc,
66 unsigned int *map)
68 int i, j, freeslots;
69 unsigned int tmp;
71 /* find first unused slot */
72 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++)
73 /* NOTHING */;
74 freeslots = CODECS_MAX_FOURCC - i;
75 if (!freeslots)
76 goto err_out_too_many;
78 do {
79 if (strlen(s) < 4)
80 goto err_out_parse_error;
81 tmp = mmioFOURCC(s[0], s[1], s[2], s[3]);
82 for (j = 0; j < i; j++)
83 if (tmp == fourcc[j])
84 goto err_out_duplicated;
85 fourcc[i] = tmp;
86 map[i] = alias ? mmioFOURCC(alias[0], alias[1], alias[2], alias[3]) : tmp;
87 s += 4;
88 i++;
89 } while ((*(s++) == ',') && --freeslots);
91 if (!freeslots)
92 goto err_out_too_many;
93 if (*(--s) != '\0')
94 goto err_out_parse_error;
95 return 1;
96 err_out_duplicated:
97 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"duplicated FourCC");
98 return 0;
99 err_out_too_many:
100 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"too many FourCCs/formats...");
101 return 0;
102 err_out_parse_error:
103 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"parse error");
104 return 0;
107 static int add_to_format(char *s, char *alias,unsigned int *fourcc, unsigned int *fourccmap)
109 int i, j;
110 char *endptr;
112 /* find first unused slot */
113 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++)
114 /* NOTHING */;
115 if (i == CODECS_MAX_FOURCC) {
116 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"too many FourCCs/formats...");
117 return 0;
120 fourcc[i]=strtoul(s,&endptr,0);
121 if (*endptr != '\0') {
122 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"parse error (format ID not a number?)");
123 return 0;
126 if(alias){
127 fourccmap[i]=strtoul(alias,&endptr,0);
128 if (*endptr != '\0') {
129 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"parse error (format ID alias not a number?)");
130 return 0;
132 } else
133 fourccmap[i]=fourcc[i];
135 for (j = 0; j < i; j++)
136 if (fourcc[j] == fourcc[i]) {
137 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"duplicated format ID");
138 return 0;
141 return 1;
144 static const struct {
145 const char *name;
146 const unsigned int num;
147 } fmt_table[] = {
148 // note: due to parser deficiencies/simplicity, if one format
149 // name matches the beginning of another, the longer one _must_
150 // come first in this list.
151 {"YV12", IMGFMT_YV12},
152 {"I420", IMGFMT_I420},
153 {"IYUV", IMGFMT_IYUV},
154 {"NV12", IMGFMT_NV12},
155 {"NV21", IMGFMT_NV21},
156 {"YVU9", IMGFMT_YVU9},
157 {"IF09", IMGFMT_IF09},
158 {"444P16LE", IMGFMT_444P16_LE},
159 {"444P16BE", IMGFMT_444P16_BE},
160 {"422P16LE", IMGFMT_422P16_LE},
161 {"422P16BE", IMGFMT_422P16_BE},
162 {"420P16LE", IMGFMT_420P16_LE},
163 {"420P16BE", IMGFMT_420P16_BE},
164 {"444P16", IMGFMT_444P16},
165 {"444P10", IMGFMT_444P10},
166 {"444P9", IMGFMT_444P9},
167 {"422P16", IMGFMT_422P16},
168 {"422P10", IMGFMT_422P10},
169 {"420P16", IMGFMT_420P16},
170 {"420P10", IMGFMT_420P10},
171 {"420P9", IMGFMT_420P9},
172 {"420A", IMGFMT_420A},
173 {"444P", IMGFMT_444P},
174 {"422P", IMGFMT_422P},
175 {"411P", IMGFMT_411P},
176 {"440P", IMGFMT_440P},
177 {"Y800", IMGFMT_Y800},
178 {"Y8", IMGFMT_Y8},
180 {"YUY2", IMGFMT_YUY2},
181 {"UYVY", IMGFMT_UYVY},
182 {"YVYU", IMGFMT_YVYU},
184 {"RGB48LE", IMGFMT_RGB48LE},
185 {"RGB48BE", IMGFMT_RGB48BE},
186 {"RGB4", IMGFMT_RGB4},
187 {"RGB8", IMGFMT_RGB8},
188 {"RGB15", IMGFMT_RGB15},
189 {"RGB16", IMGFMT_RGB16},
190 {"RGB24", IMGFMT_RGB24},
191 {"RGB32", IMGFMT_RGB32},
192 {"BGR4", IMGFMT_BGR4},
193 {"BGR8", IMGFMT_BGR8},
194 {"BGR15", IMGFMT_BGR15},
195 {"BGR16", IMGFMT_BGR16},
196 {"BGR24", IMGFMT_BGR24},
197 {"BGR32", IMGFMT_BGR32},
198 {"RGB1", IMGFMT_RGB1},
199 {"BGR1", IMGFMT_BGR1},
201 {"MPES", IMGFMT_MPEGPES},
203 {"VDPAU_MPEG1",IMGFMT_VDPAU_MPEG1},
204 {"VDPAU_MPEG2",IMGFMT_VDPAU_MPEG2},
205 {"VDPAU_H264",IMGFMT_VDPAU_H264},
206 {"VDPAU_WMV3",IMGFMT_VDPAU_WMV3},
207 {"VDPAU_VC1",IMGFMT_VDPAU_VC1},
208 {"VDPAU_MPEG4",IMGFMT_VDPAU_MPEG4},
210 {NULL, 0}
214 static int add_to_inout(char *sfmt, char *sflags, unsigned int *outfmt,
215 unsigned char *outflags)
218 static char *flagstr[] = {
219 "flip",
220 "noflip",
221 "yuvhack",
222 "query",
223 "static",
224 NULL
227 int i, j, freeslots;
228 unsigned char flags;
230 for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++)
231 /* NOTHING */;
232 freeslots = CODECS_MAX_OUTFMT - i;
233 if (!freeslots)
234 goto err_out_too_many;
236 flags = 0;
237 if(sflags) {
238 do {
239 for (j = 0; flagstr[j] != NULL; j++)
240 if (!strncmp(sflags, flagstr[j],
241 strlen(flagstr[j])))
242 break;
243 if (flagstr[j] == NULL)
244 goto err_out_parse_error;
245 flags|=(1<<j);
246 sflags+=strlen(flagstr[j]);
247 } while (*(sflags++) == ',');
249 if (*(--sflags) != '\0')
250 goto err_out_parse_error;
253 do {
254 for (j = 0; fmt_table[j].name != NULL; j++)
255 if (!strncmp(sfmt, fmt_table[j].name, strlen(fmt_table[j].name)))
256 break;
257 if (fmt_table[j].name == NULL)
258 goto err_out_parse_error;
259 outfmt[i] = fmt_table[j].num;
260 outflags[i] = flags;
261 ++i;
262 sfmt+=strlen(fmt_table[j].name);
263 } while ((*(sfmt++) == ',') && --freeslots);
265 if (!freeslots)
266 goto err_out_too_many;
268 if (*(--sfmt) != '\0')
269 goto err_out_parse_error;
271 return 1;
272 err_out_too_many:
273 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"too many out...");
274 return 0;
275 err_out_parse_error:
276 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"parse error");
277 return 0;
280 static int validate_codec(codecs_t *c, int type)
282 unsigned int i;
283 char *tmp_name = c->name;
285 for (i = 0; i < strlen(tmp_name) && isalnum(tmp_name[i]); i++)
286 /* NOTHING */;
288 if (i < strlen(tmp_name)) {
289 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"\ncodec(%s) name is not valid!\n", c->name);
290 return 0;
293 if (!c->info)
294 c->info = strdup(c->name);
296 if (!c->drv) {
297 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"\ncodec(%s) does not have a driver!\n", c->name);
298 return 0;
301 return 1;
304 static int add_comment(char *s, char **d)
306 int pos;
308 if (!*d)
309 pos = 0;
310 else {
311 pos = strlen(*d);
312 (*d)[pos++] = '\n';
314 if (!(*d = realloc(*d, pos + strlen(s) + 1))) {
315 mp_tmsg(MSGT_CODECCFG,MSGL_FATAL,"Can't allocate memory for comment. ");
316 return 0;
318 strcpy(*d + pos, s);
319 return 1;
322 static struct bstr filetext;
323 static int line_num = 0;
324 static char *line;
325 static char *token[MAX_NR_TOKEN];
326 static int read_nextline = 1;
328 static int get_token(int min, int max)
330 static int line_pos;
331 int i;
332 char c;
334 if (max >= MAX_NR_TOKEN) {
335 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"get_token(): max >= MAX_MR_TOKEN!");
336 goto out_eof;
339 memset(token, 0x00, sizeof(*token) * max);
341 if (read_nextline) {
342 if (!filetext.len)
343 goto out_eof;
344 struct bstr nextline = bstr_getline(filetext, &filetext);
345 line = nextline.start;
346 line[nextline.len - 1] = 0;
347 line_pos = 0;
348 ++line_num;
349 read_nextline = 0;
351 for (i = 0; i < max; i++) {
352 while (isspace(line[line_pos]))
353 ++line_pos;
354 if (line[line_pos] == '\0' || line[line_pos] == '#' ||
355 line[line_pos] == ';') {
356 read_nextline = 1;
357 if (i >= min)
358 goto out_ok;
359 goto out_eol;
361 token[i] = line + line_pos;
362 c = line[line_pos];
363 if (c == '"' || c == '\'') {
364 token[i]++;
365 while (line[++line_pos] != c && line[line_pos])
366 /* NOTHING */;
367 } else {
368 for (/* NOTHING */; !isspace(line[line_pos]) &&
369 line[line_pos]; line_pos++)
370 /* NOTHING */;
372 if (!line[line_pos]) {
373 read_nextline = 1;
374 if (i >= min - 1)
375 goto out_ok;
376 goto out_eol;
378 line[line_pos] = '\0';
379 line_pos++;
381 out_ok:
382 return i;
383 out_eof:
384 read_nextline = 1;
385 return RET_EOF;
386 out_eol:
387 return RET_EOL;
390 static codecs_t *video_codecs=NULL;
391 static codecs_t *audio_codecs=NULL;
392 static int nr_vcodecs = 0;
393 static int nr_acodecs = 0;
395 int parse_codec_cfg(const char *cfgfile)
397 codecs_t *codec = NULL; // current codec
398 codecs_t **codecsp = NULL;// points to audio_codecs or to video_codecs
399 char *endptr; // strtoul()...
400 int *nr_codecsp;
401 int codec_type; /* TYPE_VIDEO/TYPE_AUDIO */
402 int tmp, i;
403 int codec_cfg_min;
405 for (struct bstr s = builtin_codecs_conf; ; bstr_getline(s, &s)) {
406 if (!s.len)
407 abort();
408 if (bstr_eatstart0(&s, "release ")) {
409 codec_cfg_min = atoi(s.start);
410 break;
414 // in case we call it a second time
415 codecs_uninit_free();
417 nr_vcodecs = 0;
418 nr_acodecs = 0;
420 if (cfgfile) {
421 // Avoid printing errors from open_stream when trying optional files
422 if (!mp_path_exists(cfgfile)) {
423 mp_tmsg(MSGT_CODECCFG, MSGL_V,
424 "No optional codecs config file: %s\n", cfgfile);
425 return 0;
427 mp_msg(MSGT_CODECCFG, MSGL_V, "Reading codec config file: %s\n",
428 cfgfile);
429 struct stream *s = open_stream(cfgfile, NULL, NULL);
430 if (!s)
431 return 0;
432 filetext = stream_read_complete(s, NULL, 10000000, 1);
433 free_stream(s);
434 if (!filetext.start)
435 return 0;
436 } else
437 // Parsing modifies the data
438 filetext = bstrdup(NULL, builtin_codecs_conf);
439 void *tmpmem = filetext.start;
441 read_nextline = 1;
444 * this only catches release lines at the start of
445 * codecs.conf, before audiocodecs and videocodecs.
447 while ((tmp = get_token(1, 1)) == RET_EOL)
448 /* NOTHING */;
449 if (tmp == RET_EOF)
450 goto out;
451 if (!strcmp(token[0], "release")) {
452 if (get_token(1, 2) < 0)
453 goto err_out_parse_error;
454 tmp = atoi(token[0]);
455 if (tmp < codec_cfg_min)
456 goto err_out_release_num;
457 codecs_conf_release = tmp;
458 while ((tmp = get_token(1, 1)) == RET_EOL)
459 /* NOTHING */;
460 if (tmp == RET_EOF)
461 goto out;
462 } else
463 goto err_out_release_num;
466 * check if the next block starts with 'audiocodec' or
467 * with 'videocodec'
469 if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec"))
470 goto loop_enter;
471 goto err_out_parse_error;
473 while ((tmp = get_token(1, 1)) != RET_EOF) {
474 if (tmp == RET_EOL)
475 continue;
476 if (!strcmp(token[0], "audiocodec") ||
477 !strcmp(token[0], "videocodec")) {
478 if (!validate_codec(codec, codec_type))
479 goto err_out_not_valid;
480 loop_enter:
481 if (*token[0] == 'v') {
482 codec_type = TYPE_VIDEO;
483 nr_codecsp = &nr_vcodecs;
484 codecsp = &video_codecs;
485 } else {
486 assert(*token[0] == 'a');
487 codec_type = TYPE_AUDIO;
488 nr_codecsp = &nr_acodecs;
489 codecsp = &audio_codecs;
491 if (!(*codecsp = realloc(*codecsp,
492 sizeof(codecs_t) * (*nr_codecsp + 2)))) {
493 mp_tmsg(MSGT_CODECCFG,MSGL_FATAL,"Can't realloc '*codecsp': %s\n", strerror(errno));
494 goto err_out;
496 codec=*codecsp + *nr_codecsp;
497 ++*nr_codecsp;
498 memset(codec,0,sizeof(codecs_t));
499 memset(codec->fourcc, 0xff, sizeof(codec->fourcc));
500 memset(codec->outfmt, 0xff, sizeof(codec->outfmt));
501 memset(codec->infmt, 0xff, sizeof(codec->infmt));
503 if (get_token(1, 1) < 0)
504 goto err_out_parse_error;
505 for (i = 0; i < *nr_codecsp - 1; i++) {
506 if(( (*codecsp)[i].name!=NULL) &&
507 (!strcmp(token[0], (*codecsp)[i].name)) ) {
508 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"Codec name '%s' isn't unique.", token[0]);
509 goto err_out_print_linenum;
512 if (!(codec->name = strdup(token[0]))) {
513 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"Can't strdup -> 'name': %s\n", strerror(errno));
514 goto err_out;
516 } else if (!strcmp(token[0], "info")) {
517 if (codec->info || get_token(1, 1) < 0)
518 goto err_out_parse_error;
519 if (!(codec->info = strdup(token[0]))) {
520 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"Can't strdup -> 'info': %s\n", strerror(errno));
521 goto err_out;
523 } else if (!strcmp(token[0], "comment")) {
524 if (get_token(1, 1) < 0)
525 goto err_out_parse_error;
526 add_comment(token[0], &codec->comment);
527 } else if (!strcmp(token[0], "fourcc")) {
528 if (get_token(1, 2) < 0)
529 goto err_out_parse_error;
530 if (!add_to_fourcc(token[0], token[1],
531 codec->fourcc,
532 codec->fourccmap))
533 goto err_out_print_linenum;
534 } else if (!strcmp(token[0], "format")) {
535 if (get_token(1, 2) < 0)
536 goto err_out_parse_error;
537 if (!add_to_format(token[0], token[1],
538 codec->fourcc,codec->fourccmap))
539 goto err_out_print_linenum;
540 } else if (!strcmp(token[0], "driver")) {
541 if (get_token(1, 1) < 0)
542 goto err_out_parse_error;
543 if (!(codec->drv = strdup(token[0]))) {
544 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"Can't strdup -> 'driver': %s\n", strerror(errno));
545 goto err_out;
547 } else if (!strcmp(token[0], "dll")) {
548 if (get_token(1, 1) < 0)
549 goto err_out_parse_error;
550 if (!(codec->dll = strdup(token[0]))) {
551 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"Can't strdup -> 'dll': %s", strerror(errno));
552 goto err_out;
554 } else if (!strcmp(token[0], "guid")) {
555 if (get_token(11, 11) < 0)
556 goto err_out_parse_error;
557 codec->guid.f1=strtoul(token[0],&endptr,0);
558 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
559 *endptr != '\0')
560 goto err_out_parse_error;
561 codec->guid.f2=strtoul(token[1],&endptr,0);
562 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
563 *endptr != '\0')
564 goto err_out_parse_error;
565 codec->guid.f3=strtoul(token[2],&endptr,0);
566 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
567 *endptr != '\0')
568 goto err_out_parse_error;
569 for (i = 0; i < 8; i++) {
570 codec->guid.f4[i]=strtoul(token[i + 3],&endptr,0);
571 if ((*endptr != ',' || *(endptr + 1) != '\0') &&
572 *endptr != '\0')
573 goto err_out_parse_error;
575 } else if (!strcmp(token[0], "out")) {
576 if (get_token(1, 2) < 0)
577 goto err_out_parse_error;
578 if (!add_to_inout(token[0], token[1], codec->outfmt,
579 codec->outflags))
580 goto err_out_print_linenum;
581 } else if (!strcmp(token[0], "in")) {
582 if (get_token(1, 2) < 0)
583 goto err_out_parse_error;
584 if (!add_to_inout(token[0], token[1], codec->infmt,
585 codec->inflags))
586 goto err_out_print_linenum;
587 } else if (!strcmp(token[0], "flags")) {
588 if (get_token(1, 1) < 0)
589 goto err_out_parse_error;
590 if (!strcmp(token[0], "seekable"))
591 codec->flags |= CODECS_FLAG_SEEKABLE;
592 else if (!strcmp(token[0], "align16"))
593 codec->flags |= CODECS_FLAG_ALIGN16;
594 else
595 goto err_out_parse_error;
596 } else if (!strcmp(token[0], "status")) {
597 if (get_token(1, 1) < 0)
598 goto err_out_parse_error;
599 if (!strcasecmp(token[0], "working"))
600 codec->status = CODECS_STATUS_WORKING;
601 else if (!strcasecmp(token[0], "crashing"))
602 codec->status = CODECS_STATUS_NOT_WORKING;
603 else if (!strcasecmp(token[0], "untested"))
604 codec->status = CODECS_STATUS_UNTESTED;
605 else if (!strcasecmp(token[0], "buggy"))
606 codec->status = CODECS_STATUS_PROBLEMS;
607 else
608 goto err_out_parse_error;
609 } else if (!strcmp(token[0], "anyinput")) {
610 codec->anyinput = true;
611 } else
612 goto err_out_parse_error;
614 if (!validate_codec(codec, codec_type))
615 goto err_out_not_valid;
616 mp_tmsg(MSGT_CODECCFG, MSGL_V, "%d audio & %d video codecs\n", nr_acodecs,
617 nr_vcodecs);
618 if(video_codecs) video_codecs[nr_vcodecs].name = NULL;
619 if(audio_codecs) audio_codecs[nr_acodecs].name = NULL;
620 out:
621 talloc_free(tmpmem);
622 line=NULL;
623 return 1;
625 err_out_parse_error:
626 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"parse error");
627 err_out_print_linenum:
628 PRINT_LINENUM;
629 err_out:
630 codecs_uninit_free();
632 talloc_free(tmpmem);
633 line=NULL;
634 line_num = 0;
635 return 0;
636 err_out_not_valid:
637 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"Codec is not defined correctly.");
638 goto err_out_print_linenum;
639 err_out_release_num:
640 mp_tmsg(MSGT_CODECCFG,MSGL_ERR,"This codecs.conf is too old and incompatible with this MPlayer release!");
641 goto err_out_print_linenum;
644 static void codecs_free(codecs_t* codecs,int count) {
645 int i;
646 for ( i = 0; i < count; i++)
647 if ( codecs[i].name ) {
648 free(codecs[i].name);
649 free(codecs[i].info);
650 free(codecs[i].comment);
651 free(codecs[i].dll);
652 free(codecs[i].drv);
654 free(codecs);
657 void codecs_uninit_free(void) {
658 if (video_codecs)
659 codecs_free(video_codecs,nr_vcodecs);
660 video_codecs=NULL;
661 if (audio_codecs)
662 codecs_free(audio_codecs,nr_acodecs);
663 audio_codecs=NULL;
666 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap,
667 codecs_t *start, int force)
669 return find_codec(fourcc, fourccmap, start, 1, force);
672 codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap,
673 codecs_t *start, int force)
675 return find_codec(fourcc, fourccmap, start, 0, force);
678 struct codecs *find_codec(unsigned int fourcc, unsigned int *fourccmap,
679 codecs_t *start, int audioflag, int force)
681 struct codecs *c, *end;
683 if (audioflag) {
684 c = audio_codecs;
685 end = c + nr_acodecs;
686 } else {
687 c = video_codecs;
688 end = c + nr_vcodecs;
690 if (start)
691 c = start + 1; // actually starts from the next one after the given one
692 for (; c < end; c++) {
693 for (int j = 0; j < CODECS_MAX_FOURCC; j++) {
694 if (c->fourcc[j] == -1)
695 break;
696 if (c->fourcc[j] == fourcc) {
697 if (fourccmap)
698 *fourccmap = c->fourccmap[j];
699 return c;
702 if (c->anyinput || force)
703 return c;
705 return NULL;
708 void stringset_init(stringset_t *set) {
709 *set = calloc(1, sizeof(char *));
712 void stringset_free(stringset_t *set) {
713 int count = 0;
714 while ((*set)[count]) free((*set)[count++]);
715 free(*set);
716 *set = NULL;
719 void stringset_add(stringset_t *set, const char *str) {
720 int count = 0;
721 while ((*set)[count]) count++;
722 count++;
723 *set = realloc(*set, sizeof(char *) * (count + 1));
724 (*set)[count - 1] = strdup(str);
725 (*set)[count] = NULL;
728 int stringset_test(stringset_t *set, const char *str) {
729 stringset_t s;
730 for (s = *set; *s; s++)
731 if (strcmp(*s, str) == 0)
732 return 1;
733 return 0;
736 void list_codecs(int audioflag){
737 int i;
738 codecs_t *c;
740 if (audioflag) {
741 i = nr_acodecs;
742 c = audio_codecs;
743 mp_msg(MSGT_CODECCFG,MSGL_INFO,"ac: afm: status: info: [lib/dll]\n");
744 } else {
745 i = nr_vcodecs;
746 c = video_codecs;
747 mp_msg(MSGT_CODECCFG,MSGL_INFO,"vc: vfm: status: info: [lib/dll]\n");
749 if(!i) return;
750 for (/* NOTHING */; i--; c++) {
751 char* s="unknown ";
752 switch(c->status){
753 case CODECS_STATUS_WORKING: s="working ";break;
754 case CODECS_STATUS_PROBLEMS: s="problems";break;
755 case CODECS_STATUS_NOT_WORKING: s="crashing";break;
756 case CODECS_STATUS_UNTESTED: s="untested";break;
758 if(c->dll)
759 mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s %-9s %s %s [%s]\n",c->name,c->drv,s,c->info,c->dll);
760 else
761 mp_msg(MSGT_CODECCFG,MSGL_INFO,"%-11s %-9s %s %s\n",c->name,c->drv,s,c->info);