The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Jean-Michel Trivi | 06aff80 | 2009-03-24 18:46:20 -0700 | [diff] [blame] | 17 | //#define LOG_NDEBUG 0 |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | #define LOG_TAG "JetPlayer-C" |
| 19 | |
| 20 | #include <utils/Log.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <media/JetPlayer.h> |
| 22 | |
| 23 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | namespace android |
| 25 | { |
| 26 | |
| 27 | static const int MIX_NUM_BUFFERS = 4; |
| 28 | static const S_EAS_LIB_CONFIG* pLibConfig = NULL; |
| 29 | |
| 30 | //------------------------------------------------------------------------------------------------- |
Eric Laurent | 2e66a78 | 2012-03-26 10:47:22 -0700 | [diff] [blame] | 31 | JetPlayer::JetPlayer(void *javaJetPlayer, int maxTracks, int trackBufferSize) : |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | mEventCallback(NULL), |
| 33 | mJavaJetPlayerRef(javaJetPlayer), |
| 34 | mTid(-1), |
| 35 | mRender(false), |
| 36 | mPaused(false), |
| 37 | mMaxTracks(maxTracks), |
| 38 | mEasData(NULL), |
Marco Nelissen | 3d21ae3 | 2018-02-16 08:24:08 -0800 | [diff] [blame^] | 39 | mIoWrapper(NULL), |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | mTrackBufferSize(trackBufferSize) |
| 41 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 42 | ALOGV("JetPlayer constructor"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | mPreviousJetStatus.currentUserID = -1; |
| 44 | mPreviousJetStatus.segmentRepeatCount = -1; |
| 45 | mPreviousJetStatus.numQueuedSegments = -1; |
| 46 | mPreviousJetStatus.paused = true; |
| 47 | } |
| 48 | |
| 49 | //------------------------------------------------------------------------------------------------- |
| 50 | JetPlayer::~JetPlayer() |
| 51 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 52 | ALOGV("~JetPlayer"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | release(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | //------------------------------------------------------------------------------------------------- |
| 57 | int JetPlayer::init() |
| 58 | { |
| 59 | //Mutex::Autolock lock(&mMutex); |
| 60 | |
| 61 | EAS_RESULT result; |
| 62 | |
| 63 | // retrieve the EAS library settings |
| 64 | if (pLibConfig == NULL) |
| 65 | pLibConfig = EAS_Config(); |
| 66 | if (pLibConfig == NULL) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 67 | ALOGE("JetPlayer::init(): EAS library configuration could not be retrieved, aborting."); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | return EAS_FAILURE; |
| 69 | } |
| 70 | |
| 71 | // init the EAS library |
| 72 | result = EAS_Init(&mEasData); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 73 | if (result != EAS_SUCCESS) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 74 | ALOGE("JetPlayer::init(): Error initializing Sonivox EAS library, aborting."); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | mState = EAS_STATE_ERROR; |
| 76 | return result; |
| 77 | } |
| 78 | // init the JET library with the default app event controller range |
| 79 | result = JET_Init(mEasData, NULL, sizeof(S_JET_CONFIG)); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 80 | if (result != EAS_SUCCESS) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 81 | ALOGE("JetPlayer::init(): Error initializing JET library, aborting."); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | mState = EAS_STATE_ERROR; |
| 83 | return result; |
| 84 | } |
| 85 | |
| 86 | // create the output AudioTrack |
| 87 | mAudioTrack = new AudioTrack(); |
Glenn Kasten | 3e98ecd | 2015-05-18 13:13:24 -0700 | [diff] [blame] | 88 | status_t status = mAudioTrack->set(AUDIO_STREAM_MUSIC, //TODO parameterize this |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | pLibConfig->sampleRate, |
Glenn Kasten | e1c3962 | 2012-01-04 09:36:37 -0800 | [diff] [blame] | 90 | AUDIO_FORMAT_PCM_16_BIT, |
Glenn Kasten | ab334fd | 2012-03-14 12:56:06 -0700 | [diff] [blame] | 91 | audio_channel_out_mask_from_count(pLibConfig->numChannels), |
Glenn Kasten | bce50bf | 2014-02-27 15:29:51 -0800 | [diff] [blame] | 92 | (size_t) mTrackBufferSize, |
Eric Laurent | 0ca3cf9 | 2012-04-18 09:24:29 -0700 | [diff] [blame] | 93 | AUDIO_OUTPUT_FLAG_NONE); |
Glenn Kasten | 3e98ecd | 2015-05-18 13:13:24 -0700 | [diff] [blame] | 94 | if (status != OK) { |
| 95 | ALOGE("JetPlayer::init(): Error initializing JET library; AudioTrack error %d", status); |
| 96 | mAudioTrack.clear(); |
| 97 | mState = EAS_STATE_ERROR; |
| 98 | return EAS_FAILURE; |
| 99 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | |
| 101 | // create render and playback thread |
| 102 | { |
| 103 | Mutex::Autolock l(mMutex); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 104 | ALOGV("JetPlayer::init(): trying to start render thread"); |
Glenn Kasten | a23856c | 2011-06-23 16:43:24 -0700 | [diff] [blame] | 105 | mThread = new JetPlayerThread(this); |
| 106 | mThread->run("jetRenderThread", ANDROID_PRIORITY_AUDIO); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | mCondition.wait(mMutex); |
| 108 | } |
| 109 | if (mTid > 0) { |
| 110 | // render thread started, we're ready |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 111 | ALOGV("JetPlayer::init(): render thread(%d) successfully started.", mTid); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | mState = EAS_STATE_READY; |
| 113 | } else { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 114 | ALOGE("JetPlayer::init(): failed to start render thread."); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | mState = EAS_STATE_ERROR; |
| 116 | return EAS_FAILURE; |
| 117 | } |
| 118 | |
| 119 | return EAS_SUCCESS; |
| 120 | } |
| 121 | |
| 122 | void JetPlayer::setEventCallback(jetevent_callback eventCallback) |
| 123 | { |
| 124 | Mutex::Autolock l(mMutex); |
| 125 | mEventCallback = eventCallback; |
| 126 | } |
| 127 | |
| 128 | //------------------------------------------------------------------------------------------------- |
| 129 | int JetPlayer::release() |
| 130 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 131 | ALOGV("JetPlayer::release()"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | Mutex::Autolock lock(mMutex); |
| 133 | mPaused = true; |
| 134 | mRender = false; |
| 135 | if (mEasData) { |
| 136 | JET_Pause(mEasData); |
| 137 | JET_CloseFile(mEasData); |
| 138 | JET_Shutdown(mEasData); |
| 139 | EAS_Shutdown(mEasData); |
| 140 | } |
Marco Nelissen | 3d21ae3 | 2018-02-16 08:24:08 -0800 | [diff] [blame^] | 141 | delete mIoWrapper; |
| 142 | mIoWrapper = NULL; |
Glenn Kasten | 2799d74 | 2013-05-30 14:33:29 -0700 | [diff] [blame] | 143 | if (mAudioTrack != 0) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | mAudioTrack->stop(); |
| 145 | mAudioTrack->flush(); |
Glenn Kasten | 2799d74 | 2013-05-30 14:33:29 -0700 | [diff] [blame] | 146 | mAudioTrack.clear(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | } |
| 148 | if (mAudioBuffer) { |
| 149 | delete mAudioBuffer; |
| 150 | mAudioBuffer = NULL; |
| 151 | } |
| 152 | mEasData = NULL; |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 153 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | return EAS_SUCCESS; |
| 155 | } |
| 156 | |
| 157 | |
| 158 | //------------------------------------------------------------------------------------------------- |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | int JetPlayer::render() { |
| 160 | EAS_RESULT result = EAS_FAILURE; |
| 161 | EAS_I32 count; |
| 162 | int temp; |
| 163 | bool audioStarted = false; |
| 164 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 165 | ALOGV("JetPlayer::render(): entering"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | |
| 167 | // allocate render buffer |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 168 | mAudioBuffer = |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | new EAS_PCM[pLibConfig->mixBufferSize * pLibConfig->numChannels * MIX_NUM_BUFFERS]; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | |
| 171 | // signal main thread that we started |
| 172 | { |
| 173 | Mutex::Autolock l(mMutex); |
Glenn Kasten | 0512ab5 | 2011-05-04 17:58:57 -0700 | [diff] [blame] | 174 | mTid = gettid(); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 175 | ALOGV("JetPlayer::render(): render thread(%d) signal", mTid); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | mCondition.signal(); |
| 177 | } |
| 178 | |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 179 | while (1) { |
| 180 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | mMutex.lock(); // [[[[[[[[ LOCK --------------------------------------- |
| 182 | |
The Android Open Source Project | 1179bc9 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 183 | if (mEasData == NULL) { |
| 184 | mMutex.unlock(); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 185 | ALOGV("JetPlayer::render(): NULL EAS data, exiting render."); |
The Android Open Source Project | 1179bc9 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 186 | goto threadExit; |
| 187 | } |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 188 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | // nothing to render, wait for client thread to wake us up |
| 190 | while (!mRender) |
| 191 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 192 | ALOGV("JetPlayer::render(): signal wait"); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 193 | if (audioStarted) { |
| 194 | mAudioTrack->pause(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | // we have to restart the playback once we start rendering again |
| 196 | audioStarted = false; |
| 197 | } |
| 198 | mCondition.wait(mMutex); |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 199 | ALOGV("JetPlayer::render(): signal rx'd"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | } |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 201 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | // render midi data into the input buffer |
| 203 | int num_output = 0; |
| 204 | EAS_PCM* p = mAudioBuffer; |
| 205 | for (int i = 0; i < MIX_NUM_BUFFERS; i++) { |
| 206 | result = EAS_Render(mEasData, p, pLibConfig->mixBufferSize, &count); |
| 207 | if (result != EAS_SUCCESS) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 208 | ALOGE("JetPlayer::render(): EAS_Render returned error %ld", result); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | } |
| 210 | p += count * pLibConfig->numChannels; |
| 211 | num_output += count * pLibConfig->numChannels * sizeof(EAS_PCM); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 212 | |
| 213 | // send events that were generated (if any) to the event callback |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | fireEventsFromJetQueue(); |
| 215 | } |
| 216 | |
| 217 | // update playback state |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 218 | //ALOGV("JetPlayer::render(): updating state"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | JET_Status(mEasData, &mJetStatus); |
| 220 | fireUpdateOnStatusChange(); |
| 221 | mPaused = mJetStatus.paused; |
| 222 | |
| 223 | mMutex.unlock(); // UNLOCK ]]]]]]]] ----------------------------------- |
| 224 | |
| 225 | // check audio output track |
| 226 | if (mAudioTrack == NULL) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 227 | ALOGE("JetPlayer::render(): output AudioTrack was not created"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | goto threadExit; |
| 229 | } |
| 230 | |
| 231 | // Write data to the audio hardware |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 232 | //ALOGV("JetPlayer::render(): writing to audio output"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | if ((temp = mAudioTrack->write(mAudioBuffer, num_output)) < 0) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 234 | ALOGE("JetPlayer::render(): Error in writing:%d",temp); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | return temp; |
| 236 | } |
| 237 | |
| 238 | // start audio output if necessary |
| 239 | if (!audioStarted) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 240 | ALOGV("JetPlayer::render(): starting audio playback"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | mAudioTrack->start(); |
| 242 | audioStarted = true; |
| 243 | } |
| 244 | |
| 245 | }//while (1) |
| 246 | |
| 247 | threadExit: |
Glenn Kasten | 9d1f02d | 2012-02-08 17:47:58 -0800 | [diff] [blame] | 248 | if (mAudioTrack != NULL) { |
The Android Open Source Project | 1179bc9 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 249 | mAudioTrack->stop(); |
| 250 | mAudioTrack->flush(); |
| 251 | } |
Glenn Kasten | 9d1f02d | 2012-02-08 17:47:58 -0800 | [diff] [blame] | 252 | delete [] mAudioBuffer; |
| 253 | mAudioBuffer = NULL; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | mMutex.lock(); |
| 255 | mTid = -1; |
| 256 | mCondition.signal(); |
| 257 | mMutex.unlock(); |
| 258 | return result; |
| 259 | } |
| 260 | |
| 261 | |
| 262 | //------------------------------------------------------------------------------------------------- |
| 263 | // fire up an update if any of the status fields has changed |
| 264 | // precondition: mMutex locked |
| 265 | void JetPlayer::fireUpdateOnStatusChange() |
| 266 | { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 267 | if ( (mJetStatus.currentUserID != mPreviousJetStatus.currentUserID) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | ||(mJetStatus.segmentRepeatCount != mPreviousJetStatus.segmentRepeatCount) ) { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 269 | if (mEventCallback) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | mEventCallback( |
| 271 | JetPlayer::JET_USERID_UPDATE, |
| 272 | mJetStatus.currentUserID, |
| 273 | mJetStatus.segmentRepeatCount, |
| 274 | mJavaJetPlayerRef); |
| 275 | } |
| 276 | mPreviousJetStatus.currentUserID = mJetStatus.currentUserID; |
| 277 | mPreviousJetStatus.segmentRepeatCount = mJetStatus.segmentRepeatCount; |
| 278 | } |
| 279 | |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 280 | if (mJetStatus.numQueuedSegments != mPreviousJetStatus.numQueuedSegments) { |
| 281 | if (mEventCallback) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | mEventCallback( |
| 283 | JetPlayer::JET_NUMQUEUEDSEGMENT_UPDATE, |
| 284 | mJetStatus.numQueuedSegments, |
| 285 | -1, |
| 286 | mJavaJetPlayerRef); |
| 287 | } |
| 288 | mPreviousJetStatus.numQueuedSegments = mJetStatus.numQueuedSegments; |
| 289 | } |
| 290 | |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 291 | if (mJetStatus.paused != mPreviousJetStatus.paused) { |
| 292 | if (mEventCallback) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | mEventCallback(JetPlayer::JET_PAUSE_UPDATE, |
| 294 | mJetStatus.paused, |
| 295 | -1, |
| 296 | mJavaJetPlayerRef); |
| 297 | } |
| 298 | mPreviousJetStatus.paused = mJetStatus.paused; |
| 299 | } |
| 300 | |
| 301 | } |
| 302 | |
| 303 | |
| 304 | //------------------------------------------------------------------------------------------------- |
| 305 | // fire up all the JET events in the JET engine queue (until the queue is empty) |
| 306 | // precondition: mMutex locked |
| 307 | void JetPlayer::fireEventsFromJetQueue() |
| 308 | { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 309 | if (!mEventCallback) { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | // no callback, just empty the event queue |
| 311 | while (JET_GetEvent(mEasData, NULL, NULL)) { } |
| 312 | return; |
| 313 | } |
| 314 | |
| 315 | EAS_U32 rawEvent; |
| 316 | while (JET_GetEvent(mEasData, &rawEvent, NULL)) { |
| 317 | mEventCallback( |
| 318 | JetPlayer::JET_EVENT, |
| 319 | rawEvent, |
| 320 | -1, |
| 321 | mJavaJetPlayerRef); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | |
| 326 | //------------------------------------------------------------------------------------------------- |
| 327 | int JetPlayer::loadFromFile(const char* path) |
| 328 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 329 | ALOGV("JetPlayer::loadFromFile(): path=%s", path); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | |
| 331 | Mutex::Autolock lock(mMutex); |
| 332 | |
Marco Nelissen | 3d21ae3 | 2018-02-16 08:24:08 -0800 | [diff] [blame^] | 333 | delete mIoWrapper; |
Marco Nelissen | 08b9e2d | 2014-12-16 12:46:34 -0800 | [diff] [blame] | 334 | mIoWrapper = new MidiIoWrapper(path); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | |
Marco Nelissen | 08b9e2d | 2014-12-16 12:46:34 -0800 | [diff] [blame] | 336 | EAS_RESULT result = JET_OpenFile(mEasData, mIoWrapper->getLocator()); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 337 | if (result != EAS_SUCCESS) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | mState = EAS_STATE_ERROR; |
| 339 | else |
| 340 | mState = EAS_STATE_OPEN; |
| 341 | return( result ); |
| 342 | } |
| 343 | |
| 344 | |
| 345 | //------------------------------------------------------------------------------------------------- |
| 346 | int JetPlayer::loadFromFD(const int fd, const long long offset, const long long length) |
| 347 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 348 | ALOGV("JetPlayer::loadFromFD(): fd=%d offset=%lld length=%lld", fd, offset, length); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 349 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | Mutex::Autolock lock(mMutex); |
| 351 | |
Marco Nelissen | 3d21ae3 | 2018-02-16 08:24:08 -0800 | [diff] [blame^] | 352 | delete mIoWrapper; |
Marco Nelissen | 08b9e2d | 2014-12-16 12:46:34 -0800 | [diff] [blame] | 353 | mIoWrapper = new MidiIoWrapper(fd, offset, length); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 354 | |
Marco Nelissen | 08b9e2d | 2014-12-16 12:46:34 -0800 | [diff] [blame] | 355 | EAS_RESULT result = JET_OpenFile(mEasData, mIoWrapper->getLocator()); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 356 | if (result != EAS_SUCCESS) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | mState = EAS_STATE_ERROR; |
| 358 | else |
| 359 | mState = EAS_STATE_OPEN; |
| 360 | return( result ); |
| 361 | } |
| 362 | |
| 363 | |
| 364 | //------------------------------------------------------------------------------------------------- |
| 365 | int JetPlayer::closeFile() |
| 366 | { |
| 367 | Mutex::Autolock lock(mMutex); |
| 368 | return JET_CloseFile(mEasData); |
| 369 | } |
| 370 | |
| 371 | |
| 372 | //------------------------------------------------------------------------------------------------- |
| 373 | int JetPlayer::play() |
| 374 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 375 | ALOGV("JetPlayer::play(): entering"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | Mutex::Autolock lock(mMutex); |
| 377 | |
| 378 | EAS_RESULT result = JET_Play(mEasData); |
| 379 | |
| 380 | mPaused = false; |
| 381 | mRender = true; |
| 382 | |
| 383 | JET_Status(mEasData, &mJetStatus); |
| 384 | this->dumpJetStatus(&mJetStatus); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 385 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | fireUpdateOnStatusChange(); |
| 387 | |
| 388 | // wake up render thread |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 389 | ALOGV("JetPlayer::play(): wakeup render thread"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | mCondition.signal(); |
| 391 | |
| 392 | return result; |
| 393 | } |
| 394 | |
| 395 | //------------------------------------------------------------------------------------------------- |
| 396 | int JetPlayer::pause() |
| 397 | { |
| 398 | Mutex::Autolock lock(mMutex); |
| 399 | mPaused = true; |
| 400 | EAS_RESULT result = JET_Pause(mEasData); |
| 401 | |
| 402 | mRender = false; |
| 403 | |
| 404 | JET_Status(mEasData, &mJetStatus); |
| 405 | this->dumpJetStatus(&mJetStatus); |
| 406 | fireUpdateOnStatusChange(); |
| 407 | |
| 408 | |
| 409 | return result; |
| 410 | } |
| 411 | |
| 412 | |
| 413 | //------------------------------------------------------------------------------------------------- |
| 414 | int JetPlayer::queueSegment(int segmentNum, int libNum, int repeatCount, int transpose, |
| 415 | EAS_U32 muteFlags, EAS_U8 userID) |
| 416 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 417 | ALOGV("JetPlayer::queueSegment segmentNum=%d, libNum=%d, repeatCount=%d, transpose=%d", |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | segmentNum, libNum, repeatCount, transpose); |
| 419 | Mutex::Autolock lock(mMutex); |
Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 420 | return JET_QueueSegment(mEasData, segmentNum, libNum, repeatCount, transpose, muteFlags, |
| 421 | userID); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | //------------------------------------------------------------------------------------------------- |
| 425 | int JetPlayer::setMuteFlags(EAS_U32 muteFlags, bool sync) |
| 426 | { |
| 427 | Mutex::Autolock lock(mMutex); |
| 428 | return JET_SetMuteFlags(mEasData, muteFlags, sync); |
| 429 | } |
| 430 | |
| 431 | //------------------------------------------------------------------------------------------------- |
| 432 | int JetPlayer::setMuteFlag(int trackNum, bool muteFlag, bool sync) |
| 433 | { |
| 434 | Mutex::Autolock lock(mMutex); |
| 435 | return JET_SetMuteFlag(mEasData, trackNum, muteFlag, sync); |
| 436 | } |
| 437 | |
| 438 | //------------------------------------------------------------------------------------------------- |
| 439 | int JetPlayer::triggerClip(int clipId) |
| 440 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 441 | ALOGV("JetPlayer::triggerClip clipId=%d", clipId); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 442 | Mutex::Autolock lock(mMutex); |
| 443 | return JET_TriggerClip(mEasData, clipId); |
| 444 | } |
| 445 | |
| 446 | //------------------------------------------------------------------------------------------------- |
| 447 | int JetPlayer::clearQueue() |
| 448 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 449 | ALOGV("JetPlayer::clearQueue"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | Mutex::Autolock lock(mMutex); |
| 451 | return JET_Clear_Queue(mEasData); |
| 452 | } |
| 453 | |
| 454 | //------------------------------------------------------------------------------------------------- |
| 455 | void JetPlayer::dump() |
| 456 | { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | void JetPlayer::dumpJetStatus(S_JET_STATUS* pJetStatus) |
| 460 | { |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 461 | if (pJetStatus!=NULL) |
Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 462 | ALOGV(">> current JET player status: userID=%d segmentRepeatCount=%d numQueuedSegments=%d " |
| 463 | "paused=%d", |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | pJetStatus->currentUserID, pJetStatus->segmentRepeatCount, |
| 465 | pJetStatus->numQueuedSegments, pJetStatus->paused); |
| 466 | else |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 467 | ALOGE(">> JET player status is NULL"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | |
| 471 | } // end namespace android |