From patchwork Wed Mar 10 16:07:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Buitenhuis X-Patchwork-Id: 26309 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id C99604493A3 for ; Wed, 10 Mar 2021 18:08:18 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A723A687F21; Wed, 10 Mar 2021 18:08:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D6F16687F3D for ; Wed, 10 Mar 2021 18:08:12 +0200 (EET) Received: by mail-wr1-f50.google.com with SMTP id j2so23920135wrx.9 for ; Wed, 10 Mar 2021 08:08:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=BXPODaKjL0pF2orK29bgirvZR9WtteadxNrSxDCH6fM=; b=jsKa6qarMBesj1kEvyY/yo2PqaBhzBRTTDaeeM3x88tYZPC/iSOcvJ6YaNdgXdfgsP u/S/Lqth2efgFsgdxdXoB4JmSFQD6tSfBu7VCazXdWdR7jlQrHGK6DuW8zVM8g6C0hW7 bz0TXnKBNJGzP5OtIrKyJqc6XhdG+nwSmOU3HTsHOJCXq+kre5UAbJkVX93L7aC0LvDw aEH771C6G7bOLgZNb4myqDLxYSgHTAcTYBx8QMRfumvJbcVsoHDcp04Wd9cfUv84ykIQ diLF/Ea1vMRLgUi0kbCgnKxWJl+XbO9RyzIJF5QDiloS9j4mPlURao6uCfUh1UBGfOnI seFQ== 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:mime-version :content-transfer-encoding; bh=BXPODaKjL0pF2orK29bgirvZR9WtteadxNrSxDCH6fM=; b=K6IVRyctonlWmHtnYWIR4biJqoUJNPnW4QgRXOwbiHlD3L9B8L9UTP1qdpLZ30HMO7 1rR7m0EWcv5znxCeMCp2BXfH+sqr7C/SeMtgGpFdQ1hihc/P00ipe2xC4Hn8+fIAF5ep P19mfzmmENZrI9fgJL7pXyB4bcWTTR0GiDmdL9UA5Pdk/4V+9mmrJvISGfqxIPImZkTJ A6jPaWQXaXld6uPqkIr6k3VOvoiNG1CmGhAzP9UniuKQZbNLlJzEybo/TCfC2sO6CU9q xwwaCANPTe+PG6cLV3MrzBLfn+Cub1smNxCKopWH7lazlKJEgFjlinzZLkCYtcAKYQSi cEXA== X-Gm-Message-State: AOAM531mKg5scVuKAnuHw9VUrOSjGYHRkFYTS84+Vyn7/KHkBTEFUdjU xO1nPhuRcY0+6lhwWThDmYOIH3OGB0w= X-Google-Smtp-Source: ABdhPJwGrWdCP3BXu/ClYVpJzEqN4b7oo17zDzAegtt8Gj/DjVX4a9TpBDQCS8QCTEUOfOyksEuWXA== X-Received: by 2002:adf:8341:: with SMTP id 59mr4157773wrd.130.1615392491916; Wed, 10 Mar 2021 08:08:11 -0800 (PST) Received: from localhost.localdomain ([82.129.110.36]) by smtp.gmail.com with ESMTPSA id h20sm7311wmb.1.2021.03.10.08.08.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 08:08:11 -0800 (PST) From: Derek Buitenhuis To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 16:07:57 +0000 Message-Id: <20210310160757.59501-1-derek.buitenhuis@gmail.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mov: Properly consider if the file is self-initializing when marking sidx reading complete 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: dalecurtis@chromium.org, tfoucu@gmail.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Files with the "dash" major brand are guaranteed to only have a single initialization range for the whole file. We can check this and stop appropriately - which is useful, as the existing check to see if the offset reaches the end of the file is not sufficient. For example, YouTube creates valid self-initializing ISOBMFF files that contain a single 'uuid' box appended at the end, after the last 'moof', and this check does not catch that, which causes, for example, probing to traverse the entire file (every single 'moof'), which is extremely slow over a network, which is the main place these self-initializing fragmented ISOBMFF files would be used. This is the same behavior that was addressed in 2ff3c466eca66bb8eb32bb41a4ce70fe285e3ea0 for live-style fragmented files. Signed-off-by: Derek Buitenhuis --- libavformat/mov.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 1c07cff6b5..67eae24e02 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -5052,6 +5052,7 @@ static int mov_read_sidx(MOVContext *c, AVIOContext *pb, MOVAtom atom) AVStream *ref_st = NULL; MOVStreamContext *sc, *ref_sc = NULL; AVRational timescale; + AVDictionaryEntry *major_brand = av_dict_get(c->fc->metadata, "major_brand", NULL, AV_DICT_MATCH_CASE); version = avio_r8(pb); if (version > 1) { @@ -5120,7 +5121,11 @@ static int mov_read_sidx(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc->has_sidx = 1; // See if the remaining bytes are just an mfra which we can ignore. - is_complete = offset == stream_size; + // + // Also check to see if the file is Self-initializing, which guarantees + // only a single initialization range is present for the whole file. + // See: ISO-IEC 23009-1 Section 6.3.5. + is_complete = offset == stream_size || (major_brand && !strncmp(major_brand->value, "dash", 4)); if (!is_complete && (pb->seekable & AVIO_SEEKABLE_NORMAL)) { int64_t ret; int64_t original_pos = avio_tell(pb);