~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to src/codecs.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-25 15:47:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080225154712-qvr11ekcea4c9ry8
Tags: 1.1.6-0.1ubuntu1
* Merge from debian-multimedia (LP: #120003), Ubuntu Changes:
 - For ffmpeg-related build-deps, remove cvs from package names.
 - Standards-Version 3.7.3
 - Maintainer Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * \file codecs.c
 
3
 *
 
4
 * This file contains all data types and functions related to video and audio
 
5
 * codecs and file formats.
 
6
 */
 
7
/*
 
8
 * Copyright (C) 2004-07 Karl, Frankfurt
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation; either version 2 of the License, or
 
13
 * (at your option) any later version.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
18
 * GNU General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with this program; if not, write to the Free Software
 
22
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
23
 */
 
24
 
 
25
#ifndef DOXYGEN_SHOULD_SKIP_THIS
 
26
#define DEBUGFILE "codecs.c"
 
27
 
 
28
#ifdef HAVE_CONFIG_H
 
29
#include <config.h>
 
30
#endif
 
31
#endif     // DOXYGEN_SHOULD_SKIP_THIS
 
32
 
 
33
#include <stdio.h>
 
34
#include <stdlib.h>
 
35
#ifdef SOLARIS
 
36
#include <strings.h>
 
37
#else      // SOLARIS
 
38
#include <string.h>
 
39
#endif     // SOLARIS
 
40
#include <ctype.h>
 
41
#include <libintl.h>
 
42
#include <math.h>
 
43
#include <locale.h>
 
44
 
 
45
#ifdef USE_FFMPEG
 
46
#include <ffmpeg/avcodec.h>
 
47
#include <ffmpeg/avformat.h>
 
48
#endif     // USE_FFMPEG
 
49
 
 
50
#include "app_data.h"
 
51
#include "codecs.h"
 
52
#include "xvidcap-intl.h"
 
53
 
 
54
/*
 
55
 * fps and fps_rage arrays for use in the codecs array
 
56
 */
 
57
static const XVC_FpsRange one_to_hundred_range[] = {
 
58
    {
 
59
     {1, 10},
 
60
     {100, 1}
 
61
     }
 
62
};
 
63
 
 
64
#define len_one_to_hundred_range (sizeof(one_to_hundred_range) / \
 
65
    sizeof(XVC_FpsRange))
 
66
 
 
67
static const XVC_FpsRange mpeg4_range[] = {
 
68
    {
 
69
     {75, 10},
 
70
     {30, 1}
 
71
     }
 
72
};
 
73
 
 
74
#define len_mpeg4_range (sizeof(mpeg4_range) / sizeof(XVC_FpsRange))
 
75
 
 
76
static const XVC_Fps mpeg1_fps[] = {
 
77
    {24000, 1001},
 
78
    {24, 1},
 
79
    {25, 1},
 
80
    {30000, 1001},
 
81
    {30, 1},
 
82
    {50, 1},
 
83
    {60000, 1001},
 
84
    {60, 1},
 
85
};
 
86
 
 
87
#define len_mpeg1_fps (sizeof(mpeg1_fps) / sizeof(XVC_Fps))
 
88
 
 
89
static const XVC_Fps dv_fps[] = {
 
90
    {25, 1},
 
91
    {30000, 1001},
 
92
};
 
93
 
 
94
#define len_dv_fps (sizeof(dv_fps) / sizeof(XVC_Fps))
 
95
 
 
96
/** \brief global array storing all available codecs */
 
