aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/codec_names.sh
blob: 44ccb45afebfe27b795af9e916ce7a62327509e3 (plain) (blame)
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
#!/bin/sh

# Copyright (c) 2011 Nicolas George
#
# This file is part of FFmpeg.
#
# FFmpeg is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# FFmpeg is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with FFmpeg; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

set -e

config="$1"
out="$2"
test -n "$out"

outval=""

add_line () {
  outval="$outval$*
"
}

parse_config_h () {
  while read define var value; do
    case "$define $var $value" in
      "#define CONFIG_"*_*" 1") eval "$var=1";;
    esac
  done
}

define_codecid () {
  id="$1"
  n=${1#AV_CODEC_ID_}
  add_line "case ${id}:"
  eval "c=\${CONFIG_${n}_DECODER}:\${CONFIG_${n}_ENCODER}"
  case "$c" in
    1:*) s="decoder";;
    *:1) s="encoder";;
    *) s="";;
  esac
  case "$s" in
    "") add_line "    return \"$n\";" ;;
    *)
      add_line "    { extern AVCodec ff_${n}_${s};"
      add_line "      return ff_${n}_${s}.name; }"
      ;;
  esac
}

parse_enum_codecid () {
  while read line; do
    case "$line" in
      "};") break;;
      *AV_CODEC_ID_FIRST*=*) ;;
      AV_CODEC_ID_*) define_codecid ${line%%[=,]*};;
    esac
  done
}

parse_avcodec_h () {
  while read line; do
    case "$line" in
      "enum AVCodecID {") parse_enum_codecid; break;;
    esac
  done
}

parse_config_h  < "$config"
parse_avcodec_h # use stdin
sed -e '/case.*:/!y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' \
    -e 's/extern avcodec /extern AVCodec /' > "$out" <<EOF
$outval
EOF