summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/CallbackDataSource.cpp
diff options
context:
space:
mode:
authorWonsik Kim <wonsik@google.com>2015-06-09 13:26:03 +0900
committerWonsik Kim <wonsik@google.com>2015-06-11 03:11:41 +0000
commit06ec7f3ef28ee68714d323ca9e2d3cab2165dfe8 (patch)
treeb69b49437b9ae15fe0bc047e8e83a0f44f986749 /media/libstagefright/CallbackDataSource.cpp
parentca097142ba4664858bc29bb538bcfcf5ea03ebe7 (diff)
downloadframeworks_av-06ec7f3ef28ee68714d323ca9e2d3cab2165dfe8.zip
frameworks_av-06ec7f3ef28ee68714d323ca9e2d3cab2165dfe8.tar.gz
frameworks_av-06ec7f3ef28ee68714d323ca9e2d3cab2165dfe8.tar.bz2
stagefright: TinyCacheSource to read continuously
If the seek operation of underlying MediaDataSource implementation is expensive and each read is relatively small (e.g. Live MPEG2 TS stream), current TinyCacheSource implementation requests seek too frequently. Bug: 21764375 Change-Id: Ic620bf027bc4ef48822549c83c5c98109986884a
Diffstat (limited to 'media/libstagefright/CallbackDataSource.cpp')
-rw-r--r--media/libstagefright/CallbackDataSource.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/media/libstagefright/CallbackDataSource.cpp b/media/libstagefright/CallbackDataSource.cpp
index 41f0175..de972ce 100644
--- a/media/libstagefright/CallbackDataSource.cpp
+++ b/media/libstagefright/CallbackDataSource.cpp
@@ -109,9 +109,25 @@ ssize_t TinyCacheSource::readAt(off64_t offset, void* data, size_t size) {
}
// Check if the cache satisfies the read.
- if (offset >= mCachedOffset && offset + size <= mCachedOffset + mCachedSize) {
- memcpy(data, &mCache[offset - mCachedOffset], size);
- return size;
+ if (mCachedOffset <= offset && offset < mCachedOffset + mCachedSize) {
+ if (offset + size <= mCachedOffset + mCachedSize) {
+ memcpy(data, &mCache[offset - mCachedOffset], size);
+ return size;
+ } else {
+ // If the cache hits only partially, flush the cache and read the
+ // remainder.
+
+ // This value is guaranteed to be greater than 0 because of the
+ // enclosing if statement.
+ const ssize_t remaining = mCachedOffset + mCachedSize - offset;
+ memcpy(data, &mCache[offset - mCachedOffset], remaining);
+ const ssize_t readMore = readAt(offset + remaining,
+ (uint8_t*)data + remaining, size - remaining);
+ if (readMore < 0) {
+ return readMore;
+ }
+ return remaining + readMore;
+ }
}
// Fill the cache and copy to the caller.