}
s->frame_flags = AV_RL32(buf); buf += 4;
if(s->frame_flags&0x80){
- bpp = sizeof(float);
avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
} else if((s->frame_flags&0x03) <= 1){
- bpp = 2;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
} else {
- bpp = 4;
avctx->sample_fmt = AV_SAMPLE_FMT_S32;
}
+ bpp = av_get_bytes_per_sample(avctx->sample_fmt);
samples = (uint8_t*)samples + bpp * wc->ch_offset;
s->stereo = !(s->frame_flags & WV_MONO);
}
switch(id & WP_IDF_MASK){
case WP_ID_DECTERMS:
- s->terms = size;
- if(s->terms > MAX_TERMS){
+ if(size > MAX_TERMS){
av_log(avctx, AV_LOG_ERROR, "Too many decorrelation terms\n");
+ s->terms = 0;
buf += ssize;
continue;
}
+ s->terms = size;
for(i = 0; i < s->terms; i++) {
s->decorr[s->terms - i - 1].value = (*buf & 0x1F) - 5;
s->decorr[s->terms - i - 1].delta = *buf >> 5;
samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_S32);
else
samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_FLT);
+
+ if (samplecount < 0)
+ return -1;
+
samplecount >>= 1;
}else{
const int channel_stride = avctx->channels;
else
samplecount = wv_unpack_mono(s, &s->gb, samples, AV_SAMPLE_FMT_FLT);
+ if (samplecount < 0)
+ return -1;
+
if(s->stereo && avctx->sample_fmt == AV_SAMPLE_FMT_S16){
int16_t *dst = (int16_t*)samples + 1;
int16_t *src = (int16_t*)samples;
int cnt = samplecount;
- while(cnt-- > 0){
+ while(cnt--){
*dst = *src;
src += channel_stride;
dst += channel_stride;
int32_t *dst = (int32_t*)samples + 1;
int32_t *src = (int32_t*)samples;
int cnt = samplecount;
- while(cnt-- > 0){
+ while(cnt--){
*dst = *src;
src += channel_stride;
dst += channel_stride;
float *dst = (float*)samples + 1;
float *src = (float*)samples;
int cnt = samplecount;
- while(cnt-- > 0){
+ while(cnt--){
*dst = *src;
src += channel_stride;
dst += channel_stride;
return samplecount * bpp;
}
+static void wavpack_decode_flush(AVCodecContext *avctx)
+{
+ WavpackContext *s = avctx->priv_data;
+ int i;
+
+ for (i = 0; i < s->fdec_num; i++)
+ wv_reset_saved_context(s->fdec[i]);
+}
+
static int wavpack_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
if(frame_size < 0 || frame_size > buf_size){
av_log(avctx, AV_LOG_ERROR, "Block %d has invalid size (size %d vs. %d bytes left)\n",
s->block, frame_size, buf_size);
+ wavpack_decode_flush(avctx);
return -1;
}
if((samplecount = wavpack_decode_block(avctx, s->block, data,
- data_size, buf, frame_size)) < 0)
+ data_size, buf, frame_size)) < 0) {
+ wavpack_decode_flush(avctx);
return -1;
+ }
s->block++;
buf += frame_size; buf_size -= frame_size;
}
return s->samples_left > 0 ? 0 : avpkt->size;
}
-static void wavpack_decode_flush(AVCodecContext *avctx)
-{
- WavpackContext *s = avctx->priv_data;
- int i;
-
- for (i = 0; i < s->fdec_num; i++)
- wv_reset_saved_context(s->fdec[i]);
-}
-
AVCodec ff_wavpack_decoder = {
.name = "wavpack",
.type = AVMEDIA_TYPE_AUDIO,