2006-09-26 03:41:51 +00:00
|
|
|
/*
|
|
|
|
* WavPack lossless audio decoder
|
2011-01-22 13:43:15 +00:00
|
|
|
* Copyright (c) 2006,2011 Konstantin Shishkov
|
2020-03-09 22:23:53 +00:00
|
|
|
* Copyright (c) 2020 David Bryant
|
2006-09-26 03:41:51 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2006-09-26 03:41:51 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 15:30:46 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2006-09-26 03:41:51 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2006-09-26 03:41:51 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 15:30:46 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-09-26 03:41:51 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2012-01-02 05:14:16 +00:00
|
|
|
|
2020-04-05 20:01:40 +00:00
|
|
|
#include "libavutil/buffer.h"
|
2012-11-10 15:00:00 +00:00
|
|
|
#include "libavutil/channel_layout.h"
|
2016-06-04 13:07:30 +00:00
|
|
|
|
|
|
|
#define BITSTREAM_READER_LE
|
2006-09-26 03:41:51 +00:00
|
|
|
#include "avcodec.h"
|
2016-06-04 13:07:30 +00:00
|
|
|
#include "bytestream.h"
|
2009-04-13 16:20:26 +00:00
|
|
|
#include "get_bits.h"
|
2012-11-10 12:22:56 +00:00
|
|
|
#include "internal.h"
|
2013-06-03 16:22:46 +00:00
|
|
|
#include "thread.h"
|
2007-08-26 22:33:48 +00:00
|
|
|
#include "unary.h"
|
2013-01-22 20:05:44 +00:00
|
|
|
#include "wavpack.h"
|
2020-03-09 22:23:53 +00:00
|
|
|
#include "dsd.h"
|
2006-09-26 03:41:51 +00:00
|
|
|
|
|
|
|
/**
|
2010-04-20 14:45:34 +00:00
|
|
|
* @file
|
2006-09-26 03:41:51 +00:00
|
|
|
* WavPack lossless audio decoder
|
|
|
|
*/
|
|
|
|
|
2020-03-09 22:23:53 +00:00
|
|
|
#define DSD_BYTE_READY(low,high) (!(((low) ^ (high)) & 0xff000000))
|
|
|
|
|
|
|
|
#define PTABLE_BITS 8
|
|
|
|
#define PTABLE_BINS (1<<PTABLE_BITS)
|
|
|
|
#define PTABLE_MASK (PTABLE_BINS-1)
|
|
|
|
|
|
|
|
#define UP 0x010000fe
|
|
|
|
#define DOWN 0x00010000
|
|
|
|
#define DECAY 8
|
|
|
|
|
|
|
|
#define PRECISION 20
|
|
|
|
#define VALUE_ONE (1 << PRECISION)
|
|
|
|
#define PRECISION_USE 12
|
|
|
|
|
|
|
|
#define RATE_S 20
|
|
|
|
|
|
|
|
#define MAX_HISTORY_BITS 5
|
|
|
|
#define MAX_HISTORY_BINS (1 << MAX_HISTORY_BITS)
|
|
|
|
#define MAX_BIN_BYTES 1280 // for value_lookup, per bin (2k - 512 - 256)
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
MODULATION_PCM, // pulse code modulation
|
|
|
|
MODULATION_DSD // pulse density modulation (aka DSD)
|
|
|
|
} Modulation;
|
2010-02-19 14:05:41 +00:00
|
|
|
|
2011-01-22 13:43:15 +00:00
|
|
|
typedef struct WavpackFrameContext {
|
2006-09-26 03:41:51 +00:00
|
|
|
AVCodecContext *avctx;
|
2009-01-16 17:46:19 +00:00
|
|
|
int frame_flags;
|
2007-08-13 05:36:50 +00:00
|
|
|
int stereo, stereo_in;
|
2006-09-26 03:41:51 +00:00
|
|
|
int joint;
|
|
|
|
uint32_t CRC;
|
|
|
|
GetBitContext gb;
|
2009-05-02 05:17:20 +00:00
|
|
|
int got_extra_bits;
|
|
|
|
uint32_t crc_extra_bits;
|
|
|
|
GetBitContext gb_extra_bits;
|
2006-09-26 03:41:51 +00:00
|
|
|
int samples;
|
|
|
|
int terms;
|
|
|
|
Decorr decorr[MAX_TERMS];
|
|
|
|
int zero, one, zeroes;
|
2009-05-02 05:17:20 +00:00
|
|
|
int extra_bits;
|
2007-08-05 05:56:34 +00:00
|
|
|
int and, or, shift;
|
2009-04-23 07:44:04 +00:00
|
|
|
int post_shift;
|
2012-02-24 00:26:38 +00:00
|
|
|
int hybrid, hybrid_bitrate;
|
|
|
|
int hybrid_maxclip, hybrid_minclip;
|
2009-05-06 05:40:43 +00:00
|
|
|
int float_flag;
|
|
|
|
int float_shift;
|
|
|
|
int float_max_exp;
|
2009-01-16 17:46:19 +00:00
|
|
|
WvChannel ch[2];
|
2020-03-09 22:23:53 +00:00
|
|
|
|
|
|
|
GetByteContext gbyte;
|
|
|
|
int ptable [PTABLE_BINS];
|
|
|
|
uint8_t value_lookup_buffer[MAX_HISTORY_BINS*MAX_BIN_BYTES];
|
|
|
|
uint16_t summed_probabilities[MAX_HISTORY_BINS][256];
|
|
|
|
uint8_t probabilities[MAX_HISTORY_BINS][256];
|
|
|
|
uint8_t *value_lookup[MAX_HISTORY_BINS];
|
2011-01-22 13:43:15 +00:00
|
|
|
} WavpackFrameContext;
|
|
|
|
|
|
|
|
#define WV_MAX_FRAME_DECODERS 14
|
|
|
|
|
|
|
|
typedef struct WavpackContext {
|
|
|
|
AVCodecContext *avctx;
|
|
|
|
|
|
|
|
WavpackFrameContext *fdec[WV_MAX_FRAME_DECODERS];
|
|
|
|
int fdec_num;
|
|
|
|
|
|
|
|
int block;
|
|
|
|
int samples;
|
|
|
|
int ch_offset;
|
2020-03-09 22:23:53 +00:00
|
|
|
|
|
|
|
AVFrame *frame;
|
|
|
|
ThreadFrame curr_frame, prev_frame;
|
|
|
|
Modulation modulation;
|
2020-04-05 20:01:40 +00:00
|
|
|
|
|
|
|
AVBufferRef *dsd_ref;
|
2020-03-09 22:23:53 +00:00
|
|
|
DSDContext *dsdctx;
|
2020-04-05 20:01:40 +00:00
|
|
|
int dsd_channels;
|
2006-09-26 03:41:51 +00:00
|
|
|
} WavpackContext;
|
|
|
|
|
2014-06-18 00:54:57 +00:00
|
|
|
#define LEVEL_DECAY(a) (((a) + 0x80) >> 8)
|
2009-01-16 17:46:19 +00:00
|
|
|
|
2018-06-07 22:07:04 +00:00
|
|
|
static av_always_inline unsigned get_tail(GetBitContext *gb, int k)
|
2006-09-26 03:41:51 +00:00
|
|
|
{
|
|
|
|
int p, e, res;
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
if (k < 1)
|
|
|
|
return 0;
|
2013-05-18 14:02:47 +00:00
|
|
|
p = av_log2(k);
|
|
|
|
e = (1 << (p + 1)) - k - 1;
|
2016-01-03 00:19:23 +00:00
|
|
|
res = get_bitsz(gb, p);
|
2012-01-02 05:14:16 +00:00
|
|
|
if (res >= e)
|
|
|
|
res = (res << 1) - e + get_bits1(gb);
|
2006-09-26 03:41:51 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-03-03 19:12:21 +00:00
|
|
|
static int update_error_limit(WavpackFrameContext *ctx)
|
2009-01-16 17:46:19 +00:00
|
|
|
{
|
|
|
|
int i, br[2], sl[2];
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
for (i = 0; i <= ctx->stereo_in; i++) {
|
2017-03-03 19:12:21 +00:00
|
|
|
if (ctx->ch[i].bitrate_acc > UINT_MAX - ctx->ch[i].bitrate_delta)
|
|
|
|
return AVERROR_INVALIDDATA;
|
2009-01-16 17:46:19 +00:00
|
|
|
ctx->ch[i].bitrate_acc += ctx->ch[i].bitrate_delta;
|
2013-05-18 14:02:47 +00:00
|
|
|
br[i] = ctx->ch[i].bitrate_acc >> 16;
|
|
|
|
sl[i] = LEVEL_DECAY(ctx->ch[i].slow_level);
|
2009-01-16 17:46:19 +00:00
|
|
|
}
|
2012-01-02 05:14:16 +00:00
|
|
|
if (ctx->stereo_in && ctx->hybrid_bitrate) {
|
2009-01-16 17:46:19 +00:00
|
|
|
int balance = (sl[1] - sl[0] + br[1] + 1) >> 1;
|
2012-01-02 05:14:16 +00:00
|
|
|
if (balance > br[0]) {
|
2017-05-23 22:21:21 +00:00
|
|
|
br[1] = br[0] * 2;
|
2009-01-16 17:46:19 +00:00
|
|
|
br[0] = 0;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else if (-balance > br[0]) {
|
2017-05-23 22:21:21 +00:00
|
|
|
br[0] *= 2;
|
2013-05-18 14:02:47 +00:00
|
|
|
br[1] = 0;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2009-01-16 17:46:19 +00:00
|
|
|
br[1] = br[0] + balance;
|
|
|
|
br[0] = br[0] - balance;
|
|
|
|
}
|
|
|
|
}
|
2012-01-02 05:14:16 +00:00
|
|
|
for (i = 0; i <= ctx->stereo_in; i++) {
|
|
|
|
if (ctx->hybrid_bitrate) {
|
|
|
|
if (sl[i] - br[i] > -0x100)
|
2009-01-16 17:46:19 +00:00
|
|
|
ctx->ch[i].error_limit = wp_exp2(sl[i] - br[i] + 0x100);
|
|
|
|
else
|
|
|
|
ctx->ch[i].error_limit = 0;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2009-01-16 17:46:19 +00:00
|
|
|
ctx->ch[i].error_limit = wp_exp2(br[i]);
|
|
|
|
}
|
|
|
|
}
|
2017-03-03 19:12:21 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-01-16 17:46:19 +00:00
|
|
|
}
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb,
|
|
|
|
int channel, int *last)
|
2006-09-26 03:41:51 +00:00
|
|
|
{
|
|
|
|
int t, t2;
|
|
|
|
int sign, base, add, ret;
|
2009-01-16 17:46:19 +00:00
|
|
|
WvChannel *c = &ctx->ch[channel];
|
2006-09-26 03:41:51 +00:00
|
|
|
|
|
|
|
*last = 0;
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
if ((ctx->ch[0].median[0] < 2U) && (ctx->ch[1].median[0] < 2U) &&
|
|
|
|
!ctx->zero && !ctx->one) {
|
|
|
|
if (ctx->zeroes) {
|
2006-09-26 03:41:51 +00:00
|
|
|
ctx->zeroes--;
|
2012-01-02 05:14:16 +00:00
|
|
|
if (ctx->zeroes) {
|
2009-01-16 17:46:19 +00:00
|
|
|
c->slow_level -= LEVEL_DECAY(c->slow_level);
|
2006-09-26 03:41:51 +00:00
|
|
|
return 0;
|
2009-01-16 17:46:19 +00:00
|
|
|
}
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2007-08-26 22:38:57 +00:00
|
|
|
t = get_unary_0_33(gb);
|
2012-01-02 05:14:16 +00:00
|
|
|
if (t >= 2) {
|
2017-04-07 01:38:12 +00:00
|
|
|
if (t >= 32 || get_bits_left(gb) < t - 1)
|
2011-09-07 20:02:55 +00:00
|
|
|
goto error;
|
2015-06-27 18:16:12 +00:00
|
|
|
t = get_bits_long(gb, t - 1) | (1 << (t - 1));
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
|
|
|
if (get_bits_left(gb) < 0)
|
2011-09-07 20:02:55 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2006-09-26 03:41:51 +00:00
|
|
|
ctx->zeroes = t;
|
2012-01-02 05:14:16 +00:00
|
|
|
if (ctx->zeroes) {
|
2009-01-16 17:46:19 +00:00
|
|
|
memset(ctx->ch[0].median, 0, sizeof(ctx->ch[0].median));
|
|
|
|
memset(ctx->ch[1].median, 0, sizeof(ctx->ch[1].median));
|
|
|
|
c->slow_level -= LEVEL_DECAY(c->slow_level);
|
2006-09-26 03:41:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
if (ctx->zero) {
|
2013-05-18 14:02:47 +00:00
|
|
|
t = 0;
|
2006-09-26 03:41:51 +00:00
|
|
|
ctx->zero = 0;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2007-08-26 22:38:57 +00:00
|
|
|
t = get_unary_0_33(gb);
|
2012-01-02 05:14:16 +00:00
|
|
|
if (get_bits_left(gb) < 0)
|
2011-09-07 20:02:55 +00:00
|
|
|
goto error;
|
2012-01-02 05:14:16 +00:00
|
|
|
if (t == 16) {
|
2007-08-26 22:38:57 +00:00
|
|
|
t2 = get_unary_0_33(gb);
|
2012-01-02 05:14:16 +00:00
|
|
|
if (t2 < 2) {
|
|
|
|
if (get_bits_left(gb) < 0)
|
2011-09-07 20:02:55 +00:00
|
|
|
goto error;
|
|
|
|
t += t2;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2017-06-01 16:48:37 +00:00
|
|
|
if (t2 >= 32 || get_bits_left(gb) < t2 - 1)
|
2011-09-07 20:02:55 +00:00
|
|
|
goto error;
|
2015-06-27 18:16:12 +00:00
|
|
|
t += get_bits_long(gb, t2 - 1) | (1 << (t2 - 1));
|
2011-09-07 20:02:55 +00:00
|
|
|
}
|
2006-09-26 03:41:51 +00:00
|
|
|
}
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
if (ctx->one) {
|
|
|
|
ctx->one = t & 1;
|
2013-05-18 14:02:47 +00:00
|
|
|
t = (t >> 1) + 1;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
|
|
|
ctx->one = t & 1;
|
2013-05-18 14:02:47 +00:00
|
|
|
t >>= 1;
|
2006-09-26 03:41:51 +00:00
|
|
|
}
|
|
|
|
ctx->zero = !ctx->one;
|
|
|
|
}
|
|
|
|
|
2017-03-03 19:12:21 +00:00
|
|
|
if (ctx->hybrid && !channel) {
|
|
|
|
if (update_error_limit(ctx) < 0)
|
|
|
|
goto error;
|
|
|
|
}
|
2009-01-16 17:46:19 +00:00
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
if (!t) {
|
2006-09-26 03:41:51 +00:00
|
|
|
base = 0;
|
2012-01-02 05:14:16 +00:00
|
|
|
add = GET_MED(0) - 1;
|
2006-09-26 03:41:51 +00:00
|
|
|
DEC_MED(0);
|
2012-01-02 05:14:16 +00:00
|
|
|
} else if (t == 1) {
|
2006-09-26 03:41:51 +00:00
|
|
|
base = GET_MED(0);
|
2012-01-02 05:14:16 +00:00
|
|
|
add = GET_MED(1) - 1;
|
2006-09-26 03:41:51 +00:00
|
|
|
INC_MED(0);
|
|
|
|
DEC_MED(1);
|
2012-01-02 05:14:16 +00:00
|
|
|
} else if (t == 2) {
|
2006-09-26 03:41:51 +00:00
|
|
|
base = GET_MED(0) + GET_MED(1);
|
2012-01-02 05:14:16 +00:00
|
|
|
add = GET_MED(2) - 1;
|
2006-09-26 03:41:51 +00:00
|
|
|
INC_MED(0);
|
|
|
|
INC_MED(1);
|
|
|
|
DEC_MED(2);
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2017-06-22 23:58:48 +00:00
|
|
|
base = GET_MED(0) + GET_MED(1) + GET_MED(2) * (t - 2U);
|
2012-01-02 05:14:16 +00:00
|
|
|
add = GET_MED(2) - 1;
|
2006-09-26 03:41:51 +00:00
|
|
|
INC_MED(0);
|
|
|
|
INC_MED(1);
|
|
|
|
INC_MED(2);
|
|
|
|
}
|
2012-01-02 05:14:16 +00:00
|
|
|
if (!c->error_limit) {
|
2013-03-27 23:23:23 +00:00
|
|
|
if (add >= 0x2000000U) {
|
|
|
|
av_log(ctx->avctx, AV_LOG_ERROR, "k %d is too large\n", add);
|
|
|
|
goto error;
|
|
|
|
}
|
2009-01-16 17:46:19 +00:00
|
|
|
ret = base + get_tail(gb, add);
|
2011-09-07 20:02:55 +00:00
|
|
|
if (get_bits_left(gb) <= 0)
|
|
|
|
goto error;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2017-05-04 21:41:28 +00:00
|
|
|
int mid = (base * 2U + add + 1) >> 1;
|
2012-01-02 05:14:16 +00:00
|
|
|
while (add > c->error_limit) {
|
|
|
|
if (get_bits_left(gb) <= 0)
|
2011-09-07 20:02:55 +00:00
|
|
|
goto error;
|
2012-01-02 05:14:16 +00:00
|
|
|
if (get_bits1(gb)) {
|
2017-05-31 20:53:02 +00:00
|
|
|
add -= (mid - (unsigned)base);
|
2009-01-16 17:46:19 +00:00
|
|
|
base = mid;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else
|
2017-06-04 15:14:13 +00:00
|
|
|
add = mid - (unsigned)base - 1;
|
2017-05-04 21:41:28 +00:00
|
|
|
mid = (base * 2U + add + 1) >> 1;
|
2009-01-16 17:46:19 +00:00
|
|
|
}
|
|
|
|
ret = mid;
|
|
|
|
}
|
2006-09-26 03:41:51 +00:00
|
|
|
sign = get_bits1(gb);
|
2012-01-02 05:14:16 +00:00
|
|
|
if (ctx->hybrid_bitrate)
|
2009-01-16 17:46:19 +00:00
|
|
|
c->slow_level += wp_log2(ret) - LEVEL_DECAY(c->slow_level);
|
2006-09-26 03:41:51 +00:00
|
|
|
return sign ? ~ret : ret;
|
2011-09-07 20:02:55 +00:00
|
|
|
|
|
|
|
error:
|
2014-08-19 12:26:47 +00:00
|
|
|
ret = get_bits_left(gb);
|
|
|
|
if (ret <= 0) {
|
|
|
|
av_log(ctx->avctx, AV_LOG_ERROR, "Too few bits (%d) left\n", ret);
|
|
|
|
}
|
2011-09-07 20:02:55 +00:00
|
|
|
*last = 1;
|
|
|
|
return 0;
|
2006-09-26 03:41:51 +00:00
|
|
|
}
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
static inline int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc,
|
2017-03-14 00:17:53 +00:00
|
|
|
unsigned S)
|
2009-05-05 06:10:59 +00:00
|
|
|
{
|
2017-02-23 14:19:30 +00:00
|
|
|
unsigned bit;
|
2009-05-05 06:10:59 +00:00
|
|
|
|
2013-05-18 14:02:47 +00:00
|
|
|
if (s->extra_bits) {
|
2017-03-06 20:52:36 +00:00
|
|
|
S *= 1 << s->extra_bits;
|
2009-05-05 06:10:59 +00:00
|
|
|
|
2013-05-18 14:02:47 +00:00
|
|
|
if (s->got_extra_bits &&
|
|
|
|
get_bits_left(&s->gb_extra_bits) >= s->extra_bits) {
|
2015-07-02 21:05:05 +00:00
|
|
|
S |= get_bits_long(&s->gb_extra_bits, s->extra_bits);
|
2012-01-02 05:14:16 +00:00
|
|
|
*crc = *crc * 9 + (S & 0xffff) * 3 + ((unsigned)S >> 16);
|
2009-05-05 06:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-03 19:35:23 +00:00
|
|
|
|
2009-05-05 06:10:59 +00:00
|
|
|
bit = (S & s->and) | s->or;
|
2012-02-24 00:26:38 +00:00
|
|
|
bit = ((S + bit) << s->shift) - bit;
|
2011-12-03 19:35:23 +00:00
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
if (s->hybrid)
|
2012-02-24 00:26:38 +00:00
|
|
|
bit = av_clip(bit, s->hybrid_minclip, s->hybrid_maxclip);
|
2011-12-03 19:35:23 +00:00
|
|
|
|
2012-01-15 13:23:28 +00:00
|
|
|
return bit << s->post_shift;
|
2009-05-05 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
2011-01-22 13:43:15 +00:00
|
|
|
static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S)
|
2009-05-06 05:40:43 +00:00
|
|
|
{
|
|
|
|
union {
|
|
|
|
float f;
|
|
|
|
uint32_t u;
|
|
|
|
} value;
|
|
|
|
|
2012-03-01 21:36:08 +00:00
|
|
|
unsigned int sign;
|
2009-05-06 05:40:43 +00:00
|
|
|
int exp = s->float_max_exp;
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
if (s->got_extra_bits) {
|
|
|
|
const int max_bits = 1 + 23 + 8 + 1;
|
2009-11-16 17:42:43 +00:00
|
|
|
const int left_bits = get_bits_left(&s->gb_extra_bits);
|
2009-05-06 05:40:43 +00:00
|
|
|
|
2015-06-29 21:48:34 +00:00
|
|
|
if (left_bits + 8 * AV_INPUT_BUFFER_PADDING_SIZE < max_bits)
|
2009-05-06 05:40:43 +00:00
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
if (S) {
|
2017-05-28 10:56:25 +00:00
|
|
|
S *= 1U << s->float_shift;
|
2009-05-06 05:40:43 +00:00
|
|
|
sign = S < 0;
|
2012-01-02 05:14:16 +00:00
|
|
|
if (sign)
|
2017-06-19 12:08:58 +00:00
|
|
|
S = -(unsigned)S;
|
|
|
|
if (S >= 0x1000000U) {
|
2012-01-02 05:14:16 +00:00
|
|
|
if (s->got_extra_bits && get_bits1(&s->gb_extra_bits))
|
2009-05-06 05:40:43 +00:00
|
|
|
S = get_bits(&s->gb_extra_bits, 23);
|
2012-01-02 05:14:16 +00:00
|
|
|
else
|
2009-05-06 05:40:43 +00:00
|
|
|
S = 0;
|
|
|
|
exp = 255;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else if (exp) {
|
2009-05-06 05:40:43 +00:00
|
|
|
int shift = 23 - av_log2(S);
|
|
|
|
exp = s->float_max_exp;
|
2012-01-02 05:14:16 +00:00
|
|
|
if (exp <= shift)
|
2009-05-06 05:40:43 +00:00
|
|
|
shift = --exp;
|
|
|
|
exp -= shift;
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
if (shift) {
|
2009-05-06 05:40:43 +00:00
|
|
|
S <<= shift;
|
2012-01-02 05:14:16 +00:00
|
|
|
if ((s->float_flag & WV_FLT_SHIFT_ONES) ||
|
2013-05-18 14:02:47 +00:00
|
|
|
(s->got_extra_bits &&
|
|
|
|
(s->float_flag & WV_FLT_SHIFT_SAME) &&
|
2012-01-02 05:14:16 +00:00
|
|
|
get_bits1(&s->gb_extra_bits))) {
|
2009-05-06 05:40:43 +00:00
|
|
|
S |= (1 << shift) - 1;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else if (s->got_extra_bits &&
|
|
|
|
(s->float_flag & WV_FLT_SHIFT_SENT)) {
|
2009-05-06 05:40:43 +00:00
|
|
|
S |= get_bits(&s->gb_extra_bits, shift);
|
|
|
|
}
|
|
|
|
}
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2009-05-06 05:40:43 +00:00
|
|
|
exp = s->float_max_exp;
|
|
|
|
}
|
|
|
|
S &= 0x7fffff;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2009-05-06 05:40:43 +00:00
|
|
|
sign = 0;
|
2013-05-18 14:02:47 +00:00
|
|
|
exp = 0;
|
2012-01-02 05:14:16 +00:00
|
|
|
if (s->got_extra_bits && (s->float_flag & WV_FLT_ZERO_SENT)) {
|
|
|
|
if (get_bits1(&s->gb_extra_bits)) {
|
2009-05-06 05:40:43 +00:00
|
|
|
S = get_bits(&s->gb_extra_bits, 23);
|
2012-01-02 05:14:16 +00:00
|
|
|
if (s->float_max_exp >= 25)
|
2009-05-06 05:40:43 +00:00
|
|
|
exp = get_bits(&s->gb_extra_bits, 8);
|
|
|
|
sign = get_bits1(&s->gb_extra_bits);
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
|
|
|
if (s->float_flag & WV_FLT_ZERO_SIGN)
|
2009-05-06 05:40:43 +00:00
|
|
|
sign = get_bits1(&s->gb_extra_bits);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*crc = *crc * 27 + S * 9 + exp * 3 + sign;
|
|
|
|
|
|
|
|
value.u = (sign << 31) | (exp << 23) | S;
|
|
|
|
return value.f;
|
|
|
|
}
|
|
|
|
|
2012-02-10 18:51:57 +00:00
|
|
|
static inline int wv_check_crc(WavpackFrameContext *s, uint32_t crc,
|
|
|
|
uint32_t crc_extra_bits)
|
|
|
|
{
|
|
|
|
if (crc != s->CRC) {
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
if (s->got_extra_bits && crc_extra_bits != s->crc_extra_bits) {
|
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-09 22:23:53 +00:00
|
|
|
static void init_ptable(int *table, int rate_i, int rate_s)
|
|
|
|
{
|
|
|
|
int value = 0x808000, rate = rate_i << 8;
|
|
|
|
|
|
|
|
for (int c = (rate + 128) >> 8; c--;)
|
|
|
|
value += (DOWN - value) >> DECAY;
|
|
|
|
|
|
|
|
for (int i = 0; i < PTABLE_BINS/2; i++) {
|
|
|
|
table[i] = value;
|
|
|
|
table[PTABLE_BINS-1-i] = 0x100ffff - value;
|
|
|
|
|
|
|
|
if (value > 0x010000) {
|
|
|
|
rate += (rate * rate_s + 128) >> 8;
|
|
|
|
|
|
|
|
for (int c = (rate + 64) >> 7; c--;)
|
|
|
|
value += (DOWN - value) >> DECAY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int32_t value, fltr0, fltr1, fltr2, fltr3, fltr4, fltr5, fltr6, factor;
|
|
|
|
unsigned int byte;
|
|
|
|
} DSDfilters;
|
|
|
|
|
|
|
|
static int wv_unpack_dsd_high(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
|
|
|
|
{
|
|
|
|
uint32_t checksum = 0xFFFFFFFF;
|
|
|
|
uint8_t *dst_l = dst_left, *dst_r = dst_right;
|
|
|
|
int total_samples = s->samples, stereo = dst_r ? 1 : 0;
|
|
|
|
DSDfilters filters[2], *sp = filters;
|
|
|
|
int rate_i, rate_s;
|
|
|
|
uint32_t low, high, value;
|
|
|
|
|
|
|
|
if (bytestream2_get_bytes_left(&s->gbyte) < (stereo ? 20 : 13))
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
rate_i = bytestream2_get_byte(&s->gbyte);
|
|
|
|
rate_s = bytestream2_get_byte(&s->gbyte);
|
|
|
|
|
|
|
|
if (rate_s != RATE_S)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
init_ptable(s->ptable, rate_i, rate_s);
|
|
|
|
|
|
|
|
for (int channel = 0; channel < stereo + 1; channel++) {
|
|
|
|
DSDfilters *sp = filters + channel;
|
|
|
|
|
|
|
|
sp->fltr1 = bytestream2_get_byte(&s->gbyte) << (PRECISION - 8);
|
|
|
|
sp->fltr2 = bytestream2_get_byte(&s->gbyte) << (PRECISION - 8);
|
|
|
|
sp->fltr3 = bytestream2_get_byte(&s->gbyte) << (PRECISION - 8);
|
|
|
|
sp->fltr4 = bytestream2_get_byte(&s->gbyte) << (PRECISION - 8);
|
|
|
|
sp->fltr5 = bytestream2_get_byte(&s->gbyte) << (PRECISION - 8);
|
|
|
|
sp->fltr6 = 0;
|
|
|
|
sp->factor = bytestream2_get_byte(&s->gbyte) & 0xff;
|
|
|
|
sp->factor |= (bytestream2_get_byte(&s->gbyte) << 8) & 0xff00;
|
|
|
|
sp->factor = (int32_t)((uint32_t)sp->factor << 16) >> 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = bytestream2_get_be32(&s->gbyte);
|
|
|
|
high = 0xffffffff;
|
|
|
|
low = 0x0;
|
|
|
|
|
|
|
|
while (total_samples--) {
|
|
|
|
int bitcount = 8;
|
|
|
|
|
|
|
|
sp[0].value = sp[0].fltr1 - sp[0].fltr5 + ((sp[0].fltr6 * sp[0].factor) >> 2);
|
|
|
|
|
|
|
|
if (stereo)
|
|
|
|
sp[1].value = sp[1].fltr1 - sp[1].fltr5 + ((sp[1].fltr6 * sp[1].factor) >> 2);
|
|
|
|
|
|
|
|
while (bitcount--) {
|
|
|
|
int32_t *pp = s->ptable + ((sp[0].value >> (PRECISION - PRECISION_USE)) & PTABLE_MASK);
|
|
|
|
uint32_t split = low + ((high - low) >> 8) * (*pp >> 16);
|
|
|
|
|
|
|
|
if (value <= split) {
|
|
|
|
high = split;
|
|
|
|
*pp += (UP - *pp) >> DECAY;
|
|
|
|
sp[0].fltr0 = -1;
|
|
|
|
} else {
|
|
|
|
low = split + 1;
|
|
|
|
*pp += (DOWN - *pp) >> DECAY;
|
|
|
|
sp[0].fltr0 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (DSD_BYTE_READY(high, low) && bytestream2_get_bytes_left(&s->gbyte)) {
|
|
|
|
value = (value << 8) | bytestream2_get_byte(&s->gbyte);
|
|
|
|
high = (high << 8) | 0xff;
|
|
|
|
low <<= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp[0].value += sp[0].fltr6 * 8;
|
|
|
|
sp[0].byte = (sp[0].byte << 1) | (sp[0].fltr0 & 1);
|
|
|
|
sp[0].factor += (((sp[0].value ^ sp[0].fltr0) >> 31) | 1) &
|
|
|
|
((sp[0].value ^ (sp[0].value - (sp[0].fltr6 * 16))) >> 31);
|
|
|
|
sp[0].fltr1 += ((sp[0].fltr0 & VALUE_ONE) - sp[0].fltr1) >> 6;
|
|
|
|
sp[0].fltr2 += ((sp[0].fltr0 & VALUE_ONE) - sp[0].fltr2) >> 4;
|
|
|
|
sp[0].fltr3 += (sp[0].fltr2 - sp[0].fltr3) >> 4;
|
|
|
|
sp[0].fltr4 += (sp[0].fltr3 - sp[0].fltr4) >> 4;
|
|
|
|
sp[0].value = (sp[0].fltr4 - sp[0].fltr5) >> 4;
|
|
|
|
sp[0].fltr5 += sp[0].value;
|
|
|
|
sp[0].fltr6 += (sp[0].value - sp[0].fltr6) >> 3;
|
|
|
|
sp[0].value = sp[0].fltr1 - sp[0].fltr5 + ((sp[0].fltr6 * sp[0].factor) >> 2);
|
|
|
|
|
|
|
|
if (!stereo)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pp = s->ptable + ((sp[1].value >> (PRECISION - PRECISION_USE)) & PTABLE_MASK);
|
|
|
|
split = low + ((high - low) >> 8) * (*pp >> 16);
|
|
|
|
|
|
|
|
if (value <= split) {
|
|
|
|
high = split;
|
|
|
|
*pp += (UP - *pp) >> DECAY;
|
|
|
|
sp[1].fltr0 = -1;
|
|
|
|
} else {
|
|
|
|
low = split + 1;
|
|
|
|
*pp += (DOWN - *pp) >> DECAY;
|
|
|
|
sp[1].fltr0 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (DSD_BYTE_READY(high, low) && bytestream2_get_bytes_left(&s->gbyte)) {
|
|
|
|
value = (value << 8) | bytestream2_get_byte(&s->gbyte);
|
|
|
|
high = (high << 8) | 0xff;
|
|
|
|
low <<= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp[1].value += sp[1].fltr6 * 8;
|
|
|
|
sp[1].byte = (sp[1].byte << 1) | (sp[1].fltr0 & 1);
|
|
|
|
sp[1].factor += (((sp[1].value ^ sp[1].fltr0) >> 31) | 1) &
|
|
|
|
((sp[1].value ^ (sp[1].value - (sp[1].fltr6 * 16))) >> 31);
|
|
|
|
sp[1].fltr1 += ((sp[1].fltr0 & VALUE_ONE) - sp[1].fltr1) >> 6;
|
|
|
|
sp[1].fltr2 += ((sp[1].fltr0 & VALUE_ONE) - sp[1].fltr2) >> 4;
|
|
|
|
sp[1].fltr3 += (sp[1].fltr2 - sp[1].fltr3) >> 4;
|
|
|
|
sp[1].fltr4 += (sp[1].fltr3 - sp[1].fltr4) >> 4;
|
|
|
|
sp[1].value = (sp[1].fltr4 - sp[1].fltr5) >> 4;
|
|
|
|
sp[1].fltr5 += sp[1].value;
|
|
|
|
sp[1].fltr6 += (sp[1].value - sp[1].fltr6) >> 3;
|
|
|
|
sp[1].value = sp[1].fltr1 - sp[1].fltr5 + ((sp[1].fltr6 * sp[1].factor) >> 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
checksum += (checksum << 1) + (*dst_l = sp[0].byte & 0xff);
|
|
|
|
sp[0].factor -= (sp[0].factor + 512) >> 10;
|
|
|
|
dst_l += 4;
|
|
|
|
|
|
|
|
if (stereo) {
|
|
|
|
checksum += (checksum << 1) + (*dst_r = filters[1].byte & 0xff);
|
|
|
|
filters[1].factor -= (filters[1].factor + 512) >> 10;
|
|
|
|
dst_r += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wv_check_crc(s, checksum, 0)) {
|
|
|
|
if (s->avctx->err_recognition & AV_EF_CRCCHECK)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
memset(dst_left, 0x69, s->samples * 4);
|
|
|
|
|
|
|
|
if (dst_r)
|
|
|
|
memset(dst_right, 0x69, s->samples * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wv_unpack_dsd_fast(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
|
|
|
|
{
|
|
|
|
uint8_t *dst_l = dst_left, *dst_r = dst_right;
|
|
|
|
uint8_t history_bits, max_probability;
|
|
|
|
int total_summed_probabilities = 0;
|
|
|
|
int total_samples = s->samples;
|
|
|
|
uint8_t *vlb = s->value_lookup_buffer;
|
|
|
|
int history_bins, p0, p1, chan;
|
|
|
|
uint32_t checksum = 0xFFFFFFFF;
|
|
|
|
uint32_t low, high, value;
|
|
|
|
|
|
|
|
if (!bytestream2_get_bytes_left(&s->gbyte))
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
history_bits = bytestream2_get_byte(&s->gbyte);
|
|
|
|
|
|
|
|
if (!bytestream2_get_bytes_left(&s->gbyte) || history_bits > MAX_HISTORY_BITS)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
history_bins = 1 << history_bits;
|
|
|
|
max_probability = bytestream2_get_byte(&s->gbyte);
|
|
|
|
|
|
|
|
if (max_probability < 0xff) {
|
2020-03-11 20:50:02 +00:00
|
|
|
uint8_t *outptr = (uint8_t *)s->probabilities;
|
|
|
|
uint8_t *outend = outptr + sizeof(*s->probabilities) * history_bins;
|
2020-03-09 22:23:53 +00:00
|
|
|
|
|
|
|
while (outptr < outend && bytestream2_get_bytes_left(&s->gbyte)) {
|
|
|
|
int code = bytestream2_get_byte(&s->gbyte);
|
|
|
|
|
|
|
|
if (code > max_probability) {
|
|
|
|
int zcount = code - max_probability;
|
|
|
|
|
|
|
|
while (outptr < outend && zcount--)
|
|
|
|
*outptr++ = 0;
|
|
|
|
} else if (code) {
|
|
|
|
*outptr++ = code;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outptr < outend ||
|
|
|
|
(bytestream2_get_bytes_left(&s->gbyte) && bytestream2_get_byte(&s->gbyte)))
|
|
|
|
return AVERROR_INVALIDDATA;
|
2020-03-11 20:50:02 +00:00
|
|
|
} else if (bytestream2_get_bytes_left(&s->gbyte) > (int)sizeof(*s->probabilities) * history_bins) {
|
|
|
|
bytestream2_get_buffer(&s->gbyte, (uint8_t *)s->probabilities,
|
|
|
|
sizeof(*s->probabilities) * history_bins);
|
2020-03-09 22:23:53 +00:00
|
|
|
} else {
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (p0 = 0; p0 < history_bins; p0++) {
|
|
|
|
int32_t sum_values = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < 256; i++)
|
|
|
|
s->summed_probabilities[p0][i] = sum_values += s->probabilities[p0][i];
|
|
|
|
|
|
|
|
if (sum_values) {
|
|
|
|
total_summed_probabilities += sum_values;
|
|
|
|
|
|
|
|
if (total_summed_probabilities > history_bins * MAX_BIN_BYTES)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
s->value_lookup[p0] = vlb;
|
|
|
|
|
|
|
|
for (int i = 0; i < 256; i++) {
|
|
|
|
int c = s->probabilities[p0][i];
|
|
|
|
|
|
|
|
while (c--)
|
|
|
|
*vlb++ = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bytestream2_get_bytes_left(&s->gbyte) < 4)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
chan = p0 = p1 = 0;
|
|
|
|
low = 0; high = 0xffffffff;
|
|
|
|
value = bytestream2_get_be32(&s->gbyte);
|
|
|
|
|
|
|
|
if (dst_r)
|
|
|
|
total_samples *= 2;
|
|
|
|
|
|
|
|
while (total_samples--) {
|
|
|
|
unsigned int mult, index, code;
|
|
|
|
|
|
|
|
if (!s->summed_probabilities[p0][255])
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
mult = (high - low) / s->summed_probabilities[p0][255];
|
|
|
|
|
|
|
|
if (!mult) {
|
|
|
|
if (bytestream2_get_bytes_left(&s->gbyte) >= 4)
|
|
|
|
value = bytestream2_get_be32(&s->gbyte);
|
|
|
|
|
|
|
|
low = 0;
|
|
|
|
high = 0xffffffff;
|
|
|
|
mult = high / s->summed_probabilities[p0][255];
|
|
|
|
|
|
|
|
if (!mult)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = (value - low) / mult;
|
|
|
|
|
|
|
|
if (index >= s->summed_probabilities[p0][255])
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
if (!dst_r) {
|
|
|
|
if ((*dst_l = code = s->value_lookup[p0][index]))
|
|
|
|
low += s->summed_probabilities[p0][code-1] * mult;
|
|
|
|
|
|
|
|
dst_l += 4;
|
|
|
|
} else {
|
|
|
|
if ((code = s->value_lookup[p0][index]))
|
|
|
|
low += s->summed_probabilities[p0][code-1] * mult;
|
|
|
|
|
|
|
|
if (chan) {
|
|
|
|
*dst_r = code;
|
|
|
|
dst_r += 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*dst_l = code;
|
|
|
|
dst_l += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
chan ^= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
high = low + s->probabilities[p0][code] * mult - 1;
|
|
|
|
checksum += (checksum << 1) + code;
|
|
|
|
|
|
|
|
if (!dst_r) {
|
|
|
|
p0 = code & (history_bins-1);
|
|
|
|
} else {
|
|
|
|
p0 = p1;
|
|
|
|
p1 = code & (history_bins-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (DSD_BYTE_READY(high, low) && bytestream2_get_bytes_left(&s->gbyte)) {
|
|
|
|
value = (value << 8) | bytestream2_get_byte(&s->gbyte);
|
|
|
|
high = (high << 8) | 0xff;
|
|
|
|
low <<= 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wv_check_crc(s, checksum, 0)) {
|
|
|
|
if (s->avctx->err_recognition & AV_EF_CRCCHECK)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
memset(dst_left, 0x69, s->samples * 4);
|
|
|
|
|
|
|
|
if (dst_r)
|
|
|
|
memset(dst_right, 0x69, s->samples * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wv_unpack_dsd_copy(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
|
|
|
|
{
|
|
|
|
uint8_t *dst_l = dst_left, *dst_r = dst_right;
|
|
|
|
int total_samples = s->samples;
|
|
|
|
uint32_t checksum = 0xFFFFFFFF;
|
|
|
|
|
|
|
|
if (bytestream2_get_bytes_left(&s->gbyte) != total_samples * (dst_r ? 2 : 1))
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
while (total_samples--) {
|
|
|
|
checksum += (checksum << 1) + (*dst_l = bytestream2_get_byte(&s->gbyte));
|
|
|
|
dst_l += 4;
|
|
|
|
|
|
|
|
if (dst_r) {
|
|
|
|
checksum += (checksum << 1) + (*dst_r = bytestream2_get_byte(&s->gbyte));
|
|
|
|
dst_r += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wv_check_crc(s, checksum, 0)) {
|
|
|
|
if (s->avctx->err_recognition & AV_EF_CRCCHECK)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
memset(dst_left, 0x69, s->samples * 4);
|
|
|
|
|
|
|
|
if (dst_r)
|
|
|
|
memset(dst_right, 0x69, s->samples * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb,
|
2013-05-25 13:31:18 +00:00
|
|
|
void *dst_l, void *dst_r, const int type)
|
2006-09-26 03:41:51 +00:00
|
|
|
{
|
|
|
|
int i, j, count = 0;
|
|
|
|
int last, t;
|
2009-05-05 06:10:59 +00:00
|
|
|
int A, B, L, L2, R, R2;
|
2020-03-09 22:23:53 +00:00
|
|
|
int pos = 0;
|
|
|
|
uint32_t crc = 0xFFFFFFFF;
|
|
|
|
uint32_t crc_extra_bits = 0xFFFFFFFF;
|
2013-05-25 13:31:18 +00:00
|
|
|
int16_t *dst16_l = dst_l;
|
|
|
|
int16_t *dst16_r = dst_r;
|
|
|
|
int32_t *dst32_l = dst_l;
|
|
|
|
int32_t *dst32_r = dst_r;
|
|
|
|
float *dstfl_l = dst_l;
|
|
|
|
float *dstfl_r = dst_r;
|
2006-09-26 03:41:51 +00:00
|
|
|
|
2011-09-06 16:17:45 +00:00
|
|
|
s->one = s->zero = s->zeroes = 0;
|
2012-01-02 05:14:16 +00:00
|
|
|
do {
|
2009-01-16 17:46:19 +00:00
|
|
|
L = wv_get_value(s, gb, 0, &last);
|
2012-01-02 05:14:16 +00:00
|
|
|
if (last)
|
|
|
|
break;
|
2009-01-16 17:46:19 +00:00
|
|
|
R = wv_get_value(s, gb, 1, &last);
|
2012-01-02 05:14:16 +00:00
|
|
|
if (last)
|
|
|
|
break;
|
|
|
|
for (i = 0; i < s->terms; i++) {
|
2006-09-26 03:41:51 +00:00
|
|
|
t = s->decorr[i].value;
|
2012-01-02 05:14:16 +00:00
|
|
|
if (t > 0) {
|
|
|
|
if (t > 8) {
|
|
|
|
if (t & 1) {
|
2017-03-14 00:17:53 +00:00
|
|
|
A = 2U * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1];
|
|
|
|
B = 2U * s->decorr[i].samplesB[0] - s->decorr[i].samplesB[1];
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2017-03-14 00:17:53 +00:00
|
|
|
A = (int)(3U * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1]) >> 1;
|
|
|
|
B = (int)(3U * s->decorr[i].samplesB[0] - s->decorr[i].samplesB[1]) >> 1;
|
2006-09-26 03:41:51 +00:00
|
|
|
}
|
|
|
|
s->decorr[i].samplesA[1] = s->decorr[i].samplesA[0];
|
|
|
|
s->decorr[i].samplesB[1] = s->decorr[i].samplesB[0];
|
2013-05-18 14:02:47 +00:00
|
|
|
j = 0;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2006-09-26 03:41:51 +00:00
|
|
|
A = s->decorr[i].samplesA[pos];
|
|
|
|
B = s->decorr[i].samplesB[pos];
|
|
|
|
j = (pos + t) & 7;
|
|
|
|
}
|
2013-05-25 13:31:18 +00:00
|
|
|
if (type != AV_SAMPLE_FMT_S16P) {
|
2009-04-24 05:50:19 +00:00
|
|
|
L2 = L + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10);
|
|
|
|
R2 = R + ((s->decorr[i].weightB * (int64_t)B + 512) >> 10);
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2018-01-13 23:39:41 +00:00
|
|
|
L2 = L + (unsigned)((int)(s->decorr[i].weightA * (unsigned)A + 512) >> 10);
|
|
|
|
R2 = R + (unsigned)((int)(s->decorr[i].weightB * (unsigned)B + 512) >> 10);
|
2009-04-23 17:27:04 +00:00
|
|
|
}
|
2013-05-18 14:02:47 +00:00
|
|
|
if (A && L)
|
|
|
|
s->decorr[i].weightA -= ((((L ^ A) >> 30) & 2) - 1) * s->decorr[i].delta;
|
|
|
|
if (B && R)
|
|
|
|
s->decorr[i].weightB -= ((((R ^ B) >> 30) & 2) - 1) * s->decorr[i].delta;
|
2009-04-23 17:27:04 +00:00
|
|
|
s->decorr[i].samplesA[j] = L = L2;
|
|
|
|
s->decorr[i].samplesB[j] = R = R2;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else if (t == -1) {
|
2013-05-25 13:31:18 +00:00
|
|
|
if (type != AV_SAMPLE_FMT_S16P)
|
2009-04-24 05:50:19 +00:00
|
|
|
L2 = L + ((s->decorr[i].weightA * (int64_t)s->decorr[i].samplesA[0] + 512) >> 10);
|
|
|
|
else
|
2018-01-13 23:39:41 +00:00
|
|
|
L2 = L + (unsigned)((int)(s->decorr[i].weightA * (unsigned)s->decorr[i].samplesA[0] + 512) >> 10);
|
2009-04-23 17:27:04 +00:00
|
|
|
UPDATE_WEIGHT_CLIP(s->decorr[i].weightA, s->decorr[i].delta, s->decorr[i].samplesA[0], L);
|
|
|
|
L = L2;
|
2013-05-25 13:31:18 +00:00
|
|
|
if (type != AV_SAMPLE_FMT_S16P)
|
2009-04-24 05:50:19 +00:00
|
|
|
R2 = R + ((s->decorr[i].weightB * (int64_t)L2 + 512) >> 10);
|
|
|
|
else
|
2018-04-27 19:44:06 +00:00
|
|
|
R2 = R + (unsigned)((int)(s->decorr[i].weightB * (unsigned)L2 + 512) >> 10);
|
2009-04-23 17:27:04 +00:00
|
|
|
UPDATE_WEIGHT_CLIP(s->decorr[i].weightB, s->decorr[i].delta, L2, R);
|
2013-05-18 14:02:47 +00:00
|
|
|
R = R2;
|
2009-04-23 17:27:04 +00:00
|
|
|
s->decorr[i].samplesA[0] = R;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2013-05-25 13:31:18 +00:00
|
|
|
if (type != AV_SAMPLE_FMT_S16P)
|
2009-04-24 05:50:19 +00:00
|
|
|
R2 = R + ((s->decorr[i].weightB * (int64_t)s->decorr[i].samplesB[0] + 512) >> 10);
|
|
|
|
else
|
2018-01-13 23:39:41 +00:00
|
|
|
R2 = R + (unsigned)((int)(s->decorr[i].weightB * (unsigned)s->decorr[i].samplesB[0] + 512) >> 10);
|
2009-04-23 17:27:04 +00:00
|
|
|
UPDATE_WEIGHT_CLIP(s->decorr[i].weightB, s->decorr[i].delta, s->decorr[i].samplesB[0], R);
|
|
|
|
R = R2;
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
if (t == -3) {
|
2013-05-18 14:02:47 +00:00
|
|
|
R2 = s->decorr[i].samplesA[0];
|
2009-04-23 17:27:04 +00:00
|
|
|
s->decorr[i].samplesA[0] = R;
|
|
|
|
}
|
|
|
|
|
2013-05-25 13:31:18 +00:00
|
|
|
if (type != AV_SAMPLE_FMT_S16P)
|
2009-04-24 05:50:19 +00:00
|
|
|
L2 = L + ((s->decorr[i].weightA * (int64_t)R2 + 512) >> 10);
|
|
|
|
else
|
2018-01-13 23:39:41 +00:00
|
|
|
L2 = L + (unsigned)((int)(s->decorr[i].weightA * (unsigned)R2 + 512) >> 10);
|
2009-04-23 17:27:04 +00:00
|
|
|
UPDATE_WEIGHT_CLIP(s->decorr[i].weightA, s->decorr[i].delta, R2, L);
|
2013-05-18 14:02:47 +00:00
|
|
|
L = L2;
|
2009-04-23 17:27:04 +00:00
|
|
|
s->decorr[i].samplesB[0] = L;
|
|
|
|
}
|
|
|
|
}
|
2015-05-03 13:54:21 +00:00
|
|
|
|
|
|
|
if (type == AV_SAMPLE_FMT_S16P) {
|
2018-01-31 01:50:18 +00:00
|
|
|
if (FFABS((int64_t)L) + FFABS((int64_t)R) > (1<<19)) {
|
2015-05-03 13:54:21 +00:00
|
|
|
av_log(s->avctx, AV_LOG_ERROR, "sample %d %d too large\n", L, R);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-23 17:27:04 +00:00
|
|
|
pos = (pos + 1) & 7;
|
2012-01-02 05:14:16 +00:00
|
|
|
if (s->joint)
|
2017-03-14 00:17:53 +00:00
|
|
|
L += (unsigned)(R -= (unsigned)(L >> 1));
|
2009-04-23 17:27:04 +00:00
|
|
|
crc = (crc * 3 + L) * 3 + R;
|
2009-05-02 05:17:20 +00:00
|
|
|
|
2013-05-25 13:31:18 +00:00
|
|
|
if (type == AV_SAMPLE_FMT_FLTP) {
|
|
|
|
*dstfl_l++ = wv_get_value_float(s, &crc_extra_bits, L);
|
|
|
|
*dstfl_r++ = wv_get_value_float(s, &crc_extra_bits, R);
|
|
|
|
} else if (type == AV_SAMPLE_FMT_S32P) {
|
|
|
|
*dst32_l++ = wv_get_value_integer(s, &crc_extra_bits, L);
|
|
|
|
*dst32_r++ = wv_get_value_integer(s, &crc_extra_bits, R);
|
2009-05-05 06:10:59 +00:00
|
|
|
} else {
|
2013-05-25 13:31:18 +00:00
|
|
|
*dst16_l++ = wv_get_value_integer(s, &crc_extra_bits, L);
|
|
|
|
*dst16_r++ = wv_get_value_integer(s, &crc_extra_bits, R);
|
2009-05-02 05:17:20 +00:00
|
|
|
}
|
2009-04-23 17:27:04 +00:00
|
|
|
count++;
|
2011-09-06 16:17:45 +00:00
|
|
|
} while (!last && count < s->samples);
|
2009-04-23 17:27:04 +00:00
|
|
|
|
2013-12-22 23:17:52 +00:00
|
|
|
if (last && count < s->samples) {
|
|
|
|
int size = av_get_bytes_per_sample(type);
|
2013-12-23 22:06:10 +00:00
|
|
|
memset((uint8_t*)dst_l + count*size, 0, (s->samples-count)*size);
|
|
|
|
memset((uint8_t*)dst_r + count*size, 0, (s->samples-count)*size);
|
2013-12-22 23:17:52 +00:00
|
|
|
}
|
|
|
|
|
2012-02-10 18:51:57 +00:00
|
|
|
if ((s->avctx->err_recognition & AV_EF_CRCCHECK) &&
|
|
|
|
wv_check_crc(s, crc, crc_extra_bits))
|
|
|
|
return AVERROR_INVALIDDATA;
|
2011-09-06 16:17:45 +00:00
|
|
|
|
2013-05-26 08:32:56 +00:00
|
|
|
return 0;
|
2009-04-23 17:27:04 +00:00
|
|
|
}
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb,
|
|
|
|
void *dst, const int type)
|
2009-04-23 17:27:04 +00:00
|
|
|
{
|
|
|
|
int i, j, count = 0;
|
|
|
|
int last, t;
|
2009-05-05 06:10:59 +00:00
|
|
|
int A, S, T;
|
2020-03-09 22:23:53 +00:00
|
|
|
int pos = 0;
|
|
|
|
uint32_t crc = 0xFFFFFFFF;
|
|
|
|
uint32_t crc_extra_bits = 0xFFFFFFFF;
|
2013-05-18 14:02:47 +00:00
|
|
|
int16_t *dst16 = dst;
|
|
|
|
int32_t *dst32 = dst;
|
|
|
|
float *dstfl = dst;
|
2009-04-23 17:27:04 +00:00
|
|
|
|
2011-09-06 16:17:45 +00:00
|
|
|
s->one = s->zero = s->zeroes = 0;
|
2012-01-02 05:14:16 +00:00
|
|
|
do {
|
2009-04-23 17:27:04 +00:00
|
|
|
T = wv_get_value(s, gb, 0, &last);
|
|
|
|
S = 0;
|
2012-01-02 05:14:16 +00:00
|
|
|
if (last)
|
|
|
|
break;
|
|
|
|
for (i = 0; i < s->terms; i++) {
|
2009-04-23 17:27:04 +00:00
|
|
|
t = s->decorr[i].value;
|
2012-01-02 05:14:16 +00:00
|
|
|
if (t > 8) {
|
|
|
|
if (t & 1)
|
2017-05-23 22:21:20 +00:00
|
|
|
A = 2U * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1];
|
2009-04-23 17:27:04 +00:00
|
|
|
else
|
2017-05-23 22:21:20 +00:00
|
|
|
A = (int)(3U * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1]) >> 1;
|
2009-04-23 17:27:04 +00:00
|
|
|
s->decorr[i].samplesA[1] = s->decorr[i].samplesA[0];
|
2013-05-18 14:02:47 +00:00
|
|
|
j = 0;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2009-04-23 17:27:04 +00:00
|
|
|
A = s->decorr[i].samplesA[pos];
|
|
|
|
j = (pos + t) & 7;
|
|
|
|
}
|
2013-05-25 13:31:18 +00:00
|
|
|
if (type != AV_SAMPLE_FMT_S16P)
|
2009-04-24 05:50:19 +00:00
|
|
|
S = T + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10);
|
|
|
|
else
|
2018-01-13 23:39:41 +00:00
|
|
|
S = T + (unsigned)((int)(s->decorr[i].weightA * (unsigned)A + 512) >> 10);
|
2012-01-02 05:14:16 +00:00
|
|
|
if (A && T)
|
|
|
|
s->decorr[i].weightA -= ((((T ^ A) >> 30) & 2) - 1) * s->decorr[i].delta;
|
2009-04-23 17:27:04 +00:00
|
|
|
s->decorr[i].samplesA[j] = T = S;
|
|
|
|
}
|
|
|
|
pos = (pos + 1) & 7;
|
|
|
|
crc = crc * 3 + S;
|
2009-05-02 05:17:20 +00:00
|
|
|
|
2013-05-25 13:31:18 +00:00
|
|
|
if (type == AV_SAMPLE_FMT_FLTP) {
|
|
|
|
*dstfl++ = wv_get_value_float(s, &crc_extra_bits, S);
|
|
|
|
} else if (type == AV_SAMPLE_FMT_S32P) {
|
|
|
|
*dst32++ = wv_get_value_integer(s, &crc_extra_bits, S);
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2013-05-25 13:31:18 +00:00
|
|
|
*dst16++ = wv_get_value_integer(s, &crc_extra_bits, S);
|
2011-01-22 13:43:15 +00:00
|
|
|
}
|
2009-04-23 17:27:04 +00:00
|
|
|
count++;
|
2011-09-06 16:17:45 +00:00
|
|
|
} while (!last && count < s->samples);
|
2009-04-23 17:27:04 +00:00
|
|
|
|
2013-12-22 23:17:52 +00:00
|
|
|
if (last && count < s->samples) {
|
|
|
|
int size = av_get_bytes_per_sample(type);
|
2013-12-23 22:06:10 +00:00
|
|
|
memset((uint8_t*)dst + count*size, 0, (s->samples-count)*size);
|
2013-12-22 23:17:52 +00:00
|
|
|
}
|
|
|
|
|
2013-10-26 20:46:48 +00:00
|
|
|
if (s->avctx->err_recognition & AV_EF_CRCCHECK) {
|
|
|
|
int ret = wv_check_crc(s, crc, crc_extra_bits);
|
|
|
|
if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE)
|
|
|
|
return ret;
|
|
|
|
}
|
2011-09-06 16:17:45 +00:00
|
|
|
|
2013-05-26 08:32:56 +00:00
|
|
|
return 0;
|
2009-04-23 17:27:04 +00:00
|
|
|
}
|
|
|
|
|
2011-01-22 13:43:15 +00:00
|
|
|
static av_cold int wv_alloc_frame_context(WavpackContext *c)
|
|
|
|
{
|
2012-01-02 05:14:16 +00:00
|
|
|
if (c->fdec_num == WV_MAX_FRAME_DECODERS)
|
2011-01-22 13:43:15 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
c->fdec[c->fdec_num] = av_mallocz(sizeof(**c->fdec));
|
2012-01-02 05:14:16 +00:00
|
|
|
if (!c->fdec[c->fdec_num])
|
2011-01-22 13:43:15 +00:00
|
|
|
return -1;
|
|
|
|
c->fdec_num++;
|
|
|
|
c->fdec[c->fdec_num - 1]->avctx = c->avctx;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-05 20:01:40 +00:00
|
|
|
static int wv_dsd_reset(WavpackContext *s, int channels)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
s->dsdctx = NULL;
|
|
|
|
s->dsd_channels = 0;
|
|
|
|
av_buffer_unref(&s->dsd_ref);
|
|
|
|
|
|
|
|
if (!channels)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (channels > INT_MAX / sizeof(*s->dsdctx))
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
|
|
|
|
s->dsd_ref = av_buffer_allocz(channels * sizeof(*s->dsdctx));
|
|
|
|
if (!s->dsd_ref)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
s->dsdctx = (DSDContext*)s->dsd_ref->data;
|
|
|
|
s->dsd_channels = channels;
|
|
|
|
|
|
|
|
for (i = 0; i < channels; i++)
|
|
|
|
memset(s->dsdctx[i].buf, 0x69, sizeof(s->dsdctx[i].buf));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-17 02:22:27 +00:00
|
|
|
#if HAVE_THREADS
|
2020-03-09 22:23:53 +00:00
|
|
|
static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
|
|
|
|
{
|
|
|
|
WavpackContext *fsrc = src->priv_data;
|
|
|
|
WavpackContext *fdst = dst->priv_data;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (dst == src)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ff_thread_release_buffer(dst, &fdst->curr_frame);
|
|
|
|
if (fsrc->curr_frame.f->data[0]) {
|
|
|
|
if ((ret = ff_thread_ref_frame(&fdst->curr_frame, &fsrc->curr_frame)) < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-04-05 20:01:40 +00:00
|
|
|
fdst->dsdctx = NULL;
|
|
|
|
fdst->dsd_channels = 0;
|
2022-05-23 03:23:35 +00:00
|
|
|
ret = av_buffer_replace(&fdst->dsd_ref, fsrc->dsd_ref);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2020-04-05 20:01:40 +00:00
|
|
|
if (fsrc->dsd_ref) {
|
|
|
|
fdst->dsdctx = (DSDContext*)fdst->dsd_ref->data;
|
|
|
|
fdst->dsd_channels = fsrc->dsd_channels;
|
|
|
|
}
|
|
|
|
|
2013-06-13 21:49:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-09-17 02:22:27 +00:00
|
|
|
#endif
|
2013-06-13 21:49:18 +00:00
|
|
|
|
2008-03-21 03:11:20 +00:00
|
|
|
static av_cold int wavpack_decode_init(AVCodecContext *avctx)
|
2006-09-26 03:41:51 +00:00
|
|
|
{
|
|
|
|
WavpackContext *s = avctx->priv_data;
|
|
|
|
|
|
|
|
s->avctx = avctx;
|
2013-05-26 09:02:51 +00:00
|
|
|
|
2011-01-22 13:43:15 +00:00
|
|
|
s->fdec_num = 0;
|
2010-02-19 14:05:41 +00:00
|
|
|
|
2020-03-09 22:23:53 +00:00
|
|
|
s->curr_frame.f = av_frame_alloc();
|
|
|
|
s->prev_frame.f = av_frame_alloc();
|
|
|
|
|
2020-04-05 20:01:40 +00:00
|
|
|
if (!s->curr_frame.f || !s->prev_frame.f)
|
2020-03-09 22:23:53 +00:00
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
ff_init_dsd_data();
|
|
|
|
|
2006-09-26 03:41:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-22 13:43:15 +00:00
|
|
|
static av_cold int wavpack_decode_end(AVCodecContext *avctx)
|
2006-09-26 03:41:51 +00:00
|
|
|
{
|
|
|
|
WavpackContext *s = avctx->priv_data;
|
2011-01-22 13:43:15 +00:00
|
|
|
|
2020-03-09 22:23:53 +00:00
|
|
|
for (int i = 0; i < s->fdec_num; i++)
|
2011-01-22 13:43:15 +00:00
|
|
|
av_freep(&s->fdec[i]);
|
|
|
|
s->fdec_num = 0;
|
|
|
|
|
2020-03-09 22:23:53 +00:00
|
|
|
ff_thread_release_buffer(avctx, &s->curr_frame);
|
|
|
|
av_frame_free(&s->curr_frame.f);
|
|
|
|
|
|
|
|
ff_thread_release_buffer(avctx, &s->prev_frame);
|
|
|
|
av_frame_free(&s->prev_frame.f);
|
|
|
|
|
2020-04-05 20:01:40 +00:00
|
|
|
av_buffer_unref(&s->dsd_ref);
|
2020-03-09 22:23:53 +00:00
|
|
|
|
2011-01-22 13:43:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
|
2020-03-09 22:23:53 +00:00
|
|
|
const uint8_t *buf, int buf_size)
|
2011-01-22 13:43:15 +00:00
|
|
|
{
|
|
|
|
WavpackContext *wc = avctx->priv_data;
|
|
|
|
WavpackFrameContext *s;
|
2013-05-22 10:27:04 +00:00
|
|
|
GetByteContext gb;
|
2020-04-05 20:01:40 +00:00
|
|
|
enum AVSampleFormat sample_fmt;
|
2014-05-07 00:13:56 +00:00
|
|
|
void *samples_l = NULL, *samples_r = NULL;
|
2013-05-26 08:32:56 +00:00
|
|
|
int ret;
|
2012-01-02 05:14:16 +00:00
|
|
|
int got_terms = 0, got_weights = 0, got_samples = 0,
|
2020-03-09 22:23:53 +00:00
|
|
|
got_entropy = 0, got_pcm = 0, got_float = 0, got_hybrid = 0;
|
|
|
|
int got_dsd = 0;
|
2006-09-26 03:41:51 +00:00
|
|
|
int i, j, id, size, ssize, weights, t;
|
2020-03-09 22:23:53 +00:00
|
|
|
int bpp, chan = 0, orig_bpp, sample_rate = 0, rate_x = 1, dsd_mode = 0;
|
2013-05-27 15:23:15 +00:00
|
|
|
int multiblock;
|
2020-03-09 22:23:53 +00:00
|
|
|
uint64_t chmask = 0;
|
2006-09-26 03:41:51 +00:00
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
if (block_no >= wc->fdec_num && wv_alloc_frame_context(wc) < 0) {
|
2011-01-22 13:43:15 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Error creating frame decode context\n");
|
2013-05-17 16:28:33 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2011-01-22 13:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s = wc->fdec[block_no];
|
2012-01-02 05:14:16 +00:00
|
|
|
if (!s) {
|
2013-05-18 14:02:47 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Context for block %d is not present\n",
|
|
|
|
block_no);
|
2013-05-17 16:28:33 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2011-01-22 13:43:15 +00:00
|
|
|
}
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
|
|
|
|
memset(s->ch, 0, sizeof(s->ch));
|
2013-05-18 14:02:47 +00:00
|
|
|
s->extra_bits = 0;
|
|
|
|
s->and = s->or = s->shift = 0;
|
2012-01-02 05:14:16 +00:00
|
|
|
s->got_extra_bits = 0;
|
2006-09-26 03:41:51 +00:00
|
|
|
|
2013-05-22 10:27:04 +00:00
|
|
|
bytestream2_init(&gb, buf, buf_size);
|
|
|
|
|
2013-05-27 07:44:27 +00:00
|
|
|
s->samples = bytestream2_get_le32(&gb);
|
|
|
|
if (s->samples != wc->samples) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Mismatching number of samples in "
|
|
|
|
"a sequence: %d and %d\n", wc->samples, s->samples);
|
|
|
|
return AVERROR_INVALIDDATA;
|
2011-01-22 13:43:15 +00:00
|
|
|
}
|
2013-05-22 10:27:04 +00:00
|
|
|
s->frame_flags = bytestream2_get_le32(&gb);
|
2020-04-05 20:01:40 +00:00
|
|
|
|
|
|
|
if (s->frame_flags & (WV_FLOAT_DATA | WV_DSD_DATA))
|
|
|
|
sample_fmt = AV_SAMPLE_FMT_FLTP;
|
|
|
|
else if ((s->frame_flags & 0x03) <= 1)
|
|
|
|
sample_fmt = AV_SAMPLE_FMT_S16P;
|
|
|
|
else
|
|
|
|
sample_fmt = AV_SAMPLE_FMT_S32P;
|
|
|
|
|
2020-06-03 19:13:47 +00:00
|
|
|
if (wc->ch_offset && avctx->sample_fmt != sample_fmt)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2020-04-05 20:01:40 +00:00
|
|
|
bpp = av_get_bytes_per_sample(sample_fmt);
|
2013-05-18 14:02:47 +00:00
|
|
|
orig_bpp = ((s->frame_flags & 0x03) + 1) << 3;
|
2013-05-27 15:23:15 +00:00
|
|
|
multiblock = (s->frame_flags & WV_SINGLE_BLOCK) != WV_SINGLE_BLOCK;
|
2011-01-22 13:43:15 +00:00
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
s->stereo = !(s->frame_flags & WV_MONO);
|
|
|
|
s->stereo_in = (s->frame_flags & WV_FALSE_STEREO) ? 0 : s->stereo;
|
|
|
|
s->joint = s->frame_flags & WV_JOINT_STEREO;
|
|
|
|
s->hybrid = s->frame_flags & WV_HYBRID_MODE;
|
|
|
|
s->hybrid_bitrate = s->frame_flags & WV_HYBRID_BITRATE;
|
2012-02-24 00:26:38 +00:00
|
|
|
s->post_shift = bpp * 8 - orig_bpp + ((s->frame_flags >> 13) & 0x1f);
|
2017-02-23 14:19:29 +00:00
|
|
|
if (s->post_shift < 0 || s->post_shift > 31) {
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2013-05-18 14:02:47 +00:00
|
|
|
s->hybrid_maxclip = ((1LL << (orig_bpp - 1)) - 1);
|
2017-02-19 14:09:34 +00:00
|
|
|
s->hybrid_minclip = ((-1UL << (orig_bpp - 1)));
|
2013-05-22 10:27:04 +00:00
|
|
|
s->CRC = bytestream2_get_le32(&gb);
|
|
|
|
|
2006-09-26 03:41:51 +00:00
|
|
|
// parse metadata blocks
|
2013-05-22 10:27:04 +00:00
|
|
|
while (bytestream2_get_bytes_left(&gb)) {
|
|
|
|
id = bytestream2_get_byte(&gb);
|
|
|
|
size = bytestream2_get_byte(&gb);
|
2020-03-09 22:23:53 +00:00
|
|
|
if (id & WP_IDF_LONG)
|
|
|
|
size |= (bytestream2_get_le16u(&gb)) << 8;
|
2006-09-26 03:41:51 +00:00
|
|
|
size <<= 1; // size is specified in words
|
2013-05-18 14:02:47 +00:00
|
|
|
ssize = size;
|
2012-01-02 05:14:16 +00:00
|
|
|
if (id & WP_IDF_ODD)
|
|
|
|
size--;
|
|
|
|
if (size < 0) {
|
2013-05-18 14:02:47 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
|
|
|
"Got incorrect block %02X with size %i\n", id, size);
|
2006-09-26 03:41:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-05-22 10:27:04 +00:00
|
|
|
if (bytestream2_get_bytes_left(&gb) < ssize) {
|
2013-05-18 14:02:47 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
|
|
|
"Block size %i is out of bounds\n", size);
|
2006-09-26 03:41:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-01-02 05:14:16 +00:00
|
|
|
switch (id & WP_IDF_MASK) {
|
2006-09-26 03:41:51 +00:00
|
|
|
case WP_ID_DECTERMS:
|
2012-01-02 05:14:16 +00:00
|
|
|
if (size > MAX_TERMS) {
|
2006-09-26 03:41:51 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Too many decorrelation terms\n");
|
2011-09-07 19:43:03 +00:00
|
|
|
s->terms = 0;
|
2013-05-22 10:27:04 +00:00
|
|
|
bytestream2_skip(&gb, ssize);
|
2006-09-26 03:41:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-09-07 19:43:03 +00:00
|
|
|
s->terms = size;
|
2012-01-02 05:14:16 +00:00
|
|
|
for (i = 0; i < s->terms; i++) {
|
2013-05-22 10:27:04 +00:00
|
|
|
uint8_t val = bytestream2_get_byte(&gb);
|
|
|
|
s->decorr[s->terms - i - 1].value = (val & 0x1F) - 5;
|
|
|
|
s->decorr[s->terms - i - 1].delta = val >> 5;
|
2006-09-26 03:41:51 +00:00
|
|
|
}
|
|
|
|
got_terms = 1;
|
|
|
|
break;
|
|
|
|
case WP_ID_DECWEIGHTS:
|
2012-01-02 05:14:16 +00:00
|
|
|
if (!got_terms) {
|
2006-09-26 03:41:51 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
|
|
|
|
continue;
|
|
|
|
}
|
2007-08-13 05:36:50 +00:00
|
|
|
weights = size >> s->stereo_in;
|
2012-01-02 05:14:16 +00:00
|
|
|
if (weights > MAX_TERMS || weights > s->terms) {
|
2006-09-26 03:41:51 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Too many decorrelation weights\n");
|
2013-05-22 10:27:04 +00:00
|
|
|
bytestream2_skip(&gb, ssize);
|
2006-09-26 03:41:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-01-02 05:14:16 +00:00
|
|
|
for (i = 0; i < weights; i++) {
|
2013-05-22 10:27:04 +00:00
|
|
|
t = (int8_t)bytestream2_get_byte(&gb);
|
2017-03-04 03:55:15 +00:00
|
|
|
s->decorr[s->terms - i - 1].weightA = t * (1 << 3);
|
2012-01-02 05:14:16 +00:00
|
|
|
if (s->decorr[s->terms - i - 1].weightA > 0)
|
|
|
|
s->decorr[s->terms - i - 1].weightA +=
|
2013-05-18 14:02:47 +00:00
|
|
|
(s->decorr[s->terms - i - 1].weightA + 64) >> 7;
|
2012-01-02 05:14:16 +00:00
|
|
|
if (s->stereo_in) {
|
2013-05-22 10:27:04 +00:00
|
|
|
t = (int8_t)bytestream2_get_byte(&gb);
|
2017-03-04 03:55:15 +00:00
|
|
|
s->decorr[s->terms - i - 1].weightB = t * (1 << 3);
|
2012-01-02 05:14:16 +00:00
|
|
|
if (s->decorr[s->terms - i - 1].weightB > 0)
|
|
|
|
s->decorr[s->terms - i - 1].weightB +=
|
2013-05-18 14:02:47 +00:00
|
|
|
(s->decorr[s->terms - i - 1].weightB + 64) >> 7;
|
2006-09-26 03:41:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
got_weights = 1;
|
|
|
|
break;
|
|
|
|
case WP_ID_DECSAMPLES:
|
2012-01-02 05:14:16 +00:00
|
|
|
if (!got_terms) {
|
2006-09-26 03:41:51 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
t = 0;
|
2012-01-02 13:54:30 +00:00
|
|
|
for (i = s->terms - 1; (i >= 0) && (t < size); i--) {
|
2012-01-02 05:14:16 +00:00
|
|
|
if (s->decorr[i].value > 8) {
|
2013-05-22 10:27:04 +00:00
|
|
|
s->decorr[i].samplesA[0] =
|
|
|
|
wp_exp2(bytestream2_get_le16(&gb));
|
|
|
|
s->decorr[i].samplesA[1] =
|
|
|
|
wp_exp2(bytestream2_get_le16(&gb));
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
if (s->stereo_in) {
|
2013-05-22 10:27:04 +00:00
|
|
|
s->decorr[i].samplesB[0] =
|
|
|
|
wp_exp2(bytestream2_get_le16(&gb));
|
|
|
|
s->decorr[i].samplesB[1] =
|
|
|
|
wp_exp2(bytestream2_get_le16(&gb));
|
2013-05-18 14:02:47 +00:00
|
|
|
t += 4;
|
2006-09-26 03:41:51 +00:00
|
|
|
}
|
|
|
|
t += 4;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else if (s->decorr[i].value < 0) {
|
2013-05-22 10:27:04 +00:00
|
|
|
s->decorr[i].samplesA[0] =
|
|
|
|
wp_exp2(bytestream2_get_le16(&gb));
|
|
|
|
s->decorr[i].samplesB[0] =
|
|
|
|
wp_exp2(bytestream2_get_le16(&gb));
|
2013-05-18 14:02:47 +00:00
|
|
|
t += 4;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
|
|
|
for (j = 0; j < s->decorr[i].value; j++) {
|
2013-05-22 10:27:04 +00:00
|
|
|
s->decorr[i].samplesA[j] =
|
|
|
|
wp_exp2(bytestream2_get_le16(&gb));
|
2012-02-11 01:18:10 +00:00
|
|
|
if (s->stereo_in) {
|
2013-05-22 10:27:04 +00:00
|
|
|
s->decorr[i].samplesB[j] =
|
|
|
|
wp_exp2(bytestream2_get_le16(&gb));
|
2012-02-11 01:18:10 +00:00
|
|
|
}
|
2006-09-26 03:41:51 +00:00
|
|
|
}
|
2007-08-13 05:36:50 +00:00
|
|
|
t += s->decorr[i].value * 2 * (s->stereo_in + 1);
|
2006-09-26 03:41:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
got_samples = 1;
|
|
|
|
break;
|
|
|
|
case WP_ID_ENTROPY:
|
2012-01-02 05:14:16 +00:00
|
|
|
if (size != 6 * (s->stereo_in + 1)) {
|
2013-05-18 14:02:47 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
2013-06-08 17:38:32 +00:00
|
|
|
"Entropy vars size should be %i, got %i.\n",
|
2013-05-18 14:02:47 +00:00
|
|
|
6 * (s->stereo_in + 1), size);
|
2013-05-22 10:27:04 +00:00
|
|
|
bytestream2_skip(&gb, ssize);
|
2006-09-26 03:41:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-05-18 14:02:47 +00:00
|
|
|
for (j = 0; j <= s->stereo_in; j++)
|
2012-01-02 05:14:16 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2013-05-22 10:27:04 +00:00
|
|
|
s->ch[j].median[i] = wp_exp2(bytestream2_get_le16(&gb));
|
2009-01-16 17:46:19 +00:00
|
|
|
}
|
2006-09-26 03:41:51 +00:00
|
|
|
got_entropy = 1;
|
|
|
|
break;
|
2009-01-16 17:46:19 +00:00
|
|
|
case WP_ID_HYBRID:
|
2012-01-02 05:14:16 +00:00
|
|
|
if (s->hybrid_bitrate) {
|
|
|
|
for (i = 0; i <= s->stereo_in; i++) {
|
2013-05-22 10:27:04 +00:00
|
|
|
s->ch[i].slow_level = wp_exp2(bytestream2_get_le16(&gb));
|
2013-05-18 14:02:47 +00:00
|
|
|
size -= 2;
|
2009-01-16 17:46:19 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-02 05:14:16 +00:00
|
|
|
for (i = 0; i < (s->stereo_in + 1); i++) {
|
2013-05-22 10:27:04 +00:00
|
|
|
s->ch[i].bitrate_acc = bytestream2_get_le16(&gb) << 16;
|
2013-05-18 14:02:47 +00:00
|
|
|
size -= 2;
|
2009-01-16 17:46:19 +00:00
|
|
|
}
|
2012-01-02 05:14:16 +00:00
|
|
|
if (size > 0) {
|
|
|
|
for (i = 0; i < (s->stereo_in + 1); i++) {
|
2013-05-22 10:27:04 +00:00
|
|
|
s->ch[i].bitrate_delta =
|
|
|
|
wp_exp2((int16_t)bytestream2_get_le16(&gb));
|
2009-01-16 17:46:19 +00:00
|
|
|
}
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < (s->stereo_in + 1); i++)
|
2009-01-16 17:46:19 +00:00
|
|
|
s->ch[i].bitrate_delta = 0;
|
|
|
|
}
|
|
|
|
got_hybrid = 1;
|
|
|
|
break;
|
2013-05-22 10:27:04 +00:00
|
|
|
case WP_ID_INT32INFO: {
|
|
|
|
uint8_t val[4];
|
2012-01-02 05:14:16 +00:00
|
|
|
if (size != 4) {
|
2013-05-18 14:02:47 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
2013-05-22 10:27:04 +00:00
|
|
|
"Invalid INT32INFO, size = %i\n",
|
|
|
|
size);
|
|
|
|
bytestream2_skip(&gb, ssize - 4);
|
2007-08-05 05:56:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-05-22 10:27:04 +00:00
|
|
|
bytestream2_get_buffer(&gb, val, 4);
|
2017-06-27 11:47:32 +00:00
|
|
|
if (val[0] > 30) {
|
2015-07-02 21:05:05 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
2017-06-27 11:47:32 +00:00
|
|
|
"Invalid INT32INFO, extra_bits = %d (> 30)\n", val[0]);
|
2015-07-02 21:05:05 +00:00
|
|
|
continue;
|
|
|
|
} else if (val[0]) {
|
2013-05-22 10:27:04 +00:00
|
|
|
s->extra_bits = val[0];
|
|
|
|
} else if (val[1]) {
|
|
|
|
s->shift = val[1];
|
|
|
|
} else if (val[2]) {
|
2013-05-18 14:02:47 +00:00
|
|
|
s->and = s->or = 1;
|
2013-05-22 10:27:04 +00:00
|
|
|
s->shift = val[2];
|
|
|
|
} else if (val[3]) {
|
2012-01-02 05:14:16 +00:00
|
|
|
s->and = 1;
|
2013-05-22 10:27:04 +00:00
|
|
|
s->shift = val[3];
|
2007-08-05 05:56:34 +00:00
|
|
|
}
|
2017-03-20 01:05:23 +00:00
|
|
|
if (s->shift > 31) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
|
|
|
"Invalid INT32INFO, shift = %d (> 31)\n", s->shift);
|
|
|
|
s->and = s->or = s->shift = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2012-02-24 00:26:38 +00:00
|
|
|
/* original WavPack decoder forces 32-bit lossy sound to be treated
|
2013-05-18 14:02:47 +00:00
|
|
|
* as 24-bit one in order to have proper clipping */
|
2012-02-24 00:26:38 +00:00
|
|
|
if (s->hybrid && bpp == 4 && s->post_shift < 8 && s->shift > 8) {
|
2013-05-18 14:02:47 +00:00
|
|
|
s->post_shift += 8;
|
|
|
|
s->shift -= 8;
|
2012-02-24 00:26:38 +00:00
|
|
|
s->hybrid_maxclip >>= 8;
|
|
|
|
s->hybrid_minclip >>= 8;
|
|
|
|
}
|
2007-08-05 05:56:34 +00:00
|
|
|
break;
|
2013-05-22 10:27:04 +00:00
|
|
|
}
|
2009-05-06 05:40:43 +00:00
|
|
|
case WP_ID_FLOATINFO:
|
2012-01-02 05:14:16 +00:00
|
|
|
if (size != 4) {
|
2013-05-18 14:02:47 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
|
|
|
"Invalid FLOATINFO, size = %i\n", size);
|
2013-05-22 10:27:04 +00:00
|
|
|
bytestream2_skip(&gb, ssize);
|
2009-05-06 05:40:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-05-22 10:27:04 +00:00
|
|
|
s->float_flag = bytestream2_get_byte(&gb);
|
|
|
|
s->float_shift = bytestream2_get_byte(&gb);
|
|
|
|
s->float_max_exp = bytestream2_get_byte(&gb);
|
2017-05-30 01:13:21 +00:00
|
|
|
if (s->float_shift > 31) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
|
|
|
"Invalid FLOATINFO, shift = %d (> 31)\n", s->float_shift);
|
|
|
|
s->float_shift = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-18 14:02:47 +00:00
|
|
|
got_float = 1;
|
2013-05-22 10:27:04 +00:00
|
|
|
bytestream2_skip(&gb, 1);
|
2009-05-06 05:40:43 +00:00
|
|
|
break;
|
2006-09-26 03:41:51 +00:00
|
|
|
case WP_ID_DATA:
|
2013-10-29 09:46:32 +00:00
|
|
|
if ((ret = init_get_bits8(&s->gb, gb.buffer, size)) < 0)
|
|
|
|
return ret;
|
2013-05-22 10:27:04 +00:00
|
|
|
bytestream2_skip(&gb, size);
|
2020-03-09 22:23:53 +00:00
|
|
|
got_pcm = 1;
|
|
|
|
break;
|
|
|
|
case WP_ID_DSD_DATA:
|
|
|
|
if (size < 2) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid DSD_DATA, size = %i\n",
|
|
|
|
size);
|
|
|
|
bytestream2_skip(&gb, ssize);
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-02 19:20:45 +00:00
|
|
|
rate_x = bytestream2_get_byte(&gb);
|
|
|
|
if (rate_x > 30)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
rate_x = 1 << rate_x;
|
2020-03-09 22:23:53 +00:00
|
|
|
dsd_mode = bytestream2_get_byte(&gb);
|
|
|
|
if (dsd_mode && dsd_mode != 1 && dsd_mode != 3) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid DSD encoding mode: %d\n",
|
|
|
|
dsd_mode);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
bytestream2_init(&s->gbyte, gb.buffer, size-2);
|
|
|
|
bytestream2_skip(&gb, size-2);
|
|
|
|
got_dsd = 1;
|
2006-09-26 03:41:51 +00:00
|
|
|
break;
|
2009-05-02 05:17:20 +00:00
|
|
|
case WP_ID_EXTRABITS:
|
2012-01-02 05:14:16 +00:00
|
|
|
if (size <= 4) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid EXTRABITS, size = %i\n",
|
|
|
|
size);
|
2013-05-22 10:27:04 +00:00
|
|
|
bytestream2_skip(&gb, size);
|
2009-05-02 05:17:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-10-29 09:46:32 +00:00
|
|
|
if ((ret = init_get_bits8(&s->gb_extra_bits, gb.buffer, size)) < 0)
|
|
|
|
return ret;
|
2013-05-18 14:02:47 +00:00
|
|
|
s->crc_extra_bits = get_bits_long(&s->gb_extra_bits, 32);
|
2013-05-22 10:27:04 +00:00
|
|
|
bytestream2_skip(&gb, size);
|
2013-05-18 14:02:47 +00:00
|
|
|
s->got_extra_bits = 1;
|
2009-05-02 05:17:20 +00:00
|
|
|
break;
|
2011-01-22 13:43:15 +00:00
|
|
|
case WP_ID_CHANINFO:
|
2012-01-02 05:14:16 +00:00
|
|
|
if (size <= 1) {
|
2013-05-18 14:02:47 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
|
|
|
"Insufficient channel information\n");
|
2013-05-17 16:28:33 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2011-01-22 13:43:15 +00:00
|
|
|
}
|
2013-05-22 10:27:04 +00:00
|
|
|
chan = bytestream2_get_byte(&gb);
|
2012-01-02 05:14:16 +00:00
|
|
|
switch (size - 2) {
|
2013-05-18 14:02:47 +00:00
|
|
|
case 0:
|
2013-05-22 10:27:04 +00:00
|
|
|
chmask = bytestream2_get_byte(&gb);
|
2013-05-18 14:02:47 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2013-05-22 10:27:04 +00:00
|
|
|
chmask = bytestream2_get_le16(&gb);
|
2013-05-18 14:02:47 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2013-05-22 10:27:04 +00:00
|
|
|
chmask = bytestream2_get_le24(&gb);
|
2013-05-18 14:02:47 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2013-05-23 09:05:37 +00:00
|
|
|
chmask = bytestream2_get_le32(&gb);
|
2013-05-18 14:02:47 +00:00
|
|
|
break;
|
2018-12-28 11:16:39 +00:00
|
|
|
case 4:
|
2014-08-22 09:31:44 +00:00
|
|
|
size = bytestream2_get_byte(&gb);
|
2018-12-28 11:16:39 +00:00
|
|
|
chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
|
|
|
|
chan += 1;
|
|
|
|
if (avctx->channels != chan)
|
2014-08-22 09:31:44 +00:00
|
|
|
av_log(avctx, AV_LOG_WARNING, "%i channels signalled"
|
2018-12-28 11:16:39 +00:00
|
|
|
" instead of %i.\n", chan, avctx->channels);
|
|
|
|
chmask = bytestream2_get_le24(&gb);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
size = bytestream2_get_byte(&gb);
|
2013-05-22 10:27:04 +00:00
|
|
|
chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
|
2018-12-28 11:16:39 +00:00
|
|
|
chan += 1;
|
|
|
|
if (avctx->channels != chan)
|
|
|
|
av_log(avctx, AV_LOG_WARNING, "%i channels signalled"
|
|
|
|
" instead of %i.\n", chan, avctx->channels);
|
|
|
|
chmask = bytestream2_get_le32(&gb);
|
2011-01-22 13:43:15 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-01-02 05:14:16 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid channel info size %d\n",
|
|
|
|
size);
|
|
|
|
chan = avctx->channels;
|
2011-01-22 13:43:15 +00:00
|
|
|
chmask = avctx->channel_layout;
|
|
|
|
}
|
|
|
|
break;
|
2013-05-27 15:23:15 +00:00
|
|
|
case WP_ID_SAMPLE_RATE:
|
|
|
|
if (size != 3) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid custom sample rate.\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
sample_rate = bytestream2_get_le24(&gb);
|
|
|
|
break;
|
2006-09-26 03:41:51 +00:00
|
|
|
default:
|
2013-05-22 10:27:04 +00:00
|
|
|
bytestream2_skip(&gb, size);
|
2006-09-26 03:41:51 +00:00
|
|
|
}
|
2012-01-02 05:14:16 +00:00
|
|
|
if (id & WP_IDF_ODD)
|
2013-05-22 10:27:04 +00:00
|
|
|
bytestream2_skip(&gb, 1);
|
2006-09-26 03:41:51 +00:00
|
|
|
}
|
2011-09-06 16:17:45 +00:00
|
|
|
|
2020-03-09 22:23:53 +00:00
|
|
|
if (got_pcm) {
|
|
|
|
if (!got_terms) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "No block with decorrelation terms\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
if (!got_weights) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "No block with decorrelation weights\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
if (!got_samples) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "No block with decorrelation samples\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
if (!got_entropy) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
if (s->hybrid && !got_hybrid) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2020-04-05 20:01:40 +00:00
|
|
|
if (!got_float && sample_fmt == AV_SAMPLE_FMT_FLTP) {
|
2020-03-09 22:23:53 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Float information not found\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2020-04-05 20:01:40 +00:00
|
|
|
if (s->got_extra_bits && sample_fmt != AV_SAMPLE_FMT_FLTP) {
|
2020-03-09 22:23:53 +00:00
|
|
|
const int size = get_bits_left(&s->gb_extra_bits);
|
|
|
|
const int wanted = s->samples * s->extra_bits << s->stereo_in;
|
|
|
|
if (size < wanted) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n");
|
|
|
|
s->got_extra_bits = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-01-02 05:14:16 +00:00
|
|
|
}
|
2020-03-09 22:23:53 +00:00
|
|
|
|
|
|
|
if (!got_pcm && !got_dsd) {
|
2012-01-02 05:14:16 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n");
|
2013-05-17 16:28:33 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2012-01-02 05:14:16 +00:00
|
|
|
}
|
2020-03-09 22:23:53 +00:00
|
|
|
|
|
|
|
if ((got_pcm && wc->modulation != MODULATION_PCM) ||
|
|
|
|
(got_dsd && wc->modulation != MODULATION_DSD)) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid PCM/DSD mix encountered\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
2012-01-02 05:14:16 +00:00
|
|
|
}
|
2006-09-26 03:41:51 +00:00
|
|
|
|
2013-05-27 15:23:15 +00:00
|
|
|
if (!wc->ch_offset) {
|
2020-04-05 20:01:40 +00:00
|
|
|
int new_channels = avctx->channels;
|
|
|
|
uint64_t new_chmask = avctx->channel_layout;
|
|
|
|
int new_samplerate;
|
2013-05-27 15:23:15 +00:00
|
|
|
int sr = (s->frame_flags >> 23) & 0xf;
|
|
|
|
if (sr == 0xf) {
|
|
|
|
if (!sample_rate) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Custom sample rate missing.\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2020-05-02 19:20:45 +00:00
|
|
|
new_samplerate = sample_rate;
|
2013-05-27 15:23:15 +00:00
|
|
|
} else
|
2020-05-02 19:20:45 +00:00
|
|
|
new_samplerate = wv_rates[sr];
|
|
|
|
|
|
|
|
if (new_samplerate * (uint64_t)rate_x > INT_MAX)
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
new_samplerate *= rate_x;
|
2013-05-27 15:23:15 +00:00
|
|
|
|
2013-05-27 15:23:15 +00:00
|
|
|
if (multiblock) {
|
|
|
|
if (chan)
|
2020-04-05 20:01:40 +00:00
|
|
|
new_channels = chan;
|
2013-05-27 15:23:15 +00:00
|
|
|
if (chmask)
|
2020-04-05 20:01:40 +00:00
|
|
|
new_chmask = chmask;
|
2013-05-27 15:23:15 +00:00
|
|
|
} else {
|
2020-04-05 20:01:40 +00:00
|
|
|
new_channels = s->stereo ? 2 : 1;
|
|
|
|
new_chmask = s->stereo ? AV_CH_LAYOUT_STEREO :
|
|
|
|
AV_CH_LAYOUT_MONO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_chmask &&
|
|
|
|
av_get_channel_layout_nb_channels(new_chmask) != new_channels) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Channel mask does not match the channel count\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
2013-05-27 15:23:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 20:01:40 +00:00
|
|
|
/* clear DSD state if stream properties change */
|
|
|
|
if (new_channels != wc->dsd_channels ||
|
|
|
|
new_chmask != avctx->channel_layout ||
|
|
|
|
new_samplerate != avctx->sample_rate ||
|
|
|
|
!!got_dsd != !!wc->dsdctx) {
|
|
|
|
ret = wv_dsd_reset(wc, got_dsd ? new_channels : 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Error reinitializing the DSD context\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ff_thread_release_buffer(avctx, &wc->curr_frame);
|
|
|
|
}
|
|
|
|
avctx->channels = new_channels;
|
|
|
|
avctx->channel_layout = new_chmask;
|
|
|
|
avctx->sample_rate = new_samplerate;
|
|
|
|
avctx->sample_fmt = sample_fmt;
|
|
|
|
avctx->bits_per_raw_sample = orig_bpp;
|
|
|
|
|
2020-03-09 22:23:53 +00:00
|
|
|
ff_thread_release_buffer(avctx, &wc->prev_frame);
|
|
|
|
FFSWAP(ThreadFrame, wc->curr_frame, wc->prev_frame);
|
|
|
|
|
2013-05-27 15:23:15 +00:00
|
|
|
/* get output buffer */
|
2020-03-09 22:23:53 +00:00
|
|
|
wc->curr_frame.f->nb_samples = s->samples;
|
|
|
|
if ((ret = ff_thread_get_buffer(avctx, &wc->curr_frame, AV_GET_BUFFER_FLAG_REF)) < 0)
|
2013-05-27 15:23:15 +00:00
|
|
|
return ret;
|
2020-03-09 22:23:53 +00:00
|
|
|
|
|
|
|
wc->frame = wc->curr_frame.f;
|
|
|
|
ff_thread_finish_setup(avctx);
|
2013-05-27 15:23:15 +00:00
|
|
|
}
|
|
|
|
|
2013-05-27 17:11:09 +00:00
|
|
|
if (wc->ch_offset + s->stereo >= avctx->channels) {
|
|
|
|
av_log(avctx, AV_LOG_WARNING, "Too many channels coded in a packet.\n");
|
2016-12-07 11:06:16 +00:00
|
|
|
return ((avctx->err_recognition & AV_EF_EXPLODE) || !wc->ch_offset) ? AVERROR_INVALIDDATA : 0;
|
2013-05-27 17:11:09 +00:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:23:53 +00:00
|
|
|
samples_l = wc->frame->extended_data[wc->ch_offset];
|
2013-05-27 15:23:15 +00:00
|
|
|
if (s->stereo)
|
2020-03-09 22:23:53 +00:00
|
|
|
samples_r = wc->frame->extended_data[wc->ch_offset + 1];
|
2013-05-27 15:23:15 +00:00
|
|
|
|
|
|
|
wc->ch_offset += 1 + s->stereo;
|
|
|
|
|
2012-01-02 05:14:16 +00:00
|
|
|
if (s->stereo_in) {
|
2020-03-09 22:23:53 +00:00
|
|
|
if (got_dsd) {
|
2020-03-11 20:50:02 +00:00
|
|
|
if (dsd_mode == 3) {
|
2020-03-09 22:23:53 +00:00
|
|
|
ret = wv_unpack_dsd_high(s, samples_l, samples_r);
|
2020-03-11 20:50:02 +00:00
|
|
|
} else if (dsd_mode == 1) {
|
2020-03-09 22:23:53 +00:00
|
|
|
ret = wv_unpack_dsd_fast(s, samples_l, samples_r);
|
2020-03-11 20:50:02 +00:00
|
|
|
} else {
|
2020-03-09 22:23:53 +00:00
|
|
|
ret = wv_unpack_dsd_copy(s, samples_l, samples_r);
|
2020-03-11 20:50:02 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-09 22:23:53 +00:00
|
|
|
ret = wv_unpack_stereo(s, &s->gb, samples_l, samples_r, avctx->sample_fmt);
|
2020-03-11 20:50:02 +00:00
|
|
|
}
|
2013-05-26 08:32:56 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2012-01-02 05:14:16 +00:00
|
|
|
} else {
|
2020-03-09 22:23:53 +00:00
|
|
|
if (got_dsd) {
|
2020-03-11 20:50:02 +00:00
|
|
|
if (dsd_mode == 3) {
|
2020-03-09 22:23:53 +00:00
|
|
|
ret = wv_unpack_dsd_high(s, samples_l, NULL);
|
2020-03-11 20:50:02 +00:00
|
|
|
} else if (dsd_mode == 1) {
|
2020-03-09 22:23:53 +00:00
|
|
|
ret = wv_unpack_dsd_fast(s, samples_l, NULL);
|
2020-03-11 20:50:02 +00:00
|
|
|
} else {
|
2020-03-09 22:23:53 +00:00
|
|
|
ret = wv_unpack_dsd_copy(s, samples_l, NULL);
|
2020-03-11 20:50:02 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-09 22:23:53 +00:00
|
|
|
ret = wv_unpack_mono(s, &s->gb, samples_l, avctx->sample_fmt);
|
2020-03-11 20:50:02 +00:00
|
|
|
}
|
2013-05-26 08:32:56 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2011-09-08 18:02:43 +00:00
|
|
|
|
2013-05-25 13:31:18 +00:00
|
|
|
if (s->stereo)
|
|
|
|
memcpy(samples_r, samples_l, bpp * s->samples);
|
2011-01-22 13:43:15 +00:00
|
|
|
}
|
|
|
|
|
2013-05-26 08:32:56 +00:00
|
|
|
return 0;
|
2011-01-22 13:43:15 +00:00
|
|
|
}
|
|
|
|
|
2011-09-26 21:37:30 +00:00
|
|
|
static void wavpack_decode_flush(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
WavpackContext *s = avctx->priv_data;
|
|
|
|
|
2020-04-05 20:01:40 +00:00
|
|
|
wv_dsd_reset(s, 0);
|
2020-03-09 22:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dsd_channel(AVCodecContext *avctx, void *frmptr, int jobnr, int threadnr)
|
|
|
|
{
|
|
|
|
WavpackContext *s = avctx->priv_data;
|
|
|
|
AVFrame *frame = frmptr;
|
|
|
|
|
|
|
|
ff_dsd2pcm_translate (&s->dsdctx [jobnr], s->samples, 0,
|
2020-03-11 20:50:02 +00:00
|
|
|
(uint8_t *)frame->extended_data[jobnr], 4,
|
|
|
|
(float *)frame->extended_data[jobnr], 1);
|
2020-03-09 22:23:53 +00:00
|
|
|
|
|
|
|
return 0;
|
2011-09-26 21:37:30 +00:00
|
|
|
}
|
|
|
|
|
2011-09-06 16:17:45 +00:00
|
|
|
static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
|
|
|
|
int *got_frame_ptr, AVPacket *avpkt)
|
2011-01-22 13:43:15 +00:00
|
|
|
{
|
2012-01-02 05:14:16 +00:00
|
|
|
WavpackContext *s = avctx->priv_data;
|
2011-01-22 13:43:15 +00:00
|
|
|
const uint8_t *buf = avpkt->data;
|
2012-01-02 05:14:16 +00:00
|
|
|
int buf_size = avpkt->size;
|
2011-12-16 21:41:29 +00:00
|
|
|
int frame_size, ret, frame_flags;
|
2011-01-22 13:43:15 +00:00
|
|
|
|
2013-05-26 19:09:22 +00:00
|
|
|
if (avpkt->size <= WV_HEADER_SIZE)
|
2013-05-22 10:51:42 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
2020-03-09 22:23:53 +00:00
|
|
|
s->frame = NULL;
|
2012-01-02 05:14:16 +00:00
|
|
|
s->block = 0;
|
2011-01-22 13:43:15 +00:00
|
|
|
s->ch_offset = 0;
|
|
|
|
|
2011-09-06 16:17:45 +00:00
|
|
|
/* determine number of samples */
|
2013-05-27 07:44:27 +00:00
|
|
|
s->samples = AV_RL32(buf + 20);
|
|
|
|
frame_flags = AV_RL32(buf + 24);
|
2012-11-06 13:03:48 +00:00
|
|
|
if (s->samples <= 0 || s->samples > WV_MAX_SAMPLES) {
|
2011-09-06 16:17:45 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Invalid number of samples: %d\n",
|
|
|
|
s->samples);
|
2013-05-17 16:28:33 +00:00
|
|
|
return AVERROR_INVALIDDATA;
|
2011-09-06 16:17:45 +00:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:23:53 +00:00
|
|
|
s->modulation = (frame_flags & WV_DSD_DATA) ? MODULATION_DSD : MODULATION_PCM;
|
|
|
|
|
2020-01-11 05:31:06 +00:00
|
|
|
while (buf_size > WV_HEADER_SIZE) {
|
2013-05-27 07:44:27 +00:00
|
|
|
frame_size = AV_RL32(buf + 4) - 12;
|
|
|
|
buf += 20;
|
|
|
|
buf_size -= 20;
|
2013-05-26 08:44:11 +00:00
|
|
|
if (frame_size <= 0 || frame_size > buf_size) {
|
2013-05-18 14:02:47 +00:00
|
|
|
av_log(avctx, AV_LOG_ERROR,
|
|
|
|
"Block %d has invalid size (size %d vs. %d bytes left)\n",
|
|
|
|
s->block, frame_size, buf_size);
|
2020-03-09 22:23:53 +00:00
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
goto error;
|
2011-09-26 21:37:30 +00:00
|
|
|
}
|
2020-03-09 22:23:53 +00:00
|
|
|
if ((ret = wavpack_decode_block(avctx, s->block, buf, frame_size)) < 0)
|
|
|
|
goto error;
|
2011-01-22 13:43:15 +00:00
|
|
|
s->block++;
|
2013-05-18 14:02:47 +00:00
|
|
|
buf += frame_size;
|
|
|
|
buf_size -= frame_size;
|
2007-08-13 05:36:50 +00:00
|
|
|
}
|
2006-09-26 03:41:51 +00:00
|
|
|
|
2013-05-27 17:13:14 +00:00
|
|
|
if (s->ch_offset != avctx->channels) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Not enough channels coded in a packet.\n");
|
2020-03-09 22:23:53 +00:00
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
goto error;
|
2013-05-27 17:13:14 +00:00
|
|
|
}
|
|
|
|
|
2020-03-09 22:23:53 +00:00
|
|
|
ff_thread_await_progress(&s->prev_frame, INT_MAX, 0);
|
|
|
|
ff_thread_release_buffer(avctx, &s->prev_frame);
|
|
|
|
|
|
|
|
if (s->modulation == MODULATION_DSD)
|
|
|
|
avctx->execute2(avctx, dsd_channel, s->frame, NULL, avctx->channels);
|
|
|
|
|
|
|
|
ff_thread_report_progress(&s->curr_frame, INT_MAX, 0);
|
|
|
|
|
|
|
|
if ((ret = av_frame_ref(data, s->frame)) < 0)
|
|
|
|
return ret;
|
|
|
|
|
2013-05-26 08:47:22 +00:00
|
|
|
*got_frame_ptr = 1;
|
|
|
|
|
2011-09-06 16:17:45 +00:00
|
|
|
return avpkt->size;
|
2020-03-09 22:23:53 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (s->frame) {
|
|
|
|
ff_thread_await_progress(&s->prev_frame, INT_MAX, 0);
|
|
|
|
ff_thread_release_buffer(avctx, &s->prev_frame);
|
|
|
|
ff_thread_report_progress(&s->curr_frame, INT_MAX, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2006-09-26 03:41:51 +00:00
|
|
|
}
|
|
|
|
|
2024-02-05 11:18:57 +00:00
|
|
|
AVCodec ff_wavpack_decoder = {
|
2011-07-17 10:54:31 +00:00
|
|
|
.name = "wavpack",
|
2013-10-03 20:57:53 +00:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("WavPack"),
|
2011-07-17 10:54:31 +00:00
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
2012-08-05 09:11:04 +00:00
|
|
|
.id = AV_CODEC_ID_WAVPACK,
|
2011-07-17 10:54:31 +00:00
|
|
|
.priv_data_size = sizeof(WavpackContext),
|
|
|
|
.init = wavpack_decode_init,
|
|
|
|
.close = wavpack_decode_end,
|
|
|
|
.decode = wavpack_decode_frame,
|
2011-08-20 16:14:44 +00:00
|
|
|
.flush = wavpack_decode_flush,
|
2020-03-09 22:23:53 +00:00
|
|
|
.update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
|
|
|
|
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
|
2022-05-23 03:23:35 +00:00
|
|
|
AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_CHANNEL_CONF,
|
|
|
|
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP |
|
|
|
|
FF_CODEC_CAP_ALLOCATE_PROGRESS,
|
2006-09-26 03:41:51 +00:00
|
|
|
};
|