avcodec/adpcm: squelch 'mismatch in coded sample count' warning for AV_CODEC_ID_ADPCM_EA_R2/3
These ADPCM codecs include a per-frame flag that enables a raw 16-bit mode. Therefore
the the number of samples returned by get_nb_samples() is only ever approximate.
Fixes ticket #3460.
Signed-off-by: Peter Ross <pross@xvid.org>
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 7380201451
)
This commit is contained in:
committed by
Carl Eugen Hoyos
parent
620d80d572
commit
b1a960cc83
@ -449,9 +449,11 @@ static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_
|
|||||||
* @param[out] coded_samples set to the number of samples as coded in the
|
* @param[out] coded_samples set to the number of samples as coded in the
|
||||||
* packet, or 0 if the codec does not encode the
|
* packet, or 0 if the codec does not encode the
|
||||||
* number of samples in each frame.
|
* number of samples in each frame.
|
||||||
|
* @param[out] approx_nb_samples set to non-zero if the number of samples
|
||||||
|
* returned is an approximation.
|
||||||
*/
|
*/
|
||||||
static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
|
static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
|
||||||
int buf_size, int *coded_samples)
|
int buf_size, int *coded_samples, int *approx_nb_samples)
|
||||||
{
|
{
|
||||||
ADPCMDecodeContext *s = avctx->priv_data;
|
ADPCMDecodeContext *s = avctx->priv_data;
|
||||||
int nb_samples = 0;
|
int nb_samples = 0;
|
||||||
@ -460,6 +462,7 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
|
|||||||
int header_size;
|
int header_size;
|
||||||
|
|
||||||
*coded_samples = 0;
|
*coded_samples = 0;
|
||||||
|
*approx_nb_samples = 0;
|
||||||
|
|
||||||
if(ch <= 0)
|
if(ch <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
@ -530,10 +533,12 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
|
|||||||
case AV_CODEC_ID_ADPCM_EA_R2:
|
case AV_CODEC_ID_ADPCM_EA_R2:
|
||||||
header_size = 4 + 5 * ch;
|
header_size = 4 + 5 * ch;
|
||||||
*coded_samples = bytestream2_get_le32(gb);
|
*coded_samples = bytestream2_get_le32(gb);
|
||||||
|
*approx_nb_samples = 1;
|
||||||
break;
|
break;
|
||||||
case AV_CODEC_ID_ADPCM_EA_R3:
|
case AV_CODEC_ID_ADPCM_EA_R3:
|
||||||
header_size = 4 + 5 * ch;
|
header_size = 4 + 5 * ch;
|
||||||
*coded_samples = bytestream2_get_be32(gb);
|
*coded_samples = bytestream2_get_be32(gb);
|
||||||
|
*approx_nb_samples = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*coded_samples -= *coded_samples % 28;
|
*coded_samples -= *coded_samples % 28;
|
||||||
@ -625,11 +630,11 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
int16_t **samples_p;
|
int16_t **samples_p;
|
||||||
int st; /* stereo */
|
int st; /* stereo */
|
||||||
int count1, count2;
|
int count1, count2;
|
||||||
int nb_samples, coded_samples, ret;
|
int nb_samples, coded_samples, approx_nb_samples, ret;
|
||||||
GetByteContext gb;
|
GetByteContext gb;
|
||||||
|
|
||||||
bytestream2_init(&gb, buf, buf_size);
|
bytestream2_init(&gb, buf, buf_size);
|
||||||
nb_samples = get_nb_samples(avctx, &gb, buf_size, &coded_samples);
|
nb_samples = get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_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;
|
||||||
@ -647,7 +652,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
/* use coded_samples when applicable */
|
/* use coded_samples when applicable */
|
||||||
/* it is always <= nb_samples, so the output buffer will be large enough */
|
/* it is always <= nb_samples, so the output buffer will be large enough */
|
||||||
if (coded_samples) {
|
if (coded_samples) {
|
||||||
if (coded_samples != nb_samples)
|
if (!approx_nb_samples && coded_samples != nb_samples)
|
||||||
av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");
|
av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");
|
||||||
frame->nb_samples = nb_samples = coded_samples;
|
frame->nb_samples = nb_samples = coded_samples;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user