1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
/* codecs.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vdr/plugin.h>
#include "codecs.h"
#include "menu-vdrrip.h"
#include "a-tools.h"
#define MENCCMD "%s %s help 2>/dev/null"
#define VCODECS "lavc, xvid, divx4"
#define ACODECS "lame, copy, ogg-vorbis"
extern const char *MEncoder;
// --- cCodecs ------------------------------------------------------------
cCodecs::cCodecs() {
VCodecs = ACodecs = Containers = NULL;
queryCodecs((char *)VCODECS, (char *)ACODECS);
queryContainers();
}
cCodecs::~cCodecs() {
FREE(VCodecs);
FREE(ACodecs);
FREE(Containers);
}
void cCodecs::queryCodecs(char *v, char *a) {
char *buf = NULL, *cmd = NULL;
size_t i = 0;
int c, c1, nvc, nac;
// get number of codecs
nvc = strnumcol(v, ", ");
nac = strnumcol(a, ", ");
// reserve memory for arrays
VCodecs = (char**)malloc(nvc * sizeof(char*));
ACodecs = (char**)malloc(nac * sizeof(char*));
// read codecs in arryas
for (c = 0; c < nvc; c++) {
VCodecs[c] = strcol(v, ", ", c + 1);
}
for (c = 0; c < nac; c++) {
ACodecs[c] = strcol(a, ", ", c + 1);
}
// detect available video codecs with mencoder,
// move them to the beginning of the array and
// save the number of supported codecs in NumVCodecs
c1 = 0;
NumVCodecs = 0;
asprintf(&cmd, MENCCMD, MEncoder, "-ovc");
FILE *p = popen(cmd, "r");
if (p) {
while (getline(&buf, &i, p) != -1) {
for (c = c1; c < nvc; c++) {
if (strstr(buf, VCodecs[c])) {
// move found video codec to VCodecs[i1]
char *tmp = VCodecs[c1];
VCodecs[c1] = VCodecs[c];
VCodecs[c] = tmp;
c1++;
NumVCodecs++;
}
}
}
}
pclose(p);
FREE(cmd);
// detect available audio codecs with mencoder,
// move them to the beginning of the array and
// save the number of supported codecs in NumACodecs
c1 = 0;
NumACodecs = 0;
asprintf(&cmd, MENCCMD, MEncoder, "-oac");
p = popen(cmd, "r");
if (p) {
while (getline(&buf, &i, p) != -1) {
for (c = c1; c < nac; c++) {
if (strstr(buf, ACodecs[c])) {
// switch found audio codec with ACodecs[i1]
char *tmp = ACodecs[c1];
ACodecs[c1] = ACodecs[c];
ACodecs[c] = tmp;
c1++;
NumACodecs++;
}
}
}
}
pclose(p);
FREE(cmd);
if (VdrripSetup.OggVorbis == 1) {
ACodecs[NumACodecs] = strdup("ogg-vorbis");
NumACodecs++;
}
FREE(buf);
}
void cCodecs::queryContainers() {
NumContainers = 1;
int i = 1;
if (VdrripSetup.Ogm == 1) {NumContainers++;}
if (VdrripSetup.Matroska == 1) {NumContainers++;}
Containers = (char**)malloc(NumContainers * sizeof(char*));
Containers[0] = (char *)"avi";
if (VdrripSetup.Ogm == 1) {
Containers[i] = (char *)"ogm";
i++;}
if (VdrripSetup.Matroska == 1) {Containers[i] = (char *)"matroska";}
}
int cCodecs::getNumVCodecs() {return NumVCodecs;}
int cCodecs::getNumACodecs() {return NumACodecs;}
int cCodecs::getNumContainers() {return NumContainers;}
char **cCodecs::getVCodecs() {return VCodecs;}
char **cCodecs::getACodecs() {return ACodecs;}
char **cCodecs::getContainers() {return Containers;}
char *cCodecs::getVCodec(int i) {return VCodecs[i];}
char *cCodecs::getACodec(int i) {return ACodecs[i];}
char *cCodecs::getContainer(int i) {return Containers[i];}
int cCodecs::getNumVCodec(const char *v) {
int i = 0;
// check if there are video codecs available
if (NumVCodecs == 0) {
dsyslog("[vdrrip] fatal error: no video codec found !");
return -2;
}
while (strcmp(v, VCodecs[i]) != 0) {
i++;
if (i == NumVCodecs) {
dsyslog("[vdrrip] video codec %s not found !", v);
return -1;
}
}
return i;
}
int cCodecs::getNumACodec(const char *a) {
int i = 0;
// check if there are audio codecs available
if (NumACodecs == 0) {
dsyslog("[vdrrip] fatal error: no audio codec found !");
return -2;
}
while (strcmp(a, ACodecs[i]) != 0) {
i++;
if (i == NumACodecs) {
dsyslog("[vdrrip] audio codec %s not found !", a);
return -1;
}
}
return i;
}
int cCodecs::getNumContainer(const char *c) {
int i = 0;
while (strcmp(c, Containers[i]) != 0) {
i++;
if (i == NumContainers) {
dsyslog("[vdrrip] container %s not found !", c);
return -1;
}
}
return i;
}
|