[FFmpeg-soc] [soc]: r5229 - in concat/libavformat: avplaylist.c avplaylist.h

gkovacs subversion at mplayerhq.hu
Mon Aug 24 05:16:43 CEST 2009


Author: gkovacs
Date: Mon Aug 24 05:16:43 2009
New Revision: 5229

Log:
cache results of av_playlist_time_offset for improved performance on large playlists

Modified:
   concat/libavformat/avplaylist.c
   concat/libavformat/avplaylist.h

Modified: concat/libavformat/avplaylist.c
==============================================================================
--- concat/libavformat/avplaylist.c	Mon Aug 24 05:06:36 2009	(r5228)
+++ concat/libavformat/avplaylist.c	Mon Aug 24 05:16:43 2009	(r5229)
@@ -218,14 +218,22 @@ void av_playlist_relative_paths(char **f
     }
 }
 
-int64_t av_playlist_time_offset(const int64_t *durations, int pe_curidx)
+int64_t av_playlist_time_offset(const int64_t *durations, int stream_index)
 {
-    int i;
+    int i, cache_num;
     int64_t total = 0;
-    for (i = 0; i < pe_curidx; ++i) {
+    static int cache_stidx[STREAM_CACHE_SIZE] = {-1};
+    static int64_t cache_timeoffset[STREAM_CACHE_SIZE] = {-1};
+    for (i = 0; i < STREAM_CACHE_SIZE; ++i) {
+        if (cache_stidx[i] == stream_index)
+            return cache_timeoffset[i];
+    }
+    cache_num = stream_index % STREAM_CACHE_SIZE;
+    cache_stidx[cache_num] = stream_index;
+    for (i = 0; i < stream_index; ++i) {
         total += durations[i];
     }
-    return total;
+    return (cache_timeoffset[cache_num] = total);
 }
 
 int av_playlist_stream_index_from_time(AVPlaylistContext *ctx,
@@ -259,8 +267,7 @@ int av_playlist_localstidx_from_streamid
     cache_globalstidx[cache_num] = stream_index;
     while (stream_index >= total)
         total += ctx->nb_streams_list[i++];
-    cache_localstidx[cache_num] = stream_index - (total - ctx->nb_streams_list[i-1]);
-    return cache_localstidx[cache_num];
+    return (cache_localstidx[cache_num] = stream_index - (total - ctx->nb_streams_list[i-1]));
 }
 
 int av_playlist_streams_offset_from_playidx(AVPlaylistContext *ctx, int playidx)

Modified: concat/libavformat/avplaylist.h
==============================================================================
--- concat/libavformat/avplaylist.h	Mon Aug 24 05:06:36 2009	(r5228)
+++ concat/libavformat/avplaylist.h	Mon Aug 24 05:16:43 2009	(r5229)
@@ -123,7 +123,7 @@ void av_playlist_add_path(AVPlaylistCont
  *  @param pe_curidx Index of the playlist element for which to calculate the time offset.
  *  @return Returns the time offset in AV_TIME_BASE units.
  */
-int64_t av_playlist_time_offset(const int64_t *durations, int pe_curidx);
+int64_t av_playlist_time_offset(const int64_t *durations, int stream_index);
 
 /** @brief Calculates the index of the playlist item which would contain the timestamp specified in AV_TIME_BASE units.
  *  @param ctx AVPlaylistContext within which the list of playlist elements and durations are stored.


More information about the FFmpeg-soc mailing list