Message ID | CAB0OVGosb93BwvNAAAwtdcKQBCgwY3bHy2sM395ScMwQLW1bfQ@mail.gmail.com |
---|---|
State | Superseded |
Headers | show |
On 12/12/18, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote: > Hi! > > Attached patch fixes ticket #4553 for me. > > Please comment, Carl Eugen > I do not like what you did to G729Context. Please rewrite patch. Move relevant parts into G729ChannelContext chan[2];
2018-12-12 23:30 GMT+01:00, Paul B Mahol <onemda@gmail.com>: > On 12/12/18, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote: >> Hi! >> >> Attached patch fixes ticket #4553 for me. >> >> Please comment, Carl Eugen >> > > I do not like what you did to G729Context. > Please rewrite patch. > Move relevant parts into G729ChannelContext chan[2]; Which part of the context does not need to be duplicated? Carl Eugen
On 12/12/18, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote: > 2018-12-12 23:30 GMT+01:00, Paul B Mahol <onemda@gmail.com>: >> On 12/12/18, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote: >>> Hi! >>> >>> Attached patch fixes ticket #4553 for me. >>> >>> Please comment, Carl Eugen >>> >> >> I do not like what you did to G729Context. > >> Please rewrite patch. >> Move relevant parts into G729ChannelContext chan[2]; > > Which part of the context does not need to be duplicated? AudioDSPContext adsp;
2018-12-12 23:44 GMT+01:00, Paul B Mahol <onemda@gmail.com>: > On 12/12/18, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote: >> 2018-12-12 23:30 GMT+01:00, Paul B Mahol <onemda@gmail.com>: >>> On 12/12/18, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote: >>>> Hi! >>>> >>>> Attached patch fixes ticket #4553 for me. >>>> >>>> Please comment, Carl Eugen >>> >>> I do not like what you did to G729Context. >> >>> Please rewrite patch. >>> Move relevant parts into G729ChannelContext chan[2]; >> >> Which part of the context does not need to be duplicated? > > AudioDSPContext adsp; Looks like 24 bytes. (Or twelve?) I would really prefer not to make this patch more complicated to save 24 bytes on the heap that may get lost on the additional allocation. Carl Eugen
On 12/12/18, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote: > 2018-12-12 23:44 GMT+01:00, Paul B Mahol <onemda@gmail.com>: >> On 12/12/18, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote: >>> 2018-12-12 23:30 GMT+01:00, Paul B Mahol <onemda@gmail.com>: >>>> On 12/12/18, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote: >>>>> Hi! >>>>> >>>>> Attached patch fixes ticket #4553 for me. >>>>> >>>>> Please comment, Carl Eugen >>>> >>>> I do not like what you did to G729Context. >>> >>>> Please rewrite patch. >>>> Move relevant parts into G729ChannelContext chan[2]; >>> >>> Which part of the context does not need to be duplicated? >> >> AudioDSPContext adsp; > > Looks like 24 bytes. (Or twelve?) > I would really prefer not to make this patch more > complicated to save 24 bytes on the heap that may get lost > on the additional allocation. Then I will do it, if you can not.
Hi, On 12/13/18, Paul B Mahol <onemda@gmail.com> wrote: > On 12/12/18, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote: >> 2018-12-12 23:44 GMT+01:00, Paul B Mahol <onemda@gmail.com>: >>> On 12/12/18, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote: >>>> 2018-12-12 23:30 GMT+01:00, Paul B Mahol <onemda@gmail.com>: >>>>> On 12/12/18, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote: >>>>>> Hi! >>>>>> >>>>>> Attached patch fixes ticket #4553 for me. >>>>>> >>>>>> Please comment, Carl Eugen >>>>> >>>>> I do not like what you did to G729Context. >>>> >>>>> Please rewrite patch. >>>>> Move relevant parts into G729ChannelContext chan[2]; >>>> >>>> Which part of the context does not need to be duplicated? >>> >>> AudioDSPContext adsp; >> >> Looks like 24 bytes. (Or twelve?) >> I would really prefer not to make this patch more >> complicated to save 24 bytes on the heap that may get lost >> on the additional allocation. > > Then I will do it, if you can not. > Feel free to apply patch as is, I will then rewrite code.
From 64114575e9015608c0266df5a6339f526e9dd233 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos <ceffmpeg@gmail.com> Date: Wed, 12 Dec 2018 23:19:59 +0100 Subject: [PATCH] lavc/g729dec: Support stereo streams. Fixes ticket #4553. --- libavcodec/g729_parser.c | 1 + libavcodec/g729dec.c | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/libavcodec/g729_parser.c b/libavcodec/g729_parser.c index d13c990..9982dbf 100644 --- a/libavcodec/g729_parser.c +++ b/libavcodec/g729_parser.c @@ -48,6 +48,7 @@ static int g729_parse(AVCodecParserContext *s1, AVCodecContext *avctx, av_assert1(avctx->codec_id == AV_CODEC_ID_G729); /* FIXME: replace this heuristic block_size with more precise estimate */ s->block_size = (avctx->bit_rate < 8000) ? G729D_6K4_BLOCK_SIZE : G729_8K_BLOCK_SIZE; + s->block_size *= avctx->channels; s->duration = avctx->frame_size; } diff --git a/libavcodec/g729dec.c b/libavcodec/g729dec.c index 2e1bf18..d27ab51 100644 --- a/libavcodec/g729dec.c +++ b/libavcodec/g729dec.c @@ -339,17 +339,18 @@ static int32_t scalarproduct_int16_c(const int16_t * v1, const int16_t * v2, int static av_cold int decoder_init(AVCodecContext * avctx) { G729Context* ctx = avctx->priv_data; - int i,k; + int c,i,k; - if (avctx->channels != 1) { - av_log(avctx, AV_LOG_ERROR, "Only mono sound is supported (requested channels: %d).\n", avctx->channels); + if (avctx->channels > 2) { + av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported (requested channels: %d).\n", avctx->channels); return AVERROR(EINVAL); } - avctx->sample_fmt = AV_SAMPLE_FMT_S16; + avctx->sample_fmt = AV_SAMPLE_FMT_S16P; /* Both 8kbit/s and 6.4kbit/s modes uses two subframes per frame. */ avctx->frame_size = SUBFRAME_SIZE << 1; + for (c = 0; c < avctx->channels; c++) { ctx->gain_coeff = 16384; // 1.0 in (1.14) for (k = 0; k < MA_NP + 1; k++) { @@ -376,6 +377,9 @@ static av_cold int decoder_init(AVCodecContext * avctx) ff_audiodsp_init(&ctx->adsp); ctx->adsp.scalarproduct_int16 = scalarproduct_int16_c; + ctx++; + } + return 0; } @@ -389,7 +393,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, const G729FormatDescription *format; int frame_erasure = 0; ///< frame erasure detected during decoding int bad_pitch = 0; ///< parity check failed - int i; + int c, i; int16_t *tmp; G729Formats packet_type; G729Context *ctx = avctx->priv_data; @@ -411,16 +415,15 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, frame->nb_samples = SUBFRAME_SIZE<<1; if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; - out_frame = (int16_t*) frame->data[0]; - if (buf_size % 10 == 0) { + if (buf_size % G729_8K_BLOCK_SIZE * avctx->channels == 0) { packet_type = FORMAT_G729_8K; format = &format_g729_8k; //Reset voice decision ctx->onset = 0; ctx->voice_decision = DECISION_VOICE; av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729 @ 8kbit/s"); - } else if (buf_size == 8) { + } else if (buf_size == G729D_6K4_BLOCK_SIZE * avctx->channels) { packet_type = FORMAT_G729D_6K4; format = &format_g729d_6k4; av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729D @ 6.4kbit/s"); @@ -429,6 +432,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, return AVERROR_INVALIDDATA; } + for (c = 0; c < avctx->channels; c++) { + out_frame = (int16_t*)frame->data[c]; + for (i=0; i < buf_size; i++) frame_erasure |= buf[i]; frame_erasure = !frame_erasure; @@ -702,8 +708,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, /* Save signal for use in next frame. */ memmove(ctx->exc_base, ctx->exc_base + 2 * SUBFRAME_SIZE, (PITCH_DELAY_MAX+INTERPOL_LEN)*sizeof(int16_t)); + buf += packet_type == FORMAT_G729_8K ? G729_8K_BLOCK_SIZE : G729D_6K4_BLOCK_SIZE; + ctx++; + } + *got_frame_ptr = 1; - return packet_type == FORMAT_G729_8K ? 10 : 8; + return packet_type == FORMAT_G729_8K ? G729_8K_BLOCK_SIZE * avctx->channels : G729D_6K4_BLOCK_SIZE * avctx->channels; } AVCodec ff_g729_decoder = { @@ -711,7 +721,7 @@ AVCodec ff_g729_decoder = { .long_name = NULL_IF_CONFIG_SMALL("G.729"), .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_G729, - .priv_data_size = sizeof(G729Context), + .priv_data_size = sizeof(G729Context) * 2, .init = decoder_init, .decode = decode_frame, .capabilities = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1, -- 1.7.10.4