[FFmpeg-cvslog] avformat/utils: add helper functions to retrieve index entries from an AVStream

James Almer git at videolan.org
Wed Apr 7 16:28:33 EEST 2021


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Tue Mar 23 15:36:22 2021 -0300| [557953a397dfdd9c7a3d8c2f60d1204599e3d3ac] | committer: James Almer

avformat/utils: add helper functions to retrieve index entries from an AVStream

Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=557953a397dfdd9c7a3d8c2f60d1204599e3d3ac
---

 doc/APIchanges         |  4 ++++
 libavformat/avformat.h | 39 +++++++++++++++++++++++++++++++++++++++
 libavformat/utils.c    | 27 +++++++++++++++++++++++++++
 libavformat/version.h  |  2 +-
 4 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index b41dadee8d..9dfcc97d5c 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,10 @@ libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2021-04-06 - xxxxxxxxxx - lavf 58.78.100 - avformat.h
+  Add avformat_index_get_entries_count(), avformat_index_get_entry(),
+  and avformat_index_get_entry_from_timestamp().
+
 2021-03-21 - xxxxxxxxxx - lavu 56.72.100 - frame.h
   Deprecated av_get_colorspace_name().
   Use av_color_space_name() instead.
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 765bc3b6f5..8600ee1bf7 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2754,6 +2754,45 @@ 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 avformat_index_get_entries_count(const 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 contains it is called.
+ */
+const AVIndexEntry *avformat_index_get_entry(const 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.
+ * @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 contains it is called.
+ */
+const AVIndexEntry *avformat_index_get_entry_from_timestamp(const 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 13b1bc7c78..b671fa75b3 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2164,6 +2164,33 @@ int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags)
                                      wanted_timestamp, flags);
 }
 
+int avformat_index_get_entries_count(const AVStream *st)
+{
+    return st->internal->nb_index_entries;
+}
+
+const AVIndexEntry *avformat_index_get_entry(const AVStream *st, int idx)
+{
+    if (idx < 0 || idx >= st->internal->nb_index_entries)
+        return NULL;
+
+    return &st->internal->index_entries[idx];
+}
+
+const AVIndexEntry *avformat_index_get_entry_from_timestamp(const 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 ))
 {
diff --git a/libavformat/version.h b/libavformat/version.h
index ced5600034..b6023f9d2e 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  58
-#define LIBAVFORMAT_VERSION_MINOR  77
+#define LIBAVFORMAT_VERSION_MINOR  78
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list