FFmpeg: libavcodec/mpc8.c Source File
Go to the documentation of this file. 1 /*
2 * Musepack SV8 decoder
3 * Copyright (c) 2007 Konstantin Shishkov
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * MPEG Audio Layer 1/2 -like codec with frames of 1152 samples
25 * divided into 32 subbands.
26 */
27
36
40
43
45 {
48
51
53 }
54
56 {
60
61 do {
62 n--;
67 k--;
68 }
69 } while(k > 0);
70
72 }
73
75 {
78 }
79
81 {
83
87
89 }
90
92 const uint8_t codes_counts[16],
93 const uint8_t **syms,
int offset)
94 {
97 unsigned num = 0;
98
99 vlc->
table = &vlc_buf[*buf_offset];
101
102 for (
int i = 16;
i > 0;
i--)
103 for (
unsigned tmp = num + codes_counts[
i - 1]; num <
tmp; num++)
105
109 *syms += num;
110 }
111
113 {
118
120
123
124 for (
int i = 0;
i < 2;
i++){
126
128
130
133 &q_syms, -48 - 16 *
i);
134 for (int j = 0; j < 4; j++)
136 &q_syms, -((8 << j) - 1));
137 }
139 }
140
142 {
147
150 return -1;
151 }
152 memset(
c->oldDSCF, 0,
sizeof(
c->oldDSCF));
155
157
158 uint8_t sample_rate_idx =
get_bits(&gb, 3);
159 static const int sample_rates[] = { 44100, 48000, 37800, 32000 };
163 }
166 if (
c->maxbands >=
BANDS) {
169 }
174 }
177
181
183
184 return 0;
185 }
186
188 int *got_frame_ptr,
AVPacket *avpkt)
189 {
190 const uint8_t *buf = avpkt->
data;
191 int buf_size = avpkt->
size;
194 int i, j, k, ch, cnt, res, t;
196 int off;
197 int maxband, keyframe;
198 int last[2];
199
200 keyframe =
c->cur_frame == 0;
201
202 if(keyframe){
203 memset(
c->Q, 0,
sizeof(
c->Q));
204 c->last_bits_used = 0;
205 }
207 return res;
208
210
211 if(keyframe)
213 else{
215 if(maxband > 32) maxband -= 33;
216 }
217
219 *got_frame_ptr = 0;
220 return buf_size;
221 }
222
223 if(maxband >
c->maxbands + 1) {
226 }
227 c->last_max_band = maxband;
228
229 /* read subband indexes */
230 if(maxband){
231 last[0] = last[1] = 0;
232 for(
i = maxband - 1;
i >= 0;
i--){
233 for(ch = 0; ch < 2; ch++){
235 if(last[ch] > 15) last[ch] -= 17;
236 bands[
i].res[ch] = last[ch];
237 }
238 }
241
242 cnt = 0;
243 for(
i = 0;
i < maxband;
i++)
245 cnt++;
248 for(
i = maxband - 1;
i >= 0;
i--)
252 }
253 }
254 }
255 for(
i = maxband;
i <
c->maxbands;
i++)
257
258 if(keyframe){
259 for(
i = 0;
i < 32;
i++)
260 c->oldDSCF[0][
i] =
c->oldDSCF[1][
i] = 1;
261 }
262
263 for(
i = 0;
i < maxband;
i++){
266 if(cnt >= 0){
270 }
271 }
272 }
273
274 for(
i = 0;
i < maxband;
i++){
275 for(ch = 0; ch < 2; ch++){
276 if(!
bands[
i].res[ch])
continue;
277
278 if(
c->oldDSCF[ch][
i]){
280 c->oldDSCF[ch][
i] = 0;
281 }else{
283 if(t == 64)
285 bands[
i].scf_idx[ch][0] = ((
bands[
i].scf_idx[ch][2] + t - 25) & 0x7F) - 6;
286 }
287 for(j = 0; j < 2; j++){
288 if((
bands[
i].scfi[ch] << j) & 2)
290 else{
292 if(t == 31)
294 bands[
i].scf_idx[ch][j + 1] = ((
bands[
i].scf_idx[ch][j] + t - 25) & 0x7F) - 6;
295 }
296 }
297 }
298 }
299
301 for(ch = 0; ch < 2; ch++){
303 switch(res){
304 case -1:
306 c->Q[ch][off + j] = (
av_lfg_get(&
c->rnd) & 0x3FC) - 510;
307 break;
308 case 0:
309 break;
310 case 1:
317 }
318 break;
319 case 2:
320 cnt = 6;//2*mpc8_thres[res]
327 }
328 break;
329 case 3:
330 case 4:
333 c->Q[ch][off + j + 1] = t >> 4;
335 }
336 break;
337 case 5:
338 case 6:
339 case 7:
340 case 8:
345 cnt = (cnt >> 1) +
FFABS(
c->Q[ch][off + j]);
346 }
347 break;
348 default:
351 if(res != 9){
352 c->Q[ch][off + j] <<= res - 9;
353 c->Q[ch][off + j] |=
get_bits(gb, res - 9);
354 }
355 c->Q[ch][off + j] -= (1 << (res - 2)) - 1;
356 }
357 }
358 }
359 }
360
363 return res;
364
366 (int16_t **)
frame->extended_data,
368
370
372 if(
c->cur_frame >=
c->frames)
376 c->last_bits_used = buf_size << 3;
377 }
else if (
c->cur_frame == 0 &&
get_bits_left(gb) < 8) {
// we have only padding left
378 c->last_bits_used = buf_size << 3;
379 }
380
381 *got_frame_ptr = 1;
382
383 return c->cur_frame ?
c->last_bits_used >> 3 : buf_size;
384 }
385
387 {
390 }
391
403 };
static av_cold void mpc8_init_static(void)
int ff_vlc_init_from_lengths(VLC *vlc, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags, void *logctx)
Build VLC decoding tables suitable for use with get_vlc2()
static int get_bits_left(GetBitContext *gb)
int sample_rate
samples per second
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
static av_cold void mpc8_decode_flush(AVCodecContext *avctx)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static const uint8_t mpc8_dscf_len_counts[2][16]
static int get_bits_count(const GetBitContext *s)
av_cold void ff_mpadsp_init(MPADSPContext *s)
static int mpc8_dec_base(GetBitContext *gb, int k, int n)
static const int sample_rates[]
This structure describes decoded (raw) audio or video data.
static const uint16_t table[]
int nb_channels
Number of channels in this layout.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static void skip_bits(GetBitContext *s, int n)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static av_cold void build_vlc(VLC *vlc, unsigned *buf_offset, const uint8_t codes_counts[16], const uint8_t **syms, int offset)
AVCodec p
The public AVCodec.
AVChannelLayout ch_layout
Audio channel layout.
static int mpc8_get_mod_golomb(GetBitContext *gb, int m)
static int mpc8_get_mask(GetBitContext *gb, int size, int t)
void ff_mpc_dequantize_and_synth(MPCContext *c, int maxband, int16_t **out, int channels)
static const uint8_t mpc8_q2_len_counts[2][16]
static const uint8_t mpc8_scfi_len_counts[2][16]
static const uint32_t mpc8_cnk_lost[16][33]
static const uint8_t mpc8_cnk_len[16][33]
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s your new playground is ready Some little details about what s going which in turn will define variables for the build system and the C
static const uint8_t mpc8_q5_8_len_counts[2][4][16]
static int ff_thread_once(char *control, void(*routine)(void))
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define FF_CODEC_DECODE_CB(func)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
static const int8_t mpc8_idx52[125]
static const float bands[]
#define CODEC_LONG_NAME(str)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static const uint8_t mpc8_bands_len_counts[16]
static const uint8_t mpc8_q1_len_counts[16]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
void ff_mpa_synth_init_fixed(void)
const FFCodec ff_mpc8_decoder
static unsigned int get_bits1(GetBitContext *s)
static const int8_t mpc8_huffq2[5 *5 *5]
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static VLC quant_vlc[4][2]
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
static const uint8_t mpc8_q34_len_counts[2][16]
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
static const unsigned int mpc8_thres[]
static const uint8_t mpc8_bands_syms[MPC8_BANDS_SIZE]
static const uint8_t mpc8_q_syms[]
enum AVSampleFormat sample_fmt
audio sample format
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
#define CODEC_SAMPLEFMTS(...)
static const uint32_t mpc8_cnk[16][32]
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
#define i(width, name, range_min, range_max)
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
static const uint8_t mpc8_res_syms[]
static int mpc8_dec_enum(GetBitContext *gb, int k, int n)
static const uint8_t mpc8_dscf_syms[]
const char * name
Name of the codec implementation.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static av_cold int mpc8_decode_init(AVCodecContext *avctx)
main external API structure.
#define VLC_INIT_STATIC_OVERLONG
static const uint8_t mpc8_res_len_counts[2][16]
Subband structure - hold all variables for each subband.
static const int8_t mpc8_idx50[125]
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
static av_const int sign_extend(int val, unsigned bits)
static const uint8_t mpc8_q9up_len_counts[16]
#define avpriv_request_sample(...)
This structure stores compressed data.
#define MPC8_MAX_VLC_SIZE
static const uint8_t mpc8_scfi_syms[]
static const int8_t mpc8_idx51[125]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int mpc8_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Generated on Sat Oct 18 2025 19:22:26 for FFmpeg by
doxygen
1.8.17