blob: 426817048d0d1dc041e563901e1dd48c343b91c8 [file] [log] [blame]
The Android Open Source Projectb7986892009-01-09 17:51:23 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#ifndef JETPLAYER_H_
18#define JETPLAYER_H_
19
20#include <utils/threads.h>
21#include <nativehelper/jni.h>
22
23#include <libsonivox/jet.h>
24#include <libsonivox/eas_types.h>
25#include "AudioTrack.h"
26
27
28namespace android {
29
30typedef void (*jetevent_callback)(int eventType, int val1, int val2, void *cookie);
31
32class JetPlayer {
33
34public:
35
36 static const int JET_USERID_UPDATE = 1;
37 static const int JET_NUMQUEUEDSEGMENT_UPDATE = 2;
38 static const int JET_PAUSE_UPDATE = 3;
39
40 JetPlayer(jobject javaJetPlayer,
41 int maxTracks = 32,
42 int trackBufferSize = 1200);
43 ~JetPlayer();
44 int init();
45 int release();
46
47 int openFile(const char* url);
48 int closeFile();
49 int play();
50 int pause();
51 int queueSegment(int segmentNum, int libNum, int repeatCount, int transpose,
52 EAS_U32 muteFlags, EAS_U8 userID);
53 int setMuteFlags(EAS_U32 muteFlags, bool sync);
54 int setMuteFlag(int trackNum, bool muteFlag, bool sync);
55 int triggerClip(int clipId);
56
57 void setEventCallback(jetevent_callback callback);
58
59 int getMaxTracks() { return mMaxTracks; };
60
61
62private:
63 static int renderThread(void*);
64 int render();
65 void fireEventOnStatusChange();
66
67 JetPlayer() {} // no default constructor
68 void dump();
69 void dumpJetStatus(S_JET_STATUS* pJetStatus);
70
71 jetevent_callback mEventCallback;
72
73 jobject mJavaJetPlayerRef;
74 Mutex mMutex; // mutex to sync the render and playback thread with the JET calls
75 pid_t mTid;
76 Condition mCondition;
77 volatile bool mRender;
78 bool mPaused;
79
80 EAS_STATE mState;
81 int* mMemFailedVar;
82
83 int mMaxTracks; // max number of MIDI tracks, usually 32
84 EAS_DATA_HANDLE mEasData;
85 EAS_FILE_LOCATOR mEasJetFileLoc;
86 EAS_PCM* mAudioBuffer;// EAS renders the MIDI data into this buffer,
87 AudioTrack* mAudioTrack; // and we play it in this audio track
88 int mTrackBufferSize;
89 S_JET_STATUS mJetStatus;
90 S_JET_STATUS mPreviousJetStatus;
91
92 char mJetFilePath[256];
93
94
95}; // end class JetPlayer
96
97} // end namespace android
98
99
100
101#endif /*JETPLAYER_H_*/