blob: f6f8f7b3ef9fa8be3aa40c0ab890c42461ab575d [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Project9066cfe2009-03-03 19:31:44 -080022#include <libsonivox/eas.h>
23
24namespace android {
25
Glenn Kasten376c3932011-06-23 17:11:35 -070026// Note that the name MidiFile is misleading; this actually represents a MIDI file player
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027class MidiFile : public MediaPlayerInterface {
28public:
29 MidiFile();
30 ~MidiFile();
31
32 virtual status_t initCheck();
Andreas Huber25643002010-01-28 11:19:57 -080033
34 virtual status_t setDataSource(
35 const char* path, const KeyedVector<String8, String8> *headers);
36
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037 virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
Glenn Kastencc562a32011-02-08 17:26:17 -080038 virtual status_t setVideoSurfaceTexture(
39 const sp<ISurfaceTexture>& surfaceTexture)
40 { return UNKNOWN_ERROR; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041 virtual status_t prepare();
42 virtual status_t prepareAsync();
43 virtual status_t start();
44 virtual status_t stop();
45 virtual status_t seekTo(int msec);
46 virtual status_t pause();
47 virtual bool isPlaying();
48 virtual status_t getCurrentPosition(int* msec);
49 virtual status_t getDuration(int* msec);
50 virtual status_t release();
51 virtual status_t reset();
52 virtual status_t setLooping(int loop);
53 virtual player_type playerType() { return SONIVOX_PLAYER; }
niko89948372009-07-16 16:39:53 -070054 virtual status_t invoke(const Parcel& request, Parcel *reply) {
55 return INVALID_OPERATION;
56 }
Gloria Wangd01ec6e2011-04-25 17:28:22 -070057 virtual status_t setParameter(int key, const Parcel &request) {
58 return INVALID_OPERATION;
59 }
60 virtual status_t getParameter(int key, Parcel *reply) {
61 return INVALID_OPERATION;
62 }
63
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064
65private:
66 status_t createOutputTrack();
67 status_t reset_nosync();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 int render();
69 void updateState(){ EAS_State(mEasData, mEasHandle, &mState); }
70
71 Mutex mMutex;
72 Condition mCondition;
73 EAS_DATA_HANDLE mEasData;
74 EAS_HANDLE mEasHandle;
75 EAS_PCM* mAudioBuffer;
76 EAS_I32 mPlayTime;
77 EAS_I32 mDuration;
78 EAS_STATE mState;
79 EAS_FILE mFileLocator;
Glenn Kastenbc1d77b2012-01-12 16:38:12 -080080 audio_stream_type_t mStreamType;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 bool mLoop;
82 volatile bool mExit;
83 bool mPaused;
84 volatile bool mRender;
85 pid_t mTid;
Glenn Kasten376c3932011-06-23 17:11:35 -070086
87 class MidiFileThread : public Thread {
88 public:
89 MidiFileThread(MidiFile *midiPlayer) : mMidiFile(midiPlayer) {
90 }
91
92 protected:
93 virtual ~MidiFileThread() {}
94
95 private:
96 MidiFile *mMidiFile;
97
98 bool threadLoop() {
99 int result;
100 result = mMidiFile->render();
101 return false;
102 }
103
104 MidiFileThread(const MidiFileThread &);
105 MidiFileThread &operator=(const MidiFileThread &);
106 };
107
108 sp<MidiFileThread> mThread;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109};
110
111}; // namespace android
112
113#endif // ANDROID_MIDIFILE_H