summaryrefslogtreecommitdiff
path: root/src/combined/ffmpeg/mkcodeclist.pl
blob: c4070eb32f14ab045d679fd2b2a9ea7c718f5a7f (plain)
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
#! /usr/bin/perl -w

# Make codec lists for #inclusion by ff_*_decoder.c.
# Parameters:
#	list of ffmpeg CODEC_ID_* (pre-processed, one per line)
#	list of codecs recognised by xine-lib (see list for details)
#	output file name, or "-" to generate a report on unhandled codecs

my ($ffmpeg, $xine, $out) = @ARGV;
my $line;

# Read in the ffmpeg codec IDs
my %codecs;
open LIST, "< $ffmpeg" or die $!;
while (defined ($line = <LIST>)) {
  chomp $line;
  $line =~ s/^CODEC_ID_//o;
  $codecs{$line} = 0;
}
close LIST or die $!;

# Read in the xine-lib codec IDs
my %config;
my @known;
my $type = 'audio'; # default type
my $Type = 'AUDIO';
my ($a, $f, $t);
open LIST, "< $xine" or die $!;
while (defined ($line = <LIST>)) {
  next if substr ($line, 0, 1) eq '#' or $line =~ /^\s*$/o;
  chomp $line;
  if (substr ($line, 0, 5) eq 'type=') {
    # codec type; "FOO" in "BUF_FOO_BAR"
    $type = substr ($line, 5);
    $type =~ tr/A-Z/a-z/;
    $Type = $type;
    $Type =~ tr/a-z/A-Z/;
  } elsif (substr ($line, 0, 7) eq 'config=') { 
    # "#ifdef CONFIG_FOO_DECODER" mappings
    ($a, $f, $t) = split (/=/, $line, 3);
    $config{$f} = $t;
  } else {
    # codec details
    push @known, [split (/\s+/, $line, 3)];
  }
}
close LIST or die $!;

# Look through the mappings.
# Mark what we can handle and report on what the installed ffmpeg can't
foreach $line (@known) {
  if (defined $codecs{$line->[1]}) {
    ++$codecs{$line->[1]};
  } else {
    print "Ignored $line->[0] = $line->[1]\n";
  }
}

my $w = ($out ne '-');

if ($w) {
  # Write the C source code for the codec lists
  open LIST, "> $out" or die $!;
  print LIST "static const ff_codec_t ff_${type}_lookup[] = {\n" or die $!;
  foreach $line (@known) {
    next if $line->[0] eq '!';
    next unless defined $codecs{$line->[1]};
    print LIST "  { BUF_${Type}_$line->[0], CODEC_ID_$line->[1], \"$line->[2] (ffmpeg)\" },\n" or die $!;
  }
  print LIST "};\n\nstatic uint32_t supported_${type}_types[] = {\n" or die $!;
  foreach $line (@known) {
    next if $line->[0] eq '!';
    next unless defined $codecs{$line->[1]};
    $a = $line->[1];
    $a = $config{$a} if defined $config{$a};
    if ($a eq '') {
      print LIST "  BUF_${Type}_$line->[0],\n" or die $!;
    } else {
      print LIST "  #ifdef CONFIG_${a}_DECODER\n  BUF_${Type}_$line->[0],\n  #endif\n" or die $!;
    }
  }
  print LIST "  0,\n};\n" or die $!;
  close LIST or die $!;
}
else {
  # Report on ffmpeg codecs which we don't handle
  print "Unhandled $type codecs:\n";
  foreach $line (sort keys %codecs) {
    print "  $line\n" if $codecs{$line} == 0;
  }
}

exit 0;