From patchwork Tue Jan 2 08:59:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhangjiejun1992@gmail.com X-Patchwork-Id: 7075 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.79.195 with SMTP id r64csp14459104jad; Tue, 2 Jan 2018 00:59:42 -0800 (PST) X-Google-Smtp-Source: ACJfBos90inZ65g7CglY1pJ6kO7wmcqJgp3TMLj//yQLzVotj5CTGXVXecXpcVTm/Zx/yjyUuuAd X-Received: by 10.28.226.214 with SMTP id z205mr18116wmg.149.1514883582581; Tue, 02 Jan 2018 00:59:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514883582; cv=none; d=google.com; s=arc-20160816; b=T9wdA8w11iDleWtPTVf989kqASBT0UU+7yf3WoTEw1V9f4VFYApU5Df4r7KnRi7xxN 8GgmGJy8i8CAmwkqZcuB2hmNiGUWIZvmLDHffHBGef3Fsltg84wEEPttQVApqvqMoXBP UfOTlboL8845GOpgrYvVxtalTim2OZ4rACaretfJr6yS0+VC7A7GMwrZf4nlSS0oxGJw q9dAIv17mGnf4CLMtqZApfcb0E/fhyV2jpjoIKk6lJ5Ky3uh4j6ij1bdRnsw2rpXXfYQ sJKSHacgMUUhoHzobubG3ITjwcx+7tF+WprZIZSpBR88pskkxhj3P8aFCutWYSwn1k6b rZuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=dZQtpcwUCrGjl2oxVde8MWCxGTxuFRF+Vv04Gtnr1ak=; b=fPVI8UXhJEhgSbBqhZa+eZ58FuBdObiN3bf+UbewS08oXJiU3Y6PyvId+4DxRN5RbJ 811j/OvMZODLKO7eotoqoieIMRyulj0scgiXO/6GkCdBrjhBXpBqXYpfEAVoU8CzV8ac CtlnEK04yX4wEnfue4MTBdTUGdR/CWrX9oHdNTSpoVY9Q6JzioU8yMHpqMghSvyk8hND CluYc1KgUoQEM/5IP5Kv+tF1zQmotDLycHsOJ2jXEznFdQ97Vs6mg9HaKOAqD78inZqh it3T81TOtij8uy5ejOvTFmoCSp26knMbSmSD+WZctCPeJb/YMSTVVU30G+EIiZO8LT+Y L9lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=RP02H8Es; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b15si5341543wrh.427.2018.01.02.00.59.41; Tue, 02 Jan 2018 00:59:42 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=RP02H8Es; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D1B0768059D; Tue, 2 Jan 2018 10:59:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f68.google.com (mail-pg0-f68.google.com [74.125.83.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6B5D9680399 for ; Tue, 2 Jan 2018 10:59:18 +0200 (EET) Received: by mail-pg0-f68.google.com with SMTP id r2so8725701pgq.13 for ; Tue, 02 Jan 2018 00:59:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=b7176u1YHBbLSCnwLc/1yaPHfwJoWeyVvsDi1JUio18=; b=RP02H8EspSyRvJ2TaWribe0zA5Z7gerk3WYPANvseDwDukxdZmCApezWxZJeU13Dew 52sxuOgv4ZtIC5CQprRQ8k2oZcO6gEtmtTA55W1Id2FAR1aI7xNb5zghvevotfkzuqRw uvPLww6i305pbTUUdixlPcP9L8xullD6bWjHrXf1WSnJ68DqvP/cvVNAwN7MYeefEpUi jTTJn0USIDCl/bFfLkrWhS2Innqx13vx7YUJ2Fa8JbLnRLBZy4TVfugqop7BViiH+Tno k+GuEneW5Lb2B8yzodcuGVTnHdjnqPTPZ2riJ071cuS7Y9MX0rVgFbJt/3QwnvzhBjzX ZAwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=b7176u1YHBbLSCnwLc/1yaPHfwJoWeyVvsDi1JUio18=; b=tOM2vnMFa9OpRNvlr/+1rXEIHm3iDaKYCERRT9bMeeuk7z66dFIFIUPmsLGFrhUthH 16+QkulZbTRSK9AuBNB4iNMicyeAgkGUofw+NVHVBB0+6lciiRJ8xZMbCAB1A5eNx1c/ vsUNz89MXPEIpHHPEQVLqmB6vreKzZyhu0HT25KJ96ea14hdpx6PYiTml5aWyelpFcMj VlC29cNOd74aDCpK0s1WCUpnpDwpFwqHdFUnON3eWQVfvX6QGxJo5ls8idzSC/fHKS5o N0/wqeGRJuCyLFYEWBX80TRSuuBZb3NL7jtNwwLF5q4Hv8Z480m5RickSuuQqJwUrFWQ a2hQ== X-Gm-Message-State: AKGB3mKCr/MqO+0G9qkrtWOhM60pF4pUSrBcAxu1SDNsFYgcPKQFLqVh 7WtAGGc0EHfy7JBlZ/ZXHzIvCA== X-Received: by 10.98.23.68 with SMTP id 65mr43443332pfx.25.1514883572413; Tue, 02 Jan 2018 00:59:32 -0800 (PST) Received: from localhost.localdomain (ec2-52-220-245-83.ap-southeast-1.compute.amazonaws.com. [52.220.245.83]) by smtp.gmail.com with ESMTPSA id b63sm45684066pga.24.2018.01.02.00.59.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Jan 2018 00:59:31 -0800 (PST) From: zhangjiejun1992@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 Jan 2018 16:59:11 +0800 Message-Id: <20180102085911.91909-1-zhangjiejun1992@gmail.com> X-Mailer: git-send-email 2.14.3 (Apple Git-98) In-Reply-To: <20180102075223.65278-1-zhangjiejun1992@gmail.com> References: <20180102075223.65278-1-zhangjiejun1992@gmail.com> Subject: [FFmpeg-devel] [PATCH] lavc/audiotoolboxenc: fix noise in encoded audio 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 Cc: Jiejun Zhang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Jiejun Zhang This fixes #6940 --- libavcodec/audiotoolboxenc.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/libavcodec/audiotoolboxenc.c b/libavcodec/audiotoolboxenc.c index 71885d1530..0c1e5feadc 100644 --- a/libavcodec/audiotoolboxenc.c +++ b/libavcodec/audiotoolboxenc.c @@ -48,6 +48,9 @@ typedef struct ATDecodeContext { AudioFrameQueue afq; int eof; int frame_size; + + uint8_t* audio_data_buf; + uint32_t audio_data_buf_size; } ATDecodeContext; static UInt32 ffat_get_format_id(enum AVCodecID codec, int profile) @@ -442,6 +445,9 @@ static av_cold int ffat_init_encoder(AVCodecContext *avctx) ff_af_queue_init(avctx, &at->afq); + at->audio_data_buf_size = 0; + at->audio_data_buf = NULL; + return 0; } @@ -465,13 +471,27 @@ static OSStatus ffat_encode_callback(AudioConverterRef converter, UInt32 *nb_pac } frame = ff_bufqueue_get(&at->frame_queue); - + int audio_data_size = frame->nb_samples * + av_get_bytes_per_sample(avctx->sample_fmt) * + avctx->channels; + if (at->audio_data_buf_size < audio_data_size) { + av_log(avctx, AV_LOG_INFO, "Increasing audio data buffer size to %d\n", + audio_data_size); + av_free(at->audio_data_buf); + at->audio_data_buf_size = audio_data_size; + at->audio_data_buf = av_malloc(at->audio_data_buf_size); + if (!at->audio_data_buf) { + at->audio_data_buf_size = 0; + data->mNumberBuffers = 0; + *nb_packets = 0; + return AVERROR(ENOMEM); + } + } data->mNumberBuffers = 1; data->mBuffers[0].mNumberChannels = avctx->channels; - data->mBuffers[0].mDataByteSize = frame->nb_samples * - av_get_bytes_per_sample(avctx->sample_fmt) * - avctx->channels; - data->mBuffers[0].mData = frame->data[0]; + data->mBuffers[0].mDataByteSize = audio_data_size; + data->mBuffers[0].mData = at->audio_data_buf; + memcpy(at->audio_data_buf, frame->data[0], data->mBuffers[0].mDataByteSize); if (*nb_packets > frame->nb_samples) *nb_packets = frame->nb_samples; @@ -565,6 +585,10 @@ static av_cold int ffat_close_encoder(AVCodecContext *avctx) ff_bufqueue_discard_all(&at->frame_queue); ff_bufqueue_discard_all(&at->used_frame_queue); ff_af_queue_close(&at->afq); + if (at->audio_data_buf_size > 0) { + at->audio_data_buf_size = 0; + av_free(at->audio_data_buf); + } return 0; }