~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/wavpack.c

  • Committer: Gauvain Pocentek
  • Date: 2012-03-06 11:59:12 UTC
  • mfrom: (66.1.15 precise)
  • Revision ID: gauvain@pocentek.net-20120306115912-h9d6kt9j0l532oo5
* Merge from Ubuntu:
  - put back faac support
  - recommends apport-hooks-medibuntu
  - change Maintainer, Uploaders & Vcs-* fields.
* New upstream snapshot
* upload to unstable
* Build against external libmpeg2
* drop 51_FTBFS_arm.patch again
* no longer build depend on libcdparanoia-dev on the Hurd
* Fix FTBFS on the hurd.
  Thanks to Samuel Thibault <sthibault@debian.org> (Closes: #654974)
* Fix FTBFS on arm
* New upstream snapshot, Closes: #650339, #643621, #481807
* Imported Upstream version 1.0~rc4+svn34492
* Bump standards version
* Bump dependency on libav >= 4:0.8~, Closes: #653887
* Fix build-indep
* Build mplayer-gui again, Closes: #568514
* Drop debian/all-lang-config-mak.sh, no longer needed
* include .dfsg1 in version number
* remove get-orig-source target
* no longer prune compiler flags from the environment
* No longer advertise nor build 3fdx, mga and dxr3 backends,
  Closes: #496106, #442181, #533546
* beautify mplayer version identification string
* Brown paperbag upload.
* Next try to fix build failure on sparce after recent binutils change.
* Brown paperbag upload.
* Really fix build failure on sparc after recent binutils change.
* Properly set Replaces/Conflicts on mplayer2{,-dbg} to avoid
  file overwrite errors.
* Adjust versioning of mplayer listed in the mplayer-dbg's Depends field.
* Fix build failure on sparc after recent binutils change.
* Urgency medium bumped because of RC-level bugfix
  and speeding up x264 transition.
* Update to my @debian.org email.
* Upload to unstable
* Enable joystick support on Linux only, Closes: #638408
* Rebuild fixes toolchain issue on arm, Closes: #637077
* New upstream snapshot
* following the discussion started by Diego Biurrun <diego@biurrun.de>
  in debian-devel, I have prepared a new packaging of 'mplayer'
  (with code that comes from CVS)
* the upstream tar.bz cannot be distributed by Debian, since it contains
   CSS code; so I am repackaging it 
* I have tried my best to address all known issues:
  - the package contains the detailed Copyright made by Diego Biurrun 
  - the package does not contain CSS code, or  AFAIK other code on which 
     there is active patent enforcement
  - there is a script  debian/cvs-changelog.sh  that shows all changes
     done to files included in this source.
    This should comply with GPLv2 sec 2.a  (in spirit if not in letter)
    For this reason, the source code contains CVS directories.
* needs   make (>= 3.80) for 'html-chunked-$(1)' in DOCS/xml/Makefile

* some corrections, as suggested Diego Biurrun
  - binary codecs should go into /usr/lib/codecs (upstream default)
  - better template 'mplayer/install_codecs'
  - an empty 'font=' in mplayer.conf breaks mplayer: postinst corrected
* correction in 'mplayer/cfgnote'
* better mplayer.postinst and mplayer.config

* New upstream release
* better debian/copyright file
* do not ship a skin
* New upstream release
* changed DEB_BUILD_OPTIONS to DEB_BUILD_CONFIGURE ,
  DEB_BUILD_OPTIONS is used as in debian policy
* use gcc-3.4
* changed xlibs-dev to a long list of dependencies, for Debian/etch
* try to adhere to  http://www.mplayerhq.hu/DOCS/tech/binary-packaging.txt
  (see README.Debian for details)
* removed dependency on xlibmesa-dev, disabled opengl
* New upstream release
* Simon McVittie <hacks@pseudorandom.co.uk> wonderful work:
- Work around Debian bug #267442 (glibc's sys/uio.h and gcc's altivec.h have
  conflicting uses for __vector) by re-ordering #includes
- Fix potential symlink attack in ./configure
- Disable support for binary codecs on platforms for which those codecs
  aren't available; also disable the corresponding Debconf note when it's
  inappropriate
- Changed Build-Depends: so it works in pbuilder
- Explicitly build-depend on libjpeg62-dev, libfontconfig1-dev,
  libungif4-dev 
- Tweak debian/rules to avoid certain errors being ignored
- Use --language=all
* provide a target  'debian/rules get-orig-source' 
  that recreates the orig.tar.gz ; then use the above orig.tar.gz
* rewrote some parts of debian/rules
* don't clean and recompile docs if upstream ships them
* mplayer-doc was shipping too much stuff
* translated man pages where not installed properly
* compile with libdv4-dev
* correct README.Debian
* Forgot build-dep on libtheora
* Must not depend on libxvidcore
* New upstream release
* new release.
* rc1 to become 0.90
* new pre-release
* new pre-release
* gtk bug fixed.
* new release.
* version bumped
* 0.60 pre2 release
* 0.60 pre-release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * License along with Libav; if not, write to the Free Software
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
 */
21
 
#define ALT_BITSTREAM_READER_LE
 
21
 
 
22
#define BITSTREAM_READER_LE
 
23
 
 
24
#include "libavutil/audioconvert.h"
22
25
#include "avcodec.h"
23
26
#include "get_bits.h"
24
27
#include "unary.h"
25
 
#include "libavutil/audioconvert.h"
26
28
 
27
29
/**
28
30
 * @file
29
31
 * WavPack lossless audio decoder
30
32
 */
31
33
 
32
 
#define WV_MONO         0x00000004
33
 
#define WV_JOINT_STEREO 0x00000010
34
 
#define WV_FALSE_STEREO 0x40000000
 
34
#define WV_MONO           0x00000004
 
35
#define WV_JOINT_STEREO   0x00000010
 
36
#define WV_FALSE_STEREO   0x40000000
35
37
 
36
38
#define WV_HYBRID_MODE    0x00000008
37
39
#define WV_HYBRID_SHAPE   0x00000008
44
46
#define WV_FLT_ZERO_SENT  0x08
45
47
#define WV_FLT_ZERO_SIGN  0x10
46
48
 
47
 
enum WP_ID_Flags{
 
49
enum WP_ID_Flags {
48
50
    WP_IDF_MASK   = 0x1F,
49
51
    WP_IDF_IGNORE = 0x20,
50
52
    WP_IDF_ODD    = 0x40,
51
53
    WP_IDF_LONG   = 0x80
52
54
};
53
55
 
54
 
enum WP_ID{
 
56
enum WP_ID {
55
57
    WP_ID_DUMMY = 0,
56
58
    WP_ID_ENCINFO,
57
59
    WP_ID_DECTERMS,
110
112
    int extra_bits;
111
113
    int and, or, shift;
112
114
    int post_shift;
113
 
    int hybrid, hybrid_bitrate;
 
115
    int hybrid, hybrid_bitrate, hybrid_maxclip;
114
116
    int float_flag;
115
117
    int float_shift;
116
118
    int float_max_exp;
117
119
    WvChannel ch[2];
118
 
    int samples_left;
119
 
