From patchwork Wed Oct 26 18:31:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sasi Inguva X-Patchwork-Id: 1178 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.133 with SMTP id o127csp188532vsd; Wed, 26 Oct 2016 11:32:18 -0700 (PDT) X-Received: by 10.28.126.21 with SMTP id z21mr3861339wmc.71.1477506738145; Wed, 26 Oct 2016 11:32:18 -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 m3si4054675wjd.263.2016.10.26.11.32.17; Wed, 26 Oct 2016 11:32:18 -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=@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 02CBB689D9F; Wed, 26 Oct 2016 21:32:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f177.google.com (mail-pf0-f177.google.com [209.85.192.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8C90C689D27 for ; Wed, 26 Oct 2016 21:32:06 +0300 (EEST) Received: by mail-pf0-f177.google.com with SMTP id s8so1257156pfj.2 for ; Wed, 26 Oct 2016 11:32:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Lt2DWR9N8rkgjP2+zz0GFv2aznDfs0i1SRfindfQdOo=; b=ktGICF1bW++Ui0fIRKNj3529DsBi4hk2ohlFx/gx0lzgp/RKbjVCJNhIi/FBUCxMJW BL9fXvcyyVCtYPpTI7Atfh+/JH2alEQSlkO6Vhw5ttSGgwnCxVBUDE3raBa6Ad5R0KqM rvs64+3Vhu9V0qWq1aDli6Oyc3azFsj4c36/IoPO8UK9cS6s6V88kCgRyvCFsD/BRGDQ l8LPJoWfAQwqU5MOjBVvnctzvIPDGosv1W3T872J90xQ0SiEjfgyjCnkkrLbfYSjJjDp 7OYdereWA3goTaR/F6LZgMj+kCV5pcLqTHfryF7Pm/8jwlu7TFg5ehiPqvoJ1jfPIJ4v 5xGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Lt2DWR9N8rkgjP2+zz0GFv2aznDfs0i1SRfindfQdOo=; b=D2FdqTKAWo8D/dOrjgce89C7QoNK/S084ye/1emag8ZCYK6yPlHCdkdvhLgWnmzmT6 RE8La/HNftbEI+fWglyuV6BVh5lOQDZMxkvZLNnXvqeCXWN0FIo2yN1upWYS0l15cbwC O0kr9W+M8IznW0luWClXEGcdWqtikKiSXuHb5cRSHAQlDXDyiy1KYTy4cuw2tWx99vjS dksOT+SfU2jZpZamwCgV6QOHU31+pZ+1iBTuwSgFfYDeZjBBPuG/BHzEBFaeVEy4w1gv i6HXqigfCuf8mZUGk2b6bqzZgZ2VB/oLQY8yRSMyn8eyqOrBVGthqiGlkED67RHc+IpE hE3Q== X-Gm-Message-State: ABUngvewjRCfFj1K8soiJHRchvlNUKq/mPla7AN5aL3rwgDPbd8H1IZ1SU7cuz05V0Ab8qIx X-Received: by 10.98.144.219 with SMTP id q88mr6624042pfk.116.1477506728179; Wed, 26 Oct 2016 11:32:08 -0700 (PDT) Received: from isasi.mtv.corp.google.com ([172.27.82.89]) by smtp.gmail.com with ESMTPSA id 70sm5832928pfc.50.2016.10.26.11.32.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Oct 2016 11:32:07 -0700 (PDT) From: Sasi Inguva To: ffmpeg-devel@ffmpeg.org Date: Wed, 26 Oct 2016 11:31:03 -0700 Message-Id: <1477506663-7509-1-git-send-email-isasi@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavf/mov.c: Use the first sidx for tracks without sidx. 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: Sasi Inguva Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" According to spec ISO_IEC_15444_12 "For any media stream for which no segment index is present, referred to as non‐indexed stream, the media stream associated with the first Segment Index box in the segment serves as a reference stream in a sense that it also describes the subsegments for any non‐indexed media stream." Signed-off-by: Sasi Inguva --- libavformat/isom.h | 1 + libavformat/mov.c | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 9038057..d684502 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -179,6 +179,7 @@ typedef struct MOVStreamContext { int32_t *display_matrix; uint32_t format; + int has_sidx; // If there is an sidx entry for this stream. struct { int use_subsamples; uint8_t* auxiliary_info; diff --git a/libavformat/mov.c b/libavformat/mov.c index 357d800..d9ed5a3 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -4202,7 +4202,8 @@ static int mov_read_sidx(MOVContext *c, AVIOContext *pb, MOVAtom atom) uint8_t version; unsigned i, track_id; AVStream *st = NULL; - MOVStreamContext *sc; + AVStream *ref_st; + MOVStreamContext *sc, *ref_sc; MOVFragmentIndex *index = NULL; MOVFragmentIndex **tmp; AVRational timescale; @@ -4284,9 +4285,26 @@ static int mov_read_sidx(MOVContext *c, AVIOContext *pb, MOVAtom atom) c->fragment_index_data = tmp; c->fragment_index_data[c->fragment_index_count++] = index; + sc->has_sidx = 1; + + if (offset == avio_size(pb)) { + for (i = 0; i < c->fc->nb_streams; i++) { + if (c->fc->streams[i]->id == c->fragment_index_data[0]->track_id) { + ref_st = c->fc->streams[i]; + ref_sc = ref_st->priv_data; + break; + } + } + for (i = 0; i < c->fc->nb_streams; i++) { + st = c->fc->streams[i]; + sc = st->priv_data; + if (!sc->has_sidx) { + st->duration = sc->track_end = av_rescale(ref_st->duration, sc->time_scale, ref_sc->time_scale); + } + } - if (offset == avio_size(pb)) c->fragment_index_complete = 1; + } return 0; } @@ -5846,13 +5864,14 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) static int mov_seek_fragment(AVFormatContext *s, AVStream *st, int64_t timestamp) { MOVContext *mov = s->priv_data; + MOVStreamContext *sc = st->priv_data; int i, j; if (!mov->fragment_index_complete) return 0; for (i = 0; i < mov->fragment_index_count; i++) { - if (mov->fragment_index_data[i]->track_id == st->id) { + if (mov->fragment_index_data[i]->track_id == st->id || !sc->has_sidx) { MOVFragmentIndex *index = mov->fragment_index_data[i]; for (j = index->item_count - 1; j >= 0; j--) { if (index->items[j].time <= timestamp) {