22 #define BITSTREAM_READER_LE
24 #include "libavutil/channel_layout.h"
73 #define WV_MAX_FRAME_DECODERS 14
86 #define LEVEL_DECAY(a) ((a + 0x80) >> 8)
95 e = (1 << (p + 1)) - k - 1;
112 int balance = (sl[1] - sl[0] + br[1] + 1) >> 1;
113 if (balance > br[0]) {
116 }
else if (-balance > br[0]) {
120 br[1] = br[0] + balance;
121 br[0] = br[0] - balance;
126 if (sl[i] - br[i] > -0x100)
137 int channel,
int *last)
140 int sign, base, add,
ret;
158 t =
get_bits(gb, t - 1) | (1 << (t - 1));
189 t +=
get_bits(gb, t2 - 1) | (1 << (t2 - 1));
203 if (ctx->
hybrid && !channel)
229 if (add >= 0x2000000U) {
237 int mid = (base * 2 + add + 1) >> 1;
245 add = mid - base - 1;
246 mid = (base * 2 + add + 1) >> 1;
253 return sign ? ~ret :
ret;
271 *crc = *crc * 9 + (S & 0xffff) * 3 + ((
unsigned)S >> 16);
275 bit = (S & s->
and) | s->
or;
276 bit = ((S + bit) << s->
shift) - bit;
295 const int max_bits = 1 + 23 + 8 + 1;
307 if (S >= 0x1000000) {
326 S |= (1 <<
shift) - 1;
352 *crc = *crc * 27 + S * 9 + exp * 3 + sign;
354 value.u = (sign << 31) | (exp << 23) |
S;
365 uint32_t crc_extra_bits)
380 void *dst_l,
void *dst_r,
const int type)
386 uint32_t crc = s->
sc.
crc;
388 int16_t *dst16_l = dst_l;
389 int16_t *dst16_r = dst_r;
392 float *dstfl_l = dst_l;
393 float *dstfl_r = dst_r;
403 for (i = 0; i < s->
terms; i++) {
435 }
else if (t == -1) {
473 L += (R -= (L >> 1));
474 crc = (crc * 3 +
L) * 3 + R;
487 }
while (!last && count < s->samples);
498 void *dst,
const int type)
504 uint32_t crc = s->
sc.
crc;
506 int16_t *dst16 = dst;
516 for (i = 0; i < s->
terms; i++) {
548 }
while (!last && count < s->samples);
610 void *samples_l, *samples_r;
612 int got_terms = 0, got_weights = 0, got_samples = 0,
613 got_entropy = 0, got_bs = 0, got_float = 0, got_hybrid = 0;
614 int i, j,
id,
size, ssize, weights,
t;
615 int bpp, chan = 0, chmask = 0, orig_bpp,
sample_rate = 0;
623 s = wc->
fdec[block_no];
631 memset(s->
ch, 0,
sizeof(s->
ch));
638 s->
samples = bytestream2_get_le32(&gb);
657 s->
CRC = bytestream2_get_le32(&gb);
661 id = bytestream2_get_byte(&gb);
662 size = bytestream2_get_byte(&gb);
664 size |= (bytestream2_get_byte(&gb)) << 8;
665 size |= (bytestream2_get_byte(&gb)) << 16;
673 "Got incorrect block %02X with size %i\n",
id, size);
678 "Block size %i is out of bounds\n", size);
690 for (i = 0; i < s->
terms; i++) {
708 for (i = 0; i < weights; i++) {
709 t = (int8_t)bytestream2_get_byte(&gb);
715 t = (int8_t)bytestream2_get_byte(&gb);
730 for (i = s->
terms - 1; (i >= 0) && (t < size); i--) {
733 wp_exp2(bytestream2_get_le16(&gb));
735 wp_exp2(bytestream2_get_le16(&gb));
739 wp_exp2(bytestream2_get_le16(&gb));
741 wp_exp2(bytestream2_get_le16(&gb));
747 wp_exp2(bytestream2_get_le16(&gb));
749 wp_exp2(bytestream2_get_le16(&gb));
754 wp_exp2(bytestream2_get_le16(&gb));
757 wp_exp2(bytestream2_get_le16(&gb));
768 "Entropy vars size should be %i, got %i.\n",
774 for (i = 0; i < 3; i++) {
786 for (i = 0; i < (s->
stereo_in + 1); i++) {
791 for (i = 0; i < (s->
stereo_in + 1); i++) {
793 wp_exp2((int16_t)bytestream2_get_le16(&gb));
805 "Invalid INT32INFO, size = %i\n",
835 "Invalid FLOATINFO, size = %i\n", size);
870 "Insufficient channel information\n");
873 chan = bytestream2_get_byte(&gb);
876 chmask = bytestream2_get_byte(&gb);
879 chmask = bytestream2_get_le16(&gb);
882 chmask = bytestream2_get_le24(&gb);
885 chmask = bytestream2_get_le32(&gb);
889 chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
890 chmask = bytestream2_get_le16(&gb);
904 sample_rate = bytestream2_get_le24(&gb);
929 if (s->
hybrid && !got_hybrid) {
1000 memcpy(samples_r, samples_l, bpp * s->
samples);
1016 int *got_frame_ptr,
AVPacket *avpkt)
1020 int buf_size = avpkt->
size;
1032 frame_flags =
AV_RL32(buf + 24);
1039 if (frame_flags & 0x80) {
1041 }
else if ((frame_flags & 0x03) <= 1) {
1048 while (buf_size > 0) {
1051 frame_size =
AV_RL32(buf + 4) - 12;
1054 if (frame_size <= 0 || frame_size > buf_size) {
1056 "Block %d has invalid size (size %d vs. %d bytes left)\n",
1057 s->
block, frame_size, buf_size);
1062 frame, buf, frame_size)) < 0) {
const char const char void * val
static int shift(int a, int b)
This structure describes decoded (raw) audio or video data.
static void wavpack_decode_flush(AVCodecContext *avctx)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_cold int init(AVCodecContext *avctx)
uint8_t ** extended_data
pointers to the data planes/channels.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define WV_FLT_SHIFT_ONES
#define WV_HYBRID_BITRATE
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
#define AV_CH_LAYOUT_STEREO
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc, int S)
static int get_unary_0_33(GetBitContext *gb)
Get unary code terminated by a 0 with a maximum length of 33.
enum AVSampleFormat sample_fmt
audio sample format
AVCodec ff_wavpack_decoder
static int wavpack_decode_block(AVCodecContext *avctx, int block_no, AVFrame *frame, const uint8_t *buf, int buf_size)
Multithreading support functions.
const char * name
Name of the codec implementation.
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
bitstream reader API header.
WavpackFrameContext * fdec[WV_MAX_FRAME_DECODERS]
static const uint8_t frame_size[4]
static int get_bits_left(GetBitContext *gb)
static int init_thread_copy(AVCodecContext *avctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_always_inline int wp_exp2(int16_t val)
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Libavcodec external API header.
uint64_t channel_layout
Audio channel layout.
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
static int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, void *dst_l, void *dst_r, const int type)
static const int wv_rates[16]
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
static void wv_reset_saved_context(WavpackFrameContext *s)
static int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void *dst, const int type)
#define WV_FLT_SHIFT_SAME
#define WV_FLT_SHIFT_SENT
static void flush(AVCodecContext *avctx)
static av_always_inline int bytestream2_tell(GetByteContext *g)
static av_cold int wavpack_decode_end(AVCodecContext *avctx)
int sample_rate
samples per second
main external API structure.
static void close(AVCodecParserContext *s)
#define AV_EF_EXPLODE
abort decoding on minor error detection
static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S)
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static int wavpack_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static int wv_check_crc(WavpackFrameContext *s, uint32_t crc, uint32_t crc_extra_bits)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, int channel, int *last)
#define UPDATE_WEIGHT_CLIP(weight, delta, samples, in)
static av_always_inline int get_tail(GetBitContext *gb, int k)
common internal api header.
#define CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
static av_always_inline int wp_log2(int32_t val)
GetBitContext gb_extra_bits
#define AVERROR_INVALIDDATA
int channels
number of audio channels
#define AV_EF_CRCCHECK
verify embedded CRCs
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static av_cold int wv_alloc_frame_context(WavpackContext *c)
static av_cold int wavpack_decode_init(AVCodecContext *avctx)
#define WV_MAX_FRAME_DECODERS
#define AV_CH_LAYOUT_MONO
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
static void update_error_limit(WavpackFrameContext *ctx)
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...