[FFmpeg-soc] [soc]: r5228 - concat/libavformat/avplaylist.c

gkovacs subversion at mplayerhq.hu
Mon Aug 24 05:06:36 CEST 2009


Author: gkovacs
Date: Mon Aug 24 05:06:36 2009
New Revision: 5228

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

Modified:
   concat/libavformat/avplaylist.c

Modified: concat/libavformat/avplaylist.c
==============================================================================
--- concat/libavformat/avplaylist.c	Mon Aug 24 04:39:15 2009	(r5227)
+++ concat/libavformat/avplaylist.c	Mon Aug 24 05:06:36 2009	(r5228)
@@ -36,6 +36,8 @@
 #include "internal.h"
 #include "concat.h"
 
+#define STREAM_CACHE_SIZE (6)
+
 AVFormatContext *av_playlist_alloc_formatcontext(char *filename)
 {
     int err;
@@ -245,11 +247,20 @@ int av_playlist_stream_index_from_time(A
 
 int av_playlist_localstidx_from_streamidx(AVPlaylistContext *ctx, int stream_index)
 {
-    int i, total;
+    int i, total, cache_num;
+    static int cache_globalstidx[STREAM_CACHE_SIZE] = {-1};
+    static int cache_localstidx[STREAM_CACHE_SIZE] = {-1};
+    for (i = 0; i < STREAM_CACHE_SIZE; ++i) {
+        if (cache_globalstidx[i] == stream_index)
+            return cache_localstidx[i];
+    }
     i = total = 0;
+    cache_num = stream_index % STREAM_CACHE_SIZE;
+    cache_globalstidx[cache_num] = stream_index;
     while (stream_index >= total)
         total += ctx->nb_streams_list[i++];
-    return stream_index - (total - ctx->nb_streams_list[i-1]);
+    cache_localstidx[cache_num] = stream_index - (total - ctx->nb_streams_list[i-1]);
+    return cache_localstidx[cache_num];
 }
 
 int av_playlist_streams_offset_from_playidx(AVPlaylistContext *ctx, int playidx)


More information about the FFmpeg-soc mailing list