From patchwork Sat Apr 3 16:37:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26728 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 852BE44BE03 for ; Sat, 3 Apr 2021 19:43:14 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 59F2868A993; Sat, 3 Apr 2021 19:43:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3115E68A993 for ; Sat, 3 Apr 2021 19:43:07 +0300 (EEST) Received: by mail-pj1-f54.google.com with SMTP id gv19-20020a17090b11d3b029014c516f4eb5so2111440pjb.0 for ; Sat, 03 Apr 2021 09:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=vm/IxaoBA9hQkT4oTbsRKozfp8cLUomg1ClxvN5c9P4=; b=tiGczAX1SnTbs2MwAT5uDarLhas8ntI3/2LmqyD4ZB7HVMcNqkA1DWF+A+pFclb3Z2 hwujPWlOcYDJdqLbGoUpgcZfMMEJp/v6osV6DuOKIiC9MDly96z9+kWAxU2oYlJZxcTL Dz+Ljv3IpTv95RjVgj1I+yNecdjxSmlGrZaH6HbRELiVM4TJ8e12OXJaRPW5txZQkcv2 4O3TnRqZoz8EwKYa1L9QwX3fshrTSMw4ai/aHdDqIbP69Azmwn5XcZUs2gZFH4y6gjYc sLUu1/jsNvst8tDQZFpOUA1XDXYJIFSbRSMWlDQKNAPLRycJKdeuycynjjZgQkN/mtNi ljmQ== 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:mime-version :content-transfer-encoding; bh=vm/IxaoBA9hQkT4oTbsRKozfp8cLUomg1ClxvN5c9P4=; b=iSHpbrs8YjDg9cfQeAVIvcbTRoURDXpab+KMqiCWdEK8BXMVjuQkdNnhMdzqq86DfS 7hFYoM5/WNlqSYgM76FR3M/D68rNY5ebNWPVMssZoGjtKrKJgBRCvxZd8gBY8dUlq8/j ikbuBA/r0XDcgevD2wc05pPeNpTt81vH3aQ7MnHF9eRxrJ2cpjmxIMGA1KCBU74tBOKx IdFEVdJ09FrHpIDgpHYEYl0c4/ZtNUaaVVo98BlAvrQ5GKzqLNQglkBVp/nHmztnP5tG P4JsdjeyqFfVAe/4Q5XR55rkCh1s3kcpdFVhiQl2hnV0VbpPaAAP+1KesK4G4XdmV4uH xNrQ== X-Gm-Message-State: AOAM532UKR9wPTN4G2Q9+SFb2ke2upnmRVEtI/BWOY9g0EfavTiGjjJC +N4ls8rrYRubwWK8WM9YijU72cYcWO4= X-Google-Smtp-Source: ABdhPJx4Ft+z4smpzeZEPNCEv/FEKwJd5ZIQarwOXIBsX9bZ7SQ3urTl6Elz+tdoOgLNKEo0Ka7Ofg== X-Received: by 2002:a05:6214:1624:: with SMTP id e4mr17590496qvw.58.1617467861188; Sat, 03 Apr 2021 09:37:41 -0700 (PDT) Received: from localhost.localdomain ([191.83.218.26]) by smtp.gmail.com with ESMTPSA id b10sm9677346qkg.50.2021.04.03.09.37.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Apr 2021 09:37:40 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sat, 3 Apr 2021 13:37:25 -0300 Message-Id: <20210403163725.1078-1-jamrial@gmail.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] avformat/utils: add helper functions to retrieve index entries from an AVStream 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: James Almer --- Now returning a pointer to the requested entry. libavformat/avformat.h | 38 ++++++++++++++++++++++++++++++++++++++ libavformat/utils.c | 26 ++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 6a9b09160c..39371ea6d8 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -2767,6 +2767,44 @@ int av_find_default_stream_index(AVFormatContext *s); */ int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags); +/** + * Get the index entry count for the given AVStream. + * + * @param st stream + * @return the number of index entries in the stream + */ +int av_index_get_entries_count(AVStream *st); + +/** + * Get the AVIndexEntry corresponding to the given index. + * + * @param st Stream containing the requested AVIndexEntry. + * @param idx The desired index. + * @return A pointer to the requested AVIndexEntry if it exists, NULL otherwise. + * + * @note The pointer returned by this function is only guaranteed to be valid + * until any function that could alter the stream or the AVFormatContext + * that cointains it is called. + */ +const AVIndexEntry *av_index_get_entry(AVStream *st, int idx); + +/** + * Get the AVIndexEntry corresponding to the given timestamp. + * + * @param st Stream containing the requested AVIndexEntry. + * @param timestamp Timestamp to retrieve the index entry for. + * @param flags If AVSEEK_FLAG_BACKWARD then the returned entry will correspond + * to the timestamp which is <= the requested one, if backward + * is 0, then it will be >= + * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise. + * + * @note The pointer returned by this function is only guaranteed to be valid + * until any function that could alter the stream or the AVFormatContext + * that cointains it is called. + */ +const AVIndexEntry *av_index_get_entry_from_timestamp(AVStream *st, int64_t wanted_timestamp, + int flags); + /** * Add an index entry into a sorted list. Update the entry if the list * already contains it. diff --git a/libavformat/utils.c b/libavformat/utils.c index e9bf31e38b..812237c57e 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2176,6 +2176,32 @@ int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags) wanted_timestamp, flags); } +int av_index_get_entries_count(AVStream *st) +{ + return st->internal->nb_index_entries; +} + +const AVIndexEntry *av_index_get_entry(AVStream *st, int idx) +{ + if (idx < 0 || idx >= st->internal->nb_index_entries) + return NULL; + + return &st->internal->index_entries[idx]; +} + +const AVIndexEntry *av_index_get_entry_from_timestamp(AVStream *st, int64_t wanted_timestamp, + int flags) +{ + int idx = ff_index_search_timestamp(st->internal->index_entries, + st->internal->nb_index_entries, + wanted_timestamp, flags); + + if (idx < 0) + return NULL; + + return &st->internal->index_entries[idx]; +} + static int64_t ff_read_timestamp(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit, int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )) {