From patchwork Wed Oct 24 12:50:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Ryan X-Patchwork-Id: 10767 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 DFB1344B2C8 for ; Wed, 24 Oct 2018 15:56:52 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5424768A5FF; Wed, 24 Oct 2018 15:56:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EFE3068A1BF for ; Wed, 24 Oct 2018 15:56:17 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id w186-v6so5284763wmf.0 for ; Wed, 24 Oct 2018 05:56:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=avRDoszk0dV+gm5iuIQj8aCh7WoPVHzHw2iANnO/cZY=; b=AFCcL+Yp9DfI8Tzxs7lsAge2D+23JiCc3V+4wKqrp1qSOsgDLwkJSyNHPgfBRvi8GD Mxw0R/qq1YpC1GIcicVy4/9vy0RT1pJa9Hz8XPBMyE1TR81/EYNe7Gsj78Vw+t3/KrvD GDGYINsbHc/0+dvwl1zkhvNQSSQULz/EMFO8UY/6K+2/67pnMrkK+Ukf964GRctwiHgg 1ibTZPrh4i17oz9KK9dtXuz3kGb2U6O2XW4tcqlYdWWInRihmJnchiT4bfU+e226xQqm Gy4zmknheBT53NklkfkW+oFCD+Y6cNGZ1go1wHLHtzAUYtb+OhBDikQBxiRLMrAhiZ6q Z5TQ== 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=avRDoszk0dV+gm5iuIQj8aCh7WoPVHzHw2iANnO/cZY=; b=Ie9fv3FNg+xtLoNx6TTogonw1mjjGY8Uwg1UcVpfMutEfLdkB4niY1jNA0s44IvvfB v7wVywfATmufi6+Nw5VMxLc/pKSthHqne9D/6Kdvvdr9Yv8mgu3s35wqLb/ZdhmZ4R2F 89pGtZ5yT522rrtV5b0r1DuIRmQ8BoA1HlwWVovEAF9ZrmyEZxBbrfYoWvz9LiYC1etF 54YZ17GOzbqYhDCgySHS3Slk1iWPgbFAqFG9KlRn6WtC8HWFyxHbcrNg89z9yPicMIwF afmp6/thvzB4/4I2/AL3maCyKiRENb2cdZNkG1VAvtUsMM2BH7oaiznC2NKcKwB9t4tx gmAg== X-Gm-Message-State: AGRZ1gJ6WcujGx4rU5ee/wV2lURYQ7aCMNRhYi0Ok5FS0iZWGEhQHx3x ZfafQ7gbI1IHjV2OFsd66LJ0zdFF X-Google-Smtp-Source: AJdET5e5v6KMlreMmPO982IdJ7543dl4vGaIuoqv7SCeT6VRl+c9zCPX9O9RVPCDHeSH8GyiEfML3g== X-Received: by 2002:a1c:1314:: with SMTP id 20-v6mr2724846wmt.132.1540385427961; Wed, 24 Oct 2018 05:50:27 -0700 (PDT) Received: from mechagodzilla.com ([213.86.121.134]) by smtp.gmail.com with ESMTPSA id y7-v6sm3609985wmy.27.2018.10.24.05.50.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 Oct 2018 05:50:27 -0700 (PDT) From: Nick Ryan To: ffmpeg-devel@ffmpeg.org Date: Wed, 24 Oct 2018 13:50:15 +0100 Message-Id: <20181024125015.65290-2-nick.paul.ryan@gmail.com> X-Mailer: git-send-email 2.17.1 (Apple Git-112) In-Reply-To: <20181024125015.65290-1-nick.paul.ryan@gmail.com> References: <20181024125015.65290-1-nick.paul.ryan@gmail.com> Subject: [FFmpeg-devel] [PATCH] fix trac ticket #7359 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: Nick Ryan MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Nick Ryan --- libavformat/hls.c | 6 ++++-- libavformat/mov.c | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index 8ad08baaed..99373d0f45 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -2107,8 +2107,10 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt) ts_diff = av_rescale_rnd(pls->pkt.dts, AV_TIME_BASE, tb.den, AV_ROUND_DOWN) - pls->seek_timestamp; - if (ts_diff >= 0 && (pls->seek_flags & AVSEEK_FLAG_ANY || - pls->pkt.flags & AV_PKT_FLAG_KEY)) { + /* If AVSEEK_FLAG_ANY, keep reading until ts_diff is greater than 0 + * otherwise return the first keyframe encountered */ + if ((ts_diff >= 0 && (pls->seek_flags & AVSEEK_FLAG_ANY)) || + (!(pls->seek_flags & AVSEEK_FLAG_ANY) && (pls->pkt.flags & AV_PKT_FLAG_KEY))) { pls->seek_timestamp = AV_NOPTS_VALUE; break; } diff --git a/libavformat/mov.c b/libavformat/mov.c index ec57a05803..b13c3143ef 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7605,15 +7605,15 @@ static int mov_switch_root(AVFormatContext *s, int64_t target, int index) if (index >= 0 && index < mov->frag_index.nb_items) target = mov->frag_index.item[index].moof_offset; - if (avio_seek(s->pb, target, SEEK_SET) != target) { + if (target >= 0 && avio_seek(s->pb, target, SEEK_SET) != target) { av_log(mov->fc, AV_LOG_ERROR, "root atom offset 0x%"PRIx64": partial file\n", target); return AVERROR_INVALIDDATA; } mov->next_root_atom = 0; - if (index < 0 || index >= mov->frag_index.nb_items) + if ((index < 0 && target >= 0) || index >= mov->frag_index.nb_items) index = search_frag_moof_offset(&mov->frag_index, target); - if (index < mov->frag_index.nb_items) { + if (index >= 0 && index < mov->frag_index.nb_items) { if (index + 1 < mov->frag_index.nb_items) mov->next_root_atom = mov->frag_index.item[index + 1].moof_offset; if (mov->frag_index.item[index].headers_read) @@ -7664,8 +7664,38 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) AVStream *st = NULL; int64_t current_index; int ret; + int i; mov->fc = s; retry: + if (s->pb->pos == 0) { + + // Discard current fragment index + if (mov->frag_index.allocated_size > 0) { + av_freep(&mov->frag_index.item); + mov->frag_index.nb_items = 0; + mov->frag_index.allocated_size = 0; + mov->frag_index.current = -1; + mov->frag_index.complete = 0; + } + + for (i = 0; i < s->nb_streams; i++) { + AVStream *avst = s->streams[i]; + MOVStreamContext *msc = avst->priv_data; + + // Clear current sample + mov_current_sample_set(msc, 0); + + // Discard current index entries + if (avst->index_entries_allocated_size > 0) { + av_freep(&avst->index_entries); + avst->index_entries_allocated_size = 0; + avst->nb_index_entries = 0; + } + } + + if ((ret = mov_switch_root(s, -1, -1)) < 0) + return ret; + } sample = mov_find_next_sample(s, &st); if (!sample || (mov->next_root_atom && sample->pos > mov->next_root_atom)) { if (!mov->next_root_atom)