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/MediaExtractorPluginApi.h> 21 #include <media/MediaExtractorPluginHelper.h> 22 #include <media/stagefright/MediaBufferBase.h> 23 #include <media/stagefright/MediaBufferGroup.h> 24 #include <media/MidiIoWrapper.h> 25 #include <media/NdkMediaFormat.h> 26 #include <utils/String8.h> 27 #include <libsonivox/eas.h> 28 29 namespace android { 30 31 class MidiEngine { 32 public: 33 explicit MidiEngine(CDataSource *dataSource, 34 AMediaFormat *fileMetadata, 35 AMediaFormat *trackMetadata); 36 ~MidiEngine(); 37 38 status_t initCheck(); 39 40 status_t allocateBuffers(MediaBufferGroupHelper *group); 41 status_t releaseBuffers(); 42 status_t seekTo(int64_t positionUs); 43 MediaBufferHelper* readBuffer(); 44 private: 45 MidiIoWrapper *mIoWrapper; 46 MediaBufferGroupHelper *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 MediaExtractorPluginHelper { 54 55 public: 56 explicit MidiExtractor(CDataSource *source); 57 58 virtual size_t countTracks(); 59 virtual MediaTrackHelper *getTrack(size_t index); 60 virtual media_status_t getTrackMetaData(AMediaFormat *meta, size_t index, uint32_t flags); 61 62 virtual media_status_t getMetaData(AMediaFormat *meta); name()63 virtual const char * name() { return "MidiExtractor"; } 64 65 protected: 66 virtual ~MidiExtractor(); 67 68 private: 69 CDataSource *mDataSource; 70 status_t mInitCheck; 71 AMediaFormat *mFileMetadata; 72 73 // There is only one track 74 AMediaFormat *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(CDataSource *source, float *confidence); 92 93 } // namespace android 94 95 #endif // MIDI_EXTRACTOR_H_ 96