annotate codec-cfg.c @ 321:237b5f54bb78

flags seekable
author szabii
date Mon, 09 Apr 2001 21:28:44 +0000
parents 5427ff3e2e9d
children fc98b6c3a3dc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
1 /*
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
2 * codec.conf parser
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
3 * by Szabolcs Berecz <szabi@inf.elte.hu>
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
4 * (C) 2001
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
5 */
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
6
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
7 #define DEBUG
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
8
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
9 #ifdef DEBUG
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
10 #define DBG(str, args...) printf(str, ##args)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
11 #else
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
12 #define DBG(str, args...) do {} while (0)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
13 #endif
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
14
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
15 #define PRINT_LINENUM printf("%s(%d): ", cfgfile, line_num)
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
16
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
17 #include <stdio.h>
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
18 #include <stdlib.h>
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
19 #include <fcntl.h>
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
20 #include <unistd.h>
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
21 #include <errno.h>
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
22 #include <ctype.h>
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
23 #include <assert.h>
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
24 #include <string.h>
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
25
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
26 #include "libvo/video_out.h"
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
27 #include "codec-cfg.h"
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
28
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
29 #define MAX_NR_TOKEN 16
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
30
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
31 #define MAX_LINE_LEN 1000
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
32
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
33 #define STATE_MASK ((1<<7)-1)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
34
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
35 #define GOT_NAME (1<<0)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
36 #define GOT_INFO (1<<1)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
37 #define GOT_FOURCC (1<<2)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
38 #define GOT_FORMAT (1<<3)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
39 #define GOT_DRIVER (1<<4)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
40 #define GOT_DLL (1<<5)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
41 #define GOT_OUT (1<<6)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
42
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
43 #define RET_EOF -1
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
44 #define RET_EOL -2
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
45
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
46 static FILE *fp;
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
47 static int line_num = 0;
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
48 static int line_pos; /* line pos */
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
49 static char *line;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
50 static char *token[MAX_NR_TOKEN];
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
51
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
52 static codecs_t *codecs=NULL;
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
53 static int nr_codecs = 0;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
54
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
55 static int get_token(int min, int max)
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
56 {
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
57 static int read_nextline = 1;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
58 int i;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
59 char c;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
60
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
61 if (max >= MAX_NR_TOKEN) {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
62 printf("\nget_token(): max >= MAX_NR_TOKEN!\n");
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
63 goto ret_eof;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
64 }
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
65
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
66 memset(token, 0x00, sizeof(*token) * max);
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
67
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
68 if (read_nextline) {
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
69 if (!fgets(line, MAX_LINE_LEN, fp))
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
70 goto ret_eof;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
71 line_pos = 0;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
72 ++line_num;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
73 read_nextline = 0;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
74 }
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
75 for (i = 0; i < max; i++) {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
76 while (isspace(line[line_pos]))
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
77 ++line_pos;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
78 if (line[line_pos] == '\0' || line[line_pos] == '#' ||
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
79 line[line_pos] == ';') {
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
80 read_nextline = 1;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
81 if (i >= min)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
82 goto ret_ok;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
83 goto ret_eol;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
84 }
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
85 token[i] = line + line_pos;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
86 c = line[line_pos];
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
87 if (c == '"' || c == '\'') {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
88 token[i]++;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
89 while (line[++line_pos] != c && line[line_pos])
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
90 /* NOTHING */;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
91 } else {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
92 for (/* NOTHING */; !isspace(line[line_pos]) &&
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
93 line[line_pos]; line_pos++)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
94 /* NOTHING */;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
95 }
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
96 if (!line[line_pos]) {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
97 read_nextline = 1;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
98 if (i >= min - 1)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
99 goto ret_ok;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
100 goto ret_eol;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
101 }
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
102 line[line_pos] = '\0';
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
103 line_pos++;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
104 }
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
105 ret_ok:
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
106 return i;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
107 ret_eof:
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
108 return RET_EOF;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
109 ret_eol:
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
110 return RET_EOL;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
111 }
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
112
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
113 static int add_to_fourcc(char *s, char *alias, unsigned int *fourcc,
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
114 unsigned int *map)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
115 {
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
116 int i, j, freeslots;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
117 char **aliasp;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
118 unsigned int tmp;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
119
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
120 /* find first unused slot */
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
121 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
122 /* NOTHING */;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
123 freeslots = CODECS_MAX_FOURCC - i;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
124 if (!freeslots)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
125 goto too_many_error_out;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
126
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
127 aliasp = (alias) ? &alias : &s;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
128 do {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
129 tmp = *((unsigned int *) s);
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
130 for (j = 0; j < i; j++)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
131 if (tmp == fourcc[j])
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
132 goto duplicated_error_out;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
133 fourcc[i] = tmp;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
134 map[i] = *((unsigned int *) (*aliasp));
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
135 s += 4;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
136 i++;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
137 } while ((*(s++) == ',') && --freeslots);
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
138
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
139 if (!freeslots)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
140 goto too_many_error_out;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
141 if (*(--s) != '\0')
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
142 return 0;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
143 return 1;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
144 duplicated_error_out:
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
145 printf("\nduplicated fourcc/format\n");
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
146 return 0;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
147 too_many_error_out:
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
148 printf("\ntoo many fourcc/format...\n");
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
149 return 0;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
150 }
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
151
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
152 static int add_to_format(char *s, unsigned int *fourcc, unsigned int *fourccmap)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
153 {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
154 //printf("\n-----[%s][%s]-----\n",s,format);
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
155
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
156 int i, j;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
157
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
158 /* find first unused slot */
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
159 for (i = 0; i < CODECS_MAX_FOURCC && fourcc[i] != 0xffffffff; i++)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
160 /* NOTHING */;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
161 if (i == CODECS_MAX_FOURCC) {
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
162 printf("\ntoo many fourcc/format...\n");
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
163 return 0;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
164 }
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
165
300
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
166 fourcc[i]=fourccmap[i]=strtoul(s,NULL,0);
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
167 for (j = 0; j < i; j++)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
168 if (fourcc[j] == fourcc[i]) {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
169 printf("\nduplicated fourcc/format\n");
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
170 return 0;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
171 }
300
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
172
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
173 return 1;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
174 }
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
175
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
176
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
177 static int add_to_out(char *sfmt, char *sflags, unsigned int *outfmt,
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
178 unsigned char *outflags)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
179 {
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
180 static char *fmtstr[] = {
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
181 "YUY2",
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
182 "YV12",
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
183 "RGB8",
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
184 "RGB15",
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
185 "RGB16",
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
186 "RGB24",
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
187 "RGB32",
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
188 "BGR8",
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
189 "BGR15",
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
190 "BGR16",
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
191 "BGR24",
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
192 "BGR32",
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
193 NULL
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
194 };
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
195 static unsigned int fmtnum[] = {
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
196 IMGFMT_YUY2,
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
197 IMGFMT_YV12,
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
198 IMGFMT_RGB|8,
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
199 IMGFMT_RGB|15,
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
200 IMGFMT_RGB|16,
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
201 IMGFMT_RGB|24,
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
202 IMGFMT_RGB|32,
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
203 IMGFMT_BGR|8,
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
204 IMGFMT_BGR|15,
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
205 IMGFMT_BGR|16,
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
206 IMGFMT_BGR|24,
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
207 IMGFMT_BGR|32
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
208 };
299
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
209 static char *flagstr[] = {
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
210 "flip",
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
211 "noflip",
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
212 "yuvhack",
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
213 NULL
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
214 };
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
215
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
216 int i, j, freeslots;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
217 unsigned char flags;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
218
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
219 for (i = 0; i < CODECS_MAX_OUTFMT && outfmt[i] != 0xffffffff; i++)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
220 /* NOTHING */;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
221 freeslots = CODECS_MAX_OUTFMT - i;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
222 if (!freeslots)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
223 goto too_many_error_out;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
224
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
225 flags = 0;
299
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
226 if(sflags) do {
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
227 for (j = 0; flagstr[j] != NULL; j++)
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
228 if (!strncmp(sflags, flagstr[j], strlen(flagstr[j])))
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
229 break;
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
230 if (flagstr[j] == NULL) return 0; // error!
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
231 flags|=(1<<j);
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
232 sflags+=strlen(flagstr[j]);
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
233 } while (*(sflags++) == ',');
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
234
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
235 do {
299
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
236 for (j = 0; fmtstr[j] != NULL; j++)
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
237 if (!strncmp(sfmt, fmtstr[j], strlen(fmtstr[j])))
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
238 break;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
239 if (fmtstr[j] == NULL)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
240 return 0;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
241 outfmt[i] = fmtnum[j];
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
242 outflags[i] = flags;
299
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
243 ++i;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
244 sfmt+=strlen(fmtstr[j]);
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
245 } while ((*(sfmt++) == ',') && --freeslots);
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
246
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
247 if (!freeslots)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
248 goto too_many_error_out;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
249
299
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
250 if (*(--sfmt) != '\0') return 0;
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
251
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
252 return 1;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
253 too_many_error_out:
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
254 printf("\ntoo many out...\n");
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
255 return 0;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
256 }
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
257
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
258 static short get_driver(char *s,int audioflag)
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
259 {
301
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
260 static char *audiodrv[] = {
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
261 "mp3lib",
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
262 "pcm",
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
263 "libac3",
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
264 "acm",
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
265 "alaw",
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
266 "msgsm",
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
267 "dshow",
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
268 NULL
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
269 };
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
270 static char *videodrv[] = {
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
271 "libmpeg2",
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
272 "vfw",
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
273 "odivx",
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
274 "dshow",
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
275 NULL
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
276 };
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
277 char **drv=audioflag?audiodrv:videodrv;
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
278 int i;
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
279
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
280 for(i=0;drv[i];i++) if(!strcmp(s,drv[i])) return i+1;
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
281
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
282 return 0;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
283 }
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
284
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
285 static int valid_codec(codecs_t *codec)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
286 {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
287 #warning FIXME mi is kell egy codec-be?
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
288 return 1;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
289 }
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
290
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
291 static int add_comment(char *s, char **d)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
292 {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
293 int pos;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
294
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
295 if (!*d)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
296 pos = 0;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
297 else {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
298 pos = strlen(*d);
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
299 (*d)[pos++] = '\n';
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
300 }
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
301 if (!(*d = (char *) realloc(*d, pos + strlen(s) + 1))) {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
302 printf("can't allocate mem for comment\n");
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
303 return 0;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
304 }
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
305 strcpy(*d + pos, s);
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
306 return 1;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
307 }
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
308
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
309 codecs_t *parse_codec_cfg(char *cfgfile)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
310 {
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
311 codecs_t *codec = NULL; // current codec
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
312 int tmp, i;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
313 int state = 0;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
314
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
315 #ifdef DEBUG
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
316 assert(cfgfile != NULL);
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
317 #endif
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
318
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
319 printf("Reading codec config file: %s\n", cfgfile);
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
320
301
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
321 if ((fp = fopen(cfgfile, "r")) == NULL) {
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
322 printf("parse_codec_cfg: can't open '%s': %s\n", cfgfile, strerror(errno));
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
323 return NULL;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
324 }
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
325
301
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
326 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) {
c449b11e264d get_driver() implemented
arpi_esp
parents: 300
diff changeset
327 perror("parse_codec_cfg: can't get memory for 'line'");
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
328 return NULL;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
329 }
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
330
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
331 while ((tmp = get_token(1, 1)) != RET_EOF) {
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
332 if (tmp == RET_EOL)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
333 continue;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
334 if (!strcmp(token[0], "audiocodec") || !strcmp(token[0], "videocodec")) {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
335 if (nr_codecs)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
336 if (!valid_codec(codec))
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
337 goto not_valid_error_out;
300
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
338 if (!(codecs = (codecs_t *) realloc(codecs,
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
339 sizeof(codecs_t) * (nr_codecs + 1)))) {
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
340 perror("parse_codec_cfg: can't realloc 'codecs'");
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
341 goto err_out;
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
342 }
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
343 codec=&codecs[nr_codecs];
300
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
344 nr_codecs++;
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
345 memset(codec,0,sizeof(codecs_t));
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
346 memset(codec->fourcc, 0xff, sizeof(codec->fourcc));
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
347 memset(codec->outfmt, 0xff, sizeof(codec->outfmt));
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
348 state = 0;
300
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
349
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
350 if (*token[0] == 'a') { /* audiocodec */
300
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
351 codec->flags |= CODECS_FLAG_AUDIO;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
352 } else if (*token[0] == 'v') { /* videocodec */
300
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
353 codec->flags &= !CODECS_FLAG_AUDIO;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
354 } else {
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
355 printf("itt valami nagyon el van baszva\n");
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
356 goto err_out;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
357 }
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
358 if (get_token(1, 1) < 0)
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
359 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
360 for (i = 0; i < nr_codecs - 1; i++) {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
361 #warning audio meg videocodecnek lehet ugyanaz a neve?
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
362 if ((codec->flags & CODECS_FLAG_AUDIO) !=
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
363 (codecs[i].flags & CODECS_FLAG_AUDIO))
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
364 continue;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
365 if (!strcmp(token[0], codecs[i].name)) {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
366 PRINT_LINENUM;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
367 printf("codec name '%s' isn't unique\n", token[0]);
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
368 goto err_out;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
369 }
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
370 }
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
371 codec->name = strdup(token[0]);
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
372 state |= GOT_NAME;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
373 } else if (!strcmp(token[0], "info")) {
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
374 if (!(state & GOT_NAME))
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
375 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
376 if (state & GOT_INFO || get_token(1, 1) < 0)
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
377 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
378 codec->info = strdup(token[0]);
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
379 state |= GOT_INFO;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
380 } else if (!strcmp(token[0], "comment")) {
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
381 if (!(state & GOT_NAME))
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
382 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
383 if (get_token(1, 1) < 0)
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
384 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
385 if (!add_comment(token[0], &codec->comment)) {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
386 PRINT_LINENUM;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
387 printf("add_comment()-tel valami sux\n");
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
388 }
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
389 } else if (!strcmp(token[0], "fourcc")) {
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
390 if (!(state & GOT_NAME))
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
391 goto parse_error_out;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
392 if (get_token(1, 2) < 0)
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
393 goto parse_error_out;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
394 if (!add_to_fourcc(token[0], token[1],
300
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
395 codec->fourcc,
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
396 codec->fourccmap))
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
397 goto parse_error_out;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
398 state |= GOT_FOURCC;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
399 } else if (!strcmp(token[0], "format")) {
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
400 if (!(state & GOT_NAME))
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
401 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
402 if (get_token(1, 1) < 0)
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
403 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
404 if (!add_to_format(token[0], codec->fourcc,codec->fourccmap))
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
405 goto parse_error_out;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
406 state |= GOT_FORMAT;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
407 } else if (!strcmp(token[0], "driver")) {
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
408 if (!(state & GOT_NAME))
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
409 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
410 if (get_token(1, 1) < 0)
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
411 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
412 if ((codec->driver = get_driver(token[0],codec->flags&CODECS_FLAG_AUDIO)) == -1)
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
413 goto err_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
414 } else if (!strcmp(token[0], "dll")) {
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
415 if (!(state & GOT_NAME))
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
416 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
417 if (get_token(1, 1) < 0)
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
418 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
419 codec->dll = strdup(token[0]);
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
420 } else if (!strcmp(token[0], "guid")) {
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
421 if (!(state & GOT_NAME))
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
422 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
423 if (get_token(11, 11) < 0) goto parse_error_out;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
424 codec->guid.f1=strtoul(token[0],NULL,0);
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
425 codec->guid.f2=strtoul(token[1],NULL,0);
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
426 codec->guid.f3=strtoul(token[2],NULL,0);
300
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
427 for (i = 0; i < 8; i++) {
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
428 codec->guid.f4[i]=strtoul(token[i + 3],NULL,0);
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
429 }
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
430 } else if (!strcmp(token[0], "out")) {
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
431 if (!(state & GOT_NAME))
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
432 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
433 if (get_token(1, 2) < 0)
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
434 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
435 if (!add_to_out(token[0], token[1], codec->outfmt,
300
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
436 codec->outflags))
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
437 goto err_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
438 } else if (!strcmp(token[0], "flags")) {
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
439 if (!(state & GOT_NAME))
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
440 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
441 if (get_token(1, 1) < 0)
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
442 goto parse_error_out;
321
237b5f54bb78 flags seekable
szabii
parents: 320
diff changeset
443 if (!strcmp(token[0], "seekable"))
237b5f54bb78 flags seekable
szabii
parents: 320
diff changeset
444 codec->flags |= CODECS_FLAG_SEEKABLE;
237b5f54bb78 flags seekable
szabii
parents: 320
diff changeset
445 else
237b5f54bb78 flags seekable
szabii
parents: 320
diff changeset
446 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
447 } else if (!strcmp(token[0], "status")) {
316
589a93489054 status added
szabii
parents: 303
diff changeset
448 if (!(state & GOT_NAME))
589a93489054 status added
szabii
parents: 303
diff changeset
449 goto parse_error_out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
450 if (get_token(1, 1) < 0)
316
589a93489054 status added
szabii
parents: 303
diff changeset
451 goto parse_error_out;
320
szabii
parents: 319
diff changeset
452 if (!strcasecmp(token[0], ":-)"))
316
589a93489054 status added
szabii
parents: 303
diff changeset
453 codec->status = CODECS_STATUS_WORKING;
320
szabii
parents: 319
diff changeset
454 else if (!strcasecmp(token[0], ":-("))
316
589a93489054 status added
szabii
parents: 303
diff changeset
455 codec->status = CODECS_STATUS_NOT_WORKING;
320
szabii
parents: 319
diff changeset
456 else if (!strcasecmp(token[0], "X-("))
316
589a93489054 status added
szabii
parents: 303
diff changeset
457 codec->status = CODECS_STATUS_UNTESTED;
320
szabii
parents: 319
diff changeset
458 else if (!strcasecmp(token[0], ":-|"))
316
589a93489054 status added
szabii
parents: 303
diff changeset
459 codec->status = CODECS_STATUS_PROBLEMS;
589a93489054 status added
szabii
parents: 303
diff changeset
460 else
589a93489054 status added
szabii
parents: 303
diff changeset
461 goto parse_error_out;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
462 } else
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
463 goto parse_error_out;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
464 }
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
465 if (!valid_codec(codec))
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
466 goto not_valid_error_out;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
467 out:
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
468 free(line);
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
469 fclose(fp);
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
470 return codecs;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
471 parse_error_out:
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
472 PRINT_LINENUM;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
473 printf("parse error\n");
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
474 err_out:
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
475 printf("\nOops\n");
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
476 if (codecs)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
477 free(codecs);
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
478 codecs = NULL;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
479 goto out;
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
480 not_valid_error_out:
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
481 PRINT_LINENUM;
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
482 printf("codec is not definied correctly\n");
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
483 goto err_out;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
484 }
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
485
303
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
486 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap,int audioflag){
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
487 int i,j;
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
488 for(i=0;i<nr_codecs;i++){
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
489 codecs_t *c=&codecs[i];
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
490 if(!audioflag && (c->flags&CODECS_FLAG_AUDIO)) continue;
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
491 if(audioflag && !(c->flags&CODECS_FLAG_AUDIO)) continue;
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
492 for(j=0;j<CODECS_MAX_FOURCC;j++){
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
493 if(c->fourcc[j]==fourcc){
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
494 if(fourccmap) *fourccmap=c->fourccmap[j];
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
495 return c;
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
496 }
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
497 }
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
498 }
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
499 return NULL;
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
500 }
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
501
828ec81e0d64 codecs.conf support
arpi_esp
parents: 301
diff changeset
502
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
503 #ifdef TESTING
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
504 int main(void)
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
505 {
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
506 codecs_t *codecs;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
507 int i,j;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
508
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
509 if (!(codecs = parse_codec_cfg("DOCS/codecs.conf")))
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
510 return 0;
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
511
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
512 printf("total %d codecs parsed\n",nr_codecs);
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
513 for(i=0;i<nr_codecs;i++){
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
514 codecs_t *c=&codecs[i];
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
515 printf("\n============== codec %02d ===============\n",i);
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
516 printf("name='%s'\n",c->name);
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
517 printf("info='%s'\n",c->info);
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
518 printf("comment='%s'\n",c->comment);
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
519 printf("dll='%s'\n",c->dll);
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
520 printf("flags=%X driver=%d\n",c->flags,c->driver);
300
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
521
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
522 for(j=0;j<CODECS_MAX_FOURCC;j++){
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
523 if(c->fourcc[j]!=0xFFFFFFFF){
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
524 printf("fourcc %02d: %08X (%.4s) ===> %08X (%.4s)\n",j,c->fourcc[j],&c->fourcc[j],c->fourccmap[j],&c->fourccmap[j]);
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
525 }
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
526 }
300
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
527
299
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
528 for(j=0;j<CODECS_MAX_OUTFMT;j++){
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
529 if(c->outfmt[j]!=0xFFFFFFFF){
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
530 printf("outfmt %02d: %08X (%.4s) flags: %d\n",j,c->outfmt[j],&c->outfmt[j],c->outflags[j]);
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
531 }
3343fb3e4f49 outflags[] reading fixed
arpi_esp
parents: 298
diff changeset
532 }
300
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
533
319
6472ab2051c7 lots of changes
szabii
parents: 316
diff changeset
534 printf("GUID: %08lX %04X %04X",c->guid.f1,c->guid.f2,c->guid.f3);
300
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
535 for(j=0;j<8;j++) printf(" %02X",c->guid.f4[j]);
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
536 printf("\n");
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
537
df3f7a25584c audio format support, realloc() cleanup
arpi_esp
parents: 299
diff changeset
538
297
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
539 }
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
540
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
541 return 0;
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
542 }
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
543
9b00ddddc0b2 imported codec-cfg, small fixes
arpi_esp
parents:
diff changeset
544 #endif