24 #define BITSTREAM_READER_LE    73 #define WV_MAX_FRAME_DECODERS 14    86 #define LEVEL_DECAY(a)  (((a) + 0x80) >> 8)    95     e   = (1 << (p + 1)) - k - 1;
   114         int balance = (sl[1] - sl[0] + br[1] + 1) >> 1;
   115         if (balance > br[0]) {
   118         } 
else if (-balance > br[0]) {
   122             br[1] = br[0] + balance;
   123             br[0] = br[0] - balance;
   128             if (sl[i] - br[i] > -0x100)
   144     int sign, base, add, ret;
   207     if (ctx->
hybrid && !channel) {
   235         if (add >= 0x2000000U) {
   243         int mid = (base * 2
U + add + 1) >> 1;
   248                 add -= (mid - (unsigned)base);
   251                 add = mid - (unsigned)base - 1;
   252             mid = (base * 2
U + add + 1) >> 1;
   259     return sign ? ~ret : ret;
   281             *crc = *crc * 9 + (S & 0xffff) * 3 + ((
unsigned)S >> 16);
   285     bit = (S & s->
and) | s->
or;
   286     bit = ((S + bit) << s->
shift) - bit;
   305         const int max_bits  = 1 + 23 + 8 + 1;
   317         if (S >= 0x1000000U) {
   336                     S |= (1 << 
shift) - 1;
   362     *crc = *crc * 27 + S * 9 + exp * 3 + sign;
   364     value.u = (sign << 31) | (exp << 23) | 
S;
   375                                uint32_t crc_extra_bits)
   390                                    void *dst_l, 
void *dst_r, 
const int type)
   398     int16_t *dst16_l        = dst_l;
   399     int16_t *dst16_r        = dst_r;
   402     float *dstfl_l          = dst_l;
   403     float *dstfl_r          = dst_r;
   413         for (i = 0; i < s->
terms; i++) {
   436                     L2 = L + (unsigned)((
int)(s->
decorr[i].
weightA * (unsigned)A + 512) >> 10);
   437                     R2 = R + (unsigned)((
int)(s->
decorr[i].
weightB * (unsigned)B + 512) >> 10);
   445             } 
else if (t == -1) {
   475                     L2 = L + (unsigned)((
int)(s->
decorr[i].
weightA * (unsigned)R2 + 512) >> 10);
   483             if (
FFABS((int64_t)L) + 
FFABS((int64_t)R) > (1<<19)) {
   491             L += (unsigned)(R -= (
unsigned)(L >> 1));
   492         crc = (crc * 3 + 
L) * 3 + R;
   505     } 
while (!last && count < s->samples);
   509     if (last && count < s->samples) {
   523                                  void *dst, 
const int type)
   531     int16_t *dst16           = dst;
   541         for (i = 0; i < s->
terms; i++) {
   557                 S = T + (unsigned)((
int)(s->
decorr[i].
weightA * (unsigned)A + 512) >> 10);
   573     } 
while (!last && count < s->samples);
   577     if (last && count < s->samples) {
   645     void *samples_l = 
NULL, *samples_r = 
NULL;
   647     int got_terms   = 0, got_weights = 0, got_samples = 0,
   648         got_entropy = 0, got_bs      = 0, got_float   = 0, got_hybrid = 0;
   649     int i, j, 
id, 
size, ssize, weights, t;
   650     int bpp, chan = 0, chmask = 0, orig_bpp, 
sample_rate = 0;
   658     s = wc->
fdec[block_no];
   666     memset(s->
ch, 0, 
sizeof(s->
ch));
   673     s->
samples = bytestream2_get_le32(&gb);
   695     s->
CRC            = bytestream2_get_le32(&gb);
   699         id   = bytestream2_get_byte(&gb);
   700         size = bytestream2_get_byte(&gb);
   702             size |= (bytestream2_get_byte(&gb)) << 8;
   703             size |= (bytestream2_get_byte(&gb)) << 16;
   711                    "Got incorrect block %02X with size %i\n", 
id, size);
   716                    "Block size %i is out of bounds\n", size);
   728             for (i = 0; i < s->
terms; i++) {
   746             for (i = 0; i < weights; i++) {
   747                 t = (int8_t)bytestream2_get_byte(&gb);
   753                     t = (int8_t)bytestream2_get_byte(&gb);
   768             for (i = s->
terms - 1; (i >= 0) && (t < size); i--) {
   771                         wp_exp2(bytestream2_get_le16(&gb));
   773                         wp_exp2(bytestream2_get_le16(&gb));
   777                             wp_exp2(bytestream2_get_le16(&gb));
   779                             wp_exp2(bytestream2_get_le16(&gb));
   785                         wp_exp2(bytestream2_get_le16(&gb));
   787                         wp_exp2(bytestream2_get_le16(&gb));
   792                             wp_exp2(bytestream2_get_le16(&gb));
   795                                 wp_exp2(bytestream2_get_le16(&gb));
   806                        "Entropy vars size should be %i, got %i.\n",
   812                 for (i = 0; i < 3; i++) {
   824             for (i = 0; i < (s->
stereo_in + 1); i++) {
   829                 for (i = 0; i < (s->
stereo_in + 1); i++) {
   831                         wp_exp2((int16_t)bytestream2_get_le16(&gb));
   843                        "Invalid INT32INFO, size = %i\n",
   851                        "Invalid INT32INFO, extra_bits = %d (> 30)\n", val[0]);
   866                        "Invalid INT32INFO, shift = %d (> 31)\n", s->
shift);
   883                        "Invalid FLOATINFO, size = %i\n", size);
   892                        "Invalid FLOATINFO, shift = %d (> 31)\n", s->
float_shift);
   926                        "Insufficient channel information\n");
   929             chan = bytestream2_get_byte(&gb);
   932                 chmask = bytestream2_get_byte(&gb);
   935                 chmask = bytestream2_get_le16(&gb);
   938                 chmask = bytestream2_get_le24(&gb);
   941                 chmask = bytestream2_get_le32(&gb);
   944                 size = bytestream2_get_byte(&gb);
   947                            " instead of %i.\n", size, avctx->
channels);
   948                 chan  |= (bytestream2_get_byte(&gb) & 0xF) << 8;
   949                 chmask = bytestream2_get_le16(&gb);
   963             sample_rate = bytestream2_get_le24(&gb);
   988     if (s->
hybrid && !got_hybrid) {
  1003         if (size < wanted) {
  1059             memcpy(samples_r, samples_l, bpp * s->
samples);
  1075                                 int *got_frame_ptr, 
AVPacket *avpkt)
  1079     int buf_size       = avpkt->
size;
  1091     frame_flags = 
AV_RL32(buf + 24);
  1098     if (frame_flags & 0x80) {
  1100     } 
else if ((frame_flags & 0x03) <= 1) {
  1107     while (buf_size > 0) {
  1110         frame_size = 
AV_RL32(buf + 4) - 12;
  1113         if (frame_size <= 0 || frame_size > buf_size) {
  1115                    "Block %d has invalid size (size %d vs. %d bytes left)\n",
  1116                    s->
block, frame_size, buf_size);
  1121                                         frame, buf, frame_size)) < 0) {
 
const char const char void * val
#define AVERROR_INVALIDDATA
Invalid data found when processing input. 
static int shift(int a, int b)
This structure describes decoded (raw) audio or video data. 
static void flush(AVCodecContext *avctx)
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 int init_thread_copy(AVCodecContext *avctx)
static av_cold int init(AVCodecContext *avctx)
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FM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BL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&HAVE_MMX) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
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
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
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. 
#define u(width, name, range_min, range_max)
bitstream reader API header. 
static av_always_inline int wp_log2(uint32_t val)
WavpackFrameContext * fdec[WV_MAX_FRAME_DECODERS]
static int get_bits_left(GetBitContext *gb)
static int update_error_limit(WavpackFrameContext *ctx)
#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)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Name of the codec implementation. 
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading. 
uint64_t channel_layout
Audio channel layout. 
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified. 
audio channel layout utility functions 
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]
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 FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define AV_EF_EXPLODE
abort decoding on minor error detection 
#define WV_FLT_SHIFT_SENT
static void error(const char *err)
static av_always_inline int bytestream2_tell(GetByteContext *g)
static av_cold int wavpack_decode_end(AVCodecContext *avctx)
Libavcodec external API header. 
int sample_rate
samples per second 
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext. 
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs. 
main external API structure. 
static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S)
static int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc, unsigned S)
static unsigned int get_bits1(GetBitContext *s)
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data...
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)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample. 
static av_always_inline int get_tail(GetBitContext *gb, int k)
common internal api header. 
channel
Use these values when setting the channel map with ebur128_set_channel(). 
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
GetBitContext gb_extra_bits
int channels
number of audio channels 
static av_cold int wv_alloc_frame_context(WavpackContext *c)
static av_cold int wavpack_decode_init(AVCodecContext *avctx)
#define WV_MAX_FRAME_DECODERS
uint8_t ** extended_data
pointers to the data planes/channels. 
#define AV_CH_LAYOUT_MONO
This structure stores compressed data. 
int nb_samples
number of audio samples (per channel) described by this frame 
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators. 
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.