97
const XVC_Codec xvc_codecs[NUMCODECS] = {
 
98
    {
 
99
     "NONE",
 
100
     N_("NONE"),
 
101
     CODEC_ID_NONE,
 
102
     {0, 1},
 
103
     NULL,
 
104
     0,
 
105
     NULL,
 
106
     0},
 
107
#ifdef USE_FFMPEG
 
108
    {
 
109
     "PGM",
 
110
     N_("Portable Graymap"),
 
111
     CODEC_ID_PGM,
 
112
     {24, 1},
 
113
     one_to_hundred_range,
 
114
     len_one_to_hundred_range,
 
115
     NULL,
 
116
     0},
 
117
    {
 
118
     "PPM",
 
119
     N_("Portable Pixmap"),
 
120
     CODEC_ID_PPM,
 
121
     {24, 1},
 
122
     one_to_hundred_range,
 
123
     len_one_to_hundred_range,
 
124
     NULL,
 
125
     0},
 
126
    {
 
127
     "PNG",
 
128
     N_("Portable Network Graphics"),
 
129
     CODEC_ID_PNG,
 
130
     {24, 1},
 
131
     one_to_hundred_range,
 
132
     len_one_to_hundred_range,
 
133
     NULL,
 
134
     0},
 
135
    {
 
136
     "JPEG",
 
137
     N_("Joint Picture Expert Group"),
 
138
     CODEC_ID_MJPEG,
 
139
     {24, 1},
 
140
     one_to_hundred_range,
 
141
     len_one_to_hundred_range,
 
142
     NULL,
 
143
     0},
 
144
    {
 
145
     "MPEG1",
 
146
     N_("MPEG 1"),
 
147
     CODEC_ID_MPEG1VIDEO,
 
148
     {24, 1},
 
149
     NULL,
 
150
     0,
 
151
     mpeg1_fps,
 
152
     len_mpeg1_fps},
 
153
    {
 
154
     "MJPEG",
 
155
     N_("MJPEG"),
 
156
     CODEC_ID_MJPEG,
 
157
     {24, 1},
 
158
     mpeg4_range,                      /* this is actually MPEG4 ... dunno if
 
159
                                        * this is the same here */
 
160
     len_mpeg4_range,
 
161
     NULL,
 
162
     0},
 
163
    {
 
164
     "MPEG4",
 
165
     N_("MPEG 4 (DIVX)"),
 
166
     CODEC_ID_MPEG4,
 
167
     {24, 1},
 
168
     mpeg4_range,
 
169
     len_mpeg4_range,
 
170
     NULL,
 
171
     0},
 
172
    {
 
173
     "MS_DIV2",
 
174
     N_("Microsoft DIVX 2"),
 
175
     CODEC_ID_MSMPEG4V2,
 
176
     {24, 1},
 
177
     mpeg4_range,                      /* this is actually MPEG4 ... dunno if
 
178
                                        * this is the same here */
 
179
     len_mpeg4_range,
 
180
     NULL,
 
181
     0},
 
182
    {
 
183
     "MS_DIV3",
 
184
     N_("Microsoft DIVX 3"),
 
185
     CODEC_ID_MSMPEG4V3,
 
186
     {24, 1},
 
187
     mpeg4_range,                      /* this is actually MPEG4 ... dunno if
 
188
                                        * this is the same here */
 
189
     len_mpeg4_range,
 
190
     NULL,
 
191
     0},
 
192
    {
 
193
     "FLASH_VIDEO",
 
194
     N_("Flash Video"),
 
195
     CODEC_ID_FLV1,
 
196
     {24, 1},
 
197
     mpeg4_range,                      /* this is actually MPEG4 ... dunno if
 
198
                                        * this is the same here */
 
199
     len_mpeg4_range,
 
200
     NULL,
 
201
     0},
 
202
    {
 
203
     "DV",
 
204
     N_("DV Video"),
 
205
     CODEC_ID_DVVIDEO,
 
206
     {25, 1},
 
207
     NULL,
 
208
     0,
 
209
     dv_fps,
 
210
     len_dv_fps},
 
211
    {
 
212
     "MPEG2",
 
213
     N_("MPEG2 Video"),
 
214
     CODEC_ID_MPEG2VIDEO,
 
215
     {24, 1},
 
216
     NULL,
 
217
     0,
 
218
     mpeg1_fps,
 
219
     len_mpeg1_fps},
 
220
#ifdef HAVE_LIBTHEORA
 
221
    {
 
222
     "THEORA",
 
223
     N_("Ogg Theora"),
 
224
     CODEC_ID_THEORA,
 
225
     {24, 1},
 
226
     mpeg4_range,                      /* this is actually MPEG4 ... dunno if
 
227
                                        * this is the same here */
 
228
     len_mpeg4_range,
 
229
     NULL,
 
230
     0},
 
231
#endif     // HAVE_LIBTHEORA
 
232
    {
 
233
     "SVQ1",
 
234
     N_("Soerensen VQ 1"),
 
235
     CODEC_ID_SVQ1,
 
236
     {24, 1},
 
237
     mpeg4_range,                      /* this is actually MPEG4 ... dunno if
 
238
                                        * this is the same here */
 
239
     len_mpeg4_range,
 
240
     NULL,
 
241
     0}
 
242
#endif     // USE_FFMPEG
 
243
};
 
244
 
 
245
/**
 
246
 * \brief global array storing all available audio codecs
 
247
 */
 
248
const XVC_AuCodec xvc_audio_codecs[NUMAUCODECS] = {
 
249
    {
 
250
     "NONE",
 
251
     N_("NONE"),
 
252
     CODEC_ID_NONE}
 
253
#ifdef USE_FFMPEG
 
254
#ifdef HAVE_FFMPEG_AUDIO
 
255
    , {
 
256
       "MP2",
 
257
       N_("MPEG2"),
 
258
       CODEC_ID_MP2}
 
259
#ifdef HAVE_LIBMP3LAME
 
260
    , {
 
261
       "MP3",
 
262
       N_("MPEG2 Layer 3"),
 
263
       CODEC_ID_MP3}
 
264
#endif     // HAVE_LIBMP3LAME
 
265
    , {
 
266
       "VORBIS",
 
267
       N_("Ogg Vorbis"),
 
268
       CODEC_ID_VORBIS}
 
269
    , {
 
270
       "PCM16",
 
271
       N_("PCM"),
 
272
       CODEC_ID_PCM_S16LE}
 
273
#endif     // HAVE_FFMPEG_AUDIO
 
274
#endif     // USE_FFMPEG
 
275
};
 
