From patchwork Fri Jul 29 17:36:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Burt P X-Patchwork-Id: 31 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.67 with SMTP id o64csp1467745vsd; Fri, 29 Jul 2016 10:54:21 -0700 (PDT) X-Received: by 10.28.31.147 with SMTP id f141mr2247077wmf.69.1469814861064; Fri, 29 Jul 2016 10:54:21 -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 f197si4473417wmf.73.2016.07.29.10.54.20; Fri, 29 Jul 2016 10:54:21 -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; dkim=neutral (body hash did not verify) header.i=@gmail.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; dmarc=fail (p=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 7BDA1689E33; Fri, 29 Jul 2016 20:54:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f65.google.com (mail-it0-f65.google.com [209.85.214.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CA8BD689E12 for ; Fri, 29 Jul 2016 20:54:05 +0300 (EEST) Received: by mail-it0-f65.google.com with SMTP id d65so7565679ith.0 for ; Fri, 29 Jul 2016 10:54:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=AgRLnJMhM1YNmtuhcuDAdjc2jSiaoPn3fuVOMTIEu3k=; b=V3+KayaI/SAadHY0EwduFuSBtl28ICETQU6BJcJ09xhXzqGmkZdk+pKVahzutuWpnF 6UkLiXiOZSC84S6mukXBeCc5N/szLNx+NzIvC+VqFDfhLI1sVoMLY6Ck5a5z/a1qvlVQ kSKbiOT2Fw4WuR2//pCbO4aWaQs0aMOsJr4T1kmWbxvimPpprwsc2b3+OAM6/57uNs13 n8HyR40+YITy/u7+RkZRtJrMxM5nb7f4Hl3Z0Q14+eNt5b0R925V8zaQi9FViTS+7Kv+ lr1hyk3F58/rI2y+Rx5yeX+uj6h3WX4RVjdvJk6foPZ3K284cgNQr61Widln3BYaebVl jeqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=AgRLnJMhM1YNmtuhcuDAdjc2jSiaoPn3fuVOMTIEu3k=; b=SHPkUHCI6JCKY+gFCNe9nM3ebJwDwfPZQrMYBhCX7VK+3YUHE7Tdb2ci9o2Fr9QpNj Epzxaa5R3wyog7CXNX4OkCm+G4anf8cLprEfCa5XY5NdBouTUHMtmOIGX9WaeVL/QyHh YqvFz2QivHEP5riufroVDtg1A09H6itc9vg8djxAampOtQ2cSeuMOTtsQkHDkbozLmhb yg4ZO/my+grgOVDGS4Z5oVoZMTLpFwWmrBv/CD58ycVcPqGegcQb+2WMghxgeB10Qcsc RrtH/jzF14iNvkcotaBJ86VBYsxJsjbl7F3Ny9Q7prbbte3kABNS2IEg0bpeXVEeHOZ4 dgiQ== X-Gm-Message-State: AEkoouugdBzz3vgCC8IBz2S9D7KGmpqWR59xO4n7xhO+kYUyYLdt5pmaRXh0nGD0FdBtqA== X-Received: by 10.36.135.133 with SMTP id f127mr46406599ite.23.1469813797311; Fri, 29 Jul 2016 10:36:37 -0700 (PDT) Received: from localhost.localdomain ([216.16.66.181]) by smtp.gmail.com with ESMTPSA id u7sm1720954ita.21.2016.07.29.10.36.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Jul 2016 10:36:36 -0700 (PDT) From: Burt P To: ffmpeg-devel@ffmpeg.org Date: Fri, 29 Jul 2016 12:36:18 -0500 Message-Id: <1469813782-13305-4-git-send-email-pburt0@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1469813782-13305-1-git-send-email-pburt0@gmail.com> References: <1469472876-7262-1-git-send-email-pburt0@gmail.com> <1469813782-13305-1-git-send-email-pburt0@gmail.com> Subject: [FFmpeg-devel] [PATCH 3/7] af_hdcd: Improve error detection logging 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" * Moves the filter context member out of state and into HDCDContext * More useful information when an error is detected * Gives a location near where the error was detected Signed-off-by: Burt P --- libavfilter/af_hdcd.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/libavfilter/af_hdcd.c b/libavfilter/af_hdcd.c index 8498b35..6040400 100644 --- a/libavfilter/af_hdcd.c +++ b/libavfilter/af_hdcd.c @@ -849,8 +849,6 @@ typedef struct { /* occurences of code detect timer expiring without detecting * a code. -1 for timer never set. */ int count_sustain_expired; - - AVFilterContext *fctx; /* filter context for logging errors */ } hdcd_state_t; typedef enum { @@ -869,6 +867,9 @@ typedef struct HDCDContext { const AVClass *class; hdcd_state_t state[2]; + AVFilterContext *fctx; /* filter context for logging errors */ + int sample_count; /* used in error logging */ + /* User information/stats */ int hdcd_detected; int det_errors; /* detectable errors */ @@ -923,7 +924,7 @@ static void hdcd_update_info(hdcd_state_t *state) state->max_gain = FFMAX(state->max_gain, (state->control & 15)); } -static int hdcd_integrate(hdcd_state_t *state, int *flag, const int32_t *samples, int count, int stride) +static int hdcd_integrate(HDCDContext *ctx, hdcd_state_t *state, int *flag, const int32_t *samples, int count, int stride) { uint32_t bits = 0; int result = FFMIN(state->readahead, count); @@ -954,8 +955,8 @@ static int hdcd_integrate(hdcd_state_t *state, int *flag, const int32_t *samples } else { /* one of bits 3, 6, or 7 was not 0 */ state->code_counterA_almost++; - av_log(state->fctx, AV_LOG_VERBOSE, - "hdcd error: Control A almost: 0x%08x\n", bits); + av_log(ctx->fctx, AV_LOG_VERBOSE, + "hdcd error: Control A almost: 0x%02x near %d\n", bits & 0xff, ctx->sample_count); } } else if ((bits & 0xa0060000) == 0xa0060000) { /* B: 8-bit code, 8-bit XOR check */ @@ -968,14 +969,14 @@ static int hdcd_integrate(hdcd_state_t *state, int *flag, const int32_t *samples } else { /* XOR check failed */ state->code_counterB_checkfails++; - av_log(state->fctx, AV_LOG_VERBOSE, - "hdcd error: Control B check failed: 0x%08x\n", bits); + av_log(ctx->fctx, AV_LOG_VERBOSE, + "hdcd error: Control B check failed: 0x%04x (0x%02x vs 0x%02x) near %d\n", bits & 0xffff, (bits & 0xff00) >> 8, ~bits & 0xff, ctx->sample_count); } } else { /* told to look for a code, but didn't match one */ state->code_counterC_unmatched++; - av_log(state->fctx, AV_LOG_VERBOSE, - "hdcd error: Unmatched code: 0x%08x\n", bits); + av_log(ctx->fctx, AV_LOG_VERBOSE, + "hdcd error: Unmatched code: 0x%08x near %d\n", bits, ctx->sample_count); } if (*flag) hdcd_update_info(state); state->arg = 0; @@ -1002,7 +1003,7 @@ static void hdcd_sustain_reset(hdcd_state_t *state) state->count_sustain_expired = 0; } -static int hdcd_scan(hdcd_state_t *state, const int32_t *samples, int max, int stride) +static int hdcd_scan(HDCDContext *ctx, hdcd_state_t *state, const int32_t *samples, int max, int stride) { int cdt_active = 0; /* code detect timer */ @@ -1018,7 +1019,7 @@ static int hdcd_scan(hdcd_state_t *state, const int32_t *samples, int max, int s result = 0; while (result < max) { int flag; - int consumed = hdcd_integrate(state, &flag, samples, max - result, stride); + int consumed = hdcd_integrate(ctx, state, &flag, samples, max - result, stride); result += consumed; if (flag > 0) { /* reset timer if code detected in channel */ @@ -1092,7 +1093,7 @@ static int hdcd_envelope(int32_t *samples, int count, int stride, int gain, int return gain; } -static void hdcd_process(hdcd_state_t *state, int32_t *samples, int count, int stride) +static void hdcd_process(HDCDContext *ctx, hdcd_state_t *state, int32_t *samples, int count, int stride) { int32_t *samples_end = samples + count * stride; int gain = state->running_gain; @@ -1105,7 +1106,7 @@ static void hdcd_process(hdcd_state_t *state, int32_t *samples, int count, int s int run; av_assert0(samples + lead * stride + stride * (count - lead) <= samples_end); - run = hdcd_scan(state, samples + lead * stride, count - lead, stride) + lead; + run = hdcd_scan(ctx, state, samples + lead * stride, count - lead, stride) + lead; envelope_run = run - 1; av_assert0(samples + envelope_run * stride <= samples_end); @@ -1160,7 +1161,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) s->det_errors = 0; for (c = 0; c < inlink->channels; c++) { hdcd_state_t *state = &s->state[c]; - hdcd_process(state, out_data + c, in->nb_samples, out->channels); + hdcd_process(s, state, out_data + c, in->nb_samples, out->channels); if (state->sustain) detect++; packets += state->code_counterA + state->code_counterB; pe_packets += state->count_peak_extend; @@ -1181,6 +1182,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) * channels at the same time. */ if (detect == inlink->channels) s->hdcd_detected = 1; + s->sample_count += in->nb_samples * in->channels; + av_frame_free(&in); return ff_filter_frame(outlink, out); } @@ -1273,10 +1276,11 @@ static av_cold int init(AVFilterContext *ctx) int c; s->max_gain_adjustment = 0.0; + s->sample_count = 0; + s->fctx = ctx; for (c = 0; c < 2; c++) { hdcd_reset(&s->state[c], 44100); - s->state[c].fctx = ctx; } return 0;