From patchwork Sat Sep 10 05:31:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodger Combs X-Patchwork-Id: 521 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp644563vsd; Fri, 9 Sep 2016 22:31:32 -0700 (PDT) X-Received: by 10.28.157.139 with SMTP id g133mr1314292wme.82.1473485492676; Fri, 09 Sep 2016 22:31:32 -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 ts16si6096318wjb.163.2016.09.09.22.31.29; Fri, 09 Sep 2016 22:31:32 -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 33FD6689ED5; Sat, 10 Sep 2016 08:31:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi0-f67.google.com (mail-oi0-f67.google.com [209.85.218.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B8FF6689DC6 for ; Sat, 10 Sep 2016 08:31:09 +0300 (EEST) Received: by mail-oi0-f67.google.com with SMTP id s71so10384190oih.3 for ; Fri, 09 Sep 2016 22:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=za73V3Uor5yedqbrAft1o5EeccyaSX4SbDXb2P1gQXY=; b=t/2RRwIdRDOGZYivGzggWwpjtD9dZ8Fh6PJIDcUwu7eil5UipqSKAwL/AarsRJMYl4 UX7u0K/Lg0MEdMaDVRlxAAlfRntKS+dxpqu0n0RnHrrB8KeRg54F+oNBI0UJzPKwHS6N 41ZSRsHddLfmY2avwxKviA6bT36gD8nRfpd0It5qZFkjg6DauHzsfFebby1bI6D/mjzY n4jVwge0kncD44pulXMyrkk6B2/k+S9CnoAYtvxqm7Wzam9sFNPnAv+pFh6M3aSA7Wr4 /UpJa3FP2bJ4KqMwD4j3xH+aYxJU3yWVOn1gOpIRtXm6J+63cb+xZQGkbP4Te+a+Jm/q 1K6g== 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; bh=za73V3Uor5yedqbrAft1o5EeccyaSX4SbDXb2P1gQXY=; b=e47M0gWbQE/xOJY3ERREeKpmLy81utWjVRntxsu77xQLYT3PERv7cSv8K/1QanCjEc 90Ad1l/PK2GtuNwD8x3uU+rXQ4v8xQNSNgRa71EY11oVEHpTIQGWdFcqxPHhvzZFcRom DE/SnUIRfyCJafxYM4e//bCIrC/R2kNRgk08awCBVb11f1CnMGej6nW/g6NE6nnjFDMr tpIkOVaSFQcUjuP85ouTs5jkJ9kzMCR2GQF6BocaB07lQlQWivAsH76B9AqAFlICWBXA SHF74qugc+1PszzUCnzAnFPNekxX9uMmSp5MYf9CMv+9dbAyf8+1Wx1Pb44VGJx4OK10 syhQ== X-Gm-Message-State: AE9vXwNqBVcem2vpGmpXxDTodGU/hYCu8eAXgYB/PbMCgIUfKzqwlBom4/KwIs8+NdTFgA== X-Received: by 10.202.76.7 with SMTP id z7mr1806339oia.56.1473485479035; Fri, 09 Sep 2016 22:31:19 -0700 (PDT) Received: from Rodgers-MacBook-Pro.local.net (c-73-209-137-129.hsd1.il.comcast.net. [73.209.137.129]) by smtp.gmail.com with ESMTPSA id c72sm3736291itd.19.2016.09.09.22.31.17 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 09 Sep 2016 22:31:17 -0700 (PDT) From: Rodger Combs To: ffmpeg-devel@ffmpeg.org Date: Sat, 10 Sep 2016 00:31:12 -0500 Message-Id: <20160910053113.99251-1-rodger.combs@gmail.com> X-Mailer: git-send-email 2.10.0 Subject: [FFmpeg-devel] [PATCH 1/2] ass_split: fix handling of streams with no [Events] or Format: line 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" --- libavcodec/ass_split.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/libavcodec/ass_split.c b/libavcodec/ass_split.c index beaba7e..cdb1aa2 100644 --- a/libavcodec/ass_split.c +++ b/libavcodec/ass_split.c @@ -229,7 +229,7 @@ static inline const char *skip_space(const char *buf) return buf; } -static int *get_default_field_orders(const ASSSection *section) +static int *get_default_field_orders(const ASSSection *section, int *number) { int i; int *order = av_malloc_array(FF_ARRAY_ELEMS(section->fields), sizeof(*order)); @@ -238,8 +238,9 @@ static int *get_default_field_orders(const ASSSection *section) return NULL; for (i = 0; section->fields[i].name; i++) order[i] = i; + *number = i; while (i < FF_ARRAY_ELEMS(section->fields)) - order[i] = -1; + order[i++] = -1; return order; } @@ -255,12 +256,26 @@ static const char *ass_split_section(ASSSplitContext *ctx, const char *buf) ctx->current_section = -1; break; } - if (buf[0] == ';' || (buf[0] == '!' && buf[1] == ':')) { - /* skip comments */ - } else if (section->format_header && !order) { + if (buf[0] == ';' || (buf[0] == '!' && buf[1] == ':')) + goto next_line; // skip comments + + len = strcspn(buf, ":\r\n"); + if (buf[len] == ':' && + (!section->fields_header || strncmp(buf, section->fields_header, len))) { + for (i = 0; i < FF_ARRAY_ELEMS(ass_sections); i++) { + if (ass_sections[i].fields_header && + !strncmp(buf, ass_sections[i].fields_header, len)) { + ctx->current_section = i; + section = &ass_sections[ctx->current_section]; + number = &ctx->field_number[ctx->current_section]; + order = ctx->field_order[ctx->current_section]; + break; + } + } + } + if (section->format_header && !order) { len = strlen(section->format_header); - if (strncmp(buf, section->format_header, len) || buf[len] != ':') - goto next_line; + if (buf[len] == ':' && !strncmp(buf, section->format_header, len)) { buf += len + 1; while (!is_eol(*buf)) { buf = skip_space(buf); @@ -278,7 +293,10 @@ static const char *ass_split_section(ASSSplitContext *ctx, const char *buf) buf = skip_space(buf + len + (buf[len] == ',')); } ctx->field_order[ctx->current_section] = order; - } else if (section->fields_header) { + goto next_line; + } + } + if (section->fields_header) { len = strlen(section->fields_header); if (!strncmp(buf, section->fields_header, len) && buf[len] == ':') { uint8_t *ptr, *struct_ptr = realloc_section_array(ctx); @@ -286,7 +304,7 @@ static const char *ass_split_section(ASSSplitContext *ctx, const char *buf) /* No format header line found so far, assume default */ if (!order) { - order = get_default_field_orders(section); + order = get_default_field_orders(section, number); if (!order) return NULL; ctx->field_order[ctx->current_section] = order;