    int max_samples;
120
120
    int pos;
121
121
    SavedContext sc, extra_sc;
122
122
} WavpackFrameContext;
125
125
 
126
126
typedef struct WavpackContext {
127
127
    AVCodecContext *avctx;
 
128
    AVFrame frame;
128
129
 
129
130
    WavpackFrameContext *fdec[WV_MAX_FRAME_DECODERS];
130
131
    int fdec_num;
133
134
    int mkv_mode;
134
135
    int block;
135
136
    int samples;
136
 
    int samples_left;
137
137
    int ch_offset;
138
138
} WavpackContext;
139
139
 
180
180
{
181
181
    int res, neg = 0;
182
182
 
183
 
    if(val < 0){
 
183
    if (val < 0) {
184
184
        val = -val;
185
185
        neg = 1;
186
186
    }
195
195
{
196
196
    int bits;
197
197
 
198
 
    if(!val)
 
198
    if (!val)
199
199
        return 0;
200
 
    if(val == 1)
 
200
    if (val == 1)
201
201
        return 256;
202
202
    val += val >> 9;
203
203
    bits = av_log2(val) + 1;
204
 
    if(bits < 9)
 
204
    if (bits < 9)
205
205
        return (bits << 8) + wp_log2_table[(val << (9 - bits)) & 0xFF];
206
206
    else
207
207
        return (bits << 8) + wp_log2_table[(val >> (bits - 9)) & 0xFF];
211
211
 
212
212
// macros for manipulating median values
213
213
#define GET_MED(n) ((c->median[n] >> 4) + 1)
214
 
#define DEC_MED(n) c->median[n] -= ((c->median[n] + (128>>n) - 2) / (128>>n)) * 2
215
 
#define INC_MED(n) c->median[n] += ((c->median[n] + (128>>n)) / (128>>n)) * 5
 
214
#define DEC_MED(n) c->median[n] -= ((c->median[n] + (128 >> n) - 2) / (128 >> n)) * 2
 
215
#define INC_MED(n) c->median[n] += ((c->median[n] + (128 >> n)    ) / (128 >> n)) * 5
216
216
 
217
217
// macros for applying weight
218
218
#define UPDATE_WEIGHT_CLIP(weight, delta, samples, in) \
219
 
        if(samples && in){ \
220
 
            if((samples ^ in) < 0){ \
221
 
                weight -= delta; \
222
 
                if(weight < -1024) weight = -1024; \
223
 
            }else{ \
224
 
                weight += delta; \
225
 
                if(weight > 1024) weight = 1024; \
226
 
            } \
227
 
        }
 
219
    if (samples && in) { \
 
220
        if ((samples ^ in) < 0) { \
 
221
            weight -= delta; \
 
222
            if (weight < -1024) \
 
223
                weight = -1024; \
 
224
        } else { \
 
225
            weight += delta; \
 
226
            if (weight > 1024) \
 
227
                weight = 1024; \
 
228
        } \
 
229
    }
228
230
 
229
231
 
230
232
static av_always_inline int get_tail(GetBitContext *gb, int k)
231
233
{
232
234
    int p, e, res;
233
235
 
234
 
    if(k<1)return 0;
 
236
    if (k < 1)
 
237
        return 0;
235
238
    p = av_log2(k);
236
239
    e = (1 << (p + 1)) - k - 1;
237
240
    res = p ? get_bits(gb, p) : 0;
238
 
    if(res >= e){
239
 
        res = (res<<1) - e + get_bits1(gb);
240
 
    }
 
241
    if (res >= e)
 
242
        res = (res << 1) - e + get_bits1(gb);
241
243
    return res;
242
244
}
243
245
 
245
247
{
246
248
    int i, br[2], sl[2];
247
249
 
248
 
    for(i = 0; i <= ctx->stereo_in; i++){
 
250
    for (i = 0; i <= ctx->stereo_in; i++) {
249
251
        ctx->ch[i].bitrate_acc += ctx->ch[i].bitrate_delta;
250
252
        br[i] = ctx->ch[i].bitrate_acc >> 16;
251
253
        sl[i] = LEVEL_DECAY(ctx->ch[i].slow_level);
252
254
    }
253
 
    if(ctx->stereo_in && ctx->hybrid_bitrate){
 
255
    if (ctx->stereo_in && ctx->hybrid_bitrate) {
254
256
        int balance = (sl[1] - sl[0] + br[1] + 1) >> 1;
255
 
        if(balance > br[0]){
 
257
        if (balance > br[0]) {
256
258
            br[1] = br[0] << 1;
257
259
            br[0] = 0;
258
 
        }else if(-balance > br[0]){
 
260
        } else if (-balance > br[0]) {
259
261
            br[0] <<= 1;
260
262
            br[1] = 0;
261
 
        }else{
 
263
        } else {
262
264
            br[1] = br[0] + balance;
263
265
            br[0] = br[0] - balance;
264
266
        }
265
267
    }
266
 
    for(i = 0; i <= ctx->stereo_in; i++){
267
 
        if(ctx->hybrid_bitrate){
268
 
            if(sl[i] - br[i] > -0x100)
 
268
    for (i = 0; i <= ctx->stereo_in; i++) {
 
269
        if (ctx->hybrid_bitrate) {
 
270
            if (sl[i] - br[i] > -0x100)
269
271
                ctx->ch[i].error_limit = wp_exp2(sl[i] - br[i] + 0x100);
270
272
            else
271
273
                ctx->ch[i].error_limit = 0;
272
 
        }else{
 
274
        } else {
273
275
            ctx->ch[i].error_limit = wp_exp2(br[i]);
274
276
        }
275
277
    }
276
278
}
277
279
 
278
 
static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, int channel, int *last)
 
280
static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb,
 
281
                        int channel, int *last)
279
282
{
280
283
    int t, t2;
281
284
    int sign, base, add, ret;
283
286
 
284
287
    *last = 0;
285
288
 
286
 
    if((ctx->ch[0].median[0] < 2U) && (ctx->ch[1].median[0] < 2U) && !ctx->zero && !ctx->one){
287
 
        if(ctx->zeroes){
 
289
    if ((ctx->ch[0].median[0] < 2U) && (ctx->ch[1].median[0] < 2U) &&
 
290
        !ctx->zero && !ctx->one) {
 
291
        if (ctx->zeroes) {
288
292
            ctx->zeroes--;
289
 
            if(ctx->zeroes){
 
293
            if (ctx->zeroes) {
290
294
                c->slow_level -= LEVEL_DECAY(c->slow_level);
291
295
                return 0;
292
296
            }
293
 
        }else{
 
297
        } else {
294
298
            t = get_unary_0_33(gb);
295
 
            if(t >= 2) t = get_bits(gb, t - 1) | (1 << (t-1));
 
299
            if (t >= 2) {
 
300
                if (get_bits_left(gb) < t - 1)
 
301
                    goto error;
 
302
                t = get_bits(gb, t - 1) | (1 << (t-1));
 
303
            } else {
 
304
                if (get_bits_left(gb) < 0)
 
305
                    goto error;
 
306
            }
296
307
            ctx->zeroes = t;
297
 
            if(ctx->zeroes){
 
308
            if (ctx->zeroes) {
298
309
                memset(ctx->ch[0].median, 0, sizeof(ctx->ch[0].median));
299
310
                memset(ctx->ch[1].median, 0, sizeof(ctx->ch[1].median));
300
311
                c->slow_level -= LEVEL_DECAY(c->slow_level);
303
314
        }
304
315
    }
305
316
 
306
 
    if(get_bits_count(gb) >= ctx->data_size){
307
 
        *last = 1;
308
 
        return 0;
309
 
    }
310
 
 
311
 
    if(ctx->zero){
 
317
    if (ctx->zero) {
312
318
        t = 0;
313
319
        ctx->zero = 0;
314
 
    }else{
 
320
    } else {
315
321
        t = get_unary_0_33(gb);
316
 
        if(get_bits_count(gb) >= ctx->data_size){
317
 
            *last = 1;
318
 
            return 0;
319
 
        }
320
 
        if(t == 16) {
 
322
        if (get_bits_left(gb) < 0)
 
323
            goto error;
 
324
        if (t == 16) {
321
325
            t2 = get_unary_0_33(gb);
322
 
            if(t2 < 2) t += t2;
323
 
            else t += get_bits(gb, t2 - 1) | (1 << (t2 - 1));
 
326
            if (t2 < 2) {
 
327
                if (get_bits_left(gb) < 0)
 
328
                    goto error;
 
329
                t += t2;
 
330
            } else {
 
331
                if (get_bits_left(gb) < t2 - 1)
 
332
                    goto error;
 
333
                t += get_bits(gb, t2 - 1) | (1 << (t2 - 1));
 
334
            }
324
335
        }
325
336
 
326
 
        if(ctx->one){
327
 
            ctx->one = t&1;
328
 
            t = (t>>1) + 1;
329
 
        }else{
330
 
            ctx->one = t&1;
 
337
        if (ctx->one) {
 
338
            ctx->one = t & 1;
 
339
            t = (t >> 1) + 1;
 
340
        } else {
 
341
            ctx->one = t & 1;
331
342
            t >>= 1;
332
343
        }
333
344
        ctx->zero = !ctx->one;
334
345
    }
335
346
 
336
 
    if(ctx->hybrid && !channel)
 
347
    if (ctx->hybrid && !channel)
337
348
        update_error_limit(ctx);
338
349
 
339
 
    if(!t){
 
350
    if (!t) {
340
351
        base = 0;
341
 
        add = GET_MED(0) - 1;
 
352
        add  = GET_MED(0) - 1;
342
353
        DEC_MED(0);
343
 
    }else if(t == 1){
 
354
    } else if (t == 1) {
344
355
        base = GET_MED(0);
345
 
        add = GET_MED(1) - 1;
 
356
        add  = GET_MED(1) - 1;
346
357
        INC_MED(0);
347
358
        DEC_MED(1);
348
 
    }else if(t == 2){
 
359
    } else if (t == 2) {
349
360
        base = GET_MED(0) + GET_MED(1);
350
 
        add = GET_MED(2) - 1;
 
361
        add  = GET_MED(2) - 1;
351
362
        INC_MED(0);
352
363
        INC_MED(1);
353
364
        DEC_MED(2);
354
 
    }else{
 
365
    } else {
355
366
        base = GET_MED(0) + GET_MED(1) + GET_MED(2) * (t - 2);
356
 
        add = GET_MED(2) - 1;
 
367
        add  = GET_MED(2) - 1;
357
368
        INC_MED(0);
358
369
        INC_MED(1);
359
370
        INC_MED(2);
360
371
    }
361
 
    if(!c->error_limit){
 
372
    if (!c->error_limit) {
362
373
        ret = base + get_tail(gb, add);
363
 
    }else{
364
 
        int mid = (base*2 + add + 1) >> 1;
365
 
        while(add > c->error_limit){
366
 
            if(get_bits1(gb)){
 
374
        if (get_bits_left(gb) <= 0)
 
375
            goto error;
 
376
    } else {
 
377
        int mid = (base * 2 + add + 1) >> 1;
 
378
        while (add > c->error_limit) {
 
379
            if (get_bits_left(gb) <= 0)
 
380
                goto error;
 
381
            if (get_bits1(gb)) {
367
382
                add -= (mid - base);
368
383
                base = mid;
369
 
            }else
 
384
            } else
370
385
                add = mid - base - 1;
371
 
            mid = (base*2 + add + 1) >> 1;
 
386
            mid = (base * 2 + add + 1) >> 1;
372
387
        }
373
388
        ret = mid;
374
389
    }
375
390
    sign = get_bits1(gb);
376
 
    if(ctx->hybrid_bitrate)
 
391
    if (ctx->hybrid_bitrate)
377
392
        c->slow_level += wp_log2(ret) - LEVEL_DECAY(c->slow_level);
378
393
    return sign ? ~ret : ret;
 
394
 
 
395
error:
 
396
    *last = 1;
 
397
    return 0;
379
398
}
380
399
 
381
 
static inline int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc, int S)
 
400
static inline int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc,
 
401
                                       int S)
382
402
{
383
403
    int bit;
384
404
 
385
 
    if(s->extra_bits){
 
405
    if (s->extra_bits){
386
406
        S <<= s->extra_bits;
387
407
 
388
 
        if(s->got_extra_bits){
 
408
        if (s->got_extra_bits && get_bits_left(&s->gb_extra_bits) >= s->extra_bits) {
389
409
            S |= get_bits(&s->gb_extra_bits, s->extra_bits);
390
 
            *crc = *crc * 9 + (S&0xffff) * 3 + ((unsigned)S>>16);
 
410
            *crc = *crc * 9 + (S & 0xffff) * 3 + ((unsigned)S >> 16);
391
411
        }
392
412
    }
 
413
 
393
414
    bit = (S & s->and) | s->or;
394
 
    return (((S + bit) << s->shift) - bit) << s->post_shift;
 
415
    bit = (((S + bit) << s->shift) - bit) << s->post_shift;
 
416
 
 
417
    if (s->hybrid)
 
418
        bit = av_clip(bit, -s->hybrid_maxclip - 1, s->hybrid_maxclip);
 
419
 
 
420
    return bit;
395
421
}
396
422
 
397
423
static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S)
404
430
    int sign;
405
431
    int exp = s->float_max_exp;
406
432
 
407
 
    if(s->got_extra_bits){
408
 
        const int max_bits = 1 + 23 + 8 + 1;
 
433
    if (s->got_extra_bits) {
 
434
        const int max_bits  = 1 + 23 + 8 + 1;
409
435
        const int left_bits = get_bits_left(&s->gb_extra_bits);
410
436
 
411
 
        if(left_bits + 8 * FF_INPUT_BUFFER_PADDING_SIZE < max_bits)
 
437
        if (left_bits + 8 * FF_INPUT_BUFFER_PADDING_SIZE < max_bits)
412
438
            return 0.0;
413
439
    }
414
440
 
415
 
    if(S){
 
441
    if (S) {
416
442
        S <<= s->float_shift;
417
443
        sign = S < 0;
418
 
        if(sign)
 
444
        if (sign)
419
445
            S = -S;
420
 
        if(S >= 0x1000000){
421
 
            if(s->got_extra_bits && get_bits1(&s->gb_extra_bits)){
 
446
        if (S >= 0x1000000) {
 
447
            if (s->got_extra_bits && get_bits1(&s->gb_extra_bits))
422
448
                S = get_bits(&s->gb_extra_bits, 23);
423
 
            }else{
 
449
            else
424
450
                S = 0;
425
 
            }
426
451
            exp = 255;
427
 
        }else if(exp){
 
452
        } else if (exp) {
428
453
            int shift = 23 - av_log2(S);
429
454
            exp = s->float_max_exp;
430
 
            if(exp <= shift){
 
455
            if (exp <= shift)
431
456
                shift = --exp;
432
 
            }
433
457
            exp -= shift;
434
458
 
435
 
            if(shift){
 
459
            if (shift) {
436
460
                S <<= shift;
437
 
                if((s->float_flag & WV_FLT_SHIFT_ONES) ||
438
 
                   (s->got_extra_bits && (s->float_flag & WV_FLT_SHIFT_SAME) && get_bits1(&s->gb_extra_bits)) ){
 
461
                if ((s->float_flag & WV_FLT_SHIFT_ONES) ||
 
462
                    (s->got_extra_bits && (s->float_flag & WV_FLT_SHIFT_SAME) &&
 
463
                     get_bits1(&s->gb_extra_bits))) {
439
464
                    S |= (1 << shift) - 1;
440
 
                } else if(s->got_extra_bits && (s->float_flag & WV_FLT_SHIFT_SENT)){
 
465
                } else if (s->got_extra_bits &&
 
466
                           (s->float_flag & WV_FLT_SHIFT_SENT)) {
441
467
                    S |= get_bits(&s->gb_extra_bits, shift);
442
468
                }
443
469
            }
444
 
        }else{
 
470
        } else {
445
471
            exp = s->float_max_exp;
446
472
        }
447
473
        S &= 0x7fffff;
448
 
    }else{
 
474
    } else {
449
475
        sign = 0;
450
476
        exp = 0;
451
 
        if(s->got_extra_bits && (s->float_flag & WV_FLT_ZERO_SENT)){
452
 
            if(get_bits1(&s->gb_extra_bits)){
 
477
        if (s->got_extra_bits && (s->float_flag & WV_FLT_ZERO_SENT)) {
 
478
            if (get_bits1(&s->gb_extra_bits)) {
453
479
                S = get_bits(&s->gb_extra_bits, 23);
454
 
                if(s->float_max_exp >= 25)
 
480
                if (s->float_max_exp >= 25)
455
481
                    exp = get_bits(&s->gb_extra_bits, 8);
456
482
                sign = get_bits1(&s->gb_extra_bits);
457
 
            }else{
458
 
                if(s->float_flag & WV_FLT_ZERO_SIGN)
 
483
            } else {
 
484
                if (s->float_flag & WV_FLT_ZERO_SIGN)
459
485
                    sign = get_bits1(&s->gb_extra_bits);
460
486
            }
461
487
        }
473
499
    s->sc.crc = s->extra_sc.crc = 0xFFFFFFFF;
474
500
}
475
501
 
476
 
static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, void *dst, const int type)
 
502
static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb,
 
503
                                   void *dst, const int type)
477
504
{
478
505
    int i, j, count = 0;
479
506
    int last, t;
486
513
    float   *dstfl = dst;
487
514
    const int channel_pad = s->avctx->channels - 2;
488
515
 
489
 
    if(s->samples_left == s->samples)
490
 
        s->one = s->zero = s->zeroes = 0;
491
 
    do{
 
516
    s->one = s->zero = s->zeroes = 0;
 
517
    do {
492
518
        L = wv_get_value(s, gb, 0, &last);
493
 
        if(last) break;
 
519
        if (last)
 
520
            break;
494
521
        R = wv_get_value(s, gb, 1, &last);
495
 
        if(last) break;
496
 
        for(i = 0; i < s->terms; i++){
 
522
        if (last)
 
523
            break;
 
524
        for (i = 0; i < s->terms; i++) {
497
525
            t = s->decorr[i].value;
498
 
            if(t > 0){
499
 
                if(t > 8){
500
 
                    if(t & 1){
 
526
            if (t > 0) {
 
527
                if (t > 8) {
 
528
                    if (t & 1) {
501
529
                        A = 2 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1];
502
530
                        B = 2 * s->decorr[i].samplesB[0] - s->decorr[i].samplesB[1];
503
 
                    }else{
 
531
                    } else {
504
532
                        A = (3 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1]) >> 1;
505
533
                        B = (3 * s->decorr[i].samplesB[0] - s->decorr[i].samplesB[1]) >> 1;
506
534
                    }
507
535
                    s->decorr[i].samplesA[1] = s->decorr[i].samplesA[0];
508
536
                    s->decorr[i].samplesB[1] = s->decorr[i].samplesB[0];
509
537
                    j = 0;
510
 
                }else{
 
538
                } else {
511
539
                    A = s->decorr[i].samplesA[pos];
512
540
                    B = s->decorr[i].samplesB[pos];
513
541
                    j = (pos + t) & 7;
514
542
                }
515
 
                if(type != AV_SAMPLE_FMT_S16){
 
543
                if (type != AV_SAMPLE_FMT_S16) {
516
544
                    L2 = L + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10);
517
545
                    R2 = R + ((s->decorr[i].weightB * (int64_t)B + 512) >> 10);
518
 
                }else{
 
546
                } else {
519
547
                    L2 = L + ((s->decorr[i].weightA * A + 512) >> 10);
520
548
                    R2 = R + ((s->decorr[i].weightB * B + 512) >> 10);
521
549
                }
522
 
                if(A && L) s->decorr[i].weightA -= ((((L ^ A) >> 30) & 2) - 1) * s->decorr[i].delta;
523
 
                if(B && R) s->decorr[i].weightB -= ((((R ^ B) >> 30) & 2) - 1) * s->decorr[i].delta;
 
550
                if (A && L) s->decorr[i].weightA -= ((((L ^ A) >> 30) & 2) - 1) * s->decorr[i].delta;
 
551
                if (B && R) s->decorr[i].weightB -= ((((R ^ B) >> 30) & 2) - 1) * s->decorr[i].delta;
524
552
                s->decorr[i].samplesA[j] = L = L2;
525
553
                s->decorr[i].samplesB[j] = R = R2;
526
 
            }else if(t == -1){
527
 
                if(type != AV_SAMPLE_FMT_S16)
 
554
            } else if (t == -1) {
 
555
                if (type != AV_SAMPLE_FMT_S16)
528
556
                    L2 = L + ((s->decorr[i].weightA * (int64_t)s->decorr[i].samplesA[0] + 512) >> 10);
529
557
                else
530
558
                    L2 = L + ((s->decorr[i].weightA * s->decorr[i].samplesA[0] + 512) >> 10);
531
559
                UPDATE_WEIGHT_CLIP(s->decorr[i].weightA, s->decorr[i].delta, s->decorr[i].samplesA[0], L);
532
560
                L = L2;
533
 
                if(type != AV_SAMPLE_FMT_S16)
 
561
                if (type != AV_SAMPLE_FMT_S16)
534
562
                    R2 = R + ((s->decorr[i].weightB * (int64_t)L2 + 512) >> 10);
535
563
                else
536
564
                    R2 = R + ((s->decorr[i].weightB * L2 + 512) >> 10);
537
565
                UPDATE_WEIGHT_CLIP(s->decorr[i].weightB, s->decorr[i].delta, L2, R);
538
566
                R = R2;
539
567
                s->decorr[i].samplesA[0] = R;
540
 
            }else{
541
 
                if(type != AV_SAMPLE_FMT_S16)
 
568
            } else {
 
569
                if (type != AV_SAMPLE_FMT_S16)
542
570
                    R2 = R + ((s->decorr[i].weightB * (int64_t)s->decorr[i].samplesB[0] + 512) >> 10);
543
571
                else
544
572
                    R2 = R + ((s->decorr[i].weightB * s->decorr[i].samplesB[0] + 512) >> 10);
545
573
                UPDATE_WEIGHT_CLIP(s->decorr[i].weightB, s->decorr[i].delta, s->decorr[i].samplesB[0], R);
546
574
                R = R2;
547
575
 
548
 
                if(t == -3){
 
576
                if (t == -3) {
549
577
                    R2 = s->decorr[i].samplesA[0];
550
578
                    s->decorr[i].samplesA[0] = R;
551
579
                }
552
580
 
553
 
                if(type != AV_SAMPLE_FMT_S16)
 
581
                if (type != AV_SAMPLE_FMT_S16)
554
582
                    L2 = L + ((s->decorr[i].weightA * (int64_t)R2 + 512) >> 10);
555
583
                else
556
584
                    L2 = L + ((s->decorr[i].weightA * R2 + 512) >> 10);
560
588
            }
561
589
        }
562
590
        pos = (pos + 1) & 7;
563
 
        if(s->joint)
 
591
        if (s->joint)
564
592
            L += (R -= (L >> 1));
565
593
        crc = (crc * 3 + L) * 3 + R;
566
594
 
567
 
        if(type == AV_SAMPLE_FMT_FLT){
 
595
        if (type == AV_SAMPLE_FMT_FLT) {
568
596
            *dstfl++ = wv_get_value_float(s, &crc_extra_bits, L);
569
597
            *dstfl++ = wv_get_value_float(s, &crc_extra_bits, R);
570
598
            dstfl += channel_pad;
571
 
        } else if(type == AV_SAMPLE_FMT_S32){
 
599
        } else if (type == AV_SAMPLE_FMT_S32) {
572
600
            *dst32++ = wv_get_value_integer(s, &crc_extra_bits, L);
573
601
            *dst32++ = wv_get_value_integer(s, &crc_extra_bits, R);
574
602
            dst32 += channel_pad;
578
606
            dst16 += channel_pad;
579
607
        }
580
608
        count++;
581
 
    }while(!last && count < s->max_samples);
582
 
 
583
 
    s->samples_left -= count;
584
 
    if(!s->samples_left){
585
 
        if(crc != s->CRC){
586
 
            av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
587
 
            return -1;
588
 
        }
589
 
        if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){
590
 
            av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
591
 
            return -1;
592
 
        }
593
 
        wv_reset_saved_context(s);
594
 
    }else{
595
 
        s->pos = pos;
596
 
        s->sc.crc = crc;
597
 
        s->sc.bits_used = get_bits_count(&s->gb);
598
 
        if(s->got_extra_bits){
599
 
            s->extra_sc.crc = crc_extra_bits;
600
 
            s->extra_sc.bits_used = get_bits_count(&s->gb_extra_bits);
601
 
        }
602
 
    }
 
609
    } while (!last && count < s->samples);
 
610
 
 
611
    wv_reset_saved_context(s);
 
612
    if (crc != s->CRC) {
 
613
        av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
 
614
        return -1;
 
615
    }
 
616
    if (s->got_extra_bits && crc_extra_bits != s->crc_extra_bits) {
 
617
        av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
 
618
        return -1;
 
619
    }
 
620
 
603
621
    return count * 2;
604
622
}
605
623
 
606
 
static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void *dst, const int type)
 
624
static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb,
 
625
                                 void *dst, const int type)
607
626
{
608
627
    int i, j, count = 0;
609
628
    int last, t;
616
635
    float   *dstfl = dst;
617
636
    const int channel_stride = s->avctx->channels;
618
637
 
619
 
    if(s->samples_left == s->samples)
620
 
        s->one = s->zero = s->zeroes = 0;
621
 
    do{
 
638
    s->one = s->zero = s->zeroes = 0;
 
639
    do {
622
640
        T = wv_get_value(s, gb, 0, &last);
623
641
        S = 0;
624
 
        if(last) break;
625
 
        for(i = 0; i < s->terms; i++){
 
642
        if (last)
 
643
            break;
 
644
        for (i = 0; i < s->terms; i++) {
626
645
            t = s->decorr[i].value;
627
 
            if(t > 8){
628
 
                if(t & 1)
629
 
                    A = 2 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1];
 
646
            if (t > 8) {
 
647
                if (t & 1)
 
648
                    A =  2 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1];
630
649
                else
631
650
                    A = (3 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1]) >> 1;
632
651
                s->decorr[i].samplesA[1] = s->decorr[i].samplesA[0];
633
652
                j = 0;
634
 
            }else{
 
653
            } else {
635
654
                A = s->decorr[i].samplesA[pos];
636
655
                j = (pos + t) & 7;
637
656
            }
638
 
            if(type != AV_SAMPLE_FMT_S16)
 
657
            if (type != AV_SAMPLE_FMT_S16)
639
658
                S = T + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10);
640
659
            else
641
660
                S = T + ((s->decorr[i].weightA * A + 512) >> 10);
642
 
            if(A && T) s->decorr[i].weightA -= ((((T ^ A) >> 30) & 2) - 1) * s->decorr[i].delta;
 
661
            if (A && T)
 
662
                s->decorr[i].weightA -= ((((T ^ A) >> 30) & 2) - 1) * s->decorr[i].delta;
643
663
            s->decorr[i].samplesA[j] = T = S;
644
664
        }
645
665
        pos = (pos + 1) & 7;
646
666
        crc = crc * 3 + S;
647
667
 
648
 
        if(type == AV_SAMPLE_FMT_FLT){
 
668
        if (type == AV_SAMPLE_FMT_FLT) {
649
669
            *dstfl = wv_get_value_float(s, &crc_extra_bits, S);
650
670
            dstfl += channel_stride;
651
 
        }else if(type == AV_SAMPLE_FMT_S32){
 
671
        } else if (type == AV_SAMPLE_FMT_S32) {
652
672
            *dst32 = wv_get_value_integer(s, &crc_extra_bits, S);
653
673
            dst32 += channel_stride;
654
 
        }else{
 
674
        } else {
655
675
            *dst16 = wv_get_value_integer(s, &crc_extra_bits, S);
656
676
            dst16 += channel_stride;
657
677
        }
658
678
        count++;
659
 
    }while(!last && count < s->max_samples);
660
 
 
661
 
    s->samples_left -= count;
662
 
    if(!s->samples_left){
663
 
        if(crc != s->CRC){
664
 
            av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
665
 
            return -1;
666
 
        }
667
 
        if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){
668
 
            av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
669
 
            return -1;
670
 
        }
671
 
        wv_reset_saved_context(s);
672
 
    }else{
673
 
        s->pos = pos;
674
 
        s->sc.crc = crc;
675
 
        s->sc.bits_used = get_bits_count(&s->gb);
676
 
        if(s->got_extra_bits){
677
 
            s->extra_sc.crc = crc_extra_bits;
678
 
            s->extra_sc.bits_used = get_bits_count(&s->gb_extra_bits);
679
 
        }
680
 
    }
 
679
    } while (!last && count < s->samples);
 
680
 
 
681
    wv_reset_saved_context(s);
 
682
    if (crc != s->CRC) {
 
683
        av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
 
684
        return -1;
 
685
    }
 
686
    if (s->got_extra_bits && crc_extra_bits != s->crc_extra_bits) {
 
687
        av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
 
688
        return -1;
 
689
    }
 
690
 
681
691
    return count;
682
692
}
683
693
 
684
694
static av_cold int wv_alloc_frame_context(WavpackContext *c)
685
695
{
686
696
 
687
 
    if(c->fdec_num == WV_MAX_FRAME_DECODERS)
 
697
    if (c->fdec_num == WV_MAX_FRAME_DECODERS)
688
698
        return -1;
689
699
 
690
700
    c->fdec[c->fdec_num] = av_mallocz(sizeof(**c->fdec));
691
 
    if(!c->fdec[c->fdec_num])
 
701
    if (!c->fdec[c->fdec_num])
692
702
        return -1;
693
703
    c->fdec_num++;
694
704
    c->fdec[c->fdec_num - 1]->avctx = c->avctx;
702
712
    WavpackContext *s = avctx->priv_data;
703
713
 
704
714
    s->avctx = avctx;
705
 
    if(avctx->bits_per_coded_sample <= 16)
 
715
    if (avctx->bits_per_coded_sample <= 16)
706
716
        avctx->sample_fmt = AV_SAMPLE_FMT_S16;
707
717
    else
708
718
        avctx->sample_fmt = AV_SAMPLE_FMT_S32;
709
 
    if(avctx->channels <= 2 && !avctx->channel_layout)
710
 
        avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
 
719
    if (avctx->channels <= 2 && !avctx->channel_layout)
 
720
        avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO :
 
721
                                                         AV_CH_LAYOUT_MONO;
711
722
 
712
723
    s->multichannel = avctx->channels > 2;
713
724
    /* lavf demuxer does not provide extradata, Matroska stores 0x403
714
725
       there, use this to detect decoding mode for multichannel */
715
726
    s->mkv_mode = 0;
716
 
    if(s->multichannel && avctx->extradata && avctx->extradata_size == 2){
 
727
    if (s->multichannel && avctx->extradata && avctx->extradata_size == 2) {
717
728
        int ver = AV_RL16(avctx->extradata);
718
 
        if(ver >= 0x402 && ver <= 0x410)
 
729
        if (ver >= 0x402 && ver <= 0x410)
719
730
            s->mkv_mode = 1;
720
731
    }
721
732
 
722
733
    s->fdec_num = 0;
723
734
 
 
735
    avcodec_get_frame_defaults(&s->frame);
 
736
    avctx->coded_frame = &s->frame;
 
737
 
724
738
    return 0;
725
739
}
726
740
 
729
743
    WavpackContext *s = avctx->priv_data;
730
744
    int i;
731
745
 
732
 
    for(i = 0; i < s->fdec_num; i++)
 
746
    for (i = 0; i < s->fdec_num; i++)
733
747
        av_freep(&s->fdec[i]);
734
748
    s->fdec_num = 0;
735
749
 
737
751
}
738
752
 
739
753
static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
740
 
                                void *data, int *data_size,
 
754
                                void *data, int *got_frame_ptr,
741
755
                                const uint8_t *buf, int buf_size)
742
756
{
743
757
    WavpackContext *wc = avctx->priv_data;
744
758
    WavpackFrameContext *s;
745
759
    void *samples = data;
746
760
    int samplecount;
747
 
    int got_terms = 0, got_weights = 0, got_samples = 0, got_entropy = 0, got_bs = 0, got_float = 0;
748
 
    int got_hybrid = 0;
749
 
    const uint8_t* orig_buf = buf;
750
 
    const uint8_t* buf_end = buf + buf_size;
 
761
    int got_terms   = 0, got_weights = 0, got_samples = 0,
 
762
        got_entropy = 0, got_bs      = 0, got_float   = 0, got_hybrid = 0;
 
763
    const uint8_t *orig_buf = buf;
 
764
    const uint8_t *buf_end  = buf + buf_size;
751
765
    int i, j, id, size, ssize, weights, t;
752
766
    int bpp, chan, chmask;
753
767
 
754
 
    if (buf_size == 0){
755
 
        *data_size = 0;
 
768
    if (buf_size == 0) {
 
769
        *got_frame_ptr = 0;
756
770
        return 0;
757
771
    }
758
772
 
759
 
    if(block_no >= wc->fdec_num && wv_alloc_frame_context(wc) < 0){
 
773
    if (block_no >= wc->fdec_num && wv_alloc_frame_context(wc) < 0) {
760
774
        av_log(avctx, AV_LOG_ERROR, "Error creating frame decode context\n");
761
775
        return -1;
762
776
    }
763
777
 
764
778
    s = wc->fdec[block_no];
765
 
    if(!s){
 
779
    if (!s) {
766
780
        av_log(avctx, AV_LOG_ERROR, "Context for block %d is not present\n", block_no);
767
781
        return -1;
768
782
    }
769
783
 
770
 
    if(!s->samples_left){
771
 
        memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
772
 
        memset(s->ch, 0, sizeof(s->ch));
773
 
        s->extra_bits = 0;
774
 
        s->and = s->or = s->shift = 0;
775
 
        s->got_extra_bits = 0;
776
 
    }
 
784
    memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
 
785
    memset(s->ch, 0, sizeof(s->ch));
 
786
    s->extra_bits = 0;
 
787
    s->and = s->or = s->shift = 0;
 
788
    s->got_extra_bits = 0;
777
789
 
778
 
    if(!wc->mkv_mode){
 
790
    if (!wc->mkv_mode) {
779
791
        s->samples = AV_RL32(buf); buf += 4;
780
 
        if(!s->samples){
781
 
            *data_size = 0;
782
 
            return buf_size;
 
792
        if (!s->samples) {
 
793
            *got_frame_ptr = 0;
 
794
            return 0;
783
795
        }
784
 
    }else{
 
796
    } else {
785
797
        s->samples = wc->samples;
786
798
    }
787
799
    s->frame_flags = AV_RL32(buf); buf += 4;
788
 
    if(s->frame_flags&0x80){
789
 
        bpp = sizeof(float);
790
 
        avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
791
 
    } else if((s->frame_flags&0x03) <= 1){
792
 
        bpp = 2;
793
 
        avctx->sample_fmt = AV_SAMPLE_FMT_S16;
794
 
    } else {
795
 
        bpp = 4;
796
 
        avctx->sample_fmt = AV_SAMPLE_FMT_S32;
797
 
    }
 
800
    bpp = av_get_bytes_per_sample(avctx->sample_fmt);
798
801
    samples = (uint8_t*)samples + bpp * wc->ch_offset;
799
802
 
800
 
    s->stereo = !(s->frame_flags & WV_MONO);
801
 
    s->stereo_in = (s->frame_flags & WV_FALSE_STEREO) ? 0 : s->stereo;
802
 
    s->joint = s->frame_flags & WV_JOINT_STEREO;
803
 
    s->hybrid = s->frame_flags & WV_HYBRID_MODE;
804
 
    s->hybrid_bitrate = s->frame_flags & WV_HYBRID_BITRATE;
805
 
    s->post_shift = 8 * (bpp-1-(s->frame_flags&0x03)) + ((s->frame_flags >> 13) & 0x1f);
806
 
    s->CRC = AV_RL32(buf); buf += 4;
807
 
    if(wc->mkv_mode)
 
803
    s->stereo         = !(s->frame_flags & WV_MONO);
 
804
    s->stereo_in      =  (s->frame_flags & WV_FALSE_STEREO) ? 0 : s->stereo;
 
805
    s->joint          =   s->frame_flags & WV_JOINT_STEREO;
 
806
    s->hybrid         =   s->frame_flags & WV_HYBRID_MODE;
 
807
    s->hybrid_bitrate =   s->frame_flags & WV_HYBRID_BITRATE;
 
808
    s->hybrid_maxclip = (1LL << ((((s->frame_flags & 0x03) + 1) << 3) - 1)) - 1;
 
809
    s->post_shift     = 8 * (bpp - 1 - (s->frame_flags & 0x03)) +
 
810
                        ((s->frame_flags >> 13) & 0x1f);
 
811
    s->CRC            = AV_RL32(buf); buf += 4;
 
812
    if (wc->mkv_mode)
808
813
        buf += 4; //skip block size;
809
814
 
810
815
    wc->ch_offset += 1 + s->stereo;
811
816
 
812
 
    s->max_samples = *data_size / (bpp * avctx->channels);
813
 
    s->max_samples = FFMIN(s->max_samples, s->samples);
814
 
    if(s->samples_left > 0){
815
 
        s->max_samples = FFMIN(s->max_samples, s->samples_left);
816
 
        buf = buf_end;
817
 
    }
818
 
 
819
817
    // parse metadata blocks
820
 
    while(buf < buf_end){
821
 
        id = *buf++;
 
818
    while (buf < buf_end) {
 
819
        id   = *buf++;
822
820
        size = *buf++;
823
 
        if(id & WP_IDF_LONG) {
 
821
        if (id & WP_IDF_LONG) {
824
822
            size |= (*buf++) << 8;
825
823
            size |= (*buf++) << 16;
826
824
        }
827
825
        size <<= 1; // size is specified in words
828
826
        ssize = size;
829
 
        if(id & WP_IDF_ODD) size--;
830
 
        if(size < 0){
 
827
        if (id & WP_IDF_ODD)
 
828
            size--;
 
829
        if (size < 0) {
831
830
            av_log(avctx, AV_LOG_ERROR, "Got incorrect block %02X with size %i\n", id, size);
832
831
            break;
833
832
        }
834
 
        if(buf + ssize > buf_end){
 
833
        if (buf + ssize > buf_end) {
835
834
            av_log(avctx, AV_LOG_ERROR, "Block size %i is out of bounds\n", size);
836
835
            break;
837
836
        }
838
 
        if(id & WP_IDF_IGNORE){
 
837
        if (id & WP_IDF_IGNORE) {
839
838
            buf += ssize;
840
839
            continue;
841
840
        }
842
 
        switch(id & WP_IDF_MASK){
 
841
        switch (id & WP_IDF_MASK) {
843
842
        case WP_ID_DECTERMS:
 
843
            if (size > MAX_TERMS) {
 
844
                av_log(avctx, AV_LOG_ERROR, "Too many decorrelation terms\n");
 
845
                s->terms = 0;
 
846
                buf += ssize;
 
847
                continue;
 
848
            }
844
849
            s->terms = size;
845
 
            if(s->terms > MAX_TERMS){
846
 
                av_log(avctx, AV_LOG_ERROR, "Too many decorrelation terms\n");
847
 
                buf += ssize;
848
 
                continue;
849
 
            }
850
 
            for(i = 0; i < s->terms; i++) {
 
850
            for (i = 0; i < s->terms; i++) {
851
851
                s->decorr[s->terms - i - 1].value = (*buf & 0x1F) - 5;
852
852
                s->decorr[s->terms - i - 1].delta = *buf >> 5;
853
853
                buf++;
855
855
            got_terms = 1;
856
856
            break;
857
857
        case WP_ID_DECWEIGHTS:
858
 
            if(!got_terms){
 
858
            if (!got_terms) {
859
859
                av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
860
860
                continue;
861
861
            }
862
862
            weights = size >> s->stereo_in;
863
 
            if(weights > MAX_TERMS || weights > s->terms){
 
863
            if (weights > MAX_TERMS || weights > s->terms) {
864
864
                av_log(avctx, AV_LOG_ERROR, "Too many decorrelation weights\n");
865
865
                buf += ssize;
866
866
                continue;
867
867
            }
868
 
            for(i = 0; i < weights; i++) {
 
868
            for (i = 0; i < weights; i++) {
869
869
                t = (int8_t)(*buf++);
870
870
                s->decorr[s->terms - i - 1].weightA = t << 3;
871
 
                if(s->decorr[s->terms - i - 1].weightA > 0)
872
 
                    s->decorr[s->terms - i - 1].weightA += (s->decorr[s->terms - i - 1].weightA + 64) >> 7;
873
 
                if(s->stereo_in){
 
871
                if (s->decorr[s->terms - i - 1].weightA > 0)
 
872
                    s->decorr[s->terms - i - 1].weightA +=
 
873
                            (s->decorr[s->terms - i - 1].weightA + 64) >> 7;
 
874
                if (s->stereo_in) {
874
875
                    t = (int8_t)(*buf++);
875
876
                    s->decorr[s->terms - i - 1].weightB = t << 3;
876
 
                    if(s->decorr[s->terms - i - 1].weightB > 0)
877
 
                        s->decorr[s->terms - i - 1].weightB += (s->decorr[s->terms - i - 1].weightB + 64) >> 7;
 
877
                    if (s->decorr[s->terms - i - 1].weightB > 0)
 
878
                        s->decorr[s->terms - i - 1].weightB +=
 
879
                                (s->decorr[s->terms - i - 1].weightB + 64) >> 7;
878
880
                }
879
881
            }
880
882
            got_weights = 1;
881
883
            break;
882
884
        case WP_ID_DECSAMPLES:
883
 
            if(!got_terms){
 
885
            if (!got_terms) {
884
886
                av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
885
887
                continue;
886
888
            }
887
889
            t = 0;
888
 
            for(i = s->terms - 1; (i >= 0) && (t < size); i--) {
889
 
                if(s->decorr[i].value > 8){
 
890
            for (i = s->terms - 1; (i >= 0) && (t < size); i--) {
 
891
                if (s->decorr[i].value > 8) {
890
892
                    s->decorr[i].samplesA[0] = wp_exp2(AV_RL16(buf)); buf += 2;
891
893
                    s->decorr[i].samplesA[1] = wp_exp2(AV_RL16(buf)); buf += 2;
892
 
                    if(s->stereo_in){
 
894
                    if (s->stereo_in) {
893
895
                        s->decorr[i].samplesB[0] = wp_exp2(AV_RL16(buf)); buf += 2;
894
896
                        s->decorr[i].samplesB[1] = wp_exp2(AV_RL16(buf)); buf += 2;
895
897
                        t += 4;
896
898
                    }
897
899
                    t += 4;
898
 
                }else if(s->decorr[i].value < 0){
 
900
                } else if (s->decorr[i].value < 0) {
899
901
                    s->decorr[i].samplesA[0] = wp_exp2(AV_RL16(buf)); buf += 2;
900
902
                    s->decorr[i].samplesB[0] = wp_exp2(AV_RL16(buf)); buf += 2;
901
903
                    t += 4;
902
 
                }else{
903
 
                    for(j = 0; j < s->decorr[i].value; j++){
 
904
                } else {
 
905
                    for (j = 0; j < s->decorr[i].value; j++) {
904
906
                        s->decorr[i].samplesA[j] = wp_exp2(AV_RL16(buf)); buf += 2;
905
 
                        if(s->stereo_in){
 
907
                        if (s->stereo_in)
906
908
                            s->decorr[i].samplesB[j] = wp_exp2(AV_RL16(buf)); buf += 2;
907
 
                        }
908
909
                    }
909
910
                    t += s->decorr[i].value * 2 * (s->stereo_in + 1);
910
911
                }
912
913
            got_samples = 1;
913
914
            break;
914
915
        case WP_ID_ENTROPY:
915
 
            if(size != 6 * (s->stereo_in + 1)){
916
 
                av_log(avctx, AV_LOG_ERROR, "Entropy vars size should be %i, got %i", 6 * (s->stereo_in + 1), size);
 
916
            if (size != 6 * (s->stereo_in + 1)) {
 
917
                av_log(avctx, AV_LOG_ERROR, "Entropy vars size should be %i, "
 
918
                       "got %i", 6 * (s->stereo_in + 1), size);
917
919
                buf += ssize;
918
920
                continue;
919
921
            }
920
 
            for(j = 0; j <= s->stereo_in; j++){
921
 
                for(i = 0; i < 3; i++){
 
922
            for (j = 0; j <= s->stereo_in; j++) {
 
923
                for (i = 0; i < 3; i++) {
922
924
                    s->ch[j].median[i] = wp_exp2(AV_RL16(buf));
923
925
                    buf += 2;
924
926
                }
926
928
            got_entropy = 1;
927
929
            break;
928
930
        case WP_ID_HYBRID:
929
 
            if(s->hybrid_bitrate){
930
 
                for(i = 0; i <= s->stereo_in; i++){
 
931
            if (s->hybrid_bitrate) {
 
932
                for (i = 0; i <= s->stereo_in; i++) {
931
933
                    s->ch[i].slow_level = wp_exp2(AV_RL16(buf));
932
934
                    buf += 2;
933
935
                    size -= 2;
934
936
                }
935
937
            }
936
 
            for(i = 0; i < (s->stereo_in + 1); i++){
 
938
            for (i = 0; i < (s->stereo_in + 1); i++) {
937
939
                s->ch[i].bitrate_acc = AV_RL16(buf) << 16;
938
940
                buf += 2;
939
941
                size -= 2;
940
942
            }
941
 
            if(size > 0){
942
 
                for(i = 0; i < (s->stereo_in + 1); i++){
 
943
            if (size > 0) {
 
944
                for (i = 0; i < (s->stereo_in + 1); i++) {
943
945
                    s->ch[i].bitrate_delta = wp_exp2((int16_t)AV_RL16(buf));
944
946
                    buf += 2;
945
947
                }
946
 
            }else{
947
 
                for(i = 0; i < (s->stereo_in + 1); i++)
 
948
            } else {
 
949
                for (i = 0; i < (s->stereo_in + 1); i++)
948
950
                    s->ch[i].bitrate_delta = 0;
949
951
            }
950
952
            got_hybrid = 1;
951
953
            break;
952
954
        case WP_ID_INT32INFO:
953
 
            if(size != 4){
 
955
            if (size != 4) {
954
956
                av_log(avctx, AV_LOG_ERROR, "Invalid INT32INFO, size = %i, sent_bits = %i\n", size, *buf);
955
957
                buf += ssize;
956
958
                continue;
957
959
            }
958
 
            if(buf[0])
 
960
            if (buf[0])
959
961
                s->extra_bits = buf[0];
960
 
            else if(buf[1])
 
962
            else if (buf[1])
961
963
                s->shift = buf[1];
962
 
            else if(buf[2]){
 
964
            else if (buf[2]){
963
965
                s->and = s->or = 1;
964
966
                s->shift = buf[2];
965
 
            }else if(buf[3]){
966
 
                s->and = 1;
 
967
            } else if(buf[3]) {
 
968
                s->and   = 1;
967
969
                s->shift = buf[3];
968
970
            }
969
971
            buf += 4;
970
972
            break;
971
973
        case WP_ID_FLOATINFO:
972
 
            if(size != 4){
 
974
            if (size != 4) {
973
975
                av_log(avctx, AV_LOG_ERROR, "Invalid FLOATINFO, size = %i\n", size);
974
976
                buf += ssize;
975
977
                continue;
976
978
            }
977
 
            s->float_flag = buf[0];
978
 
            s->float_shift = buf[1];
 
979
            s->float_flag    = buf[0];
 
980
            s->float_shift   = buf[1];
979
981
            s->float_max_exp = buf[2];
980
982
            buf += 4;
981
983
            got_float = 1;
989
991
            got_bs = 1;
990
992
            break;
991
993
        case WP_ID_EXTRABITS:
992
 
            if(size <= 4){
993
 
                av_log(avctx, AV_LOG_ERROR, "Invalid EXTRABITS, size = %i\n", size);
 
994
            if (size <= 4) {
 
995
                av_log(avctx, AV_LOG_ERROR, "Invalid EXTRABITS, size = %i\n",
 
996
                       size);
994
997
                buf += size;
995
998
                continue;
996
999
            }
1002
1005
            s->got_extra_bits = 1;
1003
1006
            break;
1004
1007
        case WP_ID_CHANINFO:
1005
 
            if(size <= 1){
 
1008
            if (size <= 1) {
1006
1009
                av_log(avctx, AV_LOG_ERROR, "Insufficient channel information\n");
1007
1010
                return -1;
1008
1011
            }
1009
1012
            chan = *buf++;
1010
 
            switch(size - 2){
1011
 
            case 0:
1012
 
                chmask = *buf;
1013
 
                break;
1014
 
            case 1:
1015
 
                chmask = AV_RL16(buf);
1016
 
                break;
1017
 
            case 2:
1018
 
                chmask = AV_RL24(buf);
1019
 
                break;
1020
 
            case 3:
1021
 
                chmask = AV_RL32(buf);
1022
 
                break;
 
1013
            switch (size - 2) {
 
1014
            case 0: chmask = *buf;         break;
 
1015
            case 1: chmask = AV_RL16(buf); break;
 
1016
            case 2: chmask = AV_RL24(buf); break;
 
1017
            case 3: chmask = AV_RL32(buf); break;
1023
1018
            case 5:
1024
1019
                chan |= (buf[1] & 0xF) << 8;
1025
1020
                chmask = AV_RL24(buf + 2);
1026
1021
                break;
1027
1022
            default:
1028
 
                av_log(avctx, AV_LOG_ERROR, "Invalid channel info size %d\n", size);
1029
 
                chan = avctx->channels;
 
1023
                av_log(avctx, AV_LOG_ERROR, "Invalid channel info size %d\n",
 
1024
                       size);
 
1025
                chan   = avctx->channels;
1030
1026
                chmask = avctx->channel_layout;
1031
1027
            }
1032
 
            if(chan != avctx->channels){
1033
 
                av_log(avctx, AV_LOG_ERROR, "Block reports total %d channels, decoder believes it's %d channels\n",
1034
 
                       chan, avctx->channels);
 
1028
            if (chan != avctx->channels) {
 
1029
                av_log(avctx, AV_LOG_ERROR, "Block reports total %d channels, "
 
1030
                       "decoder believes it's %d channels\n", chan,
 
1031
                       avctx->channels);
1035
1032
                return -1;
1036
1033
            }
1037
 
            if(!avctx->channel_layout)
 
1034
            if (!avctx->channel_layout)
1038
1035
                avctx->channel_layout = chmask;
1039
1036
            buf += size - 1;
1040
1037
            break;
1041
1038
        default:
1042
1039
            buf += size;
1043
1040
        }
1044
 
        if(id & WP_IDF_ODD) buf++;
1045
 
    }
1046
 
    if(!s->samples_left){
1047
 
        if(!got_terms){
1048
 
            av_log(avctx, AV_LOG_ERROR, "No block with decorrelation terms\n");
1049
 
            return -1;
1050
 
        }
1051
 
        if(!got_weights){
1052
 
            av_log(avctx, AV_LOG_ERROR, "No block with decorrelation weights\n");
1053
 
            return -1;
1054
 
        }
1055
 
        if(!got_samples){
1056
 
            av_log(avctx, AV_LOG_ERROR, "No block with decorrelation samples\n");
1057
 
            return -1;
1058
 
        }
1059
 
        if(!got_entropy){
1060
 
            av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n");
1061
 
            return -1;
1062
 
        }
1063
 
        if(s->hybrid && !got_hybrid){
1064
 
            av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n");
1065
 
            return -1;
1066
 
        }
1067
 
        if(!got_bs){
1068
 
            av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n");
1069
 
            return -1;
1070
 
        }
1071
 
        if(!got_float && avctx->sample_fmt == AV_SAMPLE_FMT_FLT){
1072
 
            av_log(avctx, AV_LOG_ERROR, "Float information not found\n");
1073
 
            return -1;
1074
 
        }
1075
 
        if(s->got_extra_bits && avctx->sample_fmt != AV_SAMPLE_FMT_FLT){
1076
 
            const int size = get_bits_left(&s->gb_extra_bits);
1077
 
            const int wanted = s->samples * s->extra_bits << s->stereo_in;
1078
 
            if(size < wanted){
1079
 
                av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n");
1080
 
                s->got_extra_bits = 0;
1081
 
            }
1082
 
        }
1083
 
        s->samples_left = s->samples;
1084
 
    }else{
1085
 
        init_get_bits(&s->gb, orig_buf + s->sc.offset, s->sc.size);
1086
 
        skip_bits_long(&s->gb, s->sc.bits_used);
1087
 
        if(s->got_extra_bits){
1088
 
            init_get_bits(&s->gb_extra_bits, orig_buf + s->extra_sc.offset,
1089
 
                          s->extra_sc.size);
1090
 
            skip_bits_long(&s->gb_extra_bits, s->extra_sc.bits_used);
1091
 
        }
1092
 
    }
1093
 
 
1094
 
    if(s->stereo_in){
1095
 
        if(avctx->sample_fmt == AV_SAMPLE_FMT_S16)
 
1041
        if (id & WP_IDF_ODD)
 
1042
            buf++;
 
1043
    }
 
1044
 
 
1045
    if (!got_terms) {
 
1046
        av_log(avctx, AV_LOG_ERROR, "No block with decorrelation terms\n");
 
1047
        return -1;
 
1048
    }
 
1049
    if (!got_weights) {
 
1050
        av_log(avctx, AV_LOG_ERROR, "No block with decorrelation weights\n");
 
1051
        return -1;
 
1052
    }
 
1053
    if (!got_samples) {
 
1054
        av_log(avctx, AV_LOG_ERROR, "No block with decorrelation samples\n");
 
1055
        return -1;
 
1056
    }
 
1057
    if (!got_entropy) {
 
1058
        av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n");
 
1059
        return -1;
 
1060
    }
 
1061
    if (s->hybrid && !got_hybrid) {
 
1062
        av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n");
 
1063
        return -1;
 
1064
    }
 
1065
    if (!got_bs) {
 
1066
        av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n");
 
1067
        return -1;
 
1068
    }
 
1069
    if (!got_float && avctx->sample_fmt == AV_SAMPLE_FMT_FLT) {
 
1070
        av_log(avctx, AV_LOG_ERROR, "Float information not found\n");
 
1071
        return -1;
 
1072
    }
 
1073
    if (s->got_extra_bits && avctx->sample_fmt != AV_SAMPLE_FMT_FLT) {
 
1074
        const int size   = get_bits_left(&s->gb_extra_bits);
 
1075
        const int wanted = s->samples * s->extra_bits << s->stereo_in;
 
1076
        if (size < wanted) {
 
1077
            av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n");
 
1078
            s->got_extra_bits = 0;
 
1079
        }
 
1080
    }
 
1081
 
 
1082
    if (s->stereo_in) {
 
1083
        if (avctx->sample_fmt == AV_SAMPLE_FMT_S16)
1096
1084
            samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_S16);
1097
 
        else if(avctx->sample_fmt == AV_SAMPLE_FMT_S32)
 
1085
        else if (avctx->sample_fmt == AV_SAMPLE_FMT_S32)
1098
1086
            samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_S32);
1099
1087
        else
1100
1088
            samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_FLT);
 
1089
 
 
1090
        if (samplecount < 0)
 
1091
            return -1;
 
1092
 
1101
1093
        samplecount >>= 1;
1102
 
    }else{
 
1094
    } else {
1103
1095
        const int channel_stride = avctx->channels;
1104
1096
 
1105
 
        if(avctx->sample_fmt == AV_SAMPLE_FMT_S16)
 
1097
        if (avctx->sample_fmt == AV_SAMPLE_FMT_S16)
1106
1098
            samplecount = wv_unpack_mono(s, &s->gb, samples, AV_SAMPLE_FMT_S16);
1107
 
        else if(avctx->sample_fmt == AV_SAMPLE_FMT_S32)
 
1099
        else if (avctx->sample_fmt == AV_SAMPLE_FMT_S32)
1108
1100
            samplecount = wv_unpack_mono(s, &s->gb, samples, AV_SAMPLE_FMT_S32);
1109
1101
        else
1110
1102
            samplecount = wv_unpack_mono(s, &s->gb, samples, AV_SAMPLE_FMT_FLT);
1111
1103
 
1112
 
        if(s->stereo && avctx->sample_fmt == AV_SAMPLE_FMT_S16){
 
1104
        if (samplecount < 0)
 
1105
            return -1;
 
1106
 
 
1107
        if (s->stereo && avctx->sample_fmt == AV_SAMPLE_FMT_S16) {
1113
1108
            int16_t *dst = (int16_t*)samples + 1;
1114
1109
            int16_t *src = (int16_t*)samples;
1115
1110
            int cnt = samplecount;
1116
 
            while(cnt--){
 
1111
            while (cnt--) {
1117
1112
                *dst = *src;
1118
1113
                src += channel_stride;
1119
1114
                dst += channel_stride;
1120
1115
            }
1121
 
        }else if(s->stereo && avctx->sample_fmt == AV_SAMPLE_FMT_S32){
 
1116
        } else if (s->stereo && avctx->sample_fmt == AV_SAMPLE_FMT_S32) {
1122
1117
            int32_t *dst = (int32_t*)samples + 1;
1123
1118
            int32_t *src = (int32_t*)samples;
1124
1119
            int cnt = samplecount;
1125
 
            while(cnt--){
 
1120
            while (cnt--) {
1126
1121
                *dst = *src;
1127
1122
                src += channel_stride;
1128
1123
                dst += channel_stride;
1129
1124
            }
1130
 
        }else if(s->stereo){
 
1125
        } else if (s->stereo) {
1131
1126
            float *dst = (float*)samples + 1;
1132
1127
            float *src = (float*)samples;
1133
1128
            int cnt = samplecount;
1134
 
            while(cnt--){
 
1129
            while (cnt--) {
1135
1130
                *dst = *src;
1136
1131
                src += channel_stride;
1137
1132
                dst += channel_stride;
1139
1134
        }
1140
1135
    }
1141
1136
 
1142
 
    wc->samples_left = s->samples_left;
 
1137
    *got_frame_ptr = 1;
1143
1138
 
1144
1139
    return samplecount * bpp;
1145
1140
}
1146
1141
 
1147
 
static int wavpack_decode_frame(AVCodecContext *avctx,
1148
 
                            void *data, int *data_size,
1149
 
                            AVPacket *avpkt)
 
1142
static void wavpack_decode_flush(AVCodecContext *avctx)
1150
1143
{
1151
1144
    WavpackContext *s = avctx->priv_data;
 
1145
    int i;
 
1146
 
 
1147
    for (i = 0; i < s->fdec_num; i++)
 
1148
        wv_reset_saved_context(s->fdec[i]);
 
1149
}
 
1150
 
 
1151
static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
 
1152
                                int *got_frame_ptr, AVPacket *avpkt)
 
1153
{
 
1154
    WavpackContext *s  = avctx->priv_data;
1152
1155
    const uint8_t *buf = avpkt->data;
1153
 
    int buf_size = avpkt->size;
1154
 
    int frame_size;
 
1156
    int buf_size       = avpkt->size;
 
1157
    int frame_size, ret, frame_flags;
1155
1158
    int samplecount = 0;
1156
1159
 
1157
 
    s->block = 0;
1158
 
    s->samples_left = 0;
 
1160
    s->block     = 0;
1159
1161
    s->ch_offset = 0;
1160
1162
 
1161
 
    if(s->mkv_mode){
1162
 
        s->samples = AV_RL32(buf); buf += 4;
1163
 
    }
1164
 
    while(buf_size > 0){
1165
 
        if(!s->multichannel){
 
1163
    /* determine number of samples */
 
1164
    if (s->mkv_mode) {
 
1165
        s->samples  = AV_RL32(buf); buf += 4;
 
1166
        frame_flags = AV_RL32(buf);
 
1167
    } else {
 
1168
        if (s->multichannel) {
 
1169
            s->samples  = AV_RL32(buf + 4);
 
1170
            frame_flags = AV_RL32(buf + 8);
 
1171
        } else {
 
1172
            s->samples  = AV_RL32(buf);
 
1173
            frame_flags = AV_RL32(buf + 4);
 
1174
        }
 
1175
    }
 
1176
    if (s->samples <= 0) {
 
1177
        av_log(avctx, AV_LOG_ERROR, "Invalid number of samples: %d\n",
 
1178
               s->samples);
 
1179
        return AVERROR(EINVAL);
 
1180
    }
 
1181
 
 
1182
    if (frame_flags & 0x80) {
 
1183
        avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
 
1184
    } else if ((frame_flags & 0x03) <= 1) {
 
1185
        avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 
1186
    } else {
 
1187
        avctx->sample_fmt = AV_SAMPLE_FMT_S32;
 
1188
    }
 
1189
 
 
1190
    /* get output buffer */
 
1191
    s->frame.nb_samples = s->samples;
 
1192
    if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
 
1193
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
 
1194
        return ret;
 
1195
    }
 
1196
 
 
1197
    while (buf_size > 0) {
 
1198
        if (!s->multichannel) {
1166
1199
            frame_size = buf_size;
1167
 
        }else{
1168
 
            if(!s->mkv_mode){
 
1200
        } else {
 
1201
            if (!s->mkv_mode) {
1169
1202
                frame_size = AV_RL32(buf) - 12; buf += 4; buf_size -= 4;
1170
 
            }else{
1171
 
                if(buf_size < 12) //MKV files can have zero flags after last block
 
1203
            } else {
 
1204
                if (buf_size < 12) //MKV files can have zero flags after last block
1172
1205
                    break;
1173
1206
                frame_size = AV_RL32(buf + 8) + 12;
1174
1207
            }
1175
1208
        }
1176
 
        if(frame_size < 0 || frame_size > buf_size){
1177
 
            av_log(avctx, AV_LOG_ERROR, "Block %d has invalid size (size %d vs. %d bytes left)\n",
1178
 
                   s->block, frame_size, buf_size);
1179
 
            return -1;
1180
 
        }
1181
 
        if((samplecount = wavpack_decode_block(avctx, s->block, data,
1182
 
                                               data_size, buf, frame_size)) < 0)
1183
 
            return -1;
 
1209
        if (frame_size < 0 || frame_size > buf_size) {
 
1210
            av_log(avctx, AV_LOG_ERROR, "Block %d has invalid size (size %d "
 
1211
                   "vs. %d bytes left)\n", s->block, frame_size, buf_size);
 
1212
            wavpack_decode_flush(avctx);
 
1213
            return -1;
 
1214
        }
 
1215
        if ((samplecount = wavpack_decode_block(avctx, s->block,
 
1216
                                                s->frame.data[0], got_frame_ptr,
 
1217
                                                buf, frame_size)) < 0) {
 
1218
            wavpack_decode_flush(avctx);
 
1219
            return -1;
 
1220
        }
1184
1221
        s->block++;
1185
1222
        buf += frame_size; buf_size -= frame_size;
1186
1223
    }
1187
 
    *data_size = samplecount * avctx->channels;
1188
 
 
1189
 
    return s->samples_left > 0 ? 0 : avpkt->size;
 
1224
 
 
1225
    if (*got_frame_ptr)
 
1226
        *(AVFrame *)data = s->frame;
 
1227
 
 
1228
    return avpkt->size;
1190
1229
}
1191
1230
 
1192
1231
AVCodec ff_wavpack_decoder = {
1193
 
    "wavpack",
1194
 
    AVMEDIA_TYPE_AUDIO,
1195
 
    CODEC_ID_WAVPACK,
1196
 
    sizeof(WavpackContext),
1197
 
    wavpack_decode_init,
1198
 
    NULL,
1199
 
    wavpack_decode_end,
1200
 
    wavpack_decode_frame,
1201
 
    .capabilities = CODEC_CAP_SUBFRAMES,
1202
 
    .long_name = NULL_IF_CONFIG_SMALL("WavPack"),
 
1232
    .name           = "wavpack",
 
1233
    .type           = AVMEDIA_TYPE_AUDIO,
 
1234
    .id             = CODEC_ID_WAVPACK,
 
1235
    .priv_data_size = sizeof(WavpackContext),
 
1236
    .init           = wavpack_decode_init,
 
1237
    .close          = wavpack_decode_end,
 
1238
    .decode         = wavpack_decode_frame,
 
1239
    .flush          = wavpack_decode_flush,
 
1240
    .capabilities   = CODEC_CAP_SUBFRAMES | CODEC_CAP_DR1,
 
1241
    .long_name      = NULL_IF_CONFIG_SMALL("WavPack"),
1203
1242
};