Mercurial > libavcodec.hg
annotate alac.c @ 11472:258d773b8feb libavcodec
vp3: we only need a temp MV array of size 4
author | conrad |
---|---|
date | Sat, 13 Mar 2010 05:56:11 +0000 |
parents | 0d56d489e695 |
children | 8a4984c5cacc |
rev | line source |
---|---|
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
1 /* |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
2 * ALAC (Apple Lossless Audio Codec) decoder |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
3 * Copyright (c) 2005 David Hammerton |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
4 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3347
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3347
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3347
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
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:
3347
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3347
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
16 * |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
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:
3347
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:
2967
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
20 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
21 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
22 /** |
8718
e9d9d946f213
Use full internal pathname in doxygen @file directives.
diego
parents:
7836
diff
changeset
|
23 * @file libavcodec/alac.c |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
24 * ALAC (Apple Lossless Audio Codec) decoder |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
25 * @author 2005 David Hammerton |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
26 * |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
27 * For more information on the ALAC format, visit: |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
28 * http://crazney.net/programs/itunes/alac.html |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
29 * |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
30 * Note: This decoder expects a 36- (0x24-)byte QuickTime atom to be |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
31 * passed through the extradata[_size] fields. This atom is tacked onto |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
32 * the end of an 'alac' stsd atom and has the following format: |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
33 * bytes 0-3 atom size (0x24), big-endian |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
34 * bytes 4-7 atom type ('alac', not the 'alac' tag from start of stsd) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
35 * bytes 8-35 data bytes needed by decoder |
3135 | 36 * |
37 * Extradata: | |
38 * 32bit size | |
39 * 32bit tag (=alac) | |
40 * 32bit zero? | |
41 * 32bit max sample per frame | |
42 * 8bit ?? (zero?) | |
43 * 8bit sample size | |
44 * 8bit history mult | |
45 * 8bit initial history | |
46 * 8bit kmodifier | |
47 * 8bit channels? | |
48 * 16bit ?? | |
49 * 32bit max coded frame size | |
50 * 32bit bitrate? | |
51 * 32bit samplerate | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
52 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
53 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
54 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
55 #include "avcodec.h" |
9428 | 56 #include "get_bits.h" |
5276 | 57 #include "bytestream.h" |
5628 | 58 #include "unary.h" |
9097 | 59 #include "mathops.h" |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
60 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
61 #define ALAC_EXTRADATA_SIZE 36 |
5272 | 62 #define MAX_CHANNELS 2 |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
63 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
64 typedef struct { |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
65 |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
66 AVCodecContext *avctx; |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
67 GetBitContext gb; |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
68 /* init to 0; first frame decode should initialize from extradata and |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
69 * set this to 1 */ |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
70 int context_initialized; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
71 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
72 int numchannels; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
73 int bytespersample; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
74 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
75 /* buffers */ |
5272 | 76 int32_t *predicterror_buffer[MAX_CHANNELS]; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
77 |
5272 | 78 int32_t *outputsamples_buffer[MAX_CHANNELS]; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
79 |
11077 | 80 int32_t *wasted_bits_buffer[MAX_CHANNELS]; |
81 | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
82 /* stuff from setinfo */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
83 uint32_t setinfo_max_samples_per_frame; /* 0x1000 = 4096 */ /* max samples per frame? */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
84 uint8_t setinfo_sample_size; /* 0x10 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
85 uint8_t setinfo_rice_historymult; /* 0x28 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
86 uint8_t setinfo_rice_initialhistory; /* 0x0a */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
87 uint8_t setinfo_rice_kmodifier; /* 0x0e */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
88 /* end setinfo stuff */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
89 |
11077 | 90 int wasted_bits; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
91 } ALACContext; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
92 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
93 static void allocate_buffers(ALACContext *alac) |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
94 { |
5272 | 95 int chan; |
96 for (chan = 0; chan < MAX_CHANNELS; chan++) { | |
97 alac->predicterror_buffer[chan] = | |
98 av_malloc(alac->setinfo_max_samples_per_frame * 4); | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
99 |
5272 | 100 alac->outputsamples_buffer[chan] = |
101 av_malloc(alac->setinfo_max_samples_per_frame * 4); | |
11077 | 102 |
103 alac->wasted_bits_buffer[chan] = av_malloc(alac->setinfo_max_samples_per_frame * 4); | |
5272 | 104 } |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
105 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
106 |
3303
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3299
diff
changeset
|
107 static int alac_set_info(ALACContext *alac) |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
108 { |
6221 | 109 const unsigned char *ptr = alac->avctx->extradata; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
110 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
111 ptr += 4; /* size */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
112 ptr += 4; /* alac */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
113 ptr += 4; /* 0 ? */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
114 |
4364 | 115 if(AV_RB32(ptr) >= UINT_MAX/4){ |
3303
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3299
diff
changeset
|
116 av_log(alac->avctx, AV_LOG_ERROR, "setinfo_max_samples_per_frame too large\n"); |
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3299
diff
changeset
|
117 return -1; |
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3299
diff
changeset
|
118 } |
5276 | 119 |
120 /* buffer size / 2 ? */ | |
121 alac->setinfo_max_samples_per_frame = bytestream_get_be32(&ptr); | |
6634
981e2f43ea36
10l: my last commit broke compilation and introduced warnings
vitor
parents:
6633
diff
changeset
|
122 ptr++; /* ??? */ |
5360 | 123 alac->setinfo_sample_size = *ptr++; |
6778
1926f42527c7
simplify decoding of uncompressed samples. patch by matthieu castet <castet matthieu free fr>.
jbr
parents:
6773
diff
changeset
|
124 if (alac->setinfo_sample_size > 32) { |
1926f42527c7
simplify decoding of uncompressed samples. patch by matthieu castet <castet matthieu free fr>.
jbr
parents:
6773
diff
changeset
|
125 av_log(alac->avctx, AV_LOG_ERROR, "setinfo_sample_size too large\n"); |
1926f42527c7
simplify decoding of uncompressed samples. patch by matthieu castet <castet matthieu free fr>.
jbr
parents:
6773
diff
changeset
|
126 return -1; |
1926f42527c7
simplify decoding of uncompressed samples. patch by matthieu castet <castet matthieu free fr>.
jbr
parents:
6773
diff
changeset
|
127 } |
5360 | 128 alac->setinfo_rice_historymult = *ptr++; |
129 alac->setinfo_rice_initialhistory = *ptr++; | |
130 alac->setinfo_rice_kmodifier = *ptr++; | |
6634
981e2f43ea36
10l: my last commit broke compilation and introduced warnings
vitor
parents:
6633
diff
changeset
|
131 ptr++; /* channels? */ |
6633 | 132 bytestream_get_be16(&ptr); /* ??? */ |
133 bytestream_get_be32(&ptr); /* max coded frame size */ | |
134 bytestream_get_be32(&ptr); /* bitrate ? */ | |
6634
981e2f43ea36
10l: my last commit broke compilation and introduced warnings
vitor
parents:
6633
diff
changeset
|
135 bytestream_get_be32(&ptr); /* samplerate */ |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
136 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
137 allocate_buffers(alac); |
3303
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3299
diff
changeset
|
138 |
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3299
diff
changeset
|
139 return 0; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
140 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
141 |
6626 | 142 static inline int decode_scalar(GetBitContext *gb, int k, int limit, int readsamplesize){ |
143 /* read x - number of 1s before 0 represent the rice */ | |
144 int x = get_unary_0_9(gb); | |
145 | |
146 if (x > 8) { /* RICE THRESHOLD */ | |
147 /* use alternative encoding */ | |
148 x = get_bits(gb, readsamplesize); | |
149 } else { | |
6627 | 150 if (k >= limit) |
151 k = limit; | |
6625 | 152 |
6627 | 153 if (k != 1) { |
154 int extrabits = show_bits(gb, k); | |
6625 | 155 |
6627 | 156 /* multiply x by 2^k - 1, as part of their strange algorithm */ |
157 x = (x << k) - x; | |
6625 | 158 |
6627 | 159 if (extrabits > 1) { |
160 x += extrabits - 1; | |
161 skip_bits(gb, k); | |
162 } else | |
163 skip_bits(gb, k - 1); | |
164 } | |
6626 | 165 } |
6625 | 166 return x; |
167 } | |
168 | |
3071
cc0357a90e8f
make some functions static (patch by Dieter < freebsd at sopwith.solgatos.com >)
aurel
parents:
3036
diff
changeset
|
169 static void bastardized_rice_decompress(ALACContext *alac, |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
170 int32_t *output_buffer, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
171 int output_size, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
172 int readsamplesize, /* arg_10 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
173 int rice_initialhistory, /* arg424->b */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
174 int rice_kmodifier, /* arg424->d */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
175 int rice_historymult, /* arg424->c */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
176 int rice_kmodifier_mask /* arg424->e */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
177 ) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
178 { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
179 int output_count; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
180 unsigned int history = rice_initialhistory; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
181 int sign_modifier = 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
182 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
183 for (output_count = 0; output_count < output_size; output_count++) { |
5628 | 184 int32_t x; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
185 int32_t x_modified; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
186 int32_t final_val; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
187 |
6627 | 188 /* standard rice encoding */ |
189 int k; /* size of extra bits */ | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
190 |
6627 | 191 /* read k, that is bits as is */ |
6632 | 192 k = av_log2((history >> 9) + 3); |
6627 | 193 x= decode_scalar(&alac->gb, k, rice_kmodifier, readsamplesize); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
194 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
195 x_modified = sign_modifier + x; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
196 final_val = (x_modified + 1) / 2; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
197 if (x_modified & 1) final_val *= -1; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
198 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
199 output_buffer[output_count] = final_val; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
200 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
201 sign_modifier = 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
202 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
203 /* now update the history */ |
5365 | 204 history += x_modified * rice_historymult |
205 - ((history * rice_historymult) >> 9); | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
206 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
207 if (x_modified > 0xffff) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
208 history = 0xffff; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
209 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
210 /* special case: there may be compressed blocks of 0 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
211 if ((history < 128) && (output_count+1 < output_size)) { |
6742 | 212 int k; |
213 unsigned int block_size; | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
214 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
215 sign_modifier = 1; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
216 |
6632 | 217 k = 7 - av_log2(history) + ((history + 16) >> 6 /* / 64 */); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
218 |
6627 | 219 block_size= decode_scalar(&alac->gb, k, rice_kmodifier, 16); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
220 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
221 if (block_size > 0) { |
6742 | 222 if(block_size >= output_size - output_count){ |
223 av_log(alac->avctx, AV_LOG_ERROR, "invalid zero block size of %d %d %d\n", block_size, output_size, output_count); | |
224 block_size= output_size - output_count - 1; | |
225 } | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
226 memset(&output_buffer[output_count+1], 0, block_size * 4); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
227 output_count += block_size; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
228 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
229 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
230 if (block_size > 0xffff) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
231 sign_modifier = 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
232 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
233 history = 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
234 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
235 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
236 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
237 |
5616 | 238 static inline int sign_only(int v) |
239 { | |
240 return v ? FFSIGN(v) : 0; | |
241 } | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
242 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
243 static void predictor_decompress_fir_adapt(int32_t *error_buffer, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
244 int32_t *buffer_out, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
245 int output_size, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
246 int readsamplesize, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
247 int16_t *predictor_coef_table, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
248 int predictor_coef_num, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
249 int predictor_quantitization) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
250 { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
251 int i; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
252 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
253 /* first sample always copies */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
254 *buffer_out = *error_buffer; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
255 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
256 if (!predictor_coef_num) { |
5365 | 257 if (output_size <= 1) |
258 return; | |
259 | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
260 memcpy(buffer_out+1, error_buffer+1, (output_size-1) * 4); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
261 return; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
262 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
263 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
264 if (predictor_coef_num == 0x1f) { /* 11111 - max value of predictor_coef_num */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
265 /* second-best case scenario for fir decompression, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
266 * error describes a small difference from the previous sample only |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
267 */ |
5365 | 268 if (output_size <= 1) |
269 return; | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
270 for (i = 0; i < output_size - 1; i++) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
271 int32_t prev_value; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
272 int32_t error_value; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
273 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
274 prev_value = buffer_out[i]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
275 error_value = error_buffer[i+1]; |
5365 | 276 buffer_out[i+1] = |
9097 | 277 sign_extend((prev_value + error_value), readsamplesize); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
278 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
279 return; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
280 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
281 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
282 /* read warm-up samples */ |
5365 | 283 if (predictor_coef_num > 0) |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
284 for (i = 0; i < predictor_coef_num; i++) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
285 int32_t val; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
286 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
287 val = buffer_out[i] + error_buffer[i+1]; |
9097 | 288 val = sign_extend(val, readsamplesize); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
289 buffer_out[i+1] = val; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
290 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
291 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
292 #if 0 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
293 /* 4 and 8 are very common cases (the only ones i've seen). these |
5963 | 294 * should be unrolled and optimized |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
295 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
296 if (predictor_coef_num == 4) { |
5963 | 297 /* FIXME: optimized general case */ |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
298 return; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
299 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
300 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
301 if (predictor_coef_table == 8) { |
5963 | 302 /* FIXME: optimized general case */ |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
303 return; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
304 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
305 #endif |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
306 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
307 /* general case */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
308 if (predictor_coef_num > 0) { |
5365 | 309 for (i = predictor_coef_num + 1; i < output_size; i++) { |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
310 int j; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
311 int sum = 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
312 int outval; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
313 int error_val = error_buffer[i]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
314 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
315 for (j = 0; j < predictor_coef_num; j++) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
316 sum += (buffer_out[predictor_coef_num-j] - buffer_out[0]) * |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
317 predictor_coef_table[j]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
318 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
319 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
320 outval = (1 << (predictor_quantitization-1)) + sum; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
321 outval = outval >> predictor_quantitization; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
322 outval = outval + buffer_out[0] + error_val; |
9097 | 323 outval = sign_extend(outval, readsamplesize); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
324 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
325 buffer_out[predictor_coef_num+1] = outval; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
326 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
327 if (error_val > 0) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
328 int predictor_num = predictor_coef_num - 1; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
329 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
330 while (predictor_num >= 0 && error_val > 0) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
331 int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num]; |
5616 | 332 int sign = sign_only(val); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
333 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
334 predictor_coef_table[predictor_num] -= sign; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
335 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
336 val *= sign; /* absolute value */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
337 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
338 error_val -= ((val >> predictor_quantitization) * |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
339 (predictor_coef_num - predictor_num)); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
340 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
341 predictor_num--; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
342 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
343 } else if (error_val < 0) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
344 int predictor_num = predictor_coef_num - 1; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
345 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
346 while (predictor_num >= 0 && error_val < 0) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
347 int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num]; |
5616 | 348 int sign = - sign_only(val); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
349 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
350 predictor_coef_table[predictor_num] -= sign; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
351 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
352 val *= sign; /* neg value */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
353 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
354 error_val -= ((val >> predictor_quantitization) * |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
355 (predictor_coef_num - predictor_num)); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
356 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
357 predictor_num--; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
358 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
359 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
360 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
361 buffer_out++; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
362 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
363 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
364 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
365 |
5504 | 366 static void reconstruct_stereo_16(int32_t *buffer[MAX_CHANNELS], |
5505 | 367 int16_t *buffer_out, |
368 int numchannels, int numsamples, | |
369 uint8_t interlacing_shift, | |
370 uint8_t interlacing_leftweight) | |
2543
e8f1f57215ad
do not use a variable before proper initialization
melanson
parents:
2542
diff
changeset
|
371 { |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
372 int i; |
5365 | 373 if (numsamples <= 0) |
374 return; | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
375 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
376 /* weighted interlacing */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
377 if (interlacing_leftweight) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
378 for (i = 0; i < numsamples; i++) { |
5372 | 379 int32_t a, b; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
380 |
5372 | 381 a = buffer[0][i]; |
382 b = buffer[1][i]; | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
383 |
5372 | 384 a -= (b * interlacing_leftweight) >> interlacing_shift; |
385 b += a; | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
386 |
5372 | 387 buffer_out[i*numchannels] = b; |
388 buffer_out[i*numchannels + 1] = a; | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
389 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
390 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
391 return; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
392 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
393 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
394 /* otherwise basic interlacing took place */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
395 for (i = 0; i < numsamples; i++) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
396 int16_t left, right; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
397 |
5368
a31f6ae7e83d
Make deinterlace_16 receive an array as a parameter and not two separated vars
vitor
parents:
5367
diff
changeset
|
398 left = buffer[0][i]; |
a31f6ae7e83d
Make deinterlace_16 receive an array as a parameter and not two separated vars
vitor
parents:
5367
diff
changeset
|
399 right = buffer[1][i]; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
400 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
401 buffer_out[i*numchannels] = left; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
402 buffer_out[i*numchannels + 1] = right; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
403 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
404 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
405 |
11077 | 406 static void decorrelate_stereo_24(int32_t *buffer[MAX_CHANNELS], |
407 int32_t *buffer_out, | |
408 int32_t *wasted_bits_buffer[MAX_CHANNELS], | |
409 int wasted_bits, | |
410 int numchannels, int numsamples, | |
411 uint8_t interlacing_shift, | |
412 uint8_t interlacing_leftweight) | |
413 { | |
414 int i; | |
415 | |
416 if (numsamples <= 0) | |
417 return; | |
418 | |
419 /* weighted interlacing */ | |
420 if (interlacing_leftweight) { | |
421 for (i = 0; i < numsamples; i++) { | |
422 int32_t a, b; | |
423 | |
424 a = buffer[0][i]; | |
425 b = buffer[1][i]; | |
426 | |
427 a -= (b * interlacing_leftweight) >> interlacing_shift; | |
428 b += a; | |
429 | |
430 if (wasted_bits) { | |
431 b = (b << wasted_bits) | wasted_bits_buffer[0][i]; | |
432 a = (a << wasted_bits) | wasted_bits_buffer[1][i]; | |
433 } | |
434 | |
435 buffer_out[i * numchannels] = b << 8; | |
436 buffer_out[i * numchannels + 1] = a << 8; | |
437 } | |
438 } else { | |
439 for (i = 0; i < numsamples; i++) { | |
440 int32_t left, right; | |
441 | |
442 left = buffer[0][i]; | |
443 right = buffer[1][i]; | |
444 | |
445 if (wasted_bits) { | |
446 left = (left << wasted_bits) | wasted_bits_buffer[0][i]; | |
447 right = (right << wasted_bits) | wasted_bits_buffer[1][i]; | |
448 } | |
449 | |
450 buffer_out[i * numchannels] = left << 8; | |
451 buffer_out[i * numchannels + 1] = right << 8; | |
452 } | |
453 } | |
454 } | |
455 | |
2544
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
456 static int alac_decode_frame(AVCodecContext *avctx, |
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
457 void *outbuffer, int *outputsize, |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9102
diff
changeset
|
458 AVPacket *avpkt) |
2543
e8f1f57215ad
do not use a variable before proper initialization
melanson
parents:
2542
diff
changeset
|
459 { |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9102
diff
changeset
|
460 const uint8_t *inbuffer = avpkt->data; |
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9102
diff
changeset
|
461 int input_buffer_size = avpkt->size; |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
462 ALACContext *alac = avctx->priv_data; |
2544
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
463 |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
464 int channels; |
6743 | 465 unsigned int outputsamples; |
5271 | 466 int hassize; |
7660
6fe7ff34a4db
alac : check readsamplesize to ensure get_bits() doesn't
jai_menon
parents:
7451
diff
changeset
|
467 unsigned int readsamplesize; |
5271 | 468 int isnotcompressed; |
5358 | 469 uint8_t interlacing_shift; |
470 uint8_t interlacing_leftweight; | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
471 |
2544
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
472 /* short-circuit null buffers */ |
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
473 if (!inbuffer || !input_buffer_size) |
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
474 return input_buffer_size; |
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
475 |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
476 /* initialize from the extradata */ |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
477 if (!alac->context_initialized) { |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
478 if (alac->avctx->extradata_size != ALAC_EXTRADATA_SIZE) { |
3135 | 479 av_log(avctx, AV_LOG_ERROR, "alac: expected %d extradata bytes\n", |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
480 ALAC_EXTRADATA_SIZE); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
481 return input_buffer_size; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
482 } |
4226
43ebe9279fa0
fix some potential security issues, patch by Matthias Hopf, mat at mshopf dot de
bcoudurier
parents:
3947
diff
changeset
|
483 if (alac_set_info(alac)) { |
43ebe9279fa0
fix some potential security issues, patch by Matthias Hopf, mat at mshopf dot de
bcoudurier
parents:
3947
diff
changeset
|
484 av_log(avctx, AV_LOG_ERROR, "alac: set_info failed\n"); |
43ebe9279fa0
fix some potential security issues, patch by Matthias Hopf, mat at mshopf dot de
bcoudurier
parents:
3947
diff
changeset
|
485 return input_buffer_size; |
43ebe9279fa0
fix some potential security issues, patch by Matthias Hopf, mat at mshopf dot de
bcoudurier
parents:
3947
diff
changeset
|
486 } |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
487 alac->context_initialized = 1; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
488 } |
2543
e8f1f57215ad
do not use a variable before proper initialization
melanson
parents:
2542
diff
changeset
|
489 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
490 init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
491 |
5298
e00f7048c50c
Make "channels" variable mean the number of channels, not the number of
vitor
parents:
5292
diff
changeset
|
492 channels = get_bits(&alac->gb, 3) + 1; |
5362 | 493 if (channels > MAX_CHANNELS) { |
494 av_log(avctx, AV_LOG_ERROR, "channels > %d not supported\n", | |
495 MAX_CHANNELS); | |
496 return input_buffer_size; | |
497 } | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
498 |
5361 | 499 /* 2^result = something to do with output waiting. |
500 * perhaps matters if we read > 1 frame in a pass? | |
501 */ | |
5518 | 502 skip_bits(&alac->gb, 4); |
5361 | 503 |
5518 | 504 skip_bits(&alac->gb, 12); /* unknown, skip 12 bits */ |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
505 |
5361 | 506 /* the output sample size is stored soon */ |
5513 | 507 hassize = get_bits1(&alac->gb); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
508 |
11077 | 509 alac->wasted_bits = get_bits(&alac->gb, 2) << 3; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
510 |
5361 | 511 /* whether the frame is compressed */ |
5513 | 512 isnotcompressed = get_bits1(&alac->gb); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
513 |
5361 | 514 if (hassize) { |
515 /* now read the number of samples as a 32bit integer */ | |
6773 | 516 outputsamples = get_bits_long(&alac->gb, 32); |
6743 | 517 if(outputsamples > alac->setinfo_max_samples_per_frame){ |
518 av_log(avctx, AV_LOG_ERROR, "outputsamples %d > %d\n", outputsamples, alac->setinfo_max_samples_per_frame); | |
519 return -1; | |
520 } | |
5361 | 521 } else |
522 outputsamples = alac->setinfo_max_samples_per_frame; | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
523 |
11077 | 524 switch (alac->setinfo_sample_size) { |
525 case 16: avctx->sample_fmt = SAMPLE_FMT_S16; | |
526 alac->bytespersample = channels << 1; | |
527 break; | |
528 case 24: avctx->sample_fmt = SAMPLE_FMT_S32; | |
529 alac->bytespersample = channels << 2; | |
530 break; | |
531 default: av_log(avctx, AV_LOG_ERROR, "Sample depth %d is not supported.\n", | |
532 alac->setinfo_sample_size); | |
533 return -1; | |
534 } | |
535 | |
6744 | 536 if(outputsamples > *outputsize / alac->bytespersample){ |
537 av_log(avctx, AV_LOG_ERROR, "sample buffer too small\n"); | |
538 return -1; | |
539 } | |
540 | |
5361 | 541 *outputsize = outputsamples * alac->bytespersample; |
11077 | 542 readsamplesize = alac->setinfo_sample_size - (alac->wasted_bits) + channels - 1; |
7660
6fe7ff34a4db
alac : check readsamplesize to ensure get_bits() doesn't
jai_menon
parents:
7451
diff
changeset
|
543 if (readsamplesize > MIN_CACHE_BITS) { |
6fe7ff34a4db
alac : check readsamplesize to ensure get_bits() doesn't
jai_menon
parents:
7451
diff
changeset
|
544 av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\n", readsamplesize); |
6fe7ff34a4db
alac : check readsamplesize to ensure get_bits() doesn't
jai_menon
parents:
7451
diff
changeset
|
545 return -1; |
6fe7ff34a4db
alac : check readsamplesize to ensure get_bits() doesn't
jai_menon
parents:
7451
diff
changeset
|
546 } |
5271 | 547 |
5361 | 548 if (!isnotcompressed) { |
549 /* so it is compressed */ | |
550 int16_t predictor_coef_table[channels][32]; | |
551 int predictor_coef_num[channels]; | |
552 int prediction_type[channels]; | |
553 int prediction_quantitization[channels]; | |
554 int ricemodifier[channels]; | |
555 int i, chan; | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
556 |
5361 | 557 interlacing_shift = get_bits(&alac->gb, 8); |
558 interlacing_leftweight = get_bits(&alac->gb, 8); | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
559 |
5361 | 560 for (chan = 0; chan < channels; chan++) { |
5357
07c6fa478918
Remove code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5298
diff
changeset
|
561 prediction_type[chan] = get_bits(&alac->gb, 4); |
07c6fa478918
Remove code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5298
diff
changeset
|
562 prediction_quantitization[chan] = get_bits(&alac->gb, 4); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
563 |
5357
07c6fa478918
Remove code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5298
diff
changeset
|
564 ricemodifier[chan] = get_bits(&alac->gb, 3); |
07c6fa478918
Remove code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5298
diff
changeset
|
565 predictor_coef_num[chan] = get_bits(&alac->gb, 5); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
566 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
567 /* read the predictor table */ |
5365 | 568 for (i = 0; i < predictor_coef_num[chan]; i++) |
5357
07c6fa478918
Remove code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5298
diff
changeset
|
569 predictor_coef_table[chan][i] = (int16_t)get_bits(&alac->gb, 16); |
5361 | 570 } |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
571 |
11077 | 572 if (alac->wasted_bits) { |
573 int i, ch; | |
574 for (i = 0; i < outputsamples; i++) { | |
575 for (ch = 0; ch < channels; ch++) | |
576 alac->wasted_bits_buffer[ch][i] = get_bits(&alac->gb, alac->wasted_bits); | |
577 } | |
578 } | |
5361 | 579 for (chan = 0; chan < channels; chan++) { |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
580 bastardized_rice_decompress(alac, |
5357
07c6fa478918
Remove code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5298
diff
changeset
|
581 alac->predicterror_buffer[chan], |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
582 outputsamples, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
583 readsamplesize, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
584 alac->setinfo_rice_initialhistory, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
585 alac->setinfo_rice_kmodifier, |
5357
07c6fa478918
Remove code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5298
diff
changeset
|
586 ricemodifier[chan] * alac->setinfo_rice_historymult / 4, |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
587 (1 << alac->setinfo_rice_kmodifier) - 1); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
588 |
5357
07c6fa478918
Remove code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5298
diff
changeset
|
589 if (prediction_type[chan] == 0) { |
5361 | 590 /* adaptive fir */ |
5357
07c6fa478918
Remove code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5298
diff
changeset
|
591 predictor_decompress_fir_adapt(alac->predicterror_buffer[chan], |
07c6fa478918
Remove code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5298
diff
changeset
|
592 alac->outputsamples_buffer[chan], |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
593 outputsamples, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
594 readsamplesize, |
5357
07c6fa478918
Remove code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5298
diff
changeset
|
595 predictor_coef_table[chan], |
07c6fa478918
Remove code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5298
diff
changeset
|
596 predictor_coef_num[chan], |
07c6fa478918
Remove code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5298
diff
changeset
|
597 prediction_quantitization[chan]); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
598 } else { |
5357
07c6fa478918
Remove code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5298
diff
changeset
|
599 av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type[chan]); |
5366 | 600 /* I think the only other prediction type (or perhaps this is |
601 * just a boolean?) runs adaptive fir twice.. like: | |
5359
4743a1e95531
Remove more code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5358
diff
changeset
|
602 * predictor_decompress_fir_adapt(predictor_error, tempout, ...) |
4743a1e95531
Remove more code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5358
diff
changeset
|
603 * predictor_decompress_fir_adapt(predictor_error, outputsamples ...) |
4743a1e95531
Remove more code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5358
diff
changeset
|
604 * little strange.. |
4743a1e95531
Remove more code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5358
diff
changeset
|
605 */ |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
606 } |
5361 | 607 } |
608 } else { | |
609 /* not compressed, easy case */ | |
6779
a25842a4df43
cosmetics: indent after last commit. patch by matthieu castet <castet matthieu free fr>.
jbr
parents:
6778
diff
changeset
|
610 int i, chan; |
11077 | 611 if (alac->setinfo_sample_size <= 16) { |
7043
e1ed057dc7c3
fix verbatim mode decoding. patch by Jai Menon (realityman gmx net).
jbr
parents:
7040
diff
changeset
|
612 for (i = 0; i < outputsamples; i++) |
e1ed057dc7c3
fix verbatim mode decoding. patch by Jai Menon (realityman gmx net).
jbr
parents:
7040
diff
changeset
|
613 for (chan = 0; chan < channels; chan++) { |
6779
a25842a4df43
cosmetics: indent after last commit. patch by matthieu castet <castet matthieu free fr>.
jbr
parents:
6778
diff
changeset
|
614 int32_t audiobits; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
615 |
9102
42a7dfa5b3e4
alacdec: Simplify reading of uncompressed samples by using
jbr
parents:
9097
diff
changeset
|
616 audiobits = get_sbits_long(&alac->gb, alac->setinfo_sample_size); |
5359
4743a1e95531
Remove more code duplication. Based on a patch by Matthieu Castet.
vitor
parents:
5358
diff
changeset
|
617 |
6779
a25842a4df43
cosmetics: indent after last commit. patch by matthieu castet <castet matthieu free fr>.
jbr
parents:
6778
diff
changeset
|
618 alac->outputsamples_buffer[chan][i] = audiobits; |
a25842a4df43
cosmetics: indent after last commit. patch by matthieu castet <castet matthieu free fr>.
jbr
parents:
6778
diff
changeset
|
619 } |
11077 | 620 } else { |
621 for (i = 0; i < outputsamples; i++) { | |
622 for (chan = 0; chan < channels; chan++) { | |
623 alac->outputsamples_buffer[chan][i] = get_bits(&alac->gb, | |
624 alac->setinfo_sample_size); | |
625 alac->outputsamples_buffer[chan][i] = sign_extend(alac->outputsamples_buffer[chan][i], | |
626 alac->setinfo_sample_size); | |
627 } | |
628 } | |
629 } | |
630 alac->wasted_bits = 0; | |
5361 | 631 interlacing_shift = 0; |
632 interlacing_leftweight = 0; | |
633 } | |
6641 | 634 if (get_bits(&alac->gb, 3) != 7) |
635 av_log(avctx, AV_LOG_ERROR, "Error : Wrong End Of Frame\n"); | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
636 |
5361 | 637 switch(alac->setinfo_sample_size) { |
5400 | 638 case 16: |
5361 | 639 if (channels == 2) { |
5504 | 640 reconstruct_stereo_16(alac->outputsamples_buffer, |
5506 | 641 (int16_t*)outbuffer, |
642 alac->numchannels, | |
643 outputsamples, | |
644 interlacing_shift, | |
645 interlacing_leftweight); | |
5361 | 646 } else { |
647 int i; | |
648 for (i = 0; i < outputsamples; i++) { | |
11081 | 649 ((int16_t*)outbuffer)[i] = alac->outputsamples_buffer[0][i]; |
5361 | 650 } |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
651 } |
5361 | 652 break; |
653 case 24: | |
11077 | 654 if (channels == 2) { |
655 decorrelate_stereo_24(alac->outputsamples_buffer, | |
656 outbuffer, | |
657 alac->wasted_bits_buffer, | |
658 alac->wasted_bits, | |
659 alac->numchannels, | |
660 outputsamples, | |
661 interlacing_shift, | |
662 interlacing_leftweight); | |
663 } else { | |
664 int i; | |
665 for (i = 0; i < outputsamples; i++) | |
666 ((int32_t *)outbuffer)[i] = alac->outputsamples_buffer[0][i] << 8; | |
667 } | |
5361 | 668 break; |
669 } | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
670 |
6641 | 671 if (input_buffer_size * 8 - get_bits_count(&alac->gb) > 8) |
672 av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n", input_buffer_size * 8 - get_bits_count(&alac->gb)); | |
673 | |
2544
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
674 return input_buffer_size; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
675 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
676 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6221
diff
changeset
|
677 static av_cold int alac_decode_init(AVCodecContext * avctx) |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
678 { |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
679 ALACContext *alac = avctx->priv_data; |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
680 alac->avctx = avctx; |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
681 alac->context_initialized = 0; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
682 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
683 alac->numchannels = alac->avctx->channels; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
684 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
685 return 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
686 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
687 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6221
diff
changeset
|
688 static av_cold int alac_decode_close(AVCodecContext *avctx) |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
689 { |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
690 ALACContext *alac = avctx->priv_data; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
691 |
5272 | 692 int chan; |
693 for (chan = 0; chan < MAX_CHANNELS; chan++) { | |
11079 | 694 av_freep(&alac->predicterror_buffer[chan]); |
695 av_freep(&alac->outputsamples_buffer[chan]); | |
11077 | 696 av_freep(&alac->wasted_bits_buffer[chan]); |
5272 | 697 } |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
698 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
699 return 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
700 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
701 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
702 AVCodec alac_decoder = { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
703 "alac", |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
704 CODEC_TYPE_AUDIO, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
705 CODEC_ID_ALAC, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
706 sizeof(ALACContext), |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
707 alac_decode_init, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
708 NULL, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
709 alac_decode_close, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
710 alac_decode_frame, |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6779
diff
changeset
|
711 .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"), |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
712 }; |