From patchwork Wed Dec 12 22:24:21 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: 11392 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 CB25144DC36 for ; Thu, 13 Dec 2018 00:24:28 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1997A689E13; Thu, 13 Dec 2018 00:24:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 65C356899C8 for ; Thu, 13 Dec 2018 00:24:12 +0200 (EET) Received: by mail-io1-f51.google.com with SMTP id s22so6687ioc.8 for ; Wed, 12 Dec 2018 14:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=OEq4yOlZ8iPSscgfHpscqjzTaVLfAkAkrmWD9UyTOnc=; b=uHsQIyMdF36AswOVjqeatPTSNcxudoSw31QKmRgckSizstzPR0DqzlGYqf2YfNabmf GiYhs31hby+CFtdXCkFUkChJL8ZSXcf47L+jGsxd/GouV180hdKoWfUnwZGBGQRzVZxi dxiUAA8JWZPBuLdSf2voIguqo0L+OVi0MIqpLITDD+V9WLrAtBlNpZLoXahf996rTGqM JY4s0igiga/fDV+7iAsWH3AMZnnI9Oeupuu0POUrjaUBl6KxibDOxzNOhHpeauzg7F9C OG6mNWO8aSivi6ReepKaS8FHoj8PPBPSXkmhryAZqjzACKYD+Q3zCOVZwNCv9gULMZ8i X+yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=OEq4yOlZ8iPSscgfHpscqjzTaVLfAkAkrmWD9UyTOnc=; b=oGXUOmpqXaWmCGN2flhZYtzpvxq17AfACo1bBOMPLKRW7DDcu8Lt3YxV9D+SGEP5gp w16KzcjUoXasZU9VBhTWLwIVXyoUxs4VLHgWFZGA6VjlcYSSw7oK32AJZzi9CvS8bhY+ hx2Hw98gMnwMa6Y38F4NTE70ScFLe6l8J3lHWEqtVjFDWBPVpQyAJ8ziG328BSXTLo8Z FpRidav8CHhhi6M9eh8h2p595dgoizshgPU64suCzgX88DecR1e3pw6ajL6dVB01b7PV zM/gVxyblYtK6rfQ68sqQFeC4Tt+dyPXr/zbAOmK4p46JWAjH5pHmEgGtYQrNN4WnJLX 75Ig== X-Gm-Message-State: AA+aEWamY1lmqMA6W1x8sQr8yEAvJrztDQCchCSxWYi5DVG+tcpVpIj0 szLb8uZ5jXN91qAsHONxs54g7KUZ2i67cR5Kx00lvw== X-Google-Smtp-Source: AFSGD/UnhqKQ2IBP1VAQoYw4bcnCBPVqZ78KgcPdlFxjks3VKRAUnMF9mhCDUoonB4wkogPB5DOeE/gL8p2pk27BqU0= X-Received: by 2002:a5d:8359:: with SMTP id q25mr18954598ior.49.1544653462903; Wed, 12 Dec 2018 14:24:22 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a02:5f11:0:0:0:0:0 with HTTP; Wed, 12 Dec 2018 14:24:21 -0800 (PST) From: Carl Eugen Hoyos Date: Wed, 12 Dec 2018 23:24:21 +0100 Message-ID: To: FFmpeg development discussions and patches Subject: [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" Hi! Attached patch fixes ticket #4553 for me. Please comment, Carl Eugen From 64114575e9015608c0266df5a6339f526e9dd233 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos 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