blob: 2a0dcf9d17a281d7f2f2c1105203bfb036aef258 [file] [log] [blame]
The Android Open Source Project89fa4ad2009-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>
22#include <media/AudioTrack.h>
23#include <libsonivox/eas.h>
24
25namespace android {
26
Glenn Kasten90100b52011-06-23 17:11:35 -070027// Note that the name MidiFile is misleading; this actually represents a MIDI file player
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080028class MidiFile : public MediaPlayerInterface {
29public:
30 MidiFile();
31 ~MidiFile();
32
33 virtual status_t initCheck();
Andreas Huber2db84552010-01-28 11:19:57 -080034
35 virtual status_t setDataSource(
36 const char* path, const KeyedVector<String8, String8> *headers);
37
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080038 virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
Glenn Kasten11731182011-02-08 17:26:17 -080039 virtual status_t setVideoSurfaceTexture(
40 const sp<ISurfaceTexture>& surfaceTexture)
41 { return UNKNOWN_ERROR; }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080042 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; }
nikod608a812009-07-16 16:39:53 -070055 virtual status_t invoke(const Parcel& request, Parcel *reply) {
56 return INVALID_OPERATION;
57 }
Gloria Wang4f9e47f2011-04-25 17:28:22 -070058 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
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080065
66private:
67 status_t createOutputTrack();
68 status_t reset_nosync();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080069 int render();
70 void updateState(){ EAS_State(mEasData, mEasHandle, &mState); }
71
72 Mutex mMutex;
73 Condition mCondition;
74 EAS_DATA_HANDLE mEasData;
75 EAS_HANDLE mEasHandle;
76 EAS_PCM* mAudioBuffer;
77 EAS_I32 mPlayTime;
78 EAS_I32 mDuration;
79 EAS_STATE mState;
80 EAS_FILE mFileLocator;
81 int mStreamType;
82 bool mLoop;
83 volatile bool mExit;
84 bool mPaused;
85 volatile bool mRender;
86 pid_t mTid;
Glenn Kasten90100b52011-06-23 17:11:35 -070087
88 class MidiFileThread : public Thread {
89 public:
90 MidiFileThread(MidiFile *midiPlayer) : mMidiFile(midiPlayer) {
91 }
92
93 protected:
94 virtual ~MidiFileThread() {}
95
96 private:
97 MidiFile *mMidiFile;
98
99 bool threadLoop() {
100 int result;
101 result = mMidiFile->render();
102 return false;
103 }
104
105 MidiFileThread(const MidiFileThread &);
106 MidiFileThread &operator=(const MidiFileThread &);
107 };
108
109 sp<MidiFileThread> mThread;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800110};
111
112}; // namespace android
113
114#endif // ANDROID_MIDIFILE_H