Debian Codegraph @

encodedv/insert_audio.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * insert_audio.c
3 *
4 * Copyright (C) Peter Schlaile - January 2001
5 *
6 * This file is part of libdv, a free DV (IEC 61834/SMPTE 314M)
7 * codec.
8 *
9 * libdv is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser Public License as published by
11 * the Free Software Foundation; either version 2.1, or (at your
12 * option) any later version.
13 *
14 * libdv is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser Public License
20 * along with libdv; see the file COPYING. If not, write to
21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 * The libdv homepage is http://libdv.sourceforge.net/.
24 */
25
•26 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:412:9`!
27 #include <config.h>cxx . . $ `<file>/config.h`/
28 #endif
29
30 #include "libdv/dv_types.h"cxx . . $ `<file>/libdv/dv_types.h`/
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <string.h>
36 #include <assert.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <fcntl.h>
40 #include <time.h>
41
42 #include <libdv/headers.h>cxx . . $ `<file>/libdv/headers.h`/
43 #include <libdv/enc_audio_input.h>cxx . . $ `<file>/libdv/enc_audio_input.h`/
44 #include <libdv/enc_input.h>cxx . . $ `<file>/libdv/enc_input.h`/
45 #include <libdv/enc_output.h>cxx . . $ `<file>/libdv/enc_output.h`/
46
47 void generate_empty_framecxx . . $ generate_empty_frame(fc0f0e1646c32816).(unsigned char* frame_buf, int isPAL)
48 {
49 static time_tcxx . . $ time_t# t = 0;
50 static int frame_count = -1;
51 if (!t) {
52 t = timecxx . . $ time(7f38134db6521d23).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
53 }
54 if (frame_count == -1) {
55 frame_count = isPAL ? 25 : 30;
56 }
57 if (!--frame_count) {
58 frame_count = isPAL ? 25 : 30;
59 t++;
60 }
61 memsetcxx . . $ memset(d1de1e4fb215f1c6).(frame_buf, 0, isPAL ? 144000 : 120000);
62 _dv_write_meta_datacxx . . $ _dv_write_meta_data(d8030c255064409a).(frame_buf, 0, isPAL, 0, &t);
63 }
64
65 int read_framecxx . . $ read_frame(319757e74fda37e9).(FILEcxx . . $ FILE#* in_vid, unsigned char* frame_buf, int * isPAL)
66 {
67 if (freadcxx . . $ fread(738fc8ac1d711e58).(frame_buf, 1, 120000, in_vid) != 120000) {
68 generate_empty_framecxx . . $ generate_empty_frame(fc0f0e1646c32816).(frame_buf, *isPAL);
69 return 0;
70 }
71
72 *isPAL = (frame_buf[3] & 0x80);
73
74 if (*isPAL) {
75 if (freadcxx . . $ fread(738fc8ac1d711e58).(frame_buf + 120000, 1, 144000 - 120000, in_vid) !=
76 144000 - 120000) {
77 generate_empty_framecxx . . $ generate_empty_frame(fc0f0e1646c32816).(frame_buf, *isPAL);
78 return 0;
79 }
80 }
81 return 1;
82 }
83
84 #define OPT_VERSIONcxx . . $ `encodedv/insert_audio.c:84:9`! 0
85 #define OPT_VERBOSEcxx . . $ `encodedv/insert_audio.c:85:9`! 1
86 #define OPT_AUDIO_INPUTcxx . . $ `encodedv/insert_audio.c:86:9`! 2
87 #define OPT_OUTPUTcxx . . $ `encodedv/insert_audio.c:87:9`! 3
88 #define OPT_TRUNCATEcxx . . $ `encodedv/insert_audio.c:88:9`! 4
89 #define OPT_REPEATcxx . . $ `encodedv/insert_audio.c:89:9`! 5
90 #define OPT_AUTOHELPcxx . . $ `encodedv/insert_audio.c:90:9`! 6
91 #define NUM_OPTScxx . . $ `encodedv/insert_audio.c:91:9`! 7
92
93 int maincxx . . $ main(d8e43b79a186046c).(int argc, const char** argv)
94 {
95 FILEcxx . . $ FILE#* in_vid;
96
97 const char* filename = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
98 const char* audio_filename = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
99
100 unsigned char frame_buf[144000];
101 int isPAL = 1;
102 int gotframe = 0;
103 int have_pipes = 0;
104 int verbose_mode = 0;
105 int truncate_mode = 0;
106 int repeat_count = 0;
107 int count;
108 const char* audio_input_filter_str = "wav";
109 const char* output_filter_str = "raw";
110
111 dv_enc_audio_info_tcxx . . $ dv_enc_audio_info_t# audio_info_;
112 dv_enc_audio_info_tcxx . . $ dv_enc_audio_info_t#* audio_info;
113
114 dv_enc_audio_input_filter_tcxx . . $ dv_enc_audio_input_filter_t# * audio_input_filter;
115 dv_enc_output_filter_tcxx . . $ dv_enc_output_filter_t# * output_filter;
116
117 time_tcxx . . $ time_t# now;
118
119 #if HAVE_LIBPOPTcxx . . $ `config.h:38:9`!
120 struct poptOptioncxx . . $ poptOption# option_table[NUM_OPTScxx . . $ `encodedv/insert_audio.c:91:9`!+1];
121 int rc; /* return code from popt */
122 poptContextcxx . . $ poptContext# optCon; /* context for parsing command-line options */
123 option_table[OPT_VERSIONcxx . . $ `encodedv/insert_audio.c:84:9`!] = (struct poptOptioncxx . . $ poptOption#) {
124 longName: "version",
125 val: 'v',
126 descrip: "show dubdv version number"
127 }; /* version */
128
129 option_table[OPT_VERBOSEcxx . . $ `encodedv/insert_audio.c:85:9`!] = (struct poptOptioncxx . . $ poptOption#) {
130 longName: "verbose",
131 shortName: 'v',
132 arg: &verbose_mode,
133 descrip: "show encoder statistics / status information"
134 }; /* verbose mode */
135
136 option_table[OPT_AUDIO_INPUTcxx . . $ `encodedv/insert_audio.c:86:9`!] = (struct poptOptioncxx . . $ poptOption#) {
137 longName: "audio-input",
138 shortName: 'a',
139 arg: &audio_input_filter_str,
140 argInfo: POPT_ARG_STRINGcxx . . $ `<external>/16232926639102580118/popt.h:19:9`!,
141 descrip: "choose audio-input-filter [none, >wav<, dsp]"
142 }; /* audio input */
143
144 option_table[OPT_OUTPUTcxx . . $ `encodedv/insert_audio.c:87:9`!] = (struct poptOptioncxx . . $ poptOption#) {
145 longName: "output",
146 shortName: 'o',
147 arg: &output_filter_str,
148 argInfo: POPT_ARG_STRINGcxx . . $ `<external>/16232926639102580118/popt.h:19:9`!,
149 descrip: "choose output-filter [>raw<]"
150 }; /* output */
151
152 option_table[OPT_TRUNCATEcxx . . $ `encodedv/insert_audio.c:88:9`!] = (struct poptOptioncxx . . $ poptOption#) {
153 longName: "truncate",
154 shortName: 't',
155 arg: &truncate_mode,
156 descrip: "truncate output at end of input"
157 }; /* truncate */
158
159 option_table[OPT_REPEATcxx . . $ `encodedv/insert_audio.c:89:9`!] = (struct poptOptioncxx . . $ poptOption#) {
160 longName: "repeat",
161 shortName: 'r',
162 arg: &repeat_count,
163 argInfo: POPT_ARG_INTcxx . . $ `<external>/16232926639102580118/popt.h:20:9`!,
164 descrip: "repeat the first video frame this many times"
165 }; /* repeat */
166
167 option_table[OPT_AUTOHELPcxx . . $ `encodedv/insert_audio.c:90:9`!] = (struct poptOptioncxx . . $ poptOption#) {
168 argInfo: POPT_ARG_INCLUDE_TABLEcxx . . $ `<external>/16232926639102580118/popt.h:22:9`!,
169 arg: poptHelpOptionscxx . . $ poptHelpOptions.,
170 descrip: "Help options",
171 }; /* autohelp */
172
173 option_table[NUM_OPTScxx . . $ `encodedv/insert_audio.c:91:9`!] = (struct poptOptioncxx . . $ poptOption#) {
174 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0 };
175
176 optCon = poptGetContextcxx . . $ poptGetContext(69e83c0752e8078).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, argc,
177 (const char **)argv, option_table, 0);
178 poptSetOtherOptionHelpcxx . . $ poptSetOtherOptionHelp(fc627e009555550b).(optCon,
179 "<audio input> "
180 "[<filename or - for stdin>]");
181
182 while ((rc = poptGetNextOptcxx . . $ poptGetNextOpt(8c14591e39307bbe).(optCon)) > 0) {
183 switch (rc) {
184 case 'v':
185 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"insert_audio: version 0.0.2 "
186 "http://libdv.sourceforge.net/\n");
187 exitcxx . . $ exit(3ca292c338df9bb3).(0);
188 break;
189 default:
190 break;
191 } /* switch */
192 } /* while */
193
194 if (rc < -1) {
195 /* an error occurred during option processing */
196 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: %s\n",
197 poptBadOptioncxx . . $ poptBadOption(abdebb552147fd6f).(optCon, POPT_BADOPTION_NOALIAScxx . . $ `<external>/16232926639102580118/popt.h:99:9`!),
198 poptStrerrorcxx . . $ poptStrerror(f7ae7e56280f18ae).(rc));
199 exitcxx . . $ exit(3ca292c338df9bb3).(-1);
200 }
201
202 audio_filename = poptGetArgcxx . . $ poptGetArg(86c70cf25448eb00).(optCon);
203 if(audio_filename == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
204 poptPrintUsagecxx . . $ poptPrintUsage(692800addc75c9c3).(optCon, stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, 0);
205 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,
206 "\nYou have to specify at least a audio input file\n");
207 exitcxx . . $ exit(3ca292c338df9bb3).(-1);
208 }
209 filename = poptGetArgcxx . . $ poptGetArg(86c70cf25448eb00).(optCon);
210 poptFreeContextcxx . . $ poptFreeContext(c32b9b4db48a8347).(optCon);
211
212 #else
213 #warning dubdv does not work without libpopt!
214
215 #endif
216
217 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(audio_input_filter_str, "none") != 0) {
218 dv_enc_get_audio_input_filterscxx . . $ dv_enc_get_audio_input_filters(e7e97791f7a919ae).(&audio_input_filter, &count);
219 while (count
220 && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(audio_input_filter->filter_namecxx . . $ dv_audio_enc_input_filter_s#filter_name.,
221 audio_input_filter_str) != 0) {
222 audio_input_filter++;
223 count--;
224 }
225 if (!count) {
226 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,
227 "Unknown audio input filter selected: %s!\n"
228 "The following filters are supported:\n",
229 audio_input_filter_str);
230 dv_enc_get_audio_input_filterscxx . . $ dv_enc_get_audio_input_filters(e7e97791f7a919ae).(&audio_input_filter,
231 &count);
232 while (count--) {
233 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s\n",
234 audio_input_filter->filter_namecxx . . $ dv_audio_enc_input_filter_s#filter_name.);
235 audio_input_filter++;
236 }
237 return(-1);
238 }
239 if (!audio_filename) {
240 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Audio input selected but no filename "
241 "or device given!\n");
242 return(-1);
243 }
244 }
245
246 dv_enc_get_output_filterscxx . . $ dv_enc_get_output_filters(42011b2491d6e6ad).(&output_filter, &count);
247 while (count &&
248 strcmpcxx . . $ strcmp(5ae29d726ae57f88).(output_filter->filter_namecxx . . $ dv_enc_output_filter_s#filter_name., output_filter_str) != 0) {
249 output_filter++;
250 count--;
251 }
252 if (!count) {
253 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Unknown output filter selected: %s!\n"
254 "The following filters are supported:\n",
255 output_filter_str);
256 dv_enc_get_output_filterscxx . . $ dv_enc_get_output_filters(42011b2491d6e6ad).(&output_filter, &count);
257 while (count--) {
258 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s\n", output_filter->filter_namecxx . . $ dv_enc_output_filter_s#filter_name.);
259 output_filter++;
260 }
261 return(-1);
262 }
263
264 audio_info = &audio_info_;
265 if (audio_input_filter->initcxx . . $ dv_audio_enc_input_filter_s#init.(audio_filename, audio_info) != 0) {
266 return(-1);
267 }
268 if (verbose_mode) {
269 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Opening audio source with:\n"
270 "Channels: %d\n"
271 "Frequency: %d\n"
272 "Bytes per second: %d\n"
273 "Byte alignment: %d\n"
274 "Bits per sample: %d\n",
275 audio_info->channelscxx . . $ dv_enc_audio_info_s#channels., audio_info->frequencycxx . . $ dv_enc_audio_info_s#frequency.,
276 audio_info->bytespersecondcxx . . $ dv_enc_audio_info_s#bytespersecond.,
277 audio_info->bytealignmentcxx . . $ dv_enc_audio_info_s#bytealignment.,
278 audio_info->bitspersamplecxx . . $ dv_enc_audio_info_s#bitspersample.);
279 }
280
281 have_pipes = (filename == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! || strcmpcxx . . $ strcmp(5ae29d726ae57f88).(filename, "-") == 0);
282
283 if (have_pipes) {
284 if (output_filter->initcxx . . $ dv_enc_output_filter_s#init.(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!) != 0) {
285 return -1;
286 }
287 in_vid = stdincxx . . $ `<external>/232824719582829767/stdio.h:157:9`!;
288 } else {
289 FILEcxx . . $ FILE#* out_vid = fopencxx . . $ fopen(82ec0787cd37e0a3).(filename, "r+");
290 in_vid = fopencxx . . $ fopen(82ec0787cd37e0a3).(filename, "r");
291 if (output_filter->initcxx . . $ dv_enc_output_filter_s#init.(out_vid) != 0) {
292 return -1;
293 }
294
295 }
296
297 now = timecxx . . $ time(7f38134db6521d23).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
298
299 /* repeat the first frame if needed */
300 gotframe = read_framecxx . . $ read_frame(319757e74fda37e9).(in_vid, frame_buf, &isPAL);
301 if (gotframe)
302 while (repeat_count--)
303 if (output_filter->storecxx . . $ dv_enc_output_filter_s#store.(frame_buf, audio_info, 1,
304 isPAL, 0, now) != 0)
305 return -1;
306
307 for (;;) {
308 if (!gotframe && truncate_mode)
309 return 0; /* truncate audio at end of video */
310
311 if (audio_input_filter->loadcxx . . $ dv_audio_enc_input_filter_s#load.(audio_info, isPAL) != 0) {
312 /* end of audio stream */
313 if (!truncate_mode) {
314 /* copy the rest with original audio */
315 while (gotframe) {
316 fwritecxx . . $ fwrite(ab0609fa07c47d6e).(frame_buf, 1,
317 isPAL ? 144000 : 120000,
318 stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!);
319 gotframe = read_framecxx . . $ read_frame(319757e74fda37e9).(
320 in_vid, frame_buf, &isPAL);
321 }
322 }
323 return 0;
324 }
325 if (output_filter->storecxx . . $ dv_enc_output_filter_s#store.(frame_buf, audio_info, 1,
326 isPAL, 0, now) != 0) {
327 return -1;
328 }
329 gotframe = read_framecxx . . $ read_frame(319757e74fda37e9).(in_vid, frame_buf, &isPAL);
330 }
331 }
332
333
334
335