276
 
 
277
/*
 
278
 * arrays with extensions, allowed video and audio codecs for use in
 
279
 * the global xvc_formats array
 
280
 */
 
281
static const char *extension_xwd[] = { "xwd" };
 
282
 
 
283
#define len_extension_xwd (sizeof(extension_xwd) / sizeof(char*))
 
284
 
 
285
#ifdef USE_FFMPEG
 
286
static const char *extension_pgm[] = { "pgm" };
 
287
 
 
288
#define len_extension_pgm (sizeof(extension_pgm) / sizeof(char*))
 
289
 
 
290
static const char *extension_ppm[] = { "ppm" };
 
291
 
 
292
#define len_extension_ppm (sizeof(extension_ppm) / sizeof(char*))
 
293
 
 
294
static const char *extension_png[] = { "png" };
 
295
 
 
296
#define len_extension_png (sizeof(extension_png) / sizeof(char*))
 
297
 
 
298
static const char *extension_jpg[] = { "jpg", "jpeg" };
 
299
 
 
300
#define len_extension_jpg (sizeof(extension_jpg) / sizeof(char*))
 
301
 
 
302
static const char *extension_avi[] = { "avi" };
 
303
 
 
304
#define len_extension_avi (sizeof(extension_avi) / sizeof(char*))
 
305
 
 
306
static const char *extension_mpg[] = { "mpeg", "mpg" };
 
307
 
 
308
#define len_extension_mpg (sizeof(extension_mpg) / sizeof(char*))
 
309
 
 
310
static const char *extension_asf[] = { "asf" };
 
311
 
 
312
#define len_extension_asf (sizeof(extension_asf) / sizeof(char*))
 
313
 
 
314
static const char *extension_flv[] = { "flv", "flv1" };
 
315
 
 
316
#define len_extension_flv (sizeof(extension_flv) / sizeof(char*))
 
317
 
 
318
static const char *extension_swf[] = { "swf" };
 
319
 
 
320
#define len_extension_swf (sizeof(extension_swf) / sizeof(char*))
 
321
 
 
322
static const char *extension_dv[] = { "dv" };
 
323
 
 
324
#define len_extension_dv (sizeof(extension_dv) / sizeof(char*))
 
325
 
 
326
static const char *extension_m1v[] = { "m1v", "vcd" };
 
327
 
 
328
#define len_extension_m1v (sizeof(extension_m1v) / sizeof(char*))
 
329
 
 
330
static const char *extension_m2v[] = { "m2v", "svcd" };
 
331
 
 
332
#define len_extension_m2v (sizeof(extension_m2v) / sizeof(char*))
 
333
 
 
334
static const char *extension_mov[] = { "mov", "qt" };
 
335
 
 
336
#define len_extension_mov (sizeof(extension_mov) / sizeof(char*))
 
337
 
 
338
static const XVC_CodecID allowed_vid_codecs_pgm[] = { CODEC_PGM };
 
339
 
 
340
#define len_allowed_vid_codecs_pgm (sizeof(allowed_vid_codecs_pgm) / \
 
341
    sizeof(XVC_CodecID))
 
342
 
 
343
static const XVC_CodecID allowed_vid_codecs_ppm[] = { CODEC_PPM };
 
344
 
 
345
#define len_allowed_vid_codecs_ppm (sizeof(allowed_vid_codecs_ppm) / \
 
346
    sizeof(XVC_CodecID))
 
347
 
 
348
static const XVC_CodecID allowed_vid_codecs_png[] = { CODEC_PNG };
 
349
 
 
350
#define len_allowed_vid_codecs_png (sizeof(allowed_vid_codecs_png) / \
 
351
    sizeof(XVC_CodecID))
 
352
 
 
353
static const XVC_CodecID allowed_vid_codecs_jpg[] = { CODEC_JPEG };
 
354
 
 
355
#define len_allowed_vid_codecs_jpg (sizeof(allowed_vid_codecs_jpg) / \
 
356
    sizeof(XVC_CodecID))
 
357
 
 
358
static const XVC_CodecID allowed_vid_codecs_avi[] = {
 
359
    CODEC_MPEG1,
 
360
    CODEC_MJPEG,
 
361
    CODEC_MPEG4,
 
362
    CODEC_MSDIV2,
 
363
    CODEC_MPEG2,
 
364
#ifdef HAVE_LIBTHEORA
 
365
    CODEC_THEORA,
 
366
#endif     // HAVE_LIBTHEORA
 
367
    CODEC_DV
 
368
};
 
369
 
 
370
#define len_allowed_vid_codecs_avi (sizeof(allowed_vid_codecs_avi) / \
 
371
    sizeof(XVC_CodecID))
 
