mirror of https://git.ffmpeg.org/ffmpeg.git
adpcm: convert adpcm_ima_ea_eacs to bytestream2.
This commit is contained in:
parent
159831cc09
commit
8f2ed09289
|
@ -353,6 +353,7 @@ static int xa_decode(AVCodecContext *avctx,
|
||||||
* number of samples in each frame.
|
* number of samples in each frame.
|
||||||
*/
|
*/
|
||||||
static int get_nb_samples(AVCodecContext *avctx, const uint8_t *buf,
|
static int get_nb_samples(AVCodecContext *avctx, const uint8_t *buf,
|
||||||
|
GetByteContext *gb,
|
||||||
int buf_size, int *coded_samples)
|
int buf_size, int *coded_samples)
|
||||||
{
|
{
|
||||||
ADPCMDecodeContext *s = avctx->priv_data;
|
ADPCMDecodeContext *s = avctx->priv_data;
|
||||||
|
@ -410,9 +411,7 @@ static int get_nb_samples(AVCodecContext *avctx, const uint8_t *buf,
|
||||||
break;
|
break;
|
||||||
case CODEC_ID_ADPCM_IMA_EA_EACS:
|
case CODEC_ID_ADPCM_IMA_EA_EACS:
|
||||||
has_coded_samples = 1;
|
has_coded_samples = 1;
|
||||||
if (buf_size < 4)
|
*coded_samples = bytestream2_get_le32(gb);
|
||||||
return 0;
|
|
||||||
*coded_samples = AV_RL32(buf);
|
|
||||||
nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
|
nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
|
||||||
break;
|
break;
|
||||||
case CODEC_ID_ADPCM_EA_MAXIS_XA:
|
case CODEC_ID_ADPCM_EA_MAXIS_XA:
|
||||||
|
@ -529,7 +528,8 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
|
||||||
int nb_samples, coded_samples, ret;
|
int nb_samples, coded_samples, ret;
|
||||||
GetByteContext gb;
|
GetByteContext gb;
|
||||||
|
|
||||||
nb_samples = get_nb_samples(avctx, buf, buf_size, &coded_samples);
|
bytestream2_init(&gb, buf, buf_size);
|
||||||
|
nb_samples = get_nb_samples(avctx, buf, &gb, buf_size, &coded_samples);
|
||||||
if (nb_samples <= 0) {
|
if (nb_samples <= 0) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");
|
av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
|
@ -552,7 +552,6 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
src = buf;
|
src = buf;
|
||||||
bytestream2_init(&gb, buf, buf_size);
|
|
||||||
|
|
||||||
st = avctx->channels == 2 ? 1 : 0;
|
st = avctx->channels == 2 ? 1 : 0;
|
||||||
|
|
||||||
|
@ -843,16 +842,21 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CODEC_ID_ADPCM_IMA_EA_EACS:
|
case CODEC_ID_ADPCM_IMA_EA_EACS:
|
||||||
src += 4; // skip sample count (already read)
|
for (i=0; i<=st; i++) {
|
||||||
|
c->status[i].step_index = bytestream2_get_le32u(&gb);
|
||||||
|
if (c->status[i].step_index > 88u) {
|
||||||
|
av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
|
||||||
|
i, c->status[i].step_index);
|
||||||
|
return AVERROR_INVALIDDATA;
|
||||||
|
}
|
||||||
|
}
|
||||||
for (i=0; i<=st; i++)
|
for (i=0; i<=st; i++)
|
||||||
c->status[i].step_index = av_clip(bytestream_get_le32(&src), 0, 88);
|
c->status[i].predictor = bytestream2_get_le32u(&gb);
|
||||||
for (i=0; i<=st; i++)
|
|
||||||
c->status[i].predictor = bytestream_get_le32(&src);
|
|
||||||
|
|
||||||
for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
|
for (n = nb_samples >> (1 - st); n > 0; n--) {
|
||||||
*samples++ = adpcm_ima_expand_nibble(&c->status[0], *src>>4, 3);
|
int byte = bytestream2_get_byteu(&gb);
|
||||||
*samples++ = adpcm_ima_expand_nibble(&c->status[st], *src&0x0F, 3);
|
*samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 3);
|
||||||
|
*samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 3);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CODEC_ID_ADPCM_IMA_EA_SEAD:
|
case CODEC_ID_ADPCM_IMA_EA_SEAD:
|
||||||
|
|
Loading…
Reference in New Issue