From patchwork Thu Sep 10 11:59:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 22253 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 C65CE44A365 for ; Thu, 10 Sep 2020 14:59:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A784A68B729; Thu, 10 Sep 2020 14:59:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D697D68B6C2 for ; Thu, 10 Sep 2020 14:59:30 +0300 (EEST) Received: by mail-ej1-f67.google.com with SMTP id gr14so8331475ejb.1 for ; Thu, 10 Sep 2020 04:59:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=eJoIsZWAfW50lhDrsuyUb4l+luAg7P8GaLxZgaTceps=; b=VJgK2ByezViglg6BSMdTMzRlv1HZnSlsNiehR+GyKPSlu8g2a7RQnhYbLEkSrdGh5f yrQ6lZanrI0TWvKozPBMnK1p1T8bKtsKjqsyv0atmIFAUs8EuEGzriNqJF2CyxwVpXiM e8sr2CAbak7MLAWfUXZQAia8p7mruk3julbahZzET5vxyhA7S/4v1RL9+FmEBxtWCXJh OpxBy7tM2QDtTTIb+qAqGZT4cAh4VW9HZOeyptwavlqdLidCcfxFhfgeO8wjiWLnHXVW +GV5hgP44rU70ZaKmbtAC3giV0gOMiplpOh0GBKRGlWmI861RhDvQN/0C4+yHy4xZ1ZN DDuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=eJoIsZWAfW50lhDrsuyUb4l+luAg7P8GaLxZgaTceps=; b=PLN1y7me4H/gMxYotPzlLGFirUp9CPdsI1f1KYFnY+6QA5PY+1t6OAuu4D4kxbRGOh Uji8l1ZaXvd7J8DNgoLR5AY9Q5+MRxluXzI6w4x32banDD3B7yT9GpvNwJmF5Qwl+4xe XGe/1pDSjeZHLLKU3p4IkHAi/OKWthRMfTKcamAefTWjbhg7nK+X3I6SCoN6XuhR7N+p Sejit7BJRaTP7i6AVZXIrHeLRpiH4whUa3xuFRT7QNnxo3vrthgtghvWyOv23YC3rLYy croU50n8qZiZsQSbxvTsD06JjjIFPo6u9iMXhAC2O7vbWYfgQFsIpnDWfiL9KSFiwHuT F6OQ== X-Gm-Message-State: AOAM530L5kV23PlexmImZWoojY+mM5uFFGTKsaFsofL6vc3p/vQyN9Va f6CVXSzD8i1p2lr4O4VYWIsmUM9e+VChUg== X-Google-Smtp-Source: ABdhPJxfgbLO1L3k8JzR3Rtw7puJzj9M9uVmMSxqvDXyy+F2MMBoAzOT3k08kms5sJqHD+k04RRVWA== X-Received: by 2002:a17:906:300b:: with SMTP id 11mr8278337ejz.270.1599739169992; Thu, 10 Sep 2020 04:59:29 -0700 (PDT) Received: from localhost.localdomain ([94.250.162.52]) by smtp.gmail.com with ESMTPSA id v22sm2550169ejj.23.2020.09.10.04.59.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 04:59:29 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Thu, 10 Sep 2020 13:59:21 +0200 Message-Id: <20200910115921.27843-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avformat/flic: add support for seeking to start 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- libavformat/flic.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/libavformat/flic.c b/libavformat/flic.c index e65c157777..4552bff69c 100644 --- a/libavformat/flic.c +++ b/libavformat/flic.c @@ -202,6 +202,7 @@ static int flic_read_packet(AVFormatContext *s, int magic; int ret = 0; unsigned char preamble[FLIC_PREAMBLE_SIZE]; + int64_t pos = avio_tell(pb); while (!packet_read && !avio_feof(pb)) { @@ -219,15 +220,19 @@ static int flic_read_packet(AVFormatContext *s, return ret; pkt->stream_index = flic->video_stream_index; - pkt->pts = flic->frame_number++; - pkt->pos = avio_tell(pb); + pkt->pos = pos; memcpy(pkt->data, preamble, FLIC_PREAMBLE_SIZE); ret = avio_read(pb, pkt->data + FLIC_PREAMBLE_SIZE, size - FLIC_PREAMBLE_SIZE); if (ret != size - FLIC_PREAMBLE_SIZE) { ret = AVERROR(EIO); } + pkt->flags = flic->frame_number == 0 ? AV_PKT_FLAG_KEY : 0; + pkt->pts = flic->frame_number; + if (flic->frame_number == 0) + av_add_index_entry(s->streams[flic->video_stream_index], pkt->pos, pkt->pts, pkt->size, 0, AVINDEX_KEYFRAME); packet_read = 1; + flic->frame_number++; } else if (magic == FLIC_TFTD_CHUNK_AUDIO) { if ((ret = av_new_packet(pkt, size)) < 0) return ret; @@ -236,7 +241,8 @@ static int flic_read_packet(AVFormatContext *s, avio_skip(pb, 10); pkt->stream_index = flic->audio_stream_index; - pkt->pos = avio_tell(pb); + pkt->pos = pos; + pkt->flags = AV_PKT_FLAG_KEY; ret = avio_read(pb, pkt->data, size); if (ret != size) { @@ -254,6 +260,31 @@ static int flic_read_packet(AVFormatContext *s, return avio_feof(pb) ? AVERROR_EOF : ret; } +static int flic_read_seek(AVFormatContext *s, int stream_index, + int64_t pts, int flags) +{ + FlicDemuxContext *flic = s->priv_data; + AVStream *st = s->streams[stream_index]; + int64_t pos, ts; + int index; + + if (!st->index_entries || stream_index != flic->video_stream_index) + return -1; + + index = av_index_search_timestamp(st, pts, flags); + + if (index < 0) + index = av_index_search_timestamp(st, pts, flags ^ AVSEEK_FLAG_BACKWARD); + if (index < 0) + return -1; + + pos = st->index_entries[index].pos; + ts = st->index_entries[index].timestamp; + flic->frame_number = ts; + avio_seek(s->pb, pos, SEEK_SET); + return 0; +} + AVInputFormat ff_flic_demuxer = { .name = "flic", .long_name = NULL_IF_CONFIG_SMALL("FLI/FLC/FLX animation"), @@ -261,4 +292,5 @@ AVInputFormat ff_flic_demuxer = { .read_probe = flic_probe, .read_header = flic_read_header, .read_packet = flic_read_packet, + .read_seek = flic_read_seek, };