372
 
 
373
static const XVC_CodecID allowed_vid_codecs_asf[] = { CODEC_MSDIV3 };
 
374
 
 
375
#define len_allowed_vid_codecs_asf (sizeof(allowed_vid_codecs_asf) / \
 
376
    sizeof(XVC_CodecID))
 
377
 
 
378
static const XVC_CodecID allowed_vid_codecs_flv[] = { CODEC_FLV };
 
379
 
 
380
#define len_allowed_vid_codecs_flv (sizeof(allowed_vid_codecs_flv) / \
 
381
    sizeof(XVC_CodecID))
 
382
 
 
383
static const XVC_CodecID allowed_vid_codecs_swf[] = { CODEC_FLV, CODEC_MJPEG };
 
384
 
 
385
#define len_allowed_vid_codecs_swf (sizeof(allowed_vid_codecs_swf) / \
 
386
    sizeof(XVC_CodecID))
 
387
 
 
388
static const XVC_CodecID allowed_vid_codecs_dv[] = { CODEC_DV, CODEC_MJPEG };
 
389
 
 
390
#define len_allowed_vid_codecs_dv (sizeof(allowed_vid_codecs_dv) / \
 
391
    sizeof(XVC_CodecID))
 
392
 
 
393
static const XVC_CodecID allowed_vid_codecs_mpeg1[] = { CODEC_MPEG1 };
 
394
 
 
395
#define len_allowed_vid_codecs_mpeg1 (sizeof(allowed_vid_codecs_mpeg1) / \
 
396
    sizeof(XVC_CodecID))
 
397
 
 
398
static const XVC_CodecID allowed_vid_codecs_mpeg2[] = { CODEC_MPEG2 };
 
399
 
 
400
#define len_allowed_vid_codecs_mpeg2 (sizeof(allowed_vid_codecs_mpeg2) / \
 
401
    sizeof(XVC_CodecID))
 
402
 
 
403
static const XVC_CodecID allowed_vid_codecs_mov[] = {
 
404
    CODEC_MPEG4,
 
405
    CODEC_SVQ1,
 
406
    CODEC_DV
 
407
};
 
408
 
 
409
#define len_allowed_vid_codecs_mov (sizeof(allowed_vid_codecs_mov) / \
 
410
    sizeof(XVC_CodecID))
 
411
 
 
412
#ifdef HAVE_FFMPEG_AUDIO
 
413
static const XVC_AuCodecID allowed_au_codecs_avi[] = {
 
414
    AU_CODEC_MP2,
 
415
#ifdef HAVE_LIBMP3LAME
 
416
    AU_CODEC_MP3,
 
417
#endif     // HAVE_LIBMP3LAME
 
418
    AU_CODEC_VORBIS,
 
419
    AU_CODEC_PCM16
 
420
};
 
421
 
 
422
#define len_allowed_au_codecs_avi (sizeof(allowed_au_codecs_avi) / \
 
423
    sizeof(XVC_AuCodecID))
 
424
 
 
425
static const XVC_AuCodecID au_codecs_mp2_and_mp3[] = {
 
426
#ifdef HAVE_LIBMP3LAME
 
427
    AU_CODEC_MP3,
 
428
#endif     // HAVE_LIBMP3LAME
 
429
    AU_CODEC_MP2
 
430
};
 
431
 
 
432
#define len_au_codecs_mp2_and_mp3 (sizeof(au_codecs_mp2_and_mp3) / \
 
433
    sizeof(XVC_AuCodecID))
 
434
 
 
435
#ifdef HAVE_LIBMP3LAME
 
436
static const XVC_AuCodecID au_codecs_mp3[] = { AU_CODEC_MP3 };
 
437
 
 
438
#define len_au_codecs_mp3 (sizeof(au_codecs_mp3) / \
 
439
    sizeof(XVC_AuCodecID))
 
440
#endif     // HAVE_LIBMP3LAME
 
441
 
 
442
static const XVC_AuCodecID au_codecs_mp2_and_pcm[] = {
 
443
    AU_CODEC_MP2,
 
444
    AU_CODEC_PCM16
 
445
};
 
446
 
 
447
#define len_au_codecs_mp2_and_pcm (sizeof(au_codecs_mp2_and_pcm) / \
 
448
    sizeof(XVC_AuCodecID))
 
449
 
 
450
static const XVC_AuCodecID au_codecs_mp2[] = { AU_CODEC_MP2 };
 
451
 
 
452
#define len_au_codecs_mp2 (sizeof(au_codecs_mp2) / \
 
453
    sizeof(XVC_AuCodecID))
 
454
#endif     // HAVE_FFMPEG_AUDIO
 
455
#endif     // USE_FFMPEG
 
456
 
 
457
/**
 
458
 * \brief global array storing all available file formats
 
459
 */
 
