summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/include
diff options
context:
space:
mode:
authorChris Watkins <watk@google.com>2015-04-07 10:01:15 -0700
committerChris Watkins <watk@google.com>2015-04-20 10:14:19 -0700
commitda7e453e1d1c77959822cf9602ddfed1c50be445 (patch)
tree2fed02646af0da50bcfc5deb5c86167c06ddfdd2 /media/libstagefright/include
parentee4e1b1a63758941460ae79a064249d3a5189443 (diff)
downloadframeworks_av-da7e453e1d1c77959822cf9602ddfed1c50be445.zip
frameworks_av-da7e453e1d1c77959822cf9602ddfed1c50be445.tar.gz
frameworks_av-da7e453e1d1c77959822cf9602ddfed1c50be445.tar.bz2
stagefright: add a 2kb cache for CallbackDataSource.
Without a cache the mediaserver does a lot of small reads which result in round trips through binder and jni to the app MediaDataSource. On a Nexus 5 I measured time to first frame from MediaPlayer for 1) 1350kbps h264, and 2) 20480kbps vp8. Without a cache, MediaDataSource was ~250ms slower than an fd. With a 2kb cache it's 30ms slower for (1) and 70ms slower for (2). Change-Id: If1e811db7b853c4f79430603318d4744ac30acb9
Diffstat (limited to 'media/libstagefright/include')
-rw-r--r--media/libstagefright/include/CallbackDataSource.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/media/libstagefright/include/CallbackDataSource.h b/media/libstagefright/include/CallbackDataSource.h
index 678eb2e..1a21dd3 100644
--- a/media/libstagefright/include/CallbackDataSource.h
+++ b/media/libstagefright/include/CallbackDataSource.h
@@ -44,6 +44,36 @@ private:
DISALLOW_EVIL_CONSTRUCTORS(CallbackDataSource);
};
+
+// A caching DataSource that wraps a CallbackDataSource. For reads smaller
+// than kCacheSize it will read up to kCacheSize ahead and cache it.
+// This reduces the number of binder round trips to the IDataSource and has a significant
+// impact on time taken for filetype sniffing and metadata extraction.
+class TinyCacheSource : public DataSource {
+public:
+ TinyCacheSource(const sp<DataSource>& source);
+
+ virtual status_t initCheck() const;
+ virtual ssize_t readAt(off64_t offset, void* data, size_t size);
+ virtual status_t getSize(off64_t* size);
+ virtual uint32_t flags();
+
+private:
+ // 2kb comes from experimenting with the time-to-first-frame from a MediaPlayer
+ // with an in-memory MediaDataSource source on a Nexus 5. Beyond 2kb there was
+ // no improvement.
+ enum {
+ kCacheSize = 2048,
+ };
+
+ sp<DataSource> mSource;
+ uint8_t mCache[kCacheSize];
+ off64_t mCachedOffset;
+ size_t mCachedSize;
+
+ DISALLOW_EVIL_CONSTRUCTORS(TinyCacheSource);
+};
+
}; // namespace android
#endif // ANDROID_CALLBACKDATASOURCE_H