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