1 /* 2 * Copyright (C) 2014 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 MIDI_IO_WRAPPER_H_ 18 #define MIDI_IO_WRAPPER_H_ 19 20 #include <libsonivox/eas_types.h> 21 #include <utils/Mutex.h> 22 23 namespace android { 24 25 struct CDataSource; 26 27 class MidiIoWrapper { 28 public: 29 explicit MidiIoWrapper(const char *path); 30 explicit MidiIoWrapper(int fd, off64_t offset, int64_t size); 31 explicit MidiIoWrapper(CDataSource *csource); 32 33 ~MidiIoWrapper(); 34 35 int readAt(void *buffer, int offset, int size); 36 int unbufferedReadAt(void *buffer, int offset, int size); 37 int size(); 38 39 EAS_FILE_LOCATOR getLocator(); 40 41 private: 42 enum { 43 kTotalCacheSize = 1024 * 1024 + 512 * 1024, 44 kSingleCacheSize = 65536, 45 }; 46 47 int mFd; 48 off64_t mBase; 49 int64_t mLength; 50 class DataSourceUnwrapper; 51 DataSourceUnwrapper *mDataSource; 52 EAS_FILE mEasFile; 53 unsigned char *mCacheBuffer; 54 int64_t mCacheBufRangeLength; 55 static int sCacheBufferSize; 56 static Mutex mCacheLock; 57 }; 58 59 60 } // namespace android 61 62 #endif // MIDI_IO_WRAPPER_H_ 63