+ int ch;
+ for (ch = 0; ch < alac->numchannels; ch++) {
+ int buf_size = alac->setinfo_max_samples_per_frame * sizeof(int32_t);
+
+ FF_ALLOC_OR_GOTO(alac->avctx, alac->predicterror_buffer[ch],
+ buf_size, buf_alloc_fail);
+
+ FF_ALLOC_OR_GOTO(alac->avctx, alac->outputsamples_buffer[ch],
+ buf_size, buf_alloc_fail);
+
+ FF_ALLOC_OR_GOTO(alac->avctx, alac->extra_bits_buffer[ch],
+ buf_size, buf_alloc_fail);
+ }
+ return 0;
+buf_alloc_fail:
+ alac_decode_close(alac->avctx);
+ return AVERROR(ENOMEM);
+}
+
+static int alac_set_info(ALACContext *alac)
+{
+ const unsigned char *ptr = alac->avctx->extradata;
+
+ ptr += 4; /* size */
+ ptr += 4; /* alac */
+ ptr += 4; /* version */
+
+ if(AV_RB32(ptr) >= UINT_MAX/4){
+ av_log(alac->avctx, AV_LOG_ERROR, "setinfo_max_samples_per_frame too large\n");
+ return -1;
+ }
+
+ /* buffer size / 2 ? */
+ alac->setinfo_max_samples_per_frame = bytestream_get_be32(&ptr);
+ ptr++; /* compatible version */
+ alac->setinfo_sample_size = *ptr++;
+ alac->setinfo_rice_historymult = *ptr++;
+ alac->setinfo_rice_initialhistory = *ptr++;
+ alac->setinfo_rice_kmodifier = *ptr++;
+ alac->numchannels = *ptr++;
+ bytestream_get_be16(&ptr); /* maxRun */
+ bytestream_get_be32(&ptr); /* max coded frame size */
+ bytestream_get_be32(&ptr); /* average bitrate */
+ bytestream_get_be32(&ptr); /* samplerate */
+
+ return 0;
+}
+
+static av_cold int alac_decode_init(AVCodecContext * avctx)
+{
+ int ret;