Mercurial > libavcodec.hg
annotate shorten.c @ 12455:14f85520cd02 libavcodec
Fix the dependencies of the RTP muxer
This fixes building with --disable-everything --enable-muxer=rtp, closing
issue 2159.
author | mstorsjo |
---|---|
date | Fri, 03 Sep 2010 21:13:01 +0000 |
parents | 8b28e74de2c0 |
children |
rev | line source |
---|---|
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
1 /* |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
2 * Shorten decoder |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
3 * Copyright (c) 2005 Jeff Muizelaar |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
4 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3303
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3303
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3303
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
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:
3303
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3303
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
16 * |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
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:
3303
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:
2525
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
20 */ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
21 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
22 /** |
11644
7dd2a45249a9
Remove explicit filename from Doxygen @file commands.
diego
parents:
11560
diff
changeset
|
23 * @file |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
24 * Shorten decoder |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
25 * @author Jeff Muizelaar |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
26 * |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
27 */ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
28 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
29 #define DEBUG |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
30 #include <limits.h> |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
31 #include "avcodec.h" |
9428 | 32 #include "get_bits.h" |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
33 #include "golomb.h" |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
34 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
35 #define MAX_CHANNELS 8 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
36 #define MAX_BLOCKSIZE 65535 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
37 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
38 #define OUT_BUFFER_SIZE 16384 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
39 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
40 #define ULONGSIZE 2 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
41 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
42 #define WAVE_FORMAT_PCM 0x0001 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
43 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
44 #define DEFAULT_BLOCK_SIZE 256 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
45 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
46 #define TYPESIZE 4 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
47 #define CHANSIZE 0 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
48 #define LPCQSIZE 2 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
49 #define ENERGYSIZE 3 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
50 #define BITSHIFTSIZE 2 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
51 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
52 #define TYPE_S16HL 3 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
53 #define TYPE_S16LH 5 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
54 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
55 #define NWRAP 3 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
56 #define NSKIPSIZE 1 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
57 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
58 #define LPCQUANT 5 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
59 #define V2LPCQOFFSET (1 << LPCQUANT) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
60 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
61 #define FNSIZE 2 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
62 #define FN_DIFF0 0 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
63 #define FN_DIFF1 1 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
64 #define FN_DIFF2 2 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
65 #define FN_DIFF3 3 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
66 #define FN_QUIT 4 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
67 #define FN_BLOCKSIZE 5 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
68 #define FN_BITSHIFT 6 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
69 #define FN_QLPC 7 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
70 #define FN_ZERO 8 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
71 #define FN_VERBATIM 9 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
72 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
73 #define VERBATIM_CKSIZE_SIZE 5 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
74 #define VERBATIM_BYTE_SIZE 8 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
75 #define CANONICAL_HEADER_SIZE 44 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
76 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
77 typedef struct ShortenContext { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
78 AVCodecContext *avctx; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
79 GetBitContext gb; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
80 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
81 int min_framesize, max_framesize; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
82 int channels; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
83 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
84 int32_t *decoded[MAX_CHANNELS]; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
85 int32_t *offset[MAX_CHANNELS]; |
11964 | 86 int *coeffs; |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
87 uint8_t *bitstream; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
88 int bitstream_size; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
89 int bitstream_index; |
3066
04b924f8f5a5
warning fixes by Luca Abeni, lucabe72 ##@## email ##.## it
diego
parents:
3036
diff
changeset
|
90 unsigned int allocated_bitstream_size; |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
91 int header_size; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
92 uint8_t header[OUT_BUFFER_SIZE]; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
93 int version; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
94 int cur_chan; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
95 int bitshift; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
96 int nmean; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
97 int internal_ftype; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
98 int nwrap; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
99 int blocksize; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
100 int bitindex; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
101 int32_t lpcqoffset; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
102 } ShortenContext; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
103 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6249
diff
changeset
|
104 static av_cold int shorten_decode_init(AVCodecContext * avctx) |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
105 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
106 ShortenContext *s = avctx->priv_data; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
107 s->avctx = avctx; |
7451
85ab7655ad4d
Modify all codecs to report their supported input and output sample format(s).
pross
parents:
7040
diff
changeset
|
108 avctx->sample_fmt = SAMPLE_FMT_S16; |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
109 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
110 return 0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
111 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
112 |
3303
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3066
diff
changeset
|
113 static int allocate_buffers(ShortenContext *s) |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
114 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
115 int i, chan; |
11964 | 116 int *coeffs; |
117 | |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
118 for (chan=0; chan<s->channels; chan++) { |
3303
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3066
diff
changeset
|
119 if(FFMAX(1, s->nmean) >= UINT_MAX/sizeof(int32_t)){ |
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3066
diff
changeset
|
120 av_log(s->avctx, AV_LOG_ERROR, "nmean too large\n"); |
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3066
diff
changeset
|
121 return -1; |
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3066
diff
changeset
|
122 } |
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3066
diff
changeset
|
123 if(s->blocksize + s->nwrap >= UINT_MAX/sizeof(int32_t) || s->blocksize + s->nwrap <= (unsigned)s->nwrap){ |
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3066
diff
changeset
|
124 av_log(s->avctx, AV_LOG_ERROR, "s->blocksize + s->nwrap too large\n"); |
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3066
diff
changeset
|
125 return -1; |
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3066
diff
changeset
|
126 } |
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3066
diff
changeset
|
127 |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
128 s->offset[chan] = av_realloc(s->offset[chan], sizeof(int32_t)*FFMAX(1, s->nmean)); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
129 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
130 s->decoded[chan] = av_realloc(s->decoded[chan], sizeof(int32_t)*(s->blocksize + s->nwrap)); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
131 for (i=0; i<s->nwrap; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
132 s->decoded[chan][i] = 0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
133 s->decoded[chan] += s->nwrap; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
134 } |
11964 | 135 |
136 coeffs = av_realloc(s->coeffs, s->nwrap * sizeof(*s->coeffs)); | |
137 if (!coeffs) | |
138 return AVERROR(ENOMEM); | |
139 s->coeffs = coeffs; | |
140 | |
3303
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3066
diff
changeset
|
141 return 0; |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
142 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
143 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
144 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
145 static inline unsigned int get_uint(ShortenContext *s, int k) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
146 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
147 if (s->version != 0) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
148 k = get_ur_golomb_shorten(&s->gb, ULONGSIZE); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
149 return get_ur_golomb_shorten(&s->gb, k); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
150 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
151 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
152 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
153 static void fix_bitshift(ShortenContext *s, int32_t *buffer) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
154 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
155 int i; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
156 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
157 if (s->bitshift != 0) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
158 for (i = 0; i < s->blocksize; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
159 buffer[s->nwrap + i] <<= s->bitshift; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
160 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
161 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
162 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
163 static void init_offset(ShortenContext *s) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
164 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
165 int32_t mean = 0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
166 int chan, i; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
167 int nblock = FFMAX(1, s->nmean); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
168 /* initialise offset */ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
169 switch (s->internal_ftype) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
170 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
171 case TYPE_S16HL: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
172 case TYPE_S16LH: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
173 mean = 0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
174 break; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
175 default: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
176 av_log(s->avctx, AV_LOG_ERROR, "unknown audio type"); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
177 abort(); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
178 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
179 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
180 for (chan = 0; chan < s->channels; chan++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
181 for (i = 0; i < nblock; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
182 s->offset[chan][i] = mean; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
183 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
184 |
4908
777f250df232
Fix multiple "¡Æinline/static¡Ç is not at beginning of declaration" warnings.
diego
parents:
4734
diff
changeset
|
185 static inline int get_le32(GetBitContext *gb) |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
186 { |
12129 | 187 return av_bswap32(get_bits_long(gb, 32)); |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
188 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
189 |
4908
777f250df232
Fix multiple "¡Æinline/static¡Ç is not at beginning of declaration" warnings.
diego
parents:
4734
diff
changeset
|
190 static inline short get_le16(GetBitContext *gb) |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
191 { |
12129 | 192 return av_bswap16(get_bits_long(gb, 16)); |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
193 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
194 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
195 static int decode_wave_header(AVCodecContext *avctx, uint8_t *header, int header_size) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
196 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
197 GetBitContext hb; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
198 int len; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
199 int chunk_size; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
200 short wave_format; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
201 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
202 init_get_bits(&hb, header, header_size*8); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
203 if (get_le32(&hb) != MKTAG('R','I','F','F')) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
204 av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n"); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
205 return -1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
206 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
207 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
208 chunk_size = get_le32(&hb); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
209 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
210 if (get_le32(&hb) != MKTAG('W','A','V','E')) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
211 av_log(avctx, AV_LOG_ERROR, "missing WAVE tag\n"); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
212 return -1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
213 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
214 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
215 while (get_le32(&hb) != MKTAG('f','m','t',' ')) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
216 len = get_le32(&hb); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
217 skip_bits(&hb, 8*len); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
218 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
219 len = get_le32(&hb); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
220 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
221 if (len < 16) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
222 av_log(avctx, AV_LOG_ERROR, "fmt chunk was too short\n"); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
223 return -1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
224 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
225 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
226 wave_format = get_le16(&hb); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
227 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
228 switch (wave_format) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
229 case WAVE_FORMAT_PCM: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
230 break; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
231 default: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
232 av_log(avctx, AV_LOG_ERROR, "unsupported wave format\n"); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
233 return -1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
234 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
235 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
236 avctx->channels = get_le16(&hb); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
237 avctx->sample_rate = get_le32(&hb); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
238 avctx->bit_rate = get_le32(&hb) * 8; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
239 avctx->block_align = get_le16(&hb); |
7823
4525dcd81357
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
7451
diff
changeset
|
240 avctx->bits_per_coded_sample = get_le16(&hb); |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
241 |
7823
4525dcd81357
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
7451
diff
changeset
|
242 if (avctx->bits_per_coded_sample != 16) { |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
243 av_log(avctx, AV_LOG_ERROR, "unsupported number of bits per sample\n"); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
244 return -1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
245 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
246 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
247 len -= 16; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
248 if (len > 0) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
249 av_log(avctx, AV_LOG_INFO, "%d header bytes unparsed\n", len); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
250 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
251 return 0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
252 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
253 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
254 static int16_t * interleave_buffer(int16_t *samples, int nchan, int blocksize, int32_t **buffer) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
255 int i, chan; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
256 for (i=0; i<blocksize; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
257 for (chan=0; chan < nchan; chan++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
258 *samples++ = FFMIN(buffer[chan][i], 32768); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
259 return samples; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
260 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
261 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
262 static void decode_subframe_lpc(ShortenContext *s, int channel, int residual_size, int pred_order) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
263 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
264 int sum, i, j; |
11964 | 265 int *coeffs = s->coeffs; |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
266 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
267 for (i=0; i<pred_order; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
268 coeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
269 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
270 for (i=0; i < s->blocksize; i++) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
271 sum = s->lpcqoffset; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
272 for (j=0; j<pred_order; j++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
273 sum += coeffs[j] * s->decoded[channel][i-j-1]; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
274 s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + (sum >> LPCQUANT); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
275 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
276 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
277 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
278 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
279 static int shorten_decode_frame(AVCodecContext *avctx, |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
280 void *data, int *data_size, |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
281 AVPacket *avpkt) |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
282 { |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
283 const uint8_t *buf = avpkt->data; |
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
284 int buf_size = avpkt->size; |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
285 ShortenContext *s = avctx->priv_data; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
286 int i, input_buf_size = 0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
287 int16_t *samples = data; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
288 if(s->max_framesize == 0){ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
289 s->max_framesize= 1024; // should hopefully be enough for the first header |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
290 s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
291 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
292 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
293 if(1 && s->max_framesize){//FIXME truncated |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
294 buf_size= FFMIN(buf_size, s->max_framesize - s->bitstream_size); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
295 input_buf_size= buf_size; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
296 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
297 if(s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size){ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
298 // printf("memmove\n"); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
299 memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
300 s->bitstream_index=0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
301 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
302 memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
303 buf= &s->bitstream[s->bitstream_index]; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
304 buf_size += s->bitstream_size; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
305 s->bitstream_size= buf_size; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
306 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
307 if(buf_size < s->max_framesize){ |
4652 | 308 //dprintf(avctx, "wanna more data ... %d\n", buf_size); |
4734
d2db36185222
properly set *data_size when returning >= 0 values in shorten_decode_frame()
aurel
parents:
4652
diff
changeset
|
309 *data_size = 0; |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
310 return input_buf_size; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
311 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
312 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
313 init_get_bits(&s->gb, buf, buf_size*8); |
5518 | 314 skip_bits(&s->gb, s->bitindex); |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
315 if (!s->blocksize) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
316 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
317 int maxnlpc = 0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
318 /* shorten signature */ |
8715 | 319 if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) { |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
320 av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n"); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
321 return -1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
322 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
323 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
324 s->lpcqoffset = 0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
325 s->blocksize = DEFAULT_BLOCK_SIZE; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
326 s->channels = 1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
327 s->nmean = -1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
328 s->version = get_bits(&s->gb, 8); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
329 s->internal_ftype = get_uint(s, TYPESIZE); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
330 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
331 s->channels = get_uint(s, CHANSIZE); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
332 if (s->channels > MAX_CHANNELS) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
333 av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
334 return -1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
335 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
336 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
337 /* get blocksize if version > 0 */ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
338 if (s->version > 0) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
339 int skip_bytes; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
340 s->blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE)); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
341 maxnlpc = get_uint(s, LPCQSIZE); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
342 s->nmean = get_uint(s, 0); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
343 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
344 skip_bytes = get_uint(s, NSKIPSIZE); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
345 for (i=0; i<skip_bytes; i++) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
346 skip_bits(&s->gb, 8); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
347 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
348 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
349 s->nwrap = FFMAX(NWRAP, maxnlpc); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
350 |
4226
43ebe9279fa0
fix some potential security issues, patch by Matthias Hopf, mat at mshopf dot de
bcoudurier
parents:
3947
diff
changeset
|
351 if (allocate_buffers(s)) |
43ebe9279fa0
fix some potential security issues, patch by Matthias Hopf, mat at mshopf dot de
bcoudurier
parents:
3947
diff
changeset
|
352 return -1; |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
353 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
354 init_offset(s); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
355 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
356 if (s->version > 1) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
357 s->lpcqoffset = V2LPCQOFFSET; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
358 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
359 if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) { |
6068 | 360 av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at beginning of stream\n"); |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
361 return -1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
362 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
363 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
364 s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
365 if (s->header_size >= OUT_BUFFER_SIZE || s->header_size < CANONICAL_HEADER_SIZE) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
366 av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n", s->header_size); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
367 return -1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
368 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
369 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
370 for (i=0; i<s->header_size; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
371 s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
372 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
373 if (decode_wave_header(avctx, s->header, s->header_size) < 0) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
374 return -1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
375 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
376 s->cur_chan = 0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
377 s->bitshift = 0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
378 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
379 else |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
380 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
381 int cmd; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
382 int len; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
383 cmd = get_ur_golomb_shorten(&s->gb, FNSIZE); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
384 switch (cmd) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
385 case FN_ZERO: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
386 case FN_DIFF0: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
387 case FN_DIFF1: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
388 case FN_DIFF2: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
389 case FN_DIFF3: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
390 case FN_QLPC: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
391 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
392 int residual_size = 0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
393 int channel = s->cur_chan; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
394 int32_t coffset; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
395 if (cmd != FN_ZERO) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
396 residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
397 /* this is a hack as version 0 differed in defintion of get_sr_golomb_shorten */ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
398 if (s->version == 0) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
399 residual_size--; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
400 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
401 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
402 if (s->nmean == 0) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
403 coffset = s->offset[channel][0]; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
404 else { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
405 int32_t sum = (s->version < 2) ? 0 : s->nmean / 2; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
406 for (i=0; i<s->nmean; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
407 sum += s->offset[channel][i]; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
408 coffset = sum / s->nmean; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
409 if (s->version >= 2) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
410 coffset >>= FFMIN(1, s->bitshift); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
411 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
412 switch (cmd) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
413 case FN_ZERO: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
414 for (i=0; i<s->blocksize; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
415 s->decoded[channel][i] = 0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
416 break; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
417 case FN_DIFF0: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
418 for (i=0; i<s->blocksize; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
419 s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + coffset; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
420 break; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
421 case FN_DIFF1: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
422 for (i=0; i<s->blocksize; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
423 s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + s->decoded[channel][i - 1]; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
424 break; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
425 case FN_DIFF2: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
426 for (i=0; i<s->blocksize; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
427 s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 2*s->decoded[channel][i-1] |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
428 - s->decoded[channel][i-2]; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
429 break; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
430 case FN_DIFF3: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
431 for (i=0; i<s->blocksize; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
432 s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 3*s->decoded[channel][i-1] |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
433 - 3*s->decoded[channel][i-2] |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
434 + s->decoded[channel][i-3]; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
435 break; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
436 case FN_QLPC: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
437 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
438 int pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE); |
11964 | 439 if (pred_order > s->nwrap) { |
440 av_log(avctx, AV_LOG_ERROR, | |
441 "invalid pred_order %d\n", | |
442 pred_order); | |
443 return -1; | |
444 } | |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
445 for (i=0; i<pred_order; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
446 s->decoded[channel][i - pred_order] -= coffset; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
447 decode_subframe_lpc(s, channel, residual_size, pred_order); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
448 if (coffset != 0) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
449 for (i=0; i < s->blocksize; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
450 s->decoded[channel][i] += coffset; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
451 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
452 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
453 if (s->nmean > 0) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
454 int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
455 for (i=0; i<s->blocksize; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
456 sum += s->decoded[channel][i]; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
457 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
458 for (i=1; i<s->nmean; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
459 s->offset[channel][i-1] = s->offset[channel][i]; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
460 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
461 if (s->version < 2) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
462 s->offset[channel][s->nmean - 1] = sum / s->blocksize; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
463 else |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
464 s->offset[channel][s->nmean - 1] = (sum / s->blocksize) << s->bitshift; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
465 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
466 for (i=-s->nwrap; i<0; i++) |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
467 s->decoded[channel][i] = s->decoded[channel][i + s->blocksize]; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
468 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
469 fix_bitshift(s, s->decoded[channel]); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
470 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
471 s->cur_chan++; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
472 if (s->cur_chan == s->channels) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
473 samples = interleave_buffer(samples, s->channels, s->blocksize, s->decoded); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
474 s->cur_chan = 0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
475 goto frame_done; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
476 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
477 break; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
478 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
479 break; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
480 case FN_VERBATIM: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
481 len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
482 while (len--) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
483 get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
484 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
485 break; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
486 case FN_BITSHIFT: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
487 s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
488 break; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
489 case FN_BLOCKSIZE: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
490 s->blocksize = get_uint(s, av_log2(s->blocksize)); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
491 break; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
492 case FN_QUIT: |
4734
d2db36185222
properly set *data_size when returning >= 0 values in shorten_decode_frame()
aurel
parents:
4652
diff
changeset
|
493 *data_size = 0; |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
494 return buf_size; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
495 break; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
496 default: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
497 av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
498 return -1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
499 break; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
500 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
501 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
502 frame_done: |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
503 *data_size = (int8_t *)samples - (int8_t *)data; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
504 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
505 // s->last_blocksize = s->blocksize; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
506 s->bitindex = get_bits_count(&s->gb) - 8*((get_bits_count(&s->gb))/8); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
507 i= (get_bits_count(&s->gb))/8; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
508 if (i > buf_size) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
509 av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
510 s->bitstream_size=0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
511 s->bitstream_index=0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
512 return -1; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
513 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
514 if (s->bitstream_size) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
515 s->bitstream_index += i; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
516 s->bitstream_size -= i; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
517 return input_buf_size; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
518 } else |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
519 return i; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
520 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
521 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6249
diff
changeset
|
522 static av_cold int shorten_decode_close(AVCodecContext *avctx) |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
523 { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
524 ShortenContext *s = avctx->priv_data; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
525 int i; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
526 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
527 for (i = 0; i < s->channels; i++) { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
528 s->decoded[i] -= s->nwrap; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
529 av_freep(&s->decoded[i]); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
530 av_freep(&s->offset[i]); |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
531 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
532 av_freep(&s->bitstream); |
11964 | 533 av_freep(&s->coeffs); |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
534 return 0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
535 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
536 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
537 static void shorten_flush(AVCodecContext *avctx){ |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
538 ShortenContext *s = avctx->priv_data; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
539 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
540 s->bitstream_size= |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
541 s->bitstream_index= 0; |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
542 } |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
543 |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
544 AVCodec shorten_decoder = { |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
545 "shorten", |
11560
8a4984c5cacc
Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents:
9428
diff
changeset
|
546 AVMEDIA_TYPE_AUDIO, |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
547 CODEC_ID_SHORTEN, |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
548 sizeof(ShortenContext), |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
549 shorten_decode_init, |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
550 NULL, |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
551 shorten_decode_close, |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
552 shorten_decode_frame, |
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
553 .flush= shorten_flush, |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6710
diff
changeset
|
554 .long_name= NULL_IF_CONFIG_SMALL("Shorten"), |
2525
b47af698085e
shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents:
diff
changeset
|
555 }; |