[FFmpeg-cvslog] r18667 - trunk/libavcodec/wavpack.c
Laurent Aimar
fenrir
Thu Apr 23 20:00:34 CEST 2009
Hi,
On Thu, Apr 23, 2009, kostya wrote:
> static av_cold int wavpack_decode_init(AVCodecContext *avctx)
> {
> WavpackContext *s = avctx->priv_data;
>
> s->avctx = avctx;
> s->stereo = (avctx->channels == 2);
> - avctx->sample_fmt = SAMPLE_FMT_S16;
> + if(avctx->bits_per_coded_sample <= 16)
> + avctx->sample_fmt = SAMPLE_FMT_S16;
> + else
> + avctx->sample_fmt = SAMPLE_FMT_S32;
> avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
>
> return 0;
> @@ -483,11 +612,13 @@ static int wavpack_decode_frame(AVCodecC
> int buf_size = avpkt->size;
> WavpackContext *s = avctx->priv_data;
> int16_t *samples = data;
> + int32_t *samples32 = data;
> int samplecount;
> int got_terms = 0, got_weights = 0, got_samples = 0, got_entropy = 0, got_bs = 0;
> int got_hybrid = 0;
> const uint8_t* buf_end = buf + buf_size;
> int i, j, id, size, ssize, weights, t;
> + int bpp = avctx->bits_per_coded_sample <= 16 ? 2 : 4;
>
> if (buf_size == 0){
> *data_size = 0;
> @@ -504,7 +635,7 @@ static int wavpack_decode_frame(AVCodecC
> return buf_size;
> }
> /* should not happen but who knows */
> - if(s->samples * 2 * avctx->channels > *data_size){
> + if(s->samples * bpp * avctx->channels > *data_size){
> av_log(avctx, AV_LOG_ERROR, "Packet size is too big to be handled in lavc!\n");
> return -1;
> }
> @@ -513,7 +644,7 @@ static int wavpack_decode_frame(AVCodecC
> 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;
> - s->post_shift = (s->frame_flags >> 13) & 0x1f;
> + s->post_shift = 8 * (bpp-1-(s->frame_flags&0x03)) + ((s->frame_flags >> 13) & 0x1f);
Why not using (s->frame_flags&0x03) to dynamically set the output
format (avctx->sample_fmt) ?
This way, a user app will automatically have the right sample size and will
not have to fill bits_per_coded_sample (which is kind of undocumented and
I have no idea how to fill it right except by always setting 32 here).
Regards,
--
fenrir
More information about the ffmpeg-cvslog
mailing list