blob: 63d1980c67a3a5c4458b3d09992433b820e4be88 [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -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>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080021
22#include <libsonivox/jet.h>
23#include <libsonivox/eas_types.h>
Glenn Kastenb4d30742012-03-13 14:46:23 -070024#include <media/AudioTrack.h>
Marco Nelissen08b9e2d2014-12-16 12:46:34 -080025#include <media/MidiIoWrapper.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080026
27
28namespace android {
29
30typedef void (*jetevent_callback)(int eventType, int val1, int val2, void *cookie);
31
32class JetPlayer {
33
34public:
35
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;
42
Eric Laurent2e66a782012-03-26 10:47:22 -070043 JetPlayer(void *javaJetPlayer,
Glenn Kastene53b9ea2012-03-12 16:29:55 -070044 int maxTracks = 32,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080045 int trackBufferSize = 1200);
46 ~JetPlayer();
47 int init();
48 int release();
Glenn Kastene53b9ea2012-03-12 16:29:55 -070049
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080050 int loadFromFile(const char* url);
51 int loadFromFD(const int fd, const long long offset, const long long length);
52 int closeFile();
53 int play();
54 int pause();
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);
60 int clearQueue();
61
62 void setEventCallback(jetevent_callback callback);
Glenn Kastene53b9ea2012-03-12 16:29:55 -070063
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080064 int getMaxTracks() { return mMaxTracks; };
65
66
67private:
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080068 int render();
69 void fireUpdateOnStatusChange();
70 void fireEventsFromJetQueue();
71
72 JetPlayer() {} // no default constructor
73 void dump();
74 void dumpJetStatus(S_JET_STATUS* pJetStatus);
75
76 jetevent_callback mEventCallback;
77
Eric Laurent2e66a782012-03-26 10:47:22 -070078 void* mJavaJetPlayerRef;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080079 Mutex mMutex; // mutex to sync the render and playback thread with the JET calls
80 pid_t mTid;
81 Condition mCondition;
82 volatile bool mRender;
83 bool mPaused;
84
85 EAS_STATE mState;
86 int* mMemFailedVar;
87
88 int mMaxTracks; // max number of MIDI tracks, usually 32
89 EAS_DATA_HANDLE mEasData;
Marco Nelissen08b9e2d2014-12-16 12:46:34 -080090 sp<MidiIoWrapper> mIoWrapper;
Glenn Kastene53b9ea2012-03-12 16:29:55 -070091 EAS_PCM* mAudioBuffer;// EAS renders the MIDI data into this buffer,
Glenn Kasten2799d742013-05-30 14:33:29 -070092 sp<AudioTrack> mAudioTrack; // and we play it in this audio track
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080093 int mTrackBufferSize;
94 S_JET_STATUS mJetStatus;
95 S_JET_STATUS mPreviousJetStatus;
96
Glenn Kastena23856c2011-06-23 16:43:24 -070097 class JetPlayerThread : public Thread {
98 public:
99 JetPlayerThread(JetPlayer *player) : mPlayer(player) {
100 }
101
102 protected:
103 virtual ~JetPlayerThread() {}
104
105 private:
106 JetPlayer *mPlayer;
107
108 bool threadLoop() {
109 int result;
110 result = mPlayer->render();
111 return false;
112 }
113
114 JetPlayerThread(const JetPlayerThread &);
115 JetPlayerThread &operator=(const JetPlayerThread &);
116 };
117
118 sp<JetPlayerThread> mThread;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800119
120}; // end class JetPlayer
121
122} // end namespace android
123
124
125
126#endif /*JETPLAYER_H_*/