1 /* 2 ** 3 ** Copyright 2008, The Android Open Source Project 4 ** 5 ** Licensed under the Apache License, Version 2.0 (the "License"); 6 ** you may not use this file except in compliance with the License. 7 ** You may obtain a copy of the License at 8 ** 9 ** http://www.apache.org/licenses/LICENSE-2.0 10 ** 11 ** Unless required by applicable law or agreed to in writing, software 12 ** distributed under the License is distributed on an "AS IS" BASIS, 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ** See the License for the specific language governing permissions and 15 ** limitations under the License. 16 */ 17 18 #ifndef ANDROID_MIDIFILE_H 19 #define ANDROID_MIDIFILE_H 20 21 #include <media/MediaPlayerInterface.h> 22 #include <media/AudioTrack.h> 23 #include <libsonivox/eas.h> 24 25 namespace android { 26 27 class MidiFile : public MediaPlayerInterface { 28 public: 29 MidiFile(); 30 ~MidiFile(); 31 32 virtual status_t initCheck(); 33 34 virtual status_t setDataSource( 35 const char* path, const KeyedVector<String8, String8> *headers); 36 37 virtual status_t setDataSource(int fd, int64_t offset, int64_t length); 38 virtual status_t setVideoSurface(const sp<Surface>& surface) { return UNKNOWN_ERROR; } 39 virtual status_t setVideoSurfaceTexture( 40 const sp<ISurfaceTexture>& surfaceTexture) 41 { return UNKNOWN_ERROR; } 42 virtual status_t prepare(); 43 virtual status_t prepareAsync(); 44 virtual status_t start(); 45 virtual status_t stop(); 46 virtual status_t seekTo(int msec); 47 virtual status_t pause(); 48 virtual bool isPlaying(); 49 virtual status_t getCurrentPosition(int* msec); 50 virtual status_t getDuration(int* msec); 51 virtual status_t release(); 52 virtual status_t reset(); 53 virtual status_t setLooping(int loop); 54 virtual player_type playerType() { return SONIVOX_PLAYER; } 55 virtual status_t invoke(const Parcel& request, Parcel *reply) { 56 return INVALID_OPERATION; 57 } 58 virtual status_t setParameter(int key, const Parcel &request) { 59 return INVALID_OPERATION; 60 } 61 virtual status_t getParameter(int key, Parcel *reply) { 62 return INVALID_OPERATION; 63 } 64 65 66 private: 67 status_t createOutputTrack(); 68 status_t reset_nosync(); 69 static int renderThread(void*); 70 int render(); 71 void updateState(){ EAS_State(mEasData, mEasHandle, &mState); } 72 73 Mutex mMutex; 74 Condition mCondition; 75 EAS_DATA_HANDLE mEasData; 76 EAS_HANDLE mEasHandle; 77 EAS_PCM* mAudioBuffer; 78 EAS_I32 mPlayTime; 79 EAS_I32 mDuration; 80 EAS_STATE mState; 81 EAS_FILE mFileLocator; 82 int mStreamType; 83 bool mLoop; 84 volatile bool mExit; 85 bool mPaused; 86 volatile bool mRender; 87 pid_t mTid; 88 }; 89 90 }; // namespace android 91 92 #endif // ANDROID_MIDIFILE_H 93