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