Loading include/media/JetPlayer.h 0 → 100644 +101 −0 Original line number Diff line number Diff line /* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef JETPLAYER_H_ #define JETPLAYER_H_ #include <utils/threads.h> #include <nativehelper/jni.h> #include <libsonivox/jet.h> #include <libsonivox/eas_types.h> #include "AudioTrack.h" namespace android { typedef void (*jetevent_callback)(int eventType, int val1, int val2, void *cookie); class JetPlayer { public: static const int JET_USERID_UPDATE = 1; static const int JET_NUMQUEUEDSEGMENT_UPDATE = 2; static const int JET_PAUSE_UPDATE = 3; JetPlayer(jobject javaJetPlayer, int maxTracks = 32, int trackBufferSize = 1200); ~JetPlayer(); int init(); int release(); int openFile(const char* url); int closeFile(); int play(); int pause(); int queueSegment(int segmentNum, int libNum, int repeatCount, int transpose, EAS_U32 muteFlags, EAS_U8 userID); int setMuteFlags(EAS_U32 muteFlags, bool sync); int setMuteFlag(int trackNum, bool muteFlag, bool sync); int triggerClip(int clipId); void setEventCallback(jetevent_callback callback); int getMaxTracks() { return mMaxTracks; }; private: static int renderThread(void*); int render(); void fireEventOnStatusChange(); JetPlayer() {} // no default constructor void dump(); void dumpJetStatus(S_JET_STATUS* pJetStatus); jetevent_callback mEventCallback; jobject mJavaJetPlayerRef; Mutex mMutex; // mutex to sync the render and playback thread with the JET calls pid_t mTid; Condition mCondition; volatile bool mRender; bool mPaused; EAS_STATE mState; int* mMemFailedVar; int mMaxTracks; // max number of MIDI tracks, usually 32 EAS_DATA_HANDLE mEasData; EAS_FILE_LOCATOR mEasJetFileLoc; EAS_PCM* mAudioBuffer;// EAS renders the MIDI data into this buffer, AudioTrack* mAudioTrack; // and we play it in this audio track int mTrackBufferSize; S_JET_STATUS mJetStatus; S_JET_STATUS mPreviousJetStatus; char mJetFilePath[256]; }; // end class JetPlayer } // end namespace android #endif /*JETPLAYER_H_*/ include/media/ToneGenerator.h +1 −0 Original line number Diff line number Diff line Loading @@ -134,6 +134,7 @@ private: Condition mWaitCbkCond; // condition enabling interface to wait for audio callback completion after a change is requested float mVolume; // Volume applied to audio track int mStreamType; // Audio stream used for output int mProcessSize; // Size of audio blocks generated at a time by audioCallback() (in PCM frames). bool initAudioTrack(); static void audioCallback(int event, void* user, void *info); Loading include/media/mediametadataretriever.h +5 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,11 @@ enum { METADATA_KEY_RATING = 13, METADATA_KEY_COMMENT = 14, METADATA_KEY_COPYRIGHT = 15, METADATA_KEY_BIT_RATE = 16, METADATA_KEY_FRAME_RATE = 17, METADATA_KEY_VIDEO_FORMAT = 18, METADATA_KEY_VIDEO_HEIGHT = 19, METADATA_KEY_VIDEO_WIDTH = 20, // Add more here... }; Loading media/libmedia/Android.mk +3 −2 Original line number Diff line number Diff line Loading @@ -16,10 +16,11 @@ LOCAL_SRC_FILES:= \ mediarecorder.cpp \ IMediaMetadataRetriever.cpp \ mediametadataretriever.cpp \ ToneGenerator.cpp ToneGenerator.cpp \ JetPlayer.cpp LOCAL_SHARED_LIBRARIES := \ libui libcutils libutils libui libcutils libutils libsonivox LOCAL_MODULE:= libmedia Loading media/libmedia/AudioTrack.cpp +7 −15 Original line number Diff line number Diff line Loading @@ -231,20 +231,22 @@ status_t AudioTrack::set( mAudioTrack = track; mCblkMemory = cblk; mCblk = static_cast<audio_track_cblk_t*>(cblk->pointer()); mCblk->out = 1; // Update buffer size in case it has been limited by AudioFlinger during track creation mFrameCount = mCblk->frameCount; if (sharedBuffer == 0) { mCblk->buffers = (char*)mCblk + sizeof(audio_track_cblk_t); } else { mCblk->buffers = sharedBuffer->pointer(); // Force buffer full condition as data is already present in shared memory mCblk->stepUser(mFrameCount); } mCblk->out = 1; mCblk->volume[0] = mCblk->volume[1] = 0x1000; mVolume[LEFT] = 1.0f; mVolume[RIGHT] = 1.0f; mSampleRate = sampleRate; mStreamType = streamType; mFormat = format; // Update buffer size in case it has been limited by AudioFlinger during track creation mFrameCount = mCblk->frameCount; mChannelCount = channelCount; mSharedBuffer = sharedBuffer; mMuted = false; Loading Loading @@ -327,11 +329,6 @@ void AudioTrack::start() } if (android_atomic_or(1, &mActive) == 0) { if (mSharedBuffer != 0) { // Force buffer full condition as data is already present in shared memory mCblk->user = mFrameCount; mCblk->flowControlFlag = 0; } mNewPosition = mCblk->server + mUpdatePeriod; if (t != 0) { t->run("AudioTrackThread", THREAD_PRIORITY_AUDIO_CLIENT); Loading Loading @@ -467,7 +464,6 @@ status_t AudioTrack::setLoop(uint32_t loopStart, uint32_t loopEnd, int loopCount } if (loopStart >= loopEnd || loopStart < cblk->user || loopEnd - loopStart > mFrameCount) { LOGW("setLoop invalid value: loopStart %d, loopEnd %d, loopCount %d, framecount %d, user %d", loopStart, loopEnd, loopCount, mFrameCount, cblk->user); return BAD_VALUE; Loading Loading @@ -958,12 +954,8 @@ uint32_t audio_track_cblk_t::framesAvailable_l() uint32_t s = this->server; if (out) { if (u < loopEnd) { return s + frameCount - u; } else { uint32_t limit = (s < loopStart) ? s : loopStart; return limit + frameCount - u; } } else { return frameCount + u - s; } Loading Loading
include/media/JetPlayer.h 0 → 100644 +101 −0 Original line number Diff line number Diff line /* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef JETPLAYER_H_ #define JETPLAYER_H_ #include <utils/threads.h> #include <nativehelper/jni.h> #include <libsonivox/jet.h> #include <libsonivox/eas_types.h> #include "AudioTrack.h" namespace android { typedef void (*jetevent_callback)(int eventType, int val1, int val2, void *cookie); class JetPlayer { public: static const int JET_USERID_UPDATE = 1; static const int JET_NUMQUEUEDSEGMENT_UPDATE = 2; static const int JET_PAUSE_UPDATE = 3; JetPlayer(jobject javaJetPlayer, int maxTracks = 32, int trackBufferSize = 1200); ~JetPlayer(); int init(); int release(); int openFile(const char* url); int closeFile(); int play(); int pause(); int queueSegment(int segmentNum, int libNum, int repeatCount, int transpose, EAS_U32 muteFlags, EAS_U8 userID); int setMuteFlags(EAS_U32 muteFlags, bool sync); int setMuteFlag(int trackNum, bool muteFlag, bool sync); int triggerClip(int clipId); void setEventCallback(jetevent_callback callback); int getMaxTracks() { return mMaxTracks; }; private: static int renderThread(void*); int render(); void fireEventOnStatusChange(); JetPlayer() {} // no default constructor void dump(); void dumpJetStatus(S_JET_STATUS* pJetStatus); jetevent_callback mEventCallback; jobject mJavaJetPlayerRef; Mutex mMutex; // mutex to sync the render and playback thread with the JET calls pid_t mTid; Condition mCondition; volatile bool mRender; bool mPaused; EAS_STATE mState; int* mMemFailedVar; int mMaxTracks; // max number of MIDI tracks, usually 32 EAS_DATA_HANDLE mEasData; EAS_FILE_LOCATOR mEasJetFileLoc; EAS_PCM* mAudioBuffer;// EAS renders the MIDI data into this buffer, AudioTrack* mAudioTrack; // and we play it in this audio track int mTrackBufferSize; S_JET_STATUS mJetStatus; S_JET_STATUS mPreviousJetStatus; char mJetFilePath[256]; }; // end class JetPlayer } // end namespace android #endif /*JETPLAYER_H_*/
include/media/ToneGenerator.h +1 −0 Original line number Diff line number Diff line Loading @@ -134,6 +134,7 @@ private: Condition mWaitCbkCond; // condition enabling interface to wait for audio callback completion after a change is requested float mVolume; // Volume applied to audio track int mStreamType; // Audio stream used for output int mProcessSize; // Size of audio blocks generated at a time by audioCallback() (in PCM frames). bool initAudioTrack(); static void audioCallback(int event, void* user, void *info); Loading
include/media/mediametadataretriever.h +5 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,11 @@ enum { METADATA_KEY_RATING = 13, METADATA_KEY_COMMENT = 14, METADATA_KEY_COPYRIGHT = 15, METADATA_KEY_BIT_RATE = 16, METADATA_KEY_FRAME_RATE = 17, METADATA_KEY_VIDEO_FORMAT = 18, METADATA_KEY_VIDEO_HEIGHT = 19, METADATA_KEY_VIDEO_WIDTH = 20, // Add more here... }; Loading
media/libmedia/Android.mk +3 −2 Original line number Diff line number Diff line Loading @@ -16,10 +16,11 @@ LOCAL_SRC_FILES:= \ mediarecorder.cpp \ IMediaMetadataRetriever.cpp \ mediametadataretriever.cpp \ ToneGenerator.cpp ToneGenerator.cpp \ JetPlayer.cpp LOCAL_SHARED_LIBRARIES := \ libui libcutils libutils libui libcutils libutils libsonivox LOCAL_MODULE:= libmedia Loading
media/libmedia/AudioTrack.cpp +7 −15 Original line number Diff line number Diff line Loading @@ -231,20 +231,22 @@ status_t AudioTrack::set( mAudioTrack = track; mCblkMemory = cblk; mCblk = static_cast<audio_track_cblk_t*>(cblk->pointer()); mCblk->out = 1; // Update buffer size in case it has been limited by AudioFlinger during track creation mFrameCount = mCblk->frameCount; if (sharedBuffer == 0) { mCblk->buffers = (char*)mCblk + sizeof(audio_track_cblk_t); } else { mCblk->buffers = sharedBuffer->pointer(); // Force buffer full condition as data is already present in shared memory mCblk->stepUser(mFrameCount); } mCblk->out = 1; mCblk->volume[0] = mCblk->volume[1] = 0x1000; mVolume[LEFT] = 1.0f; mVolume[RIGHT] = 1.0f; mSampleRate = sampleRate; mStreamType = streamType; mFormat = format; // Update buffer size in case it has been limited by AudioFlinger during track creation mFrameCount = mCblk->frameCount; mChannelCount = channelCount; mSharedBuffer = sharedBuffer; mMuted = false; Loading Loading @@ -327,11 +329,6 @@ void AudioTrack::start() } if (android_atomic_or(1, &mActive) == 0) { if (mSharedBuffer != 0) { // Force buffer full condition as data is already present in shared memory mCblk->user = mFrameCount; mCblk->flowControlFlag = 0; } mNewPosition = mCblk->server + mUpdatePeriod; if (t != 0) { t->run("AudioTrackThread", THREAD_PRIORITY_AUDIO_CLIENT); Loading Loading @@ -467,7 +464,6 @@ status_t AudioTrack::setLoop(uint32_t loopStart, uint32_t loopEnd, int loopCount } if (loopStart >= loopEnd || loopStart < cblk->user || loopEnd - loopStart > mFrameCount) { LOGW("setLoop invalid value: loopStart %d, loopEnd %d, loopCount %d, framecount %d, user %d", loopStart, loopEnd, loopCount, mFrameCount, cblk->user); return BAD_VALUE; Loading Loading @@ -958,12 +954,8 @@ uint32_t audio_track_cblk_t::framesAvailable_l() uint32_t s = this->server; if (out) { if (u < loopEnd) { return s + frameCount - u; } else { uint32_t limit = (s < loopStart) ? s : loopStart; return limit + frameCount - u; } } else { return frameCount + u - s; } Loading