annotate liba52.c @ 6290:b7045a85cd7d libavcodec

some const
author michael
date Fri, 01 Feb 2008 16:04:29 +0000
parents 98be2e14e5d6
children b568fe642948
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
1 /*
4617
a0b9e07527c4 Clarify that this decoder uses liba52.
diego
parents: 4514
diff changeset
2 * A52 decoder using liba52
429
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
3 * Copyright (c) 2001 Fabrice Bellard.
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3059
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3059
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3059
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
429
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3059
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3059
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
429
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
15 * Lesser General Public License for more details.
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
16 *
429
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3059
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2979
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
20 */
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
21
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
22 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
23 * @file a52dec.c
4617
a0b9e07527c4 Clarify that this decoder uses liba52.
diego
parents: 4514
diff changeset
24 * A52 decoder using liba52
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
25 */
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
26
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
27 #include "avcodec.h"
4511
91872ae737b2 Remove internal liba52; external lib still works, native decoder coming up.
diego
parents: 4356
diff changeset
28 #include <a52dec/a52.h>
4514
790d1cb93686 Restore the possibility to link liba52 instead of dlopening.
diego
parents: 4513
diff changeset
29
790d1cb93686 Restore the possibility to link liba52 instead of dlopening.
diego
parents: 4513
diff changeset
30 #ifdef CONFIG_LIBA52BIN
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
31 #include <dlfcn.h>
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
32 static const char* liba52name = "liba52.so.0";
4514
790d1cb93686 Restore the possibility to link liba52 instead of dlopening.
diego
parents: 4513
diff changeset
33 #endif
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
34
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
35 /**
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
36 * liba52 - Copyright (C) Aaron Holtzman
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
37 * released under the GPL license.
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
38 */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
39 typedef struct AC3DecodeState {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1018
diff changeset
40 uint8_t inbuf[4096]; /* input buffer */
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1018
diff changeset
41 uint8_t *inbuf_ptr;
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
42 int frame_size;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
43 int flags;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
44 int channels;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
45 a52_state_t* state;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
46 sample_t* samples;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
47
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
48 /*
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
49 * virtual method table
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
50 *
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
51 * using this function table so the liba52 doesn't
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
52 * have to be really linked together with ffmpeg
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
53 * and might be linked in runtime - this allows binary
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
54 * distribution of ffmpeg library which doens't depend
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
55 * on liba52 library - but if user has it installed
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
56 * it will be used - user might install such library
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
57 * separately
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
58 */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
59 void* handle;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
60 a52_state_t* (*a52_init)(uint32_t mm_accel);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
61 sample_t* (*a52_samples)(a52_state_t * state);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
62 int (*a52_syncinfo)(uint8_t * buf, int * flags,
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2846
diff changeset
63 int * sample_rate, int * bit_rate);
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
64 int (*a52_frame)(a52_state_t * state, uint8_t * buf, int * flags,
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2846
diff changeset
65 sample_t * level, sample_t bias);
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
66 void (*a52_dynrng)(a52_state_t * state,
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2846
diff changeset
67 sample_t (* call) (sample_t, void *), void * data);
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
68 int (*a52_block)(a52_state_t * state);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
69 void (*a52_free)(a52_state_t * state);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
70
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
71 } AC3DecodeState;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
72
4618
bb06df70f857 Add proper #idef to dlsymm call, also fixes an unresolved symbol on OS X 10.2.
diego
parents: 4617
diff changeset
73 #ifdef CONFIG_LIBA52BIN
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
74 static void* dlsymm(void* handle, const char* symbol)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
75 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
76 void* f = dlsym(handle, symbol);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
77 if (!f)
2846
40765c51a7a9 Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents: 2028
diff changeset
78 av_log( NULL, AV_LOG_ERROR, "A52 Decoder - function '%s' can't be resolved\n", symbol);
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
79 return f;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
80 }
4618
bb06df70f857 Add proper #idef to dlsymm call, also fixes an unresolved symbol on OS X 10.2.
diego
parents: 4617
diff changeset
81 #endif
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
82
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
83 static int a52_decode_init(AVCodecContext *avctx)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
84 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
85 AC3DecodeState *s = avctx->priv_data;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
86
4514
790d1cb93686 Restore the possibility to link liba52 instead of dlopening.
diego
parents: 4513
diff changeset
87 #ifdef CONFIG_LIBA52BIN
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
88 s->handle = dlopen(liba52name, RTLD_LAZY);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
89 if (!s->handle)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
90 {
2846
40765c51a7a9 Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents: 2028
diff changeset
91 av_log( avctx, AV_LOG_ERROR, "A52 library %s could not be opened! \n%s\n", liba52name, dlerror());
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
92 return -1;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
93 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
94 s->a52_init = (a52_state_t* (*)(uint32_t)) dlsymm(s->handle, "a52_init");
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
95 s->a52_samples = (sample_t* (*)(a52_state_t*)) dlsymm(s->handle, "a52_samples");
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
96 s->a52_syncinfo = (int (*)(uint8_t*, int*, int*, int*)) dlsymm(s->handle, "a52_syncinfo");
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
97 s->a52_frame = (int (*)(a52_state_t*, uint8_t*, int*, sample_t*, sample_t)) dlsymm(s->handle, "a52_frame");
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
98 s->a52_block = (int (*)(a52_state_t*)) dlsymm(s->handle, "a52_block");
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
99 s->a52_free = (void (*)(a52_state_t*)) dlsymm(s->handle, "a52_free");
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
100 if (!s->a52_init || !s->a52_samples || !s->a52_syncinfo
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
101 || !s->a52_frame || !s->a52_block || !s->a52_free)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
102 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2846
diff changeset
103 dlclose(s->handle);
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
104 return -1;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
105 }
4514
790d1cb93686 Restore the possibility to link liba52 instead of dlopening.
diego
parents: 4513
diff changeset
106 #else
790d1cb93686 Restore the possibility to link liba52 instead of dlopening.
diego
parents: 4513
diff changeset
107 s->handle = 0;
790d1cb93686 Restore the possibility to link liba52 instead of dlopening.
diego
parents: 4513
diff changeset
108 s->a52_init = a52_init;
790d1cb93686 Restore the possibility to link liba52 instead of dlopening.
diego
parents: 4513
diff changeset
109 s->a52_samples = a52_samples;
790d1cb93686 Restore the possibility to link liba52 instead of dlopening.
diego
parents: 4513
diff changeset
110 s->a52_syncinfo = a52_syncinfo;
790d1cb93686 Restore the possibility to link liba52 instead of dlopening.
diego
parents: 4513
diff changeset
111 s->a52_frame = a52_frame;
790d1cb93686 Restore the possibility to link liba52 instead of dlopening.
diego
parents: 4513
diff changeset
112 s->a52_block = a52_block;
790d1cb93686 Restore the possibility to link liba52 instead of dlopening.
diego
parents: 4513
diff changeset
113 s->a52_free = a52_free;
790d1cb93686 Restore the possibility to link liba52 instead of dlopening.
diego
parents: 4513
diff changeset
114 #endif
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
115 s->state = s->a52_init(0); /* later use CPU flags */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
116 s->samples = s->a52_samples(s->state);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
117 s->inbuf_ptr = s->inbuf;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
118 s->frame_size = 0;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
119
6114
f6b691720c7d use request_channels in liba52 decoder
jbr
parents: 5525
diff changeset
120 /* allow downmixing to stereo or mono */
f6b691720c7d use request_channels in liba52 decoder
jbr
parents: 5525
diff changeset
121 if (avctx->channels > 0 && avctx->request_channels > 0 &&
f6b691720c7d use request_channels in liba52 decoder
jbr
parents: 5525
diff changeset
122 avctx->request_channels < avctx->channels &&
f6b691720c7d use request_channels in liba52 decoder
jbr
parents: 5525
diff changeset
123 avctx->request_channels <= 2) {
f6b691720c7d use request_channels in liba52 decoder
jbr
parents: 5525
diff changeset
124 avctx->channels = avctx->request_channels;
f6b691720c7d use request_channels in liba52 decoder
jbr
parents: 5525
diff changeset
125 }
f6b691720c7d use request_channels in liba52 decoder
jbr
parents: 5525
diff changeset
126
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
127 return 0;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
128 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
129
5525
bc4791868c52 various simplifications around recent av_clip_int16() usage
aurel
parents: 5523
diff changeset
130 /**** the following function comes from a52dec */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1018
diff changeset
131 static inline void float_to_int (float * _f, int16_t * s16, int nchannels)
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
132 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
133 int i, j, c;
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2846
diff changeset
134 int32_t * f = (int32_t *) _f; // XXX assumes IEEE float format
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
135
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
136 j = 0;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
137 nchannels *= 256;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
138 for (i = 0; i < 256; i++) {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2846
diff changeset
139 for (c = 0; c < nchannels; c += 256)
5525
bc4791868c52 various simplifications around recent av_clip_int16() usage
aurel
parents: 5523
diff changeset
140 s16[j++] = av_clip_int16(f[i + c] - 0x43c00000);
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
141 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
142 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
143
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
144 /**** end */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
145
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
146 #define HEADER_SIZE 7
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
147
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
148 static int a52_decode_frame(AVCodecContext *avctx,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
149 void *data, int *data_size,
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1018
diff changeset
150 uint8_t *buf, int buf_size)
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
151 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
152 AC3DecodeState *s = avctx->priv_data;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1018
diff changeset
153 uint8_t *buf_ptr;
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
154 int flags, i, len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
155 int sample_rate, bit_rate;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
156 short *out_samples = data;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
157 float level;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
158 static const int ac3_channels[8] = {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2846
diff changeset
159 2, 1, 2, 3, 3, 4, 4, 5
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
160 };
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
161
4356
c8bc01fee409 set data_size to 0 so that in case we return without setting it nothing funny can happen
michael
parents: 4343
diff changeset
162 *data_size= 0;
c8bc01fee409 set data_size to 0 so that in case we return without setting it nothing funny can happen
michael
parents: 4343
diff changeset
163
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
164 buf_ptr = buf;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
165 while (buf_size > 0) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
166 len = s->inbuf_ptr - s->inbuf;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
167 if (s->frame_size == 0) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
168 /* no header seen : find one. We need at least 7 bytes to parse it */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
169 len = HEADER_SIZE - len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
170 if (len > buf_size)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
171 len = buf_size;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
172 memcpy(s->inbuf_ptr, buf_ptr, len);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
173 buf_ptr += len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
174 s->inbuf_ptr += len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
175 buf_size -= len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
176 if ((s->inbuf_ptr - s->inbuf) == HEADER_SIZE) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
177 len = s->a52_syncinfo(s->inbuf, &s->flags, &sample_rate, &bit_rate);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
178 if (len == 0) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
179 /* no sync found : move by one byte (inefficient, but simple!) */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
180 memcpy(s->inbuf, s->inbuf + 1, HEADER_SIZE - 1);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
181 s->inbuf_ptr--;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
182 } else {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2846
diff changeset
183 s->frame_size = len;
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
184 /* update codec info */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
185 avctx->sample_rate = sample_rate;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
186 s->channels = ac3_channels[s->flags & 7];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
187 if (s->flags & A52_LFE)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2846
diff changeset
188 s->channels++;
6114
f6b691720c7d use request_channels in liba52 decoder
jbr
parents: 5525
diff changeset
189 if (avctx->request_channels > 0 &&
f6b691720c7d use request_channels in liba52 decoder
jbr
parents: 5525
diff changeset
190 avctx->request_channels <= 2 &&
f6b691720c7d use request_channels in liba52 decoder
jbr
parents: 5525
diff changeset
191 avctx->request_channels < s->channels) {
f6b691720c7d use request_channels in liba52 decoder
jbr
parents: 5525
diff changeset
192 avctx->channels = avctx->request_channels;
6115
98be2e14e5d6 do not set channels before checking request_channels
jbr
parents: 6114
diff changeset
193 } else {
98be2e14e5d6 do not set channels before checking request_channels
jbr
parents: 6114
diff changeset
194 avctx->channels = s->channels;
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2846
diff changeset
195 }
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2846
diff changeset
196 avctx->bit_rate = bit_rate;
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
197 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
198 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
199 } else if (len < s->frame_size) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
200 len = s->frame_size - len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
201 if (len > buf_size)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
202 len = buf_size;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
203
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
204 memcpy(s->inbuf_ptr, buf_ptr, len);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
205 buf_ptr += len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
206 s->inbuf_ptr += len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
207 buf_size -= len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
208 } else {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
209 flags = s->flags;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
210 if (avctx->channels == 1)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
211 flags = A52_MONO;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
212 else if (avctx->channels == 2)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
213 flags = A52_STEREO;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
214 else
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
215 flags |= A52_ADJUST_LEVEL;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
216 level = 1;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
217 if (s->a52_frame(s->state, s->inbuf, &flags, &level, 384)) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
218 fail:
4343
d9a61f401c11 print error when decoding fails
bcoudurier
parents: 4334
diff changeset
219 av_log(avctx, AV_LOG_ERROR, "Error decoding frame\n");
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
220 s->inbuf_ptr = s->inbuf;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
221 s->frame_size = 0;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
222 continue;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
223 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
224 for (i = 0; i < 6; i++) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
225 if (s->a52_block(s->state))
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
226 goto fail;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
227 float_to_int(s->samples, out_samples + i * 256 * avctx->channels, avctx->channels);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
228 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
229 s->inbuf_ptr = s->inbuf;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
230 s->frame_size = 0;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1018
diff changeset
231 *data_size = 6 * avctx->channels * 256 * sizeof(int16_t);
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
232 break;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
233 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
234 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
235 return buf_ptr - buf;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
236 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
237
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
238 static int a52_decode_end(AVCodecContext *avctx)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
239 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
240 AC3DecodeState *s = avctx->priv_data;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
241 s->a52_free(s->state);
4514
790d1cb93686 Restore the possibility to link liba52 instead of dlopening.
diego
parents: 4513
diff changeset
242 #ifdef CONFIG_LIBA52BIN
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
243 dlclose(s->handle);
4514
790d1cb93686 Restore the possibility to link liba52 instead of dlopening.
diego
parents: 4513
diff changeset
244 #endif
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
245 return 0;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
246 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
247
4513
3367310f8460 Rename ac3 decoder to liba52 to prepare for native decoder.
diego
parents: 4511
diff changeset
248 AVCodec liba52_decoder = {
5102
4323e587708d Give names of external library decoders/encoders a lib prefix
diego
parents: 5101
diff changeset
249 "liba52",
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
250 CODEC_TYPE_AUDIO,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
251 CODEC_ID_AC3,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
252 sizeof(AC3DecodeState),
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
253 a52_decode_init,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
254 NULL,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
255 a52_decode_end,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
256 a52_decode_frame,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
257 };