From patchwork Fri Dec 14 14:18:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 11413 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id BE0F544D7DB for ; Fri, 14 Dec 2018 16:25:55 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DDF8468AAC0; Fri, 14 Dec 2018 16:25:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it1-f194.google.com (mail-it1-f194.google.com [209.85.166.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6559A68AAC0 for ; Fri, 14 Dec 2018 16:25:48 +0200 (EET) Received: by mail-it1-f194.google.com with SMTP id b5so9512358iti.2 for ; Fri, 14 Dec 2018 06:25:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=CuVEkvQeYnWHFYvYSHDBFK077My3MZC89XGFWrhoXas=; b=cqm/za6RAJc6emBEquXgzLZonnT5Qb0sMmSgvIpBbpzwkoATFAvguJghSlu3ikeyf7 yJFLajxX9LoNTcNXsFA2oPhpQDpTHIFMv4Jc+yvDqEZEUyyCSP5wKESx+Lk/RaGMHwY4 E4BAj3woM8DKD6+AY7BhUH6pvSUbL4XuuLBB+5HHMqHv5fNELutGQjgVKwNhlS1obvkR 4dovHnvqCZ1ZMwmN8yVjWVs8H2KAOknLQk5wd6kpBBn9iFJgaUyxK8Q0hUVej+F9H+GP ReeVRi1uT6vqqj61U86b8uMYITxb2hwQ5sBcua1Fr/o52PMhpEicR7x82GonDHbrTiUb /YUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=CuVEkvQeYnWHFYvYSHDBFK077My3MZC89XGFWrhoXas=; b=Vfh/rPMANQjDbAHsf0JVnFvoNCBlt5UDTyOrYZetM1W3yPvg8yKPFclYLJTu0KsYns 15mfyPA3oO5tEXFp09fSLXzSX3YyJoy+Ux/mkPrHl88rjRJKSCa1XbvHcWmge68lZ4NZ JKrStxTk8eJS360JJkQKpuQWSuFR886+wvaoCLrh0GEiLKqL978I8SqFYFXiGJYj9Rvt 0iIbC5cHUZxnjtkxlIQ06Z7G3iCfB0hVNeKnzonHxjPybYtJGWL8XdOXVZSic4a0pxVR yKXZTjiQdwdZb8edZVVZdY93soQkV6ujqmot87Clee5TWZB+jUmtypAuKvncAVaFPu8K CVHA== X-Gm-Message-State: AA+aEWZGVLNykrHCcetPFnBRhgnxVRRTPb5mfQYMQ1FCW4PN6JGY2TfA VliJ9gn/LYwSaU2vHjDa9J8nVE0/rgLDsffYFbELvQ== X-Google-Smtp-Source: AFSGD/Vra1tcIScncXjWnLVqtyTJ8yDU0k9/i5mxAYMnilMYYh9ILLSCbIG0lYgSJg+LI1Ogh+B4Stf/xaTZVunuZs0= X-Received: by 2002:a24:3752:: with SMTP id r79mr2781294itr.121.1544797094188; Fri, 14 Dec 2018 06:18:14 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a02:5f11:0:0:0:0:0 with HTTP; Fri, 14 Dec 2018 06:18:12 -0800 (PST) In-Reply-To: References: From: Carl Eugen Hoyos Date: Fri, 14 Dec 2018 15:18:12 +0100 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH]lavc/g729dec: Support stereo streams X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 2018-12-12 23:44 GMT+01:00, Paul B Mahol : > On 12/12/18, Carl Eugen Hoyos wrote: >> 2018-12-12 23:30 GMT+01:00, Paul B Mahol : >>> On 12/12/18, Carl Eugen Hoyos 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; New patch attached. Please comment, Carl Eugen From 9fb106d7ae33f2d182cd5c95ec10a823a344fa93 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Fri, 14 Dec 2018 15:16:56 +0100 Subject: [PATCH] lavc/g729dec: Support stereo streams. Fixes ticket #4553. --- libavcodec/g729_parser.c | 1 + libavcodec/g729dec.c | 72 ++++++++++++++++++++++++++++++++-------------- libavcodec/version.h | 2 +- 3 files changed, 53 insertions(+), 22 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..101ce97 100644 --- a/libavcodec/g729dec.c +++ b/libavcodec/g729dec.c @@ -100,8 +100,6 @@ typedef struct { } G729FormatDescription; typedef struct { - AudioDSPContext adsp; - /// past excitation signal buffer int16_t exc_base[2*SUBFRAME_SIZE+PITCH_DELAY_MAX+INTERPOL_LEN]; @@ -152,7 +150,13 @@ typedef struct { /// high-pass filter data (past output) int16_t hpf_z[2]; -} G729Context; +} G729ChannelContext; + +typedef struct { + AudioDSPContext adsp; + + G729ChannelContext *channel_context; +} G729Context; static const G729FormatDescription format_g729_8k = { .ac_index_bits = {8,5}, @@ -338,18 +342,25 @@ 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; + G729Context *s = avctx->priv_data; + G729ChannelContext *ctx; + 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 < 1 || 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; + ctx = + s->channel_context = av_mallocz(sizeof(G729ChannelContext) * avctx->channels); + if (!ctx) + return AVERROR(ENOMEM); + + for (c = 0; c < avctx->channels; c++) { ctx->gain_coeff = 16384; // 1.0 in (1.14) for (k = 0; k < MA_NP + 1; k++) { @@ -373,8 +384,11 @@ static av_cold int decoder_init(AVCodecContext * avctx) for(i=0; i<4; i++) ctx->quant_energy[i] = -14336; // -14 in (5.10) - ff_audiodsp_init(&ctx->adsp); - ctx->adsp.scalarproduct_int16 = scalarproduct_int16_c; + ctx++; + } + + ff_audiodsp_init(&s->adsp); + s->adsp.scalarproduct_int16 = scalarproduct_int16_c; return 0; } @@ -387,12 +401,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, int16_t *out_frame; GetBitContext gb; 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; + G729Context *s = avctx->priv_data; + G729ChannelContext *ctx = s->channel_context; int16_t lp[2][11]; // (3.12) uint8_t ma_predictor; ///< switched MA predictor of LSP quantizer uint8_t quantizer_1st; ///< first stage vector of quantizer @@ -405,22 +418,20 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, int16_t synth[SUBFRAME_SIZE+10]; // fixed-codebook vector int j, ret; int gain_before, gain_after; - int is_periodic = 0; // whether one of the subframes is declared as periodic or not AVFrame *frame = data; 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 +440,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, return AVERROR_INVALIDDATA; } + for (c = 0; c < avctx->channels; c++) { + int frame_erasure = 0; ///< frame erasure detected during decoding + int bad_pitch = 0; ///< parity check failed + int is_periodic = 0; ///< whether one of the subframes is declared as periodic or not + out_frame = (int16_t*)frame->data[c]; + for (i=0; i < buf_size; i++) frame_erasure |= buf[i]; frame_erasure = !frame_erasure; @@ -570,7 +587,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, } /* Decode the fixed-codebook gain. */ - ctx->past_gain_code[0] = ff_acelp_decode_gain_code(&ctx->adsp, gain_corr_factor, + ctx->past_gain_code[0] = ff_acelp_decode_gain_code(&s->adsp, gain_corr_factor, fc, MR_ENERGY, ctx->quant_energy, ma_prediction_coeff, @@ -660,7 +677,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, /* Call postfilter and also update voicing decision for use in next frame. */ ff_g729_postfilter( - &ctx->adsp, + &s->adsp, &ctx->ht_prev_data, &is_periodic, &lp[i][0], @@ -702,8 +719,20 @@ 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; +} + +static av_cold int decode_close(AVCodecContext *avctx) +{ + G729Context *s = avctx->priv_data; + av_freep(&s->channel_context); + + return 0; } AVCodec ff_g729_decoder = { @@ -714,5 +743,6 @@ AVCodec ff_g729_decoder = { .priv_data_size = sizeof(G729Context), .init = decoder_init, .decode = decode_frame, + .close = decode_close, .capabilities = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1, }; diff --git a/libavcodec/version.h b/libavcodec/version.h index 5677a7f..9e43338 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #define LIBAVCODEC_VERSION_MAJOR 58 #define LIBAVCODEC_VERSION_MINOR 42 -#define LIBAVCODEC_VERSION_MICRO 100 +#define LIBAVCODEC_VERSION_MICRO 101 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ -- 1.7.10.4