From patchwork Wed Oct 26 06:07:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sasi Inguva X-Patchwork-Id: 1177 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.133 with SMTP id o127csp309483vsd; Tue, 25 Oct 2016 23:15:01 -0700 (PDT) X-Received: by 10.194.89.104 with SMTP id bn8mr521907wjb.132.1477462501641; Tue, 25 Oct 2016 23:15:01 -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 b13si1341977wmi.34.2016.10.25.23.15.01; Tue, 25 Oct 2016 23:15:01 -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 5FABC689BD7; Wed, 26 Oct 2016 09:14:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f174.google.com (mail-pf0-f174.google.com [209.85.192.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3B9386897C8 for ; Wed, 26 Oct 2016 09:14:49 +0300 (EEST) Received: by mail-pf0-f174.google.com with SMTP id n85so17142718pfi.1 for ; Tue, 25 Oct 2016 23:14:52 -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:mime-version :content-transfer-encoding; bh=C/mdcVF/0emWATuCssUZFKCdFox4oWQ+8ZvIf7yS4+s=; b=IWYHjc4Kp8IMVzSG26ppDBd0yWLBebrmO73PIXVcBmctj74W08PN1KrCjOQl6xhVdi Em+ANxfOIwwIr2D5h05UPB6J1mRPQoWC9Kd0nokSqMZkVt+jDJzM5408JrrwzNfc/ubM CM8xWdypWotGmTT2KcV1V8wiNy5B95hqUTh6YD0jFljLVQyjaqPJ8KeUpCk4KC7c37F4 XaCJx3npIIrM6NnfOEystE3sMO+jFzHA8yPcJ0XYotvykisxxO3ZFPMjgKTnPhiOdkdM i3nEY81aJedDdv32sbSjmA7hw/E+WHk6/pxP+Kqr82iOLj7Ra642qDS0pckbpaWex33J XnxQ== 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:mime-version :content-transfer-encoding; bh=C/mdcVF/0emWATuCssUZFKCdFox4oWQ+8ZvIf7yS4+s=; b=WgqwXW//g2nJV+5wBv19+75ovvB3QUgC0Xcu0lDKiUH9KSA8SMSaRqguHPmRP3NBpZ PxnzizgA4/aO2JgZQLjJTezqRJs6uW9mZtUkvnjqSEWoh0AwdvQ9VrACl3THt7Vd3wkO lkMeKV8T6XzwLnPB+6O34/jFJEZ83vLs/fhzspDsRYrhEz7/WbjLQw65QZzSXMA4xE6y 69oTCAE0pbj4O73odA4dmgo5tsYA55uq9GqR5iXAqyNILbLep9XGUxaEkN4duGoDdJpo mr5/VPMu6yP0ROOX5D9exvlJsTAXWT5NZoL0ig0z8GUnrlnkQRTKfe5ORtfcqnjFRAkS T7Ww== X-Gm-Message-State: ABUngvfwACc4mkR2Cg+0tdpnwUXaWAmOu6/VdkM9deuFOw7kYogv1bQf/+k+Ky5IpkmKeqU1 X-Received: by 10.99.146.69 with SMTP id s5mr859143pgn.9.1477462119767; Tue, 25 Oct 2016 23:08:39 -0700 (PDT) Received: from isasi.mtv.corp.google.com ([172.27.82.89]) by smtp.gmail.com with ESMTPSA id y123sm781570pfg.28.2016.10.25.23.08.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Oct 2016 23:08:39 -0700 (PDT) From: Sasi Inguva To: ffmpeg-devel@ffmpeg.org Date: Tue, 25 Oct 2016 23:07:58 -0700 Message-Id: <1477462078-1997-1-git-send-email-isasi@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 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 | 26 +++++++++++++++++++++++--- 2 files changed, 24 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..1b04b1a 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -4189,6 +4189,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) frag->implicit_offset = offset; + av_log(c, AV_LOG_DEBUG, "stindex: %d duration: %d end: %d\n", st->index, st->duration, sc->track_end); sc->track_end = dts + sc->time_offset; if (st->duration < sc->track_end) st->duration = sc->track_end; @@ -4202,7 +4203,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 +4286,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 +5865,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) {