+ /* get stream config */
+ if (avctx->codec_id == AV_CODEC_ID_XMA2 && avctx->extradata_size == 34) { /* XMA2WAVEFORMATEX */
+ s->num_streams = (avctx->channels + 1) / 2;
+ } else if (avctx->codec_id == AV_CODEC_ID_XMA2 && avctx->extradata_size >= 2) { /* XMA2WAVEFORMAT */
+ s->num_streams = avctx->extradata[1];
+ if (avctx->extradata_size != (32 + ((avctx->extradata[0]==3)?0:8) + 4*s->num_streams)) {
+ av_log(avctx, AV_LOG_ERROR, "Incorrect XMA2 extradata size\n");
+ return AVERROR(EINVAL);
+ }
+ } else if (avctx->codec_id == AV_CODEC_ID_XMA1 && avctx->extradata_size >= 4) { /* XMAWAVEFORMAT */
+ s->num_streams = avctx->extradata[4];
+ if (avctx->extradata_size != (8 + 20*s->num_streams)) {
+ av_log(avctx, AV_LOG_ERROR, "Incorrect XMA1 extradata size\n");
+ return AVERROR(EINVAL);
+ }
+ } else {
+ av_log(avctx, AV_LOG_ERROR, "Incorrect XMA config\n");
+ return AVERROR(EINVAL);
+ }
+
+ /* encoder supports up to 64 streams / 64*2 channels (would have to alloc arrays) */
+ if (avctx->channels > XMA_MAX_CHANNELS || s->num_streams > XMA_MAX_STREAMS) {
+ avpriv_request_sample(avctx, "More than %d channels in %d streams", XMA_MAX_CHANNELS, s->num_streams);
+ return AVERROR_PATCHWELCOME;
+ }
+
+ /* init all streams (several streams of 1/2ch make Nch files) */
+ for (i = 0; i < s->num_streams; i++) {
+ ret = decode_init(&s->xma[i], avctx, i);