Revision d8d12c15

View differences:

Changelog
137 137
- E-AC-3 support added to AC-3 decoder
138 138
- Nellymoser ASAO encoder
139 139
- ASS and SSA demuxer and muxer
140
- liba52 wrapper removed
140 141

  
141 142
version 0.4.9-pre1:
142 143

  
configure
87 87
  echo
88 88
  echo "External library support:"
89 89
  echo "  --enable-mlib            use Sun medialib [default=no]"
90
  echo "  --enable-liba52          enable GPLed liba52 support [default=no]"
91
  echo "  --enable-liba52bin       open liba52.so.0 at runtime [default=no]"
92 90
  echo "  --enable-avisynth        allow reading AVISynth script files [default=no]"
93 91
  echo "  --enable-libamr-nb       enable libamr-nb floating point audio codec"
94 92
  echo "  --enable-libamr-wb       enable libamr-wb floating point audio codec"
......
666 664
    gray
667 665
    hardcoded_tables
668 666
    ipv6
669
    liba52
670
    liba52bin
671 667
    libamr_nb
672 668
    libamr_wb
673 669
    libdc1394
......
852 848
byteswap_h_deps="!armv4l"
853 849

  
854 850
# decoders / encoders
855
ac3_decoder_deps="gpl !liba52"
851
ac3_decoder_deps="gpl"
856 852
dxa_decoder_deps="zlib"
857 853
eac3_decoder_deps="gpl"
858 854
flashsv_decoder_deps="zlib"
......
865 861
zmbv_encoder_deps="zlib"
866 862

  
867 863
# external libraries
868
liba52_decoder_deps="liba52"
869
liba52bin_decoder_extralibs='$ldl'
870 864
libamr_nb_decoder_deps="libamr_nb"
871 865
libamr_nb_encoder_deps="libamr_nb"
872 866
libamr_wb_decoder_deps="libamr_wb"
......
1407 1401
        enabled_any $@ && die "$name is under GPL and --enable-gpl is not specified."
1408 1402
    }
1409 1403
    die_gpl_disabled "The Postprocessing code" postproc
1410
    die_gpl_disabled "liba52"                  liba52
1411 1404
    die_gpl_disabled "libx264"                 libx264
1412 1405
    die_gpl_disabled "libxvidcore"             libxvid
1413 1406
    die_gpl_disabled "FAAD2"                   libfaad2
......
1704 1697

  
1705 1698
# these are off by default, so fail if requested and not available
1706 1699
enabled avisynth   && require2 vfw32 "windows.h vfw.h" AVIFileInit -lvfw32
1707
enabled liba52     && require  liba52 a52dec/a52.h a52_init -la52
1708 1700
enabled libamr_nb  && require  libamrnb amrnb/interf_dec.h Speech_Decode_Frame_init -lamrnb -lm
1709 1701
enabled libamr_wb  && require  libamrwb amrwb/dec_if.h D_IF_init -lamrwb -lm
1710 1702
enabled libdirac   && add_cflags "$(pkg-config --cflags dirac)" \
......
2010 2002
fi
2011 2003
echo "Sun medialib support      ${mlib-no}"
2012 2004
echo "AVISynth enabled          ${avisynth-no}"
2013
echo "liba52 support            ${liba52-no}"
2014
echo "liba52 dlopened           ${liba52bin-no}"
2015 2005
echo "libamr-nb support         ${libamr_nb-no}"
2016 2006
echo "libamr-wb support         ${libamr_wb-no}"
2017 2007
echo "libdc1394 support         ${libdc1394-no}"
doc/general.texi
339 339
@item AAC                    @tab  X  @tab  X
340 340
    @tab Encoding is supported through the external library libfaac.
341 341
@item AC-3                   @tab IX  @tab IX
342
    @tab liba52 can be used alternatively for decoding.
343 342
@item AMR-NB                 @tab  X  @tab  X
344 343
    @tab Supported through an external library.
345 344
@item AMR-WB                 @tab  X  @tab  X
libavcodec/Makefile
324 324
OBJS-$(CONFIG_RTP_MUXER)               += mpegvideo.o
325 325

  
326 326
# external codec libraries
327
OBJS-$(CONFIG_LIBA52)                  += liba52.o
328 327
OBJS-$(CONFIG_LIBAMR_NB)               += libamr.o
329 328
OBJS-$(CONFIG_LIBAMR_WB)               += libamr.o
330 329
OBJS-$(CONFIG_LIBDIRAC_DECODER)        += libdiracdec.o
......
495 494
include $(SUBDIR)../subdir.mak
496 495

  
497 496
$(SUBDIR)dct-test$(EXESUF): $(SUBDIR)fdctref.o
497
$(SUBDIR)fft-test$(EXESUF): $(SUBDIR)fdctref.o
libavcodec/allcodecs.c
284 284
    REGISTER_ENCDEC  (DVDSUB, dvdsub);
