From patchwork Fri Feb 3 22:42:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chcunningham@chromium.org X-Patchwork-Id: 2419 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp849033vsb; Fri, 3 Feb 2017 14:51:43 -0800 (PST) X-Received: by 10.223.165.17 with SMTP id i17mr16786638wrb.62.1486162303146; Fri, 03 Feb 2017 14:51:43 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x81si3545461wmb.43.2017.02.03.14.51.42; Fri, 03 Feb 2017 14:51:43 -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=@chromium.org; 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 sp=NONE dis=NONE) header.from=chromium.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BD385687EB1; Sat, 4 Feb 2017 00:51:38 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f42.google.com (mail-pg0-f42.google.com [74.125.83.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8A393680AB6 for ; Sat, 4 Feb 2017 00:51:32 +0200 (EET) Received: by mail-pg0-f42.google.com with SMTP id 14so10108806pgg.1 for ; Fri, 03 Feb 2017 14:51:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6pSawia5eqxDvoqy7NDleIhpeM7Sr0pAP/lOSisEcqQ=; b=KTAI5ze7EO0qkiW6BB3eqGTo1+zzdLxn1wgXQHjJ6c+TYnsRG4Gk0ie4ozWWoExi35 Ed5W0FurV0Yh3jIM/oWRq4EkHapWCEQBBJ2g8isiJ9Kw462+AGhfFtG/esdwW60xjQVg cNbr9LSJ4J6ug9HNnm6SybEXBoHMzOZWxEHn0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6pSawia5eqxDvoqy7NDleIhpeM7Sr0pAP/lOSisEcqQ=; b=JQZhiH07V8u5UNiWMQ/0u6pZWR/yVO3tFD5G6V8jP7gSKTymWjRUe+75fOplRLFbYY ZmfBT77HnYDNidSf6tOSp4NIeXA4Xkq0/aD7VNVKo8VWBA0CeScN7D+fONL2AIAb8IE4 XnZDvCqJxvdoh+ObSxYQKaLSf88mBM51HWys0rQW8/AdCyakqfxABbjjMT/3w+nAL/iK PztWt52kRkSkxcEXJfS68cg2BPBeJ87bxwE0BuSelEWe2rBNb0UtqKYTHVE/Q5VdPFRR rx/jDwGtaLmh/K1zJ01gxTDvLhVaLMlf1UpHiQqBRYEMnUltsLZl7Spm9dBSvs49Lj3K lBPA== X-Gm-Message-State: AIkVDXIp00TpKLDqA7IYtr4rTWAaqgsgdYRzjOgNHfrSA4o0OpjvOYWeq7Z9lHEz64PYF3jG X-Received: by 10.99.65.67 with SMTP id o64mr20749095pga.119.1486161794898; Fri, 03 Feb 2017 14:43:14 -0800 (PST) Received: from chcunningham-linux.sea.corp.google.com ([172.31.70.190]) by smtp.gmail.com with ESMTPSA id i82sm69591429pfk.52.2017.02.03.14.43.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Feb 2017 14:43:14 -0800 (PST) From: Chris Cunningham To: ffmpeg-devel@ffmpeg.org Date: Fri, 3 Feb 2017 14:42:44 -0800 Message-Id: <20170203224244.30066-1-chcunningham@chromium.org> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog In-Reply-To: <20170203202317.224ebe82@debian> References: <20170203202317.224ebe82@debian> Subject: [FFmpeg-devel] [PATCH] lavf/matroskadec: fix is_keyframe for early Blocks 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: Chris Cunningham MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Blocks are marked as key frames whenever the "reference" field is zero. This breaks for non-keyframe Blocks with a reference timestamp of zero. The likelihood of reference timestamp being zero is increased by a longstanding bug in muxing that encodes reference timestamp as the absolute time of the referenced frame (rather than relative to the current Block timestamp, as described in MKV spec). Now using INT64_MIN to denote "no reference". Reported to chromium at http://crbug.com/497889 (contains sample) --- libavformat/matroskadec.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index e6737a70b2..7223e94b55 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -89,6 +89,7 @@ typedef const struct EbmlSyntax { int list_elem_size; int data_offset; union { + int64_t i; uint64_t u; double f; const char *s; @@ -696,7 +697,7 @@ static const EbmlSyntax matroska_blockgroup[] = { { MATROSKA_ID_SIMPLEBLOCK, EBML_BIN, 0, offsetof(MatroskaBlock, bin) }, { MATROSKA_ID_BLOCKDURATION, EBML_UINT, 0, offsetof(MatroskaBlock, duration) }, { MATROSKA_ID_DISCARDPADDING, EBML_SINT, 0, offsetof(MatroskaBlock, discard_padding) }, - { MATROSKA_ID_BLOCKREFERENCE, EBML_SINT, 0, offsetof(MatroskaBlock, reference) }, + { MATROSKA_ID_BLOCKREFERENCE, EBML_SINT, 0, offsetof(MatroskaBlock, reference), { .i = INT64_MIN } }, { MATROSKA_ID_CODECSTATE, EBML_NONE }, { 1, EBML_UINT, 0, offsetof(MatroskaBlock, non_simple), { .u = 1 } }, { 0 } @@ -1071,6 +1072,9 @@ static int ebml_parse_nest(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, for (i = 0; syntax[i].id; i++) switch (syntax[i].type) { + case EBML_SINT: + *(int64_t *) ((char *) data + syntax[i].data_offset) = syntax[i].def.i; + break; case EBML_UINT: *(uint64_t *) ((char *) data + syntax[i].data_offset) = syntax[i].def.u; break; @@ -3361,7 +3365,7 @@ static int matroska_parse_cluster_incremental(MatroskaDemuxContext *matroska) matroska->current_cluster_num_blocks = blocks_list->nb_elem; i = blocks_list->nb_elem - 1; if (blocks[i].bin.size > 0 && blocks[i].bin.data) { - int is_keyframe = blocks[i].non_simple ? !blocks[i].reference : -1; + int is_keyframe = blocks[i].non_simple ? blocks[i].reference == INT64_MIN : -1; uint8_t* additional = blocks[i].additional.size > 0 ? blocks[i].additional.data : NULL; if (!blocks[i].non_simple) @@ -3399,7 +3403,7 @@ static int matroska_parse_cluster(MatroskaDemuxContext *matroska) blocks = blocks_list->elem; for (i = 0; i < blocks_list->nb_elem; i++) if (blocks[i].bin.size > 0 && blocks[i].bin.data) { - int is_keyframe = blocks[i].non_simple ? !blocks[i].reference : -1; + int is_keyframe = blocks[i].non_simple ? blocks[i].reference == INT64_MIN : -1; res = matroska_parse_block(matroska, blocks[i].bin.data, blocks[i].bin.size, blocks[i].bin.pos, cluster.timecode, blocks[i].duration,