460
const XVC_FFormat xvc_formats[NUMCAPS] = {
 
461
    {
 
462
     "NONE",
 
463
     N_("NONE"),
 
464
     NULL,
 
465
     CODEC_NONE,
 
466
     NULL,
 
467
     0,
 
468
     AU_CODEC_NONE,
 
469
     NULL,
 
470
     0,
 
471
     NULL,
 
472
     0},
 
473
    {
 
474
     "xwd",
 
475
     N_("X11 Window Dump"),
 
476
     NULL,
 
477
     CODEC_NONE,
 
478
     NULL,
 
479
     0,
 
480
     AU_CODEC_NONE,
 
481
     NULL,
 
482
     0,
 
483
     extension_xwd,
 
484
     len_extension_xwd}
 
485
#ifdef USE_FFMPEG
 
486
    , {
 
487
       "pgm",
 
488
       N_("Portable Graymap File"),
 
489
       NULL,
 
490
       CODEC_PGM,
 
491
       allowed_vid_codecs_pgm,
 
492
       len_allowed_vid_codecs_pgm,
 
493
       AU_CODEC_NONE,
 
494
       NULL,
 
495
       0,
 
496
       extension_pgm,
 
497
       len_extension_pgm},
 
498
    {
 
499
     "ppm",
 
500
     N_("Portable Anymap File"),
 
501
     NULL,
 
502
     CODEC_PPM,
 
503
     allowed_vid_codecs_ppm,
 
504
     len_allowed_vid_codecs_ppm,
 
505
     AU_CODEC_NONE,
 
506
     NULL,
 
507
     0,
 
508
     extension_ppm,
 
509
     len_extension_ppm},
 
510
    {
 
511
     "png",
 
512
     N_("Portable Network Graphics File"),
 
513
     NULL,
 
514
     CODEC_PNG,
 
515
     allowed_vid_codecs_png,
 
516
     len_allowed_vid_codecs_png,
 
517
     AU_CODEC_NONE,
 
518
     NULL,
 
519
     0,
 
520
     extension_png,
 
521
     len_extension_png},
 
522
    {
 
523
     "jpg",
 
524
     N_("Joint Picture Expert Group"),
 
525
     NULL,
 
526
     CODEC_JPEG,
 
527
     allowed_vid_codecs_jpg,
 
528
     len_allowed_vid_codecs_jpg,
 
529
     AU_CODEC_NONE,
 
530
     NULL,
 
531
     0,
 
532
     extension_jpg,
 
533
     len_extension_jpg},
 
534
    {
 
535
     "avi",
 
536
     N_("Microsoft Audio Video Interleaved File"),
 
537
     "avi",
 
538
     CODEC_MSDIV2,
 
539
     allowed_vid_codecs_avi,
 
540
     len_allowed_vid_codecs_avi,
 
541
#ifdef HAVE_FFMPEG_AUDIO
 
542
#ifdef HAVE_LIBMP3LAME
 
543
     AU_CODEC_MP3,
 
544
#else      // HAVE_LIBMP3LAME
 
545
     AU_CODEC_MP2,
 
546
#endif     // HAVE_LIBMP3LAME
 
547
     allowed_au_codecs_avi,
 
548
     len_allowed_au_codecs_avi,
 
549
#else      // HAVE_FFMPEG_AUDIO
 
550
     AU_CODEC_NONE,
 
551
     NULL,
 
552
     0,
 
553
#endif     // HAVE_FFMPEG_AUDIO
 
554
     extension_avi,
 
555
     len_extension_avi},
 
556
    {
 
557
     "divx",
 
558
     N_("General AVI file (DIVX default)"),
 
559
     "avi",
 
560
     CODEC_MPEG4,
 
561
     allowed_vid_codecs_avi,
 
562
     len_allowed_vid_codecs_avi,
 
563
#ifdef HAVE_FFMPEG_AUDIO
 
564
#ifdef HAVE_LIBMP3LAME
 
565
     AU_CODEC_MP3,
 
566
#else      // HAVE_LIBMP3LAME
 
567
     AU_CODEC_MP2,
 
568
#endif     // HAVE_LIBMP3LAME
 
569
     allowed_au_codecs_avi,
 
570
     len_allowed_au_codecs_avi,
 
571
#else      // HAVE_FFMPEG_AUDIO
 
572
     AU_CODEC_NONE,
 
573
     NULL,
 
574
     0,
 
575
#endif     // HAVE_FFMPEG_AUDIO
 
576
     extension_mpg,
 
577
     len_extension_mpg},
 
578
    {
 
579
     "asf",
 
580
     N_("Microsoft Advanced Streaming Format"),
 
581
     "asf",
 
582
     CODEC_MSDIV3,
 
583
     allowed_vid_codecs_asf,
 
584
     len_allowed_vid_codecs_asf,
 
585
     AU_CODEC_NONE,
 
586
#ifdef HAVE_FFMPEG_AUDIO
 
587
     au_codecs_mp2_and_mp3,
 
588
     len_au_codecs_mp2_and_mp3,
 
589
#else      // HAVE_FFMPEG_AUDIO
 
590
     NULL,
 
591
     0,
 
592
#endif     // HAVE_FFMPEG_AUDIO
 
593
     extension_asf,
 
594
     len_extension_asf},
 
595
    {
 
596
     "flv1",
 
597
     N_("Macromedia Flash Video Stream"),
 
598
     "flv",
 
599
     CODEC_FLV,
 
600
     allowed_vid_codecs_flv,
 
601
     len_allowed_vid_codecs_flv,
 
602
#ifdef HAVE_FFMPEG_AUDIO
 
603
#ifdef HAVE_LIBMP3LAME
 
604
     AU_CODEC_MP3,
 
605
     au_codecs_mp3,
 
606
     len_au_codecs_mp3,
 
607
#else      // HAVE_LIBMP3LAME
 
608
     AU_CODEC_NONE,
 
609
     NULL,
 
610
     0,
 
611
#endif     // HAVE_LIBMP3LAME
 
612
#else      // HAVE_FFMPEG_AUDIO
 
613
     AU_CODEC_NONE,
 
614
     NULL,
 
615
     0,
 
616
#endif     // HAVE_FFMPEG_AUDIO
 
617
     extension_flv,
 
618
     len_extension_flv},
 
619
    {
 
620
     "swf",
 
621
     N_("Macromedia Shockwave Flash File"),
 
622
     "swf",
 
623
     CODEC_FLV,
 
624
     allowed_vid_codecs_swf,
 
625
     len_allowed_vid_codecs_swf,
 
626
#ifdef HAVE_FFMPEG_AUDIO
 
627
#ifdef HAVE_LIBMP3LAME
 
628
     AU_CODEC_MP3,
 
629
     au_codecs_mp3,
 
630
     len_au_codecs_mp3,
 
631
#else      // HAVE_LIBMP3LAME
 
632
     AU_CODEC_NONE,
 
633
     NULL,
 
634
     0,
 
635
#endif     // HAVE_LIBMP3LAME
 
636
#else      // HAVE_FFMPEG_AUDIO
 
637
     AU_CODEC_NONE,
 
638
     NULL,
 
639
     0,
 
640
#endif     // HAVE_FFMPEG_AUDIO
 
641
     extension_swf,
 
642
     len_extension_swf},
 
643
    {
 
644
     "dv",
 
645
     N_("DV Video Format"),
 
646
     "dv",
 
647
     CODEC_DV,
 
648
     allowed_vid_codecs_dv,
 
649
     len_allowed_vid_codecs_dv,
 
650
#ifdef HAVE_FFMPEG_AUDIO
 
651
     AU_CODEC_MP2,
 
652
     au_codecs_mp2_and_pcm,
 
653
     len_au_codecs_mp2_and_pcm,
 
654
#else      // HAVE_FFMPEG_AUDIO
 
655
     AU_CODEC_NONE,
 
656
     NULL,
 
657
     0,
 
658
#endif     // HAVE_FFMPEG_AUDIO
 
659
     extension_dv,
 
660
     len_extension_dv},
 
661
    {
 
662
     "mpeg",
 
663
     N_("MPEG1 System Format"),
 
664
     "mpeg",
 
665
     CODEC_MPEG1,
 
666
     allowed_vid_codecs_mpeg1,
 
667
     len_allowed_vid_codecs_mpeg1,
 
668
#ifdef HAVE_FFMPEG_AUDIO
 
669
     AU_CODEC_MP2,
 
670
     au_codecs_mp2,
 
671
     len_au_codecs_mp2,
 
672
#else
 
673
     AU_CODEC_NONE,
 
674
     NULL,
 
675
     0,
 
676
#endif     // HAVE_FFMPEG_AUDIO
 
677
     extension_m1v,
 
678
     len_extension_m1v},
 
679
    {
 
680
     "mpeg2",
 
681
     N_("MPEG2 PS Format"),
 
682
     "svcd",
 
683
     CODEC_MPEG2,
 
684
     allowed_vid_codecs_mpeg2,
 
685
     len_allowed_vid_codecs_mpeg2,
 
686
#ifdef HAVE_FFMPEG_AUDIO
 
687
     AU_CODEC_MP2,
 
688
     au_codecs_mp2,
 
689
     len_au_codecs_mp2,
 
690
#else
 
691
     AU_CODEC_NONE,
 
692
     NULL,
 
693
     0,
 
694
#endif     // HAVE_FFMPEG_AUDIO
 
695
     extension_m2v,
 
696
     len_extension_m2v},
 
697
    {
 
698
     "mov",
 
699
     N_("Quicktime Format"),
 
700
     "mov",
 
701
     CODEC_MPEG4,
 
702
     allowed_vid_codecs_mov,
 
703
     len_allowed_vid_codecs_mov,
 
704
#ifdef HAVE_FFMPEG_AUDIO
 
705
     AU_CODEC_MP2,
 
706
     allowed_au_codecs_avi,
 
707
     len_allowed_au_codecs_avi,
 
708
#else      // HAVE_FFMPEG_AUDIO
 
709
     AU_CODEC_NONE,
 
710
     NULL,
 
711
     0,
 
712
#endif     // HAVE_FFMPEG_AUDIO
 
713
     extension_mov,
 
714
     len_extension_mov}
 
715
#endif     // USE_FFMPEG
 
716
};
 
