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_EXTRACTOR_H_ 18 #define MIDI_EXTRACTOR_H_ 19 20 #include <media/DataSourceBase.h> 21 #include <media/MediaExtractor.h> 22 #include <media/stagefright/MediaBufferBase.h> 23 #include <media/stagefright/MediaBufferGroup.h> 24 #include <media/stagefright/MetaDataBase.h> 25 #include <media/MidiIoWrapper.h> 26 #include <utils/String8.h> 27 #include <libsonivox/eas.h> 28 29 namespace android { 30 31 class MidiEngine { 32 public: 33 explicit MidiEngine(DataSourceBase *dataSource, 34 MetaDataBase *fileMetadata, 35 MetaDataBase *trackMetadata); 36 ~MidiEngine(); 37 38 status_t initCheck(); 39 40 status_t allocateBuffers(); 41 status_t releaseBuffers(); 42 status_t seekTo(int64_t positionUs); 43 MediaBufferBase* readBuffer(); 44 private: 45 MidiIoWrapper *mIoWrapper; 46 MediaBufferGroup *mGroup; 47 EAS_DATA_HANDLE mEasData; 48 EAS_HANDLE mEasHandle; 49 const S_EAS_LIB_CONFIG* mEasConfig; 50 bool mIsInitialized; 51 }; 52 53 class MidiExtractor : public MediaExtractor { 54 55 public: 56 explicit MidiExtractor(DataSourceBase *source); 57 58 virtual size_t countTracks(); 59 virtual MediaTrack *getTrack(size_t index); 60 virtual status_t getTrackMetaData(MetaDataBase& meta, size_t index, uint32_t flags); 61 62 virtual status_t getMetaData(MetaDataBase& meta); name()63 virtual const char * name() { return "MidiExtractor"; } 64 65 protected: 66 virtual ~MidiExtractor(); 67 68 private: 69 DataSourceBase *mDataSource; 70 status_t mInitCheck; 71 MetaDataBase mFileMetadata; 72 73 // There is only one track 74 MetaDataBase mTrackMetadata; 75 76 MidiEngine *mEngine; 77 78 EAS_DATA_HANDLE mEasData; 79 EAS_HANDLE mEasHandle; 80 EAS_PCM* mAudioBuffer; 81 EAS_I32 mPlayTime; 82 EAS_I32 mDuration; 83 EAS_STATE mState; 84 EAS_FILE mFileLocator; 85 86 MidiExtractor(const MidiExtractor &); 87 MidiExtractor &operator=(const MidiExtractor &); 88 89 }; 90 91 bool SniffMidi(DataSourceBase *source, float *confidence); 92 93 } // namespace android 94 95 #endif // MIDI_EXTRACTOR_H_ 96