blob: 4cc266dec4455dd3f5aa2b95b325f8534a2ca9ac [file] [log] [blame]
Marco Nelissenf0ef8562019-10-17 08:55:52 -07001/*
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
22#include <libsonivox/jet.h>
23#include <libsonivox/eas_types.h>
24#include <media/AudioTrack.h>
25#include <media/MidiIoWrapper.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 // 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
Bart Van Asscheb48ae8a2024-08-02 10:12:22 -070043 explicit JetPlayer(void *javaJetPlayer,
Marco Nelissenf0ef8562019-10-17 08:55:52 -070044 int maxTracks = 32,
45 int trackBufferSize = 1200);
46 ~JetPlayer();
47 int init();
48 int release();
49
50 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);
63
64 int getMaxTracks() { return mMaxTracks; };
65
66
67private:
68 int render();
69 void fireUpdateOnStatusChange();
70 void fireEventsFromJetQueue();
71
Marco Nelissenf0ef8562019-10-17 08:55:52 -070072 void dump();
73 void dumpJetStatus(S_JET_STATUS* pJetStatus);
74
75 jetevent_callback mEventCallback;
76
77 void* mJavaJetPlayerRef;
78 Mutex mMutex; // mutex to sync the render and playback thread with the JET calls
79 pid_t mTid;
80 Condition mCondition;
81 volatile bool mRender;
82 bool mPaused;
83
84 EAS_STATE mState;
85 int* mMemFailedVar;
86
87 int mMaxTracks; // max number of MIDI tracks, usually 32
88 EAS_DATA_HANDLE mEasData;
89 MidiIoWrapper* mIoWrapper;
90 EAS_PCM* mAudioBuffer;// EAS renders the MIDI data into this buffer,
91 sp<AudioTrack> mAudioTrack; // and we play it in this audio track
92 int mTrackBufferSize;
93 S_JET_STATUS mJetStatus;
94 S_JET_STATUS mPreviousJetStatus;
95
96 class JetPlayerThread : public Thread {
97 public:
Bart Van Asscheb48ae8a2024-08-02 10:12:22 -070098 explicit JetPlayerThread(JetPlayer *player) : mPlayer(player) {
Marco Nelissenf0ef8562019-10-17 08:55:52 -070099 }
100
101 protected:
102 virtual ~JetPlayerThread() {}
103
104 private:
105 JetPlayer *mPlayer;
106
107 bool threadLoop() {
Bart Van Asscheb48ae8a2024-08-02 10:12:22 -0700108 mPlayer->render();
Marco Nelissenf0ef8562019-10-17 08:55:52 -0700109 return false;
110 }
111
112 JetPlayerThread(const JetPlayerThread &);
113 JetPlayerThread &operator=(const JetPlayerThread &);
114 };
115
116 sp<JetPlayerThread> mThread;
117
118}; // end class JetPlayer
119
120} // end namespace android
121
122
123
124#endif /*JETPLAYER_H_*/