285 285

  
286 286
    /* external libraries */
287
    REGISTER_DECODER (LIBA52, liba52);
288 287
    REGISTER_ENCDEC  (LIBAMR_NB, libamr_nb);
289 288
    REGISTER_ENCDEC  (LIBAMR_WB, libamr_wb);
290 289
    REGISTER_ENCDEC  (LIBDIRAC, libdirac);
libavcodec/liba52.c
1
/*
2
 * A52 decoder using liba52
3
 * Copyright (c) 2001 Fabrice Bellard.
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
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

  
22
/**
23
 * @file a52dec.c
24
 * A52 decoder using liba52
25
 */
26

  
27
#include "avcodec.h"
28
#include <a52dec/a52.h>
29

  
30
#ifdef CONFIG_LIBA52BIN
31
#include <dlfcn.h>
32
static const char* const liba52name = "liba52.so.0";
33
#endif
34

  
35
/**
36
 * liba52 - Copyright (C) Aaron Holtzman
37
 * released under the GPL license.
38
 */
39
typedef struct AC3DecodeState {
40
    int flags;
41
    int channels;
42
    a52_state_t* state;
43
    sample_t* samples;
44

  
45
    /*
46
     * virtual method table
47
     *
48
     * using this function table so the liba52 doesn't
49
     * have to be really linked together with ffmpeg
50
     * and might be linked in runtime - this allows binary
51
     * distribution of ffmpeg library which doens't depend
52
     * on liba52 library - but if user has it installed
53
     * it will be used - user might install such library
54
     * separately
55
     */
56
    void* handle;
57
    a52_state_t* (*a52_init)(uint32_t mm_accel);
58
    sample_t* (*a52_samples)(a52_state_t * state);
59
    int (*a52_syncinfo)(uint8_t * buf, int * flags,
60
                          int * sample_rate, int * bit_rate);
61
    int (*a52_frame)(a52_state_t * state, uint8_t * buf, int * flags,
62
                       sample_t * level, sample_t bias);
63
    void (*a52_dynrng)(a52_state_t * state,
64
                         sample_t (* call) (sample_t, void *), void * data);
65
    int (*a52_block)(a52_state_t * state);
66
    void (*a52_free)(a52_state_t * state);
67

  
68
} AC3DecodeState;
69

  
70
#ifdef CONFIG_LIBA52BIN
71
static void* dlsymm(void* handle, const char* symbol)
72
{
73
    void* f = dlsym(handle, symbol);
74
    if (!f)
75
        av_log( NULL, AV_LOG_ERROR, "A52 Decoder - function '%s' can't be resolved\n", symbol);
76
    return f;
77
}
78
#endif
79

  
80
static av_cold int a52_decode_init(AVCodecContext *avctx)
81
{
82
    AC3DecodeState *s = avctx->priv_data;
83

  
84
#ifdef CONFIG_LIBA52BIN
85
    s->handle = dlopen(liba52name, RTLD_LAZY);
86
    if (!s->handle)
87
    {
88
        av_log( avctx, AV_LOG_ERROR, "A52 library %s could not be opened! \n%s\n", liba52name, dlerror());
89
        return -1;
90
    }
91
    s->a52_init = (a52_state_t* (*)(uint32_t)) dlsymm(s->handle, "a52_init");
92
    s->a52_samples = (sample_t* (*)(a52_state_t*)) dlsymm(s->handle, "a52_samples");
93
    s->a52_syncinfo = (int (*)(uint8_t*, int*, int*, int*)) dlsymm(s->handle, "a52_syncinfo");
94
    s->a52_frame = (int (*)(a52_state_t*, uint8_t*, int*, sample_t*, sample_t)) dlsymm(s->handle, "a52_frame");
95
    s->a52_block = (int (*)(a52_state_t*)) dlsymm(s->handle, "a52_block");
96
    s->a52_free = (void (*)(a52_state_t*)) dlsymm(s->handle, "a52_free");
97
    if (!s->a52_init || !s->a52_samples || !s->a52_syncinfo
98
        || !s->a52_frame || !s->a52_block || !s->a52_free)
99
    {
100
        dlclose(s->handle);
101
        return -1;
102
    }
103
#else
104
    s->handle = 0;
105
    s->a52_init = a52_init;
106
    s->a52_samples = a52_samples;
107
    s->a52_syncinfo = a52_syncinfo;
108
    s->a52_frame = a52_frame;
109
    s->a52_block = a52_block;
110
    s->a52_free = a52_free;
111
#endif
112
    s->state = s->a52_init(0); /* later use CPU flags */
113
    s->samples = s->a52_samples(s->state);
114

  
115
    /* allow downmixing to stereo or mono */
116
    if (avctx->channels > 0 && avctx->request_channels > 0 &&
117
            avctx->request_channels < avctx->channels &&
118
            avctx->request_channels <= 2) {
119
        avctx->channels = avctx->request_channels;
120
    }
121

  
122
    avctx->sample_fmt = SAMPLE_FMT_S16;
123
    return 0;
124
}
125

  
126
/**** the following function comes from a52dec */
127
static inline void float_to_int (float * _f, int16_t * s16, int nchannels)
128
{
129
    int i, j, c;
130
    int32_t * f = (int32_t *) _f;       // XXX assumes IEEE float format
131

  
132
    j = 0;
133
    nchannels *= 256;
134
    for (i = 0; i < 256; i++) {
135
        for (c = 0; c < nchannels; c += 256)
136
            s16[j++] = av_clip_int16(f[i + c] - 0x43c00000);
137
    }
138
}
139

  
140
/**** end */
141

  
142
#define HEADER_SIZE 7
143

  
144
static int a52_decode_frame(AVCodecContext *avctx,
145
                            void *data, int *data_size,
146
                            uint8_t *buf, int buf_size)
