From patchwork Mon Feb 12 09:48:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaullier Nicolas X-Patchwork-Id: 7566 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.1 with SMTP id c1csp3792160jai; Mon, 12 Feb 2018 01:49:12 -0800 (PST) X-Google-Smtp-Source: AH8x225rKsJqVbvFd7YMPbRe68ZRS6m+mHzdCAeSjc03UC4iF/bc1LJPYImHVHgbt8UKbjGYcHOd X-Received: by 10.223.175.235 with SMTP id y43mr393623wrd.41.1518428952047; Mon, 12 Feb 2018 01:49:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518428952; cv=none; d=google.com; s=arc-20160816; b=X7ddE5q+f59OMHScm5adKkYsJCAm3UTySWMLNO9gD4gpxzTqimiJAIyKdqhU7XxGOq 8bdPCMyWk8Jqz69idfEE9se9oRnYHle2sZE3jFSliJ9bA1uuydi5X8+m7TbC4yMPasls SNsGVSAfNuisISNOu9z1mbyRoW4scQC78FaPcgCMqBAgsc6q9w69CPsrDrOahrLC5x2e Nilypg2zG9+TihZ/nUUPjqzaUnjUMdCyihHLZV7FGD9wZawv/5SFxYWZGLltp+9Jxtnb 8MKRG60j+1/pWzxMaHv3oscLVR5C3suHieVeN5xG2wKH4JH43+yvkSculEt66WoBzqet 96Ng== 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=JqnjCCYNgnhFJcCtb0g5WQH5HSKUgGDuth45PTho63k=; b=gXhSmvNeaEs0pADGyNzeDsFXElREcB3XeNhXiPgcaCl2wgl4CWYBZvqEx3GR3GPuzr 977zh83R5x8gsi55bUmcRzy5Nj0RibLG5i5BrZAjvDdfaNGyiEB40+4nZI4HowznF4Fw jvgdZmYu7tyMd5sA+mIZ/Flv9Cx1Eyl8loXBrM7tWtKy8xI5cSDk1RawQX9Rl8KIbJP0 wUo2eyDfgj0rmCJLQouNrnSfqBL/mYcDmgb7jKhVtTISMqEd9Y73Wvhd8P+1tvY5R4no g1t+6Eo2ekvglus70cPV/IeE/zH5RtEHZUr3bTnRnzC2F42MHaY9NVFEpsY0OhfRNbsG sQ1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@arkena.com header.s=20150421 header.b=h0XlDuYo; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r3si6435462wre.246.2018.02.12.01.49.11; Mon, 12 Feb 2018 01:49:12 -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=@arkena.com header.s=20150421 header.b=h0XlDuYo; 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 364DF689A96; Mon, 12 Feb 2018 11:48:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp-1.arkena.net (smtp-1.arkena.net [95.81.173.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 46F006899DC for ; Mon, 12 Feb 2018 11:48:26 +0200 (EET) Received: from secu2 (unknown [10.180.103.10]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-1.arkena.net (Postfix) with ESMTPSA id 3zg1836tqFzMcXP; Mon, 12 Feb 2018 09:48:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arkena.com; s=20150421; t=1518428915; bh=RDJE8m6IOsrxnBypE3X4DTmS9lWCWvwi93F+/i0m2ag=; h=From:To:Cc:Subject:Date:Message-Id; b=h0XlDuYoQKOtUTqZILqYDLkPDLiXEi7Gx9ORMz5x2x3hxyHGcGllNnDImNPa1ecHs NnIeBE+rZV/ksrrHiahLSldFgG+vBHKHjBGXC3IjF1ue9FLlPpF43Gagw+asUq+noO MZj4IbJTgfyU6hHVLZjiOnjOhyDW8/EvepxkbZeI= Received: from arkena.com (unknown [172.16.3.159]) by secu2 (Postfix) with ESMTP id 35E653FA74; Mon, 12 Feb 2018 12:39:29 +0100 (CET) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Feb 2018 10:48:24 +0100 Message-Id: <20180212094830.9304-2-nicolas.gaullier@arkena.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20180212094830.9304-1-nicolas.gaullier@arkena.com> References: <20180212094830.9304-1-nicolas.gaullier@arkena.com> Subject: [FFmpeg-devel] [PATCH v2 2/8] avfilter/silencedetect: fix when silence_start=0 0 is a valid value for silence_start 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: nicolas gaullier MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: nicolas gaullier --- libavfilter/af_silencedetect.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libavfilter/af_silencedetect.c b/libavfilter/af_silencedetect.c index c53b9d9218..b4184c2486 100644 --- a/libavfilter/af_silencedetect.c +++ b/libavfilter/af_silencedetect.c @@ -39,7 +39,7 @@ typedef struct SilenceDetectContext { int mono; ///< mono mode : check each channel separately (default = check when ALL channels are silent) int independant_channels; ///< number of entries in following arrays (always 1 in mono mode) int64_t *nb_null_samples; ///< (array) current number of continuous zero samples - int64_t *start; ///< (array) if silence is detected, this value contains the time of the first zero sample + int64_t *start; ///< (array) if silence is detected, this value contains the time of the first zero sample (default/unset = INT64_MIN) int last_sample_rate; ///< last sample rate to check for sample rate changes void (*silencedetect)(struct SilenceDetectContext *s, AVFrame *insamples, @@ -76,7 +76,7 @@ static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples, { int channel = current_sample % s->independant_channels; if (is_silence) { - if (!s->start[channel]) { + if (s->start[channel] == INT64_MIN) { s->nb_null_samples[channel]++; if (s->nb_null_samples[channel] >= nb_samples_notify) { s->start[channel] = insamples->pts - (int64_t)(s->duration / av_q2d(time_base) + .5); @@ -89,7 +89,7 @@ static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples, } } } else { - if (s->start[channel]) { + if (s->start[channel] > INT64_MIN) { int64_t end_pts = insamples->pts; int64_t duration_ts = end_pts - s->start[channel]; set_meta(insamples, s->mono ? channel + 1 : 0, "silence_end", @@ -102,7 +102,8 @@ static av_always_inline void update(SilenceDetectContext *s, AVFrame *insamples, av_ts2timestr(end_pts, &time_base), av_ts2timestr(duration_ts, &time_base)); } - s->nb_null_samples[channel] = s->start[channel] = 0; + s->nb_null_samples[channel] = 0; + s->start[channel] = INT64_MIN; } } @@ -129,14 +130,17 @@ static int config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; SilenceDetectContext *s = ctx->priv; + int c; s->independant_channels = s->mono ? inlink->channels : 1; s->nb_null_samples = av_mallocz_array(sizeof(*s->nb_null_samples), s->independant_channels); if (!s->nb_null_samples) return AVERROR(ENOMEM); - s->start = av_mallocz_array(sizeof(*s->start), s->independant_channels); + s->start = av_malloc_array(sizeof(*s->start), s->independant_channels); if (!s->start) return AVERROR(ENOMEM); + for (c = 0; c < s->independant_channels; c++) + s->start[c] = INT64_MIN; switch (inlink->format) { case AV_SAMPLE_FMT_DBL: s->silencedetect = silencedetect_dbl; break;