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

Anton Khirnov anton at khirnov.net
Thu Apr 8 16:09:21 EEST 2021


Quoting James Almer (2021-04-04 01:12:00)
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
> Now using the avformat_ prefix as Anton requested. I forgot about it when i
> made v3.
> 
>  libavformat/avformat.h | 39 +++++++++++++++++++++++++++++++++++++++
>  libavformat/utils.c    | 27 +++++++++++++++++++++++++++
>  2 files changed, 66 insertions(+)
> 
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 6a9b09160c..a1e87ef891 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -2767,6 +2767,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(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 *avformat_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.
> + * @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.

How can the user know which functions can "alter the stream or the
AVFormatContext"?

I would prefer invalidating the pointer on ANY lavf call on that
AVFormatContext or its children, including calls to
avformat_index_get_entry*. That would allow us more freedom to change
the implementation later.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list