147
{
148
    AC3DecodeState *s = avctx->priv_data;
149
    int flags, i, len;
150
    int sample_rate, bit_rate;
151
    short *out_samples = data;
152
    float level;
153
    static const int ac3_channels[8] = {
154
        2, 1, 2, 3, 3, 4, 4, 5
155
    };
156

  
157
    *data_size= 0;
158

  
159
    if (buf_size < HEADER_SIZE) {
160
        av_log(avctx, AV_LOG_ERROR, "Error decoding frame, not enough bytes for header\n");
161
        return -1;
162
    }
163
    len = s->a52_syncinfo(buf, &s->flags, &sample_rate, &bit_rate);
164
    if (len == 0) {
165
        av_log(avctx, AV_LOG_ERROR, "Error decoding frame, no sync byte at begin\n");
166
        return -1;
167
    }
168
    if (buf_size < len) {
169
        av_log(avctx, AV_LOG_ERROR, "Error decoding frame, not enough bytes\n");
170
        return -1;
171
    }
172
    /* update codec info */
173
    avctx->sample_rate = sample_rate;
174
    s->channels = ac3_channels[s->flags & 7];
175
    if (s->flags & A52_LFE)
176
            s->channels++;
177
    if (avctx->request_channels > 0 &&
178
        avctx->request_channels <= 2 &&
179
        avctx->request_channels < s->channels) {
180
        avctx->channels = avctx->request_channels;
181
    } else {
182
        avctx->channels = s->channels;
183
    }
184
    avctx->bit_rate = bit_rate;
185
    flags = s->flags;
186
    if (avctx->channels == 1)
187
        flags = A52_MONO;
188
    else if (avctx->channels == 2)
189
        flags = A52_STEREO;
190
    else
191
        flags |= A52_ADJUST_LEVEL;
192
    level = 1;
193
    if (s->a52_frame(s->state, buf, &flags, &level, 384)) {
194
    fail:
195
        av_log(avctx, AV_LOG_ERROR, "Error decoding frame\n");
196
        return -1;
197
    }
198
    for (i = 0; i < 6; i++) {
199
        if (s->a52_block(s->state))
200
            goto fail;
201
        float_to_int(s->samples, out_samples + i * 256 * avctx->channels, avctx->channels);
202
    }
203
    *data_size = 6 * avctx->channels * 256 * sizeof(int16_t);
204
    return len;
205
}
206

  
207
static av_cold int a52_decode_end(AVCodecContext *avctx)
208
{
209
    AC3DecodeState *s = avctx->priv_data;
210
    s->a52_free(s->state);
211
#ifdef CONFIG_LIBA52BIN
212
    dlclose(s->handle);
213
#endif
214
    return 0;
215
}
216

  
217
AVCodec liba52_decoder = {
218
    "liba52",
219
    CODEC_TYPE_AUDIO,
220
    CODEC_ID_AC3,
221
    sizeof(AC3DecodeState),
222
    a52_decode_init,
223
    NULL,
224
    a52_decode_end,
225
    a52_decode_frame,
226
    .long_name = NULL_IF_CONFIG_SMALL("liba52 ATSC A/52 / AC-3"),
227
};

Also available in: Unified diff