Earlier, bits per sample was defined as 8, which wasn't chosen
with any thought, only chosen since it didn't seem to change
anything compared to not defining it at all.
g722 encodes 2 samples into one byte codeword, therefore the
bits per sample is 4. By changing this, the generated timestamps
for streams encoded with g722 become correct.
Due to the way avcodec_encode_audio is defined for non frame
based codecs, calculating the number of input samples in the
encode function has to be changed once the bits per samples
definition is changed.
---
libavcodec/g722enc.c | 4 ++--
libavcodec/utils.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c
index bdc30d5..706a7ae 100644
--- a/libavcodec/g722enc.c
+++ b/libavcodec/g722enc.c
@@ -280,12 +280,12 @@ static int g722_encode_frame(AVCodecContext *avctx,
{
G722Context *c = avctx->priv_data;
const int16_t *samples = data;
- int i;
+ int i, nsamples = buf_size * 8 / av_get_bits_per_sample(avctx->codec->id);
if (avctx->trellis)
return g722_encode_trellis(avctx, dst, buf_size, data);
- for (i = 0; i < buf_size >> 1; i++) {
+ for (i = 0; i < nsamples >> 1; i++) {
int xlow, xhigh, ihigh, ilow;
filter_samples(c, &samples[2*i], &xlow, &xhigh);
ihigh = encode_high(&c->band[1], xhigh);
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 53440e0..59588d7 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1151,8 +1151,8 @@ int av_get_bits_per_sample(enum CodecID codec_id){
case CODEC_ID_ADPCM_SWF:
case CODEC_ID_ADPCM_MS:
case CODEC_ID_ADPCM_YAMAHA:
- return 4;
case CODEC_ID_ADPCM_G722:
+ return 4;
case CODEC_ID_PCM_ALAW:
case CODEC_ID_PCM_MULAW:
case CODEC_ID_PCM_S8:
--
1.7.3.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel