annotate a52dec.c @ 2897:a5360f2a673e libavcodec

13% faster decode_residual (cavlc). patch by diane_cartman at gmx dot de.
author lorenm
date Tue, 27 Sep 2005 04:46:45 +0000
parents 40765c51a7a9
children bfabfdf9ce55
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
1 /*
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
2 * A52 decoder
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 *
429
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
5 * This library is free software; you can redistribute it and/or
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
7 * License as published by the Free Software Foundation; either
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
8 * version 2 of the License, or (at your option) any later version.
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
9 *
429
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
10 * This library is distributed in the hope that it will be useful,
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
429
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
13 * Lesser General Public License for more details.
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
14 *
429
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
16 * License along with this library; if not, write to the Free Software
718a22dc121f license/copyright change
glantau
parents: 368
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
18 */
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
19
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
20 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
21 * @file a52dec.c
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
22 * A52 decoder.
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
23 */
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
24
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
25 #include "avcodec.h"
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
26 #include "liba52/a52.h"
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
27
338
1a38b3b4ea28 * using liba52
kabi
parents: 332
diff changeset
28 #ifdef CONFIG_A52BIN
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
29 #include <dlfcn.h>
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
30 static const char* liba52name = "liba52.so.0";
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
31 #endif
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
32
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
33 /**
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
34 * liba52 - Copyright (C) Aaron Holtzman
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
35 * released under the GPL license.
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
36 */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
37 typedef struct AC3DecodeState {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1018
diff changeset
38 uint8_t inbuf[4096]; /* input buffer */
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1018
diff changeset
39 uint8_t *inbuf_ptr;
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
40 int frame_size;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
41 int flags;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
42 int channels;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
43 a52_state_t* state;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
44 sample_t* samples;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
45
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
46 /*
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
47 * virtual method table
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
48 *
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
49 * using this function table so the liba52 doesn't
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
50 * have to be really linked together with ffmpeg
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
51 * and might be linked in runtime - this allows binary
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
52 * distribution of ffmpeg library which doens't depend
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
53 * on liba52 library - but if user has it installed
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
54 * it will be used - user might install such library
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
55 * separately
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
56 */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
57 void* handle;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
58 a52_state_t* (*a52_init)(uint32_t mm_accel);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
59 sample_t* (*a52_samples)(a52_state_t * state);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
60 int (*a52_syncinfo)(uint8_t * buf, int * flags,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
61 int * sample_rate, int * bit_rate);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
62 int (*a52_frame)(a52_state_t * state, uint8_t * buf, int * flags,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
63 sample_t * level, sample_t bias);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
64 void (*a52_dynrng)(a52_state_t * state,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
65 sample_t (* call) (sample_t, void *), void * data);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
66 int (*a52_block)(a52_state_t * state);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
67 void (*a52_free)(a52_state_t * state);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
68
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
69 } AC3DecodeState;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
70
338
1a38b3b4ea28 * using liba52
kabi
parents: 332
diff changeset
71 #ifdef CONFIG_A52BIN
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
72 static void* dlsymm(void* handle, const char* symbol)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
73 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
74 void* f = dlsym(handle, symbol);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
75 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
76 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
77 return f;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
78 }
2846
40765c51a7a9 Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents: 2028
diff changeset
79
40765c51a7a9 Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents: 2028
diff changeset
80 int ff_a52_syncinfo( AVCodecContext * avctx, uint8_t * buf, int * flags, int * sample_rate, int * bit_rate )
40765c51a7a9 Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents: 2028
diff changeset
81 {
40765c51a7a9 Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents: 2028
diff changeset
82 AC3DecodeState *s = avctx->priv_data;
40765c51a7a9 Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents: 2028
diff changeset
83
40765c51a7a9 Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents: 2028
diff changeset
84 return s->a52_syncinfo(buf, flags, sample_rate, bit_rate);
40765c51a7a9 Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents: 2028
diff changeset
85 }
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
86 #endif
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
87
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
88 static int a52_decode_init(AVCodecContext *avctx)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
89 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
90 AC3DecodeState *s = avctx->priv_data;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
91
338
1a38b3b4ea28 * using liba52
kabi
parents: 332
diff changeset
92 #ifdef CONFIG_A52BIN
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
93 s->handle = dlopen(liba52name, RTLD_LAZY);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
94 if (!s->handle)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
95 {
2846
40765c51a7a9 Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents: 2028
diff changeset
96 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
97 return -1;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
98 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
99 s->a52_init = (a52_state_t* (*)(uint32_t)) dlsymm(s->handle, "a52_init");
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
100 s->a52_samples = (sample_t* (*)(a52_state_t*)) dlsymm(s->handle, "a52_samples");
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
101 s->a52_syncinfo = (int (*)(uint8_t*, int*, int*, int*)) dlsymm(s->handle, "a52_syncinfo");
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
102 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
103 s->a52_block = (int (*)(a52_state_t*)) dlsymm(s->handle, "a52_block");
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
104 s->a52_free = (void (*)(a52_state_t*)) dlsymm(s->handle, "a52_free");
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
105 if (!s->a52_init || !s->a52_samples || !s->a52_syncinfo
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
106 || !s->a52_frame || !s->a52_block || !s->a52_free)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
107 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
108 dlclose(s->handle);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
109 return -1;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
110 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
111 #else
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
112 /* static linked version */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
113 s->handle = 0;
1018
696ccd81403e reverse
nickols_k
parents: 1017
diff changeset
114 s->a52_init = a52_init;
696ccd81403e reverse
nickols_k
parents: 1017
diff changeset
115 s->a52_samples = a52_samples;
696ccd81403e reverse
nickols_k
parents: 1017
diff changeset
116 s->a52_syncinfo = a52_syncinfo;
696ccd81403e reverse
nickols_k
parents: 1017
diff changeset
117 s->a52_frame = a52_frame;
696ccd81403e reverse
nickols_k
parents: 1017
diff changeset
118 s->a52_block = a52_block;
696ccd81403e reverse
nickols_k
parents: 1017
diff changeset
119 s->a52_free = a52_free;
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
120 #endif
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
121 s->state = s->a52_init(0); /* later use CPU flags */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
122 s->samples = s->a52_samples(s->state);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
123 s->inbuf_ptr = s->inbuf;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
124 s->frame_size = 0;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
125
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
126 return 0;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
127 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
128
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
129 /**** the following two functions comes from a52dec */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
130 static inline int blah (int32_t i)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
131 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
132 if (i > 0x43c07fff)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
133 return 32767;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
134 else if (i < 0x43bf8000)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
135 return -32768;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
136 return i - 0x43c00000;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
137 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
138
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1018
diff changeset
139 static inline void float_to_int (float * _f, int16_t * s16, int nchannels)
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
140 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
141 int i, j, c;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
142 int32_t * f = (int32_t *) _f; // XXX assumes IEEE float format
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
143
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
144 j = 0;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
145 nchannels *= 256;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
146 for (i = 0; i < 256; i++) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
147 for (c = 0; c < nchannels; c += 256)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
148 s16[j++] = blah (f[i + c]);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
149 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
150 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
151
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
152 /**** end */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
153
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
154 #define HEADER_SIZE 7
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
155
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
156 static int a52_decode_frame(AVCodecContext *avctx,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
157 void *data, int *data_size,
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1018
diff changeset
158 uint8_t *buf, int buf_size)
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
159 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
160 AC3DecodeState *s = avctx->priv_data;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1018
diff changeset
161 uint8_t *buf_ptr;
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
162 int flags, i, len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
163 int sample_rate, bit_rate;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
164 short *out_samples = data;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
165 float level;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
166 static const int ac3_channels[8] = {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
167 2, 1, 2, 3, 3, 4, 4, 5
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
168 };
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
169
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
170 buf_ptr = buf;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
171 while (buf_size > 0) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
172 len = s->inbuf_ptr - s->inbuf;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
173 if (s->frame_size == 0) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
174 /* no header seen : find one. We need at least 7 bytes to parse it */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
175 len = HEADER_SIZE - len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
176 if (len > buf_size)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
177 len = buf_size;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
178 memcpy(s->inbuf_ptr, buf_ptr, len);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
179 buf_ptr += len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
180 s->inbuf_ptr += len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
181 buf_size -= len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
182 if ((s->inbuf_ptr - s->inbuf) == HEADER_SIZE) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
183 len = s->a52_syncinfo(s->inbuf, &s->flags, &sample_rate, &bit_rate);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
184 if (len == 0) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
185 /* no sync found : move by one byte (inefficient, but simple!) */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
186 memcpy(s->inbuf, s->inbuf + 1, HEADER_SIZE - 1);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
187 s->inbuf_ptr--;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
188 } else {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
189 s->frame_size = len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
190 /* update codec info */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
191 avctx->sample_rate = sample_rate;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
192 s->channels = ac3_channels[s->flags & 7];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
193 if (s->flags & A52_LFE)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
194 s->channels++;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
195 if (avctx->channels == 0)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
196 /* No specific number of channel requested */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
197 avctx->channels = s->channels;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
198 else if (s->channels < avctx->channels) {
1602
fdb8244da1e5 av_log patch(2 of ?) by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 1106
diff changeset
199 av_log(avctx, AV_LOG_ERROR, "ac3dec: AC3 Source channels are less than specified: output to %d channels.. (frmsize: %d)\n", s->channels, len);
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
200 avctx->channels = s->channels;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
201 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
202 avctx->bit_rate = bit_rate;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
203 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
204 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
205 } else if (len < s->frame_size) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
206 len = s->frame_size - len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
207 if (len > buf_size)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
208 len = buf_size;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
209
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
210 memcpy(s->inbuf_ptr, buf_ptr, len);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
211 buf_ptr += len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
212 s->inbuf_ptr += len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
213 buf_size -= len;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
214 } else {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
215 flags = s->flags;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
216 if (avctx->channels == 1)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
217 flags = A52_MONO;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
218 else if (avctx->channels == 2)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
219 flags = A52_STEREO;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
220 else
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
221 flags |= A52_ADJUST_LEVEL;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
222 level = 1;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
223 if (s->a52_frame(s->state, s->inbuf, &flags, &level, 384)) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
224 fail:
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
225 s->inbuf_ptr = s->inbuf;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
226 s->frame_size = 0;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
227 continue;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
228 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
229 for (i = 0; i < 6; i++) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
230 if (s->a52_block(s->state))
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
231 goto fail;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
232 float_to_int(s->samples, out_samples + i * 256 * avctx->channels, avctx->channels);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
233 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
234 s->inbuf_ptr = s->inbuf;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
235 s->frame_size = 0;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1018
diff changeset
236 *data_size = 6 * avctx->channels * 256 * sizeof(int16_t);
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
237 break;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
238 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
239 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
240 return buf_ptr - buf;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
241 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
242
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
243 static int a52_decode_end(AVCodecContext *avctx)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
244 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
245 AC3DecodeState *s = avctx->priv_data;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
246 s->a52_free(s->state);
338
1a38b3b4ea28 * using liba52
kabi
parents: 332
diff changeset
247 #ifdef CONFIG_A52BIN
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
248 dlclose(s->handle);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
249 #endif
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
250 return 0;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
251 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
252
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
253 AVCodec ac3_decoder = {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
254 "ac3",
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
255 CODEC_TYPE_AUDIO,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
256 CODEC_ID_AC3,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
257 sizeof(AC3DecodeState),
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
258 a52_decode_init,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
259 NULL,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
260 a52_decode_end,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
261 a52_decode_frame,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
262 };