]> git.sesse.net Git - ffmpeg/blob - libavcodec/codec_names.sh
Merge remote-tracking branch 'mans/ac3'
[ffmpeg] / libavcodec / codec_names.sh
1 #!/bin/sh
2
3 # Copyright (c) 2011 Nicolas George
4 #
5 # This file is part of FFmpeg.
6 #
7 # FFmpeg is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # FFmpeg is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with FFmpeg; if not, write to the Free Software Foundation,
19 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
21 set -e
22
23 config="$1"
24 codecs="$2"
25 out="$3"
26 test -n "$out"
27
28 outval=""
29
30 add_line () {
31   outval="$outval$*
32 "
33 }
34
35 parse_config_h () {
36   while read define var value; do
37     case "$define $var $value" in
38       "#define CONFIG_"*_*" 1") eval "$var=1";;
39     esac
40   done
41 }
42
43 define_codecid () {
44   id="$1"
45   n=${1#CODEC_ID_}
46   add_line "case ${id}:"
47   eval "c=\${CONFIG_${n}_DECODER}:\${CONFIG_${n}_ENCODER}"
48   case "$c" in
49     1:*) s="decoder";;
50     *:1) s="encoder";;
51     *) s="";;
52   esac
53   case "$s" in
54     "") add_line "    return \"$n\";" ;;
55     *)
56       add_line "    { extern AVCodec ff_${n}_${s};"
57       add_line "      return ff_${n}_${s}.name; }"
58       ;;
59   esac
60 }
61
62 parse_enum_codecid () {
63   while read line; do
64     case "$line" in
65       "};") break;;
66       *CODEC_ID_FIRST*///*dummy*) ;;
67       CODEC_ID_*) define_codecid ${line%%[=,]*};;
68     esac
69   done
70 }
71
72 parse_avcodec_h () {
73   while read line; do
74     case "$line" in
75       "enum CodecID {") parse_enum_codecid; break;;
76     esac
77   done
78 }
79
80 parse_config_h  < "$config"
81 parse_avcodec_h < "$codecs"
82 sed -e '/case.*:/!y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' \
83     -e 's/extern avcodec /extern AVCodec /' > "$out" <<EOF
84 $outval
85 EOF