| @@ -307,6 +307,10 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) · 306 unmodified lines |
| 307 | 307 | avctx->block_align != 17 * avctx->ch_layout.nb_channels) |
| 308 | 308 | return AVERROR_INVALIDDATA; |
| 309 | 309 | break; |
| 310 | + case AV_CODEC_ID_ADPCM_IMA_XBOX: |
| 311 | + if (avctx->bits_per_coded_sample != 4) |
| 312 | + return AVERROR_INVALIDDATA; |
| 313 | + break; |
| 310 | 314 | case AV_CODEC_ID_ADPCM_ZORK: |
| 311 | 315 | if (avctx->bits_per_coded_sample != 8) |
| 312 | 316 | return AVERROR_INVALIDDATA; |
| @@ -321,6 +325,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) · 8 unmodified lines |
| 321 | 325 | case AV_CODEC_ID_ADPCM_IMA_DAT4: |
| 322 | 326 | case AV_CODEC_ID_ADPCM_IMA_QT: |
| 323 | 327 | case AV_CODEC_ID_ADPCM_IMA_WAV: |
| 328 | + case AV_CODEC_ID_ADPCM_IMA_XBOX: |
| 324 | 329 | case AV_CODEC_ID_ADPCM_4XM: |
| 325 | 330 | case AV_CODEC_ID_ADPCM_XA: |
| 326 | 331 | case AV_CODEC_ID_ADPCM_XMD: |
| @@ -979,6 +984,15 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, · 652 unmodified lines |
| 979 | 984 | return AVERROR_INVALIDDATA; |
| 980 | 985 | nb_samples = 1 + (buf_size - 4 * ch) / (bsize * ch) * bsamples; |
| 981 | 986 | ) /* End of CASE */ |
| 987 | + CASE(ADPCM_IMA_XBOX, |
| 988 | + int bsize = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2]; |
| 989 | + int bsamples = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2]; |
| 990 | + if (avctx->block_align > 0) |
| 991 | + buf_size = FFMIN(buf_size, avctx->block_align); |
| 992 | + if (buf_size < 4 * ch) |
| 993 | + return AVERROR_INVALIDDATA; |
| 994 | + nb_samples = (buf_size - 4 * ch) / (bsize * ch) * bsamples + 1; |
| 995 | + ) /* End of CASE */ |
| 982 | 996 | case AV_CODEC_ID_ADPCM_MS: |
| 983 | 997 | if (avctx->block_align > 0) |
| 984 | 998 | buf_size = FFMIN(buf_size, avctx->block_align); |
| @@ -1197,6 +1211,32 @@ static int adpcm_decode_frame(AVCodecContext *avctx, AVFrame *frame, · 212 unmodified lines |
| 1197 | 1211 | } |
| 1198 | 1212 | } |
| 1199 | 1213 | ) /* End of CASE */ |
| 1214 | + CASE(ADPCM_IMA_XBOX, |
| 1215 | + for (int i = 0; i < channels; i++) { |
| 1216 | + ADPCMChannelStatus *cs = &c->status[i]; |
| 1217 | + cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16); |
| 1218 | + |
| 1219 | + cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16); |
| 1220 | + if (cs->step_index > 88u) { |
| 1221 | + av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n", |
| 1222 | + i, cs->step_index); |
| 1223 | + return AVERROR_INVALIDDATA; |
| 1224 | + } |
| 1225 | + } |
| 1226 | + |
| 1227 | + for (int n = 0; n < (nb_samples-1) / 8; n++) { |
| 1228 | + for (int i = 0; i < channels; i++) { |
| 1229 | + ADPCMChannelStatus *cs = &c->status[i]; |
| 1230 | + samples = &samples_p[i][1 + n * 8]; |
| 1231 | + for (int m = 0; m < 8; m += 2) { |
| 1232 | + int v = bytestream2_get_byteu(&gb); |
| 1233 | + samples[m ] = adpcm_ima_expand_nibble(cs, v & 0x0F, 3); |
| 1234 | + samples[m + 1] = adpcm_ima_expand_nibble(cs, v >> 4 , 3); |
| 1235 | + } |
| 1236 | + } |
| 1237 | + } |
| 1238 | + frame->nb_samples--; |
| 1239 | + ) /* End of CASE */ |
| 1200 | 1240 | CASE(ADPCM_4XM, |
| 1201 | 1241 | for (int i = 0; i < channels; i++) |
| 1202 | 1242 | c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16); |
| @@ -2404,6 +2444,7 @@ ADPCM_DECODER(ADPCM_IMA_SMJPEG, sample_fmts_s16, adpcm_ima_smjpeg, "ADPCM IMA · 1201 unmodified lines |
| 2404 | 2444 | ADPCM_DECODER(ADPCM_IMA_ALP, sample_fmts_s16, adpcm_ima_alp, "ADPCM IMA High Voltage Software ALP") |
| 2405 | 2445 | ADPCM_DECODER(ADPCM_IMA_WAV, sample_fmts_s16p, adpcm_ima_wav, "ADPCM IMA WAV") |
| 2406 | 2446 | ADPCM_DECODER(ADPCM_IMA_WS, sample_fmts_both, adpcm_ima_ws, "ADPCM IMA Westwood") |
| 2447 | +ADPCM_DECODER(ADPCM_IMA_XBOX, sample_fmts_s16p, adpcm_ima_xbox, "ADPCM IMA Xbox") |
| 2407 | 2448 | ADPCM_DECODER(ADPCM_MS, sample_fmts_both, adpcm_ms, "ADPCM Microsoft") |
| 2408 | 2449 | ADPCM_DECODER(ADPCM_MTAF, sample_fmts_s16p, adpcm_mtaf, "ADPCM MTAF") |
| 2409 | 2450 | ADPCM_DECODER(ADPCM_PSX, sample_fmts_s16p, adpcm_psx, "ADPCM Playstation") |