From patchwork Fri Sep 2 01:59:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Campbell X-Patchwork-Id: 395 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp1214814vsd; Thu, 1 Sep 2016 19:01:08 -0700 (PDT) X-Received: by 10.28.8.137 with SMTP id 131mr603966wmi.38.1472781665793; Thu, 01 Sep 2016 19:01:05 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d7si9050018wjy.157.2016.09.01.19.00.58; Thu, 01 Sep 2016 19:01:05 -0700 (PDT) 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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2B923689CFA; Fri, 2 Sep 2016 05:00:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from p3plsmtpout003.prod.phx3.secureserver.net (p3plsmtpout003.prod.phx3.secureserver.net [208.109.80.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E713C689AD4 for ; Fri, 2 Sep 2016 05:00:42 +0300 (EEST) Received: from ip-192-169-235-64.secureserver.net ([192.169.235.64]) by : HOSTING RELAY : with SMTP id fdljbUt0YM8BZfdljbgJkj; Thu, 01 Sep 2016 18:59:47 -0700 x-originating-ip: 192.169.235.64 Received: from 50-245-141-73-static.hfc.comcastbusiness.net ([50.245.141.73]:44247 helo=[172.19.234.190]) by ip-192-169-235-64.secureserver.net with esmtpsa (TLSv1:DHE-RSA-CAMELLIA256-SHA:256) (Exim 4.82) (envelope-from ) id 1bfdli-0001Lq-WE for ffmpeg-devel@ffmpeg.org; Thu, 01 Sep 2016 18:59:47 -0700 Message-ID: <57C8DD12.7030104@impactstudiopro.com> Date: Thu, 01 Sep 2016 18:59:46 -0700 From: Jonathan Campbell User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org X-CMAE-Envelope: MS4wfOX6dClo2MDuK+uQkKQioUxqzUV9D8MTreOnwdaSU/SMcl3UlZqtIg9NuroxM8NUBFmS8QGCQBglpJJlDSSKrxthR25VNr428Cd6ggq24ChNTmu8R6zo qbqq7dbbB2+dH8ZR/wpNaIGL/YQkuU5i6CEuZo+2ub/WTo4OBHdaiTRWpIaK9HWvW0K6t0/AlVDdxHnf6J4oUSIJNeJ8VDYYfE7+NfpoK3mNlm1mNt6J51db Subject: [FFmpeg-devel] CNG (consistent noise generation) patch for AC-3 decoder 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" I finished the consistent noise generation patch for AC-3 decoding. Set AVOption "cons_noisegen" to 1 (true) to enable it. Git repository: https://github.com/joncampbell123/FFmpeg.git commit dbd086586f0ad1591ea2013293bbb6e4dbfd0455 Author: Jonathan Campbell Date: Thu Sep 1 18:46:16 2016 -0700 AC-3 consistent noise generation: avopt -cons_noisegen When -cons_noisegen 1, the linear feedback generator used for AC-3 dithering is seeded with the contents of the AC-3 frame. Seeding from the AC-3 frame ensures the dithering noise comes out exactly the same when given the same AC-3 frame data, which can then be used by non-linear editing software to reliably decode discontinuous segments of an AC-3 bitstream without gaps or discontinuities. Jonathan Campbell Patch follows, hope Thunderbird doesn't garble it: OFFSET(drc_scale), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 6.0, PAR }, { "heavy_compr", "enable heavy dynamic range compression", OFFSET(heavy_compression), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, PAR }, { "target_level", "target level in -dBFS (0 not applied)", OFFSET(target_level), AV_OPT_TYPE_INT, {.i64 = 0 }, -31, 0, PAR }, diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index fac189b..28048d7 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -1419,6 +1419,19 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, (const uint16_t *) buf, cnt); } else memcpy(s->input_buffer, buf, FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE)); + + /* if consistent noise generation is enabled, seed the linear feedback generator + * with the contents of the AC-3 frame so that the noise is identical across + * decodes given the same AC-3 frame data, for use with non-linear edititing software. */ + if (s->consistent_noise_generation) { + const AVCRC *avcrc = av_crc_get_table(AV_CRC_32_IEEE); + + if (avcrc != NULL) + av_lfg_init(&s->dith_state, av_crc(avcrc, 0, s->input_buffer, FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE))); + else + av_log(avctx, AV_LOG_ERROR, "CNG unable to seed from frame"); + } + buf = s->input_buffer; /* initialize the GetBitContext with the start of valid AC-3 Frame */ if ((ret = init_get_bits8(&s->gbc, buf, buf_size)) < 0) diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h index c2b867e..98184e9 100644 --- a/libavcodec/ac3dec.h +++ b/libavcodec/ac3dec.h @@ -177,6 +177,10 @@ typedef struct AC3DecodeContext { int end_freq[AC3_MAX_CHANNELS]; ///< end frequency bin (endmant) ///@} +///@name Consistent noise generation + int consistent_noise_generation; ///< seed noise generation with AC-3 frame on decode +///@} + ///@name Rematrixing int num_rematrixing_bands; ///< number of rematrixing bands (nrematbnd) int rematrixing_flags[4]; ///< rematrixing flags (rematflg) diff --git a/libavcodec/ac3dec_fixed.c b/libavcodec/ac3dec_fixed.c index 6416da4..1f79ade 100644 --- a/libavcodec/ac3dec_fixed.c +++ b/libavcodec/ac3dec_fixed.c @@ -168,6 +168,7 @@ static void ac3_downmix_c_fixed16(int16_t **samples, int16_t (*matrix)[2], #include "ac3dec.c" static const AVOption options[] = { + { "cons_noisegen", "enable consistent noise generation", OFFSET(consistent_noise_generation), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, PAR }, { "drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 6.0, PAR }, { "heavy_compr", "enable heavy dynamic range compression", OFFSET(heavy_compression), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, PAR }, { NULL}, diff --git a/libavcodec/ac3dec_float.c b/libavcodec/ac3dec_float.c index 0a5319a..b85a4ce 100644 --- a/libavcodec/ac3dec_float.c +++ b/libavcodec/ac3dec_float.c @@ -32,6 +32,7 @@ #include "ac3dec.c" static const AVOption options[] = { + { "cons_noisegen", "enable consistent noise generation", OFFSET(consistent_noise_generation), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, PAR }, { "drc_scale", "percentage of dynamic range compression to apply",