From patchwork Tue Jun 13 13:09:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 3963 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.22.4 with SMTP id 4csp338902vsw; Tue, 13 Jun 2017 06:10:11 -0700 (PDT) X-Received: by 10.28.191.26 with SMTP id p26mr2702614wmf.89.1497359410955; Tue, 13 Jun 2017 06:10:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497359410; cv=none; d=google.com; s=arc-20160816; b=or+EAe3kBz+TryyCYnD0hQSQVvgLbjh86xhEF1oOvSOm1T398rTA26cPBnNVcl97xV IYp7Zd8l9YNpznErql1qzL+5Y9yInnXImUWoSf+/SyOF+5B8hH2jwqCqFRr/M+r8L3R3 jAO7KZsOUNuY5OnTDVhggFzXptz+0omPCGyiPleevV+OK+/uOKPVNVFr5JgEqIlENqdY gFPRTWwOKp+jtAzy0U2p7NpHcFs7lk3NL1Zx1HbiCoHhGFXidravnhNO7TRBRbeRNU1x 3Lm8jBvo/RtSpq44Lxeep12AEL5JTIXun+VA5f7yHFmsrx1/w93VAmekucE7wBDcYOeo WTxQ== 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:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=yZwZpx99WjWBRlEu+8IDdqHztOkcFROxhP4cV2s0/tU=; b=sGA7Xv0eLFRsXRN4Id071yy9gKZI7MHt04y4UfHAmgd9lH/2i5hTPvRZjBlCdMoB+d cccHMMUrhxEk2ynjqr6S70kVXXhxQwu/t5RC1UNU+xau01oESrk8ILMhkJLoiiW/pHJY 8Y1xXfySIMIR9FJJ6cpS35my7nppT2JHt78Gb5Z7ssBVO3/sPdtqmwWXQUe/zHLOCFvW mi+YcUx/t5RHALJRzNgC8YsPYTnaVqR3TykbeFeEgycKtHecE0lLv0F7I15LBfF7h4MN hUzLtUXsNh+DZg3mgdTMlsUP3Bp8TYnsv51EzJkfRo4uyNBU6xnrRkZhfN/hl/ili6eo 30Mw== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b204si7920935wme.32.2017.06.13.06.10.10; Tue, 13 Jun 2017 06:10:10 -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 4655B68A17E; Tue, 13 Jun 2017 16:10:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-1.mx.upcmail.net (vie01a-dmta-pe08-1.mx.upcmail.net [84.116.36.20]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D5FC268A16A for ; Tue, 13 Jun 2017 16:09:59 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe08.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dKla5-0003nf-LF for ffmpeg-devel@ffmpeg.org; Tue, 13 Jun 2017 15:10:01 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id YD9u1v01C0S5wYM01D9vui; Tue, 13 Jun 2017 15:09:55 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 13 Jun 2017 15:09:54 +0200 Message-Id: <20170613130954.11348-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.13.0 Subject: [FFmpeg-devel] [PATCH] avcodec/htmlsubtitles: drop an state 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" Simplifies code but changes handling of multiple an tags Suggested-by: wm4 Signed-off-by: Michael Niedermayer --- libavcodec/htmlsubtitles.c | 11 +++++------ tests/ref/fate/sub-srt | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/libavcodec/htmlsubtitles.c b/libavcodec/htmlsubtitles.c index be5c9316ca..8bea867051 100644 --- a/libavcodec/htmlsubtitles.c +++ b/libavcodec/htmlsubtitles.c @@ -53,15 +53,14 @@ static void rstrip_spaces_buf(AVBPrint *buf) /* skip all {\xxx} substrings except for {\an%d} and all microdvd like styles such as {Y:xxx} */ -static void handle_open_brace(AVBPrint *dst, const char **inp, int *an, int *closing_brace_missing) +static void handle_open_brace(AVBPrint *dst, const char **inp, int *closing_brace_missing) { int len = 0; const char *in = *inp; - - *an += sscanf(in, "{\\an%*1u}%n", &len) >= 0 && len > 0; + int an = sscanf(in, "{\\an%*1u}%n", &len) >= 0 && len > 0; if (!*closing_brace_missing) { - if ( (*an != 1 && in[1] == '\\') + if ( (!an && in[1] == '\\') || (in[1] && strchr("CcFfoPSsYy", in[1]) && in[2] == ':')) { char *bracep = strchr(in+2, '}'); if (bracep) { @@ -78,7 +77,7 @@ static void handle_open_brace(AVBPrint *dst, const char **inp, int *an, int *clo int ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in) { char *param, buffer[128], tmp[128]; - int len, tag_close, sptr = 1, line_start = 1, an = 0, end = 0; + int len, tag_close, sptr = 1, line_start = 1, end = 0; SrtStack stack[16]; int closing_brace_missing = 0; @@ -105,7 +104,7 @@ int ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in) av_bprint_chars(dst, *in, 1); break; case '{': - handle_open_brace(dst, &in, &an, &closing_brace_missing); + handle_open_brace(dst, &in, &closing_brace_missing); break; case '<': tag_close = in[1] == '/'; diff --git a/tests/ref/fate/sub-srt b/tests/ref/fate/sub-srt index 40b20cde90..c64f46864c 100644 --- a/tests/ref/fate/sub-srt +++ b/tests/ref/fate/sub-srt @@ -24,7 +24,7 @@ Dialogue: 0,0:00:22.50,0:00:24.50,Default,,0,0,0,,Implementation is the same of Dialogue: 0,0:00:22.50,0:00:24.50,Default,,0,0,0,,{\an5}This text should be at the\Nmiddle and horizontally centered Dialogue: 0,0:00:22.50,0:00:24.50,Default,,0,0,0,,{\an2}This text should be at the\Nbottom and horizontally centered Dialogue: 0,0:00:24.50,0:00:26.50,Default,,0,0,0,,This text should be at the\Ntop and horizontally at the left{\an7} -Dialogue: 0,0:00:24.50,0:00:26.50,Default,,0,0,0,,{\an4}This text should be at the\Nmiddle and horizontally at the left\N(The second position must be ignored) +Dialogue: 0,0:00:24.50,0:00:26.50,Default,,0,0,0,,{\an4}This text should be at the\Nmiddle and horiz{\an6}ontally at the left\N(The second position must be ignored) Dialogue: 0,0:00:24.50,0:00:26.50,Default,,0,0,0,,{\an1}This text should be at the\Nbottom and horizontally at the left Dialogue: 0,0:00:26.50,0:00:28.50,Default,,0,0,0,,{\an9}This text should be at the\Ntop and horizontally at the right Dialogue: 0,0:00:26.50,0:00:28.50,Default,,0,0,0,,{\an6}This text should be at the\Nmiddle and horizontally at the right