717
 
 
718
/**
 
719
 * \brief finds libavcodec's codec id from xvidcap's
 
720
 *
 
721
 * @param xv_codec xvidcap's codec id
 
722
 * @return an integer codec id as understood by libavcodec. Since 0 is a valid
 
723
 *      codec id we return -1 on failure
 
724
 */
 
725
int
 
726
xvc_trans_codec (XVC_CodecID xv_codec)
 
727
{
 
728
    int ret = -1;
 
729
 
 
730
    if (xv_codec > 0 && xv_codec < NUMCODECS)
 
731
        ret = xvc_codecs[xv_codec].ffmpeg_id;
 
732
 
 
733
    return ret;
 
734
}
 
735
 
 
736
/**
 
737
 * \brief finds out if a codec is in the an array of valid video codec ids
 
738
 *      for a given format
 
739
 *
 
740
 * @param format the id of the format to check
 
741
 * @param codec the codec id to check for
 
742
 * @return 0 for not found, otherwise the position in the array where codec
 
743
 *      was found started at 1 (i. e. normal index + 1)
 
744
 */
 
745
int
 
746
xvc_is_valid_video_codec (XVC_FFormatID format, XVC_CodecID codec)
 
747
{
 
748
    int i = 0, found = 0;
 
749
 
 
750
    if (format < 0 || format >= NUMCAPS ||
 
751
        xvc_formats[format].num_allowed_vid_codecs == 0)
 
752
        return found;
 
753
    for (i = 0; i < xvc_formats[format].num_allowed_vid_codecs; i++) {
 
754
        if (xvc_formats[format].allowed_vid_codecs[i] == codec) {
 
755
            found = ++i;
 
756
            return found;
 
757
        }
 
758
    }
 
759
    return found;
 
760
}
 
