2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <utils/threads.h>
21 #include <nativehelper/jni.h>
23 #include <libsonivox/jet.h>
24 #include <libsonivox/eas_types.h>
25 #include "AudioTrack.h"
30 typedef void (*jetevent_callback)(int eventType, int val1, int val2, void *cookie);
36 // to keep in sync with the JetPlayer class constants
37 // defined in frameworks/base/media/java/android/media/JetPlayer.java
38 static const int JET_EVENT = 1;
39 static const int JET_USERID_UPDATE = 2;
40 static const int JET_NUMQUEUEDSEGMENT_UPDATE = 3;
41 static const int JET_PAUSE_UPDATE = 4;
43 JetPlayer(jobject javaJetPlayer,
45 int trackBufferSize = 1200);
50 int loadFromFile(const char* url);
51 int loadFromFD(const int fd, const long long offset, const long long length);
55 int queueSegment(int segmentNum, int libNum, int repeatCount, int transpose,
56 EAS_U32 muteFlags, EAS_U8 userID);
57 int setMuteFlags(EAS_U32 muteFlags, bool sync);
58 int setMuteFlag(int trackNum, bool muteFlag, bool sync);
59 int triggerClip(int clipId);
62 void setEventCallback(jetevent_callback callback);
64 int getMaxTracks() { return mMaxTracks; };
68 static int renderThread(void*);
70 void fireUpdateOnStatusChange();
71 void fireEventsFromJetQueue();
73 JetPlayer() {} // no default constructor
75 void dumpJetStatus(S_JET_STATUS* pJetStatus);
77 jetevent_callback mEventCallback;
79 jobject mJavaJetPlayerRef;
80 Mutex mMutex; // mutex to sync the render and playback thread with the JET calls
83 volatile bool mRender;
89 int mMaxTracks; // max number of MIDI tracks, usually 32
90 EAS_DATA_HANDLE mEasData;
91 EAS_FILE_LOCATOR mEasJetFileLoc;
92 EAS_PCM* mAudioBuffer;// EAS renders the MIDI data into this buffer,
93 AudioTrack* mAudioTrack; // and we play it in this audio track
95 S_JET_STATUS mJetStatus;
96 S_JET_STATUS mPreviousJetStatus;
98 char mJetFilePath[256];
101 }; // end class JetPlayer
103 } // end namespace android
107 #endif /*JETPLAYER_H_*/