[FFmpeg-devel] [RFC][PATCH] Windows Television (WTV) file system handling

Måns Rullgård mans
Fri Feb 4 03:27:15 CET 2011


Peter Ross <pross at xvid.org> writes:

> From a8caba581f97eae7616cf1dac754970e89bdc459 Mon Sep 17 00:00:00 2001
> From: Peter Ross <pross at xvid.org>
> Date: Sat, 22 Jan 2011 20:03:22 +1100
> Subject: [PATCH 3/3] add ff_index_search_timestamp and ff_add_index_entry
>
> ---
>  libavformat/avformat.h |   14 ++++++++++++++
>  libavformat/utils.c    |   45 ++++++++++++++++++++++++++++++---------------
>  2 files changed, 44 insertions(+), 15 deletions(-)
>
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index f9f9be5..9fab840 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -1278,6 +1278,12 @@ void av_set_pts_info(AVStream *s, int pts_wrap_bits,
>  int av_find_default_stream_index(AVFormatContext *s);
>  
>  /**
> + * Internal version of av_index_search_timestamp
> + */
> +int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries,
> +                              int64_t wanted_timestamp, int flags);
> +
> +/**
>   * Get the index for a specific timestamp.
>   * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
>   *                 to the timestamp which is <= the requested one, if backward
> @@ -1297,6 +1303,14 @@ int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
>  void ff_reduce_index(AVFormatContext *s, int stream_index);
>  
>  /**
> + * Internal version of av_add_index_entry
> + */
> +int ff_add_index_entry(AVIndexEntry **index_entries,
> +                       int *nb_index_entries,
> +                       unsigned int *index_entries_allocated_size,
> +                       int64_t pos, int64_t timestamp, int size, int distance, int flags);
> +
> +/**
>   * Add an index entry into a sorted list. Update the entry if the list
>   * already contains it.
>   *

Internal stuff does not belong in public headers.  Please move it elsewhere.

> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index c208bd9..03be10d 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -1370,28 +1370,30 @@ void ff_reduce_index(AVFormatContext *s, int stream_index)
>      }
>  }
>  
> -int av_add_index_entry(AVStream *st,
> -                            int64_t pos, int64_t timestamp, int size, int distance, int flags)
> +int ff_add_index_entry(AVIndexEntry **index_entries,
> +                       int *nb_index_entries, 
> +                       unsigned int *index_entries_allocated_size,
> +                       int64_t pos, int64_t timestamp, int size, int distance, int flags)
>  {
>      AVIndexEntry *entries, *ie;
>      int index;
>  
> -    if((unsigned)st->nb_index_entries + 1 >= UINT_MAX / sizeof(AVIndexEntry))
> +    if((unsigned)*nb_index_entries + 1 >= UINT_MAX / sizeof(AVIndexEntry))
>          return -1;
>  
> -    entries = av_fast_realloc(st->index_entries,
> -                              &st->index_entries_allocated_size,
> -                              (st->nb_index_entries + 1) *
> +    entries = av_fast_realloc(*index_entries,
> +                              index_entries_allocated_size,
> +                              (*nb_index_entries + 1) *
>                                sizeof(AVIndexEntry));
>      if(!entries)
>          return -1;
>  
> -    st->index_entries= entries;
> +    *index_entries= entries;
>  
> -    index= av_index_search_timestamp(st, timestamp, AVSEEK_FLAG_ANY);
> +    index= ff_index_search_timestamp(*index_entries, *nb_index_entries, timestamp, AVSEEK_FLAG_ANY);
>  
>      if(index<0){
> -        index= st->nb_index_entries++;
> +        index= (*nb_index_entries)++;
>          ie= &entries[index];
>          assert(index==0 || ie[-1].timestamp < timestamp);
>      }else{
> @@ -1399,8 +1401,8 @@ int av_add_index_entry(AVStream *st,
>          if(ie->timestamp != timestamp){
>              if(ie->timestamp <= timestamp)
>                  return -1;
> -            memmove(entries + index + 1, entries + index, sizeof(AVIndexEntry)*(st->nb_index_entries - index));
> -            st->nb_index_entries++;
> +            memmove(entries + index + 1, entries + index, sizeof(AVIndexEntry)*(*nb_index_entries - index));
> +            (*nb_index_entries)++;
>          }else if(ie->pos == pos && distance < ie->min_distance) //do not reduce the distance
>              distance= ie->min_distance;
>      }
> @@ -1414,11 +1416,17 @@ int av_add_index_entry(AVStream *st,
>      return index;
>  }
>  
> -int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp,
> -                              int flags)
> +int av_add_index_entry(AVStream *st,
> +                       int64_t pos, int64_t timestamp, int size, int distance, int flags)
> +{
> +    return ff_add_index_entry(&st->index_entries, &st->nb_index_entries, 
> +                              &st->index_entries_allocated_size, pos,
> +                              timestamp, size, distance, flags);
> +}
> +
> +int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries,
> +                              int64_t wanted_timestamp, int flags)
>  {
> -    AVIndexEntry *entries= st->index_entries;
> -    int nb_entries= st->nb_index_entries;
>      int a, b, m;
>      int64_t timestamp;
>  
> @@ -1450,6 +1458,13 @@ int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp,
>      return  m;
>  }
>  
> +int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp,
> +                              int flags)
> +{
> +    return ff_index_search_timestamp(st->index_entries, st->nb_index_entries,
> +                                     wanted_timestamp, flags);
> +}
> +
>  #define DEBUG_SEEK
>  
>  int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){
> -- 
> 1.7.1

Looks reasonable.

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-devel mailing list