761
 
 
762
/**
 
763
 * \brief finds out if an audio codec is in the an array of valid audio codec
 
764
 *      ids for a given format
 
765
 *
 
766
 * @param format the id of the format to check
 
767
 * @param codec the audio codec id to check for
 
768
 * @return 0 for not found, otherwise the position in the array where codec
 
769
 *      was found started at 1 (i. e. normal index + 1)
 
770
 */
 
771
int
 
772
xvc_is_valid_audio_codec (XVC_FFormatID format, XVC_AuCodecID codec)
 
773
{
 
774
    int i = 0;
 
775
    int found = 0;
 
776
 
 
777
    if (format < 0 || format >= NUMCAPS ||
 
778
        xvc_formats[format].num_allowed_au_codecs == 0)
 
779
        return found;
 
780
 
 
781
    for (i = 0; i < xvc_formats[format].num_allowed_au_codecs; i++) {
 
782
        if (xvc_formats[format].allowed_au_codecs[i] == codec) {
 
783
            found = ++i;
 
784
            return found;
 
785
        }
 
786
    }
 
787
    return found;
 
788
}
 
789
 
 
790
/**
 
791
 * \brief find target file format based on filename, i. e. the extension
 
792
 *
 
793
 * @param file a filename to test
 
794
 * @return the index number pointing to the array element for the format found
 
795
 *      in the global file xvc_formats array
 
796
 */
 
797
XVC_FFormatID
 
798
xvc_codec_get_target_from_filename (const char *file)
 
799
{
 
800
    char *ext = NULL;
 
801
    int ret = 0, i, i2;
 
802
 
 
803
    ext = rindex (file, '.');
 
804
    if (ext == NULL) {
 
805
        return ret;
 
806
    }
 
807
    ext++;
 
808
 
 
809
    for (i = 0; i < NUMCAPS; i++) {
 
810
        if (xvc_formats[i].extensions) {
 
811
            for (i2 = 0; i2 < xvc_formats[i].num_extensions; i2++) {
 
812
                if (strcasecmp (ext, xvc_formats[i].extensions[i2]) == 0) {
 
813
                    // then we have found the right extension in target n
 
814
                    ret = i;
 
815
                    return ret;
 
816
                }
 
817
            }
 
818
        }
 
819
    }
 
820
 
 
821
    return ret;
 
822
}
 
823
 
 
824
/**
 
825
 * \brief checks if fps rate is valid for given codec
 
826
 *
 
827
 * @param fps the fps rate to test
 
828
 * @param codec the codec to test the fps rate against specified as an index
 
829
 *      number pointing to a codec in the global codecs array
 
830
 * @param exact if 1 the function does an exact check, if 0 it will accept
 
831
 *      an fps value as valid, if there is a valid fps value that is
 
832
 *      not more than 0.01 larger or smaller than the fps given
 
833
 * @return 1 for fps is valid for given codec or 0 for not valid
 
834
 */
 
