1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CACHING_DATASOURCE_H_ 18 19 #define CACHING_DATASOURCE_H_ 20 21 #include <media/stagefright/DataSource.h> 22 #include <media/stagefright/MediaErrors.h> 23 #include <utils/threads.h> 24 25 namespace android { 26 27 class CachingDataSource : public DataSource { 28 public: 29 CachingDataSource( 30 const sp<DataSource> &source, size_t pageSize, int numPages); 31 32 status_t InitCheck() const; 33 34 virtual ssize_t read_at(off_t offset, void *data, size_t size); 35 36 protected: 37 virtual ~CachingDataSource(); 38 39 private: 40 struct Page { 41 Page *mPrev, *mNext; 42 off_t mOffset; 43 size_t mLength; 44 void *mData; 45 }; 46 47 sp<DataSource> mSource; 48 void *mData; 49 size_t mPageSize; 50 Page *mFirst, *mLast; 51 52 Page *allocate_page(); 53 54 Mutex mLock; 55 56 CachingDataSource(const CachingDataSource &); 57 CachingDataSource &operator=(const CachingDataSource &); 58 }; 59 60 } // namespace android 61 62 #endif // CACHING_DATASOURCE_H_ 63