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 25namespace android { 26 27class CachingDataSource : public DataSource { 28public: 29 CachingDataSource( 30 const sp<DataSource> &source, size_t pageSize, int numPages); 31 32 virtual status_t initCheck() const; 33 34 virtual ssize_t readAt(off_t offset, void *data, size_t size); 35 36 virtual status_t getSize(off_t *size); 37 38 virtual uint32_t flags(); 39 40protected: 41 virtual ~CachingDataSource(); 42 43private: 44 struct Page { 45 Page *mPrev, *mNext; 46 off_t mOffset; 47 size_t mLength; 48 void *mData; 49 }; 50 51 sp<DataSource> mSource; 52 void *mData; 53 size_t mPageSize; 54 Page *mFirst, *mLast; 55 56 Page *allocate_page(); 57 58 Mutex mLock; 59 60 CachingDataSource(const CachingDataSource &); 61 CachingDataSource &operator=(const CachingDataSource &); 62}; 63 64} // namespace android 65 66#endif // CACHING_DATASOURCE_H_ 67