diff options
author | Wonsik Kim <wonsik@google.com> | 2015-06-11 05:14:21 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-06-11 05:14:22 +0000 |
commit | 054bf835731c0fa5e6c2fbee93b0befa74c10119 (patch) | |
tree | 194825d72899bdfd79281c946fda1119b86ef16d /media | |
parent | f4b30c200cfc7c8c502f759dcb90979586e43b27 (diff) | |
parent | 06ec7f3ef28ee68714d323ca9e2d3cab2165dfe8 (diff) | |
download | frameworks_av-054bf835731c0fa5e6c2fbee93b0befa74c10119.zip frameworks_av-054bf835731c0fa5e6c2fbee93b0befa74c10119.tar.gz frameworks_av-054bf835731c0fa5e6c2fbee93b0befa74c10119.tar.bz2 |
Merge "stagefright: TinyCacheSource to read continuously" into mnc-dev
Diffstat (limited to 'media')
-rw-r--r-- | media/libstagefright/CallbackDataSource.cpp | 22 |
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. |