The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include <libsonivox/eas.h> |
| 23 | |
| 24 | namespace android { |
| 25 | |
Glenn Kasten | 90100b5 | 2011-06-23 17:11:35 -0700 | [diff] [blame] | 26 | // Note that the name MidiFile is misleading; this actually represents a MIDI file player |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | class MidiFile : public MediaPlayerInterface { |
| 28 | public: |
| 29 | MidiFile(); |
| 30 | ~MidiFile(); |
| 31 | |
| 32 | virtual status_t initCheck(); |
Andreas Huber | 2db8455 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 33 | |
| 34 | virtual status_t setDataSource( |
Andreas Huber | 1b86fe0 | 2014-01-29 11:13:26 -0800 | [diff] [blame] | 35 | const sp<IMediaHTTPService> &httpService, |
| 36 | const char* path, |
| 37 | const KeyedVector<String8, String8> *headers); |
Andreas Huber | 2db8455 | 2010-01-28 11:19:57 -0800 | [diff] [blame] | 38 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | virtual status_t setDataSource(int fd, int64_t offset, int64_t length); |
Glenn Kasten | 1173118 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 40 | virtual status_t setVideoSurfaceTexture( |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 41 | const sp<IGraphicBufferProducer>& bufferProducer) |
Glenn Kasten | 1173118 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 42 | { return UNKNOWN_ERROR; } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | virtual status_t prepare(); |
| 44 | virtual status_t prepareAsync(); |
| 45 | virtual status_t start(); |
| 46 | virtual status_t stop(); |
| 47 | virtual status_t seekTo(int msec); |
| 48 | virtual status_t pause(); |
| 49 | virtual bool isPlaying(); |
| 50 | virtual status_t getCurrentPosition(int* msec); |
| 51 | virtual status_t getDuration(int* msec); |
| 52 | virtual status_t release(); |
| 53 | virtual status_t reset(); |
| 54 | virtual status_t setLooping(int loop); |
| 55 | virtual player_type playerType() { return SONIVOX_PLAYER; } |
niko | d608a81 | 2009-07-16 16:39:53 -0700 | [diff] [blame] | 56 | virtual status_t invoke(const Parcel& request, Parcel *reply) { |
| 57 | return INVALID_OPERATION; |
| 58 | } |
Gloria Wang | 4f9e47f | 2011-04-25 17:28:22 -0700 | [diff] [blame] | 59 | virtual status_t setParameter(int key, const Parcel &request) { |
| 60 | return INVALID_OPERATION; |
| 61 | } |
| 62 | virtual status_t getParameter(int key, Parcel *reply) { |
| 63 | return INVALID_OPERATION; |
| 64 | } |
| 65 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | |
| 67 | private: |
| 68 | status_t createOutputTrack(); |
| 69 | status_t reset_nosync(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 82 | audio_stream_type_t mStreamType; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | bool mLoop; |
| 84 | volatile bool mExit; |
| 85 | bool mPaused; |
| 86 | volatile bool mRender; |
| 87 | pid_t mTid; |
Glenn Kasten | 90100b5 | 2011-06-23 17:11:35 -0700 | [diff] [blame] | 88 | |
| 89 | class MidiFileThread : public Thread { |
| 90 | public: |
| 91 | MidiFileThread(MidiFile *midiPlayer) : mMidiFile(midiPlayer) { |
| 92 | } |
| 93 | |
| 94 | protected: |
| 95 | virtual ~MidiFileThread() {} |
| 96 | |
| 97 | private: |
| 98 | MidiFile *mMidiFile; |
| 99 | |
| 100 | bool threadLoop() { |
| 101 | int result; |
| 102 | result = mMidiFile->render(); |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | MidiFileThread(const MidiFileThread &); |
| 107 | MidiFileThread &operator=(const MidiFileThread &); |
| 108 | }; |
| 109 | |
| 110 | sp<MidiFileThread> mThread; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | }; // namespace android |
| 114 | |
| 115 | #endif // ANDROID_MIDIFILE_H |