835
int
 
836
xvc_codec_is_valid_fps (XVC_Fps fps, XVC_CodecID codec, int exact)
 
837
{
 
838
#define DEBUGFUNCTION "xvc_codec_is_valid_fps()"
 
839
    int found = 0;
 
840
 
 
841
    if (xvc_codecs[codec].num_allowed_fps == 0 &&
 
842
        xvc_codecs[codec].num_allowed_fps_ranges == 0)
 
843
        return found;
 
844
 
 
845
    if (xvc_get_index_of_fps_array_element (xvc_codecs[codec].num_allowed_fps,
 
846
                                            xvc_codecs[codec].allowed_fps,
 
847
                                            fps, exact) >= 0) {
 
848
        found = 1;
 
849
        return found;
 
850
    }
 
851
 
 
852
    if (xvc_codecs[codec].num_allowed_fps_ranges != 0) {
 
853
        int i = 0;
 
854
 
 
855
        for (i = 0; i < xvc_codecs[codec].num_allowed_fps_ranges; i++) {
 
856
            XVC_FpsRange curr = xvc_codecs[codec].allowed_fps_ranges[i];
 
857
 
 
858
            if (XVC_FPS_GTE (fps, curr.start) && XVC_FPS_LTE (fps, curr.end)) {
 
859
                found = 1;
 
860
                return found;
 
861
            }
 
862
        }
 
863
    }
 
864
 
 
865
    return found;
 
866
#undef DEBUGFUNCTION
 
867
}
 
868
 
 
869
/**
 
870
 * \brief gets the index number of a given fps value from an array of fps
 
871
 *      values
 
872
 *
 
873
 * @param size the size of the array of fps values
 
874
 * @param haystack array of XVC_Fps values
 
875
 * @param needle the fps to search for
 
876
 * @param exact if 1 the function looks for an exact match, if 0 it will accept
 
877
 *      an fps value as matching, if there is a valid fps value that is
 
878
 *      not more than 0.01 larger or smaller than the fps given
 
879
 * @return the index number of the fps value in the array or -1 if not found
 
880
 */
 
881
int
 
882
xvc_get_index_of_fps_array_element (int size,
 
883
                                    const XVC_Fps * haystack,
 
884
                                    XVC_Fps needle, int exact)
 
885
{
 
886
    int i, found = -1;
 
887
 
 
888
    for (i = 0; i < size; i++) {
 
889
        if (XVC_FPS_EQUAL (haystack[i], needle)) {
 
890
            found = i;
 
891
            return found;
 
892
        }
 
893
    }
 
894
 
 
895
    if (!exact) {
 
896
        for (i = 0; i < size; i++) {
 
897
            double n, h;
 
898
 
 
899
            h = (double) haystack[i].num / (double) haystack[i].den;
 
900
            n = (double) needle.num / (double) needle.den;
 
901
            if (fabs (n - h) < 0.01) {
 
902
                found = i;
 
903
                return found;
 
904
            }
 
905
        }
 
906
    }
 
907
    return found;
 
908
}
 
909
 
 
910
/**
 
911
 * \brief reads a string and returns an fps value
 
912
 *
 
913
 * This accepts two forms of specifying an fps value: Either as a floating
 
914
 * point number with locale specific decimal point, or as a fraction like
 
915
 * "int/int"
 
916
 *
 
917
 * @param fps_string a string representation of an fps value
 
918
 * @return the fps value read from the string or { 0, 1}
 
919
 */
 
920
XVC_Fps
 
921
xvc_read_fps_from_string (char *fps_string)
 
922
{
 
923
    struct lconv *loc = localeconv ();
 
924
    XVC_Fps fps = { 0, 1 };
 
925
 
 
926
    if ((index (fps_string, '/') &&
 
927
         !strstr (fps_string, loc->decimal_point)) ||
 
928
        (index (fps_string, '/') && strstr (fps_string, loc->decimal_point) &&
 
929
         index (fps_string, '/') < strstr (fps_string, loc->decimal_point))
 
930
        ) {
 
931
        char *slash, *endptr;
 
932
 
 
933
        fps.num = strtol (fps_string, &endptr, 10);
 
934
        slash = index (fps_string, '/');
 
935
        slash++;
 
936
        fps.den = strtol (slash, &endptr, 10);
 
937
    } else {
 
938
        char *endptr = NULL;
 
939
 
 
940
        fps.num = (int) (strtod (fps_string, &endptr) * pow (10,
 
941
                                                             xvc_get_number_of_fraction_digits_from_float_string
 
942
                                                             (fps_string)) +
 
943
                         0.5);
 
944
        fps.den =
 
945
            (int) (pow
 
946
                   (10,
 
947
                    xvc_get_number_of_fraction_digits_from_float_string
 
948
                    (fps_string)) + 0.5);
 
949
    }
 
950
    return fps;
 
951
}